Skip to content

Commit d14a43e

Browse files
committed
feat: Add working Batch Transaction e2e test
Signed-off-by: gsstoykov <[email protected]>
1 parent 1fe4616 commit d14a43e

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/batch_transaction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ impl ToTransactionDataProtobuf for BatchTransactionData {
204204
let signed_transaction_bytes = transaction
205205
.to_signed_transaction_bytes()
206206
.expect("Inner transaction should be frozen and serializable");
207+
208+
println!("Signed transaction bytes: {:?}", signed_transaction_bytes);
207209
builder.transactions.push(signed_transaction_bytes);
208210
}
209211

src/transaction/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ impl<D: TransactionExecute> Transaction<D> {
543543

544544
/// Convenience method to mark a transaction as part of a batch transaction.
545545
/// The Transaction will be frozen and signed by the operator of the client.
546+
/// Per HIP-551, inner transactions use node account ID 0.0.0.
546547
///
547548
/// # Errors
548549
///
@@ -554,6 +555,8 @@ impl<D: TransactionExecute> Transaction<D> {
554555
) -> crate::Result<&mut Self> {
555556
self.require_not_frozen();
556557
self.set_batch_key(batch_key);
558+
// Set node account ID to 0.0.0 for batch transactions (as per HIP-551)
559+
self.node_account_ids([crate::AccountId::new(0, 0, 0)]);
557560
self.freeze_with(client)?;
558561
self.sign_with_operator(client)
559562
}
@@ -833,7 +836,7 @@ impl<D: TransactionExecute> Transaction<D> {
833836
sig_map: Some(services::SignatureMap { sig_pair: signatures.clone() }),
834837
};
835838
services::Transaction {
836-
signed_transaction_bytes: Vec::new(),
839+
signed_transaction_bytes: signed_transaction.encode_to_vec(),
837840
body: None,
838841
sigs: None,
839842
body_bytes: signed_transaction.body_bytes,

tests/e2e/batch_transaction.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::str::FromStr;
2+
use hedera::{
3+
AccountCreateTransaction,
4+
BatchTransaction,
5+
Hbar,
6+
PrivateKey,
7+
};
8+
9+
use crate::common::{
10+
setup_nonfree,
11+
TestEnvironment,
12+
};
13+
14+
#[tokio::test]
15+
async fn can_execute_batch_transaction() -> anyhow::Result<()> {
16+
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
17+
return Ok(());
18+
};
19+
20+
// Given
21+
let operator_key = PrivateKey::from_str(
22+
"302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"
23+
)?;
24+
25+
let account_key = PrivateKey::generate_ed25519();
26+
27+
let mut inner_transaction = AccountCreateTransaction::new();
28+
inner_transaction
29+
.set_key_without_alias(account_key.public_key())
30+
.initial_balance(Hbar::new(1));
31+
32+
// Use batchify to prepare the transaction
33+
inner_transaction.batchify(&client, operator_key.public_key().into())?;
34+
35+
// When / Then
36+
let mut batch_transaction = BatchTransaction::new();
37+
batch_transaction.add_inner_transaction(inner_transaction.into())?;
38+
39+
let tx_response = batch_transaction.execute(&client).await?;
40+
let _tx_receipt = tx_response.get_receipt(&client).await?;
41+
42+
Ok(())
43+
}

tests/e2e/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod account;
22
mod address_book;
3+
mod batch_transaction;
34
mod client;
45
mod common;
56
mod contract;

0 commit comments

Comments
 (0)