From 5fa192f2f3ef746c464884a00400e52495f7f38f Mon Sep 17 00:00:00 2001 From: Dkwcs Date: Thu, 20 Feb 2025 15:23:05 +0100 Subject: [PATCH 1/3] feat(iota-transactional-test-runner): Add a way to create programmable transactions with gas from a sponsor address, rather than a sender address Add the ability to specify an explicit gas payment object to a programmable transaction in transactional test runner --- .../src/args.rs | 4 + .../src/test_adapter.rs | 87 ++++++++++++++----- 2 files changed, 68 insertions(+), 23 deletions(-) diff --git a/crates/iota-transactional-test-runner/src/args.rs b/crates/iota-transactional-test-runner/src/args.rs index f53437d59d2..f714b7030f6 100644 --- a/crates/iota-transactional-test-runner/src/args.rs +++ b/crates/iota-transactional-test-runner/src/args.rs @@ -105,10 +105,14 @@ pub struct ConsensusCommitPrologueCommand { pub struct ProgrammableTransactionCommand { #[arg(long = "sender")] pub sender: Option, + #[clap(long = "sponsor")] + pub sponsor: Option, #[arg(long = "gas-budget")] pub gas_budget: Option, #[arg(long = "gas-price")] pub gas_price: Option, + #[clap(long = "gas-payment", value_parser = parse_fake_id)] + pub gas_payment: Option, #[arg(long = "dev-inspect")] pub dev_inspect: bool, #[arg( diff --git a/crates/iota-transactional-test-runner/src/test_adapter.rs b/crates/iota-transactional-test-runner/src/test_adapter.rs index a14230ed8a0..0a0754e76f6 100644 --- a/crates/iota-transactional-test-runner/src/test_adapter.rs +++ b/crates/iota-transactional-test-runner/src/test_adapter.rs @@ -62,7 +62,7 @@ use iota_types::{ Argument, CallArg, Command, ProgrammableTransaction, Transaction, TransactionData, TransactionDataAPI, TransactionKind, VerifiedTransaction, }, - utils::to_sender_signed_transaction, + utils::{to_sender_signed_transaction, to_sender_signed_transaction_with_multi_signers}, }; use move_binary_format::CompiledModule; use move_bytecode_utils::module_cache::GetModule; @@ -748,8 +748,10 @@ impl MoveTestAdapter<'_> for IotaTestAdapter { } IotaSubcommand::ProgrammableTransaction(ProgrammableTransactionCommand { sender, + sponsor, gas_budget, gas_price, + gas_payment, dev_inspect, inputs, }) => { @@ -795,15 +797,21 @@ impl MoveTestAdapter<'_> for IotaTestAdapter { let summary = if !dev_inspect { let gas_budget = gas_budget.unwrap_or(DEFAULT_GAS_BUDGET); let gas_price = gas_price.unwrap_or(self.gas_price); - let transaction = self.sign_txn(sender, |sender, gas| { - TransactionData::new_programmable( - sender, - vec![gas], - ProgrammableTransaction { inputs, commands }, - gas_budget, - gas_price, - ) - }); + let transaction = self.sign_sponsor_txn( + sender, + sponsor, + gas_payment, + |sender, sponsor, gas| { + TransactionData::new_programmable_allow_sponsor( + sender, + vec![gas], + ProgrammableTransaction { inputs, commands }, + gas_budget, + gas_price, + sponsor, + ) + }, + ); self.execute_txn(transaction).await? } else { assert!( @@ -1387,13 +1395,49 @@ impl IotaTestAdapter { ObjectRef, ) -> TransactionData, ) -> Transaction { - let test_account = self.get_sender(sender); - let gas_payment = self - .get_object(&test_account.gas, None) + self.sign_sponsor_txn(sender, None, None, move |sender, _, gas| { + txn_data(sender, gas) + }) + } + + fn sign_sponsor_txn( + &self, + sender: Option, + sponsor: Option, + payment: Option, + txn_data: impl FnOnce( + // sender + IotaAddress, + // sponsor + IotaAddress, + // gas + ObjectRef, + ) -> TransactionData, + ) -> Transaction { + let sender = self.get_sender(sender); + let sponsor = sponsor.map_or(sender, |a| self.get_sender(Some(a))); + + let payment = if let Some(payment) = payment { + self.fake_to_real_object_id(payment) + .expect("Could not find specified payment object") + } else { + sponsor.gas + }; + + let payment_ref = self + .get_object(&payment, None) .unwrap() .compute_object_reference(); - let data = txn_data(test_account.address, gas_payment); - to_sender_signed_transaction(data, &test_account.key_pair) + + let data = txn_data(sender.address, sponsor.address, payment_ref); + if sender.address == sponsor.address { + to_sender_signed_transaction(data, &sender.key_pair) + } else { + to_sender_signed_transaction_with_multi_signers(data, vec![ + &sender.key_pair, + &sponsor.key_pair, + ]) + } } fn get_sender(&self, sender: Option) -> &TestAccount { @@ -2195,14 +2239,11 @@ async fn init_sim_executor( objects.push(o.clone()); account_objects.insert(name.clone(), o.id()); - accounts.insert( - name.to_owned(), - TestAccount { - address: addr, - key_pair: kp, - gas: o.id(), - }, - ); + accounts.insert(name.to_owned(), TestAccount { + address: addr, + key_pair: kp, + gas: o.id(), + }); } let o = sim .store() From f6284066134c5e5917448a59c79593e7753bc426 Mon Sep 17 00:00:00 2001 From: Dkwcs Date: Thu, 20 Feb 2025 17:03:57 +0100 Subject: [PATCH 2/3] fmt --- .../src/test_adapter.rs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/iota-transactional-test-runner/src/test_adapter.rs b/crates/iota-transactional-test-runner/src/test_adapter.rs index 0a0754e76f6..33ea17ae301 100644 --- a/crates/iota-transactional-test-runner/src/test_adapter.rs +++ b/crates/iota-transactional-test-runner/src/test_adapter.rs @@ -1433,10 +1433,10 @@ impl IotaTestAdapter { if sender.address == sponsor.address { to_sender_signed_transaction(data, &sender.key_pair) } else { - to_sender_signed_transaction_with_multi_signers(data, vec![ - &sender.key_pair, - &sponsor.key_pair, - ]) + to_sender_signed_transaction_with_multi_signers( + data, + vec![&sender.key_pair, &sponsor.key_pair], + ) } } @@ -2239,11 +2239,14 @@ async fn init_sim_executor( objects.push(o.clone()); account_objects.insert(name.clone(), o.id()); - accounts.insert(name.to_owned(), TestAccount { - address: addr, - key_pair: kp, - gas: o.id(), - }); + accounts.insert( + name.to_owned(), + TestAccount { + address: addr, + key_pair: kp, + gas: o.id(), + }, + ); } let o = sim .store() From ff7d6c28febf0a754a8068e1faea5ccea84bb53e Mon Sep 17 00:00:00 2001 From: Dkwcs Date: Fri, 21 Feb 2025 10:56:47 +0100 Subject: [PATCH 3/3] cargo lock --- Cargo.lock | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 854cd8621bc..5bd44f3fadd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7595,6 +7595,7 @@ dependencies = [ "axum", "axum-extra", "axum-server", + "bcs", "bytes", "clap", "const-str", @@ -7604,6 +7605,7 @@ dependencies = [ "hex", "hyper 1.4.1", "iota-metrics", + "iota-sdk 0.10.0-alpha", "iota-tls", "iota-types", "itertools 0.13.0", @@ -7709,6 +7711,32 @@ dependencies = [ "url", ] +[[package]] +name = "iota-rest-kv" +version = "0.10.0-alpha" +dependencies = [ + "anyhow", + "aws-config", + "aws-sdk-dynamodb", + "axum", + "base64-url", + "bcs", + "bin-version", + "bytes", + "clap", + "iota-config", + "iota-storage", + "iota-types", + "object_store 0.10.2", + "serde", + "serde_yaml", + "thiserror", + "tokio", + "tokio-util 0.7.12", + "tracing", + "tracing-subscriber", +] + [[package]] name = "iota-rosetta" version = "0.10.0-alpha" @@ -8073,6 +8101,7 @@ dependencies = [ "rustls 0.23.18", "serde", "serde_json", + "strum 0.26.3", "tap", "telemetry-subscribers", "tempfile",