From 60efd78b2877de41afe46998833f5e09999c2918 Mon Sep 17 00:00:00 2001 From: DaughterOfMars Date: Thu, 5 Oct 2023 05:16:20 -0400 Subject: [PATCH 1/2] Refactor block signature (#995) * Add parents to block * Add burned mana to rust block (#926) * merge imports * Split block into basic and validation types * udep * Comment out more tests that will change * oop * no_std * impl more of BlockWrapper * fix client block builder * Update sdk/src/types/block/protocol.rs Co-authored-by: Thibault Martinez * PR suggestion * no_std * Update sdk/src/types/block/validation.rs Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> * invalid block kind * Refactor types so that `Block` is the highest level enum * small improvements * Pr suggestions * Allow warnings and stub in missing values * clippy * properly pack kind and disable clippy CI for now * Implement new block ID * Rework BlockId into struct * serde with string * align dto to spec * PR suggestions * PR suggs * remove pub(crate) protocol params fields * cleanup * comments * fix tests * Use Signature for serialized layouts * more signature fixes * Refactor block signature * Fix block id computation, fix return type, reexport BlockHash, clippy (#998) * no_std * fix block ID slot index on big endian systems and clippy * fix with_slot_index too * PR suggestion * oof Co-authored-by: Abdulrahim Al Methiab <31316147+abdulmth@users.noreply.github.com> * add memory layout test * no_std * Merge branch 2.0 * Add ext trait to help block builder signing * Update sdk/src/types/block/core.rs * Fix merge breakage and clippy * fix nostd * fix tests * remove generics * Nits * simplify name * rename trait * use header more * move it move it * PR suggestions * no_std * Nit --------- Co-authored-by: Thibault Martinez Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Co-authored-by: Abdulrahim Al Methiab <31316147+abdulmth@users.noreply.github.com> --- bindings/core/src/method_handler/client.rs | 7 +- .../client/block/00_block_no_payload.rs | 10 +- .../block/01_block_confirmation_time.rs | 10 +- .../client/block/02_block_custom_parents.rs | 10 +- .../client/block/03_block_custom_payload.rs | 10 +- .../client/block/04_block_tagged_data.rs | 10 +- .../client/node_api_core/04_post_block.rs | 10 +- .../client/node_api_core/05_post_block_raw.rs | 10 +- sdk/src/client/api/block_builder/mod.rs | 48 +++++---- sdk/src/client/secret/mod.rs | 28 ++++++ sdk/src/types/block/core/basic.rs | 12 +++ sdk/src/types/block/core/mod.rs | 26 ++++- sdk/src/types/block/core/validation.rs | 12 +++ sdk/src/types/block/core/wrapper.rs | 98 ++++++++++++++----- sdk/src/types/block/rand/block.rs | 69 +++++++++---- sdk/src/types/block/rand/signature.rs | 6 +- sdk/src/wallet/account/operations/balance.rs | 1 + .../account/operations/output_claiming.rs | 1 + .../operations/output_consolidation.rs | 1 + .../account/operations/output_finder.rs | 1 + .../operations/participation/voting.rs | 1 + .../operations/participation/voting_power.rs | 1 + sdk/src/wallet/account/operations/reissue.rs | 13 ++- .../wallet/account/operations/syncing/mod.rs | 1 + .../operations/syncing/transactions.rs | 1 + .../burning_melting/melt_native_token.rs | 1 + .../transaction/high_level/create_account.rs | 1 + .../high_level/minting/create_native_token.rs | 1 + .../high_level/minting/mint_native_token.rs | 1 + .../high_level/minting/mint_nfts.rs | 1 + .../operations/transaction/high_level/send.rs | 1 + .../high_level/send_native_tokens.rs | 1 + .../transaction/high_level/send_nft.rs | 1 + .../account/operations/transaction/mod.rs | 1 + .../operations/transaction/prepare_output.rs | 1 + .../transaction/prepare_transaction.rs | 1 + .../transaction/sign_transaction.rs | 1 + .../transaction/submit_transaction.rs | 8 +- sdk/src/wallet/core/mod.rs | 6 ++ .../core/operations/account_recovery.rs | 1 + .../core/operations/address_generation.rs | 1 + .../core/operations/background_syncing.rs | 1 + sdk/tests/client/node_api/core.rs | 12 ++- sdk/tests/client/node_api/mod.rs | 22 +++-- sdk/tests/types/block.rs | 20 ++-- 45 files changed, 359 insertions(+), 121 deletions(-) diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index bfae35f84b..5c1845d46d 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -4,7 +4,7 @@ #[cfg(feature = "mqtt")] use iota_sdk::client::mqtt::{MqttPayload, Topic}; use iota_sdk::{ - client::{request_funds_from_faucet, Client}, + client::{request_funds_from_faucet, secret::SecretManager, Client}, types::{ api::core::response::OutputWithMetadataResponse, block::{ @@ -173,15 +173,16 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM ClientMethod::GetProtocolParameters => Response::ProtocolParameters(client.get_protocol_parameters().await?), ClientMethod::PostBlockPayload { payload } => { let block = client - .finish_basic_block_builder( + .build_basic_block::( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::try_from_dto_with_params( payload, &client.get_protocol_parameters().await?, )?), + todo!("secret manager"), + todo!("chain"), ) .await?; diff --git a/sdk/examples/client/block/00_block_no_payload.rs b/sdk/examples/client/block/00_block_no_payload.rs index 015634be92..ce029516bc 100644 --- a/sdk/examples/client/block/00_block_no_payload.rs +++ b/sdk/examples/client/block/00_block_no_payload.rs @@ -8,7 +8,8 @@ //! cargo run --release --example block_no_payload //! ``` -use iota_sdk::client::{Client, Result}; +use crypto::keys::bip44::Bip44; +use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}; #[tokio::main] async fn main() -> Result<()> { @@ -20,14 +21,17 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Create and send the block. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, None, + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; diff --git a/sdk/examples/client/block/01_block_confirmation_time.rs b/sdk/examples/client/block/01_block_confirmation_time.rs index 267562f40f..6b6b961dc8 100644 --- a/sdk/examples/client/block/01_block_confirmation_time.rs +++ b/sdk/examples/client/block/01_block_confirmation_time.rs @@ -8,8 +8,9 @@ //! cargo run --release --example block_confirmation_time //! ``` +use crypto::keys::bip44::Bip44; use iota_sdk::{ - client::{Client, Result}, + client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}, types::api::core::response::BlockState, }; @@ -23,14 +24,17 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Create and send a block. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, None, + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; let block_id = client.block_id(&block).await?; diff --git a/sdk/examples/client/block/02_block_custom_parents.rs b/sdk/examples/client/block/02_block_custom_parents.rs index 823da8d391..2a01e8f95b 100644 --- a/sdk/examples/client/block/02_block_custom_parents.rs +++ b/sdk/examples/client/block/02_block_custom_parents.rs @@ -8,7 +8,8 @@ //! cargo run --release --example block_custom_parents //! ``` -use iota_sdk::client::{Client, Result}; +use crypto::keys::bip44::Bip44; +use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}; #[tokio::main] async fn main() -> Result<()> { @@ -20,18 +21,21 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Use issuance as custom parents. let issuance = client.get_issuance().await?; println!("Issuance:\n{issuance:#?}"); // Create and send the block with custom parents. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), Some(issuance.strong_parents()?), None, + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; diff --git a/sdk/examples/client/block/03_block_custom_payload.rs b/sdk/examples/client/block/03_block_custom_payload.rs index 90a621723a..b27c5a289c 100644 --- a/sdk/examples/client/block/03_block_custom_payload.rs +++ b/sdk/examples/client/block/03_block_custom_payload.rs @@ -8,8 +8,9 @@ //! cargo run --release --example block_custom_payload //! ``` +use crypto::keys::bip44::Bip44; use iota_sdk::{ - client::{Client, Result}, + client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}, types::block::payload::{Payload, TaggedDataPayload}, }; @@ -23,17 +24,20 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Create a custom payload. let tagged_data_payload = TaggedDataPayload::new(*b"Your tag", *b"Your data")?; // Create and send the block with the custom payload. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::from(tagged_data_payload)), + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; diff --git a/sdk/examples/client/block/04_block_tagged_data.rs b/sdk/examples/client/block/04_block_tagged_data.rs index 16fee70d0f..2fc25aa84f 100644 --- a/sdk/examples/client/block/04_block_tagged_data.rs +++ b/sdk/examples/client/block/04_block_tagged_data.rs @@ -8,8 +8,9 @@ //! cargo run --release --example block_tagged_data [TAG] [DATA] //! ``` +use crypto::keys::bip44::Bip44; use iota_sdk::{ - client::{Client, Result}, + client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}, types::block::payload::{Payload, TaggedDataPayload}, }; @@ -23,11 +24,12 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Create and send the block with tag and data. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::TaggedData(Box::new( @@ -43,6 +45,8 @@ async fn main() -> Result<()> { ) .unwrap(), ))), + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; diff --git a/sdk/examples/client/node_api_core/04_post_block.rs b/sdk/examples/client/node_api_core/04_post_block.rs index 17b277fe9f..414e3ca7cf 100644 --- a/sdk/examples/client/node_api_core/04_post_block.rs +++ b/sdk/examples/client/node_api_core/04_post_block.rs @@ -8,7 +8,8 @@ //! cargo run --release --example node_api_core_post_block [NODE URL] //! ``` -use iota_sdk::client::{Client, Result}; +use crypto::keys::bip44::Bip44; +use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}; #[tokio::main] async fn main() -> Result<()> { @@ -23,14 +24,17 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Create the block. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, None, + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; // Post the block. diff --git a/sdk/examples/client/node_api_core/05_post_block_raw.rs b/sdk/examples/client/node_api_core/05_post_block_raw.rs index c93f8129c8..a20a0ad257 100644 --- a/sdk/examples/client/node_api_core/05_post_block_raw.rs +++ b/sdk/examples/client/node_api_core/05_post_block_raw.rs @@ -8,7 +8,8 @@ //! cargo run --release --example node_api_core_post_block_raw [NODE URL] //! ``` -use iota_sdk::client::{Client, Result}; +use crypto::keys::bip44::Bip44; +use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result}; #[tokio::main] async fn main() -> Result<()> { @@ -23,14 +24,17 @@ async fn main() -> Result<()> { // Create a node client. let client = Client::builder().with_node(&node_url)?.finish().await?; + let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; + // Create the block. let block = client - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, None, + &secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await?; // Post the block as raw bytes. diff --git a/sdk/src/client/api/block_builder/mod.rs b/sdk/src/client/api/block_builder/mod.rs index a1d38def3f..80b5b78280 100644 --- a/sdk/src/client/api/block_builder/mod.rs +++ b/sdk/src/client/api/block_builder/mod.rs @@ -4,26 +4,34 @@ pub mod input_selection; pub mod transaction; +use crypto::keys::bip44::Bip44; + pub use self::transaction::verify_semantic; use crate::{ - client::{ClientInner, Result}, + client::{ + secret::{SecretManage, SignBlock}, + ClientInner, Result, + }, types::block::{ - core::{basic, Block, BlockWrapper}, + core::{basic, BlockHeader, BlockWrapper}, payload::Payload, - signature::Ed25519Signature, - IssuerId, + Block, IssuerId, }, }; impl ClientInner { - pub async fn finish_basic_block_builder( + pub async fn build_basic_block( &self, issuer_id: IssuerId, - signature: Ed25519Signature, issuing_time: Option, strong_parents: Option, payload: Option, - ) -> Result { + secret_manager: &S, + chain: Bip44, + ) -> Result + where + crate::client::Error: From, + { let issuance = self.get_issuance().await?; let strong_parents = strong_parents.unwrap_or(issuance.strong_parents()?); @@ -40,22 +48,24 @@ impl ClientInner { issuing_time }); - let protocol_parameters = self.get_protocol_parameters().await?; + let protocol_params = self.get_protocol_parameters().await?; - Ok(BlockWrapper::new( - protocol_parameters.version(), - protocol_parameters.network_id(), - issuing_time, - issuance.commitment.id(), - issuance.latest_finalized_slot, - issuer_id, - // TODO correct value for max_burned_mana - Block::build_basic(strong_parents, 0) + Ok(BlockWrapper::build( + BlockHeader::new( + protocol_params.version(), + protocol_params.network_id(), + issuing_time, + issuance.commitment.id(), + issuance.latest_finalized_slot, + issuer_id, + ), + Block::build_basic(strong_parents, 0) // TODO: burned mana calculation .with_weak_parents(issuance.weak_parents()?) .with_shallow_like_parents(issuance.shallow_like_parents()?) .with_payload(payload) .finish_block()?, - signature, - )) + ) + .sign_ed25519(secret_manager, chain) + .await?) } } diff --git a/sdk/src/client/secret/mod.rs b/sdk/src/client/secret/mod.rs index 67c58865e8..1815419905 100644 --- a/sdk/src/client/secret/mod.rs +++ b/sdk/src/client/secret/mod.rs @@ -53,10 +53,12 @@ use crate::{ }, types::block::{ address::{Address, Ed25519Address}, + core::BlockWrapperBuilder, output::Output, payload::{transaction::TransactionEssence, TransactionPayload}, signature::{Ed25519Signature, Signature}, unlock::{AccountUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, Unlocks}, + BlockWrapper, }, }; @@ -602,3 +604,29 @@ where Ok(tx_payload) } + +#[async_trait] +pub trait SignBlock { + async fn sign_ed25519( + self, + secret_manager: &S, + chain: Bip44, + ) -> crate::client::Result + where + crate::client::Error: From; +} + +#[async_trait] +impl SignBlock for BlockWrapperBuilder { + async fn sign_ed25519( + self, + secret_manager: &S, + chain: Bip44, + ) -> crate::client::Result + where + crate::client::Error: From, + { + let msg = self.signing_input(); + Ok(self.finish(secret_manager.sign_ed25519(&msg, chain).await?)?) + } +} diff --git a/sdk/src/types/block/core/basic.rs b/sdk/src/types/block/core/basic.rs index 7c19d46f28..5535c70075 100644 --- a/sdk/src/types/block/core/basic.rs +++ b/sdk/src/types/block/core/basic.rs @@ -95,6 +95,18 @@ impl BasicBlockBuilder { } } +impl From for BasicBlockBuilder { + fn from(value: BasicBlock) -> Self { + Self { + strong_parents: value.strong_parents, + weak_parents: value.weak_parents, + shallow_like_parents: value.shallow_like_parents, + payload: value.payload, + max_burned_mana: value.max_burned_mana, + } + } +} + #[derive(Clone, Debug, Eq, PartialEq)] pub struct BasicBlock { /// Blocks that are strongly directly approved. diff --git a/sdk/src/types/block/core/mod.rs b/sdk/src/types/block/core/mod.rs index 416f644b66..bd3c3fcd38 100644 --- a/sdk/src/types/block/core/mod.rs +++ b/sdk/src/types/block/core/mod.rs @@ -21,7 +21,7 @@ pub use self::{ basic::{BasicBlock, BasicBlockBuilder}, parent::Parents, validation::{ValidationBlock, ValidationBlockBuilder}, - wrapper::{BlockHeader, BlockWrapper}, + wrapper::{BlockHeader, BlockWrapper, BlockWrapperBuilder}, }; use crate::types::block::{ protocol::{ProtocolParameters, ProtocolParametersHash}, @@ -46,6 +46,30 @@ impl From for Block { } } +impl TryFrom for BasicBlockBuilder { + type Error = Error; + + fn try_from(value: Block) -> Result { + if let Block::Basic(block) = value { + Ok((*block).into()) + } else { + Err(Error::InvalidBlockKind(value.kind())) + } + } +} + +impl TryFrom for ValidationBlockBuilder { + type Error = Error; + + fn try_from(value: Block) -> Result { + if let Block::Validation(block) = value { + Ok((*block).into()) + } else { + Err(Error::InvalidBlockKind(value.kind())) + } + } +} + impl Block { /// Return the block kind of a [`Block`]. pub fn kind(&self) -> u8 { diff --git a/sdk/src/types/block/core/validation.rs b/sdk/src/types/block/core/validation.rs index 4e37a68bab..f93970c41b 100644 --- a/sdk/src/types/block/core/validation.rs +++ b/sdk/src/types/block/core/validation.rs @@ -98,6 +98,18 @@ impl ValidationBlockBuilder { } } +impl From for ValidationBlockBuilder { + fn from(value: ValidationBlock) -> Self { + Self { + strong_parents: value.strong_parents, + weak_parents: value.weak_parents, + shallow_like_parents: value.shallow_like_parents, + highest_supported_version: value.highest_supported_version, + protocol_parameters_hash: value.protocol_parameters_hash, + } + } +} + /// A Validation Block is a special type of block used by validators to secure the network. It is recognized by the /// Congestion Control of the IOTA 2.0 protocol and can be issued without burning Mana within the constraints of the /// allowed validator throughput. It is allowed to reference more parent blocks than a normal Basic Block. diff --git a/sdk/src/types/block/core/wrapper.rs b/sdk/src/types/block/core/wrapper.rs index ecf61b5f38..d66cf14d71 100644 --- a/sdk/src/types/block/core/wrapper.rs +++ b/sdk/src/types/block/core/wrapper.rs @@ -1,6 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use alloc::vec::Vec; use core::mem::size_of; use crypto::hashes::{blake2b::Blake2b256, Digest}; @@ -21,6 +22,45 @@ use crate::types::block::{ Block, Error, IssuerId, }; +/// Builder for a [`BlockWrapper`]. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct BlockWrapperBuilder { + /// The block header. + pub(crate) header: BlockHeader, + /// The inner block. + pub(crate) block: Block, +} + +impl BlockWrapperBuilder { + pub fn new(header: BlockHeader, block: Block) -> Self { + Self { header, block } + } + + /// Updates the block header. + #[inline(always)] + pub fn with_block_header(mut self, header: BlockHeader) -> Self { + self.header = header; + self + } + + /// Updates the block. + #[inline(always)] + pub fn with_block(mut self, block: Block) -> Self { + self.block = block; + self + } + + /// Get the signing input that can be used to generate a [`Signature`](crate::types::block::signature::Signature) + /// for the resulting block. + pub fn signing_input(&self) -> Vec { + [self.header.hash(), self.block.hash()].concat() + } + + pub fn finish(self, signature: impl Into) -> Result { + Ok(BlockWrapper::new(self.header, self.block, signature)) + } +} + #[derive(Clone, Debug, Eq, PartialEq, CopyGetters)] #[getset(get_copy = "pub")] pub struct BlockHeader { @@ -43,6 +83,24 @@ impl BlockHeader { pub const LENGTH: usize = size_of::() + 2 * size_of::() + SlotCommitmentId::LENGTH + size_of::() + IssuerId::LENGTH; + pub fn new( + protocol_version: u8, + network_id: u64, + issuing_time: u64, + slot_commitment_id: SlotCommitmentId, + latest_finalized_slot: SlotIndex, + issuer_id: IssuerId, + ) -> Self { + Self { + protocol_version, + network_id, + issuing_time, + slot_commitment_id, + latest_finalized_slot, + issuer_id, + } + } + pub(crate) fn hash(&self) -> [u8; 32] { let mut bytes = [0u8; Self::LENGTH]; @@ -128,25 +186,7 @@ impl BlockWrapper { /// Creates a new [`BlockWrapper`]. #[inline(always)] - pub fn new( - protocol_version: u8, - network_id: u64, - issuing_time: u64, - slot_commitment_id: SlotCommitmentId, - latest_finalized_slot: SlotIndex, - issuer_id: IssuerId, - block: impl Into, - signature: impl Into, - ) -> Self { - let header = BlockHeader { - protocol_version, - network_id, - issuing_time, - slot_commitment_id, - latest_finalized_slot, - issuer_id, - }; - let block = block.into(); + pub fn new(header: BlockHeader, block: Block, signature: impl Into) -> Self { let signature = signature.into(); Self { @@ -156,6 +196,12 @@ impl BlockWrapper { } } + /// Creates a new [`BlockWrapperBuilder`]. + #[inline(always)] + pub fn build(header: BlockHeader, block: Block) -> BlockWrapperBuilder { + BlockWrapperBuilder::new(header, block) + } + /// Returns the protocol version of a [`BlockWrapper`]. #[inline(always)] pub fn protocol_version(&self) -> u8 { @@ -353,12 +399,14 @@ pub(crate) mod dto { } Ok(Self::new( - dto.protocol_version, - dto.network_id, - dto.issuing_time, - dto.slot_commitment_id, - dto.latest_finalized_slot, - dto.issuer_id, + BlockHeader::new( + dto.protocol_version, + dto.network_id, + dto.issuing_time, + dto.slot_commitment_id, + dto.latest_finalized_slot, + dto.issuer_id, + ), Block::try_from_dto_with_params_inner(dto.block, params)?, dto.signature, )) diff --git a/sdk/src/types/block/rand/block.rs b/sdk/src/types/block/rand/block.rs index c1de20b13d..cedfa623ce 100644 --- a/sdk/src/types/block/rand/block.rs +++ b/sdk/src/types/block/rand/block.rs @@ -4,7 +4,10 @@ use alloc::vec::Vec; use crate::types::block::{ - core::{basic, BasicBlockBuilder, Block, BlockWrapper}, + core::{ + basic::{self, BasicBlockBuilder}, + BlockHeader, BlockWrapper, BlockWrapperBuilder, + }, protocol::ProtocolParameters, rand::{ bytes::rand_bytes_array, @@ -12,10 +15,10 @@ use crate::types::block::{ number::rand_number, parents::rand_strong_parents, payload::rand_payload_for_block, - signature::rand_signature, + signature::rand_sign_ed25519, slot::{rand_slot_commitment_id, rand_slot_index}, }, - BlockId, + Block, BlockId, }; /// Generates a random block id. @@ -31,30 +34,54 @@ pub fn rand_block_ids(len: usize) -> Vec { } /// Generates a random basic block with given strong parents. +pub fn rand_basic_block_with_strong_parents(strong_parents: basic::StrongParents) -> Block { + rand_basic_block_builder_with_strong_parents(strong_parents) + .with_payload(rand_payload_for_block()) + .finish_block() + .unwrap() +} + +/// Generates a random basic block builder with given strong parents. pub fn rand_basic_block_builder_with_strong_parents(strong_parents: basic::StrongParents) -> BasicBlockBuilder { - Block::build_basic(strong_parents, rand_number()).with_payload(rand_payload_for_block()) + Block::build_basic(strong_parents, rand_number()) } -/// Generates a random block wrapper. -pub fn rand_block_wrapper_with_block(protocol_params: &ProtocolParameters, block: impl Into) -> BlockWrapper { - BlockWrapper::new( - protocol_params.version(), - protocol_params.network_id(), - rand_number(), - rand_slot_commitment_id(), - rand_slot_index(), - rand_issuer_id(), +/// Generates a random block wrapper with given block. +pub fn rand_block_wrapper_with_block(protocol_params: ProtocolParameters, block: Block) -> BlockWrapper { + BlockWrapper::build( + BlockHeader::new( + protocol_params.version(), + protocol_params.network_id(), + rand_number(), + rand_slot_commitment_id(), + rand_slot_index(), + rand_issuer_id(), + ), block, - rand_signature(), ) + .sign_random() +} + +/// Generates a random block wrapper with given strong parents. +pub fn rand_block_wrapper_with_strong_parents( + protocol_params: ProtocolParameters, + strong_parents: basic::StrongParents, +) -> BlockWrapper { + rand_block_wrapper_with_block(protocol_params, rand_basic_block_with_strong_parents(strong_parents)) } /// Generates a random block wrapper. -pub fn rand_block_wrapper(protocol_params: &ProtocolParameters) -> BlockWrapper { - rand_block_wrapper_with_block( - protocol_params, - rand_basic_block_builder_with_strong_parents(rand_strong_parents()) - .finish_block() - .unwrap(), - ) +pub fn rand_block_wrapper(protocol_params: ProtocolParameters) -> BlockWrapper { + rand_block_wrapper_with_strong_parents(protocol_params, rand_strong_parents()) +} + +pub trait SignBlockRandom { + fn sign_random(self) -> BlockWrapper; +} + +impl SignBlockRandom for BlockWrapperBuilder { + fn sign_random(self) -> BlockWrapper { + let signing_input = self.signing_input(); + self.finish(rand_sign_ed25519(&signing_input)).unwrap() + } } diff --git a/sdk/src/types/block/rand/signature.rs b/sdk/src/types/block/rand/signature.rs index 7ffd5d5508..d9a7680ce3 100644 --- a/sdk/src/types/block/rand/signature.rs +++ b/sdk/src/types/block/rand/signature.rs @@ -13,6 +13,10 @@ use super::bytes::{rand_bytes, rand_bytes_array}; use crate::types::block::signature::{Ed25519Signature, Signature}; pub fn rand_ed25519_signature() -> Ed25519Signature { + rand_sign_ed25519(&rand_bytes(64)) +} + +pub fn rand_sign_ed25519(msg: &[u8]) -> Ed25519Signature { let mnemonic = wordlist::encode(&rand_bytes_array::<32>(), &wordlist::ENGLISH).unwrap(); let seed = Seed::from(mnemonic_to_seed(&mnemonic, &Passphrase::default())); let chain = [0; 5]; @@ -20,7 +24,7 @@ pub fn rand_ed25519_signature() -> Ed25519Signature { .derive::(chain.into_iter().map(Segment::harden)) .secret_key(); let public_key = private_key.public_key(); - let signature = private_key.sign(&rand_bytes(64)); + let signature = private_key.sign(msg); Ed25519Signature::new(public_key, signature) } diff --git a/sdk/src/wallet/account/operations/balance.rs b/sdk/src/wallet/account/operations/balance.rs index 0a6d8fb026..2d71126820 100644 --- a/sdk/src/wallet/account/operations/balance.rs +++ b/sdk/src/wallet/account/operations/balance.rs @@ -23,6 +23,7 @@ use crate::{ impl Account where Error: From, + crate::client::Error: From, { /// Get the balance of the account. pub async fn balance(&self) -> Result { diff --git a/sdk/src/wallet/account/operations/output_claiming.rs b/sdk/src/wallet/account/operations/output_claiming.rs index 66192f018a..000b26513f 100644 --- a/sdk/src/wallet/account/operations/output_claiming.rs +++ b/sdk/src/wallet/account/operations/output_claiming.rs @@ -36,6 +36,7 @@ pub enum OutputsToClaim { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Get basic and nft outputs that have /// [`ExpirationUnlockCondition`](crate::types::block::output::unlock_condition::ExpirationUnlockCondition), diff --git a/sdk/src/wallet/account/operations/output_consolidation.rs b/sdk/src/wallet/account/operations/output_consolidation.rs index d27feae1ce..acf4577198 100644 --- a/sdk/src/wallet/account/operations/output_consolidation.rs +++ b/sdk/src/wallet/account/operations/output_consolidation.rs @@ -73,6 +73,7 @@ impl ConsolidationParams { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { fn should_consolidate_output( &self, diff --git a/sdk/src/wallet/account/operations/output_finder.rs b/sdk/src/wallet/account/operations/output_finder.rs index eab49bdb0d..e15c6cf683 100644 --- a/sdk/src/wallet/account/operations/output_finder.rs +++ b/sdk/src/wallet/account/operations/output_finder.rs @@ -11,6 +11,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Search addresses with unspent outputs /// `address_gap_limit`: The number of addresses to search for, after the last address with unspent outputs diff --git a/sdk/src/wallet/account/operations/participation/voting.rs b/sdk/src/wallet/account/operations/participation/voting.rs index 26b1c541dd..dda76cbf49 100644 --- a/sdk/src/wallet/account/operations/participation/voting.rs +++ b/sdk/src/wallet/account/operations/participation/voting.rs @@ -22,6 +22,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Casts a given number of votes for a given (voting) event. /// diff --git a/sdk/src/wallet/account/operations/participation/voting_power.rs b/sdk/src/wallet/account/operations/participation/voting_power.rs index 7abe682f60..bc14c01f80 100644 --- a/sdk/src/wallet/account/operations/participation/voting_power.rs +++ b/sdk/src/wallet/account/operations/participation/voting_power.rs @@ -23,6 +23,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Returns an account's total voting power (voting or NOT voting). pub async fn get_voting_power(&self) -> Result { diff --git a/sdk/src/wallet/account/operations/reissue.rs b/sdk/src/wallet/account/operations/reissue.rs index 9124ceabcd..54c93a4f42 100644 --- a/sdk/src/wallet/account/operations/reissue.rs +++ b/sdk/src/wallet/account/operations/reissue.rs @@ -1,6 +1,8 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use crypto::keys::bip44::Bip44; + use crate::{ client::{secret::SecretManage, Error as ClientError}, types::{ @@ -22,6 +24,7 @@ const DEFAULT_REISSUE_UNTIL_INCLUDED_MAX_AMOUNT: u64 = 40; impl Account where Error: From, + crate::client::Error: From, { /// Reissues a transaction sent from the account for a provided transaction id until it's /// included (referenced by a milestone). Returns the included block id. @@ -55,12 +58,13 @@ where Some(block_id) => block_id, None => self .client() - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::Transaction(Box::new(transaction.payload.clone()))), + &*self.get_secret_manager().read().await, + Bip44::new(self.wallet.coin_type()), ) .await? .id(&protocol_parameters), @@ -104,12 +108,13 @@ where if index == block_ids_len - 1 && should_reissue { let reissued_block = self .client() - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::Transaction(Box::new(transaction.payload.clone()))), + &*self.get_secret_manager().read().await, + Bip44::new(self.wallet.coin_type()), ) .await?; block_ids.push(reissued_block.id(&protocol_parameters)); diff --git a/sdk/src/wallet/account/operations/syncing/mod.rs b/sdk/src/wallet/account/operations/syncing/mod.rs index 250a3beb45..84019b4641 100644 --- a/sdk/src/wallet/account/operations/syncing/mod.rs +++ b/sdk/src/wallet/account/operations/syncing/mod.rs @@ -26,6 +26,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Set the fallback SyncOptions for account syncing. /// If storage is enabled, will persist during restarts. diff --git a/sdk/src/wallet/account/operations/syncing/transactions.rs b/sdk/src/wallet/account/operations/syncing/transactions.rs index d0dbeff01b..028ab8ecf4 100644 --- a/sdk/src/wallet/account/operations/syncing/transactions.rs +++ b/sdk/src/wallet/account/operations/syncing/transactions.rs @@ -21,6 +21,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Sync transactions and reissue them if unconfirmed. Returns the transaction with updated metadata and spent /// output ids that don't need to be locked anymore diff --git a/sdk/src/wallet/account/operations/transaction/high_level/burning_melting/melt_native_token.rs b/sdk/src/wallet/account/operations/transaction/high_level/burning_melting/melt_native_token.rs index 242e329164..759879ce96 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/burning_melting/melt_native_token.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/burning_melting/melt_native_token.rs @@ -18,6 +18,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Melts native tokens. /// diff --git a/sdk/src/wallet/account/operations/transaction/high_level/create_account.rs b/sdk/src/wallet/account/operations/transaction/high_level/create_account.rs index 6a5a4b2310..4259eb6b63 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/create_account.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/create_account.rs @@ -38,6 +38,7 @@ pub struct CreateAccountParams { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Creates an account output. /// ```ignore diff --git a/sdk/src/wallet/account/operations/transaction/high_level/minting/create_native_token.rs b/sdk/src/wallet/account/operations/transaction/high_level/minting/create_native_token.rs index 8e7c71997e..4d07f59381 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/minting/create_native_token.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/minting/create_native_token.rs @@ -88,6 +88,7 @@ impl From<&PreparedCreateNativeTokenTransaction> for PreparedCreateNativeTokenTr impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Creates a new foundry output with minted native tokens. /// diff --git a/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_native_token.rs b/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_native_token.rs index 6fa5103052..219ad5867f 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_native_token.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_native_token.rs @@ -17,6 +17,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Mints additional native tokens. /// diff --git a/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_nfts.rs b/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_nfts.rs index 18996d33ee..7bbdd202d5 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_nfts.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/minting/mint_nfts.rs @@ -112,6 +112,7 @@ impl MintNftParams { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Mints NFTs. /// diff --git a/sdk/src/wallet/account/operations/transaction/high_level/send.rs b/sdk/src/wallet/account/operations/transaction/high_level/send.rs index 943aa87b9f..1da4896136 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/send.rs @@ -80,6 +80,7 @@ impl SendParams { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Sends a certain amount of base coins to a single address. /// diff --git a/sdk/src/wallet/account/operations/transaction/high_level/send_native_tokens.rs b/sdk/src/wallet/account/operations/transaction/high_level/send_native_tokens.rs index 758074730e..f59c3d2144 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/send_native_tokens.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/send_native_tokens.rs @@ -82,6 +82,7 @@ impl SendNativeTokensParams { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Sends native tokens in basic outputs with a [`StorageDepositReturnUnlockCondition`] and an /// [`ExpirationUnlockCondition`], so that the storage deposit is returned to the sender and the sender gets access diff --git a/sdk/src/wallet/account/operations/transaction/high_level/send_nft.rs b/sdk/src/wallet/account/operations/transaction/high_level/send_nft.rs index 32e56d3676..eb371cd421 100644 --- a/sdk/src/wallet/account/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/account/operations/transaction/high_level/send_nft.rs @@ -42,6 +42,7 @@ impl SendNftParams { impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Sends native tokens in basic outputs with a /// [`StorageDepositReturnUnlockCondition`](crate::types::block::output::unlock_condition::StorageDepositReturnUnlockCondition) and an diff --git a/sdk/src/wallet/account/operations/transaction/mod.rs b/sdk/src/wallet/account/operations/transaction/mod.rs index c3003ef4f8..4a88d21660 100644 --- a/sdk/src/wallet/account/operations/transaction/mod.rs +++ b/sdk/src/wallet/account/operations/transaction/mod.rs @@ -33,6 +33,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Sends a transaction by specifying its outputs. /// diff --git a/sdk/src/wallet/account/operations/transaction/prepare_output.rs b/sdk/src/wallet/account/operations/transaction/prepare_output.rs index f682314eb9..b904acdb9f 100644 --- a/sdk/src/wallet/account/operations/transaction/prepare_output.rs +++ b/sdk/src/wallet/account/operations/transaction/prepare_output.rs @@ -28,6 +28,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Prepare a basic or NFT output for sending /// If the amount is below the minimum required storage deposit, by default the remaining amount will automatically diff --git a/sdk/src/wallet/account/operations/transaction/prepare_transaction.rs b/sdk/src/wallet/account/operations/transaction/prepare_transaction.rs index 659fbb028d..39086d7b2d 100644 --- a/sdk/src/wallet/account/operations/transaction/prepare_transaction.rs +++ b/sdk/src/wallet/account/operations/transaction/prepare_transaction.rs @@ -23,6 +23,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Get inputs and build the transaction essence pub async fn prepare_transaction( diff --git a/sdk/src/wallet/account/operations/transaction/sign_transaction.rs b/sdk/src/wallet/account/operations/transaction/sign_transaction.rs index 883d0631a4..01c2242481 100644 --- a/sdk/src/wallet/account/operations/transaction/sign_transaction.rs +++ b/sdk/src/wallet/account/operations/transaction/sign_transaction.rs @@ -23,6 +23,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Signs a transaction essence. pub async fn sign_transaction_essence( diff --git a/sdk/src/wallet/account/operations/transaction/submit_transaction.rs b/sdk/src/wallet/account/operations/transaction/submit_transaction.rs index 916f21a875..3175410e34 100644 --- a/sdk/src/wallet/account/operations/transaction/submit_transaction.rs +++ b/sdk/src/wallet/account/operations/transaction/submit_transaction.rs @@ -1,6 +1,8 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use crypto::keys::bip44::Bip44; + #[cfg(feature = "events")] use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ @@ -12,6 +14,7 @@ use crate::{ impl Account where crate::wallet::Error: From, + crate::client::Error: From, { /// Submits a payload in a block pub(crate) async fn submit_transaction_payload( @@ -24,12 +27,13 @@ where let block = self .client() - .finish_basic_block_builder( + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::from(transaction_payload)), + &*self.get_secret_manager().read().await, + Bip44::new(self.wallet.coin_type()), ) .await?; diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index 837408de50..0eb401fdf9 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -4,6 +4,7 @@ pub(crate) mod builder; pub(crate) mod operations; +use core::sync::atomic::Ordering; use std::sync::{ atomic::{AtomicU32, AtomicUsize}, Arc, @@ -88,6 +89,7 @@ pub struct WalletInner { impl Wallet where crate::wallet::Error: From, + crate::client::Error: From, { /// Get all accounts pub async fn get_accounts(&self) -> crate::wallet::Result>> { @@ -167,6 +169,10 @@ where } impl WalletInner { + pub fn coin_type(&self) -> u32 { + self.coin_type.load(Ordering::Relaxed) + } + /// Get the [SecretManager] pub fn get_secret_manager(&self) -> &Arc> { &self.secret_manager diff --git a/sdk/src/wallet/core/operations/account_recovery.rs b/sdk/src/wallet/core/operations/account_recovery.rs index f72ea75da8..743639080d 100644 --- a/sdk/src/wallet/core/operations/account_recovery.rs +++ b/sdk/src/wallet/core/operations/account_recovery.rs @@ -11,6 +11,7 @@ use crate::{ impl Wallet where crate::wallet::Error: From, + crate::client::Error: From, { /// Find accounts with unspent outputs. /// diff --git a/sdk/src/wallet/core/operations/address_generation.rs b/sdk/src/wallet/core/operations/address_generation.rs index f84277de38..6fb477fa87 100644 --- a/sdk/src/wallet/core/operations/address_generation.rs +++ b/sdk/src/wallet/core/operations/address_generation.rs @@ -132,6 +132,7 @@ impl Wallet { impl Wallet where crate::wallet::Error: From, + crate::client::Error: From, { /// Get the bech32 hrp from the first account address or if not existent, from the client pub async fn get_bech32_hrp(&self) -> crate::wallet::Result { diff --git a/sdk/src/wallet/core/operations/background_syncing.rs b/sdk/src/wallet/core/operations/background_syncing.rs index f7f59fa24d..174317c9c2 100644 --- a/sdk/src/wallet/core/operations/background_syncing.rs +++ b/sdk/src/wallet/core/operations/background_syncing.rs @@ -16,6 +16,7 @@ pub(crate) const DEFAULT_BACKGROUNDSYNCING_INTERVAL: Duration = Duration::from_s impl Wallet where crate::wallet::Error: From, + crate::client::Error: From, { /// Start the background syncing process for all accounts, default interval is 7 seconds pub async fn start_background_syncing( diff --git a/sdk/tests/client/node_api/core.rs b/sdk/tests/client/node_api/core.rs index ffc73afa7f..b44bae435a 100644 --- a/sdk/tests/client/node_api/core.rs +++ b/sdk/tests/client/node_api/core.rs @@ -50,7 +50,8 @@ async fn test_get_issuance() { #[ignore] #[tokio::test] async fn test_post_block_with_tagged_data() { - let block_id = setup_tagged_data_block().await; + let secret_manager = setup_secret_manager(); + let block_id = setup_tagged_data_block(&secret_manager).await; println!("{block_id}"); } @@ -66,8 +67,9 @@ async fn test_post_block_with_transaction() { #[tokio::test] async fn test_get_block_data() { let client = setup_client_with_node_health_ignored().await; + let secret_manager = setup_secret_manager(); - let block_id = setup_tagged_data_block().await; + let block_id = setup_tagged_data_block(&secret_manager).await; let r = client.get_block(&block_id).await.unwrap(); println!("{r:#?}"); @@ -76,7 +78,8 @@ async fn test_get_block_data() { #[ignore] #[tokio::test] async fn test_get_block_metadata() { - let block_id = setup_tagged_data_block().await; + let secret_manager = setup_secret_manager(); + let block_id = setup_tagged_data_block(&secret_manager).await; let r = setup_client_with_node_health_ignored() .await @@ -90,7 +93,8 @@ async fn test_get_block_metadata() { #[ignore] #[tokio::test] async fn test_get_block_raw() { - let block_id = setup_tagged_data_block().await; + let secret_manager = setup_secret_manager(); + let block_id = setup_tagged_data_block(&secret_manager).await; let r = setup_client_with_node_health_ignored() .await diff --git a/sdk/tests/client/node_api/mod.rs b/sdk/tests/client/node_api/mod.rs index d79dd52193..f4839038af 100644 --- a/sdk/tests/client/node_api/mod.rs +++ b/sdk/tests/client/node_api/mod.rs @@ -6,10 +6,11 @@ mod indexer; #[cfg(feature = "mqtt")] mod mqtt; +use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ - api::GetAddressesOptions, node_api::indexer::query_parameters::QueryParameter, request_funds_from_faucet, - secret::SecretManager, Client, + api::GetAddressesOptions, constants::IOTA_COIN_TYPE, node_api::indexer::query_parameters::QueryParameter, + request_funds_from_faucet, secret::SecretManager, Client, }, types::block::{ payload::{tagged_data::TaggedDataPayload, transaction::TransactionId, Payload}, @@ -23,22 +24,25 @@ use crate::client::common::{setup_client_with_node_health_ignored, FAUCET_URL}; const DEFAULT_DEVELOPMENT_SEED: &str = "0x256a818b2aac458941f7274985a410e57fb750f3a3a67969ece5bd9ae7eef5b2"; // Sends a tagged data block to the node to test against it. -async fn setup_tagged_data_block() -> BlockId { +async fn setup_tagged_data_block(secret_manager: &SecretManager) -> BlockId { let client = setup_client_with_node_health_ignored().await; - let block = client - .finish_basic_block_builder( + + let protocol_params = client.get_protocol_parameters().await.unwrap(); + + client + .build_basic_block( todo!("issuer id"), - todo!("block signature"), todo!("issuing time"), None, Some(Payload::TaggedData(Box::new( TaggedDataPayload::new(b"Hello".to_vec(), b"Tangle".to_vec()).unwrap(), ))), + secret_manager, + Bip44::new(IOTA_COIN_TYPE), ) .await - .unwrap(); - - client.block_id(&block).await.unwrap() + .unwrap() + .id(&protocol_params) } pub fn setup_secret_manager() -> SecretManager { diff --git a/sdk/tests/types/block.rs b/sdk/tests/types/block.rs index a2939defba..0a19f5ff98 100644 --- a/sdk/tests/types/block.rs +++ b/sdk/tests/types/block.rs @@ -92,7 +92,7 @@ use packable::PackableExt; #[test] fn pack_unpack_valid() { let protocol_parameters = protocol_parameters(); - let block = rand_block_wrapper(&protocol_parameters); + let block = rand_block_wrapper(protocol_parameters.clone()); let packed_block = block.pack_to_vec(); assert_eq!(packed_block.len(), block.packed_len()); @@ -108,17 +108,15 @@ fn getters() { let parents = rand_strong_parents(); let payload = Payload::from(rand_tagged_data_payload()); - let block = rand_block_wrapper_with_block( - &protocol_parameters, - rand_basic_block_builder_with_strong_parents(parents.clone()) - .with_payload(payload.clone()) - .finish() - .unwrap(), - ); + let block = rand_basic_block_builder_with_strong_parents(parents.clone()) + .with_payload(payload.clone()) + .finish_block() + .unwrap(); + let wrapper = rand_block_wrapper_with_block(protocol_parameters.clone(), block); - assert_eq!(block.protocol_version(), protocol_parameters.version()); - assert_eq!(*block.as_basic().strong_parents(), parents); - assert_eq!(*block.as_basic().payload().as_ref().unwrap(), &payload); + assert_eq!(wrapper.protocol_version(), protocol_parameters.version()); + assert_eq!(*wrapper.as_basic().strong_parents(), parents); + assert_eq!(*wrapper.as_basic().payload().as_ref().unwrap(), &payload); } #[test] From 39e6e24c6504ab46de0158b89713a5c5d083b4cd Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 5 Oct 2023 20:33:16 +0200 Subject: [PATCH 2/2] Some protocol changes (#1399) * Payload type as u8 * Reset payload types * Reset Output types * Fix tests * fmt --- sdk/src/types/block/error.rs | 2 +- sdk/src/types/block/output/account.rs | 2 +- sdk/src/types/block/output/basic.rs | 2 +- sdk/src/types/block/output/delegation.rs | 2 +- sdk/src/types/block/output/foundry.rs | 2 +- sdk/src/types/block/output/nft.rs | 2 +- sdk/src/types/block/payload/mod.rs | 4 +- .../types/block/payload/tagged_data/mod.rs | 4 +- .../types/block/payload/transaction/mod.rs | 4 +- sdk/tests/client/input_signing_data.rs | 2 +- sdk/tests/types/block_id.rs | 373 +++++++++--------- sdk/tests/types/payload.rs | 4 +- sdk/tests/types/tagged_data_payload.rs | 2 +- sdk/tests/types/transaction_id.rs | 169 ++++---- sdk/tests/types/transaction_payload.rs | 2 +- .../types/transaction_regular_essence.rs | 2 +- 16 files changed, 293 insertions(+), 285 deletions(-) diff --git a/sdk/src/types/block/error.rs b/sdk/src/types/block/error.rs index 0ac9c990b0..bc889c0898 100644 --- a/sdk/src/types/block/error.rs +++ b/sdk/src/types/block/error.rs @@ -96,7 +96,7 @@ pub enum Error { // https://github.com/iotaledger/iota-sdk/issues/647 // InvalidParentCount(>::Error), InvalidParentCount, - InvalidPayloadKind(u32), + InvalidPayloadKind(u8), InvalidPayloadLength { expected: usize, actual: usize, diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 5e1d832928..f4ba0d9a7d 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -392,7 +392,7 @@ pub struct AccountOutput { impl AccountOutput { /// The [`Output`](crate::types::block::output::Output) kind of an [`AccountOutput`]. - pub const KIND: u8 = 4; + pub const KIND: u8 = 1; /// Maximum possible length in bytes of the state metadata. pub const STATE_METADATA_LENGTH_MAX: u16 = 8192; /// The set of allowed [`UnlockCondition`]s for an [`AccountOutput`]. diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index 7fed97f268..d557b28b1f 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -232,7 +232,7 @@ pub struct BasicOutput { impl BasicOutput { /// The [`Output`](crate::types::block::output::Output) kind of an [`BasicOutput`]. - pub const KIND: u8 = 3; + pub const KIND: u8 = 0; /// The set of allowed [`UnlockCondition`]s for an [`BasicOutput`]. const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::ADDRESS diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index 5c926cd55f..0c2dda387e 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -259,7 +259,7 @@ pub struct DelegationOutput { impl DelegationOutput { /// The [`Output`](crate::types::block::output::Output) kind of a [`DelegationOutput`]. - pub const KIND: u8 = 7; + pub const KIND: u8 = 4; /// The set of allowed [`UnlockCondition`]s for a [`DelegationOutput`]. pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::ADDRESS; diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index f8b0854ee5..90a042eade 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -347,7 +347,7 @@ pub struct FoundryOutput { impl FoundryOutput { /// The [`Output`](crate::types::block::output::Output) kind of a [`FoundryOutput`]. - pub const KIND: u8 = 5; + pub const KIND: u8 = 2; /// The set of allowed [`UnlockCondition`]s for a [`FoundryOutput`]. pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::IMMUTABLE_ACCOUNT_ADDRESS; /// The set of allowed [`Feature`]s for a [`FoundryOutput`]. diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 957e384e51..6e8430e44e 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -305,7 +305,7 @@ pub struct NftOutput { impl NftOutput { /// The [`Output`](crate::types::block::output::Output) kind of an [`NftOutput`]. - pub const KIND: u8 = 6; + pub const KIND: u8 = 3; /// The set of allowed [`UnlockCondition`]s for an [`NftOutput`]. pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::ADDRESS .union(UnlockConditionFlags::STORAGE_DEPOSIT_RETURN) diff --git a/sdk/src/types/block/payload/mod.rs b/sdk/src/types/block/payload/mod.rs index e7ce979cf8..1f386b016b 100644 --- a/sdk/src/types/block/payload/mod.rs +++ b/sdk/src/types/block/payload/mod.rs @@ -55,7 +55,7 @@ impl From for Payload { impl Payload { /// Returns the payload kind of a `Payload`. - pub fn kind(&self) -> u32 { + pub fn kind(&self) -> u8 { match self { Self::Transaction(_) => TransactionPayload::KIND, Self::TaggedData(_) => TaggedDataPayload::KIND, @@ -86,7 +86,7 @@ impl Packable for Payload { unpacker: &mut U, visitor: &Self::UnpackVisitor, ) -> Result> { - Ok(match u32::unpack::<_, VERIFY>(unpacker, &()).coerce()? { + Ok(match u8::unpack::<_, VERIFY>(unpacker, &()).coerce()? { TransactionPayload::KIND => { Self::from(TransactionPayload::unpack::<_, VERIFY>(unpacker, visitor).coerce()?) } diff --git a/sdk/src/types/block/payload/tagged_data/mod.rs b/sdk/src/types/block/payload/tagged_data/mod.rs index 7fd29988e1..dba8239e9e 100644 --- a/sdk/src/types/block/payload/tagged_data/mod.rs +++ b/sdk/src/types/block/payload/tagged_data/mod.rs @@ -31,7 +31,7 @@ pub struct TaggedDataPayload { impl TaggedDataPayload { /// The payload kind of a [`TaggedDataPayload`]. - pub const KIND: u32 = 5; + pub const KIND: u8 = 0; /// Valid lengths for the tag. pub const TAG_LENGTH_RANGE: RangeInclusive = 0..=64; /// Valid lengths for the data. @@ -80,7 +80,7 @@ pub mod dto { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] struct TaggedDataPayloadDto { #[serde(rename = "type")] - kind: u32, + kind: u8, #[serde(skip_serializing_if = "<[_]>::is_empty", default, with = "prefix_hex_bytes")] tag: Box<[u8]>, #[serde(skip_serializing_if = "<[_]>::is_empty", default, with = "prefix_hex_bytes")] diff --git a/sdk/src/types/block/payload/transaction/mod.rs b/sdk/src/types/block/payload/transaction/mod.rs index 8161ee7cb1..f3356abc00 100644 --- a/sdk/src/types/block/payload/transaction/mod.rs +++ b/sdk/src/types/block/payload/transaction/mod.rs @@ -25,7 +25,7 @@ pub struct TransactionPayload { impl TransactionPayload { /// The payload kind of a [`TransactionPayload`]. - pub const KIND: u32 = 6; + pub const KIND: u8 = 1; /// Creates a new [`TransactionPayload`]. pub fn new(essence: RegularTransactionEssence, unlocks: Unlocks) -> Result { @@ -110,7 +110,7 @@ pub mod dto { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct TransactionPayloadDto { #[serde(rename = "type")] - pub kind: u32, + pub kind: u8, pub essence: TransactionEssenceDto, pub unlocks: Vec, } diff --git a/sdk/tests/client/input_signing_data.rs b/sdk/tests/client/input_signing_data.rs index 6f9630c0fa..479a41370a 100644 --- a/sdk/tests/client/input_signing_data.rs +++ b/sdk/tests/client/input_signing_data.rs @@ -72,7 +72,7 @@ fn input_signing_data_conversion() { InputSigningData::try_from_dto_with_params(input_signing_data_dto.clone(), &protocol_parameters).unwrap(); assert_eq!(input_signing_data, restored_input_signing_data); - let input_signing_data_dto_str = r#"{"output":{"type":3,"amount":"1000000","mana":"0","unlockConditions":[{"type":0,"address":{"type":0,"pubKeyHash":"0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]},"outputMetadata":{"blockId":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda0000000000000000","transactionId":"0xbce525324af12eda02bf7927e92cea3a8e8322d0f41966271443e6c3b245a440","outputIndex":0,"isSpent":false,"commitmentIdSpent":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda4f9567d82bf96689","transactionIdSpent":"0x24a1f46bdb6b2bf38f1c59f73cdd4ae5b418804bb231d76d06fbf246498d5883","includedCommitmentId":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda4f9567d82bf96689","latestCommitmentId":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda4f9567d82bf96689"},"chain":{"coinType":4219,"account":0,"change":0,"addressIndex":0}}"#; + let input_signing_data_dto_str = r#"{"output":{"type":0,"amount":"1000000","mana":"0","unlockConditions":[{"type":0,"address":{"type":0,"pubKeyHash":"0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]},"outputMetadata":{"blockId":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda0000000000000000","transactionId":"0xbce525324af12eda02bf7927e92cea3a8e8322d0f41966271443e6c3b245a440","outputIndex":0,"isSpent":false,"commitmentIdSpent":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda4f9567d82bf96689","transactionIdSpent":"0x24a1f46bdb6b2bf38f1c59f73cdd4ae5b418804bb231d76d06fbf246498d5883","includedCommitmentId":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda4f9567d82bf96689","latestCommitmentId":"0xedf5f572c58ddf4b4f9567d82bf96689cc68b730df796d822b4b9fb643f5efda4f9567d82bf96689"},"chain":{"coinType":4219,"account":0,"change":0,"addressIndex":0}}"#; assert_eq!( serde_json::to_string(&input_signing_data_dto).unwrap(), input_signing_data_dto_str diff --git a/sdk/tests/types/block_id.rs b/sdk/tests/types/block_id.rs index 5e21824713..eeb5fb8fa5 100644 --- a/sdk/tests/types/block_id.rs +++ b/sdk/tests/types/block_id.rs @@ -71,201 +71,206 @@ fn protocol_parameters() -> ProtocolParameters { ProtocolParameters::new(3, "test", "rms", RentStructure::default(), 0, 1695275822, 10, 0).unwrap() } -#[test] -fn basic_block_id_tagged_data_payload() { - // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-tagged-data-payload +// TODO +// #[test] +// fn basic_block_id_tagged_data_payload() { +// // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-tagged-data-payload - let block_json = serde_json::json!({ - "protocolVersion": 3, - "networkId": "10549460113735494767", - "issuingTime": "1695275834000000000", - "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", - "latestFinalizedSlot": "21", - "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", - "block": { - "type": 0, - "strongParents": [ - "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", - "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" - ], - "weakParents": [ - "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" - ], - "shallowLikeParents": [ - "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" - ], - "payload": { - "type": 5, - "tag": "0x68656c6c6f20776f726c64", - "data": "0x01020304" - }, - "maxBurnedMana": "180500" - }, - "signature": { - "type": 0, - "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", - "signature": "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" - } - }); +// let block_json = serde_json::json!({ +// "protocolVersion": 3, +// "networkId": "10549460113735494767", +// "issuingTime": "1695275834000000000", +// "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", +// "latestFinalizedSlot": "21", +// "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", +// "block": { +// "type": 0, +// "strongParents": [ +// "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", +// "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" +// ], +// "weakParents": [ +// "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" +// ], +// "shallowLikeParents": [ +// "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" +// ], +// "payload": { +// "type": 5, +// "tag": "0x68656c6c6f20776f726c64", +// "data": "0x01020304" +// }, +// "maxBurnedMana": "180500" +// }, +// "signature": { +// "type": 0, +// "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", +// "signature": +// "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" +// } +// }); - let block_dto = serde_json::from_value::(block_json).unwrap(); - let block = BlockWrapper::try_from_dto(block_dto).unwrap(); - let block_bytes = block.pack_to_vec(); +// let block_dto = serde_json::from_value::(block_json).unwrap(); +// let block = BlockWrapper::try_from_dto(block_dto).unwrap(); +// let block_bytes = block.pack_to_vec(); - assert_eq!( - block_bytes, - [ - 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, 135, - 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, 187, 48, - 148, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, 66, 89, 116, - 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 0, 2, 48, 68, 66, 72, - 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, 30, 14, 85, 122, - 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, 52, 59, 22, 11, 49, - 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, 105, 17, 60, 11, 92, 1, - 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, 111, 1, 46, 27, 17, 124, 78, - 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, 120, 3, 0, 96, 120, 4, 11, 15, - 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, 27, 125, 34, 12, 119, 43, 86, 22, - 90, 18, 24, 0, 0, 0, 5, 0, 0, 0, 11, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 4, 0, 0, 0, 1, - 2, 3, 4, 20, 193, 2, 0, 0, 0, 0, 0, 0, 2, 75, 111, 8, 97, 119, 21, 99, 80, 17, 29, 94, 86, 34, 114, 66, 3, - 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, 25, 60, 124, 39, 78, 94, 119, 29, 93, 96, 32, 45, 51, - 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, 35, 27, 78, 105, 48, 83, 41, 38, 122, 72, 52, 55, 75, 15, - 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, 76, 119, 59, 22, 121, 64, 12, 82, 48, 61, 31, 35, 18, 26, - 64, 73 - ] - ); +// assert_eq!( +// block_bytes, +// [ +// 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, +// 135, 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, +// 187, 48, 148, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, +// 66, 89, 116, 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 0, 2, +// 48, 68, 66, 72, 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, +// 30, 14, 85, 122, 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, +// 52, 59, 22, 11, 49, 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, +// 105, 17, 60, 11, 92, 1, 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, +// 111, 1, 46, 27, 17, 124, 78, 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, +// 120, 3, 0, 96, 120, 4, 11, 15, 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, +// 27, 125, 34, 12, 119, 43, 86, 22, 90, 18, 24, 0, 0, 0, 5, 0, 0, 0, 11, 104, 101, 108, 108, 111, 32, 119, +// 111, 114, 108, 100, 4, 0, 0, 0, 1, 2, 3, 4, 20, 193, 2, 0, 0, 0, 0, 0, 0, 2, 75, 111, 8, 97, 119, 21, 99, +// 80, 17, 29, 94, 86, 34, 114, 66, 3, 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, 25, 60, 124, 39, +// 78, 94, 119, 29, 93, 96, 32, 45, 51, 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, 35, 27, 78, 105, +// 48, 83, 41, 38, 122, 72, 52, 55, 75, 15, 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, 76, 119, 59, 22, +// 121, 64, 12, 82, 48, 61, 31, 35, 18, 26, 64, 73 +// ] +// ); - let block_id = block.id(&protocol_parameters()).to_string(); +// let block_id = block.id(&protocol_parameters()).to_string(); - assert_eq!( - block_id, - "0xb2c397afa61262c10af75320a166d28be34debcc4449f272f90c8769681c0b710200000000000000" - ); -} +// assert_eq!( +// block_id, +// "0xb2c397afa61262c10af75320a166d28be34debcc4449f272f90c8769681c0b710200000000000000" +// ); +// } -#[test] -fn basic_block_id_transaction_payload() { - // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-transaction-payload +// TODO +// #[test] +// fn basic_block_id_transaction_payload() { +// // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-transaction-payload - let block_json = serde_json::json!({ - "protocolVersion": 3, - "networkId": "10549460113735494767", - "issuingTime": "1695275834000000000", - "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", - "latestFinalizedSlot": "21", - "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", - "block": { - "type": 0, - "strongParents": [ - "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", - "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" - ], - "weakParents": [ - "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" - ], - "shallowLikeParents": [ - "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" - ], - "payload": { - "type": 6, - "essence": { - "type": 2, - "networkId": "3650798313638353144", - "creationSlot": "28", - "contextInputs": [], - "inputs": [ - { - "type": 0, - "transactionId": "0x24ff9b3038506fb1b406306a496001c3e24e2be07c838317922bf21d686a078f", - "transactionOutputIndex": 10 - } - ], - "inputsCommitment": "0xb70c6f86a1ea03a59a71d73dcd07e2082bbdf0ce971faa21748348bca22fb023", - "outputs": [ - { - "type": 3, - "amount": "10000", - "mana": "0", - "unlockConditions": [ - { - "type": 0, - "address": { - "type": 0, - "pubKeyHash": "0xd9f84458286dc41cd34789dec566cd096cf47de991aa36a97aebfaea14128f6d" - } - } - ] - } - ], - "allotments": [], - "payload": { - "type": 5, - "tag": "0x1d7b3e11697264111e130b0e", - "data": "0x1d7b3e11697264111e130b0e" - } - }, - "unlocks": [ - { - "type": 0, - "signature": { - "type": 0, - "publicKey": "0x803361fe1effc899dca7f931d8ad07c01ba23aaa93f986adb04d4c17cf6368d8", - "signature": "0xccddbac3aaac413e0193e16da3449f30c183d0e7eaa7f303dc12ae0dbc9fb890e449a52f9056e7d952ea796fd3e5645f60d9eb98ed91cb3261720fb528d2a105" - } - } - ] - }, - "maxBurnedMana": "180500" - }, - "signature": { - "type": 0, - "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", - "signature": "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" - } - }); +// let block_json = serde_json::json!({ +// "protocolVersion": 3, +// "networkId": "10549460113735494767", +// "issuingTime": "1695275834000000000", +// "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", +// "latestFinalizedSlot": "21", +// "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", +// "block": { +// "type": 0, +// "strongParents": [ +// "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", +// "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" +// ], +// "weakParents": [ +// "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" +// ], +// "shallowLikeParents": [ +// "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" +// ], +// "payload": { +// "type": 6, +// "essence": { +// "type": 2, +// "networkId": "3650798313638353144", +// "creationSlot": "28", +// "contextInputs": [], +// "inputs": [ +// { +// "type": 0, +// "transactionId": "0x24ff9b3038506fb1b406306a496001c3e24e2be07c838317922bf21d686a078f", +// "transactionOutputIndex": 10 +// } +// ], +// "inputsCommitment": "0xb70c6f86a1ea03a59a71d73dcd07e2082bbdf0ce971faa21748348bca22fb023", +// "outputs": [ +// { +// "type": 3, +// "amount": "10000", +// "mana": "0", +// "unlockConditions": [ +// { +// "type": 0, +// "address": { +// "type": 0, +// "pubKeyHash": "0xd9f84458286dc41cd34789dec566cd096cf47de991aa36a97aebfaea14128f6d" +// } +// } +// ] +// } +// ], +// "allotments": [], +// "payload": { +// "type": 5, +// "tag": "0x1d7b3e11697264111e130b0e", +// "data": "0x1d7b3e11697264111e130b0e" +// } +// }, +// "unlocks": [ +// { +// "type": 0, +// "signature": { +// "type": 0, +// "publicKey": "0x803361fe1effc899dca7f931d8ad07c01ba23aaa93f986adb04d4c17cf6368d8", +// "signature": +// "0xccddbac3aaac413e0193e16da3449f30c183d0e7eaa7f303dc12ae0dbc9fb890e449a52f9056e7d952ea796fd3e5645f60d9eb98ed91cb3261720fb528d2a105" +// } +// } +// ] +// }, +// "maxBurnedMana": "180500" +// }, +// "signature": { +// "type": 0, +// "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", +// "signature": +// "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" +// } +// }); - let block_dto = serde_json::from_value::(block_json).unwrap(); - let block = BlockWrapper::try_from_dto(block_dto).unwrap(); - let block_bytes = block.pack_to_vec(); +// let block_dto = serde_json::from_value::(block_json).unwrap(); +// let block = BlockWrapper::try_from_dto(block_dto).unwrap(); +// let block_bytes = block.pack_to_vec(); - assert_eq!( - block_bytes, - [ - 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, 135, - 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, 187, 48, - 148, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, 66, 89, 116, - 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 0, 2, 48, 68, 66, 72, - 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, 30, 14, 85, 122, - 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, 52, 59, 22, 11, 49, - 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, 105, 17, 60, 11, 92, 1, - 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, 111, 1, 46, 27, 17, 124, 78, - 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, 120, 3, 0, 96, 120, 4, 11, 15, - 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, 27, 125, 34, 12, 119, 43, 86, 22, - 90, 18, 31, 1, 0, 0, 6, 0, 0, 0, 2, 248, 88, 2, 55, 185, 61, 170, 50, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 36, 255, 155, 48, 56, 80, 111, 177, 180, 6, 48, 106, 73, 96, 1, 195, 226, 78, 43, 224, 124, 131, 131, - 23, 146, 43, 242, 29, 104, 106, 7, 143, 10, 0, 183, 12, 111, 134, 161, 234, 3, 165, 154, 113, 215, 61, 205, - 7, 226, 8, 43, 189, 240, 206, 151, 31, 170, 33, 116, 131, 72, 188, 162, 47, 176, 35, 1, 0, 3, 16, 39, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 217, 248, 68, 88, 40, 109, 196, 28, 211, 71, 137, 222, 197, - 102, 205, 9, 108, 244, 125, 233, 145, 170, 54, 169, 122, 235, 250, 234, 20, 18, 143, 109, 0, 0, 0, 33, 0, - 0, 0, 5, 0, 0, 0, 12, 29, 123, 62, 17, 105, 114, 100, 17, 30, 19, 11, 14, 12, 0, 0, 0, 29, 123, 62, 17, - 105, 114, 100, 17, 30, 19, 11, 14, 1, 0, 0, 0, 128, 51, 97, 254, 30, 255, 200, 153, 220, 167, 249, 49, 216, - 173, 7, 192, 27, 162, 58, 170, 147, 249, 134, 173, 176, 77, 76, 23, 207, 99, 104, 216, 204, 221, 186, 195, - 170, 172, 65, 62, 1, 147, 225, 109, 163, 68, 159, 48, 193, 131, 208, 231, 234, 167, 243, 3, 220, 18, 174, - 13, 188, 159, 184, 144, 228, 73, 165, 47, 144, 86, 231, 217, 82, 234, 121, 111, 211, 229, 100, 95, 96, 217, - 235, 152, 237, 145, 203, 50, 97, 114, 15, 181, 40, 210, 161, 5, 20, 193, 2, 0, 0, 0, 0, 0, 0, 2, 75, 111, - 8, 97, 119, 21, 99, 80, 17, 29, 94, 86, 34, 114, 66, 3, 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, - 25, 60, 124, 39, 78, 94, 119, 29, 93, 96, 32, 45, 51, 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, 35, - 27, 78, 105, 48, 83, 41, 38, 122, 72, 52, 55, 75, 15, 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, 76, - 119, 59, 22, 121, 64, 12, 82, 48, 61, 31, 35, 18, 26, 64, 73 - ] - ); +// assert_eq!( +// block_bytes, +// [ +// 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, +// 135, 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, +// 187, 48, 148, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, +// 66, 89, 116, 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 0, 2, +// 48, 68, 66, 72, 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, +// 30, 14, 85, 122, 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, +// 52, 59, 22, 11, 49, 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, +// 105, 17, 60, 11, 92, 1, 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, +// 111, 1, 46, 27, 17, 124, 78, 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, +// 120, 3, 0, 96, 120, 4, 11, 15, 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, +// 27, 125, 34, 12, 119, 43, 86, 22, 90, 18, 31, 1, 0, 0, 6, 0, 0, 0, 2, 248, 88, 2, 55, 185, 61, 170, 50, +// 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 36, 255, 155, 48, 56, 80, 111, 177, 180, 6, 48, 106, 73, 96, 1, +// 195, 226, 78, 43, 224, 124, 131, 131, 23, 146, 43, 242, 29, 104, 106, 7, 143, 10, 0, 183, 12, 111, 134, +// 161, 234, 3, 165, 154, 113, 215, 61, 205, 7, 226, 8, 43, 189, 240, 206, 151, 31, 170, 33, 116, 131, 72, +// 188, 162, 47, 176, 35, 1, 0, 3, 16, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 217, 248, +// 68, 88, 40, 109, 196, 28, 211, 71, 137, 222, 197, 102, 205, 9, 108, 244, 125, 233, 145, 170, 54, 169, +// 122, 235, 250, 234, 20, 18, 143, 109, 0, 0, 0, 33, 0, 0, 0, 5, 0, 0, 0, 12, 29, 123, 62, 17, 105, 114, +// 100, 17, 30, 19, 11, 14, 12, 0, 0, 0, 29, 123, 62, 17, 105, 114, 100, 17, 30, 19, 11, 14, 1, 0, 0, 0, +// 128, 51, 97, 254, 30, 255, 200, 153, 220, 167, 249, 49, 216, 173, 7, 192, 27, 162, 58, 170, 147, 249, +// 134, 173, 176, 77, 76, 23, 207, 99, 104, 216, 204, 221, 186, 195, 170, 172, 65, 62, 1, 147, 225, 109, +// 163, 68, 159, 48, 193, 131, 208, 231, 234, 167, 243, 3, 220, 18, 174, 13, 188, 159, 184, 144, 228, 73, +// 165, 47, 144, 86, 231, 217, 82, 234, 121, 111, 211, 229, 100, 95, 96, 217, 235, 152, 237, 145, 203, 50, +// 97, 114, 15, 181, 40, 210, 161, 5, 20, 193, 2, 0, 0, 0, 0, 0, 0, 2, 75, 111, 8, 97, 119, 21, 99, 80, 17, +// 29, 94, 86, 34, 114, 66, 3, 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, 25, 60, 124, 39, 78, 94, +// 119, 29, 93, 96, 32, 45, 51, 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, 35, 27, 78, 105, 48, 83, +// 41, 38, 122, 72, 52, 55, 75, 15, 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, 76, 119, 59, 22, 121, 64, +// 12, 82, 48, 61, 31, 35, 18, 26, 64, 73 ] +// ); - let block_id = block.id(&protocol_parameters()).to_string(); +// let block_id = block.id(&protocol_parameters()).to_string(); - assert_eq!( - block_id, - "0x22215ad9e912989a4886d48a7147b23b753c251861cd0ed14649a11cd85028f60200000000000000" - ); -} +// assert_eq!( +// block_id, +// "0x22215ad9e912989a4886d48a7147b23b753c251861cd0ed14649a11cd85028f60200000000000000" +// ); +// } #[test] fn validation_block_id() { diff --git a/sdk/tests/types/payload.rs b/sdk/tests/types/payload.rs index 3896aafd33..c662c0d4d2 100644 --- a/sdk/tests/types/payload.rs +++ b/sdk/tests/types/payload.rs @@ -55,7 +55,7 @@ fn transaction() { let payload: Payload = tx_payload.into(); let packed = payload.pack_to_vec(); - assert_eq!(payload.kind(), 6); + assert_eq!(payload.kind(), 1); assert_eq!(payload.packed_len(), packed.len()); assert!(matches!(payload, Payload::Transaction(_))); assert_eq!( @@ -70,7 +70,7 @@ fn tagged_data() { let packed = payload.pack_to_vec(); - assert_eq!(payload.kind(), 5); + assert_eq!(payload.kind(), 0); assert_eq!(payload.packed_len(), packed.len()); assert!(matches!(payload, Payload::TaggedData(_))); } diff --git a/sdk/tests/types/tagged_data_payload.rs b/sdk/tests/types/tagged_data_payload.rs index 39d56cc036..ddf22a0531 100644 --- a/sdk/tests/types/tagged_data_payload.rs +++ b/sdk/tests/types/tagged_data_payload.rs @@ -14,7 +14,7 @@ use packable::{ #[test] fn kind() { - assert_eq!(TaggedDataPayload::KIND, 5); + assert_eq!(TaggedDataPayload::KIND, 0); } #[test] diff --git a/sdk/tests/types/transaction_id.rs b/sdk/tests/types/transaction_id.rs index 4320d5cb2e..74cf770991 100644 --- a/sdk/tests/types/transaction_id.rs +++ b/sdk/tests/types/transaction_id.rs @@ -54,86 +54,89 @@ fn pack_unpack_valid() { ); } -#[test] -fn transaction_id() { - // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#transaction-id - - let transaction_payload_json = serde_json::json!({ - "type":6, - "essence":{ - "type":2, - "networkId":"3650798313638353144", - "creationSlot":"28", - "contextInputs":[], - "inputs":[ - { - "type":0, - "transactionId":"0x24ff9b3038506fb1b406306a496001c3e24e2be07c838317922bf21d686a078f", - "transactionOutputIndex":10 - } - ], - "inputsCommitment":"0xb70c6f86a1ea03a59a71d73dcd07e2082bbdf0ce971faa21748348bca22fb023", - "outputs":[ - { - "type":3, - "amount":"10000", - "mana":"0", - "unlockConditions":[ - { - "type":0, - "address":{ - "type":0, - "pubKeyHash":"0xd9f84458286dc41cd34789dec566cd096cf47de991aa36a97aebfaea14128f6d" - } - } - ] - } - ], - "allotments":[], - "payload":{ - "type":5, - "tag":"0x1d7b3e11697264111e130b0e", - "data":"0x1d7b3e11697264111e130b0e" - } - }, - "unlocks":[ - { - "type":0, - "signature":{ - "type":0, - "publicKey":"0x803361fe1effc899dca7f931d8ad07c01ba23aaa93f986adb04d4c17cf6368d8", - "signature":"0xccddbac3aaac413e0193e16da3449f30c183d0e7eaa7f303dc12ae0dbc9fb890e449a52f9056e7d952ea796fd3e5645f60d9eb98ed91cb3261720fb528d2a105" - } - } - ] - }); - - let transaction_payload_dto = serde_json::from_value::(transaction_payload_json).unwrap(); - let transaction_payload = TransactionPayload::try_from_dto(transaction_payload_dto).unwrap(); - let transaction_payload_bytes = Payload::from(transaction_payload.clone()).pack_to_vec(); - - assert_eq!( - transaction_payload_bytes, - [ - 6, 0, 0, 0, 2, 248, 88, 2, 55, 185, 61, 170, 50, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 36, 255, 155, 48, - 56, 80, 111, 177, 180, 6, 48, 106, 73, 96, 1, 195, 226, 78, 43, 224, 124, 131, 131, 23, 146, 43, 242, 29, - 104, 106, 7, 143, 10, 0, 183, 12, 111, 134, 161, 234, 3, 165, 154, 113, 215, 61, 205, 7, 226, 8, 43, 189, - 240, 206, 151, 31, 170, 33, 116, 131, 72, 188, 162, 47, 176, 35, 1, 0, 3, 16, 39, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 217, 248, 68, 88, 40, 109, 196, 28, 211, 71, 137, 222, 197, 102, 205, 9, 108, - 244, 125, 233, 145, 170, 54, 169, 122, 235, 250, 234, 20, 18, 143, 109, 0, 0, 0, 33, 0, 0, 0, 5, 0, 0, 0, - 12, 29, 123, 62, 17, 105, 114, 100, 17, 30, 19, 11, 14, 12, 0, 0, 0, 29, 123, 62, 17, 105, 114, 100, 17, - 30, 19, 11, 14, 1, 0, 0, 0, 128, 51, 97, 254, 30, 255, 200, 153, 220, 167, 249, 49, 216, 173, 7, 192, 27, - 162, 58, 170, 147, 249, 134, 173, 176, 77, 76, 23, 207, 99, 104, 216, 204, 221, 186, 195, 170, 172, 65, 62, - 1, 147, 225, 109, 163, 68, 159, 48, 193, 131, 208, 231, 234, 167, 243, 3, 220, 18, 174, 13, 188, 159, 184, - 144, 228, 73, 165, 47, 144, 86, 231, 217, 82, 234, 121, 111, 211, 229, 100, 95, 96, 217, 235, 152, 237, - 145, 203, 50, 97, 114, 15, 181, 40, 210, 161, 5 - ] - ); - - let transaction_id = transaction_payload.id().to_string(); - - assert_eq!( - transaction_id, - "0xc4f095a7ee824c8fd53040c4143963153636d56bb2334167fd4f531472682533" - ); -} +// TODO +// #[test] +// fn transaction_id() { +// // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#transaction-id + +// let transaction_payload_json = serde_json::json!({ +// "type":6, +// "essence":{ +// "type":2, +// "networkId":"3650798313638353144", +// "creationSlot":"28", +// "contextInputs":[], +// "inputs":[ +// { +// "type":0, +// "transactionId":"0x24ff9b3038506fb1b406306a496001c3e24e2be07c838317922bf21d686a078f", +// "transactionOutputIndex":10 +// } +// ], +// "inputsCommitment":"0xb70c6f86a1ea03a59a71d73dcd07e2082bbdf0ce971faa21748348bca22fb023", +// "outputs":[ +// { +// "type":3, +// "amount":"10000", +// "mana":"0", +// "unlockConditions":[ +// { +// "type":0, +// "address":{ +// "type":0, +// "pubKeyHash":"0xd9f84458286dc41cd34789dec566cd096cf47de991aa36a97aebfaea14128f6d" +// } +// } +// ] +// } +// ], +// "allotments":[], +// "payload":{ +// "type":5, +// "tag":"0x1d7b3e11697264111e130b0e", +// "data":"0x1d7b3e11697264111e130b0e" +// } +// }, +// "unlocks":[ +// { +// "type":0, +// "signature":{ +// "type":0, +// "publicKey":"0x803361fe1effc899dca7f931d8ad07c01ba23aaa93f986adb04d4c17cf6368d8", +// +// "signature":" +// 0xccddbac3aaac413e0193e16da3449f30c183d0e7eaa7f303dc12ae0dbc9fb890e449a52f9056e7d952ea796fd3e5645f60d9eb98ed91cb3261720fb528d2a105" +// } +// } +// ] +// }); + +// let transaction_payload_dto = serde_json::from_value::(transaction_payload_json).unwrap(); +// let transaction_payload = TransactionPayload::try_from_dto(transaction_payload_dto).unwrap(); +// let transaction_payload_bytes = Payload::from(transaction_payload.clone()).pack_to_vec(); + +// assert_eq!( +// transaction_payload_bytes, +// [ +// 6, 0, 0, 0, 2, 248, 88, 2, 55, 185, 61, 170, 50, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 36, 255, 155, +// 48, 56, 80, 111, 177, 180, 6, 48, 106, 73, 96, 1, 195, 226, 78, 43, 224, 124, 131, 131, 23, 146, 43, 242, +// 29, 104, 106, 7, 143, 10, 0, 183, 12, 111, 134, 161, 234, 3, 165, 154, 113, 215, 61, 205, 7, 226, 8, 43, +// 189, 240, 206, 151, 31, 170, 33, 116, 131, 72, 188, 162, 47, 176, 35, 1, 0, 3, 16, 39, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 217, 248, 68, 88, 40, 109, 196, 28, 211, 71, 137, 222, 197, 102, 205, +// 9, 108, 244, 125, 233, 145, 170, 54, 169, 122, 235, 250, 234, 20, 18, 143, 109, 0, 0, 0, 33, 0, 0, 0, 5, +// 0, 0, 0, 12, 29, 123, 62, 17, 105, 114, 100, 17, 30, 19, 11, 14, 12, 0, 0, 0, 29, 123, 62, 17, 105, 114, +// 100, 17, 30, 19, 11, 14, 1, 0, 0, 0, 128, 51, 97, 254, 30, 255, 200, 153, 220, 167, 249, 49, 216, 173, 7, +// 192, 27, 162, 58, 170, 147, 249, 134, 173, 176, 77, 76, 23, 207, 99, 104, 216, 204, 221, 186, 195, 170, +// 172, 65, 62, 1, 147, 225, 109, 163, 68, 159, 48, 193, 131, 208, 231, 234, 167, 243, 3, 220, 18, 174, 13, +// 188, 159, 184, 144, 228, 73, 165, 47, 144, 86, 231, 217, 82, 234, 121, 111, 211, 229, 100, 95, 96, 217, +// 235, 152, 237, 145, 203, 50, 97, 114, 15, 181, 40, 210, 161, 5 +// ] +// ); + +// let transaction_id = transaction_payload.id().to_string(); + +// assert_eq!( +// transaction_id, +// "0xc4f095a7ee824c8fd53040c4143963153636d56bb2334167fd4f531472682533" +// ); +// } diff --git a/sdk/tests/types/transaction_payload.rs b/sdk/tests/types/transaction_payload.rs index b7250d91e0..f8b5bb39fe 100644 --- a/sdk/tests/types/transaction_payload.rs +++ b/sdk/tests/types/transaction_payload.rs @@ -21,7 +21,7 @@ const ED25519_SIGNATURE: &str = "0xc6a40edf9a089f42c18f4ebccb35fe4b578d93b879e99 #[test] fn kind() { - assert_eq!(TransactionPayload::KIND, 6); + assert_eq!(TransactionPayload::KIND, 1); } // Validate that attempting to construct a `TransactionPayload` with too few unlocks is an error. diff --git a/sdk/tests/types/transaction_regular_essence.rs b/sdk/tests/types/transaction_regular_essence.rs index d7a9f192c5..08eb1d02ba 100644 --- a/sdk/tests/types/transaction_regular_essence.rs +++ b/sdk/tests/types/transaction_regular_essence.rs @@ -151,7 +151,7 @@ fn build_invalid_payload_kind() { .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) .finish_with_params(&protocol_parameters); - assert!(matches!(essence, Err(Error::InvalidPayloadKind(6)))); + assert!(matches!(essence, Err(Error::InvalidPayloadKind(1)))); } #[test]