Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Feb 11, 2020
1 parent 1f36c14 commit 65d86be
Show file tree
Hide file tree
Showing 9 changed files with 661 additions and 138 deletions.
48 changes: 32 additions & 16 deletions raiden-ts/tests/e2e/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import memdown from 'memdown';
import { range } from 'lodash';
import asyncPool from 'tiny-async-pool';

import { Web3Provider } from 'ethers/providers';
import { Web3Provider, AsyncSendable } from 'ethers/providers';
import { MaxUint256, AddressZero } from 'ethers/constants';
import { ContractFactory } from 'ethers/contract';
import { parseUnits, ParamType } from 'ethers/utils';
Expand All @@ -19,17 +19,18 @@ import { UserDeposit } from 'raiden-ts/contracts/UserDeposit';
import Contracts from '../../raiden-contracts/raiden_contracts/data/contracts.json';

export class TestProvider extends Web3Provider {
public constructor(opts?: GanacheServerOptions) {
public constructor(web3?: AsyncSendable, opts?: GanacheServerOptions) {
super(
ganache.provider({
total_accounts: 3,
default_balance_ether: 5,
seed: 'testrpc_provider',
network_id: 1338,
db: memdown(),
// logger: console,
...opts,
}),
web3 ??
ganache.provider({
total_accounts: 3,
default_balance_ether: 5,
seed: 'testrpc_provider',
network_id: 1338,
db: memdown(),
// logger: console,
...opts,
}),
);
this.pollingInterval = 10;
}
Expand All @@ -45,17 +46,32 @@ export class TestProvider extends Web3Provider {
public async mine(count = 1): Promise<number> {
const blockNumber = await this.getBlockNumber();
console.debug(`mining ${count} blocks after blockNumber=${blockNumber}`);
const promise = new Promise(resolve => {
const promise = new Promise<number>(resolve => {
const cb = (b: number): void => {
if (b < blockNumber + count) return;
this.removeListener('block', cb);
resolve();
resolve(b);
};
this.on('block', cb);
});
await asyncPool(10, range(count), () => this.send('evm_mine', null));
await promise;
return this.blockNumber;
asyncPool(10, range(count), () => this.send('evm_mine', null));
return promise;
}

public async mineUntil(block: number): Promise<number> {
const blockNumber = await this.getBlockNumber();
console.debug(`mining until block=${block} from ${blockNumber}`);
if (blockNumber >= block) return blockNumber;
const promise = new Promise<number>(resolve => {
const cb = (b: number): void => {
if (b < block) return;
this.removeListener('block', cb);
resolve(b);
};
this.on('block', cb);
});
asyncPool(10, range(block - blockNumber), () => this.send('evm_mine', null));
return promise;
}

public async deployRegistry(): Promise<ContractsInfo> {
Expand Down
Loading

0 comments on commit 65d86be

Please sign in to comment.