Skip to content

Commit

Permalink
test: reduce flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque committed Nov 27, 2023
1 parent 6981bc1 commit 76bb171
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 82 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ yarn run lint

### Test

Disable API tests OR define all required explorer API keys.

```bash
export DISABLE_API_TESTS=1
# OR
export EXPLORER_API_KEY_MAINNET=
export EXPLORER_API_KEY_RINKEBY=
export EXPLORER_API_KEY_FUSE=
export EXPLORER_API_KEY_MATIC=
export EXPLORER_API_KEY_FANTOM=
```

Test all the packages in the monorepo.

```bash
Expand Down
16 changes: 3 additions & 13 deletions packages/payment-detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,8 @@ yarn codegen

# Test

The ETH `InfoRetriever` tests require explorer API keys. Before running the
payment-detection tests, define `DISABLE_API_TESTS` or define all required
explorer API keys.

```bash
export DISABLE_API_TESTS=1
# OR
export EXPLORER_API_KEY_MAINNET=
export EXPLORER_API_KEY_RINKEBY=
export EXPLORER_API_KEY_FUSE=
export EXPLORER_API_KEY_MATIC=
export EXPLORER_API_KEY_FANTOM=

yarn run test

```
```
84 changes: 84 additions & 0 deletions packages/payment-detection/test/eth/etherscan-fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { BigNumber } from 'ethers';

export default [
{
hash: '0x74d5dafdfaa023583d8bb6993a873babd403a05b2286e556e2617801b130cb8e',
type: 0,
accessList: null,
blockHash: '0xcd58c67561d7b94447e8e9d313f5e7c343f9fe5606961f4f33142bafea005cd5',
blockNumber: 9081997,
transactionIndex: 12,
confirmations: 9581715,
from: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
gasPrice: BigNumber.from('0x04a817c800'),
gasLimit: BigNumber.from('0x5288'),
to: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
value: BigNumber.from('0x05'),
nonce: 17,
data: '0xa93299ed2555d098',
creates: null,
chainId: 0,
timestamp: 1575964424,
},
{
hash: '0x0b53c5296a7b286fef52336529f3934584fea116725d1fe4c59552e926229059',
type: 0,
accessList: null,
blockHash: '0x8535994e0a366ccfc61f5f925ce59404346569342bda1d80ccedfa6fed24c21a',
blockNumber: 9082338,
transactionIndex: 151,
confirmations: 9581374,
from: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
gasPrice: BigNumber.from('0x02540be400'),
gasLimit: BigNumber.from('0x5288'),
to: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
value: BigNumber.from('0x21'),
nonce: 18,
data: '0x9649a1a4dd5854ed',
creates: null,
chainId: 0,
timestamp: 1575969371,
},

{
hash: '0x06d95c3889dcd974106e82fa27358549d9392d6fee6ea14fe1acedadc1013114',
type: 0,
accessList: null,
blockHash: '0x74705d798896a8dfefd3057170f95e6b3a5a05f735440c761cd6f17f4aabd422',
blockNumber: 10013330,
transactionIndex: 120,
confirmations: 8650382,
from: '0x74Ef019C1E9F11366c5c8DC4Ab556C16fe13B51F',
gasPrice: BigNumber.from('0x059682f000'),
gasLimit: BigNumber.from('0x5428'),
to: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
value: BigNumber.from('0x02dd231b00'),
nonce: 205,
data: '0xc19da4923539c37f',
creates: null,
chainId: 0,
timestamp: 1588776378,
},

// polygonscan

{
hash: '0x50af07756eb07bb0eb29943cb7206d8359c829aef7f6dad50f61b488c2790c1c',
type: 0,
accessList: null,
blockHash: '0x186a3f7a4a49ef302223bc72cd45a07f01a7c0c6bf1fc3127fc97de7879874f5',
blockNumber: 17182533,
transactionIndex: 108,
confirmations: 33274506,
from: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
gasPrice: BigNumber.from('0x02f4d4f484'),
gasLimit: BigNumber.from('0x5288'),
to: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
value: BigNumber.from('0x038d7ea4c68000'),
nonce: 11,
data: '0x5f05d421a5ed3558',
creates: null,
chainId: 0,
timestamp: 1627050587,
},
];
73 changes: 41 additions & 32 deletions packages/payment-detection/test/eth/info-retriever.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PaymentTypes } from '@requestnetwork/types';
import { EthInputDataInfoRetriever } from '../../src/eth/info-retriever';
import PaymentReferenceCalculator from '../../src/payment-reference-calculator';
import etherscanFixtures from './etherscan-fixtures';
import { providers } from 'ethers';

