-
Notifications
You must be signed in to change notification settings - Fork 41
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
intercept and mock e2e swaps calls #1754
Open
greg-schrammel
wants to merge
28
commits into
master
Choose a base branch
from
greg-mock-swap-e2e
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+612
−128
Open
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
db0810f
prevent useSwapSlippage from making unnecessary requests
greg-schrammel 9164172
test
greg-schrammel 1cd7b09
response
greg-schrammel 2119c2d
popular in rainbow
greg-schrammel a5e1c8f
dad can you come pick me up im scared
greg-schrammel 8624638
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes 1752d7f
yarn setup ran lol
BrodyHughes 5efb232
hmm
BrodyHughes becb035
fix test 1, test test 2
BrodyHughes 06942ad
logging
BrodyHughes 52efb0b
skip test
BrodyHughes 37d9f68
okay
BrodyHughes 5675d1a
audit fix
BrodyHughes 74e8084
yarn install
BrodyHughes e9d33be
fix send
BrodyHughes 1c3e162
reenable retries
BrodyHughes 37d7bfc
add all mocks, fix unit tests by making them use hardhat now
BrodyHughes 64d38ff
rm retry:0
BrodyHughes 4030edf
clean up
BrodyHughes 235db69
check vlock number add new hashed responses
BrodyHughes 0de1dfa
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes 25d7ebd
tweak script and get new responses + yarn install
BrodyHughes 924befc
okay point the script at the anvil instance instead of our prod key
BrodyHughes aff68a2
undo the removal of chainIds from testIds (#1779)
BrodyHughes c3a70cc
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes 6995691
bad merge oops
BrodyHughes d988f48
Merge branch 'master' into greg-mock-swap-e2e
BrodyHughes 60196a9
failOnError: false
BrodyHughes 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 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,29 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
// this file is ran locally with ts-node to fetch the responses from the swap quotes urls | ||
require('dotenv').config(); | ||
const { writeFile } = require('fs/promises'); | ||
|
||
const { createClient, http, sha256 } = require('viem'); | ||
const { getBlockNumber } = require('viem/actions'); | ||
|
||
const urls = require('./mocks/mock_swap_quotes_urls.json'); | ||
|
||
(async () => { | ||
const client = createClient({ transport: http(process.env.ETH_MAINNET_RPC) }); | ||
const blockNumber = await getBlockNumber(client); | ||
|
||
// check initial blockNumber | ||
console.log('OUTSIDE FUNCTION', blockNumber.toString()); | ||
|
||
await Promise.all( | ||
urls.map(async (url: RequestInfo | URL) => { | ||
const res = await fetch(url).then((r) => r.text()); | ||
const hash = sha256(url); | ||
|
||
// check if blockNumber is the same the entire time | ||
console.log('INSIDE FUNCTION', blockNumber.toString()); | ||
BrodyHughes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await writeFile(`e2e/mocks/swap_quotes/${hash}.json`, res); | ||
}), | ||
); | ||
})(); |
This file contains 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,38 @@ | ||
import { Hex, sha256 } from 'viem'; | ||
|
||
export function mockFetch() { | ||
const nativeFetch = window.fetch; | ||
window.fetch = async function mockedFetch( | ||
input: RequestInfo | URL, | ||
init?: RequestInit, | ||
) { | ||
if (input instanceof Request || !URL.canParse(input)) | ||
return nativeFetch(input, init); | ||
|
||
const url = new URL(input); | ||
|
||
if (url.hostname === 'swap.p.rainbow.me') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intercepts requests to |
||
console.log('Intercepting swap request:', { | ||
url: url.href, | ||
params: Object.fromEntries(url.searchParams), | ||
}); | ||
|
||
const hash = sha256(url.href as Hex); | ||
console.log('Looking for mock file with hash:', hash); | ||
|
||
const response = await import(`./mocks/swap_quotes/${hash}.json`); | ||
console.log('Mock response:', response); | ||
|
||
if (!response) | ||
throw new Error('no response for request', { | ||
cause: { url: url.href, hash }, | ||
}); | ||
|
||
return new Response(JSON.stringify(response), { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
} | ||
|
||
return nativeFetch(input, init); | ||
}; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...mocks/swap_quotes/0x038dce7884e70b272cd1e2451c7ac6c7acead26c6fbd4593ac6840211a966072.json
This file contains 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 @@ | ||
{"error":true,"error_code":504,"message":"no routes found"} |
1 change: 1 addition & 0 deletions
1
...mocks/swap_quotes/0x05b313c513342f25909168d9f4116a1473a0e7b4d661ef5f420cf46fd919813b.json
This file contains 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 @@ | ||
{"data":{"slippagePercent":2}} |
1 change: 1 addition & 0 deletions
1
...mocks/swap_quotes/0x075d7d1eefb1fad7a225af737745bc9a5a099d33eacbce33d15ff5419eccd0fc.json
This file contains 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 @@ | ||
{"sellTokenAddress":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","sellTokenAsset":{"assetCode":"eth","decimals":18,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/ethereum/eth.png","name":"Ethereum","network":"mainnet","symbol":"ETH","networks":{"1":{"address":"eth","decimals":18},"10":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"42161":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"56":{"address":"0x2170ed0880ac9a755fd29b2688956bd959f933f8","decimals":18},"7777777":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"81457":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"8453":{"address":"0x0000000000000000000000000000000000000000","decimals":18}},"chainId":1,"price":{"value":3582.92,"available":true},"totalPrice":{"value":358292002.19248796,"available":true}},"buyTokenAddress":"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599","buyTokenAsset":{"assetCode":"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599","decimals":8,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1693266228/assets/ethereum/0x2260fac5e5542a773aa44fbcfedf7c193bc2c599.png","name":"Wrapped Bitcoin","network":"mainnet","symbol":"WBTC","networks":{"1":{"address":"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599","decimals":8},"10":{"address":"0x68f180fcce6836688e9084f035309e29bf0a2095","decimals":8},"137":{"address":"0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6","decimals":8},"42161":{"address":"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f","decimals":8},"43114":{"address":"0x50b7545627a5162f82a992c33b87adc75187b218","decimals":8},"81457":{"address":"0xf7bc58b8d8f97adc129cfc4c9f45ce3c0e1d2692","decimals":8}},"chainId":1,"price":{"value":95075.26989325,"available":true},"totalPrice":{"value":73751688.77119744,"available":true}},"allowanceTarget":"0x00000000009726632680fb29d3f7a9734e3010e2","allowanceNeeded":false,"to":"0xdef1c0ded9bec7f1a1670819833240f027b25eff","data":"0x415565b0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000014feeeab6899a69b0be700000000000000000000000000000000000000000000000000000011e1570d3300000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000e400000000000000000000000000000000000000000000000000000000000000f400000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000014feeeab6899a69b0be7000000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000ca000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000c600000000000000000000000000000000000000000000000000000000000000c600000000000000000000000000000000000000000000000000000000000000b600000000000000000000000000000000000000000000014feeeab6899a69b0be700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c60000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000006200000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000012556e69737761705633000000000000000000000000000000000000000000000000000000000001931eb34171ec79f218000000000000000000000000000000000000000000000000000000055f94a0ef000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000e592427a0aece92de3edee1f18e0157c0586156400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb82260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000000000000000000000000000000000000000000000012556e69737761705633000000000000000000000000000000000000000000000000000000000001931eb34171ec79f21800000000000000000000000000000000000000000000000000000004dc50b4fc000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000e592427a0aece92de3edee1f18e0157c0586156400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000000000000000253757368695377617000000000000000000000000000000000000000000000000000000000000865f9115d0a42b3112a000000000000000000000000000000000000000000000000000000038c8b93f7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000002556e6973776170563200000000000000000000000000000000000000000000000000000000000432fc88ae852159889500000000000000000000000000000000000000000000000000000001add32015000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000f164fc0ec4e93095b804a4795bbe1e041497b92a00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000014437572766556320000000000000000000000000000000000000000000000000000000000000003263d6682e3d8f3e430000000000000000000000000000000000000000000000000000000016c3bff3900000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000080000000000000000000000000d51a44d3fae010294c616388b506acda1bfaae465b41b90800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000001c42616e636f72563300000000000000000000000000000000000000000000000000000000000001931eb34171ec79f21800000000000000000000000000000000000000000000000000000000b9111930000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000eef417e1d5cc832e619ae18d2f140de2999dd4fb00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000012556e69737761705633000000000000000000000000000000000000000000000000000000000000865f9115d0a42cb7b3000000000000000000000000000000000000000000000000000000004ca6419d000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb8dac17f958d2ee523a2206206994597c13d831ec7000bb82260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000006e056ce000000000000000000000000ad01c20d5886137e056775af56915de824c8fce5000000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000000000000000000000000000012168593e400000000000000000000000069d6d375de8c7ade7e44446df97f49e661fdad7d000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000000aef01038b44e7f2cedf16dd","sellAmount":"100000000611927694623603","sellAmountMinusFees":"99150000606726309219303","sellAmountDisplay":"100000000611927694623603","sellAmountInEth":"100000000611927694622720","buyAmount":"77571895251","buyAmountMinusFees":"77571895251","buyAmountDisplay":"77571895251","buyAmountDisplayMinimum":"76796176299","buyAmountInEth":"20584241002086966155264","tradeAmountUSD":358292002.19248796,"tradeFeeAmountUSD":3045482.018636148,"value":"100000000611927694623603","gasPrice":"30015947302","source":"0x","protocols":[{"name":"SushiSwap","part":40},{"name":"Uniswap_V3","part":17.5},{"name":"Curve_V2","part":15},{"name":"Uniswap_V2","part":20},{"name":"BancorV3","part":7.5}],"feeTokenAsset":{"assetCode":"eth","decimals":18,"iconUrl":"https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/ethereum/eth.png","name":"Ethereum","network":"mainnet","symbol":"ETH","networks":{"1":{"address":"eth","decimals":18},"10":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"42161":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"56":{"address":"0x2170ed0880ac9a755fd29b2688956bd959f933f8","decimals":18},"7777777":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"81457":{"address":"0x0000000000000000000000000000000000000000","decimals":18},"8453":{"address":"0x0000000000000000000000000000000000000000","decimals":18}},"chainId":1,"price":{"value":3582.92,"available":true},"totalPrice":{"value":3045482.018636148,"available":true}},"fee":"850000005201385404300","feeInEth":"850000005201385404288","feePercentageBasisPoints":"8500000000000000","tradeType":"exact_input","from":"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720","defaultGasLimit":"350000","swapType":"normal","txTarget":"0x00000000009726632680fb29d3f7a9734e3010e2","chainId":1} |
1 change: 1 addition & 0 deletions
1
...mocks/swap_quotes/0x07feb3d58cf9bbbcc846d008e73c739e2a1a737497781513fe28049fc588da14.json
This file contains 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 @@ | ||
{"data":{"slippagePercent":2}} |
1 change: 1 addition & 0 deletions
1
...mocks/swap_quotes/0x08c6cc57e3fba32a3b2caea0dd4303370f9b4a58c389da6e30cfb5b32b70770b.json
This file contains 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 @@ | ||
{"data":{"slippagePercent":2}} |
Oops, something went wrong.
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.
Ran locally to get swap_quotes outputs