iota_cluster_test/test_case/
fullnode_execute_transaction_test.rs1use async_trait::async_trait;
6use iota_json_rpc_types::{
7 IotaExecutionStatus, IotaTransactionBlockEffectsAPI, IotaTransactionBlockResponseOptions,
8};
9use iota_sdk::IotaClient;
10use iota_types::{
11 base_types::TransactionDigest, quorum_driver_types::ExecuteTransactionRequestType,
12};
13use tracing::info;
14
15use crate::{TestCaseImpl, TestContext};
16
17pub struct FullNodeExecuteTransactionTest;
18
19impl FullNodeExecuteTransactionTest {
20 async fn verify_transaction(fullnode: &IotaClient, tx_digest: TransactionDigest) {
21 fullnode
22 .read_api()
23 .get_transaction_with_options(tx_digest, IotaTransactionBlockResponseOptions::new())
24 .await
25 .unwrap_or_else(|e| {
26 panic!(
27 "Failed get transaction {:?} from fullnode: {:?}",
28 tx_digest, e
29 )
30 });
31 }
32}
33
34#[async_trait]
35impl TestCaseImpl for FullNodeExecuteTransactionTest {
36 fn name(&self) -> &'static str {
37 "FullNodeExecuteTransaction"
38 }
39
40 fn description(&self) -> &'static str {
41 "Test executing transaction via Fullnode Quorum Driver"
42 }
43
44 async fn run(&self, ctx: &mut TestContext) -> Result<(), anyhow::Error> {
45 let txn_count = 4;
46 ctx.get_iota_from_faucet(Some(1)).await;
47
48 let mut txns = ctx.make_transactions(txn_count).await;
49 assert!(
50 txns.len() >= txn_count,
51 "Expect at least {} txns, but only got {}. Do we generate enough gas objects during genesis?",
52 txn_count,
53 txns.len(),
54 );
55
56 let fullnode = ctx.get_fullnode_client();
57
58 info!("Test execution with WaitForEffectsCert");
59 let txn = txns.swap_remove(0);
60 let txn_digest = *txn.digest();
61
62 let response = fullnode
63 .quorum_driver_api()
64 .execute_transaction_block(
65 txn,
66 IotaTransactionBlockResponseOptions::new().with_effects(),
67 Some(ExecuteTransactionRequestType::WaitForEffectsCert),
68 )
69 .await?;
70
71 assert!(!response.confirmed_local_execution.unwrap());
72 assert_eq!(txn_digest, response.digest);
73 let effects = response.effects.unwrap();
74 if !matches!(effects.status(), IotaExecutionStatus::Success) {
75 panic!(
76 "Failed to execute transfer transaction {:?}: {:?}",
77 txn_digest,
78 effects.status()
79 )
80 }
81 ctx.let_fullnode_sync(vec![txn_digest], 5).await;
83 Self::verify_transaction(fullnode, txn_digest).await;
84
85 info!("Test execution with WaitForLocalExecution");
86 let txn = txns.swap_remove(0);
87 let txn_digest = *txn.digest();
88
89 let response = fullnode
90 .quorum_driver_api()
91 .execute_transaction_block(
92 txn,
93 IotaTransactionBlockResponseOptions::new().with_effects(),
94 Some(ExecuteTransactionRequestType::WaitForLocalExecution),
95 )
96 .await?;
97 assert!(response.confirmed_local_execution.unwrap());
98 assert_eq!(txn_digest, response.digest);
99 let effects = response.effects.unwrap();
100 if !matches!(effects.status(), IotaExecutionStatus::Success) {
101 panic!(
102 "Failed to execute transfer transaction {:?}: {:?}",
103 txn_digest,
104 effects.status()
105 )
106 }
107 Self::verify_transaction(fullnode, txn_digest).await;
109
110 Ok(())
111 }
112}