Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Feb 12, 2020
1 parent 6c5ec76 commit 2bd7512
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 49 deletions.
2 changes: 1 addition & 1 deletion raiden-ts/tests/e2e/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export class TestProvider extends Web3Provider {

public async mineUntil(block: number): Promise<number> {
const blockNumber = await this.getBlockNumber();
block = Math.max(block, blockNumber + 1);
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;
Expand Down
18 changes: 4 additions & 14 deletions raiden-ts/tests/e2e/raiden.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/camelcase */
import { timer } from 'rxjs';
import { first, filter, takeUntil } from 'rxjs/operators';
import { Zero } from 'ethers/constants';
import { parseEther, parseUnits, bigNumberify, BigNumber, keccak256, Network } from 'ethers/utils';
Expand All @@ -13,7 +14,7 @@ import 'raiden-ts/polyfills';
import { Raiden } from 'raiden-ts/raiden';
import { ShutdownReason } from 'raiden-ts/constants';
import { makeInitialState, RaidenState } from 'raiden-ts/state';
import { raidenShutdown } from 'raiden-ts/actions';
import { raidenShutdown, ConfirmableActions } from 'raiden-ts/actions';
import { newBlock, tokenMonitored } from 'raiden-ts/channels/actions';
import { ChannelState } from 'raiden-ts/channels/state';
import { Storage, Secret, Address } from 'raiden-ts/utils/types';
Expand All @@ -25,7 +26,6 @@ import { makeSecret, getSecrethash } from 'raiden-ts/transfers/utils';
import { matrixSetup } from 'raiden-ts/transport/actions';
import { losslessStringify } from 'raiden-ts/utils/data';
import { ServiceRegistryFactory } from 'raiden-ts/contracts/ServiceRegistryFactory';
import { timer } from 'rxjs';

describe('Raiden', () => {
const provider = new TestProvider();
Expand Down Expand Up @@ -68,18 +68,8 @@ describe('Raiden', () => {
);
raiden.action$
.pipe(
filter(
(
a: any, // eslint-disable-line @typescript-eslint/no-explicit-any
): a is {
payload: { txHash: string; txBlock: number; confirmed: undefined | boolean };
} =>
a &&
a.payload?.['txHash'] &&
a.payload['txBlock'] &&
'confirmed' in a.payload &&
a.payload.confirmed === undefined,
),
filter(isActionOf(ConfirmableActions)),
filter(a => a.payload.confirmed === undefined),
)
.subscribe(a =>
provider.mineUntil(a.payload.txBlock + raiden.config.confirmationBlocks + 1),
Expand Down
48 changes: 41 additions & 7 deletions raiden-ts/tests/unit/epics/channels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ describe('channels epic', () => {
{
id: channelId,
participant: depsMock.address,
closeBlock,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
Expand Down Expand Up @@ -531,7 +532,13 @@ describe('channels epic', () => {

await expect(promise).resolves.toEqual(
channelClose.success(
{ id: channelId, participant: partner, closeBlock, txHash },
{
id: channelId,
participant: partner,
txHash,
txBlock: closeBlock,
confirmed: undefined,
},
{ tokenNetwork, partner },
),
);
Expand All @@ -552,7 +559,13 @@ describe('channels epic', () => {
{ tokenNetwork, partner },
),
channelClose.success(
{ id: channelId, participant: depsMock.address, closeBlock, txHash },
{
id: channelId,
participant: depsMock.address,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
), // channel is in "closed" state already
].reduce(raidenReducer, state);
Expand All @@ -579,7 +592,10 @@ describe('channels epic', () => {
);

await expect(promise).resolves.toEqual(
channelSettle.success({ id: channelId, settleBlock, txHash }, { tokenNetwork, partner }),
channelSettle.success(
{ id: channelId, txHash, txBlock: settleBlock, confirmed: undefined },
{ tokenNetwork, partner },
),
);

// ensure ChannelSettledAction completed channel monitoring and unsubscribed from events
Expand Down Expand Up @@ -946,7 +962,13 @@ describe('channels epic', () => {
),
newBlock({ blockNumber: closeBlock }),
channelClose.success(
{ id: channelId, participant: depsMock.address, closeBlock, txHash },
{
id: channelId,
participant: depsMock.address,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
].reduce(raidenReducer, state);
Expand Down Expand Up @@ -977,7 +999,13 @@ describe('channels epic', () => {
),
newBlock({ blockNumber: closeBlock }),
channelClose.success(
{ id: channelId, participant: depsMock.address, closeBlock, txHash },
{
id: channelId,
participant: depsMock.address,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
newBlock({ blockNumber: settleBlock }),
Expand Down Expand Up @@ -1024,7 +1052,13 @@ describe('channels epic', () => {
),
newBlock({ blockNumber: closeBlock }),
channelClose.success(
{ id: channelId, participant: depsMock.address, closeBlock, txHash },
{
id: channelId,
participant: depsMock.address,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
newBlock({ blockNumber: settleBlock }),
Expand Down
2 changes: 1 addition & 1 deletion raiden-ts/tests/unit/epics/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ describe('PFS: pathFindServiceEpic', () => {
state$.next(
[
channelClose.success(
{ id: channelId, participant: partner, closeBlock: 126, txHash },
{ id: channelId, participant: partner, txHash, txBlock: 126, confirmed: true },
{ tokenNetwork, partner },
),
].reduce(raidenReducer, state$.value),
Expand Down
2 changes: 1 addition & 1 deletion raiden-ts/tests/unit/epics/raiden.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('raiden epic', () => {
),
newBlock({ blockNumber: 128 }),
channelClose.success(
{ id: channelId, participant: partner, closeBlock: 128, txHash },
{ id: channelId, participant: partner, txHash, txBlock: 128, confirmed: true },
{ tokenNetwork, partner },
),
newBlock({ blockNumber: 629 }),
Expand Down
34 changes: 29 additions & 5 deletions raiden-ts/tests/unit/epics/transfers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ describe('transfers epic', () => {
{
id: channelId + 1,
participant: closingPartner,
closeBlock: openBlock + 1,
txHash,
txBlock: openBlock + 1,
confirmed: true,
},
{ tokenNetwork, partner: closingPartner },
),
Expand Down Expand Up @@ -457,12 +458,23 @@ describe('transfers epic', () => {
state$ = of(
[
channelClose.success(
{ id: channelId, participant: partner, closeBlock, txHash },
{
id: channelId,
participant: partner,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
newBlock({ blockNumber: closeBlock + settleTimeout + 1 }),
channelSettle.success(
{ id: channelId, settleBlock: closeBlock + settleTimeout + 1, txHash },
{
id: channelId,
txHash,
txBlock: closeBlock + settleTimeout + 1,
confirmed: true,
},
{ tokenNetwork, partner },
),
newBlock({ blockNumber: closeBlock + settleTimeout + 2 }),
Expand Down Expand Up @@ -497,7 +509,13 @@ describe('transfers epic', () => {
state$ = of(
[
channelClose.success(
{ id: channelId, participant: partner, closeBlock, txHash },
{
id: channelId,
participant: partner,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
].reduce(raidenReducer, transferingState),
Expand Down Expand Up @@ -612,7 +630,13 @@ describe('transfers epic', () => {
state$ = of(
[
channelClose.success(
{ id: channelId, participant: partner, closeBlock, txHash },
{
id: channelId,
participant: partner,
txHash,
txBlock: closeBlock,
confirmed: true,
},
{ tokenNetwork, partner },
),
newBlock({ blockNumber: signedTransfer.lock.expiration.toNumber() + 1 }),
Expand Down
Loading

0 comments on commit 2bd7512

Please sign in to comment.