Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jan 11, 2024
1 parent 71b34ef commit 14dd3cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 54 deletions.
25 changes: 7 additions & 18 deletions sdk/tests/client/signing/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use iota_sdk::{
output::AccountId,
payload::{signed_transaction::Transaction, SignedTransactionPayload},
protocol::protocol_parameters,
slot::SlotIndex,
unlock::{SignatureUnlock, Unlock},
},
};
Expand Down Expand Up @@ -47,6 +48,7 @@ async fn sign_account_state_transition() -> Result<()> {

let protocol_parameters = protocol_parameters();
let account_id = AccountId::from_str(ACCOUNT_ID_1)?;
let slot_index = SlotIndex::from(10);

let inputs = build_inputs(
[Account(
Expand All @@ -57,7 +59,7 @@ async fn sign_account_state_transition() -> Result<()> {
None,
Some(Bip44::new(SHIMMER_COIN_TYPE)),
)],
None,
Some(slot_index),
);

let outputs = build_outputs([Account(1_000_000, account_id, address.clone(), None, None, None)]);
Expand All @@ -70,14 +72,7 @@ async fn sign_account_state_transition() -> Result<()> {
.collect::<Vec<_>>(),
)
.with_outputs(outputs)
.with_creation_slot(
inputs
.iter()
.map(|i| i.output_id().transaction_id().slot_index())
.max()
.unwrap()
+ 1,
)
.with_creation_slot(slot_index + 1)
.finish_with_params(&protocol_parameters)?;

let prepared_transaction_data = PreparedTransactionData {
Expand Down Expand Up @@ -123,6 +118,7 @@ async fn account_reference_unlocks() -> Result<()> {
let protocol_parameters = protocol_parameters();
let account_id = AccountId::from_str(ACCOUNT_ID_1)?;
let account_address = Address::Account(AccountAddress::new(account_id));
let slot_index = SlotIndex::from(10);

let inputs = build_inputs(
[
Expand All @@ -137,7 +133,7 @@ async fn account_reference_unlocks() -> Result<()> {
Basic(1_000_000, account_address.clone(), None, None, None, None, None, None),
Basic(1_000_000, account_address.clone(), None, None, None, None, None, None),
],
None,
Some(slot_index),
);

let outputs = build_outputs([
Expand All @@ -153,14 +149,7 @@ async fn account_reference_unlocks() -> Result<()> {
.collect::<Vec<_>>(),
)
.with_outputs(outputs)
.with_creation_slot(
inputs
.iter()
.map(|i| i.output_id().transaction_id().slot_index())
.max()
.unwrap()
+ 1,
)
.with_creation_slot(slot_index + 1)
.finish_with_params(&protocol_parameters)?;

let prepared_transaction_data = PreparedTransactionData {
Expand Down
37 changes: 10 additions & 27 deletions sdk/tests/client/signing/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use iota_sdk::{
input::{Input, UtxoInput},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
protocol::protocol_parameters,
slot::SlotIndex,
unlock::{SignatureUnlock, Unlock},
},
};
Expand All @@ -38,6 +39,7 @@ async fn single_ed25519_unlock() -> Result<()> {
.into_inner();

let protocol_parameters = protocol_parameters();
let slot_index = SlotIndex::from(10);

let inputs = build_inputs(
[Basic(
Expand All @@ -50,7 +52,7 @@ async fn single_ed25519_unlock() -> Result<()> {
None,
Some(Bip44::new(SHIMMER_COIN_TYPE)),
)],
None,
Some(slot_index),
);

let outputs = build_outputs([Basic(
Expand All @@ -72,14 +74,7 @@ async fn single_ed25519_unlock() -> Result<()> {
.collect::<Vec<_>>(),
)
.with_outputs(outputs)
.with_creation_slot(
inputs
.iter()
.map(|i| i.output_id().transaction_id().slot_index())
.max()
.unwrap()
+ 1,
)
.with_creation_slot(slot_index + 1)
.finish_with_params(&protocol_parameters)?;

let prepared_transaction_data = PreparedTransactionData {
Expand Down Expand Up @@ -123,6 +118,7 @@ async fn ed25519_reference_unlocks() -> Result<()> {
.into_inner();

let protocol_parameters = protocol_parameters();
let slot_index = SlotIndex::from(10);

let inputs = build_inputs(
[
Expand Down Expand Up @@ -157,7 +153,7 @@ async fn ed25519_reference_unlocks() -> Result<()> {
Some(Bip44::new(SHIMMER_COIN_TYPE)),
),
],
None,
Some(slot_index),
);

let outputs = build_outputs([Basic(
Expand All @@ -179,14 +175,7 @@ async fn ed25519_reference_unlocks() -> Result<()> {
.collect::<Vec<_>>(),
)
.with_outputs(outputs)
.with_creation_slot(
inputs
.iter()
.map(|i| i.output_id().transaction_id().slot_index())
.max()
.unwrap()
+ 1,
)
.with_creation_slot(slot_index + 1)
.finish_with_params(&protocol_parameters)?;

let prepared_transaction_data = PreparedTransactionData {
Expand Down Expand Up @@ -251,6 +240,7 @@ async fn two_signature_unlocks() -> Result<()> {
.into_inner();

let protocol_parameters = protocol_parameters();
let slot_index = SlotIndex::from(10);

let inputs = build_inputs(
[
Expand All @@ -275,7 +265,7 @@ async fn two_signature_unlocks() -> Result<()> {
Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)),
),
],
None,
Some(slot_index),
);

let outputs = build_outputs([Basic(
Expand All @@ -297,14 +287,7 @@ async fn two_signature_unlocks() -> Result<()> {
.collect::<Vec<_>>(),
)
.with_outputs(outputs)
.with_creation_slot(
inputs
.iter()
.map(|i| i.output_id().transaction_id().slot_index())
.max()
.unwrap()
+ 1,
)
.with_creation_slot(slot_index + 1)
.finish_with_params(&protocol_parameters)?;

let prepared_transaction_data = PreparedTransactionData {
Expand Down
13 changes: 4 additions & 9 deletions sdk/tests/client/signing/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use iota_sdk::{
output::NftId,
payload::{signed_transaction::Transaction, SignedTransactionPayload},
protocol::protocol_parameters,
slot::SlotIndex,
unlock::{SignatureUnlock, Unlock},
},
};
Expand Down Expand Up @@ -48,6 +49,7 @@ async fn nft_reference_unlocks() -> Result<()> {
let protocol_parameters = protocol_parameters();
let nft_id = NftId::from_str(NFT_ID_1)?;
let nft_address = Address::Nft(NftAddress::new(nft_id));
let slot_index = SlotIndex::from(10);

let inputs = build_inputs(
[
Expand All @@ -64,7 +66,7 @@ async fn nft_reference_unlocks() -> Result<()> {
Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None),
Basic(1_000_000, nft_address.clone(), None, None, None, None, None, None),
],
None,
Some(slot_index),
);

let outputs = build_outputs([
Expand All @@ -80,14 +82,7 @@ async fn nft_reference_unlocks() -> Result<()> {
.collect::<Vec<_>>(),
)
.with_outputs(outputs)
.with_creation_slot(
inputs
.iter()
.map(|i| i.output_id().transaction_id().slot_index())
.max()
.unwrap()
+ 1,
)
.with_creation_slot(slot_index + 1)
.finish_with_params(&protocol_parameters)?;

let prepared_transaction_data = PreparedTransactionData {
Expand Down

0 comments on commit 14dd3cc

Please sign in to comment.