describe('api/eth/info-retriever', () => {
// In this test, we're looking this transaction:
Expand Down Expand Up @@ -45,38 +47,36 @@ describe('api/eth/info-retriever', () => {
await expect(infoRetreiver.getTransferEvents()).rejects.toThrowError();
});

// Utility for conditionally skipping tests
const describeIf = (
condition: any,
...args: [string | number | Function | jest.FunctionLike, jest.EmptyFunction]
) => (condition ? describe(...args) : describe.skip(...args));

// Skip tests if build is from external fork or API tests are disabled
// External forks cannot access secret API keys
describeIf(!process.env.CIRCLE_PR_NUMBER && !process.env.DISABLE_API_TESTS, 'Multichain', () => {
describe('Multichain retriever', () => {
beforeAll(() => {
jest
.spyOn(providers.EtherscanProvider.prototype, 'getHistory')
.mockResolvedValue(etherscanFixtures as any);
});
// TODO temporary disable xDAI, CELO, Sokol, and Goerli
// FIXME: API-based checks should run nightly and be mocked for CI
[
'mainnet',
// 'rinkeby',
// 'goerli',
// 'xdai',
// 'sokol',
'fuse',
//'celo',
'matic',
'fantom',
].forEach((network) => {
it(`Can get the balance on ${network}`, async () => {
const retriever = new EthInputDataInfoRetriever(
'0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
PaymentTypes.EVENTS_NAMES.PAYMENT,
network,
'9649a1a4dd5854ed',
process.env[`EXPLORER_API_KEY_${network.toUpperCase()}`],
);
await expect(retriever.getTransferEvents()).resolves.not.toThrow();
});

it(`Can get the balance with the Multichain retriever`, async () => {
const retriever = new EthInputDataInfoRetriever(
'0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB',
PaymentTypes.EVENTS_NAMES.PAYMENT,
'mainnet',
'9649a1a4dd5854ed',
);
await expect(retriever.getTransferEvents()).resolves.toMatchObject([
{
amount: '33',
name: 'payment',
parameters: {
block: 9082338,
confirmations: 9581374,
txHash: '0x0b53c5296a7b286fef52336529f3934584fea116725d1fe4c59552e926229059',
},
timestamp: 1575969371,
},
]);
});

it('can detect a MATIC payment to self', async () => {
Expand All @@ -93,12 +93,21 @@ describe('api/eth/info-retriever', () => {
PaymentTypes.EVENTS_NAMES.PAYMENT,
'matic',
paymentReference,
process.env[`EXPLORER_API_KEY_MATIC`],
);
const events = await infoRetriever.getTransferEvents();
expect(events).toHaveLength(1);

expect(events[0].amount).toBe('1000000000000000');
const events = await infoRetriever.getTransferEvents();
expect(events).toMatchObject([
{
amount: '1000000000000000',
name: 'payment',
parameters: {
block: 17182533,
confirmations: 33274506,
txHash: '0x50af07756eb07bb0eb29943cb7206d8359c829aef7f6dad50f61b488c2790c1c',
},
timestamp: 1627050587,
},
]);
});
});
});
25 changes: 0 additions & 25 deletions packages/payment-processor/test/payment/erc777-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,6 @@ describe('erc777-stream', () => {
});
});

describe('Superfluid framework', () => {
it.each([
{ network: 'goerli' },
{ network: 'matic' },
// { network: 'xdai' },
{ network: 'optimism' },
{ network: 'avalanche' },
{ network: 'arbitrum-one' },
] as Array<{ network: CurrencyTypes.EvmChainName }>)(
'Should initialize superfluid framework on $network',
async ({ network }) => {
const provider = getDefaultProvider(network);
const networkValidRequest = {
...validRequest,
currencyInfo: {
...validRequest.currencyInfo,
network,
},
};
const sf = await getSuperFluidFramework(networkValidRequest, provider);
expect(sf).toBeDefined();
},
);
});

describe('encodePayErc20FeeRequest (used to pay and swap to pay)', () => {
it('should throw an error if the request is not erc777', async () => {
const request = deepCopy(validRequest) as ClientTypes.IRequestData;
Expand Down

0 comments on commit 76bb171

Please sign in to comment.