bytes32 for equal and notEqual

pull/5370/head
aniket-engg 5 years ago committed by Aniket
parent 78adf3d47d
commit fe4db19070
  1. 11
      libs/remix-tests/sol/tests.sol.ts
  2. 4
      libs/remix-tests/src/assertionEvents.ts
  3. 12
      libs/remix-tests/tests/examples_0/assert_equal_test.sol
  4. 12
      libs/remix-tests/tests/examples_0/assert_notEqual_test.sol
  5. 24
      libs/remix-tests/tests/testRunner.spec.ts

@ -36,6 +36,13 @@ library Assert {
address expected
);
event AssertionEventBytes32(
bool passed,
string message,
bytes32 returned,
bytes32 expected
);
function ok(bool a, string memory message) public returns (bool result) {
result = a;
emit AssertionEvent(result, message);
@ -75,7 +82,7 @@ library Assert {
function equal(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEvent(result, message);
emit AssertionEventBytes32(result, message, a, b);
}
function equal(string memory a, string memory b, string memory message) public returns (bool result) {
@ -117,7 +124,7 @@ library Assert {
function notEqual(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEvent(result, message);
emit AssertionEventBytes32(result, message, a, b);
}
function notEqual(string memory a, string memory b, string memory message) public returns (bool result) {

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

@ -33,4 +33,16 @@ contract AssertEqualTest {
function equalAddressFailTest() public {
Assert.equal(0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9, 0x1c6637567229159d1eFD45f95A6675e77727E013, "equalAddressFailTest fails");
}
function equalBytes32PassTest() public {
bytes32 e = 0x72656d6978000000000000000000000000000000000000000000000000000000;
bytes32 r = 0x72656d6978000000000000000000000000000000000000000000000000000000;
Assert.equal(r, e, "equalBytes32PassTest passes");
}
function equalBytes32FailTest() public {
bytes32 e = 0x72656d6978000000000000000000000000000000000000000000000000000000;
bytes32 r = 0x72656d6979000000000000000000000000000000000000000000000000000000;
Assert.equal(r, e, "equalBytes32FailTest fails");
}
}

@ -33,4 +33,16 @@ contract AssertNotEqualTest {
function notEqualAddressFailTest() public {
Assert.notEqual(0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9, 0x7994f14563F39875a2F934Ce42cAbF48a93FdDA9, "notEqualAddressFailTest fails");
}
function notEqualBytes32PassTest() public {
bytes32 e = 0x72656d6978000000000000000000000000000000000000000000000000000000;
bytes32 r = 0x72656d6979000000000000000000000000000000000000000000000000000000;
Assert.notEqual(r, e, "notEqualBytes32PassTest fails");
}
function notEqualBytes32FailTest() public {
bytes32 e = 0x72656d6978000000000000000000000000000000000000000000000000000000;
bytes32 r = 0x72656d6978000000000000000000000000000000000000000000000000000000;
Assert.notEqual(r, e, "notEqualBytes32FailTest fails");
}
}

@ -143,12 +143,12 @@ describe('testRunner', () => {
afterAll(() => { tests = [] })
it('should have 4 passing test', () => {
assert.equal(results.passingNum, 4)
it('should have 5 passing test', () => {
assert.equal(results.passingNum, 5)
})
it('should have 4 failing test', () => {
assert.equal(results.failureNum, 4)
it('should have 5 failing test', () => {
assert.equal(results.failureNum, 5)
})
it('should return', () => {
@ -162,7 +162,9 @@ describe('testRunner', () => {
{ 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},
{ 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: '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'}
], ['time'])
})
})
@ -178,12 +180,12 @@ describe('testRunner', () => {
afterAll(() => { tests = [] })
it('should have 4 passing test', () => {
assert.equal(results.passingNum, 4)
it('should have 5 passing test', () => {
assert.equal(results.passingNum, 5)
})
it('should have 4 failing test', () => {
assert.equal(results.failureNum, 4)
it('should have 5 failing test', () => {
assert.equal(results.failureNum, 5)
})
it('should return', () => {
@ -197,7 +199,9 @@ describe('testRunner', () => {
{ 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},
{ 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: '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'}
], ['time'])
})
})

Loading…
Cancel
Save