diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index f027a6efcd..6b2409edca 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.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), diff --git a/libs/remix-tests/tests/examples_0/assert_test.sol b/libs/remix-tests/tests/examples_0/assert_test.sol new file mode 100644 index 0000000000..ea524055ea --- /dev/null +++ b/libs/remix-tests/tests/examples_0/assert_test.sol @@ -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"); + } +} \ No newline at end of file diff --git a/libs/remix-tests/tests/testRunner.spec.ts b/libs/remix-tests/tests/testRunner.spec.ts index ac588157f5..3157c5f904 100644 --- a/libs/remix-tests/tests/testRunner.spec.ts +++ b/libs/remix-tests/tests/testRunner.spec.ts @@ -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'