Skip to content

Commit

Permalink
test: bad test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dristpunk committed Jan 23, 2024
1 parent d917f1e commit f22f77f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 39 deletions.
18 changes: 9 additions & 9 deletions sample-data/BasicSample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ contract BasicSample is AbstractBasic {
return true;
}

/**
* @notice External function that returns a bool
* @dev A dev comment
* @return Some return data
*/
function externalSimpleUnnamedReturns() external pure returns (bool) {
return true;
}

/**
* @notice Private test function
* @param _magicNumber A parameter description
Expand Down Expand Up @@ -85,6 +76,15 @@ contract BasicSample is AbstractBasic {
return (true, 111);
}

/**
* @notice External function that returns a bool
* @dev A dev comment
* @return Some return data
*/
function externalSimpleMultipleUnnamedReturn() external pure returns (bool, uint256) {
return (true, 111);
}

/**
* @notice This function should have an inheritdoc tag
*/
Expand Down
6 changes: 6 additions & 0 deletions sample-data/ParserTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ contract ParserTestFunny is IParserTest {
return 1;
}

/// @return
/// @return
function functionUnnamedEmptyReturn() external view returns (uint256, bool){
return (1, true);
}

// Forgot there is @inheritdoc and @notice
function viewFunctionWithParams(uint256 _param1, uint256 _param2) external view returns (uint256) {
return _param1 + _param2;
Expand Down
22 changes: 22 additions & 0 deletions test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,28 @@ describe('Parser', () => {
})
);
});

it.only('should parse empty return tag', async () => {
const node = contract.vFunctions.find(({ name }) => name === 'functionUnnamedEmptyReturn')!;
const result = parseNodeNatspec(node);

expect(result).toEqual(
mockNatspec({
tags: [],
params: [],
returns: [
{
name: '',
content: '',
},
{
name: '',
content: '',
},
],
})
);
});
});

describe('Contract with invalid natspec', () => {
Expand Down
84 changes: 54 additions & 30 deletions test/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,60 @@ describe('Validator', () => {
expect(result).toContainEqual(`@return missing for unnamed return`);
});

it('should warn of missed unnamed return', () => {
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleUnnamedReturn')!;
let natspec = {
tags: [
{
name: 'notice',
content: 'External function that returns a bool',
},
{
name: 'dev',
content: 'A dev comment',
},
],
params: [],
returns: [
{
name: 'Some',
content: 'return data',
},
],
};

const result = validator.validate(node, natspec);
console.log(result);
expect(result).toEqual([`@return missing for unnamed return`]); // only 1 warning
});

it('should warn even if @return is empty', () => {
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleMultipleUnnamedReturn')!;
let natspec = {
tags: [
{
name: 'notice',
content: 'External function that returns a bool',
},
{
name: 'dev',
content: 'A dev comment',
},
],
params: [],
returns: [
{
name: '',
content: '',
},
],
};

const result = validator.validate(node, natspec);
console.log(result);
expect(result).toEqual([`@return missing for unnamed return`]); // only 1 warning
});

// TODO: Check overridden functions, virtual, etc?
// it('should reveal missing natspec for an external function');
// it('should reveal missing natspec for a public function');
Expand Down Expand Up @@ -277,35 +331,5 @@ describe('Validator', () => {
const result = validator.validate(node, natspec);
expect(result).toContainEqual(`@inheritdoc is missing`);
});

it.only('should display unnamed returns correct', () => {
node = contract.vFunctions.find(({ name }) => name === 'externalSimpleUnnamedReturns')!;
let natspec = {
tags: [
{
name: 'notice',
content: 'External function that returns a bool',
},
{
name: 'dev',
content: 'A dev comment',
},
{
name: 'return',
content: 'Some return data',
},
],
params: [],
returns: [
{
name: '',
content: 'Some return data',
},
],
};

const result = validator.validate(node, natspec);
expect(result).toEqual([]);
});
});
});

0 comments on commit f22f77f

Please sign in to comment.