-
Notifications
You must be signed in to change notification settings - Fork 91
fix: detection conversion currency check #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c878bc8
fix(payment-detection): conversion queries should filter request curr…
yomarion 4980eaf
fix test
yomarion 7c7bbe5
fix types
yomarion 07188a1
test passing
yomarion 0b10d30
fix minor type issue
yomarion ac05e7d
Merge branch 'master' into fix/detection-conversion-currency-check
yomarion 6c18cf8
fix: test info-retriever
yomarion e3e09be
fix: any-to-eth graph query method
yomarion ba405fd
Merge branch 'master' into fix/detection-conversion-currency-check
yomarion 3401a8d
chore: use the retriever inheritance
yomarion 6ef8f17
fix: test
yomarion 792dff7
fix: test
yomarion 8dee6f6
fix imports and address case
yomarion a288926
fix: transferable receivable test
yomarion 26ba83b
fix: fee-proxy detector
yomarion 0f18122
--amend
yomarion 4111b2d
added scheduled eth and any-to-eth payment detection
yomarion 2a73ddf
fix: missing escrowEvents in test
yomarion 8f93b49
fix: transferable receivable test
yomarion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/integration-test/test/scheduled/any-to-erc20-detector.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { PaymentNetworkFactory } from '@requestnetwork/payment-detection'; | ||
| import { CurrencyTypes, PaymentTypes, RequestLogicTypes } from '@requestnetwork/types'; | ||
| import { CurrencyManager } from '@requestnetwork/currency'; | ||
|
|
||
| import { mockAdvancedLogic } from './mocks'; | ||
| import { createMockConversionErc20Request } from '../utils'; | ||
|
|
||
| const pnFactory = new PaymentNetworkFactory(mockAdvancedLogic, CurrencyManager.getDefault()); | ||
|
|
||
| const paidEURRequest = { | ||
| network: 'matic' as CurrencyTypes.EvmChainName, | ||
| requestId: '0117d7a59a48e5031b3c56c92621453149e4a4462dba6eaeb3271a995c4201448b', | ||
| paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93', | ||
| salt: '5ddb1c1645ac2daf', | ||
| tokenAddress: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', // DAI on matic | ||
| feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7', | ||
| feeAmount: '0', | ||
| currency: { | ||
| type: RequestLogicTypes.CURRENCY.ISO4217, | ||
| value: 'EUR', | ||
| }, | ||
| }; | ||
|
|
||
| describe('Any to ERC20 Fee Proxy detection test-suite', () => { | ||
| it('can getBalance on a matic request with TheGraph', async () => { | ||
| const mockRequest = createMockConversionErc20Request(paidEURRequest); | ||
| const paymentDetector = pnFactory.getPaymentNetworkFromRequest(mockRequest); | ||
| expect(paymentDetector).toBeDefined(); | ||
|
|
||
| const balance = await paymentDetector!.getBalance(mockRequest); | ||
|
|
||
| expect(balance.balance).toBe('10'); | ||
| expect(balance.events).toHaveLength(1); | ||
| expect(balance.events[0].name).toBe('payment'); | ||
| const params = balance.events[0].parameters as PaymentTypes.IERC20FeePaymentEventParameters; | ||
| expect(params?.to).toBe('0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93'); | ||
| expect(balance.events[0].amount).toBe('10'); | ||
| expect(balance.events[0].timestamp).toBe(1679579206); | ||
| }); | ||
|
|
||
| it('cannot trick getBalance with a payment denominated in the wrong currency', async () => { | ||
| const mockRequest = createMockConversionErc20Request({ | ||
| ...paidEURRequest, | ||
| currency: { | ||
| type: RequestLogicTypes.CURRENCY.ISO4217, | ||
| value: 'JPY', | ||
| }, | ||
| }); | ||
| const paymentDetector = pnFactory.getPaymentNetworkFromRequest(mockRequest); | ||
| expect(paymentDetector).toBeDefined(); | ||
|
|
||
| const balance = await paymentDetector!.getBalance(mockRequest); | ||
|
|
||
| expect(balance.balance).toBe('0'); | ||
| expect(balance.events).toHaveLength(0); | ||
| }); | ||
| }); | ||
56 changes: 56 additions & 0 deletions
56
packages/integration-test/test/scheduled/any-to-eth-detector.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { PaymentNetworkFactory } from '@requestnetwork/payment-detection'; | ||
| import { CurrencyTypes, PaymentTypes, RequestLogicTypes } from '@requestnetwork/types'; | ||
| import { CurrencyManager } from '@requestnetwork/currency'; | ||
|
|
||
| import { mockAdvancedLogic } from './mocks'; | ||
| import { createMockConversionEthTokenRequest } from '../utils'; | ||
|
|
||
| const pnFactory = new PaymentNetworkFactory(mockAdvancedLogic, CurrencyManager.getDefault()); | ||
|
|
||
| const paidEURRequest = { | ||
| network: 'matic' as CurrencyTypes.EvmChainName, | ||
| requestId: '01814304b39265cbf0c2abb4f3c7e8432d1e2c8779be6022e545d25f95144360e0', | ||
| paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93', | ||
| salt: 'b3f2e478374bff64', | ||
| feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7', | ||
| feeAmount: '0', | ||
| currency: { | ||
| type: RequestLogicTypes.CURRENCY.ISO4217, | ||
| value: 'EUR', | ||
| }, | ||
| }; | ||
|
|
||
| describe('Any to ETH Fee Proxy detection test-suite (with a TheGraph Retriever)', () => { | ||
| it('can getBalance on a matic request', async () => { | ||
| const mockRequest = createMockConversionEthTokenRequest(paidEURRequest); | ||
|
|
||
| const detector = pnFactory.getPaymentNetworkFromRequest(mockRequest); | ||
| expect(detector).not.toBeNull(); | ||
| const balance = await detector!.getBalance(mockRequest); | ||
|
|
||
| expect(balance.balance).toBe('500'); // 5 EUR | ||
| expect(balance.events).toHaveLength(1); | ||
| expect(balance.events[0].name).toBe('payment'); | ||
| const params = balance.events[0].parameters as PaymentTypes.ETHPaymentNetworkEventParameters; | ||
| expect(params?.to).toBe('0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93'); | ||
| expect(balance.events[0].amount).toBe('500'); | ||
| expect(balance.events[0].timestamp).toBe(1679673909); | ||
| }); | ||
|
|
||
| it('cannot trick getBalance with a payment denominated in the wrong currency', async () => { | ||
| const mockRequest = createMockConversionEthTokenRequest({ | ||
| ...paidEURRequest, | ||
| currency: { | ||
| type: RequestLogicTypes.CURRENCY.ISO4217, | ||
| value: 'USD', | ||
| }, | ||
| }); | ||
|
|
||
| const detector = pnFactory.getPaymentNetworkFromRequest(mockRequest); | ||
| expect(detector).not.toBeNull(); | ||
| const balance = await detector!.getBalance(mockRequest); | ||
|
|
||
| expect(balance.balance).toBe('0'); | ||
| expect(balance.events).toHaveLength(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was failing 😱