2022-09-14 17:57:48 +00:00
|
|
|
use std::collections::BTreeMap;
|
2022-09-08 21:46:48 +00:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
2022-11-17 17:14:13 +00:00
|
|
|
use ethers::types::{Address, Filter, H256, U256};
|
2022-09-08 21:46:48 +00:00
|
|
|
use ssz_rs::{List, Vector};
|
|
|
|
|
|
|
|
use common::utils::hex_str_to_bytes;
|
2023-03-15 04:46:00 +00:00
|
|
|
use consensus::types::{ExecutionPayload, ExecutionPayloadBellatrix};
|
2022-09-08 21:46:48 +00:00
|
|
|
use execution::rpc::mock_rpc::MockRpc;
|
|
|
|
use execution::ExecutionClient;
|
|
|
|
|
|
|
|
fn get_client() -> ExecutionClient<MockRpc> {
|
|
|
|
ExecutionClient::new("testdata/").unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_account() {
|
|
|
|
let execution = get_client();
|
|
|
|
let address = Address::from_str("14f9D4aF749609c1438528C0Cce1cC3f6D411c47").unwrap();
|
|
|
|
|
2023-03-15 04:46:00 +00:00
|
|
|
let payload = ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
|
2022-12-04 20:28:44 +00:00
|
|
|
state_root: Vector::from_iter(
|
|
|
|
hex_str_to_bytes("0xaa02f5db2ee75e3da400d10f3c30e894b6016ce8a2501680380a907b6674ce0d")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2023-03-15 04:46:00 +00:00
|
|
|
..ExecutionPayloadBellatrix::default()
|
|
|
|
});
|
2022-09-08 21:46:48 +00:00
|
|
|
|
|
|
|
let account = execution
|
|
|
|
.get_account(&address, None, &payload)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
account.balance,
|
|
|
|
U256::from_str_radix("48c27395000", 16).unwrap()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_account_bad_proof() {
|
|
|
|
let execution = get_client();
|
|
|
|
let address = Address::from_str("14f9D4aF749609c1438528C0Cce1cC3f6D411c47").unwrap();
|
|
|
|
let payload = ExecutionPayload::default();
|
|
|
|
|
|
|
|
let account_res = execution.get_account(&address, None, &payload).await;
|
|
|
|
|
|
|
|
assert!(account_res.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_tx() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
|
|
|
let mut payload = ExecutionPayload::default();
|
2023-03-15 04:46:00 +00:00
|
|
|
payload.transactions_mut().push(List::from_iter(hex_str_to_bytes("0x02f8b20583623355849502f900849502f91082ea6094326c977e6efc84e512bb9c30f76e30c160ed06fb80b844a9059cbb0000000000000000000000007daccf9b3c1ae2fa5c55f1c978aeef700bc83be0000000000000000000000000000000000000000000000001158e460913d00000c080a0e1445466b058b6f883c0222f1b1f3e2ad9bee7b5f688813d86e3fa8f93aa868ca0786d6e7f3aefa8fe73857c65c32e4884d8ba38d0ecfb947fbffb82e8ee80c167").unwrap()));
|
2022-09-08 21:46:48 +00:00
|
|
|
|
2022-09-14 17:57:48 +00:00
|
|
|
let mut payloads = BTreeMap::new();
|
2022-09-08 21:46:48 +00:00
|
|
|
payloads.insert(7530933, payload);
|
|
|
|
|
|
|
|
let tx = execution
|
|
|
|
.get_transaction(&tx_hash, &payloads)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(tx.hash(), tx_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_tx_bad_proof() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
|
|
|
let payload = ExecutionPayload::default();
|
2022-09-14 17:57:48 +00:00
|
|
|
|
|
|
|
let mut payloads = BTreeMap::new();
|
2022-09-08 21:46:48 +00:00
|
|
|
payloads.insert(7530933, payload);
|
|
|
|
|
|
|
|
let tx_res = execution.get_transaction(&tx_hash, &payloads).await;
|
|
|
|
|
|
|
|
assert!(tx_res.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_tx_not_included() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
2022-09-14 17:57:48 +00:00
|
|
|
let payloads = BTreeMap::new();
|
2022-09-08 21:46:48 +00:00
|
|
|
|
|
|
|
let tx_opt = execution
|
|
|
|
.get_transaction(&tx_hash, &payloads)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(tx_opt.is_none());
|
|
|
|
}
|
|
|
|
|
2022-11-17 17:14:13 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_logs() {
|
|
|
|
let execution = get_client();
|
2023-03-15 04:46:00 +00:00
|
|
|
let mut payload = ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
|
2022-12-04 20:28:44 +00:00
|
|
|
receipts_root: Vector::from_iter(
|
|
|
|
hex_str_to_bytes("dd82a78eccb333854f0c99e5632906e092d8a49c27a21c25cae12b82ec2a113f")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2023-03-15 04:46:00 +00:00
|
|
|
..ExecutionPayloadBellatrix::default()
|
|
|
|
});
|
2022-11-17 17:14:13 +00:00
|
|
|
|
2023-03-15 04:46:00 +00:00
|
|
|
payload.transactions_mut().push(List::from_iter(hex_str_to_bytes("0x02f8b20583623355849502f900849502f91082ea6094326c977e6efc84e512bb9c30f76e30c160ed06fb80b844a9059cbb0000000000000000000000007daccf9b3c1ae2fa5c55f1c978aeef700bc83be0000000000000000000000000000000000000000000000001158e460913d00000c080a0e1445466b058b6f883c0222f1b1f3e2ad9bee7b5f688813d86e3fa8f93aa868ca0786d6e7f3aefa8fe73857c65c32e4884d8ba38d0ecfb947fbffb82e8ee80c167").unwrap()));
|
2022-11-17 17:14:13 +00:00
|
|
|
|
|
|
|
let mut payloads = BTreeMap::new();
|
|
|
|
payloads.insert(7530933, payload);
|
|
|
|
|
|
|
|
let filter = Filter::new();
|
|
|
|
let logs = execution.get_logs(&filter, &payloads).await.unwrap();
|
|
|
|
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
|
|
|
assert!(!logs.is_empty());
|
|
|
|
assert!(logs[0].transaction_hash.is_some());
|
|
|
|
assert!(logs[0].transaction_hash.unwrap() == tx_hash);
|
|
|
|
}
|
|
|
|
|
2022-09-08 21:46:48 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_receipt() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
2023-03-15 04:46:00 +00:00
|
|
|
let mut payload = ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
|
2022-12-04 20:28:44 +00:00
|
|
|
receipts_root: Vector::from_iter(
|
|
|
|
hex_str_to_bytes("dd82a78eccb333854f0c99e5632906e092d8a49c27a21c25cae12b82ec2a113f")
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2023-03-15 04:46:00 +00:00
|
|
|
..ExecutionPayloadBellatrix::default()
|
|
|
|
});
|
2022-09-08 21:46:48 +00:00
|
|
|
|
2023-03-15 04:46:00 +00:00
|
|
|
payload.transactions_mut().push(List::from_iter(hex_str_to_bytes("0x02f8b20583623355849502f900849502f91082ea6094326c977e6efc84e512bb9c30f76e30c160ed06fb80b844a9059cbb0000000000000000000000007daccf9b3c1ae2fa5c55f1c978aeef700bc83be0000000000000000000000000000000000000000000000001158e460913d00000c080a0e1445466b058b6f883c0222f1b1f3e2ad9bee7b5f688813d86e3fa8f93aa868ca0786d6e7f3aefa8fe73857c65c32e4884d8ba38d0ecfb947fbffb82e8ee80c167").unwrap()));
|
2022-09-08 21:46:48 +00:00
|
|
|
|
2022-09-14 17:57:48 +00:00
|
|
|
let mut payloads = BTreeMap::new();
|
2022-09-08 21:46:48 +00:00
|
|
|
payloads.insert(7530933, payload);
|
|
|
|
|
|
|
|
let receipt = execution
|
|
|
|
.get_transaction_receipt(&tx_hash, &payloads)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(receipt.transaction_hash, tx_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_receipt_bad_proof() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
|
|
|
let mut payload = ExecutionPayload::default();
|
2023-03-15 04:46:00 +00:00
|
|
|
payload.transactions_mut().push(List::from_iter(hex_str_to_bytes("0x02f8b20583623355849502f900849502f91082ea6094326c977e6efc84e512bb9c30f76e30c160ed06fb80b844a9059cbb0000000000000000000000007daccf9b3c1ae2fa5c55f1c978aeef700bc83be0000000000000000000000000000000000000000000000001158e460913d00000c080a0e1445466b058b6f883c0222f1b1f3e2ad9bee7b5f688813d86e3fa8f93aa868ca0786d6e7f3aefa8fe73857c65c32e4884d8ba38d0ecfb947fbffb82e8ee80c167").unwrap()));
|
2022-09-08 21:46:48 +00:00
|
|
|
|
2022-09-14 17:57:48 +00:00
|
|
|
let mut payloads = BTreeMap::new();
|
2022-09-08 21:46:48 +00:00
|
|
|
payloads.insert(7530933, payload);
|
|
|
|
|
|
|
|
let receipt_res = execution.get_transaction_receipt(&tx_hash, &payloads).await;
|
|
|
|
|
|
|
|
assert!(receipt_res.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_receipt_not_included() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
2022-09-14 17:57:48 +00:00
|
|
|
let payloads = BTreeMap::new();
|
2022-09-08 21:46:48 +00:00
|
|
|
let receipt_opt = execution
|
|
|
|
.get_transaction_receipt(&tx_hash, &payloads)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(receipt_opt.is_none());
|
|
|
|
}
|
|
|
|
|
2022-10-27 17:46:32 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_block() {
|
2022-09-08 21:46:48 +00:00
|
|
|
let execution = get_client();
|
2023-03-15 04:46:00 +00:00
|
|
|
let payload = ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
|
2022-12-04 20:28:44 +00:00
|
|
|
block_number: 12345,
|
2023-03-15 04:46:00 +00:00
|
|
|
..ExecutionPayloadBellatrix::default()
|
|
|
|
});
|
2022-09-08 21:46:48 +00:00
|
|
|
|
2022-10-27 17:46:32 +00:00
|
|
|
let block = execution.get_block(&payload, false).await.unwrap();
|
2022-09-08 21:46:48 +00:00
|
|
|
|
|
|
|
assert_eq!(block.number, 12345);
|
|
|
|
}
|
2023-01-03 14:45:56 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_tx_by_block_hash_and_index() {
|
|
|
|
let execution = get_client();
|
|
|
|
let tx_hash =
|
|
|
|
H256::from_str("2dac1b27ab58b493f902dda8b63979a112398d747f1761c0891777c0983e591f").unwrap();
|
|
|
|
|
2023-03-15 04:46:00 +00:00
|
|
|
let mut payload = ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
|
2023-01-03 14:45:56 +00:00
|
|
|
block_number: 7530933,
|
2023-03-15 04:46:00 +00:00
|
|
|
..ExecutionPayloadBellatrix::default()
|
|
|
|
});
|
|
|
|
payload.transactions_mut().push(List::from_iter(hex_str_to_bytes("0x02f8b20583623355849502f900849502f91082ea6094326c977e6efc84e512bb9c30f76e30c160ed06fb80b844a9059cbb0000000000000000000000007daccf9b3c1ae2fa5c55f1c978aeef700bc83be0000000000000000000000000000000000000000000000001158e460913d00000c080a0e1445466b058b6f883c0222f1b1f3e2ad9bee7b5f688813d86e3fa8f93aa868ca0786d6e7f3aefa8fe73857c65c32e4884d8ba38d0ecfb947fbffb82e8ee80c167").unwrap()));
|
2023-01-03 14:45:56 +00:00
|
|
|
|
|
|
|
let tx = execution
|
|
|
|
.get_transaction_by_block_hash_and_index(&payload, 0)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(tx.hash(), tx_hash);
|
|
|
|
}
|