Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 74042d8

Browse files
committed
Update tests to work with latest changes
1 parent 187f9b9 commit 74042d8

File tree

4 files changed

+271
-73
lines changed

4 files changed

+271
-73
lines changed

test/helpers/StandardTokenMock.sol

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
pragma solidity ^0.4.11;
1+
pragma solidity 0.4.18;
22

33

4-
import '../../contracts/lib/StandardToken.sol';
4+
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
55

66

77
// mock class using BasicToken
88
contract StandardTokenMock is StandardToken {
9+
string public name;
10+
string public symbol;
11+
uint256 public totalSupply;
912

10-
function StandardTokenMock(address initialAccount, uint256 initialBalance) {
13+
function StandardTokenMock(
14+
address initialAccount,
15+
uint256 initialBalance,
16+
string _name,
17+
string _symbol)
18+
public
19+
{
1120
balances[initialAccount] = initialBalance;
1221
totalSupply = initialBalance;
22+
name = _name;
23+
symbol = _symbol;
1324
}
1425

15-
}
26+
}

test/helpers/expectedException.js

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
1-
module.exports = function expectedExceptionPromise(action, gasToUse) {
2-
return new Promise(function (resolve, reject) {
3-
try {
4-
resolve(action());
5-
} catch(e) {
6-
reject(e);
7-
}
8-
})
9-
.then(function (txObj) {
10-
return typeof txn === "string"
11-
? web3.eth.getTransactionReceiptMined(txObj) // regular tx hash
12-
: typeof txObj.receipt !== "undefined"
13-
? txObj.receipt // truffle-contract function call
14-
: typeof txObj.transactionHash === "string"
15-
? web3.eth.getTransactionReceiptMined(txObj.transactionHash) // deployment
16-
: txObj; // Unknown last case
17-
})
18-
.then(function (receipt) {
19-
console.log('Receipt', receipt);
1+
"use strict";
202

21-
// We are in Geth or the tx wrongly passed
22-
assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas");
23-
})
24-
.catch(function (e) {
25-
if ((e + "").indexOf("invalid JUMP") > -1 ||
26-
(e + "").indexOf("out of gas") > -1 ||
27-
(e + "").indexOf("invalid opcode") > -1) {
28-
// We are in TestRPC
29-
} else if ((e + "").indexOf("please check your gas amount") > -1) {
30-
// We are in Geth for a deployment
31-
} else {
32-
throw e;
33-
}
34-
});
35-
};
3+
/**
4+
* @param {!Function.<!Promise>} action.
5+
* @param {!Number | !string | !BigNumber} gasToUse.
6+
* @returns {!Promise} which throws unless it hit a valid error.
7+
*/
8+
module.exports = function expectedExceptionPromise(action, gasToUse) {
9+
return new Promise(function (resolve, reject) {
10+
try {
11+
resolve(action());
12+
} catch(e) {
13+
reject(e);
14+
}
15+
})
16+
.then(function (txObj) {
17+
return typeof txn === "string"
18+
? web3.eth.getTransactionReceiptMined(txObj) // regular tx hash
19+
: typeof txObj.receipt !== "undefined"
20+
? txObj.receipt // truffle-contract function call
21+
: typeof txObj.transactionHash === "string"
22+
? web3.eth.getTransactionReceiptMined(txObj.transactionHash) // deployment
23+
: txObj; // Unknown last case
24+
})
25+
.then(
26+
function (receipt) {
27+
console.log("Receipt: " + receipt);
28+
// We are in Geth
29+
if (typeof receipt.status !== "undefined") {
30+
// Byzantium
31+
assert.include(["0x0", "0x00"], receipt.status, "should have reverted");
32+
} else {
33+
// Pre Byzantium
34+
assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas");
35+
}
36+
},
37+
function (e) {
38+
if ((e + "").indexOf("invalid JUMP") > -1 ||
39+
(e + "").indexOf("out of gas") > -1 ||
40+
(e + "").indexOf("invalid opcode") > -1 ||
41+
(e + "").indexOf("revert") > -1) {
42+
// We are in TestRPC
43+
} else if ((e + "").indexOf("please check your gas amount") > -1) {
44+
// We are in Geth for a deployment
45+
} else {
46+
throw e;
47+
}
48+
}
49+
);
50+
};

test/helpers/getTransactionReceiptMined.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ module.exports = function getTransactionReceiptMined(txHash, interval) {
2222
} else {
2323
throw new Error("Invalid Type: " + txHash);
2424
}
25-
};
25+
};

0 commit comments

Comments
 (0)