Promisify web3 sync requests in tests (#1009)
This commit is contained in:
@ -31,8 +31,8 @@ export default function increaseTime (duration) {
|
||||
*
|
||||
* @param target time in seconds
|
||||
*/
|
||||
export function increaseTimeTo (target) {
|
||||
let now = latestTime();
|
||||
export async function increaseTimeTo (target) {
|
||||
let now = (await latestTime());
|
||||
if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`);
|
||||
let diff = target - now;
|
||||
return increaseTime(diff);
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import { ethGetBlock } from './web3';
|
||||
|
||||
// Returns the time of the last mined block in seconds
|
||||
export default function latestTime () {
|
||||
return web3.eth.getBlock('latest').timestamp;
|
||||
export default async function latestTime () {
|
||||
const block = await ethGetBlock('latest');
|
||||
return block.timestamp;
|
||||
}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
export default func =>
|
||||
(...args) =>
|
||||
new Promise((resolve, reject) =>
|
||||
func(...args, (error, data) => error ? reject(error) : resolve(data)));
|
||||
7
test/helpers/web3.js
Normal file
7
test/helpers/web3.js
Normal file
@ -0,0 +1,7 @@
|
||||
const pify = require('pify');
|
||||
|
||||
const ethAsync = pify(web3.eth);
|
||||
|
||||
export const ethGetBalance = ethAsync.getBalance;
|
||||
export const ethSendTransaction = ethAsync.sendTransaction;
|
||||
export const ethGetBlock = ethAsync.getBlock;
|
||||
Reference in New Issue
Block a user