Skip to content

Commit

Permalink
fix: transferable receivable test
Browse files Browse the repository at this point in the history
  • Loading branch information
yomarion committed Mar 24, 2023
1 parent 2a73ddf commit 8f93b49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
7 changes: 6 additions & 1 deletion packages/payment-detection/src/thegraph/info-retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TheGraphInfoRetriever<TGraphQuery extends TransferEventsParams = Tr
params: TGraphQuery,
): Promise<PaymentTypes.AllNetworkEvents<PaymentTypes.IERC20FeePaymentEventParameters>> {
if (params.acceptedTokens && params.acceptedTokens.length > 1) {
throw new Error('TheGraphInfoRetriever can only be called with no or 1 acceptedToken.');
throw new Error('TheGraphInfoRetriever only supports no or 1 acceptedToken.');
}
const { payments, escrowEvents } = await this.client.GetPaymentsAndEscrowState({
reference: utils.keccak256(`0x${params.paymentReference}`),
Expand All @@ -41,8 +41,13 @@ export class TheGraphInfoRetriever<TGraphQuery extends TransferEventsParams = Tr
public async getReceivableEvents(
params: TGraphQuery,
): Promise<PaymentTypes.AllNetworkEvents<PaymentTypes.IERC20FeePaymentEventParameters>> {
if (params.acceptedTokens && params.acceptedTokens.length > 1) {
throw new Error('TheGraphInfoRetriever only supports no or 1 acceptedToken.');
}
const { payments, escrowEvents } = await this.client.GetPaymentsAndEscrowStateForReceivables({
reference: utils.keccak256(`0x${params.paymentReference}`),
tokenAddress: params.acceptedTokens ? params.acceptedTokens[0].toLowerCase() : null,
contractAddress: params.contractAddress.toLowerCase(),
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ query GetAnyToNativePayments(
}

# Receivables can be transferred to different owners, so searching by to could drop balance events.
query GetPaymentsAndEscrowStateForReceivables($reference: Bytes!) {
payments(where: { reference: $reference }, orderBy: timestamp, orderDirection: asc) {
query GetPaymentsAndEscrowStateForReceivables(
$reference: Bytes!
$tokenAddress: Bytes!
$contractAddress: Bytes!
) {
payments(
where: { reference: $reference, tokenAddress: $tokenAddress, contractAddress: $contractAddress }
orderBy: timestamp
orderDirection: asc
) {
...PaymentEventResult
}
escrowEvents(where: { reference: $reference }, orderBy: timestamp, orderDirection: asc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,21 +397,6 @@ describe('api/erc20/transferable-receivable-contract', () => {

const paymentsMockData = {
[hashedReference as string]: [
// Correct reference but incorrect contract
{
contractAddress: '0x186e7fe6c34ea0eca7f9c2fd29651fc0443e3f32',
to: paymentAddress,
from: '0x186e7fe6c34ea0eca7f9c2fd29651fc0443e3f29',
amount: '30000000000000',
feeAmount: '0',
reference: hashedReference,
block: 9606098,
txHash: '0x3e2d6cc2534b1d340ba2954f34e6cc819d6da64ff76863ea89c6d34b15d13c97',
feeAddress: feeAddress,
gasPrice: '',
gasUsed: '',
timestamp: 1,
},
// Correct reference and contract
{
contractAddress: erc20LocalhostContractAddress,
Expand Down

0 comments on commit 8f93b49

Please sign in to comment.