Move more shared utils into utils package and reuse them
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/dev-utils": "^0.0.1",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@0xproject/types": "^0.1.0",
|
||||
"@types/bluebird": "^3.5.3",
|
||||
|
@@ -1,13 +1,14 @@
|
||||
import {RPC} from '@0xproject/dev-utils';
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import Web3 = require('web3');
|
||||
|
||||
import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json';
|
||||
import * as truffleConf from '../../truffle.js';
|
||||
import {Artifacts} from '../../util/artifacts';
|
||||
import {constants} from '../../util/constants';
|
||||
import {MultiSigWrapper} from '../../util/multi_sig_wrapper';
|
||||
import {RPC} from '../../util/rpc';
|
||||
import {ContractInstance} from '../../util/types';
|
||||
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
@@ -38,7 +39,8 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
|
||||
|
||||
const secondsTimeLocked = await multiSig.secondsTimeLocked.call();
|
||||
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
|
||||
rpc = new RPC();
|
||||
const rpcUrl = `http://${truffleConf.networks.development.host}:${truffleConf.networks.development.port}`;
|
||||
rpc = new RPC(rpcUrl);
|
||||
});
|
||||
|
||||
describe('changeTimeLock', () => {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import {bigNumberConfigs} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {bigNumberConfigs} from './bignumber_config';
|
||||
import {BalancesByOwner, ContractInstance} from './types';
|
||||
|
||||
bigNumberConfigs.configure();
|
||||
|
@@ -1,11 +0,0 @@
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
|
||||
export const bigNumberConfigs = {
|
||||
configure() {
|
||||
// By default BigNumber's `toString` method converts to exponential notation if the value has
|
||||
// more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number
|
||||
BigNumber.config({
|
||||
EXPONENTIAL_AT: 1000,
|
||||
});
|
||||
},
|
||||
};
|
@@ -1,43 +0,0 @@
|
||||
import 'isomorphic-fetch';
|
||||
|
||||
import * as truffleConf from '../truffle.js';
|
||||
|
||||
export class RPC {
|
||||
private host: string;
|
||||
private port: number;
|
||||
private id: number;
|
||||
constructor() {
|
||||
this.host = truffleConf.networks.development.host;
|
||||
this.port = truffleConf.networks.development.port;
|
||||
this.id = 0;
|
||||
}
|
||||
public async increaseTimeAsync(time: number) {
|
||||
const method = 'evm_increaseTime';
|
||||
const params = [time];
|
||||
const payload = this.toPayload(method, params);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
public async mineBlockAsync() {
|
||||
const method = 'evm_mine';
|
||||
const payload = this.toPayload(method);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
private toPayload(method: string, params: any[] = []) {
|
||||
const payload = JSON.stringify({
|
||||
id: this.id,
|
||||
method,
|
||||
params,
|
||||
});
|
||||
this.id++;
|
||||
return payload;
|
||||
}
|
||||
private async sendAsync(payload: string): Promise<any> {
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
};
|
||||
const response = await fetch(`http://${this.host}:${this.port}`, opts);
|
||||
const responsePayload = await response.json();
|
||||
return responsePayload;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user