From 8399a885583fc4a720c75cdce085355b65f00d96 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 17 Aug 2020 14:30:59 +0530 Subject: [PATCH] assertion event for int params added --- libs/remix-tests/sol/tests.sol.ts | 23 ++++++--- libs/remix-tests/src/assertionEvents.ts | 4 ++ .../tests/examples_0/assert_equal_test.sol | 8 +++ .../examples_0/assert_greaterThan_test.sol | 8 +++ .../examples_0/assert_lesserThan_test.sol | 8 +++ .../tests/examples_0/assert_notEqual_test.sol | 9 +++- libs/remix-tests/tests/testRunner.spec.ts | 49 +++++++++++-------- 7 files changed, 79 insertions(+), 30 deletions(-) diff --git a/libs/remix-tests/sol/tests.sol.ts b/libs/remix-tests/sol/tests.sol.ts index a859e370f1..f1c8b47ff3 100644 --- a/libs/remix-tests/sol/tests.sol.ts +++ b/libs/remix-tests/sol/tests.sol.ts @@ -15,6 +15,13 @@ library Assert { uint256 expected ); + event AssertionEventInt( + bool passed, + string message, + int256 returned, + int256 expected + ); + function ok(bool a, string memory message) public returns (bool result) { result = a; emit AssertionEvent(result, message); @@ -25,9 +32,9 @@ library Assert { emit AssertionEventUint(result, message, a, b); } - function equal(int a, int b, string memory message) public returns (bool result) { + function equal(int256 a, int256 b, string memory message) public returns (bool result) { result = (a == b); - emit AssertionEvent(result, message); + emit AssertionEventInt(result, message, a, b); } function equal(bool a, bool b, string memory message) public returns (bool result) { @@ -67,9 +74,9 @@ library Assert { emit AssertionEventUint(result, message, a, b); } - function notEqual(int a, int b, string memory message) public returns (bool result) { + function notEqual(int256 a, int256 b, string memory message) public returns (bool result) { result = (a != b); - emit AssertionEvent(result, message); + emit AssertionEventInt(result, message, a, b); } function notEqual(bool a, bool b, string memory message) public returns (bool result) { @@ -110,9 +117,9 @@ library Assert { emit AssertionEventUint(result, message, a, b); } - function greaterThan(int a, int b, string memory message) public returns (bool result) { + function greaterThan(int256 a, int256 b, string memory message) public returns (bool result) { result = (a > b); - emit AssertionEvent(result, message); + emit AssertionEventInt(result, message, a, b); } // TODO: safely compare between uint and int function greaterThan(uint a, int b, string memory message) public returns (bool result) { @@ -139,9 +146,9 @@ library Assert { emit AssertionEventUint(result, message, a, b); } - function lesserThan(int a, int b, string memory message) public returns (bool result) { + function lesserThan(int256 a, int256 b, string memory message) public returns (bool result) { result = (a < b); - emit AssertionEvent(result, message); + emit AssertionEventInt(result, message, a, b); } // TODO: safely compare between uint and int function lesserThan(uint a, int b, string memory message) public returns (bool result) { diff --git a/libs/remix-tests/src/assertionEvents.ts b/libs/remix-tests/src/assertionEvents.ts index 2aeedf5499..747ec645e3 100644 --- a/libs/remix-tests/src/assertionEvents.ts +++ b/libs/remix-tests/src/assertionEvents.ts @@ -6,6 +6,10 @@ const assertionEvents = [ { name: 'AssertionEventUint', params: ['bool', 'string', 'uint256', 'uint256'] + }, + { + name: 'AssertionEventInt', + params: ['bool', 'string', 'int256', 'int256'] } ] 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 63fa7cb938..04b9a5b56c 100644 --- a/libs/remix-tests/tests/examples_0/assert_equal_test.sol +++ b/libs/remix-tests/tests/examples_0/assert_equal_test.sol @@ -9,4 +9,12 @@ contract AssertEqualTest { function equalUintFailTest() public { Assert.equal(uint(1), uint(2), "equalUintFailTest fails"); } + + function equalIntPassTest() public { + Assert.equal(-1, -1, "equalIntPassTest passes"); + } + + function equalIntFailTest() public { + Assert.equal(-1, 2, "equalIntFailTest fails"); + } } \ No newline at end of file diff --git a/libs/remix-tests/tests/examples_0/assert_greaterThan_test.sol b/libs/remix-tests/tests/examples_0/assert_greaterThan_test.sol index a19b192339..cdd720a690 100644 --- a/libs/remix-tests/tests/examples_0/assert_greaterThan_test.sol +++ b/libs/remix-tests/tests/examples_0/assert_greaterThan_test.sol @@ -9,4 +9,12 @@ contract AssertGreaterThanTest { function greaterThanUintFailTest() public { Assert.greaterThan(uint(1), uint(4), "greaterThanUintFailTest fails"); } + + function greaterThanIntPassTest() public { + Assert.greaterThan(int(-1), int(-2), "greaterThanIntPassTest passes"); + } + + function greaterThanIntFailTest() public { + Assert.greaterThan(int(-1), int(1), "greaterThanIntFailTest fails"); + } } \ No newline at end of file diff --git a/libs/remix-tests/tests/examples_0/assert_lesserThan_test.sol b/libs/remix-tests/tests/examples_0/assert_lesserThan_test.sol index cf2afc2bcd..035b3ce21e 100644 --- a/libs/remix-tests/tests/examples_0/assert_lesserThan_test.sol +++ b/libs/remix-tests/tests/examples_0/assert_lesserThan_test.sol @@ -9,4 +9,12 @@ contract AssertLesserThanTest { function lesserThanUintFailTest() public { Assert.lesserThan(uint(4), uint(2), "lesserThanUintFailTest fails"); } + + function lesserThanIntPassTest() public { + Assert.lesserThan(int(-1), int(0), "lesserThanIntPassTest passes"); + } + + function lesserThanIntFailTest() public { + Assert.lesserThan(int(1), int(-1), "lesserThanIntFailTest 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 63b4c73b8a..7f0ec7e9a7 100644 --- a/libs/remix-tests/tests/examples_0/assert_notEqual_test.sol +++ b/libs/remix-tests/tests/examples_0/assert_notEqual_test.sol @@ -9,4 +9,11 @@ contract AssertNotEqualTest { function notEqualUintFailTest() public { Assert.notEqual(uint(1), uint(1), "notEqualUintFailTest fails"); } -} \ No newline at end of file + function notEqualIntPassTest() public { + Assert.notEqual(1, -1, "notEqualIntPassTest passes"); + } + + function notEqualIntFailTest() public { + Assert.notEqual(-2, -2, "notEqualIntFailTest fails"); + } +} diff --git a/libs/remix-tests/tests/testRunner.spec.ts b/libs/remix-tests/tests/testRunner.spec.ts index 00eabc5c93..74aaa3bc6c 100644 --- a/libs/remix-tests/tests/testRunner.spec.ts +++ b/libs/remix-tests/tests/testRunner.spec.ts @@ -142,12 +142,12 @@ describe('testRunner', () => { afterAll(() => { tests = [] }) - it('should have 1 passing test', () => { - assert.equal(results.passingNum, 1) + it('should have 2 passing test', () => { + assert.equal(results.passingNum, 2) }) - it('should have 1 failing test', () => { - assert.equal(results.failureNum, 1) + it('should have 2 failing test', () => { + assert.equal(results.failureNum, 2) }) it('should return', () => { @@ -155,7 +155,9 @@ describe('testRunner', () => { { type: 'accountList', value: accounts }, { type: 'contract', value: 'AssertEqualTest', filename: __dirname + '/examples_0/assert_equal_test.sol' }, { 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: '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'} ], ['time']) }) }) @@ -171,12 +173,12 @@ describe('testRunner', () => { afterAll(() => { tests = [] }) - it('should have 1 passing test', () => { - assert.equal(results.passingNum, 1) + it('should have 2 passing test', () => { + assert.equal(results.passingNum, 2) }) - it('should have 1 failing test', () => { - assert.equal(results.failureNum, 1) + it('should have 2 failing test', () => { + assert.equal(results.failureNum, 2) }) it('should return', () => { @@ -184,7 +186,9 @@ describe('testRunner', () => { { type: 'accountList', value: accounts }, { type: 'contract', value: 'AssertNotEqualTest', filename: __dirname + '/examples_0/assert_notEqual_test.sol' }, { 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: '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'} ], ['time']) }) }) @@ -200,20 +204,21 @@ describe('testRunner', () => { afterAll(() => { tests = [] }) - it('should have 1 passing test', () => { - assert.equal(results.passingNum, 1) + it('should have 2 passing test', () => { + assert.equal(results.passingNum, 2) }) - it('should have 1 failing test', () => { - assert.equal(results.failureNum, 1) + it('should have 2 failing test', () => { + assert.equal(results.failureNum, 2) }) - it('should return', () => { deepEqualExcluding(tests, [ { type: 'accountList', value: accounts }, { type: 'contract', value: 'AssertGreaterThanTest', filename: __dirname + '/examples_0/assert_greaterThan_test.sol' }, { type: 'testPass', value: 'Greater than uint pass test', context: 'AssertGreaterThanTest' }, - { type: 'testFailure', value: 'Greater than uint fail test', errMsg: 'greaterThanUintFailTest fails', context: 'AssertGreaterThanTest', expected: '4', returned: '1'} + { type: 'testFailure', value: 'Greater than uint fail test', errMsg: 'greaterThanUintFailTest fails', context: 'AssertGreaterThanTest', expected: '4', returned: '1'}, + { type: 'testPass', value: 'Greater than int pass test', context: 'AssertGreaterThanTest' }, + { type: 'testFailure', value: 'Greater than int fail test', errMsg: 'greaterThanIntFailTest fails', context: 'AssertGreaterThanTest', expected: '1', returned: '-1'} ], ['time']) }) }) @@ -229,12 +234,12 @@ describe('testRunner', () => { afterAll(() => { tests = [] }) - it('should have 1 passing test', () => { - assert.equal(results.passingNum, 1) + it('should have 2 passing test', () => { + assert.equal(results.passingNum, 2) }) - it('should have 1 failing test', () => { - assert.equal(results.failureNum, 1) + it('should have 2 failing test', () => { + assert.equal(results.failureNum, 2) }) it('should return', () => { @@ -242,7 +247,9 @@ describe('testRunner', () => { { type: 'accountList', value: accounts }, { type: 'contract', value: 'AssertLesserThanTest', filename: __dirname + '/examples_0/assert_lesserThan_test.sol' }, { type: 'testPass', value: 'Lesser than uint pass test', context: 'AssertLesserThanTest' }, - { type: 'testFailure', value: 'Lesser than uint fail test', errMsg: 'lesserThanUintFailTest fails', context: 'AssertLesserThanTest', expected: '2', returned: '4'} + { type: 'testFailure', value: 'Lesser than uint fail test', errMsg: 'lesserThanUintFailTest fails', context: 'AssertLesserThanTest', expected: '2', returned: '4'}, + { type: 'testPass', value: 'Lesser than int pass test', context: 'AssertLesserThanTest' }, + { type: 'testFailure', value: 'Lesser than int fail test', errMsg: 'lesserThanIntFailTest fails', context: 'AssertLesserThanTest', expected: '-1', returned: '1'} ], ['time']) }) })