Skip to content

Commit 435f9fc

Browse files
authored
E2E test: NodeCreateTransaction
1 parent 44b1c48 commit 435f9fc

File tree

9 files changed

+81
-10
lines changed

9 files changed

+81
-10
lines changed

src/address_book/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
* ‍
1919
*/
2020

21-
mod node_create_transaction;
22-
mod node_delete_transaction;
23-
mod node_update_transaction;
21+
pub mod node_create_transaction;
22+
pub mod node_delete_transaction;
23+
pub mod node_update_transaction;
2424

25-
pub use node_create_transaction::NodeCreateTransactionData;
26-
pub use node_delete_transaction::NodeDeleteTransactionData;
27-
pub use node_update_transaction::NodeUpdateTransactionData;
25+
pub use node_create_transaction::NodeCreateTransaction;
26+
pub(crate) use node_create_transaction::NodeCreateTransactionData;
27+
pub use node_delete_transaction::NodeDeleteTransaction;
28+
pub(crate) use node_delete_transaction::NodeDeleteTransactionData;
29+
pub use node_update_transaction::NodeUpdateTransaction;
30+
pub(crate) use node_update_transaction::NodeUpdateTransactionData;

src/address_book/node_create_transaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ‌
33
* Hedera Rust SDK
44
* ​
5-
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC
5+
* Copyright (C) 2022 - 2024 Hedera Hashgraph, LLC
66
* ​
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -54,6 +54,7 @@ use crate::{
5454
/// to join the network, and requires governing council authorization.
5555
pub type NodeCreateTransaction = Transaction<NodeCreateTransactionData>;
5656

57+
/// A transaction body to add a new consensus node to the network address book.
5758
#[derive(Debug, Clone, Default)]
5859
pub struct NodeCreateTransactionData {
5960
/// A Node account identifier.

src/address_book/node_delete_transaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ‌
33
* Hedera Rust SDK
44
* ​
5-
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC
5+
* Copyright (C) 2022 - 2024 Hedera Hashgraph, LLC
66
* ​
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -58,6 +58,7 @@ use crate::{
5858
/// receipt.
5959
pub type NodeDeleteTransaction = Transaction<NodeDeleteTransactionData>;
6060

61+
/// A transaction body to delete a node from the network address book.
6162
#[derive(Debug, Clone, Default)]
6263
pub struct NodeDeleteTransactionData {
6364
/// A consensus node identifier in the network state.

src/address_book/node_update_transaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ‌
33
* Hedera Rust SDK
44
* ​
5-
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC
5+
* Copyright (C) 2022 - 2024 Hedera Hashgraph, LLC
66
* ​
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -65,6 +65,7 @@ use crate::{
6565
/// transaction receipt.
6666
pub type NodeUpdateTransaction = Transaction<NodeUpdateTransactionData>;
6767

68+
/// Transaction body to modify address book node attributes.
6869
#[derive(Debug, Clone, Default)]
6970
pub struct NodeUpdateTransactionData {
7071
/// A consensus node identifier in the network state.

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ pub use account::{
183183
AllProxyStakers,
184184
ProxyStaker,
185185
};
186+
pub use address_book::{
187+
NodeCreateTransaction,
188+
NodeDeleteTransaction,
189+
NodeUpdateTransaction,
190+
};
186191
pub use client::Client;
187192
pub(crate) use client::Operator;
188193
pub use contract::{
@@ -293,6 +298,7 @@ pub use schedule::{
293298
ScheduleSignTransaction,
294299
};
295300
pub use semantic_version::SemanticVersion;
301+
pub use service_endpoint::ServiceEndpoint;
296302
pub use staking_info::StakingInfo;
297303
pub use system::{
298304
FreezeTransaction,

src/service_endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ‌
33
* Hedera Rust SDK
44
* ​
5-
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC
5+
* Copyright (C) 2022 - 2024 Hedera Hashgraph, LLC
66
* ​
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.

tests/e2e/address_book/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod node_create;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use std::collections::HashMap;
2+
use std::str::FromStr;
3+
4+
use hedera::{
5+
AccountId,
6+
Client,
7+
NodeCreateTransaction,
8+
PrivateKey,
9+
ServiceEndpoint,
10+
};
11+
12+
const VALID_GOSSIP_CERT_DER: &str = "3082052830820310a003020102020101300d06092a864886f70d01010c05003010310e300c060355040313056e6f6465333024170d3234313030383134333233395a181332313234313030383134333233392e3337395a3010310e300c060355040313056e6f64653330820222300d06092a864886f70d01010105000382020f003082020a0282020100af111cff0c4ad8125d2f4b8691ce87332fecc867f7a94ddc0f3f96514cc4224d44af516394f7384c1ef0a515d29aa6116b65bc7e4d7e2d848cf79fbfffedae3a6583b3957a438bdd780c4981b800676ea509bc8c619ae04093b5fc642c4484152f0e8bcaabf19eae025b630028d183a2f47caf6d9f1075efb30a4248679d871beef1b7e9115382270cbdb68682fae4b1fd592cadb414d918c0a8c23795c7c5a91e22b3e90c410825a2bc1a840efc5bf9976a7f474c7ed7dc047e4ddd2db631b68bb4475f173baa3edc234c4bed79c83e2f826f79e07d0aade2d984da447a8514135bfa4145274a7f62959a23c4f0fae5adc6855974e7c04164951d052beb5d45cb1f3cdfd005da894dea9151cb62ba43f4731c6bb0c83e10fd842763ba6844ef499f71bc67fa13e4917fb39f2ad18112170d31cdcb3c61c9e3253accf703dbd8427fdcb87ece78b787b6cfdc091e8fedea8ad95dc64074e1fc6d0e42ea2337e18a5e54e4aaab3791a98dfcef282e2ae1caec9cf986fabe8f36e6a21c8711647177e492d264415e765a86c58599cd97b103cb4f6a01d2edd06e3b60470cf64daca7aecf831197b466cae04baeeac19840a05394bef628aed04b611cfa13677724b08ddfd662b02fd0ef0af17eb7f4fb8c1c17fbe9324f6dc7bcc02449622636cc45ec04909b3120ab4df4726b21bf79e955fe8f832699d2196dcd7a58bfeafb170203010001a38186308183300f0603551d130101ff04053003020100300e0603551d0f0101ff0404030204b030200603551d250101ff0416301406082b0601050507030106082b06010505070302301d0603551d0e04160414643118e05209035edd83d44a0c368de2fb2fe4c0301f0603551d23041830168014643118e05209035edd83d44a0c368de2fb2fe4c0300d06092a864886f70d01010c05000382020100ad41c32bb52650eb4b76fce439c9404e84e4538a94916b3dc7983e8b5c58890556e7384601ca7440dde68233bb07b97bf879b64487b447df510897d2a0a4e789c409a9b237a6ad240ad5464f2ce80c58ddc4d07a29a74eb25e1223db6c00e334d7a27d32bfa6183a82f5e35bccf497c2445a526eabb0c068aba9b94cc092ea4756b0dcfb574f6179f0089e52b174ccdbd04123eeb6d70daeabd8513fcba6be0bc2b45ca9a69802dae11cc4d9ff6053b3a87fd8b0c6bf72fffc3b81167f73cca2b3fd656c5d353c8defca8a76e2ad535f984870a590af4e28fed5c5a125bf360747c5e7742e7813d1bd39b5498c8eb6ba72f267eda034314fdbc596f6b967a0ef8be5231d364e634444c84e64bd7919425171016fcd9bb05f01c58a303dee28241f6e860fc3aac3d92aad7dac2801ce79a3b41a0e1f1509fc0d86e96d94edb18616c000152490f64561713102128990fedd3a5fa642f2ff22dc11bc4dc5b209986a0c3e4eb2bdfdd40e9fdf246f702441cac058dd8d0d51eb0796e2bea2ce1b37b2a2f468505e1f8980a9f66d719df034a6fbbd2f9585991d259678fb9a4aebdc465d22c240351ed44abffbdd11b79a706fdf7c40158d3da87f68d7bd557191a8016b5b899c07bf1b87590feb4fa4203feea9a2a7a73ec224813a12b7a21e5dc93fcde4f0a7620f570d31fe27e9b8d65b74db7dc18a5e51adc42d7805d4661938";
13+
14+
#[tokio::test]
15+
#[ignore = "Temporarily disabled to prevent failed local-node calls"]
16+
async fn create_new_network_node() -> anyhow::Result<()> {
17+
// Set the network
18+
let network = HashMap::from([("localhost:50211".into(), AccountId::new(0, 0, 3))]);
19+
20+
let client = Client::for_network(network)?;
21+
client.set_mirror_network(vec!["127.0.0.1:5600".into()]);
22+
23+
// Set the operator to Account Id 0.0.2
24+
let operator_key = PrivateKey::from_str("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")?;
25+
26+
client.set_operator(AccountId::new(0, 0, 2), operator_key);
27+
28+
// The account of the new node
29+
let account_id = AccountId::new(0, 0, 4);
30+
31+
// Create new endpoints. IPV4 address is not required
32+
let endpoint1 =
33+
ServiceEndpoint { ip_address_v4: None, port: 1234, domain_name: "tests.com".to_owned() };
34+
let endpoint2 =
35+
ServiceEndpoint { ip_address_v4: None, port: 123, domain_name: "testing.com".to_owned() };
36+
37+
// Convert hex string to byte array
38+
let valid_gossip_cert = VALID_GOSSIP_CERT_DER.as_bytes().to_vec();
39+
40+
// Generate new admin key
41+
let admin_key = PrivateKey::generate_ed25519();
42+
43+
let _ = NodeCreateTransaction::new()
44+
.account_id(account_id)
45+
.admin_key(admin_key.public_key())
46+
.description("test node")
47+
.gossip_ca_certificate(valid_gossip_cert)
48+
.gossip_endpoints(vec![endpoint1.clone(), endpoint2.clone()])
49+
.service_endpoints(vec![endpoint1, endpoint2])
50+
.freeze_with(&client)?
51+
.sign(admin_key)
52+
.execute(&client)
53+
.await?
54+
.get_receipt(&client);
55+
56+
Ok(())
57+
}

tests/e2e/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod account;
2+
mod address_book;
23
mod client;
34
mod common;
45
mod contract;

0 commit comments

Comments
 (0)