passing all tests

pull/7/head
Sab94 6 years ago
parent dcf8b12417
commit 7f80f9a6aa
  1. 225
      remix-tests/tests/testRunner.ts

@ -7,78 +7,78 @@ let Compiler = require('../src/compiler.js')
let Deployer = require('../src/deployer.js') let Deployer = require('../src/deployer.js')
import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js' import runTest, { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/testRunner.js'
function compileAndDeploy (filename: string, callback: Function) { function compileAndDeploy(filename: string, callback: Function) {
let web3: Web3 = new Web3() let web3: Web3 = new Web3()
web3.setProvider(new Provider()) web3.setProvider(new Provider())
let compilationData: object let compilationData: object
let accounts: object let accounts: object
async.waterfall([ async.waterfall([
function getAccountList(next: Function): void { function getAccountList(next: Function): void {
web3.eth.getAccounts((_err: Error | null | undefined, _accounts: object) => { web3.eth.getAccounts((_err: Error | null | undefined, _accounts: object) => {
accounts = _accounts accounts = _accounts
next(_err) next(_err)
}) })
}, },
function compile(next: Function) { function compile(next: Function) {
Compiler.compileFileOrFiles(filename, false, {accounts}, next) Compiler.compileFileOrFiles(filename, false, { accounts }, next)
}, },
function deployAllContracts(compilationResult: object, next: Function): void { function deployAllContracts(compilationResult: object, next: Function): void {
try { try {
compilationData = compilationResult compilationData = compilationResult
Deployer.deployAll(compilationResult, web3, next) Deployer.deployAll(compilationResult, web3, next)
} catch(e) { } catch (e) {
throw e throw e
}
} }
], function(_err: Error | null | undefined, contracts: any): void { }
callback(null, compilationData, contracts, accounts) ], function (_err: Error | null | undefined, contracts: any): void {
}) callback(null, compilationData, contracts, accounts)
} })
}
describe('testRunner', () => {
describe('#runTest', () => {
describe('test with beforeAll', () => {
let filename = 'tests/examples_1/simple_storage_test.sol'
let tests:any[] = [], results:ResultsInterface;
before((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) => {
var testCallback: TestCbInterface = (err, test) => {
if (err) { throw err }
tests.push(test)
}
var resultsCallback: ResultCbInterface = (err, _results) => {
if (err) { throw err }
results = _results
done()
}
runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback)
})
})
it('should 1 passing test', function () {
assert.equal(results.passingNum, 2)
})
it('should 1 failing test', function () { describe('testRunner', () => {
assert.equal(results.failureNum, 2) describe('#runTest', () => {
}) describe('test with beforeAll', () => {
let filename = 'tests/examples_1/simple_storage_test.sol'
let tests: any[] = [], results: ResultsInterface;
it('should returns 5 messages', function () { before((done) => {
assert.deepEqual(tests, [ compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) => {
{ type: 'contract', value: 'MyTest', filename: 'tests/examples_1/simple_storage_test.sol' }, var testCallback: TestCbInterface = (err, test) => {
{ type: 'testFailure', value: 'Should trigger one fail', time: 1, context: 'MyTest', errMsg: 'the test 1 fails' }, if (err) { throw err }
{ type: 'testPass', value: 'Should trigger one pass', time: 1, context: 'MyTest'}, tests.push(test)
{ type: 'testPass', value: 'Initial value should be100', time: 1, context: 'MyTest' }, }
{ type: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' } var resultsCallback: ResultCbInterface = (err, _results) => {
]) if (err) { throw err }
results = _results
done()
}
runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback)
}) })
}) })
describe('test with beforeEach', function () { it('should 1 passing test', function () {
assert.equal(results.passingNum, 2)
})
it('should 1 failing test', function () {
assert.equal(results.failureNum, 2)
})
it('should returns 5 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'MyTest', filename: 'tests/examples_1/simple_storage_test.sol' },
{ type: 'testFailure', value: 'Should trigger one fail', time: 1, context: 'MyTest', errMsg: 'the test 1 fails' },
{ type: 'testPass', value: 'Should trigger one pass', time: 1, context: 'MyTest' },
{ type: 'testPass', value: 'Initial value should be100', time: 1, context: 'MyTest' },
{ type: 'testFailure', value: 'Initial value should be200', time: 1, context: 'MyTest', errMsg: 'function returned false' }
])
})
})
describe('test with beforeEach', function () {
let filename = 'tests/examples_2/simple_storage_test.sol' let filename = 'tests/examples_2/simple_storage_test.sol'
let tests:any[] = [], results:ResultsInterface; let tests: any[] = [], results: ResultsInterface;
before(function (done) { before(function (done) {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, accounts: object) {
@ -111,5 +111,102 @@ function compileAndDeploy (filename: string, callback: Function) {
]) ])
}) })
}) })
// Test string equality
describe('test string equality', function () {
let filename = 'tests/examples_3/simple_string_test.sol'
let tests: any[] = [], results: ResultsInterface;
before(function (done) {
compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) {
var testCallback: TestCbInterface = (err, test) => {
if (err) { throw err }
tests.push(test)
}
var resultsCallback: ResultCbInterface = (err, _results) => {
if (err) { throw err }
results = _results
done()
}
runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], { accounts }, testCallback, resultsCallback)
runTest('StringTest2', contracts.StringTest2, compilationData[filename]['StringTest2'], { accounts }, testCallback, resultsCallback)
})
})
it('should 2 passing tests', function () {
assert.equal(results.passingNum, 2)
})
it('should 1 failing tests', function () {
assert.equal(results.failureNum, 1)
})
it('should returns 3 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'StringTest', filename: 'tests/examples_3/simple_string_test.sol' },
{ type: 'testFailure', value: 'Value should be hello world', time: 1, context: 'StringTest', "errMsg": "initial value is not correct" },
{ type: 'testPass', value: 'Value should not be hello wordl', time: 1, context: 'StringTest' },
{ type: 'testPass', value: 'Initial value should be hello', time: 1, context: 'StringTest' },
])
})
})
//Test signed/unsigned integer weight
describe('test number weight', function () {
let filename = 'tests/number/number_test.sol'
let tests: any[] = [], results: ResultsInterface;
before(function (done) {
compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) {
var testCallback: TestCbInterface = (err, test) => {
if (err) { throw err }
tests.push(test)
}
var resultsCallback: ResultCbInterface = (err, _results) => {
if (err) { throw err }
results = _results
done()
}
runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], { accounts }, testCallback, resultsCallback)
})
})
it('should have 6 passing tests', function () {
assert.equal(results.passingNum, 6)
})
it('should have 2 failing tests', function () {
assert.equal(results.failureNum, 2)
})
})
// Test Transaction with different sender
describe('various sender', function () {
let filename = 'tests/various_sender/sender_test.sol'
let tests: any[] = [], results: ResultsInterface;
before(function (done) {
compileAndDeploy(filename, function (_err, compilationData, contracts, accounts) {
var testCallback: TestCbInterface = (err, test) => {
if (err) { throw err }
tests.push(test)
}
var resultsCallback: ResultCbInterface = (err, _results) => {
if (err) { throw err }
results = _results
done()
}
runTest('SenderTest', contracts.SenderTest, compilationData[filename]['SenderTest'], { accounts }, testCallback, resultsCallback)
})
})
it('should have 4 passing tests', function () {
assert.equal(results.passingNum, 4)
})
it('should have 1 failing tests', function () {
assert.equal(results.failureNum, 0)
})
}) })
}) })
})

Loading…
Cancel
Save