From 05fd9c73c104b435a67c8c51ebf7c6aa329788f1 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 3 Oct 2023 19:52:25 +0200 Subject: [PATCH] Fix some tests --- .../client/input_selection/account_outputs.rs | 712 +++--------------- sdk/tests/client/input_selection/burn.rs | 4 +- .../client/input_selection/foundry_outputs.rs | 68 +- sdk/tests/client/signing/account.rs | 78 -- 4 files changed, 105 insertions(+), 757 deletions(-) diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/input_selection/account_outputs.rs index 548a1c92bf..dc3a0a2f25 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/input_selection/account_outputs.rs @@ -15,8 +15,8 @@ use iota_sdk::{ use crate::client::{ addresses, build_inputs, build_outputs, is_remainder_or_return, unsorted_eq, Build::{Account, Basic}, - ACCOUNT_ID_0, ACCOUNT_ID_1, ACCOUNT_ID_2, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ACCOUNT_2, - BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1, BECH32_ADDRESS_ED25519_2, BECH32_ADDRESS_NFT_1, TOKEN_SUPPLY, + ACCOUNT_ID_0, ACCOUNT_ID_1, ACCOUNT_ID_2, BECH32_ADDRESS_ACCOUNT_1, BECH32_ADDRESS_ED25519_0, + BECH32_ADDRESS_ED25519_1, BECH32_ADDRESS_ED25519_2, BECH32_ADDRESS_NFT_1, TOKEN_SUPPLY, }; #[test] @@ -1037,7 +1037,7 @@ fn take_amount_from_account_to_fund_basic() { assert_eq!(output.amount(), 1_800_000); assert_eq!(output.as_account().native_tokens().len(), 0); assert_eq!(*output.as_account().account_id(), account_id_1); - assert_eq!(output.as_account().unlock_conditions().len(), 2); + assert_eq!(output.as_account().unlock_conditions().len(), 1); assert_eq!(output.as_account().features().len(), 0); assert_eq!(output.as_account().immutable_features().len(), 0); assert_eq!( @@ -1134,92 +1134,6 @@ fn account_burn_should_not_validate_account_address() { )); } -#[test] -fn account_governance_transition_should_not_validate_account_sender() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([ - Basic(2_000_000, BECH32_ADDRESS_ED25519_0, None, None, None, None, None, None), - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - ]); - let mut outputs = build_outputs([Basic( - 2_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ACCOUNT_1), - None, - None, - None, - None, - )]); - outputs.push(inputs[1].output.clone()); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Sender(sender))) if sender == Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap() - )); -} - -#[test] -fn account_governance_transition_should_not_validate_account_address() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([ - Basic(2_000_000, BECH32_ADDRESS_ACCOUNT_1, None, None, None, None, None, None), - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - ]); - let mut outputs = build_outputs([Basic( - 2_000_000, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - None, - None, - )]); - outputs.push(inputs[1].output.clone()); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Account(account_id))) if account_id == account_id_1 - )); -} - #[test] fn transitioned_zero_account_id_no_longer_is_zero() { let protocol_parameters = protocol_parameters(); @@ -1435,7 +1349,7 @@ fn state_controller_sender_required_already_selected() { } #[test] -fn state_controller_sender_required_but_governance() { +fn state_transition_and_required() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); @@ -1448,65 +1362,48 @@ fn state_controller_sender_required_but_governance() { None, None, )]); - let outputs = build_outputs([ - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_0), - None, - None, - None, - None, - ), - ]); + let outputs = build_outputs([Account( + 2_000_000, + account_id_1, + BECH32_ADDRESS_ED25519_0, + None, + None, + None, + None, + )]); let selected = InputSelection::new( inputs.clone(), - outputs, + outputs.clone(), addresses([BECH32_ADDRESS_ED25519_0]), protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .select(); + .select() + .unwrap(); - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Sender(sender))) if sender == Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap() - )); + assert!(unsorted_eq(&selected.inputs, &inputs)); + assert!(unsorted_eq(&selected.outputs, &outputs)); } #[test] -fn governor_sender_required() { +fn remainder_address_in_state_controller() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - Basic(1_000_000, BECH32_ADDRESS_ED25519_0, None, None, None, None, None, None), - ]); - let outputs = build_outputs([Basic( - 1_000_000, + let inputs = build_inputs([Account( + 2_000_000, + account_id_1, BECH32_ADDRESS_ED25519_0, None, - Some(BECH32_ADDRESS_ED25519_1), + None, + None, + None, + )]); + let outputs = build_outputs([Account( + 1_000_000, + account_id_1, + BECH32_ADDRESS_ED25519_0, None, None, None, @@ -1516,7 +1413,7 @@ fn governor_sender_required() { let selected = InputSelection::new( inputs.clone(), outputs.clone(), - addresses([BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1]), + addresses([BECH32_ADDRESS_ED25519_0]), protocol_parameters, ) .select() @@ -1525,63 +1422,62 @@ fn governor_sender_required() { assert!(unsorted_eq(&selected.inputs, &inputs)); assert_eq!(selected.outputs.len(), 2); assert!(selected.outputs.contains(&outputs[0])); + selected.outputs.iter().for_each(|output| { + if !outputs.contains(output) { + assert!(is_remainder_or_return( + output, + 1_000_000, + BECH32_ADDRESS_ED25519_0, + None + )); + } + }); } #[test] -fn governor_sender_required_already_selected() { +fn state_transition_required_but_state_controller_not_provided() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - Basic(1_000_000, BECH32_ADDRESS_ED25519_1, None, None, None, None, None, None), - ]); - let outputs = build_outputs([ - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_1), - None, - None, - None, - None, - ), - ]); + let inputs = build_inputs([Account( + 2_000_000, + account_id_1, + BECH32_ADDRESS_ED25519_0, + None, + None, + None, + None, + )]); + let outputs = build_outputs([Basic( + 1_000_000, + BECH32_ADDRESS_ED25519_0, + None, + None, + None, + None, + None, + None, + )]); let selected = InputSelection::new( - inputs.clone(), - outputs.clone(), + inputs, + outputs, addresses([BECH32_ADDRESS_ED25519_1]), protocol_parameters, ) - .with_required_inputs([*inputs[0].output_id()]) - .select() - .unwrap(); + .select(); - assert!(unsorted_eq(&selected.inputs, &inputs)); - assert!(unsorted_eq(&selected.outputs, &outputs)); + assert!(matches!( + selected, + Err(Error::InsufficientAmount { + found: 0, + required: 1_000_000, + }) + )); } #[test] -fn governance_transition_and_required() { +fn state_transition_but_state_controller_not_owned() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); @@ -1605,21 +1501,21 @@ fn governance_transition_and_required() { )]); let selected = InputSelection::new( - inputs.clone(), - outputs.clone(), + inputs, + outputs, addresses([BECH32_ADDRESS_ED25519_1]), protocol_parameters, ) - .with_required_inputs([*inputs[0].output_id()]) - .select() - .unwrap(); + .select(); - assert!(unsorted_eq(&selected.inputs, &inputs)); - assert!(unsorted_eq(&selected.outputs, &outputs)); + assert!(matches!( + selected, + Err(Error::UnfulfillableRequirement(Requirement::Ed25519(address))) if address == Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap() + )); } #[test] -fn state_transition_and_required() { +fn burn_account_but_governor_not_owned() { let protocol_parameters = protocol_parameters(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); @@ -1632,416 +1528,15 @@ fn state_transition_and_required() { None, None, )]); - let outputs = build_outputs([Account( - 2_000_000, - account_id_1, + let outputs = build_outputs([Basic( + 1_000_000, BECH32_ADDRESS_ED25519_0, None, None, None, None, - )]); - - let selected = InputSelection::new( - inputs.clone(), - outputs.clone(), - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .with_required_inputs([*inputs[0].output_id()]) - .select() - .unwrap(); - - assert!(unsorted_eq(&selected.inputs, &inputs)); - assert!(unsorted_eq(&selected.outputs, &outputs)); -} - -#[test] -fn governor_sender_required_but_state() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([ - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_1), - None, - None, - None, - None, - ), - ]); - - let selected = InputSelection::new( - inputs.clone(), - outputs, - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .with_required_inputs([*inputs[0].output_id()]) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Sender(sender))) if sender == Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap() - )); -} - -#[test] -fn both_state_controller_and_governor_sender() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([ - Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_0), - None, - None, - None, - None, - ), - Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_1), - None, - None, - None, - None, - ), - ]); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_0, BECH32_ADDRESS_ED25519_1]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Sender(sender))) if sender == Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap() - )); -} - -#[test] -fn remainder_address_in_state_controller() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs.clone(), - outputs.clone(), - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .select() - .unwrap(); - - assert!(unsorted_eq(&selected.inputs, &inputs)); - assert_eq!(selected.outputs.len(), 2); - assert!(selected.outputs.contains(&outputs[0])); - selected.outputs.iter().for_each(|output| { - if !outputs.contains(output) { - assert!(is_remainder_or_return( - output, - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None - )); - } - }); -} - -#[test] -fn remainder_address_in_governor() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ACCOUNT_2, - None, - None, - None, - None, - ), - Basic(1_000_000, BECH32_ADDRESS_ED25519_0, None, None, None, None, None, None), - ]); - let outputs = build_outputs([Account( - 1_000_000, - account_id_1, - BECH32_ADDRESS_ACCOUNT_2, - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs.clone(), - outputs.clone(), - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - // Add the basic output so it will be consumed - .with_required_inputs([*inputs[1].output_id()]) - .select() - .unwrap(); - - assert!(unsorted_eq(&selected.inputs, &inputs)); - assert_eq!(selected.outputs.len(), 2); - assert!(selected.outputs.contains(&outputs[0])); - selected.outputs.iter().for_each(|output| { - if !outputs.contains(output) { - assert!(is_remainder_or_return( - output, - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None - )); - } - }); -} - -#[test] -fn do_not_change_amount_of_governance_transition() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_1), - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_1]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::InsufficientAmount { - found: 2_000_000, - required: 3_000_000, - }) - )); -} - -#[test] -fn state_transition_required_but_state_controller_not_provided() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_1]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::InsufficientAmount { - found: 0, - required: 1_000_000, - }) - )); -} - -#[test] -fn state_transition_but_state_controller_not_owned() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_1]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Ed25519(address))) if address == Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap() - )); -} - -#[test] -fn governance_transition_but_governor_not_owned() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Ed25519(address))) if address == Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap() - )); -} - -#[test] -fn burn_account_but_governor_not_owned() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - None, - None, + None, + None, )]); let selected = InputSelection::new( @@ -2097,42 +1592,3 @@ fn sender_in_state_controller_but_not_owned() { Err(Error::UnfulfillableRequirement(Requirement::Sender(sender))) if sender == Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap() )); } - -#[test] -fn sender_in_governor_but_not_owned() { - let protocol_parameters = protocol_parameters(); - let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); - - let inputs = build_inputs([Account( - 2_000_000, - account_id_1, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - )]); - let outputs = build_outputs([Basic( - 1_000_000, - BECH32_ADDRESS_ED25519_0, - None, - Some(BECH32_ADDRESS_ED25519_1), - None, - None, - None, - None, - )]); - - let selected = InputSelection::new( - inputs, - outputs, - addresses([BECH32_ADDRESS_ED25519_2]), - protocol_parameters, - ) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Sender(sender))) if sender == Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap() - )); -} diff --git a/sdk/tests/client/input_selection/burn.rs b/sdk/tests/client/input_selection/burn.rs index 843ec6f69f..fa428721a2 100644 --- a/sdk/tests/client/input_selection/burn.rs +++ b/sdk/tests/client/input_selection/burn.rs @@ -637,7 +637,7 @@ fn burn_foundry_present() { assert_eq!(output.amount(), 1_000_000); assert_eq!(output.as_account().native_tokens().len(), 0); assert_eq!(*output.as_account().account_id(), account_id_1); - assert_eq!(output.as_account().unlock_conditions().len(), 2); + assert_eq!(output.as_account().unlock_conditions().len(), 1); assert_eq!(output.as_account().features().len(), 0); assert_eq!(output.as_account().immutable_features().len(), 0); assert_eq!( @@ -767,7 +767,7 @@ fn burn_foundries_present() { assert_eq!(output.amount(), 1_000_000); assert_eq!(output.as_account().native_tokens().len(), 0); assert_eq!(*output.as_account().account_id(), account_id_1); - assert_eq!(output.as_account().unlock_conditions().len(), 2); + assert_eq!(output.as_account().unlock_conditions().len(), 1); assert_eq!(output.as_account().features().len(), 0); assert_eq!(output.as_account().immutable_features().len(), 0); assert_eq!( diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/input_selection/foundry_outputs.rs index a8f0587e8e..c24614ee42 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/input_selection/foundry_outputs.rs @@ -303,46 +303,6 @@ fn destroy_foundry_with_account_state_transition() { assert_eq!(selected.outputs.len(), 1); } -#[test] -fn destroy_foundry_with_account_governance_transition() { - let protocol_parameters = protocol_parameters(); - let account_id_2 = AccountId::from_str(ACCOUNT_ID_2).unwrap(); - - let inputs = build_inputs([ - Account( - 1_000_000, - account_id_2, - BECH32_ADDRESS_ED25519_0, - None, - None, - None, - None, - ), - Foundry( - 1_000_000, - account_id_2, - 1, - SimpleTokenScheme::new(10, 10, 10).unwrap(), - None, - ), - ]); - let outputs = [inputs[0].output.clone()]; - - let selected = InputSelection::new( - inputs.clone(), - outputs, - addresses([BECH32_ADDRESS_ED25519_0]), - protocol_parameters, - ) - .with_burn(Burn::new().add_foundry(inputs[1].output.as_foundry().id())) - .select(); - - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Account(account_id))) if account_id == account_id_2 - )); -} - #[test] fn destroy_foundry_with_account_burn() { let protocol_parameters = protocol_parameters(); @@ -379,7 +339,7 @@ fn destroy_foundry_with_account_burn() { let selected = InputSelection::new( inputs.clone(), - outputs, + outputs.clone(), addresses([BECH32_ADDRESS_ED25519_0]), protocol_parameters, ) @@ -388,12 +348,22 @@ fn destroy_foundry_with_account_burn() { .add_foundry(inputs[1].output.as_foundry().id()) .add_account(account_id_2), ) - .select(); + .select() + .unwrap(); - assert!(matches!( - selected, - Err(Error::UnfulfillableRequirement(Requirement::Account(account_id))) if account_id == account_id_2 - )); + assert!(unsorted_eq(&selected.inputs, &inputs)); + assert_eq!(selected.outputs.len(), 2); + assert!(selected.outputs.contains(&outputs[0])); + selected.outputs.iter().for_each(|output| { + if !outputs.contains(output) { + assert!(is_remainder_or_return( + output, + 1_000_000, + BECH32_ADDRESS_ED25519_0, + None, + )); + } + }); } #[test] @@ -501,7 +471,7 @@ fn simple_foundry_transition_basic_not_needed() { assert_eq!(output.amount(), 2_000_000); assert_eq!(output.as_account().native_tokens().len(), 0); assert_eq!(*output.as_account().account_id(), account_id_1); - assert_eq!(output.as_account().unlock_conditions().len(), 2); + assert_eq!(output.as_account().unlock_conditions().len(), 1); assert_eq!(output.as_account().features().len(), 0); assert_eq!(output.as_account().immutable_features().len(), 0); assert_eq!( @@ -567,7 +537,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { assert_eq!(output.amount(), 2_000_000); assert_eq!(output.as_account().native_tokens().len(), 0); assert_eq!(*output.as_account().account_id(), account_id_1); - assert_eq!(output.as_account().unlock_conditions().len(), 2); + assert_eq!(output.as_account().unlock_conditions().len(), 1); assert_eq!(output.as_account().features().len(), 0); assert_eq!(output.as_account().immutable_features().len(), 0); assert_eq!( @@ -628,7 +598,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { // // assert_eq!(output.amount(), 2_000_000); // // assert_eq!(output.as_account().native_tokens().len(), 0); // // assert_eq!(*output.as_account().account_id(), account_id_1); -// // assert_eq!(output.as_account().unlock_conditions().len(), 2); +// // assert_eq!(output.as_account().unlock_conditions().len(), 1); // // assert_eq!(output.as_account().features().len(), 0); // // assert_eq!(output.as_account().immutable_features().len(), 0); // // assert_eq!( diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 90fccd41c3..427f86e7cb 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -112,84 +112,6 @@ async fn sign_account_state_transition() -> Result<()> { Ok(()) } -#[tokio::test] -async fn sign_account_governance_transition() -> Result<()> { - let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic()?)?; - - let bech32_address = &secret_manager - .generate_ed25519_addresses( - GetAddressesOptions::default() - .with_coin_type(SHIMMER_COIN_TYPE) - .with_range(0..1), - ) - .await?[0] - .to_bech32(SHIMMER_TESTNET_BECH32_HRP); - - let protocol_parameters = protocol_parameters(); - let account_id = AccountId::from_str(ACCOUNT_ID_1)?; - - let inputs = build_inputs([Account( - 1_000_000, - account_id, - &bech32_address.to_string(), - None, - None, - None, - Some(Bip44::new(SHIMMER_COIN_TYPE).with_address_index(1)), - )]); - - let outputs = build_outputs([Account( - 1_000_000, - account_id, - &bech32_address.to_string(), - None, - None, - None, - None, - )]); - - let essence = TransactionEssence::Regular( - RegularTransactionEssence::builder( - protocol_parameters.network_id(), - InputsCommitment::new(inputs.iter().map(|i| &i.output)), - ) - .with_inputs( - inputs - .iter() - .map(|i| Input::Utxo(UtxoInput::from(*i.output_metadata.output_id()))) - .collect::>(), - ) - .with_outputs(outputs) - .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?, - ); - - let prepared_transaction_data = PreparedTransactionData { - essence, - inputs_data: inputs, - remainder: None, - }; - - let unlocks = secret_manager - .sign_transaction_essence(&prepared_transaction_data) - .await?; - - assert_eq!(unlocks.len(), 1); - assert_eq!((*unlocks).get(0).unwrap().kind(), SignatureUnlock::KIND); - - let tx_payload = TransactionPayload::new(prepared_transaction_data.essence.as_regular().clone(), unlocks)?; - - validate_transaction_payload_length(&tx_payload)?; - - let conflict = verify_semantic(&prepared_transaction_data.inputs_data, &tx_payload)?; - - if let Some(conflict) = conflict { - panic!("{conflict:?}, with {tx_payload:#?}"); - } - - Ok(()) -} - #[tokio::test] async fn account_reference_unlocks() -> Result<()> { let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic()?)?;