forked from gnosis/pm-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update js test files to work with Web3 v1.0.
- Use BigNumber.js and `.toString()` instead of `.valueOf()` because of issues with BN.js: web3/web3.js#2171 - Use async / await with Web3 because all Web3 v1.0 calls are asynchronous
- Loading branch information
1 parent
408bf3c
commit 661caf1
Showing
9 changed files
with
822 additions
and
714 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//This is a modified copy of: https://github.com/DigixGlobal/tempo/blob/master/lib/index.js | ||
// It is not compatible with Web3 v1.0 (https://github.com/DigixGlobal/tempo/issues/5) | ||
// A pull request has been created https://github.com/DigixGlobal/tempo/pull/4 | ||
// In the mean time, a local modified copy is used. | ||
|
||
'use strict'; | ||
|
||
module.exports = function (web3) { | ||
function sendRpc(method, params) { | ||
return new Promise(function (resolve) { | ||
web3.currentProvider.send({ | ||
jsonrpc: '2.0', | ||
method: method, | ||
params: params || [], | ||
id: new Date().getTime() | ||
}, function (err, res) { | ||
resolve(res); | ||
}); | ||
}); | ||
} | ||
function waitUntilBlock(seconds, targetBlock) { | ||
return new Promise(function (resolve) { | ||
var asyncIterator = function asyncIterator() { | ||
return web3.eth.getBlock('latest', function (e, _ref) { | ||
var number = _ref.number; | ||
|
||
if (number >= targetBlock - 1) { | ||
return sendRpc('evm_increaseTime', [seconds]).then(function () { | ||
return sendRpc('evm_mine'); | ||
}).then(resolve); | ||
} | ||
return sendRpc('evm_mine').then(asyncIterator); | ||
}); | ||
}; | ||
asyncIterator(); | ||
}); | ||
} | ||
function wait() { | ||
var seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20; | ||
var blocks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
|
||
return new Promise(function (resolve) { | ||
return web3.eth.getBlock('latest', function (e, _ref2) { | ||
var number = _ref2.number; | ||
|
||
resolve(blocks + number); | ||
}); | ||
}).then(function (targetBlock) { | ||
return waitUntilBlock(seconds, targetBlock); | ||
}); | ||
} | ||
return { wait: wait, waitUntilBlock: waitUntilBlock }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.