forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 6
feat(anvil-polkadot): add transaction pool RPCs 1/2 #356
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
12 commits
Select commit
Hold shift + click to select a range
64e5b4f
Implement Drop RPCs
dragann-milosevic 19320ca
tx pool status RPC
dragann-milosevic e3e6633
extract helper for ETH hash matching in transaction pool
dragann-milosevic 7ea9848
Add basic tests
dragann-milosevic 483e47a
fix warning
dragann-milosevic a02f4e0
Merge branch 'master' into dragann-milosevic/dropTx
dragann-milosevic 6808c8d
rust fmt code
dragann-milosevic 23d11e2
Merge branch 'master' into dragann-milosevic/dropTx
dragann-milosevic d93c8fd
update drop_transaction return type and simplify helper
dragann-milosevic d887146
update tests
dragann-milosevic 4062325
Merge branch 'master' into dragann-milosevic/dropTx
dragann-milosevic 39f7e9a
extend txpool tests to cover queued transactions and fmt code
dragann-milosevic 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ mod snapshot; | |
| mod standard_rpc; | ||
| mod state_injector; | ||
| mod time_machine; | ||
| mod txpool; | ||
| mod utils; | ||
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,148 @@ | ||
| use crate::utils::{TestNode, unwrap_response}; | ||
| use alloy_primitives::{Address, B256, U256}; | ||
| use alloy_rpc_types::{TransactionRequest, txpool::TxpoolStatus}; | ||
| use anvil_core::eth::EthRequest; | ||
| use anvil_polkadot::{ | ||
| api_server::revive_conversions::ReviveAddress, | ||
| config::{AnvilNodeConfig, SubstrateNodeConfig}, | ||
| }; | ||
| use polkadot_sdk::pallet_revive::evm::Account; | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_txpool_status() { | ||
| let anvil_node_config = AnvilNodeConfig::test_config(); | ||
| let substrate_node_config = SubstrateNodeConfig::new(&anvil_node_config); | ||
| let mut node = TestNode::new(anvil_node_config, substrate_node_config).await.unwrap(); | ||
|
|
||
| let alith = Account::from(subxt_signer::eth::dev::alith()); | ||
| let alith_addr = Address::from(ReviveAddress::new(alith.address())); | ||
| let recipient_addr = Address::repeat_byte(0x42); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 0); | ||
| assert_eq!(status.queued, 0); | ||
|
|
||
| for i in 0..3 { | ||
| let tx = TransactionRequest::default() | ||
| .from(alith_addr) | ||
| .to(recipient_addr) | ||
| .value(U256::from(1000 * (i + 1))) | ||
| .nonce(i); | ||
| node.send_transaction(tx, None).await.unwrap(); | ||
| } | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 3); | ||
| assert_eq!(status.queued, 0); | ||
|
|
||
| let tx_future = TransactionRequest::default() | ||
| .from(alith_addr) | ||
| .to(recipient_addr) | ||
| .value(U256::from(5000)) | ||
| .nonce(5); | ||
| node.send_transaction(tx_future, None).await.unwrap(); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 3); | ||
| assert_eq!(status.queued, 1); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_drop_transaction() { | ||
| let anvil_node_config = AnvilNodeConfig::test_config(); | ||
| let substrate_node_config = SubstrateNodeConfig::new(&anvil_node_config); | ||
| let mut node = TestNode::new(anvil_node_config, substrate_node_config).await.unwrap(); | ||
|
|
||
| let alith = Account::from(subxt_signer::eth::dev::alith()); | ||
| let alith_addr = Address::from(ReviveAddress::new(alith.address())); | ||
| let recipient_addr = Address::repeat_byte(0x42); | ||
|
|
||
| let tx1 = | ||
| TransactionRequest::default().from(alith_addr).to(recipient_addr).value(U256::from(1000)); | ||
| node.send_transaction(tx1, None).await.unwrap(); | ||
|
|
||
| let tx2 = TransactionRequest::default() | ||
| .from(alith_addr) | ||
| .to(recipient_addr) | ||
| .value(U256::from(2000)) | ||
| .nonce(1); | ||
dragann-milosevic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let tx2_hash = node.send_transaction(tx2, None).await.unwrap(); | ||
|
|
||
| let tx_future = TransactionRequest::default() | ||
| .from(alith_addr) | ||
| .to(recipient_addr) | ||
| .value(U256::from(5000)) | ||
| .nonce(5); | ||
| let tx_future_hash = node.send_transaction(tx_future, None).await.unwrap(); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 2); | ||
| assert_eq!(status.queued, 1); | ||
|
|
||
| let tx2_hash_b256 = B256::from_slice(tx2_hash.0.as_ref()); | ||
| let dropped_hash = unwrap_response::<Option<B256>>( | ||
| node.eth_rpc(EthRequest::DropTransaction(tx2_hash_b256)).await.unwrap(), | ||
| ) | ||
| .unwrap(); | ||
| assert_eq!(dropped_hash, Some(tx2_hash_b256)); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 1); | ||
| assert_eq!(status.queued, 1); | ||
|
|
||
| let tx_future_hash_b256 = B256::from_slice(tx_future_hash.0.as_ref()); | ||
| let dropped_hash = unwrap_response::<Option<B256>>( | ||
| node.eth_rpc(EthRequest::DropTransaction(tx_future_hash_b256)).await.unwrap(), | ||
| ) | ||
| .unwrap(); | ||
| assert_eq!(dropped_hash, Some(tx_future_hash_b256)); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 1); | ||
| assert_eq!(status.queued, 0); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_drop_all_transactions() { | ||
| let anvil_node_config = AnvilNodeConfig::test_config(); | ||
| let substrate_node_config = SubstrateNodeConfig::new(&anvil_node_config); | ||
| let mut node = TestNode::new(anvil_node_config, substrate_node_config).await.unwrap(); | ||
|
|
||
| let alith = Account::from(subxt_signer::eth::dev::alith()); | ||
| let alith_addr = Address::from(ReviveAddress::new(alith.address())); | ||
| let recipient_addr = Address::repeat_byte(0x42); | ||
|
|
||
| for i in 0..3 { | ||
| let tx = TransactionRequest::default() | ||
| .from(alith_addr) | ||
| .to(recipient_addr) | ||
| .value(U256::from(1000 * (i + 1))) | ||
| .nonce(i); | ||
| node.send_transaction(tx, None).await.unwrap(); | ||
| } | ||
|
|
||
| let tx_future = TransactionRequest::default() | ||
| .from(alith_addr) | ||
| .to(recipient_addr) | ||
| .value(U256::from(5000)) | ||
| .nonce(5); | ||
| node.send_transaction(tx_future, None).await.unwrap(); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 3); | ||
| assert_eq!(status.queued, 1); | ||
|
|
||
| unwrap_response::<()>(node.eth_rpc(EthRequest::DropAllTransactions()).await.unwrap()).unwrap(); | ||
|
|
||
| let status: TxpoolStatus = | ||
| unwrap_response(node.eth_rpc(EthRequest::TxPoolStatus(())).await.unwrap()).unwrap(); | ||
| assert_eq!(status.pending, 0); | ||
| assert_eq!(status.queued, 0); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.