From fc2878827e8133b7d2817a2c5ef58cabbb7f7ab9 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 10 Aug 2023 00:31:59 -0400 Subject: [PATCH] fix tests --- libs/remix-simulator/src/VmProxy.ts | 5 +- libs/remix-tests/src/run.ts | 3 +- libs/remix-tests/tests/testRunner.cli.spec.ts | 168 +++++++++--------- 3 files changed, 88 insertions(+), 88 deletions(-) diff --git a/libs/remix-simulator/src/VmProxy.ts b/libs/remix-simulator/src/VmProxy.ts index 1ad22e075f..f20a741942 100644 --- a/libs/remix-simulator/src/VmProxy.ts +++ b/libs/remix-simulator/src/VmProxy.ts @@ -47,7 +47,7 @@ export class VmProxy { stateCopy: StateManager flagDoNotRecordEVMSteps: boolean lastMemoryUpdate: Array - + constructor (vmContext: VMContext) { this.vmContext = vmContext this.stateCopy @@ -176,6 +176,7 @@ export class VmProxy { const topics = [] if (log[1].length > 0) { for (const k in log[1]) { + // @ts-ignore topics.push('0x' + log[1][k].toString('hex')) } } else { @@ -348,7 +349,7 @@ export class VmProxy { getStorageAt (address: string, position: string, blockNumber: string, cb) { // we don't use the range params here address = toChecksumAddress(address) - + blockNumber = blockNumber === 'latest' ? this.vmContext.latestBlockNumber : blockNumber const block = this.vmContext.blocks[blockNumber] diff --git a/libs/remix-tests/src/run.ts b/libs/remix-tests/src/run.ts index 116da1cb28..83fc6c1dc9 100644 --- a/libs/remix-tests/src/run.ts +++ b/libs/remix-tests/src/run.ts @@ -127,10 +127,9 @@ commander nodeUrl: options.nodeUrl || null, blockNumber: options.blockNumber || null } - const web3 = new Web3() const provider: any = new Provider(providerConfig) await provider.init() - web3.setProvider(provider) + const web3 = new Web3(provider) extend(web3) runTestFiles(path.resolve(file_path), isDirectory, web3, compilerConfig, (error, totalPassing, totalFailing) => { if (error) process.exit(1) diff --git a/libs/remix-tests/tests/testRunner.cli.spec.ts b/libs/remix-tests/tests/testRunner.cli.spec.ts index e3f16f560d..30d7e4cd7d 100644 --- a/libs/remix-tests/tests/testRunner.cli.spec.ts +++ b/libs/remix-tests/tests/testRunner.cli.spec.ts @@ -60,12 +60,12 @@ Commands: it('remix-tests running a test file', function() { const res = spawnSync(executablePath, [resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - console.log(res.stdout.toString()) + // console.log(res.stdout.toString()) // match initial lines expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) // match test result - expect(res.stdout.toString().trim()).to.match(/AssertOkTest/gi) + expect(res.stdout.toString().trim()).to.match(/AssertOkTest/) expect(res.stdout.toString().trim()).to.match(/AssertOkTest okPassTest/) // check if console.log is printed expect(res.stdout.toString().trim()).to.match(/Ok pass test/) expect(res.stdout.toString().trim()).to.match(/AssertOkTest okFailTest/) // check if console.log is printed @@ -79,88 +79,88 @@ Commands: - // it('remix-tests running a test file with custom compiler version', () => { - // const res = spawnSync(executablePath, ['--compiler', '0.7.4', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim()).to.contain('Compiler version set to 0.7.4. Latest version is') - // expect(res.stdout.toString().trim()).to.contain('Loading remote solc version v0.7.4+commit.3f05b770 ...') - // expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) - // expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) - // // match test result - // expect(res.stdout.toString().trim()).to.match(/Ok pass test/) - // expect(res.stdout.toString().trim()).to.match(/Ok fail test/) - // // match fail test details - // expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) - // }) - // - // it('remix-tests running a test file with unavailable custom compiler version (should fail)', () => { - // const res = spawnSync(executablePath, ['--compiler', '1.10.4', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim()).to.contain('No compiler found in releases with version 1.10.4') - // }) - // - // it('remix-tests running a test file with custom EVM', () => { - // const res = spawnSync(executablePath, ['--evm', 'petersburg', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim()).to.contain('EVM set to petersburg') - // expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) - // expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) - // // match test result - // expect(res.stdout.toString().trim()).to.match(/Ok pass test/) - // expect(res.stdout.toString().trim()).to.match(/Ok fail test/) - // // match fail test details - // expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) - // }) - // - // it('remix-tests running a test file by enabling optimization', () => { - // const res = spawnSync(executablePath, ['--optimize', 'true', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim().includes('Optimization is enabled')) - // expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) - // expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) - // // match test result - // expect(res.stdout.toString().trim()).to.match(/Ok pass test/) - // expect(res.stdout.toString().trim()).to.match(/Ok fail test/) - // // match fail test details - // expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) - // }) - // - // it('remix-tests running a test file by enabling optimization and setting runs', () => { - // const res = spawnSync(executablePath, ['--optimize', 'true', '--runs', '300', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim()).to.contain('Optimization is enabled') - // expect(res.stdout.toString().trim()).to.contain('Runs set to 300') - // expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) - // expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) - // // match test result - // expect(res.stdout.toString().trim()).to.match(/Ok pass test/) - // expect(res.stdout.toString().trim()).to.match(/Ok fail test/) - // // match fail test details - // expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) - // }) - // - // it('remix-tests running a test file without enabling optimization and setting runs (should fail)', () => { - // const res = spawnSync(executablePath, ['--runs', '300', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim()).to.contain('Optimization should be enabled for runs') - // }) - // - // it('remix-tests running a test file with all options', () => { - // const res = spawnSync(executablePath, ['--compiler', '0.7.5', '--evm', 'istanbul', '--optimize', 'true', '--runs', '250', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) - // // match initial lines - // expect(res.stdout.toString().trim()).to.contain('Compiler version set to 0.7.5. Latest version is') - // expect(res.stdout.toString().trim()).to.contain('Loading remote solc version v0.7.5+commit.eb77ed08 ...') - // expect(res.stdout.toString().trim()).to.contain('EVM set to istanbul') - // expect(res.stdout.toString().trim()).to.contain('Optimization is enabled') - // expect(res.stdout.toString().trim()).to.contain('Runs set to 250') - // expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) - // expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) - // // match test result - // expect(res.stdout.toString().trim()).to.match(/Ok pass test/) - // expect(res.stdout.toString().trim()).to.match(/Ok fail test/) - // // match fail test details - // expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) - // }) + it('remix-tests running a test file with custom compiler version', () => { + const res = spawnSync(executablePath, ['--compiler', '0.7.4', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim()).to.contain('Compiler version set to 0.7.4. Latest version is') + expect(res.stdout.toString().trim()).to.contain('Loading remote solc version v0.7.4+commit.3f05b770 ...') + expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) + expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) + // match test result + expect(res.stdout.toString().trim()).to.match(/Ok pass test/) + expect(res.stdout.toString().trim()).to.match(/Ok fail test/) + // match fail test details + expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) + }) + + it('remix-tests running a test file with unavailable custom compiler version (should fail)', () => { + const res = spawnSync(executablePath, ['--compiler', '1.10.4', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim()).to.contain('No compiler found in releases with version 1.10.4') + }) + + it('remix-tests running a test file with custom EVM', () => { + const res = spawnSync(executablePath, ['--evm', 'petersburg', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim()).to.contain('EVM set to petersburg') + expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) + expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) + // match test result + expect(res.stdout.toString().trim()).to.match(/Ok pass test/) + expect(res.stdout.toString().trim()).to.match(/Ok fail test/) + // match fail test details + expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) + }) + + it('remix-tests running a test file by enabling optimization', () => { + const res = spawnSync(executablePath, ['--optimize', 'true', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim().includes('Optimization is enabled')) + expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) + expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) + // match test result + expect(res.stdout.toString().trim()).to.match(/Ok pass test/) + expect(res.stdout.toString().trim()).to.match(/Ok fail test/) + // match fail test details + expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) + }) + + it('remix-tests running a test file by enabling optimization and setting runs', () => { + const res = spawnSync(executablePath, ['--optimize', 'true', '--runs', '300', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim()).to.contain('Optimization is enabled') + expect(res.stdout.toString().trim()).to.contain('Runs set to 300') + expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) + expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) + // match test result + expect(res.stdout.toString().trim()).to.match(/Ok pass test/) + expect(res.stdout.toString().trim()).to.match(/Ok fail test/) + // match fail test details + expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) + }) + + it('remix-tests running a test file without enabling optimization and setting runs (should fail)', () => { + const res = spawnSync(executablePath, ['--runs', '300', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim()).to.contain('Optimization should be enabled for runs') + }) + + it('remix-tests running a test file with all options', () => { + const res = spawnSync(executablePath, ['--compiler', '0.7.5', '--evm', 'istanbul', '--optimize', 'true', '--runs', '250', resolve(__dirname + '/examples_0/assert_ok_test.sol')]) + // match initial lines + expect(res.stdout.toString().trim()).to.contain('Compiler version set to 0.7.5. Latest version is') + expect(res.stdout.toString().trim()).to.contain('Loading remote solc version v0.7.5+commit.eb77ed08 ...') + expect(res.stdout.toString().trim()).to.contain('EVM set to istanbul') + expect(res.stdout.toString().trim()).to.contain('Optimization is enabled') + expect(res.stdout.toString().trim()).to.contain('Runs set to 250') + expect(res.stdout.toString().trim()).to.match(/:: Running tests using remix-tests ::/) + expect(res.stdout.toString().trim()).to.match(/creation of library remix_tests.sol:Assert pending.../) + // match test result + expect(res.stdout.toString().trim()).to.match(/Ok pass test/) + expect(res.stdout.toString().trim()).to.match(/Ok fail test/) + // match fail test details + expect(res.stdout.toString().trim()).to.match(/Message: okFailTest fails/) + }) }) })