From e4288f8b7666708aa5f1c9ee60b503b55ab551f0 Mon Sep 17 00:00:00 2001 From: Adam Lessey Date: Sat, 2 Nov 2024 00:43:38 -0400 Subject: [PATCH] chore: mock --- .../components/OnchainProviders.tsx | 675 +++++++++++++++++- src/OnchainKitProvider.tsx | 7 + src/internal/utils/mockFetch.ts | 40 ++ src/types.ts | 4 + 4 files changed, 722 insertions(+), 4 deletions(-) create mode 100644 src/internal/utils/mockFetch.ts diff --git a/playground/nextjs-app-router/components/OnchainProviders.tsx b/playground/nextjs-app-router/components/OnchainProviders.tsx index f7cb4f1770..60dff06f99 100644 --- a/playground/nextjs-app-router/components/OnchainProviders.tsx +++ b/playground/nextjs-app-router/components/OnchainProviders.tsx @@ -6,16 +6,23 @@ import type { ReactNode } from 'react'; import { http, createConfig } from 'wagmi'; import { WagmiProvider } from 'wagmi'; import { base, baseSepolia } from 'wagmi/chains'; -import { coinbaseWallet } from 'wagmi/connectors'; +import { coinbaseWallet, mock } from 'wagmi/connectors'; -export const config = createConfig({ +export const getConfig = (mocks: boolean) => createConfig({ chains: [base, baseSepolia], transports: { [base.id]: http(), [baseSepolia.id]: http(), }, ssr: true, - connectors: [ + connectors: mocks ? [ + mock({ + accounts: ['0xbB68Fc6d7469899dC8eb79Ad2895B16Ec36dF5Fe'], // smart wallet mock + }), + mock({ + accounts: ['0xbB68Fc6d7469899dC8eb79Ad2895B16Ec36dF5Fe'], // eoa mock + }) + ] : [ coinbaseWallet({ appName: 'OnchainKit', preference: 'smartWalletOnly', @@ -27,11 +34,670 @@ export const config = createConfig({ ], }); +const mocks = new Map([ + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_getBalance/ + }, + response: { + delay: 1000, + status: 200, + json: { + "id": 0, + "jsonrpc": "2.0", + "result":"0x120724dcd370b7" + } + } + }], + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_call/ + }, + response: { + delay: 2000, + status: 200, + json: { + "id":1, + "jsonrpc":"2.0", + "result": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000001f2770" + } + } + }], + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_sendTransaction/ + }, + response: { + delay: 2000, + status: 200, + json: { + "id":1, + "jsonrpc":"2.0", + "result": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000001f2770" + } + } + }], + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_blockNumber/ + }, + response: { + delay: 2000, + status: 200, + json: {"jsonrpc":"2.0","result":"0x14e94aa","id":2} + } + }], + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_estimateGas/ + }, + response: { + delay: 2000, + status: 200, + json: {"jsonrpc":"2.0","result":"0x22ae7","id":2} + } + }], + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_getTransactionByHash/ + }, + response: { + delay: 2000, + status: 200, + json: { + "jsonrpc": "2.0", + "result": { + "accessList": [], + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "chainId": "0x2105", + "from": "0xfbd85a0c200b286ef2d7a08306113669013c39da", + "gas": "0x15fec8", + "gasPrice": "0x8d5533", + "hash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "input": "0x1fad948c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000fbd85a0c200b286ef2d7a08306113669013c39da0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000005600000000000000000000000000000000000000000000000000000000000000a800000000000000000000000000000000000000000000000000000000000000fa0000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e000000000000000000000000000000000000000000000000000000000000004d00000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000001f365000000000000000000000000000000000000000000000000000000000001687a000000000000000000000000000000000000000000000000000000000002325a0000000000000000000000000000000000000000000000000000000000a6a6bf00000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000000460000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a4b61d27f6000000000000000000000000017405a2de0613e12cd3d7b67e691bfefc46debf000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000104ebefad06000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000006727888b000000000000000000000000000000000000000000000000000000000000001c0226e2abae86f438dda6189bc189eeba499e801420226ca7cf98c5f9e76e4a82207b449df021d5d21223e7f5fc5bb37bc2fd45b5f6d142b698a56943b77ad9f000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c22faeb0760d4230ef2ac21496bb4f0b47d634fd4c0000672786ab00000000000037233018550b44e3af73c8dc20a6213f000100b676f87a6e701f0de8de5ab91b56b66109766db195796e0d139d02eb0d89a79ca2938f79dd324a2e000000000000000000000000000000000000000000000114afc3d30fdc194a00000000006978b49af979d378bf70d416121c9b884df72fc104662df53dd9f281813c9fd4bbce54319dc9f4ef4cc64f24243e7afebcb7a40bfcc70fb8df8042b1983fb4f76f9d1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041c63c3c875840e51ba6d337517e86762cd86b5c666ef29530ebdd112eb01eb9f234f5ff97c03963e39a2c90e303d6ad58bc158d7dcf4e172cb98a502de6c47c081c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000a6e1cbd4a0e55523d00099b118d17c98fa3b1a1a00000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000045e0000000000000000000000000000000000000000000000000000000000001687a00000000000000000000000000000000000000000000000000000000000266b30000000000000000000000000000000000000000000000000000000000a6abdb00000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000244b61d27f60000000000000000000000004af334f9ae78edd787750063b22a2eaefdbcd3ee0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a48c7a3e2c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000002463383930386364302d363064382d346366642d393361342d35393835613961386264303300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867616d654c6f61640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b71c755b47dda53ea53419bd88a214c19035b1e706bf2a288a1b98bfdfa208ad754baeea93553ba856632f743671c6eeedb614b9fda7d091ead6f19d0f3891438fdc937212fddd82d328554f311475af5c71be291a9dca47a8eb7352cdb081c354d5bcf212434c83bded0c8a8bb6e0ebdab804c0298118ef0f9fae7ad1ff8d2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000072a270ef92c1e11f1c1f95753c2e56801e8125fa830000672786ac000000000000009897aa0000003635c9adc5dea0000000a586b11a206fb0c2f3686e757f13d3bacffc1253d15fb3386b3ed4f3582e001737453269b1809e5213e26726b526ba1c7089de84f4d3fbb2e445e007fa8332401b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004128e0e903246dc27ba45fdd258de7c574f2ae749278efb36ee2b98c33aa8bae1505b23a0f50682a3e04fe8bb92f946ed027331ec2456ef1d22f55e62bf44abb721c000000000000000000000000000000000000000000000000000000000000000000000000000000000000006593b5a738344a847b9d5ba79912fbb7a34f4bc200000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000045e0000000000000000000000000000000000000000000000000000000000001687a00000000000000000000000000000000000000000000000000000000000266c50000000000000000000000000000000000000000000000000000000000a6a6bf00000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000244b61d27f6000000000000000000000000974474c8bcb36302be93858466728271fb36544e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a48c7a3e2c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000002464316430363265662d333036302d343062632d383962662d66666130323365316233376300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867616d654c6f61640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b71c755b47dda53ea53419bd88a214c19035b1e706bf2a288a1b98bfdfa208ad754baeea93553ba856632f743671c6eeedb614b9fda7d091ead6f19d0f3891438fdc937212fddd82d328554f311475af5c71be291a9dca47a8eb7352cdb081c354d5bcf212434c83bded0c8a8bb6e0ebdab804c0298118ef0f9fae7ad1ff8d2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000072a270ef92c1e11f1c1f95753c2e56801e8125fa830000672786ab000000000000009897aa0000003635c9adc5dea00000005845c10293c1e3f59f1b4ed477e930f6003b1c6f657a639b83af7483c0d72b7b16216c9c8f239a105a03ecf557380258c376d9f5005e8bb9c8b9ba64f403739f1c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000412c905c2afa2466e283c19522921f98c375912a2d5272c6488d4d2d79aff1607b136604dc918ab87de91a39c2f11296d080ebf65d964ea18aaf4c8f915768d2501b000000000000000000000000000000000000000000000000000000000000000000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce000000000000000000000000000000000000000000000000000000000000001f000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000022ee0000000000000000000000000000000000000000000000000000000000008a29c000000000000000000000000000000000000000000000000000000000002b2ca00000000000000000000000000000000000000000000000000000000009e467f00000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000054000000000000000000000000000000000000000000000000000000000000005600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038534fcd5be0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad00000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000026424856bc30000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000024da9a00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b4200000000000000000000000000000000000006000064833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e15b0a8c44ecad456533d0110ead2ce000e15b0a8c44ecad456533d0110ead2ce0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000018e45501a5e1ad92afe3ac934c2aafca8622bb05d03ea4d376defb7bed8b1a769028d9765eb961b8a16e8163abbbfc59a6b821a9f372286b1e260e70c58ba913c0000000000000000000000000000000000000000000000000000000000000025f198086b2db17256731bc456673b96bcef23f51d1fbacdd7c4379ef65465572f050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f77b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a22584136642d4b765053482d4a4d4a6f6c53505962573630354f6234324459614136504b4b4c77344c434634222c226f726967696e223a2268747470733a2f2f6b6579732e636f696e626173652e636f6d222c2263726f73734f726967696e223a66616c73652c226f746865725f6b6579735f63616e5f62655f61646465645f68657265223a22646f206e6f7420636f6d7061726520636c69656e74446174614a534f4e20616761696e737420612074656d706c6174652e205365652068747470733a2f2f676f6f2e676c2f796162506578227d000000000000000000", + "maxFeePerGas": "0x10b7d10", + "maxPriorityFeePerGas": "0xf4240", + "nonce": "0x1a8e35", + "r": "0x1b93cf52b0c79278dfdcd6d6fcf9d30ab98f2fcf863d3f0cc7bad2982ca51901", + "s": "0x546e30451c17729ba88c25d91760c74220c0fe6fe0783adccbc32a32e201db7e", + "to": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "transactionIndex": "0x52", + "type": "0x2", + "v": "0x0", + "value": "0x0", + "yParity": "0x0" + }, + "id": 3 + } + } + }], + [/^https:\/\/mainnet\.base\.org.*/, { + matchParams: { + body: /eth_getTransactionReceipt/ + }, + response: { + delay: 2000, + status: 200, + json: { + "jsonrpc": "2.0", + "result": { + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "contractAddress": null, + "cumulativeGasUsed": "0xe0ff6a", + "effectiveGasPrice": "0x8d5533", + "from": "0xfbd85a0c200b286ef2d7a08306113669013c39da", + "gasUsed": "0x8b2e9", + "l1BaseFeeScalar": "0x8dd", + "l1BlobBaseFee": "0x1ddf86", + "l1BlobBaseFeeScalar": "0x101c12", + "l1Fee": "0xe7ece4de9a", + "l1GasPrice": "0x38fdfc3f4", + "l1GasUsed": "0x6fad", + "logs": [ + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x", + "logIndex": "0xd6", + "removed": false, + "topics": [ + "0xbb47ee3e183a558b1a2ff0874b079f3fc5478b7454eacf2bfc5af2ff5878f972" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x0982b3a5b24b2bd8ef74126e15fca2decfd75a28", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x", + "logIndex": "0xd7", + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000017405a2de0613e12cd3d7b67e691bfefc46debf", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x00000000000000000000000000000000000000000000000000000000001c7e8b" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x017405a2de0613e12cd3d7b67e691bfefc46debf", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000000000001c7e8b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000067278637", + "logIndex": "0xd8", + "removed": false, + "topics": [ + "0x38dec76e9092e477174a0cb4853dc54e13726bedc62922b9f2cbb292bdabbece", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0xb676f87a6e701f0de8de5ab91b56b66109766db1", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000003625d1534f8c513cfb", + "logIndex": "0xd9", + "removed": false, + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x0000000000000000000000002faeb0760d4230ef2ac21496bb4f0b47d634fd4c" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0xb676f87a6e701f0de8de5ab91b56b66109766db1", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000398df7658854e9", + "logIndex": "0xda", + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x00000000000000000000000095796e0d139d02eb0d89a79ca2938f79dd324a2e" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x2faeb0760d4230ef2ac21496bb4f0b47d634fd4c", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000095796e0d139d02eb0d89a79ca2938f79dd324a2e00000000000000000000000000000000000000000000000000398df7658854e9", + "logIndex": "0xdb", + "removed": false, + "topics": [ + "0xe2459e4c2a3c2f358a092e76af1f3b2337c91875a1d49fe8afd6126342444f6f", + "0x3787e0840694197e889ce6502fd4427fbcd80c000c9bbf3d6c32b7232cdeaaf5", + "0x0000000000000000000000000000000037233018550b44e3af73c8dc20a6213f", + "0x000000000000000000000000b676f87a6e701f0de8de5ab91b56b66109766db1" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x000000000000000000000000000000000000000000000000000000000000004d0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000002e3b8d9a2d30000000000000000000000000000000000000000000000000000000000053be1", + "logIndex": "0xdc", + "removed": false, + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0x3787e0840694197e889ce6502fd4427fbcd80c000c9bbf3d6c32b7232cdeaaf5", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x0000000000000000000000002faeb0760d4230ef2ac21496bb4f0b47d634fd4c" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x4af334f9ae78edd787750063b22a2eaefdbcd3ee", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000002463383930386364302d363064382d346366642d393361342d35393835613961386264303300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867616d654c6f61640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b71c755b47dda53ea53419bd88a214c19035b1e706bf2a288a1b98bfdfa208ad754baeea93553ba856632f743671c6eeedb614b9fda7d091ead6f19d0f3891438fdc937212fddd82d328554f311475af5c71be291a9dca47a8eb7352cdb081c354d5bcf212434c83bded0c8a8bb6e0ebdab804c0298118ef0f9fae7ad1ff8d25", + "logIndex": "0xdd", + "removed": false, + "topics": [ + "0x729fedf706b78debb34ef30843b5dae81b19d0ee8dbdd5457b925ac843c2e0e9" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000001e1f3ad969b00000000000000000000000000000000000000000000000000000000000368f9", + "logIndex": "0xde", + "removed": false, + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0xad8e5bb6dee968d8a77f5b1d0ccd43c53acda3539712dcf4f5830a9ad408c84b", + "0x000000000000000000000000a6e1cbd4a0e55523d00099b118d17c98fa3b1a1a", + "0x000000000000000000000000a270ef92c1e11f1c1f95753c2e56801e8125fa83" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x974474c8bcb36302be93858466728271fb36544e", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000002464316430363265662d333036302d343062632d383962662d66666130323365316233376300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867616d654c6f61640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b71c755b47dda53ea53419bd88a214c19035b1e706bf2a288a1b98bfdfa208ad754baeea93553ba856632f743671c6eeedb614b9fda7d091ead6f19d0f3891438fdc937212fddd82d328554f311475af5c71be291a9dca47a8eb7352cdb081c354d5bcf212434c83bded0c8a8bb6e0ebdab804c0298118ef0f9fae7ad1ff8d25", + "logIndex": "0xdf", + "removed": false, + "topics": [ + "0x729fedf706b78debb34ef30843b5dae81b19d0ee8dbdd5457b925ac843c2e0e9" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000001be14e8f8000000000000000000000000000000000000000000000000000000000000032800", + "logIndex": "0xe0", + "removed": false, + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0xecb996b8bd3011a9b9ba286b02703f092c6c8532c7908f31bd15fe98b2aa6e96", + "0x0000000000000000000000006593b5a738344a847b9d5ba79912fbb7a34f4bc2", + "0x000000000000000000000000a270ef92c1e11f1c1f95753c2e56801e8125fa83" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x4200000000000000000000000000000000000006", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000", + "logIndex": "0xe1", + "removed": false, + "topics": [ + "0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c", + "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000000000002526ba", + "logIndex": "0xe2", + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000b4cb800910b228ed3d0834cf79d697127bbb00e5", + "0x0000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x4200000000000000000000000000000000000006", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000", + "logIndex": "0xe3", + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad", + "0x000000000000000000000000b4cb800910b228ed3d0834cf79d697127bbb00e5" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0xb4cb800910b228ed3d0834cf79d697127bbb00e5", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdad946000000000000000000000000000000000000000000033be14cac53a8f8fdd29a0000000000000000000000000000000000000000000000000023e212725f84befffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcf938", + "logIndex": "0xe4", + "removed": false, + "topics": [ + "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67", + "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad", + "0x0000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": "0x14e94aa", + "data": "0x000000000000000000000000000000000000000000000000000000000000001f0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000002f945cc669e00000000000000000000000000000000000000000000000000000000000562ea", + "logIndex": "0xe5", + "removed": false, + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0x5c0e9df8abcf487f89309a2548f61b5bad3939be360d8680e8f28a2f0e0b085e", + "0x0000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce", + "0x0000000000000000000000000000000000000000000000000000000000000000" + ], + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52" + } + ], + "logsBloom": "0x000000000000000880000008010000202004000000000000000400000200100000080002000020000002001100001000001088800100200000000a00002400000000000800020108040000080200000000000000000c00000011000080201000008000000a02000000000c0000002c00040210000000000000400810040800000000000002008000000000000100808008800001006000001020040000000000028140000080000000508000000000200000000200080080010006000000008000000002400004000001000000008000006000000020100001000000100060000810020000002000000000040010000000045000000000400000000800000000", + "status": "0x1", + "to": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786", + "transactionIndex": "0x52", + "type": "0x2" + }, + "id": 4 + } + } + }], + [/^https:\/\/chain-proxy\.wallet\.coinbase\.com.*/, { + matchParams: { + body: /wallet_getCallsStatus/ + }, + response: { + delay: 2000, + status: 200, + json: { + "jsonrpc": "2.0", + "id": "e58d8cb2-1378-4bb1-9cc5-03de94e089a8", + "result": { + "status": "CONFIRMED", + "receipts": [ + { + "logs": [ + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "topics": [ + "0xbb47ee3e183a558b1a2ff0874b079f3fc5478b7454eacf2bfc5af2ff5878f972" + ], + "data": "0x" + }, + { + "address": "0x0982b3a5b24b2bd8ef74126e15fca2decfd75a28", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000017405a2de0613e12cd3d7b67e691bfefc46debf", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x00000000000000000000000000000000000000000000000000000000001c7e8b" + ], + "data": "0x" + }, + { + "address": "0x017405a2de0613e12cd3d7b67e691bfefc46debf", + "topics": [ + "0x38dec76e9092e477174a0cb4853dc54e13726bedc62922b9f2cbb292bdabbece", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ], + "data": "0x00000000000000000000000000000000000000000000000000000000001c7e8b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000067278637" + }, + { + "address": "0xb676f87a6e701f0de8de5ab91b56b66109766db1", + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x0000000000000000000000002faeb0760d4230ef2ac21496bb4f0b47d634fd4c" + ], + "data": "0x00000000000000000000000000000000000000000000003625d1534f8c513cfb" + }, + { + "address": "0xb676f87a6e701f0de8de5ab91b56b66109766db1", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x00000000000000000000000095796e0d139d02eb0d89a79ca2938f79dd324a2e" + ], + "data": "0x00000000000000000000000000000000000000000000000000398df7658854e9" + }, + { + "address": "0x2faeb0760d4230ef2ac21496bb4f0b47d634fd4c", + "topics": [ + "0xe2459e4c2a3c2f358a092e76af1f3b2337c91875a1d49fe8afd6126342444f6f", + "0x3787e0840694197e889ce6502fd4427fbcd80c000c9bbf3d6c32b7232cdeaaf5", + "0x0000000000000000000000000000000037233018550b44e3af73c8dc20a6213f", + "0x000000000000000000000000b676f87a6e701f0de8de5ab91b56b66109766db1" + ], + "data": "0x00000000000000000000000095796e0d139d02eb0d89a79ca2938f79dd324a2e00000000000000000000000000000000000000000000000000398df7658854e9" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0x3787e0840694197e889ce6502fd4427fbcd80c000c9bbf3d6c32b7232cdeaaf5", + "0x000000000000000000000000f3847718571b36c623d9f8138dc54e6165fe7f8e", + "0x0000000000000000000000002faeb0760d4230ef2ac21496bb4f0b47d634fd4c" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000004d0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000002e3b8d9a2d30000000000000000000000000000000000000000000000000000000000053be1" + }, + { + "address": "0x4af334f9ae78edd787750063b22a2eaefdbcd3ee", + "topics": [ + "0x729fedf706b78debb34ef30843b5dae81b19d0ee8dbdd5457b925ac843c2e0e9" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000002463383930386364302d363064382d346366642d393361342d35393835613961386264303300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867616d654c6f61640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b71c755b47dda53ea53419bd88a214c19035b1e706bf2a288a1b98bfdfa208ad754baeea93553ba856632f743671c6eeedb614b9fda7d091ead6f19d0f3891438fdc937212fddd82d328554f311475af5c71be291a9dca47a8eb7352cdb081c354d5bcf212434c83bded0c8a8bb6e0ebdab804c0298118ef0f9fae7ad1ff8d25" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0xad8e5bb6dee968d8a77f5b1d0ccd43c53acda3539712dcf4f5830a9ad408c84b", + "0x000000000000000000000000a6e1cbd4a0e55523d00099b118d17c98fa3b1a1a", + "0x000000000000000000000000a270ef92c1e11f1c1f95753c2e56801e8125fa83" + ], + "data": "0x00000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000001e1f3ad969b00000000000000000000000000000000000000000000000000000000000368f9" + }, + { + "address": "0x974474c8bcb36302be93858466728271fb36544e", + "topics": [ + "0x729fedf706b78debb34ef30843b5dae81b19d0ee8dbdd5457b925ac843c2e0e9" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000002464316430363265662d333036302d343062632d383962662d66666130323365316233376300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867616d654c6f61640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b71c755b47dda53ea53419bd88a214c19035b1e706bf2a288a1b98bfdfa208ad754baeea93553ba856632f743671c6eeedb614b9fda7d091ead6f19d0f3891438fdc937212fddd82d328554f311475af5c71be291a9dca47a8eb7352cdb081c354d5bcf212434c83bded0c8a8bb6e0ebdab804c0298118ef0f9fae7ad1ff8d25" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0xecb996b8bd3011a9b9ba286b02703f092c6c8532c7908f31bd15fe98b2aa6e96", + "0x0000000000000000000000006593b5a738344a847b9d5ba79912fbb7a34f4bc2", + "0x000000000000000000000000a270ef92c1e11f1c1f95753c2e56801e8125fa83" + ], + "data": "0x00000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000001be14e8f8000000000000000000000000000000000000000000000000000000000000032800" + }, + { + "address": "0x4200000000000000000000000000000000000006", + "topics": [ + "0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c", + "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + }, + { + "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000b4cb800910b228ed3d0834cf79d697127bbb00e5", + "0x0000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce" + ], + "data": "0x00000000000000000000000000000000000000000000000000000000002526ba" + }, + { + "address": "0x4200000000000000000000000000000000000006", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad", + "0x000000000000000000000000b4cb800910b228ed3d0834cf79d697127bbb00e5" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + }, + { + "address": "0xb4cb800910b228ed3d0834cf79d697127bbb00e5", + "topics": [ + "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67", + "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad", + "0x0000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdad946000000000000000000000000000000000000000000033be14cac53a8f8fdd29a0000000000000000000000000000000000000000000000000023e212725f84befffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcf938" + }, + { + "address": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789", + "topics": [ + "0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f", + "0x5c0e9df8abcf487f89309a2548f61b5bad3939be360d8680e8f28a2f0e0b085e", + "0x0000000000000000000000001f48734b41ebc1a1474e4c8d7df2986b56b478ce", + "0x0000000000000000000000000000000000000000000000000000000000000000" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000001f0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000002f945cc669e00000000000000000000000000000000000000000000000000000000000562ea" + } + ], + "status": 1, + "blockHash": "0x01ae4aa03d9e416f6a925a89efb9632dde911050f4970a0493b5d9ebd4087088", + "blockNumber": 21927082, + "gasUsed": 570089, + "transactionHash": "0x39aaebf6188626e31a8b17d772ddf49db95b68dff24e78a6f61063a96af92786" + } + ] + } + } + } + }], + [/^https:\/\/api\.developer\.coinbase\.com\/rpc\/v1\/base\/.*$/, { + matchParams: { + body: /cdp_getSwapQuote/ + }, + response: { + delay: 2000, + status: 200, + json: { + "id": 1, + "jsonrpc": "2.0", + "result": { + "from": { + "address": "", + "chainId": 8453, + "decimals": 18, + "image": "", + "name": "Ether", + "symbol": "" + }, + "to": { + "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + "chainId": 8453, + "decimals": 6, + "image": "", + "name": "", + "symbol": "" + }, + "fromAmount": "100000000000000", + "fromAmountUSD": "0.24787150000000002", + "toAmount": "247991", + "toAmountUSD": "0.24770019283225023", + "amountReference": "from", + "priceImpact": "0", + "chainId": 8453, + "highPriceImpact": false, + "slippage": "3" + } + } + } + }], + [/^https:\/\/api\.developer\.coinbase\.com\/rpc\/v1\/base\/.*$/, { + matchParams: { + body: /cdp_getSwapTrade/ + }, + response: { + delay: 2000, + status: 200, + json: { + "id": 1, + "jsonrpc": "2.0", + "result": { + "tx": { + "data": "0x24856bc30000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000024da9a00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b4200000000000000000000000000000000000006000064833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000", + "gas": "", + "gasPrice": "", + "from": "", + "to": "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD", + "value": "0x038d7ea4c68000" + }, + "quote": { + "from": { + "address": "", + "chainId": 8453, + "decimals": 18, + "image": "", + "name": "Ether", + "symbol": "" + }, + "to": { + "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + "chainId": 8453, + "decimals": 6, + "image": "", + "name": "", + "symbol": "" + }, + "fromAmount": "1000000000000000", + "fromAmountUSD": "", + "toAmount": "2487716", + "toAmountUSD": "", + "amountReference": "from", + "priceImpact": "0.01022", + "chainId": 8453, + "highPriceImpact": false, + "slippage": "3" + }, + "fee": { + "baseAsset": { + "name": "", + "address": "", + "currencyCode": "", + "decimals": 0, + "imageURL": "", + "blockchain": "", + "aggregators": null, + "swappable": false, + "unverified": false, + "chainId": 0 + }, + "percentage": "", + "amount": "" + }, + "approveTx": { + "data": "", + "gas": "", + "gasPrice": "", + "from": "", + "to": "", + "value": "" + }, + "chainId": 0 + } + } + } }],]) as Map; + + const queryClient = new QueryClient(); function OnchainProviders({ children }: { children: ReactNode }) { return ( - + {children} diff --git a/src/OnchainKitProvider.tsx b/src/OnchainKitProvider.tsx index 5509f9e262..4c3933fbf7 100644 --- a/src/OnchainKitProvider.tsx +++ b/src/OnchainKitProvider.tsx @@ -3,6 +3,8 @@ import { ONCHAIN_KIT_CONFIG, setOnchainKitConfig } from './OnchainKitConfig'; import { checkHashLength } from './internal/utils/checkHashLength'; import type { OnchainKitContextType, OnchainKitProviderReact } from './types'; +import { initializeMockFetch } from './internal/utils/mockFetch'; + export const OnchainKitContext = createContext(ONCHAIN_KIT_CONFIG); @@ -18,11 +20,16 @@ export function OnchainKitProvider({ projectId, rpcUrl, schemaId, + mock, }: OnchainKitProviderReact) { if (schemaId && !checkHashLength(schemaId, 64)) { throw Error('EAS schemaId must be 64 characters prefixed with "0x"'); } + if (mock) { + initializeMockFetch(mock); + } + const value = useMemo(() => { const defaultPaymasterUrl = apiKey ? `https://api.developer.coinbase.com/rpc/v1/${chain.name diff --git a/src/internal/utils/mockFetch.ts b/src/internal/utils/mockFetch.ts new file mode 100644 index 0000000000..05b57638f5 --- /dev/null +++ b/src/internal/utils/mockFetch.ts @@ -0,0 +1,40 @@ +import type { Mocks } from '../../types'; + +export const initializeMockFetch = (mocks: Mocks) => { + if (typeof window !== 'undefined') { + const originalFetch = window.fetch; + + window.fetch = async function mockFetch(resource, options = {}) { + try { + const url = resource instanceof Request ? resource.url : resource; + console.log('fetch request:', url); + + // look for matching url in mocks map + for (const [pattern, { matchParams, response }] of mocks) { + if (pattern.test(url.toString())) { + // check for any additional match params + if ( + !matchParams?.body || + matchParams?.body.test(options.body as string) + ) { + console.log(`returning mock response for: ${pattern}`, response.json); + if (response.delay) { + await new Promise(resolve => setTimeout(resolve, response.delay)); + } + return new Response(JSON.stringify(response.json), { + status: response.status, + headers: { 'Content-Type': 'application/json' }, + }); + } + } + } + + // no match found, use original fetch + return originalFetch(resource, options); + } catch (error) { + console.error('mock fetch error, returning original fetch', error); + return originalFetch(resource, options); + } + }; + } +}; diff --git a/src/types.ts b/src/types.ts index 4711a0bfc3..d1923e2204 100644 --- a/src/types.ts +++ b/src/types.ts @@ -62,8 +62,11 @@ export type OnchainKitConfig = { rpcUrl: string | null; // RPC URL for onchain requests. Defaults to using CDP Node if the API Key is set schemaId: EASSchemaUid | null; // SchemaId is optional as not all apps need to use EAS projectId: string | null; // ProjectId from Coinbase Developer Platform, only required for Coinbase Onramp support + mock?: Mocks; // Mock is optional and defaults to false. If true, the fetch function will be overridden to return mock data. }; +export type Mocks = Map; + export type SetOnchainKitConfig = Partial; /** @@ -83,6 +86,7 @@ export type OnchainKitProviderReact = { rpcUrl?: string; schemaId?: EASSchemaUid; projectId?: string; + mock?: Mocks; }; export type UseCapabilitiesSafeParams = {