git ssb

0+

dangerousbeans / Entropy_contracts



Tree: e2d16c3510e7763b548d4c0110a89fa0924236d6

Files: e2d16c3510e7763b548d4c0110a89fa0924236d6 / test / helpers.js

1337 bytesRaw
1exports.deployEntropyContract = () => {
2 return Entropy.new({gas: 2000000})
3}
4
5
6exports.getBalance = (address) => {
7 return new Promise((fullfil, reject) => {
8 web3.eth.getBalance(address, (err, balance) => {
9 if (err) { return reject(err) }
10 return fullfil(balance);
11 })
12 })
13};
14
15
16exports.expectedExceptionPromise = (action, gasToUse) => {
17 return new Promise((resolve, reject) => {
18 try {
19 resolve(action());
20 } catch(e) {
21 reject(e);
22 }
23 })
24 .then(function (txn) {
25 // https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
26 return web3.eth.getTransactionReceiptMined(txn);
27 })
28 .then(function (receipt) {
29 // We are in Geth
30 assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas");
31 })
32 .catch(function (e) {
33 if ((e + "").indexOf("invalid JUMP") || (e + "").indexOf("out of gas") > -1) {
34 // We are in TestRPC
35 } else if ((e + "").indexOf("please check your gas amount") > -1) {
36 // We are in Geth for a deployment
37 } else {
38 throw e;
39 }
40 });
41};
42
43
44// Wrap the call and assert pattern in promises
45exports.callAndCheck = ( contract, f, expected, message ) => {
46 return contract[f].call().then((response) => {
47 assert.equal(response, expected, false, message);
48 })
49}
50

Built with git-ssb-web