From a29462cf14ea8fd4991aeb800dae7e48ad2d16ec Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 10:31:35 -0300 Subject: [PATCH 01/10] autofix payable-fallback added --- e2e/08-autofix/payable-fallback/.solhint.json | 5 ++ e2e/08-autofix/payable-fallback/Foo1.sol | 50 +++++++++++++++++++ .../payable-fallback/Foo1AfterFix.sol | 50 +++++++++++++++++++ .../payable-fallback/Foo1BeforeFix.sol | 50 +++++++++++++++++++ e2e/autofix-test.js | 42 +++++++++++++++- lib/common/ast-types.js | 2 +- lib/rules/best-practises/payable-fallback.js | 21 +++++++- test/rules/best-practises/payable-fallback.js | 11 ++++ 8 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 e2e/08-autofix/payable-fallback/.solhint.json create mode 100644 e2e/08-autofix/payable-fallback/Foo1.sol create mode 100644 e2e/08-autofix/payable-fallback/Foo1AfterFix.sol create mode 100644 e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol diff --git a/e2e/08-autofix/payable-fallback/.solhint.json b/e2e/08-autofix/payable-fallback/.solhint.json new file mode 100644 index 00000000..3dd72e68 --- /dev/null +++ b/e2e/08-autofix/payable-fallback/.solhint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "payable-fallback": "warn" + } +} diff --git a/e2e/08-autofix/payable-fallback/Foo1.sol b/e2e/08-autofix/payable-fallback/Foo1.sol new file mode 100644 index 00000000..eb1cfdaf --- /dev/null +++ b/e2e/08-autofix/payable-fallback/Foo1.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +contract Generic { + + constructor() {} + + function anyFunction() {} + + //// fallback with receive + receive() public {} + + receive() external onlyOwner {} + + receive() external virtual { + uint256 anUintToFillSpace; + } + + //// fallback with no name + function() public {} + + function() { + uint256 anUintToFillSpace; + } + + function() external onlyOwner {} + + function() virtual { + uint256 anUintToFillSpace; + } + + + //// fallback explicit + fallback() {} + + fallback() { + uint256 anUintToFillSpace; + } + + fallback() external onlyOwner{ + uint256 anUintToFillSpace; + } + + fallback() virtual {} + + + fallback() external payable {} + function() external payable {} + receive() public virtual payable {} +} diff --git a/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol b/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol new file mode 100644 index 00000000..95d55746 --- /dev/null +++ b/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +contract Generic { + + constructor() {} + + function anyFunction() {} + + //// fallback with receive + receive() payable public {} + + receive() payable external onlyOwner {} + + receive() payable external virtual { + uint256 anUintToFillSpace; + } + + //// fallback with no name + function() payable {} + + function() payable { + uint256 anUintToFillSpace; + } + + function() payable external onlyOwner {} + + function() payable virtual { + uint256 anUintToFillSpace; + } + + + //// fallback explicit + fallback() payable {} + + fallback() payable { + uint256 anUintToFillSpace; + } + + fallback() payable external onlyOwner{ + uint256 anUintToFillSpace; + } + + fallback() payable virtual {} + + + fallback() external payable {} + function() external payable {} + receive() external virtual payable {} +} diff --git a/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol b/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol new file mode 100644 index 00000000..60b2f9c4 --- /dev/null +++ b/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.0; + +contract Generic { + + constructor() {} + + function anyFunction() {} + + //// fallback with receive + receive() public {} + + receive() external onlyOwner {} + + receive() external virtual { + uint256 anUintToFillSpace; + } + + //// fallback with no name + function() public {} + + function() { + uint256 anUintToFillSpace; + } + + function() external onlyOwner {} + + function() virtual { + uint256 anUintToFillSpace; + } + + + //// fallback explicit + fallback() {} + + fallback() { + uint256 anUintToFillSpace; + } + + fallback() external onlyOwner{ + uint256 anUintToFillSpace; + } + + fallback() virtual {} + + + fallback() external payable {} + function() external payable {} + receive() public virtual payable {} +} diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index 5579f83e..d24e2508 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -269,8 +269,48 @@ describe('e2e', function () { expect(result).to.be.true }) }) + + describe('autofix rule: payable-fallback', () => { + before(function () { + params = retrieveParams('private-vars-underscore/') + currentConfig = `${params.path}${params.subpath}.solhint.json` + currentFile = `${params.path}${params.subpath}Foo1.sol` + beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol` + afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol` + }) + describe('--fix with noPrompt', () => { + after(function () { + if (!E2E) { + copyFile(beforeFixFile, currentFile) + } + }) + + it('should compare Foo1 file with template BEFORE FIX file and they should match 5', () => { + result = compareTextFiles(currentFile, beforeFixFile) + expect(result).to.be.true + }) + + it('should compare Foo1 file with template AFTER FIX file and they should match 5', () => { + const { code, stdout } = shell.exec( + `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` + ) + + expect(code).to.equal(1) + + const reportLines = stdout.split('\n') + const finalLine = '11 problems (0 errors, 11 warnings)' + expect(reportLines[reportLines.length - 3]).to.contain(finalLine) + + result = compareTextFiles(currentFile, afterFixFile) + expect(result).to.be.true + }) + }) + it('should check FOO1 does not change after test 5', () => { + result = compareTextFiles(currentFile, beforeFixFile) + expect(result).to.be.true + }) + }) }) }) -// FALTA LA COMPARACION DEL FIX CON EL TEMPLATE FIX // FALTA LA PRUEBA DEL STORE TO FILE diff --git a/lib/common/ast-types.js b/lib/common/ast-types.js index 0bdae5ac..d2fbe4d4 100644 --- a/lib/common/ast-types.js +++ b/lib/common/ast-types.js @@ -1,5 +1,5 @@ function isFallbackFunction(node) { - return isFunctionDefinition(node) && node.isFallback + return isFunctionDefinition(node) && (node.isFallback || node.isReceiveEther) } function isReceiveFunction(node) { diff --git a/lib/rules/best-practises/payable-fallback.js b/lib/rules/best-practises/payable-fallback.js index 79921a92..723925ad 100644 --- a/lib/rules/best-practises/payable-fallback.js +++ b/lib/rules/best-practises/payable-fallback.js @@ -27,7 +27,7 @@ const meta = { isDefault: false, recommended: true, defaultSetup: 'warn', - + fixable: true, schema: null, } @@ -39,10 +39,27 @@ class PayableFallbackChecker extends BaseChecker { FunctionDefinition(node) { if (isFallbackFunction(node)) { if (node.stateMutability !== 'payable') { - this.warn(node, 'When fallback is not payable you will not be able to receive ether') + this.warn( + node, + 'Fallback should be external and payable to accept native currency', + this.fixStatement(node) + ) } } } + + fixStatement(node) { + const range = node.range + const stringToPut = ' payable ' + + if (node.isReceiveEther) { + range[0] += 9 + } else { + range[0] += 10 + } + + return (fixer) => fixer.insertTextBeforeRange(range, stringToPut) + } } module.exports = PayableFallbackChecker diff --git a/test/rules/best-practises/payable-fallback.js b/test/rules/best-practises/payable-fallback.js index 734c551b..281b7768 100644 --- a/test/rules/best-practises/payable-fallback.js +++ b/test/rules/best-practises/payable-fallback.js @@ -33,4 +33,15 @@ describe('Linter - payable-fallback', () => { assertNoWarnings(report) }) + + it('should raise for other fallback types when are not payable', () => { + const code = contractWith('fallback() external {} receive() onlyOwner {}') + + const report = linter.processStr(code, { + rules: { 'payable-fallback': 'warn' }, + }) + + assertWarnsCount(report, 2) + assertErrorMessage(report, 'payable') + }) }) From eb3aed3cbceb93fd70d53aeb230b86ff4f1911e3 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 10:36:48 -0300 Subject: [PATCH 02/10] fix: e2e folder name --- e2e/autofix-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index d24e2508..1d762fa8 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -272,7 +272,7 @@ describe('e2e', function () { describe('autofix rule: payable-fallback', () => { before(function () { - params = retrieveParams('private-vars-underscore/') + params = retrieveParams('payable-fallback/') currentConfig = `${params.path}${params.subpath}.solhint.json` currentFile = `${params.path}${params.subpath}Foo1.sol` beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol` From dcc74c86d6caa5a4bf6a0f9258a1f7f92c2634a9 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 10:44:55 -0300 Subject: [PATCH 03/10] fix: files for e2e --- e2e/08-autofix/payable-fallback/Foo1AfterFix.sol | 4 ++-- e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol b/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol index 95d55746..f32e5c55 100644 --- a/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol +++ b/e2e/08-autofix/payable-fallback/Foo1AfterFix.sol @@ -17,7 +17,7 @@ contract Generic { } //// fallback with no name - function() payable {} + function() payable public {} function() payable { uint256 anUintToFillSpace; @@ -46,5 +46,5 @@ contract Generic { fallback() external payable {} function() external payable {} - receive() external virtual payable {} + receive() public virtual payable {} } diff --git a/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol b/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol index 60b2f9c4..eb1cfdaf 100644 --- a/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol +++ b/e2e/08-autofix/payable-fallback/Foo1BeforeFix.sol @@ -46,5 +46,5 @@ contract Generic { fallback() external payable {} function() external payable {} - receive() public virtual payable {} + receive() public virtual payable {} } From ff5e3927e03095806067b053a08a8a4ab5302003 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 10:54:35 -0300 Subject: [PATCH 04/10] test: e2e not workin 1 --- e2e/autofix-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index 1d762fa8..e659b2d9 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -25,7 +25,8 @@ function retrieveParams(subpath) { function compareTextFiles(file1Path, file2Path) { const file1Content = fs.readFileSync(file1Path, 'utf-8') const file2Content = fs.readFileSync(file2Path, 'utf-8') - + console.log('file1Content :>> ', file1Content); + console.log('file2Content :>> ', file2Content); return file1Content === file2Content } From 1230b50aa174b827e02e4b33065df773ee44ff30 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 11:01:28 -0300 Subject: [PATCH 05/10] test: e2e not workin 2 --- e2e/autofix-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index e659b2d9..60965c92 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -271,7 +271,7 @@ describe('e2e', function () { }) }) - describe('autofix rule: payable-fallback', () => { + describe.only('autofix rule: payable-fallback', () => { before(function () { params = retrieveParams('payable-fallback/') currentConfig = `${params.path}${params.subpath}.solhint.json` @@ -286,7 +286,7 @@ describe('e2e', function () { } }) - it('should compare Foo1 file with template BEFORE FIX file and they should match 5', () => { + xit('should compare Foo1 file with template BEFORE FIX file and they should match 5', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) @@ -302,8 +302,8 @@ describe('e2e', function () { const finalLine = '11 problems (0 errors, 11 warnings)' expect(reportLines[reportLines.length - 3]).to.contain(finalLine) - result = compareTextFiles(currentFile, afterFixFile) - expect(result).to.be.true + // result = compareTextFiles(currentFile, afterFixFile) + // expect(result).to.be.true }) }) it('should check FOO1 does not change after test 5', () => { From 725b1d88a97b23cb34b07927608b6a17731bfb1e Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 11:24:11 -0300 Subject: [PATCH 06/10] test: e2e not workin 3 --- e2e/08-autofix/payable-fallback/.solhint.json | 2 +- e2e/autofix-test.js | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/e2e/08-autofix/payable-fallback/.solhint.json b/e2e/08-autofix/payable-fallback/.solhint.json index 3dd72e68..aa02d3b1 100644 --- a/e2e/08-autofix/payable-fallback/.solhint.json +++ b/e2e/08-autofix/payable-fallback/.solhint.json @@ -1,5 +1,5 @@ { "rules": { - "payable-fallback": "warn" + "payable-fallback": "error" } } diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index 60965c92..a6726158 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -25,8 +25,6 @@ function retrieveParams(subpath) { function compareTextFiles(file1Path, file2Path) { const file1Content = fs.readFileSync(file1Path, 'utf-8') const file2Content = fs.readFileSync(file2Path, 'utf-8') - console.log('file1Content :>> ', file1Content); - console.log('file2Content :>> ', file2Content); return file1Content === file2Content } @@ -161,12 +159,12 @@ describe('e2e', function () { } }) - it('should compare Foo1 file with template BEFORE FIX file and they should match 2', () => { + it('should compare Foo1 file with template BEFORE FIX file and they should match (2)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match 2', () => { + it('should compare Foo1 file with template AFTER FIX file and they should match (2)', () => { const { code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) @@ -182,7 +180,7 @@ describe('e2e', function () { }) }) - it('should check FOO1 does not change after test 2', () => { + it('should check FOO1 does not change after test (2)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) @@ -203,12 +201,12 @@ describe('e2e', function () { } }) - it('should compare Foo1 file with template BEFORE FIX file and they should match 3', () => { + it('should compare Foo1 file with template BEFORE FIX file and they should match (3)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match 3', () => { + it('should compare Foo1 file with template AFTER FIX file and they should match (3)', () => { const { code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) @@ -224,7 +222,7 @@ describe('e2e', function () { }) }) - it('should check FOO1 does not change after test 3', () => { + it('should check FOO1 does not change after test (3)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) @@ -245,12 +243,12 @@ describe('e2e', function () { } }) - it('should compare Foo1 file with template BEFORE FIX file and they should match 4', () => { + it('should compare Foo1 file with template BEFORE FIX file and they should match (4)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match 4', () => { + it('should compare Foo1 file with template AFTER FIX file and they should match (4)', () => { const { code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) @@ -265,13 +263,16 @@ describe('e2e', function () { expect(result).to.be.true }) }) - it('should check FOO1 does not change after test 4', () => { + it('should check FOO1 does not change after test (4)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) }) describe.only('autofix rule: payable-fallback', () => { + let code + let stdout + before(function () { params = retrieveParams('payable-fallback/') currentConfig = `${params.path}${params.subpath}.solhint.json` @@ -286,27 +287,32 @@ describe('e2e', function () { } }) - xit('should compare Foo1 file with template BEFORE FIX file and they should match 5', () => { + it('should compare Foo1 file with template BEFORE FIX file and they should match (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match 5', () => { - const { code, stdout } = shell.exec( + it('should execute and exit with code 1 (5)', () => { + ({ code, stdout }) = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) expect(code).to.equal(1) + }) + it('should get the right report (5)', () => { const reportLines = stdout.split('\n') - const finalLine = '11 problems (0 errors, 11 warnings)' + const finalLine = '11 problems (11 errors, 0 warnings)' expect(reportLines[reportLines.length - 3]).to.contain(finalLine) + }) - // result = compareTextFiles(currentFile, afterFixFile) - // expect(result).to.be.true + it('should compare Foo1 file with template AFTER FIX file and they should match (5)', () => { + result = compareTextFiles(currentFile, afterFixFile) + expect(result).to.be.true }) }) - it('should check FOO1 does not change after test 5', () => { + + it('should check FOO1 does not change after test (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) From ade4e98af72c18f6445e51f8104f265d81201774 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 11:38:31 -0300 Subject: [PATCH 07/10] test: e2e not workin 4 --- e2e/autofix-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index a6726158..2ee4790d 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -293,9 +293,9 @@ describe('e2e', function () { }) it('should execute and exit with code 1 (5)', () => { - ({ code, stdout }) = shell.exec( + ({ code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` - ) + )) expect(code).to.equal(1) }) @@ -311,7 +311,7 @@ describe('e2e', function () { expect(result).to.be.true }) }) - + it('should check FOO1 does not change after test (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true From 46eb0dd09b62187ddf17503f991348bf5bd61144 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 11:49:47 -0300 Subject: [PATCH 08/10] test: e2e not workin 5 --- e2e/autofix-test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index 2ee4790d..11d8323e 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -25,6 +25,8 @@ function retrieveParams(subpath) { function compareTextFiles(file1Path, file2Path) { const file1Content = fs.readFileSync(file1Path, 'utf-8') const file2Content = fs.readFileSync(file2Path, 'utf-8') + console.log('file1Content :>> ', file1Content) + console.log('file2Content :>> ', file2Content) return file1Content === file2Content } @@ -287,7 +289,7 @@ describe('e2e', function () { } }) - it('should compare Foo1 file with template BEFORE FIX file and they should match (5)', () => { + xit('should compare Foo1 file with template BEFORE FIX file and they should match (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) @@ -312,7 +314,7 @@ describe('e2e', function () { }) }) - it('should check FOO1 does not change after test (5)', () => { + xit('should check FOO1 does not change after test (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) From c07270793121febd9d11e6829773a1f6a1fdd6e5 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 11:56:20 -0300 Subject: [PATCH 09/10] test: e2e not workin 6 --- e2e/autofix-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index 11d8323e..6b968b48 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -294,11 +294,16 @@ describe('e2e', function () { expect(result).to.be.true }) - it('should execute and exit with code 1 (5)', () => { + it('should execute and compare Foo1 with template AFTER FIX and they should match (5)', () => { ({ code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` )) + result = compareTextFiles(currentFile, afterFixFile) + expect(result).to.be.true + }) + + it('should execute and exit with code 1 (5)', () => { expect(code).to.equal(1) }) @@ -307,11 +312,6 @@ describe('e2e', function () { const finalLine = '11 problems (11 errors, 0 warnings)' expect(reportLines[reportLines.length - 3]).to.contain(finalLine) }) - - it('should compare Foo1 file with template AFTER FIX file and they should match (5)', () => { - result = compareTextFiles(currentFile, afterFixFile) - expect(result).to.be.true - }) }) xit('should check FOO1 does not change after test (5)', () => { From b6c6d73c3ec9f84b7055b386ffefdd7b8e243325 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 20 Dec 2023 12:03:53 -0300 Subject: [PATCH 10/10] test: e2e not workin 7 --- e2e/autofix-test.js | 62 ++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index 6b968b48..b79d9612 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -25,8 +25,6 @@ function retrieveParams(subpath) { function compareTextFiles(file1Path, file2Path) { const file1Content = fs.readFileSync(file1Path, 'utf-8') const file2Content = fs.readFileSync(file2Path, 'utf-8') - console.log('file1Content :>> ', file1Content) - console.log('file2Content :>> ', file2Content) return file1Content === file2Content } @@ -52,6 +50,8 @@ function useFixture(dir) { describe('e2e', function () { let result = false + let code + let stdout describe('autofix tests', () => { if (E2E) { @@ -166,19 +166,23 @@ describe('e2e', function () { expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match (2)', () => { - const { code, stdout } = shell.exec( + it('should execute and compare Foo1 with template AFTER FIX and they should match (2)', () => { + ({ code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` - ) + )) + + result = compareTextFiles(currentFile, afterFixFile) + expect(result).to.be.true + }) + it('should execute and exit with code 1 (2)', () => { expect(code).to.equal(1) + }) + it('should get the right report (2)', () => { const reportLines = stdout.split('\n') const finalLine = '5 problems (5 errors, 0 warnings)' expect(reportLines[reportLines.length - 3]).to.contain(finalLine) - - result = compareTextFiles(currentFile, afterFixFile) - expect(result).to.be.true }) }) @@ -208,19 +212,23 @@ describe('e2e', function () { expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match (3)', () => { - const { code, stdout } = shell.exec( + it('should execute and compare Foo1 with template AFTER FIX and they should match (3)', () => { + ({ code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` - ) + )) + + result = compareTextFiles(currentFile, afterFixFile) + expect(result).to.be.true + }) + it('should execute and exit with code 1 (3)', () => { expect(code).to.equal(1) + }) + it('should get the right report (3)', () => { const reportLines = stdout.split('\n') const finalLine = '9 problems (9 errors, 0 warnings)' expect(reportLines[reportLines.length - 3]).to.contain(finalLine) - - result = compareTextFiles(currentFile, afterFixFile) - expect(result).to.be.true }) }) @@ -250,31 +258,33 @@ describe('e2e', function () { expect(result).to.be.true }) - it('should compare Foo1 file with template AFTER FIX file and they should match (4)', () => { - const { code, stdout } = shell.exec( + it('should execute and compare Foo1 with template AFTER FIX and they should match (4)', () => { + ({ code, stdout } = shell.exec( `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` - ) + )) + result = compareTextFiles(currentFile, afterFixFile) + expect(result).to.be.true + }) + + it('should execute and exit with code 1 (4)', () => { expect(code).to.equal(1) + }) + it('should get the right report (4)', () => { const reportLines = stdout.split('\n') const finalLine = '19 problems (19 errors, 0 warnings)' expect(reportLines[reportLines.length - 3]).to.contain(finalLine) - - result = compareTextFiles(currentFile, afterFixFile) - expect(result).to.be.true }) }) + it('should check FOO1 does not change after test (4)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) }) - describe.only('autofix rule: payable-fallback', () => { - let code - let stdout - + describe('autofix rule: payable-fallback', () => { before(function () { params = retrieveParams('payable-fallback/') currentConfig = `${params.path}${params.subpath}.solhint.json` @@ -289,7 +299,7 @@ describe('e2e', function () { } }) - xit('should compare Foo1 file with template BEFORE FIX file and they should match (5)', () => { + it('should compare Foo1 file with template BEFORE FIX file and they should match (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true }) @@ -314,7 +324,7 @@ describe('e2e', function () { }) }) - xit('should check FOO1 does not change after test (5)', () => { + it('should check FOO1 does not change after test (5)', () => { result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true })