Skip to content

Commit

Permalink
feat: add unit test for stream closing
Browse files Browse the repository at this point in the history
  • Loading branch information
bertux committed Jul 12, 2022
1 parent 9a06745 commit c113e74
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions packages/payment-processor/test/payment/erc777-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
} from '@requestnetwork/types';
import Utils from '@requestnetwork/utils';

import { payErc777StreamRequest, resolverAddress } from '../../src/payment/erc777-stream';
import {
completeErc777StreamRequest,
payErc777StreamRequest,
resolverAddress,
} from '../../src/payment/erc777-stream';
import { getRequestPaymentValues } from '../../src/payment/utils';
const daiABI = require('../abis/fDAIABI');

Expand Down Expand Up @@ -120,8 +124,8 @@ describe('erc777-stream', () => {
});
});

describe('payErc777StreamRequest', () => {
it('should pay an ERC777 request with fees', async () => {
describe('Streams management', () => {
it('payErc777StreamRequest should pay an ERC777 request', async () => {
let tx;
let confirmedTx;
// initialize the superfluid framework...put custom and web3 only bc we are using ganache locally
Expand Down Expand Up @@ -183,18 +187,53 @@ describe('erc777-stream', () => {
expect(confirmedTx.status).toBe(1);
expect(tx.hash).not.toBeUndefined();

const wFlowRate = await sf.cfaV1.getNetFlow({
const walletFlowRate = await sf.cfaV1.getNetFlow({
superToken: daix.address,
account: wallet.address,
providerOrSigner: provider,
});
expect(walletFlowRate).toBe(`-${expectedFlowRate}`);
const paymentFlowRate = await sf.cfaV1.getNetFlow({
superToken: daix.address,
account: paymentAddress,
providerOrSigner: provider,
});
expect(paymentFlowRate).toBe(expectedFlowRate);
});

it('completeErc777StreamRequest should complete an ERC777 request', async () => {
let tx;
let confirmedTx;
// initialize the superfluid framework...put custom and web3 only bc we are using ganache locally
const sf = await Framework.create({
networkName: 'custom',
provider,
dataMode: 'WEB3_ONLY',
resolverAddress: resolverAddress,
protocolReleaseVersion: 'test',
});

// use the framework to get the SuperToken
const daix = await sf.loadSuperToken('fDAIx');

// Paying fDAIX stream request
tx = await completeErc777StreamRequest(validRequest, wallet);
confirmedTx = await tx.wait(1);
expect(confirmedTx.status).toBe(1);
expect(tx.hash).not.toBeUndefined();

const walletFlowRate = await sf.cfaV1.getNetFlow({
superToken: daix.address,
account: wallet.address,
providerOrSigner: provider,
});
expect(wFlowRate).toBe(`-${expectedFlowRate}`);
const pFlowRate = await sf.cfaV1.getNetFlow({
expect(walletFlowRate).toBe('0');
const paymentFlowRate = await sf.cfaV1.getNetFlow({
superToken: daix.address,
account: paymentAddress,
providerOrSigner: provider,
});
expect(pFlowRate).toBe(expectedFlowRate);
expect(paymentFlowRate).toBe('0');
});
});
});

0 comments on commit c113e74

Please sign in to comment.