From 62a3bd9d2a858eef28c545ad038cb602083ab28c Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 19 Aug 2020 20:43:46 +0530 Subject: [PATCH] bool for equal and notEqual done --- libs/remix-tests/sol/tests.sol.ts | 11 ++++++-- libs/remix-tests/src/assertionEvents.ts | 4 +++ .../tests/examples_0/assert_equal_test.sol | 8 ++++++ .../tests/examples_0/assert_notEqual_test.sol | 9 +++++++ libs/remix-tests/tests/testRunner.spec.ts | 25 +++++++++++-------- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/libs/remix-tests/sol/tests.sol.ts b/libs/remix-tests/sol/tests.sol.ts index f1c8b47ff3..007d1b1a5a 100644 --- a/libs/remix-tests/sol/tests.sol.ts +++ b/libs/remix-tests/sol/tests.sol.ts @@ -22,6 +22,13 @@ library Assert { int256 expected ); + event AssertionEventBool( + bool passed, + string message, + bool returned, + bool expected + ); + function ok(bool a, string memory message) public returns (bool result) { result = a; emit AssertionEvent(result, message); @@ -39,7 +46,7 @@ library Assert { function equal(bool a, bool b, string memory message) public returns (bool result) { result = (a == b); - emit AssertionEvent(result, message); + emit AssertionEventBool(result, message, a, b); } // TODO: only for certain versions of solc @@ -81,7 +88,7 @@ library Assert { function notEqual(bool a, bool b, string memory message) public returns (bool result) { result = (a != b); - emit AssertionEvent(result, message); + emit AssertionEventBool(result, message, a, b); } // TODO: only for certain versions of solc diff --git a/libs/remix-tests/src/assertionEvents.ts b/libs/remix-tests/src/assertionEvents.ts index 747ec645e3..37beae0048 100644 --- a/libs/remix-tests/src/assertionEvents.ts +++ b/libs/remix-tests/src/assertionEvents.ts @@ -10,6 +10,10 @@ const assertionEvents = [ { name: 'AssertionEventInt', params: ['bool', 'string', 'int256', 'int256'] + }, + { + name: 'AssertionEventBool', + params: ['bool', 'string', 'bool', 'bool'] } ] diff --git a/libs/remix-tests/tests/examples_0/assert_equal_test.sol b/libs/remix-tests/tests/examples_0/assert_equal_test.sol index 04b9a5b56c..d7375e7f54 100644 --- a/libs/remix-tests/tests/examples_0/assert_equal_test.sol +++ b/libs/remix-tests/tests/examples_0/assert_equal_test.sol @@ -17,4 +17,12 @@ contract AssertEqualTest { function equalIntFailTest() public { Assert.equal(-1, 2, "equalIntFailTest fails"); } + + function equalBoolPassTest() public { + Assert.equal(true, true, "equalBoolPassTest passes"); + } + + function equalBoolFailTest() public { + Assert.equal(true, false, "equalBoolFailTest fails"); + } } \ No newline at end of file diff --git a/libs/remix-tests/tests/examples_0/assert_notEqual_test.sol b/libs/remix-tests/tests/examples_0/assert_notEqual_test.sol index 7f0ec7e9a7..c16383739c 100644 --- a/libs/remix-tests/tests/examples_0/assert_notEqual_test.sol +++ b/libs/remix-tests/tests/examples_0/assert_notEqual_test.sol @@ -9,6 +9,7 @@ contract AssertNotEqualTest { function notEqualUintFailTest() public { Assert.notEqual(uint(1), uint(1), "notEqualUintFailTest fails"); } + function notEqualIntPassTest() public { Assert.notEqual(1, -1, "notEqualIntPassTest passes"); } @@ -16,4 +17,12 @@ contract AssertNotEqualTest { function notEqualIntFailTest() public { Assert.notEqual(-2, -2, "notEqualIntFailTest fails"); } + + function notEqualBoolPassTest() public { + Assert.notEqual(true, false, "notEqualBoolPassTest passes"); + } + + function notEqualBoolFailTest() public { + Assert.notEqual(true, true, "notEqualBoolFailTest fails"); + } } diff --git a/libs/remix-tests/tests/testRunner.spec.ts b/libs/remix-tests/tests/testRunner.spec.ts index 74aaa3bc6c..2609dcceb5 100644 --- a/libs/remix-tests/tests/testRunner.spec.ts +++ b/libs/remix-tests/tests/testRunner.spec.ts @@ -76,6 +76,7 @@ async function compileAndDeploy(filename: string, callback: Function) { }) } +// Use `export NODE_OPTIONS="--max-old-space-size=2048"` if there is a JavaScript heap out of memory issue describe('testRunner', () => { let tests: any[] = [], results: ResultsInterface; @@ -142,12 +143,12 @@ describe('testRunner', () => { afterAll(() => { tests = [] }) - it('should have 2 passing test', () => { - assert.equal(results.passingNum, 2) + it('should have 3 passing test', () => { + assert.equal(results.passingNum, 3) }) - it('should have 2 failing test', () => { - assert.equal(results.failureNum, 2) + it('should have 3 failing test', () => { + assert.equal(results.failureNum, 3) }) it('should return', () => { @@ -157,7 +158,9 @@ describe('testRunner', () => { { type: 'testPass', value: 'Equal uint pass test', context: 'AssertEqualTest' }, { type: 'testFailure', value: 'Equal uint fail test', errMsg: 'equalUintFailTest fails', context: 'AssertEqualTest', expected: '2', returned: '1'}, { type: 'testPass', value: 'Equal int pass test', context: 'AssertEqualTest' }, - { type: 'testFailure', value: 'Equal int fail test', errMsg: 'equalIntFailTest fails', context: 'AssertEqualTest', expected: '2', returned: '-1'} + { type: 'testFailure', value: 'Equal int fail test', errMsg: 'equalIntFailTest fails', context: 'AssertEqualTest', expected: '2', returned: '-1'}, + { type: 'testPass', value: 'Equal bool pass test', context: 'AssertEqualTest' }, + { type: 'testFailure', value: 'Equal bool fail test', errMsg: 'equalBoolFailTest fails', context: 'AssertEqualTest', expected: false, returned: true} ], ['time']) }) }) @@ -173,12 +176,12 @@ describe('testRunner', () => { afterAll(() => { tests = [] }) - it('should have 2 passing test', () => { - assert.equal(results.passingNum, 2) + it('should have 3 passing test', () => { + assert.equal(results.passingNum, 3) }) - it('should have 2 failing test', () => { - assert.equal(results.failureNum, 2) + it('should have 3 failing test', () => { + assert.equal(results.failureNum, 3) }) it('should return', () => { @@ -188,7 +191,9 @@ describe('testRunner', () => { { type: 'testPass', value: 'Not equal uint pass test', context: 'AssertNotEqualTest' }, { type: 'testFailure', value: 'Not equal uint fail test', errMsg: 'notEqualUintFailTest fails', context: 'AssertNotEqualTest', expected: '1', returned: '1'}, { type: 'testPass', value: 'Not equal int pass test', context: 'AssertNotEqualTest' }, - { type: 'testFailure', value: 'Not equal int fail test', errMsg: 'notEqualIntFailTest fails', context: 'AssertNotEqualTest', expected: '-2', returned: '-2'} + { type: 'testFailure', value: 'Not equal int fail test', errMsg: 'notEqualIntFailTest fails', context: 'AssertNotEqualTest', expected: '-2', returned: '-2'}, + { type: 'testPass', value: 'Not equal bool pass test', context: 'AssertNotEqualTest' }, + { type: 'testFailure', value: 'Not equal bool fail test', errMsg: 'notEqualBoolFailTest fails', context: 'AssertNotEqualTest', expected: true, returned: true} ], ['time']) }) })