ok method expectvsreturn handled and tests added for ok and equalUint

pull/370/head
aniket-engg 4 years ago committed by Aniket
parent 35bd3f7408
commit 40ba68559e
  1. 4
      libs/remix-tests/src/testRunner.ts
  2. 20
      libs/remix-tests/tests/examples_0/assert_test.sol
  3. 32
      libs/remix-tests/tests/testRunner.spec.ts

@ -247,6 +247,10 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
if (eIndex >= 0) {
const testEvent = web3.eth.abi.decodeParameters(assertionEvents[eIndex].params, event.raw.data)
if (!testEvent[0]) {
if(eIndex === 0) { // for 'Assert.ok' method
testEvent[2] = 'false'
testEvent[3] = 'true'
}
const resp: TestResultInterface = {
type: 'testFailure',
value: changeCase.sentenceCase(func.name),

@ -0,0 +1,20 @@
import "remix_tests.sol"; // this import is automatically injected by Remix.
contract AssertTest {
function okPassTest() public {
Assert.ok(true, "okPassTest fails");
}
function okFailTest() public {
Assert.ok(false, "okFailTest fails");
}
function equalUintPassTest() public {
Assert.equal(uint(1), uint(1), "equalUintPassTest fails");
}
function equalUintFailTest() public {
Assert.equal(uint(1), uint(2), "equalUintFailTest fails");
}
}

@ -100,6 +100,38 @@ describe('testRunner', () => {
}
describe('#runTest', () => {
describe('assert library methods test', () => {
const filename: string = __dirname + '/examples_0/assert_test.sol'
beforeAll((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) => {
runTest('AssertTest', contracts.AssertTest, compilationData[filename]['AssertTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})
afterAll(() => { tests = [] })
it('should have 2 passing test', () => {
assert.equal(results.passingNum, 2)
})
it('should have 2 failing test', () => {
assert.equal(results.failureNum, 2)
})
it('should return', () => {
deepEqualExcluding(tests, [
{ type: 'accountList', value: accounts },
{ type: 'contract', value: 'AssertTest', filename: __dirname + '/examples_0/assert_test.sol' },
{ type: 'testPass', value: 'Ok pass test', context: 'AssertTest' },
{ type: 'testFailure', value: 'Ok fail test', errMsg: 'okFailTest fails', context: 'AssertTest', expected: 'true', returned: 'false'},
{ type: 'testPass', value: 'Equal uint pass test', context: 'AssertTest' },
{ type: 'testFailure', value: 'Equal uint fail test', errMsg: 'equalUintFailTest fails', context: 'AssertTest', expected: '2', returned: '1'}
], ['time'])
})
})
describe('test with beforeAll', () => {
const filename: string = __dirname + '/examples_1/simple_storage_test.sol'

Loading…
Cancel
Save