diff --git a/client/faucet/src/main.rs b/client/faucet/src/main.rs index 86e449266e645..2864c2f71e30a 100644 --- a/client/faucet/src/main.rs +++ b/client/faucet/src/main.rs @@ -136,7 +136,7 @@ mod tests { transaction::{ metadata::{CoinTradeMetadata, Metadata}, SignedTransaction, TransactionPayload, - TransactionPayload::Script, + TransactionPayload::{Script, ScriptFunction}, }, }, }; @@ -403,6 +403,18 @@ mod tests { } _ => panic!("unexpected type of script"), }, + ScriptFunction(_) => match ScriptFunctionCall::decode(payload) { + Some(ScriptFunctionCall::PeerToPeerWithMetadata { metadata, .. }) => { + match bcs::from_bytes(&metadata).expect("should decode metadata") { + Metadata::CoinTradeMetadata(CoinTradeMetadata::CoinTradeMetadataV0( + coin_trade_metadata, + )) => coin_trade_metadata.trade_ids, + _ => panic!("unexpected type of transaction metadata"), + } + } + _ => panic!("unexpected type of script"), + }, + _ => panic!("unexpected payload type"), } } @@ -489,7 +501,28 @@ mod tests { .unwrap() .remove(index); } - _ => panic!("unexpected type of script"), + ScriptFunctionCall::CreateParentVaspAccount { + new_account_address: address, + .. + } => { + let mut writer = accounts.write(); + let previous = writer + .insert(address, create_vasp_account(&address.to_string(), 0)); + assert!(previous.is_none(), "should not create account twice"); + } + ScriptFunctionCall::CreateDesignatedDealer { addr: address, .. } => { + let mut writer = accounts.write(); + let previous = + writer.insert(address, create_dd_account(&address.to_string(), 0)); + assert!(previous.is_none(), "should not create account twice"); + } + ScriptFunctionCall::PeerToPeerWithMetadata { payee, amount, .. } => { + let mut writer = accounts.write(); + let account = + writer.get_mut(&payee).expect("account should be created"); + account["balances"][0]["amount"] = serde_json::json!(amount); + } + script => panic!("unexpected type of script: {:?}", script), } } create_response(&req["id"], chain_id.id(), None) diff --git a/json-rpc/integration-tests/src/lib.rs b/json-rpc/integration-tests/src/lib.rs index 20b2a06a1dff4..1c95d956986de 100644 --- a/json-rpc/integration-tests/src/lib.rs +++ b/json-rpc/integration-tests/src/lib.rs @@ -554,7 +554,7 @@ impl Test for PeerToPeerWithEvents { impl PublicUsageTest for PeerToPeerWithEvents { fn run<'t>(&self, ctx: &mut PublicUsageContext<'t>) -> Result<()> { let env = JsonRpcTestHelper::new(ctx.url().to_owned()); - let factory = ctx.transaction_factory(); + let factory = ctx.transaction_factory().with_diem_version(0); // Force use of Scripts not ScriptFunctions let prev_ledger_version = env.send("get_metadata", json!([])).diem_ledger_version; diff --git a/sdk/src/transaction_builder.rs b/sdk/src/transaction_builder.rs index 0dfcba2e67769..8de868f2211bc 100644 --- a/sdk/src/transaction_builder.rs +++ b/sdk/src/transaction_builder.rs @@ -95,7 +95,7 @@ impl TransactionFactory { gas_currency: Currency::XUS, transaction_expiration_time: 100, chain_id, - diem_version: 0, + diem_version: 2, } } diff --git a/testsuite/smoke-test/src/transaction.rs b/testsuite/smoke-test/src/transaction.rs index 4f503915e49aa..6b31c733bd037 100644 --- a/testsuite/smoke-test/src/transaction.rs +++ b/testsuite/smoke-test/src/transaction.rs @@ -50,6 +50,7 @@ impl PublicUsageTest for ExternalTransactionSigner { let unsigned_txn = ctx .transaction_factory() + .with_diem_version(0) // Force Script not ScriptFunctions .peer_to_peer(Currency::XUS, receiver.address(), amount) .sender(sender_address) .sequence_number(test_sequence_number)