Skip to content

Commit 5a72cc5

Browse files
gsstoykovRickyLB
andauthored
feat: Add auto set for auto_renew_account (#907)
Signed-off-by: gsstoykov <[email protected]> Co-authored-by: Ricky Saechao <[email protected]>
1 parent 061b730 commit 5a72cc5

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed

.github/workflows/rust-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
repo-token: ${{ secrets.GITHUB_TOKEN }}
118118

119119
- name: Start the local node
120-
run: npx @hashgraph/hedera-local start -d --network local
120+
run: npx @hashgraph/hedera-local start -d --network local --network-tag=0.60.0-alpha.0
121121

122122
- name: "Create env file"
123123
run: |

src/token/token_create_transaction.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,15 @@ impl ToTransactionDataProtobuf for TokenCreateTransactionData {
487487
) -> services::transaction_body::Data {
488488
let _ = chunk_info.assert_single_transaction();
489489

490-
services::transaction_body::Data::TokenCreation(self.to_protobuf())
490+
// Generate the protobuf data
491+
let mut protobuf_data = self.to_protobuf();
492+
493+
// Manually assign the auto_renew_account with operator_id if none is set
494+
if protobuf_data.auto_renew_account.is_none() {
495+
let operator_id = chunk_info.current_transaction_id.account_id;
496+
protobuf_data.auto_renew_account = Some(operator_id.to_protobuf());
497+
}
498+
services::transaction_body::Data::TokenCreation(protobuf_data)
491499
}
492500
}
493501

src/topic/topic_create_transaction.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,15 @@ impl ToTransactionDataProtobuf for TopicCreateTransactionData {
240240
) -> services::transaction_body::Data {
241241
let _ = chunk_info.assert_single_transaction();
242242

243-
services::transaction_body::Data::ConsensusCreateTopic(self.to_protobuf())
243+
// Generate the protobuf data
244+
let mut protobuf_data = self.to_protobuf();
245+
246+
// Manually assign the auto_renew_account with operator_id if none is set
247+
if protobuf_data.auto_renew_account.is_none() {
248+
let operator_id = chunk_info.current_transaction_id.account_id;
249+
protobuf_data.auto_renew_account = Some(operator_id.to_protobuf());
250+
}
251+
services::transaction_body::Data::ConsensusCreateTopic(protobuf_data)
244252
}
245253
}
246254

tests/e2e/token/create.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use hedera::{
1212
Status,
1313
TokenCreateTransaction,
1414
TokenId,
15+
TokenInfoQuery,
1516
TokenType,
1617
};
1718
use time::{
@@ -611,3 +612,59 @@ async fn royalty_fee() -> anyhow::Result<()> {
611612
account.delete(&client).await?;
612613
Ok(())
613614
}
615+
616+
#[tokio::test]
617+
async fn auto_renew_account() -> anyhow::Result<()> {
618+
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
619+
return Ok(());
620+
};
621+
622+
let account = Account::create(Hbar::new(0), &client).await?;
623+
624+
let token_id = TokenCreateTransaction::new()
625+
.name("ffff")
626+
.symbol("F")
627+
.treasury_account_id(account.id)
628+
.auto_renew_account_id(account.id)
629+
.expiration_time(OffsetDateTime::now_utc() + Duration::minutes(5))
630+
.sign(account.key.clone())
631+
.execute(&client)
632+
.await?
633+
.get_receipt(&client)
634+
.await?
635+
.token_id
636+
.unwrap();
637+
638+
let info = TokenInfoQuery::new().token_id(token_id).execute(&client).await?;
639+
640+
// auto renew account should be set to operator account
641+
assert_eq!(info.auto_renew_account.unwrap(), account.id);
642+
Ok(())
643+
}
644+
645+
#[tokio::test]
646+
async fn autoset_auto_renew_account() -> anyhow::Result<()> {
647+
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
648+
return Ok(());
649+
};
650+
651+
let account = Account::create(Hbar::new(0), &client).await?;
652+
653+
let token_id = TokenCreateTransaction::new()
654+
.name("ffff")
655+
.symbol("F")
656+
.treasury_account_id(account.id)
657+
.expiration_time(OffsetDateTime::now_utc() + Duration::minutes(5))
658+
.sign(account.key.clone())
659+
.execute(&client)
660+
.await?
661+
.get_receipt(&client)
662+
.await?
663+
.token_id
664+
.unwrap();
665+
666+
let info = TokenInfoQuery::new().token_id(token_id).execute(&client).await?;
667+
// auto renew account should be set to operator account
668+
assert_eq!(info.auto_renew_account.unwrap(), client.get_operator_account_id().unwrap());
669+
Ok(())
670+
}

tests/e2e/topic/create.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,27 @@ async fn fieldless() -> anyhow::Result<()> {
6262
.await?
6363
.topic_id
6464
.unwrap();
65+
Ok(())
66+
}
6567

68+
#[tokio::test]
69+
async fn autoset_auto_renew_account() -> anyhow::Result<()> {
70+
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
71+
return Ok(());
72+
};
73+
74+
let topic_id = TopicCreateTransaction::new()
75+
.admin_key(client.get_operator_public_key().unwrap())
76+
.topic_memo("[e2e::TopicCreateTransaction]")
77+
.execute(&client)
78+
.await?
79+
.get_receipt(&client)
80+
.await?
81+
.topic_id
82+
.unwrap();
83+
84+
let info = TopicInfoQuery::new().topic_id(topic_id).execute(&client).await?;
85+
assert_eq!(info.auto_renew_account_id.unwrap(), client.get_operator_account_id().unwrap());
6686
Ok(())
6787
}
6888

@@ -429,7 +449,6 @@ async fn exempts_fee_exempt_keys_from_hbar_fees() -> anyhow::Result<()> {
429449

430450
// Test temporarily taken out until can figure out a solution for a separate freeze
431451
#[tokio::test]
432-
#[ignore = "Not Supported. Apply test when 0.60.0 is released to networks (mainnet, testnet, previewnet)"]
433452
async fn automatically_assign_auto_renew_account_id_on_topic_create() -> anyhow::Result<()> {
434453
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
435454
return Ok(());
@@ -448,7 +467,6 @@ async fn automatically_assign_auto_renew_account_id_on_topic_create() -> anyhow:
448467
}
449468

450469
#[tokio::test]
451-
#[ignore = "Not Supported. Apply test when 0.60.0 is released to networks (mainnet, testnet, previewnet)"]
452470
async fn create_with_transaction_id_assigns_auto_renew_account_id_to_transaction_id_account_id(
453471
) -> anyhow::Result<()> {
454472
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {

0 commit comments

Comments
 (0)