pull/3951/head
Oleksii Kosynskyi 2 years ago
parent 2858e526a6
commit fc2878827e
No known key found for this signature in database
GPG Key ID: B4A8D3CCE22EA65E
  1. 5
      libs/remix-simulator/src/VmProxy.ts
  2. 3
      libs/remix-tests/src/run.ts
  3. 168
      libs/remix-tests/tests/testRunner.cli.spec.ts

@ -47,7 +47,7 @@ export class VmProxy {
stateCopy: StateManager
flagDoNotRecordEVMSteps: boolean
lastMemoryUpdate: Array<string>
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]

@ -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)

@ -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/)
})
})
})

Loading…
Cancel
Save