|
| 1 | +import chai, { assert } from "chai"; |
| 2 | +import { JsonStreamStringify } from "json-stream-stringify"; |
| 3 | + |
| 4 | +import { |
| 5 | + ContractAndFunctionName, |
| 6 | + EdrContext, |
| 7 | + MineOrdering, |
| 8 | + Provider, |
| 9 | + SpecId, |
| 10 | + SubscriptionEvent, |
| 11 | +} from ".."; |
| 12 | +import { ALCHEMY_URL, isCI } from "./helpers"; |
| 13 | + |
| 14 | +describe("Provider", () => { |
| 15 | + const context = new EdrContext(); |
| 16 | + const providerConfig = { |
| 17 | + allowBlocksWithSameTimestamp: false, |
| 18 | + allowUnlimitedContractSize: true, |
| 19 | + bailOnCallFailure: false, |
| 20 | + bailOnTransactionFailure: false, |
| 21 | + blockGasLimit: 300_000_000n, |
| 22 | + chainId: 1n, |
| 23 | + chains: [], |
| 24 | + coinbase: Buffer.from("0000000000000000000000000000000000000000", "hex"), |
| 25 | + enableRip7212: false, |
| 26 | + genesisAccounts: [ |
| 27 | + { |
| 28 | + secretKey: |
| 29 | + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", |
| 30 | + balance: 1000n * 10n ** 18n, |
| 31 | + }, |
| 32 | + ], |
| 33 | + hardfork: SpecId.Latest, |
| 34 | + initialBlobGas: { |
| 35 | + gasUsed: 0n, |
| 36 | + excessGas: 0n, |
| 37 | + }, |
| 38 | + initialParentBeaconBlockRoot: Buffer.from( |
| 39 | + "0000000000000000000000000000000000000000000000000000000000000000", |
| 40 | + "hex", |
| 41 | + ), |
| 42 | + minGasPrice: 0n, |
| 43 | + mining: { |
| 44 | + autoMine: true, |
| 45 | + memPool: { |
| 46 | + order: MineOrdering.Priority, |
| 47 | + }, |
| 48 | + }, |
| 49 | + networkId: 123n, |
| 50 | + }; |
| 51 | + |
| 52 | + const loggerConfig = { |
| 53 | + enable: false, |
| 54 | + decodeConsoleLogInputsCallback: (inputs: Buffer[]): string[] => { |
| 55 | + return []; |
| 56 | + }, |
| 57 | + getContractAndFunctionNameCallback: ( |
| 58 | + _code: Buffer, |
| 59 | + _calldata?: Buffer, |
| 60 | + ): ContractAndFunctionName => { |
| 61 | + return { |
| 62 | + contractName: "", |
| 63 | + }; |
| 64 | + }, |
| 65 | + printLineCallback: (message: string, replace: boolean) => {}, |
| 66 | + }; |
| 67 | + |
| 68 | + it("issue 543", async function () { |
| 69 | + if (ALCHEMY_URL === undefined || !isCI()) { |
| 70 | + this.skip(); |
| 71 | + } |
| 72 | + |
| 73 | + // This test is slow because the debug_traceTransaction is performed on a large transaction. |
| 74 | + this.timeout(240_000); |
| 75 | + |
| 76 | + const provider = await Provider.withConfig( |
| 77 | + context, |
| 78 | + { |
| 79 | + fork: { |
| 80 | + jsonRpcUrl: ALCHEMY_URL, |
| 81 | + }, |
| 82 | + initialBaseFeePerGas: 0n, |
| 83 | + ...providerConfig, |
| 84 | + }, |
| 85 | + loggerConfig, |
| 86 | + (_event: SubscriptionEvent) => {}, |
| 87 | + ); |
| 88 | + |
| 89 | + const debugTraceTransaction = `{ |
| 90 | + "jsonrpc": "2.0", |
| 91 | + "method": "debug_traceTransaction", |
| 92 | + "params": ["0x7e460f200343e5ab6653a8857cc5ef798e3f5bea6a517b156f90c77ef311a57c"], |
| 93 | + "id": 1 |
| 94 | + }`; |
| 95 | + |
| 96 | + const response = await provider.handleRequest(debugTraceTransaction); |
| 97 | + |
| 98 | + let responseData; |
| 99 | + |
| 100 | + if (typeof response.data === "string") { |
| 101 | + responseData = JSON.parse(response.data); |
| 102 | + } else { |
| 103 | + responseData = response.data; |
| 104 | + } |
| 105 | + |
| 106 | + // Validate that we can query the response data without crashing. |
| 107 | + const _json = new JsonStreamStringify(responseData); |
| 108 | + }); |
| 109 | +}); |
0 commit comments