Skip to content

Commit

Permalink
sdk: default to diem_version 2 for TransactionBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and bors-libra committed Aug 11, 2021
1 parent 3a4b86a commit aec868a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
37 changes: 35 additions & 2 deletions client/faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
transaction::{
metadata::{CoinTradeMetadata, Metadata},
SignedTransaction, TransactionPayload,
TransactionPayload::Script,
TransactionPayload::{Script, ScriptFunction},
},
},
};
Expand Down Expand Up @@ -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"),
}
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion json-rpc/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl TransactionFactory {
gas_currency: Currency::XUS,
transaction_expiration_time: 100,
chain_id,
diem_version: 0,
diem_version: 2,
}
}

Expand Down
1 change: 1 addition & 0 deletions testsuite/smoke-test/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aec868a

Please sign in to comment.