Skip to content

Commit

Permalink
fix: nigthly tests (#1222)
Browse files Browse the repository at this point in the history
Co-authored-by: Yo <56731761+yomarion@users.noreply.github.com>
  • Loading branch information
benjlevesque and yomarion committed Oct 27, 2023
1 parent 52f0e5f commit ab1eb42
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
10 changes: 2 additions & 8 deletions packages/integration-test/test/layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
StorageTypes,
} from '@requestnetwork/types';
import { providers, Wallet } from 'ethers';
import { automine } from './scheduled/fixtures';

let advancedLogic: AdvancedLogicTypes.IAdvancedLogic;
let requestLogic: RequestLogicTypes.IRequestLogic;
Expand All @@ -38,14 +39,7 @@ let signatureProvider: any;

let dataAccess: DataAccessTypes.IDataAccess;

const interval = setInterval(async () => {
await provider.send('evm_mine', []);
// eslint-disable-next-line no-magic-numbers
}, 200);

afterAll(() => {
clearInterval(interval);
});
automine();

const mnemonic = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Types, Utils } from '@requestnetwork/request-client.js';

import { mockAdvancedLogic } from './mocks';
import {
automine,
erc20requestCreationHash,
localErc20PaymentNetworkParams,
payeeIdentity,
Expand All @@ -14,6 +15,8 @@ import {
} from './fixtures';
import { createMockErc20FeeRequest } from '../utils';

automine();

const pnFactory = new PaymentNetworkFactory(mockAdvancedLogic, CurrencyManager.getDefault());

const paidRequest = {
Expand Down
14 changes: 8 additions & 6 deletions packages/integration-test/test/scheduled/erc20-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { mockAdvancedLogic } from './mocks';
import { Types, Utils } from '@requestnetwork/request-client.js';
import { CurrencyManager } from '@requestnetwork/currency';
import {
automine,
erc20requestCreationHash,
localErc20PaymentNetworkParams,
payeeIdentity,
Expand All @@ -13,6 +14,8 @@ import {
requestNetwork,
} from './fixtures';

automine();

const erc20ProxyAddressedBased = new Erc20PaymentNetwork.ERC20ProxyPaymentDetector({
advancedLogic: mockAdvancedLogic,
currencyManager: CurrencyManager.getDefault(),
Expand All @@ -29,6 +32,7 @@ describe('ERC20 Proxy detection test-suite', () => {
requestInfo: erc20requestCreationHash,
signer: payeeIdentity,
});
await request.waitForConfirmation();

let requestData = await request.declareReceivedPayment('1', 'OK', payeeIdentity);
const declarationTimestamp = Utils.getCurrentTimestampInSecond();
Expand Down Expand Up @@ -60,14 +64,12 @@ describe('ERC20 Proxy detection test-suite', () => {
requestInfo: erc20requestCreationHash,
signer: payeeIdentity,
});
const refreshedRequest = await request.waitForConfirmation();
expect(refreshedRequest.state).toBe('created');

// The payer declares a payment
let requestData: Types.IRequestDataWithEvents = await request.declareSentPayment(
'1',
'OK',
payerIdentity,
);
requestData = await new Promise((resolve): unknown => requestData.on('confirmed', resolve));
let requestData = await request.declareSentPayment('1', 'OK', payerIdentity);
requestData = await new Promise((resolve) => requestData.on('confirmed', resolve));
const balance = await erc20ProxyAddressedBased.getBalance({
...requestData,
currency: {
Expand Down
8 changes: 8 additions & 0 deletions packages/integration-test/test/scheduled/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IdentityTypes, PaymentTypes, ExtensionTypes } from '@requestnetwork/types';
import { RequestNetwork, Types } from '@requestnetwork/request-client.js';
import { EthereumPrivateKeySignatureProvider } from '@requestnetwork/epk-signature';
import { providers } from 'ethers';

export const httpConfig = {
getConfirmationDeferDelay: 1000,
Expand Down Expand Up @@ -67,3 +68,10 @@ export const localEthInputDataPaymentNetworkParams: PaymentTypes.PaymentNetworkC
paymentAddress: '0xf17f52151EbEF6C7334FAD080c5704D77216b732',
},
};

export const automine = (freq = 200) => {
const provider = new providers.JsonRpcProvider();
setInterval(async () => {
await provider.send('evm_mine', []);
}, freq).unref();
};

0 comments on commit ab1eb42

Please sign in to comment.