restore spec test

pull/3233/head
filip mertens 2 years ago
parent 89b7bf2a9d
commit 9157ec6014
  1. 118
      libs/remix-tests/tests/testRunner.spec.ts

@ -8,6 +8,8 @@ import { deployAll } from '../src/deployer'
import { runTest, compilationInterface } from '../src/index' import { runTest, compilationInterface } from '../src/index'
import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../src/index' import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../src/index'
// deepEqualExcluding allows us to exclude specific keys whose values vary. // deepEqualExcluding allows us to exclude specific keys whose values vary.
// In this specific test, we'll use this helper to exclude `time` keys. // In this specific test, we'll use this helper to exclude `time` keys.
// Assertions for the existance of these will be made at the correct places. // Assertions for the existance of these will be made at the correct places.
@ -48,7 +50,7 @@ async function compileAndDeploy(filename: string, callback: any) {
await provider.init() await provider.init()
web3.setProvider(provider) web3.setProvider(provider)
extend(web3) extend(web3)
let compilationData: object let compilationData: any
async.waterfall([ async.waterfall([
function getAccountList(next: any): void { function getAccountList(next: any): void {
web3.eth.getAccounts((_err: Error | null | undefined, _accounts: string[]) => { web3.eth.getAccounts((_err: Error | null | undefined, _accounts: string[]) => {
@ -78,9 +80,7 @@ async function compileAndDeploy(filename: string, callback: any) {
}) })
} }
// Use `export NODE_OPTIONS="--max-old-space-size=4096"` if there is a JavaScript heap out of memory issue describe('testRunner', function () {
describe('testRunner', () => {
let tests: any[] = [], results: ResultsInterface; let tests: any[] = [], results: ResultsInterface;
const testCallback: TestCbInterface = (err, test) => { const testCallback: TestCbInterface = (err, test) => {
@ -102,18 +102,18 @@ describe('testRunner', () => {
} }
} }
describe('#runTest', () => { describe('#runTest', function () {
this.timeout(10000)
describe('assert library OK method tests', () => { describe('assert library OK method tests', () => {
const filename: string = __dirname + '/examples_0/assert_ok_test.sol' const filename: string = __dirname + '/examples_0/assert_ok_test.sol'
beforeAll((done) => { before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) => { compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) => {
runTest('AssertOkTest', contracts.AssertOkTest, compilationData[filename]['AssertOkTest'], asts[filename], { accounts, web3 }, testCallback, resultsCallback(done)) runTest('AssertOkTest', contracts.AssertOkTest, compilationData[filename]['AssertOkTest'], asts[filename], { accounts, web3 }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 1 passing test', () => { it('should have 1 passing test', () => {
assert.equal(results.passingNum, 1) assert.equal(results.passingNum, 1)
@ -136,16 +136,16 @@ describe('testRunner', () => {
}) })
}) })
describe('assert library EQUAL method tests', () => { describe('assert library EQUAL method tests', function () {
const filename: string = __dirname + '/examples_0/assert_equal_test.sol' const filename: string = __dirname + '/examples_0/assert_equal_test.sol'
beforeAll((done) => { before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) => { compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) => {
runTest('AssertEqualTest', contracts.AssertEqualTest, compilationData[filename]['AssertEqualTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('AssertEqualTest', contracts.AssertEqualTest, compilationData[filename]['AssertEqualTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 6 passing test', () => { it('should have 6 passing test', () => {
assert.equal(results.passingNum, 6) assert.equal(results.passingNum, 6)
@ -175,16 +175,18 @@ describe('testRunner', () => {
}) })
}) })
describe('assert library NOTEQUAL method tests', () => {
describe('assert library NOTEQUAL method tests', function () {
const filename: string = __dirname + '/examples_0/assert_notEqual_test.sol' const filename: string = __dirname + '/examples_0/assert_notEqual_test.sol'
beforeAll((done) => { before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) => { compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) => {
runTest('AssertNotEqualTest', contracts.AssertNotEqualTest, compilationData[filename]['AssertNotEqualTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('AssertNotEqualTest', contracts.AssertNotEqualTest, compilationData[filename]['AssertNotEqualTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 6 passing test', () => { it('should have 6 passing test', () => {
assert.equal(results.passingNum, 6) assert.equal(results.passingNum, 6)
@ -205,7 +207,6 @@ describe('testRunner', () => {
{ type: 'testPass', debugTxHash: '0x12bc9eb3a653ebe4c7ab954c144dab4848295c88d71d17cb86a41e8a004419ba', value: 'Not equal bool pass test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', context: 'AssertNotEqualTest' }, { type: 'testPass', debugTxHash: '0x12bc9eb3a653ebe4c7ab954c144dab4848295c88d71d17cb86a41e8a004419ba', value: 'Not equal bool pass test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', context: 'AssertNotEqualTest' },
{ type: 'testFailure', debugTxHash: '0x901b9cd631f8f29841243a257d1914060b9c36d88ee7d8b624de76dad4a34c85', value: 'Not equal bool fail test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', errMsg: 'notEqualBoolFailTest fails', context: 'AssertNotEqualTest', assertMethod: 'notEqual', location: '760:57:0', expected: true, returned: true }, { type: 'testFailure', debugTxHash: '0x901b9cd631f8f29841243a257d1914060b9c36d88ee7d8b624de76dad4a34c85', value: 'Not equal bool fail test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', errMsg: 'notEqualBoolFailTest fails', context: 'AssertNotEqualTest', assertMethod: 'notEqual', location: '760:57:0', expected: true, returned: true },
{ type: 'testPass', debugTxHash: '0xf9e48bac26d3a2871ceb92974b897cae61e60bbc4db115b7e8eff4ac0390e4a5', value: 'Not equal address pass test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', context: 'AssertNotEqualTest' }, { type: 'testPass', debugTxHash: '0xf9e48bac26d3a2871ceb92974b897cae61e60bbc4db115b7e8eff4ac0390e4a5', value: 'Not equal address pass test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', context: 'AssertNotEqualTest' },
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
{ type: 'testFailure', debugTxHash: '0x4e83a17426bc79b147ddd30a5434a2430a8302b3ce78b6979088ac5eceac5d3c', value: 'Not equal address fail test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', errMsg: 'notEqualAddressFailTest fails', context: 'AssertNotEqualTest', assertMethod: 'notEqual', location: '1084:136:0', expected: 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9, returned: 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9 }, { type: 'testFailure', debugTxHash: '0x4e83a17426bc79b147ddd30a5434a2430a8302b3ce78b6979088ac5eceac5d3c', value: 'Not equal address fail test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', errMsg: 'notEqualAddressFailTest fails', context: 'AssertNotEqualTest', assertMethod: 'notEqual', location: '1084:136:0', expected: 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9, returned: 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9 },
{ type: 'testPass', debugTxHash: '0xfb4b30bb8373eeb6b09e38ad07880b86654f72780b41d7cf7554a112a04a0f53', value: 'Not equal bytes32 pass test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', context: 'AssertNotEqualTest' }, { type: 'testPass', debugTxHash: '0xfb4b30bb8373eeb6b09e38ad07880b86654f72780b41d7cf7554a112a04a0f53', value: 'Not equal bytes32 pass test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', context: 'AssertNotEqualTest' },
{ type: 'testFailure', debugTxHash: '0x43edf8bc68229415ee63f63f5303351a0dfecf9f3eb2ec35ffd2c10c60cf7005', value: 'Not equal bytes32 fail test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', errMsg: 'notEqualBytes32FailTest fails', context: 'AssertNotEqualTest', assertMethod: 'notEqual', location: '1756:54:0', expected: '0x72656d6978000000000000000000000000000000000000000000000000000000', returned: '0x72656d6978000000000000000000000000000000000000000000000000000000' }, { type: 'testFailure', debugTxHash: '0x43edf8bc68229415ee63f63f5303351a0dfecf9f3eb2ec35ffd2c10c60cf7005', value: 'Not equal bytes32 fail test', filename: __dirname + '/examples_0/assert_notEqual_test.sol', errMsg: 'notEqualBytes32FailTest fails', context: 'AssertNotEqualTest', assertMethod: 'notEqual', location: '1756:54:0', expected: '0x72656d6978000000000000000000000000000000000000000000000000000000', returned: '0x72656d6978000000000000000000000000000000000000000000000000000000' },
@ -215,16 +216,16 @@ describe('testRunner', () => {
}) })
}) })
describe('assert library GREATERTHAN method tests', () => { describe('assert library GREATERTHAN method tests', function () {
const filename: string = __dirname + '/examples_0/assert_greaterThan_test.sol' const filename: string = __dirname + '/examples_0/assert_greaterThan_test.sol'
beforeAll((done) => { before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) => { compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) => {
runTest('AssertGreaterThanTest', contracts.AssertGreaterThanTest, compilationData[filename]['AssertGreaterThanTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('AssertGreaterThanTest', contracts.AssertGreaterThanTest, compilationData[filename]['AssertGreaterThanTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 4 passing test', () => { it('should have 4 passing test', () => {
assert.equal(results.passingNum, 4) assert.equal(results.passingNum, 4)
@ -249,16 +250,16 @@ describe('testRunner', () => {
}) })
}) })
describe('assert library LESSERTHAN method tests', () => { describe('assert library LESSERTHAN method tests', function () {
const filename: string = __dirname + '/examples_0/assert_lesserThan_test.sol' const filename: string = __dirname + '/examples_0/assert_lesserThan_test.sol'
beforeAll((done) => { before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) => { compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) => {
runTest('AssertLesserThanTest', contracts.AssertLesserThanTest, compilationData[filename]['AssertLesserThanTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('AssertLesserThanTest', contracts.AssertLesserThanTest, compilationData[filename]['AssertLesserThanTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 4 passing test', () => { it('should have 4 passing test', () => {
assert.equal(results.passingNum, 4) assert.equal(results.passingNum, 4)
@ -284,16 +285,16 @@ describe('testRunner', () => {
}) })
}) })
describe('test with beforeAll', () => { describe('test with before', function () {
const filename: string = __dirname + '/examples_1/simple_storage_test.sol' const filename: string = __dirname + '/examples_1/simple_storage_test.sol'
beforeAll((done) => { before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) => { compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) => {
runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 3 passing test', () => { it('should have 3 passing test', () => {
assert.equal(results.passingNum, 3) assert.equal(results.passingNum, 3)
@ -315,16 +316,16 @@ describe('testRunner', () => {
}) })
}) })
describe('test with beforeEach', () => { describe('test with beforeEach', function () {
const filename: string = __dirname + '/examples_2/simple_storage_test.sol' const filename: string = __dirname + '/examples_2/simple_storage_test.sol'
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 2 passing tests', () => { it('should have 2 passing tests', () => {
assert.equal(results.passingNum, 2) assert.equal(results.passingNum, 2)
@ -345,16 +346,16 @@ describe('testRunner', () => {
}) })
// Test string equality // Test string equality
describe('test string equality', () => { describe('test string equality', function () {
const filename: string = __dirname + '/examples_3/simple_string_test.sol' const filename: string = __dirname + '/examples_3/simple_string_test.sol'
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should 2 passing tests', () => { it('should 2 passing tests', () => {
assert.equal(results.passingNum, 2) assert.equal(results.passingNum, 2)
@ -371,16 +372,16 @@ describe('testRunner', () => {
}) })
// Test multiple directory import in test contract // Test multiple directory import in test contract
describe('test multiple directory import in test contract', () => { describe('test multiple directory import in test contract', function () {
const filename: string = __dirname + '/examples_5/test/simple_storage_test.sol' const filename: string = __dirname + '/examples_5/test/simple_storage_test.sol'
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('StorageResolveTest', contracts.StorageResolveTest, compilationData[filename]['StorageResolveTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('StorageResolveTest', contracts.StorageResolveTest, compilationData[filename]['StorageResolveTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should 3 passing tests', () => { it('should 3 passing tests', () => {
assert.equal(results.passingNum, 3) assert.equal(results.passingNum, 3)
@ -398,16 +399,16 @@ describe('testRunner', () => {
}) })
//Test SafeMath library methods //Test SafeMath library methods
describe('test SafeMath library', () => { describe('test SafeMath library', function () {
const filename: string = __dirname + '/examples_4/SafeMath_test.sol' const filename: string = __dirname + '/examples_4/SafeMath_test.sol'
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('SafeMathTest', contracts.SafeMathTest, compilationData[filename]['SafeMathTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('SafeMathTest', contracts.SafeMathTest, compilationData[filename]['SafeMathTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 10 passing tests', () => { it('should have 10 passing tests', () => {
assert.equal(results.passingNum, 10) assert.equal(results.passingNum, 10)
@ -418,16 +419,16 @@ describe('testRunner', () => {
}) })
//Test signed/unsigned integer weight //Test signed/unsigned integer weight
describe('test number weight', () => { describe('test number weight', function () {
const filename: string = __dirname + '/number/number_test.sol' const filename: string = __dirname + '/number/number_test.sol'
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 6 passing tests', () => { it('should have 6 passing tests', () => {
assert.equal(results.passingNum, 6) assert.equal(results.passingNum, 6)
@ -438,16 +439,16 @@ describe('testRunner', () => {
}) })
// Test Transaction with custom sender & value // Test Transaction with custom sender & value
describe('various sender', () => { describe('various sender', function () {
const filename: string = __dirname + '/various_sender/sender_and_value_test.sol' const filename: string = __dirname + '/various_sender/sender_and_value_test.sol'
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('SenderAndValueTest', contracts.SenderAndValueTest, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) runTest('SenderAndValueTest', contracts.SenderAndValueTest, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
}) })
}) })
afterAll(() => { tests = [] }) after(() => { tests = [] })
it('should have 17 passing tests', () => { it('should have 17 passing tests', () => {
assert.equal(results.passingNum, 17) assert.equal(results.passingNum, 17)
@ -458,9 +459,9 @@ describe('testRunner', () => {
}) })
// Test `runTest` method without sending contract object (should throw error) // Test `runTest` method without sending contract object (should throw error)
describe('runTest method without contract json interface', () => { describe('runTest method without contract json interface', function () {
const filename: string = __dirname + '/various_sender/sender_and_value_test.sol' const filename: string = __dirname + '/various_sender/sender_and_value_test.sol'
const errorCallback = (done) => { const errorCallback: any = (done) => {
return (err, _results) => { return (err, _results) => {
if (err && err.message.includes('Contract interface not available')) { if (err && err.message.includes('Contract interface not available')) {
results = _results results = _results
@ -469,8 +470,8 @@ describe('testRunner', () => {
else throw err else throw err
} }
} }
beforeAll(done => { before(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[], web3: any) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: any, contracts: any, asts: any, accounts: string[], web3: any) {
runTest('SenderAndValueTest', undefined, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, errorCallback(done)) runTest('SenderAndValueTest', undefined, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, errorCallback(done))
}) })
}) })
@ -482,5 +483,6 @@ describe('testRunner', () => {
assert.equal(results.failureNum, 0) assert.equal(results.failureNum, 0)
}) })
}) })
}) })
}) })
Loading…
Cancel
Save