string for equal and notEqual

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent fe4db19070
commit f5ee22e0a3
  1. 11
      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_notEqual_test.sol
  5. 24
      libs/remix-tests/tests/testRunner.spec.ts

@ -43,6 +43,13 @@ library Assert {
bytes32 expected
);
event AssertionEventString(
bool passed,
string message,
string returned,
string expected
);
function ok(bool a, string memory message) public returns (bool result) {
result = a;
emit AssertionEvent(result, message);
@ -87,7 +94,7 @@ library Assert {
function equal(string memory a, string memory b, string memory message) public returns (bool result) {
result = (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)));
emit AssertionEvent(result, message);
emit AssertionEventString(result, message, a, b);
}
function notEqual(uint256 a, uint256 b, string memory message) public returns (bool result) {
@ -129,7 +136,7 @@ library Assert {
function notEqual(string memory a, string memory b, string memory message) public returns (bool result) {
result = (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b)));
emit AssertionEvent(result, message);
emit AssertionEventString(result, message, a, b);
}
/*----------------- Greater than --------------------*/

@ -22,6 +22,10 @@ const assertionEvents = [
{
name: 'AssertionEventBytes32',
params: ['bool', 'string', 'bytes32', 'bytes32']
},
{
name: 'AssertionEventString',
params: ['bool', 'string', 'string', 'string']
}
]

@ -45,4 +45,12 @@ contract AssertEqualTest {
bytes32 r = 0x72656d6979000000000000000000000000000000000000000000000000000000;
Assert.equal(r, e, "equalBytes32FailTest fails");
}
function equalStringPassTest() public {
Assert.equal(string("remix"), string("remix"), "equalStringPassTest passes");
}
function equalStringFailTest() public {
Assert.equal(string("remix"), string("remix-tests"), "equalStringFailTest fails");
}
}

@ -45,4 +45,12 @@ contract AssertNotEqualTest {
bytes32 r = 0x72656d6978000000000000000000000000000000000000000000000000000000;
Assert.notEqual(r, e, "notEqualBytes32FailTest fails");
}
function notEqualStringPassTest() public {
Assert.notEqual(string("remix"), string("remix-tests"), "notEqualStringPassTest passes");
}
function notEqualStringFailTest() public {
Assert.notEqual(string("remix"), string("remix"), "notEqualStringFailTest fails");
}
}

@ -143,12 +143,12 @@ describe('testRunner', () => {
afterAll(() => { tests = [] })
it('should have 5 passing test', () => {
assert.equal(results.passingNum, 5)
it('should have 6 passing test', () => {
assert.equal(results.passingNum, 6)
})
it('should have 5 failing test', () => {
assert.equal(results.failureNum, 5)
it('should have 6 failing test', () => {
assert.equal(results.failureNum, 6)
})
it('should return', () => {
@ -164,7 +164,9 @@ describe('testRunner', () => {
{ type: 'testPass', value: 'Equal address pass test', context: 'AssertEqualTest' },
{ type: 'testFailure', value: 'Equal address fail test', errMsg: 'equalAddressFailTest fails', context: 'AssertEqualTest', expected: '0x1c6637567229159d1eFD45f95A6675e77727E013', returned: '0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9'},
{ type: 'testPass', value: 'Equal bytes32 pass test', context: 'AssertEqualTest' },
{ type: 'testFailure', value: 'Equal bytes32 fail test', errMsg: 'equalBytes32FailTest fails', context: 'AssertEqualTest', expected: '0x72656d6978000000000000000000000000000000000000000000000000000000', returned: '0x72656d6979000000000000000000000000000000000000000000000000000000'}
{ type: 'testFailure', value: 'Equal bytes32 fail test', errMsg: 'equalBytes32FailTest fails', context: 'AssertEqualTest', expected: '0x72656d6978000000000000000000000000000000000000000000000000000000', returned: '0x72656d6979000000000000000000000000000000000000000000000000000000'},
{ type: 'testPass', value: 'Equal string pass test', context: 'AssertEqualTest' },
{ type: 'testFailure', value: 'Equal string fail test', errMsg: 'equalStringFailTest fails', context: 'AssertEqualTest', expected: 'remix-tests', returned: 'remix'}
], ['time'])
})
})
@ -180,12 +182,12 @@ describe('testRunner', () => {
afterAll(() => { tests = [] })
it('should have 5 passing test', () => {
assert.equal(results.passingNum, 5)
it('should have 6 passing test', () => {
assert.equal(results.passingNum, 6)
})
it('should have 5 failing test', () => {
assert.equal(results.failureNum, 5)
it('should have 6 failing test', () => {
assert.equal(results.failureNum, 6)
})
it('should return', () => {
@ -201,7 +203,9 @@ describe('testRunner', () => {
{ type: 'testPass', value: 'Not equal address pass test', context: 'AssertNotEqualTest' },
{ type: 'testFailure', value: 'Not equal address fail test', errMsg: 'notEqualAddressFailTest fails', context: 'AssertNotEqualTest', expected: 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9, returned: 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9},
{ type: 'testPass', value: 'Not equal bytes32 pass test', context: 'AssertNotEqualTest' },
{ type: 'testFailure', value: 'Not equal bytes32 fail test', errMsg: 'notEqualBytes32FailTest fails', context: 'AssertNotEqualTest', expected: '0x72656d6978000000000000000000000000000000000000000000000000000000', returned: '0x72656d6978000000000000000000000000000000000000000000000000000000'}
{ type: 'testFailure', value: 'Not equal bytes32 fail test', errMsg: 'notEqualBytes32FailTest fails', context: 'AssertNotEqualTest', expected: '0x72656d6978000000000000000000000000000000000000000000000000000000', returned: '0x72656d6978000000000000000000000000000000000000000000000000000000'},
{ type: 'testPass', value: 'Not equal string pass test', context: 'AssertNotEqualTest' },
{ type: 'testFailure', value: 'Not equal string fail test', errMsg: 'notEqualStringFailTest fails', context: 'AssertNotEqualTest', expected: 'remix', returned: 'remix'},
], ['time'])
})
})

Loading…
Cancel
Save