Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-abrioux committed Nov 23, 2023
1 parent aa8bfda commit 2e4a962
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/payment-detection/src/thegraph/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const THE_GRAPH_URL_MANTLE =
// NB: the GraphQL client is automatically generated based on files present in ./queries,
// using graphql-codegen.
// To generate types, run `yarn codegen`, then open the generated files so that the code editor picks up the changes.

/**
* A GraphQL client to query Request's subgraph.
*
Expand All @@ -40,6 +41,11 @@ const extractClientOptions = (options?: TheGraphClientOptions) => {
return pick(options, 'timeout');
};

export const getTheGraphClient = (network: string, url: string, options?: TheGraphClientOptions) =>
NearChains.isChainSupported(network)
? getTheGraphNearClient(url, options)
: getTheGraphEvmClient(url, options);

export const getTheGraphEvmClient = (url: string, options?: TheGraphClientOptions) => {
const sdk: TheGraphClient<CurrencyTypes.EvmChainName> = getSdk(
new GraphQLClient(url, extractClientOptions(options)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
} from '@requestnetwork/types';
import { CurrencyManager } from '@requestnetwork/currency';
import { ERC20__factory } from '@requestnetwork/smart-contracts/types';
import { AnyToERC20PaymentDetector, getTheGraphEvmClient } from '../../src';
import { AnyToERC20PaymentDetector, TheGraphClient } from '../../src';
import { mockAdvancedLogicBase } from '../utils';

jest.mock('../../src/thegraph/client');
const theGraphClientMock = jest.mocked(getTheGraphEvmClient(''));
const theGraphClientMock = {
GetAnyToFungiblePayments: jest.fn(),
} as jest.MockedObjectDeep<TheGraphClient>;

let anyToErc20Proxy: AnyToERC20PaymentDetector;
const currencyManager = CurrencyManager.getDefault();
Expand Down
7 changes: 5 additions & 2 deletions packages/payment-detection/test/any/any-to-eth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { CurrencyManager } from '@requestnetwork/currency';
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { AnyToEthFeeProxyPaymentDetector } from '../../src/any';
import { getTheGraphEvmClient } from '../../src/thegraph';
import { getTheGraphEvmClient, TheGraphClient } from '../../src/thegraph';

const getLogs = jest.spyOn(StaticJsonRpcProvider.prototype, 'getLogs');

jest.mock('../../src/thegraph/client');
const theGraphClientMock = jest.mocked(getTheGraphEvmClient(''));
const theGraphClientMock = {
GetAnyToNativePayments: jest.fn(),
} as jest.MockedObjectDeep<TheGraphClient>;

describe('Any to ETH payment detection', () => {
const mockRequest: RequestLogicTypes.IRequest = {
creator: { type: IdentityTypes.TYPE.ETHEREUM_ADDRESS, value: '0x2' },
Expand Down
7 changes: 5 additions & 2 deletions packages/payment-detection/test/erc20/proxy-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from '@requestnetwork/types';
import { CurrencyManager } from '@requestnetwork/currency';
import { ERC20ProxyPaymentDetector } from '../../src/erc20';
import { getTheGraphEvmClient } from '../../src';
import { mockAdvancedLogicBase } from '../utils';
import { TheGraphClient } from '../../src';

let erc20ProxyContract: ERC20ProxyPaymentDetector;

Expand All @@ -18,7 +18,10 @@ const createAddPaymentInstructionAction = jest.fn();
const createAddRefundInstructionAction = jest.fn();

jest.mock('../../src/thegraph/client');
const theGraphClientMock = jest.mocked(getTheGraphEvmClient(''));
const theGraphClientMock = {
GetPaymentsAndEscrowState: jest.fn(),
} as jest.MockedObjectDeep<TheGraphClient>;

const mockAdvancedLogic: AdvancedLogicTypes.IAdvancedLogic = {
...mockAdvancedLogicBase,
extensions: {
Expand Down
4 changes: 2 additions & 2 deletions packages/payment-detection/test/eth/input-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
PaymentTypes,
RequestLogicTypes,
} from '@requestnetwork/types';
import { getTheGraphEvmClient } from '../../src/thegraph';
import { TheGraphClient } from '../../src/thegraph';
import { EthInputDataPaymentDetector } from '../../src/eth/input-data';
import { mockAdvancedLogicBase } from '../utils';

jest.mock('../../src/thegraph/client');
const theGraphClientMock = jest.mocked(getTheGraphEvmClient(''));
const theGraphClientMock = {} as jest.MockedObjectDeep<TheGraphClient>;

let ethInputData: EthInputDataPaymentDetector;

Expand Down

0 comments on commit 2e4a962

Please sign in to comment.