assertion event for int params added

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent 41b07ed602
commit 8399a88558
  1. 23
      libs/remix-tests/sol/tests.sol.ts
  2. 4
      libs/remix-tests/src/assertionEvents.ts
  3. 8
      libs/remix-tests/tests/examples_0/assert_equal_test.sol
  4. 8
      libs/remix-tests/tests/examples_0/assert_greaterThan_test.sol
  5. 8
      libs/remix-tests/tests/examples_0/assert_lesserThan_test.sol
  6. 7
      libs/remix-tests/tests/examples_0/assert_notEqual_test.sol
  7. 49
      libs/remix-tests/tests/testRunner.spec.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) {

@ -6,6 +6,10 @@ const assertionEvents = [
{
name: 'AssertionEventUint',
params: ['bool', 'string', 'uint256', 'uint256']
},
{
name: 'AssertionEventInt',
params: ['bool', 'string', 'int256', 'int256']
}
]

@ -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");
}
}

@ -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");
}
}

@ -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");
}
}

@ -9,4 +9,11 @@ contract AssertNotEqualTest {
function notEqualUintFailTest() public {
Assert.notEqual(uint(1), uint(1), "notEqualUintFailTest fails");
}
function notEqualIntPassTest() public {
Assert.notEqual(1, -1, "notEqualIntPassTest passes");
}
function notEqualIntFailTest() public {
Assert.notEqual(-2, -2, "notEqualIntFailTest fails");
}
}

@ -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'])
})
})

Loading…
Cancel
Save