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