Commit e9faef98 authored by aniket-engg's avatar aniket-engg Committed by Aniket

return assert emthod for failed tests

parent 13480178
......@@ -5,12 +5,14 @@ library Assert {
event AssertionEvent(
bool passed,
string message
string message,
string methodName
);
event AssertionEventUint(
bool passed,
string message,
string methodName,
uint256 returned,
uint256 expected
);
......@@ -18,6 +20,7 @@ library Assert {
event AssertionEventInt(
bool passed,
string message,
string methodName,
int256 returned,
int256 expected
);
......@@ -25,6 +28,7 @@ library Assert {
event AssertionEventBool(
bool passed,
string message,
string methodName,
bool returned,
bool expected
);
......@@ -32,6 +36,7 @@ library Assert {
event AssertionEventAddress(
bool passed,
string message,
string methodName,
address returned,
address expected
);
......@@ -39,6 +44,7 @@ library Assert {
event AssertionEventBytes32(
bool passed,
string message,
string methodName,
bytes32 returned,
bytes32 expected
);
......@@ -46,6 +52,7 @@ library Assert {
event AssertionEventString(
bool passed,
string message,
string methodName,
string returned,
string expected
);
......@@ -53,6 +60,7 @@ library Assert {
event AssertionEventUintInt(
bool passed,
string message,
string methodName,
uint256 returned,
int256 expected
);
......@@ -60,28 +68,29 @@ library Assert {
event AssertionEventIntUint(
bool passed,
string message,
string methodName,
int256 returned,
uint256 expected
);
function ok(bool a, string memory message) public returns (bool result) {
result = a;
emit AssertionEvent(result, message);
emit AssertionEvent(result, message, "ok");
}
function equal(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventUint(result, message, a, b);
emit AssertionEventUint(result, message, "equal", a, b);
}
function equal(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventInt(result, message, a, b);
emit AssertionEventInt(result, message, "equal", a, b);
}
function equal(bool a, bool b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventBool(result, message, a, b);
emit AssertionEventBool(result, message, "equal", a, b);
}
// TODO: only for certain versions of solc
......@@ -98,32 +107,32 @@ library Assert {
function equal(address a, address b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventAddress(result, message, a, b);
emit AssertionEventAddress(result, message, "equal", a, b);
}
function equal(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventBytes32(result, message, a, b);
emit AssertionEventBytes32(result, message, "equal", a, b);
}
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 AssertionEventString(result, message, a, b);
emit AssertionEventString(result, message, "equal", a, b);
}
function notEqual(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventUint(result, message, a, b);
emit AssertionEventUint(result, message, "notEqual", a, b);
}
function notEqual(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventInt(result, message, a, b);
emit AssertionEventInt(result, message, "notEqual", a, b);
}
function notEqual(bool a, bool b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventBool(result, message, a, b);
emit AssertionEventBool(result, message, "notEqual", a, b);
}
// TODO: only for certain versions of solc
......@@ -140,28 +149,28 @@ library Assert {
function notEqual(address a, address b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventAddress(result, message, a, b);
emit AssertionEventAddress(result, message, "notEqual", a, b);
}
function notEqual(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventBytes32(result, message, a, b);
emit AssertionEventBytes32(result, message, "notEqual", a, b);
}
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 AssertionEventString(result, message, a, b);
emit AssertionEventString(result, message, "notEqual", a, b);
}
/*----------------- Greater than --------------------*/
function greaterThan(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a > b);
emit AssertionEventUint(result, message, a, b);
emit AssertionEventUint(result, message, "greaterThan", a, b);
}
function greaterThan(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a > b);
emit AssertionEventInt(result, message, a, b);
emit AssertionEventInt(result, message, "greaterThan", a, b);
}
// TODO: safely compare between uint and int
function greaterThan(uint256 a, int256 b, string memory message) public returns (bool result) {
......@@ -171,7 +180,7 @@ library Assert {
} else {
result = (a > uint(b));
}
emit AssertionEventUintInt(result, message, a, b);
emit AssertionEventUintInt(result, message, "greaterThan", a, b);
}
function greaterThan(int256 a, uint256 b, string memory message) public returns (bool result) {
if(a < int(0)) {
......@@ -180,17 +189,17 @@ library Assert {
} else {
result = (uint(a) > b);
}
emit AssertionEventIntUint(result, message, a, b);
emit AssertionEventIntUint(result, message, "greaterThan", a, b);
}
/*----------------- Lesser than --------------------*/
function lesserThan(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a < b);
emit AssertionEventUint(result, message, a, b);
emit AssertionEventUint(result, message, "lesserThan", a, b);
}
function lesserThan(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a < b);
emit AssertionEventInt(result, message, a, b);
emit AssertionEventInt(result, message, "lesserThan", a, b);
}
// TODO: safely compare between uint and int
function lesserThan(uint256 a, int256 b, string memory message) public returns (bool result) {
......@@ -200,7 +209,7 @@ library Assert {
} else {
result = (a < uint(b));
}
emit AssertionEventUintInt(result, message, a, b);
emit AssertionEventUintInt(result, message, "lesserThan", a, b);
}
function lesserThan(int256 a, uint256 b, string memory message) public returns (bool result) {
......@@ -210,7 +219,7 @@ library Assert {
} else {
result = (uint(a) < b);
}
emit AssertionEventIntUint(result, message, a, b);
emit AssertionEventIntUint(result, message, "lesserThan", a, b);
}
}
`
const assertionEvents = [
{
name: 'AssertionEvent',
params: ['bool', 'string']
params: ['bool', 'string', 'string']
},
{
name: 'AssertionEventUint',
params: ['bool', 'string', 'uint256', 'uint256']
params: ['bool', 'string', 'string', 'uint256', 'uint256']
},
{
name: 'AssertionEventInt',
params: ['bool', 'string', 'int256', 'int256']
params: ['bool', 'string', 'string', 'int256', 'int256']
},
{
name: 'AssertionEventBool',
params: ['bool', 'string', 'bool', 'bool']
params: ['bool', 'string', 'string', 'bool', 'bool']
},
{
name: 'AssertionEventAddress',
params: ['bool', 'string', 'address', 'address']
params: ['bool', 'string', 'string', 'address', 'address']
},
{
name: 'AssertionEventBytes32',
params: ['bool', 'string', 'bytes32', 'bytes32']
params: ['bool', 'string', 'string', 'bytes32', 'bytes32']
},
{
name: 'AssertionEventString',
params: ['bool', 'string', 'string', 'string']
params: ['bool', 'string', 'string', 'string', 'string']
},
{
name: 'AssertionEventUintInt',
params: ['bool', 'string', 'uint256', 'int256']
params: ['bool', 'string', 'string', 'uint256', 'int256']
},
{
name: 'AssertionEventIntUint',
params: ['bool', 'string', 'int256', 'uint256']
params: ['bool', 'string', 'string', 'int256', 'uint256']
}
]
......
......@@ -237,9 +237,9 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
if (eIndex >= 0) {
const testEvent = web3.eth.abi.decodeParameters(assertionEvents[eIndex].params, event.raw.data)
if (!testEvent[0]) {
if(eIndex === 0) { // for 'Assert.ok' method
testEvent[2] = 'false'
testEvent[3] = 'true'
if(testEvent[2] === 'ok') { // for 'Assert.ok' method
testEvent[3] = 'false'
testEvent[4] = 'true'
}
const resp: TestResultInterface = {
type: 'testFailure',
......@@ -247,8 +247,9 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
time: time,
errMsg: testEvent[1],
context: testName,
returned: testEvent[2],
expected: testEvent[3]
assertMethod: testEvent[2],
returned: testEvent[3],
expected: testEvent[4]
};
testCallback(undefined, resp)
failureNum += 1
......
......@@ -32,6 +32,7 @@ export interface TestResultInterface {
context?: string
errMsg?: string
filename?: string
assertMethod?: string
returned?: string | number
expected?: string | number
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment