Skip to content

Commit

Permalink
Use from_str
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Dec 6, 2023
1 parent 47f45c6 commit 66302ed
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions sdk/tests/types/transaction_regular_essence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use core::str::FromStr;

use iota_sdk::types::block::{
address::{Address, AliasAddress, Ed25519Address},
input::{Input, TreasuryInput, UtxoInput},
Expand Down Expand Up @@ -43,8 +45,7 @@ fn build_valid() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -67,8 +68,7 @@ fn build_valid_with_payload() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -92,8 +92,7 @@ fn build_valid_add_inputs_outputs() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -116,8 +115,7 @@ fn build_invalid_payload_kind() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -138,8 +136,7 @@ fn build_invalid_payload_kind() {
#[test]
fn build_invalid_input_count_low() {
let protocol_parameters = protocol_parameters();
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -163,8 +160,7 @@ fn build_invalid_input_count_high() {
let protocol_parameters = protocol_parameters();
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand Down Expand Up @@ -205,8 +201,7 @@ fn build_invalid_output_count_high() {
let protocol_parameters = protocol_parameters();
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -231,8 +226,7 @@ fn build_invalid_duplicate_utxo() {
let protocol_parameters = protocol_parameters();
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -253,8 +247,7 @@ fn build_invalid_duplicate_utxo() {
fn build_invalid_input_kind() {
let protocol_parameters = protocol_parameters();
let input = Input::Treasury(TreasuryInput::new(MilestoneId::new(rand_bytes_array())));
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let output = Output::Basic(
BasicOutput::build_with_amount(amount)
Expand Down Expand Up @@ -327,8 +320,7 @@ fn getters() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let outputs = [Output::Basic(
BasicOutput::build_with_amount(amount)
Expand All @@ -355,14 +347,13 @@ fn duplicate_output_nft() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let basic = BasicOutput::build_with_amount(amount)
.add_unlock_condition(AddressUnlockCondition::new(address))
.finish_output(protocol_parameters.token_supply())
.unwrap();
let nft_id = NftId::from(bytes);
let nft_id = NftId::from_str(ED25519_ADDRESS_1).unwrap();
let nft = NftOutput::build_with_amount(1_000_000, nft_id)
.add_unlock_condition(AddressUnlockCondition::new(address))
.finish_output(protocol_parameters.token_supply())
Expand All @@ -385,8 +376,7 @@ fn duplicate_output_nft_null() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let basic = BasicOutput::build_with_amount(amount)
.add_unlock_condition(AddressUnlockCondition::new(address))
Expand All @@ -412,14 +402,13 @@ fn duplicate_output_alias() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let basic = BasicOutput::build_with_amount(amount)
.add_unlock_condition(AddressUnlockCondition::new(address))
.finish_output(protocol_parameters.token_supply())
.unwrap();
let alias_id = AliasId::from(bytes);
let alias_id = AliasId::from_str(ED25519_ADDRESS_1).unwrap();
let alias = AliasOutput::build_with_amount(1_000_000, alias_id)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(address))
.add_unlock_condition(GovernorAddressUnlockCondition::new(address))
Expand All @@ -443,14 +432,13 @@ fn duplicate_output_foundry() {
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input1 = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let input2 = Input::Utxo(UtxoInput::new(transaction_id, 1).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let basic = BasicOutput::build_with_amount(amount)
.add_unlock_condition(AddressUnlockCondition::new(address))
.finish_output(protocol_parameters.token_supply())
.unwrap();
let alias_id = AliasId::from(bytes);
let alias_id = AliasId::from_str(ED25519_ADDRESS_1).unwrap();
let token_scheme = TokenScheme::Simple(SimpleTokenScheme::new(70, 0, 100).unwrap());
let foundry_id = FoundryId::build(&AliasAddress::from(alias_id), 1, token_scheme.kind());
let token_id = TokenId::from(foundry_id);
Expand All @@ -476,10 +464,9 @@ fn more_than_64_same_native_tokens() {
let protocol_parameters = protocol_parameters();
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;
let alias_id = AliasId::from(bytes);
let alias_id = AliasId::from_str(ED25519_ADDRESS_1).unwrap();
let token_scheme = TokenScheme::Simple(SimpleTokenScheme::new(70, 0, 100).unwrap());
let foundry_id = FoundryId::build(&AliasAddress::from(alias_id), 1, token_scheme.kind());
let token_id = TokenId::from(foundry_id);
Expand All @@ -502,8 +489,7 @@ fn more_than_64_distinctive_native_tokens() {
let protocol_parameters = protocol_parameters();
let transaction_id = TransactionId::new(prefix_hex::decode(TRANSACTION_ID).unwrap());
let input = Input::Utxo(UtxoInput::new(transaction_id, 0).unwrap());
let bytes: [u8; 32] = prefix_hex::decode(ED25519_ADDRESS_1).unwrap();
let address = Address::from(Ed25519Address::new(bytes));
let address = Address::from(Ed25519Address::from_str(ED25519_ADDRESS_1).unwrap());
let amount = 1_000_000;

let mut outputs = Vec::new();
Expand Down

0 comments on commit 66302ed

Please sign in to comment.