ITADN

bug: Anvil does not return correct error code when timeouting for eth_sendRawTransactionSync

#16035Openkirsanium 创建于 22 天前
T-bugC-anvil
K
kirsaniumcommented
### Component Anvil ### Have you ensured that all of these are up to date? - [x] Foundry - [x] Foundryup ### What version of Foundry are you on? 1.8.0-nightly ### What version of Foundryup are you on? 1.9.2 ### What command(s) is the bug in? _No response_ ### Operating System Linux ### Describe the bug While preparing a pull request for [alloy-rs](https://github.com/alloy-rs/alloy/) implementing the possibility of eth_sendRawTransactionSync with timeout (see https://github.com/alloy-rs/alloy/issues/4041) I found out that Anvil's error response to the call does not conform to [EIP-7966](https://eips.ethereum.org/EIPS/eip-7966#error-codes-and-response-structure). Example as a test for alloy: ```rust #[tokio::test] async fn test_send_raw_transaction_sync_with_timeout_fail() { let provider = ProviderBuilder::new().connect_anvil_with_wallet(); // Create a transaction let tx = TransactionRequest { nonce: Some(0), value: Some(U256::from(100)), to: Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into()), gas_price: Some(20e9 as u128), gas: Some(21000), ..Default::default() }; // Build and sign the transaction to get the envelope let tx_envelope = tx.build(&provider.wallet()).await.expect("failed to build tx"); // Encode the transaction let encoded = tx_envelope.encoded_2718(); // Send using the sync method - this has to return ErrorResp let error_payload = provider .send_raw_transaction_sync_with_timeout(&encoded, 1) .await .expect_err("timeout should fire") .as_error_resp() .expect("error should be ErrorResp"); // Verify error code assert_eq!(error_payload.code, 4); // Data has to contain transaction hash let data = error_payload.data.as_ref()?; let data_str = data.get().trim_matches('"').trim(); let tx_hash: B256 = data_str.parse().expect("data should contain tx hash"); assert!(error_payload.data != B256::ZERO, "error payload data should have valid tx hash"); } ``` The response is expected to look something like: ```json { "code": 4, "message": "Transaction confirmation timeout", "data": "0x123....." } ``` But instead it looks like: ```json { "code": -32603, "message": "Transaction confirmation timeout" } ```
0 条评论