From 020d4a551ac6e14c3ce778e0441a8177c63eba81 Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Fri, 16 Aug 2024 18:16:18 +0400 Subject: [PATCH] fix tests --- dan_layer/engine/tests/shenanigans.rs | 2 +- dan_layer/engine/tests/test.rs | 8 +-- dan_layer/engine_types/src/argument_parser.rs | 21 ++++--- dan_layer/engine_types/src/substate.rs | 55 ++++++++++--------- dan_layer/template_lib/src/models/resource.rs | 2 +- dan_layer/transaction_manifest/src/value.rs | 14 +++-- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/dan_layer/engine/tests/shenanigans.rs b/dan_layer/engine/tests/shenanigans.rs index 0893a59e0..40daa0212 100644 --- a/dan_layer/engine/tests/shenanigans.rs +++ b/dan_layer/engine/tests/shenanigans.rs @@ -112,7 +112,7 @@ fn it_rejects_unknown_substate_addresses() { ); assert_reject_reason(reason, RuntimeError::ReferencedSubstateNotFound { - address: ResourceAddress::from_hex("abababababababababababababababababababababababababababab") + address: ResourceAddress::from_hex("abababababababababababababababababababababababababababababababab") .unwrap() .into(), }) diff --git a/dan_layer/engine/tests/test.rs b/dan_layer/engine/tests/test.rs index da933e015..9118bcfdc 100644 --- a/dan_layer/engine/tests/test.rs +++ b/dan_layer/engine/tests/test.rs @@ -157,7 +157,7 @@ fn test_buggy_template() { .unwrap_err(); assert!(matches!( err, - TemplateLoaderError::WasmModuleError(WasmExecutionError::AbiDecodeError { .. }) + TemplateLoaderError::WasmModuleError(WasmExecutionError::MemoryPointerOutOfRange { .. }) )); let err = compile_template("tests/templates/buggy", &["unexpected_export_function"]) @@ -238,7 +238,7 @@ fn test_engine_errors() { assert_eq!( reason, "Runtime error: Substate not found with address \ - 'resource_7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b'" + 'resource_7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b'" ); } @@ -334,7 +334,6 @@ fn test_errors_on_infinite_loop() { } mod errors { - use super::*; #[test] @@ -392,7 +391,6 @@ mod errors { } mod consensus { - use super::*; #[test] @@ -909,7 +907,6 @@ mod basic_nft { } mod emoji_id { - use serde::{Deserialize, Serialize}; use super::*; @@ -1102,7 +1099,6 @@ mod emoji_id { } mod tickets { - use serde::{Deserialize, Serialize}; use super::*; diff --git a/dan_layer/engine_types/src/argument_parser.rs b/dan_layer/engine_types/src/argument_parser.rs index c25948db4..3b3b5467e 100644 --- a/dan_layer/engine_types/src/argument_parser.rs +++ b/dan_layer/engine_types/src/argument_parser.rs @@ -259,16 +259,17 @@ mod tests { assert_eq!(args, from_str); // Deserialize from special string representation - let some_args: SomeArgs = - json::from_str(r#"{"args": ["component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d"] }"#) - .unwrap(); + let some_args: SomeArgs = json::from_str( + r#"{"args": ["component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff"] }"#, + ) + .unwrap(); match &some_args.args[0] { Arg::Workspace(_) => panic!(), Arg::Literal(a) => { let a: ComponentAddress = decode_exact(a).unwrap(); assert_eq!( a.to_string(), - "component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d" + "component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff" ); }, } @@ -305,8 +306,10 @@ mod tests { .map(|(k, v)| (k.to_string(), v.to_string())) .collect(), opt: Some( - ComponentAddress::from_str("component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d") - .unwrap(), + ComponentAddress::from_str( + "component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff", + ) + .unwrap(), ), }; @@ -366,9 +369,9 @@ mod tests { #[test] fn it_parses_addresses() { let cases = &[ - "component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d", - "resource_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d", - "vault_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028d", + "component_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff", + "resource_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff", + "vault_4e146f73f764ddc21a89c315bd00c939cfaae7d86df082a36e47028dffffffff", ]; for case in cases { diff --git a/dan_layer/engine_types/src/substate.rs b/dan_layer/engine_types/src/substate.rs index 89868b82d..3e85be20e 100644 --- a/dan_layer/engine_types/src/substate.rs +++ b/dan_layer/engine_types/src/substate.rs @@ -112,7 +112,10 @@ pub enum SubstateId { Component(#[serde(with = "serde_with::string")] ComponentAddress), Resource(#[serde(with = "serde_with::string")] ResourceAddress), Vault(#[serde(with = "serde_with::string")] VaultId), - UnclaimedConfidentialOutput(#[cfg_attr(feature = "ts", ts(type = "string"))] UnclaimedConfidentialOutputAddress), + UnclaimedConfidentialOutput(#[cfg_attr( + feature = "ts", + ts(type = "string") + )] UnclaimedConfidentialOutputAddress), NonFungible(#[serde(with = "serde_with::string")] NonFungibleAddress), NonFungibleIndex(NonFungibleIndexAddress), TransactionReceipt(TransactionReceiptAddress), @@ -318,7 +321,7 @@ impl FromStr for SubstateId { Some(("component", addr)) => { let addr = ComponentAddress::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(s.to_string()))?; Ok(SubstateId::Component(addr)) - }, + } Some(("resource", addr)) => { match addr.split_once(' ') { Some((resource_str, addr)) => match addr.split_once('_') { @@ -327,7 +330,7 @@ impl FromStr for SubstateId { let nft_address = NonFungibleAddress::from_str(s).map_err(|e| InvalidSubstateIdFormat(e.to_string()))?; Ok(SubstateId::NonFungible(nft_address)) - }, + } // resource_xxxx index_ Some(("index", index_str)) => { let resource_addr = ResourceAddress::from_hex(resource_str) @@ -337,7 +340,7 @@ impl FromStr for SubstateId { resource_addr, index, ))) - }, + } _ => Err(InvalidSubstateIdFormat(s.to_string())), }, // resource_xxxx @@ -345,27 +348,27 @@ impl FromStr for SubstateId { let addr = ResourceAddress::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(s.to_string()))?; Ok(SubstateId::Resource(addr)) - }, + } } - }, + } Some(("vault", addr)) => { let id = VaultId::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(s.to_string()))?; Ok(SubstateId::Vault(id)) - }, + } Some(("commitment", addr)) => { let commitment_address = UnclaimedConfidentialOutputAddress::from_hex(addr) .map_err(|_| InvalidSubstateIdFormat(s.to_string()))?; Ok(SubstateId::UnclaimedConfidentialOutput(commitment_address)) - }, + } Some(("txreceipt", addr)) => { let tx_receipt_addr = TransactionReceiptAddress::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(addr.to_string()))?; Ok(SubstateId::TransactionReceipt(tx_receipt_addr)) - }, + } Some(("feeclaim", addr)) => { let addr = Hash::from_hex(addr).map_err(|_| InvalidSubstateIdFormat(addr.to_string()))?; Ok(SubstateId::FeeClaim(addr.into())) - }, + } Some(_) | None => Err(InvalidSubstateIdFormat(s.to_string())), } } @@ -614,7 +617,7 @@ impl Display for SubstateValue { // TODO: improve output match self { SubstateValue::Component(component) => write!(f, "{:?}", component.state()), - SubstateValue::Resource(resource) => write!(f, "{:?}", resource,), + SubstateValue::Resource(resource) => write!(f, "{:?}", resource, ), SubstateValue::Vault(vault) => write!(f, "{:?}", vault), SubstateValue::NonFungible(nft) => write!(f, "{:?}", nft), SubstateValue::NonFungibleIndex(index) => write!(f, "{:?}", index), @@ -648,15 +651,15 @@ impl SubstateDiff { self.down_substates.push((address, version)); } - pub fn up_iter(&self) -> impl Iterator + '_ { + pub fn up_iter(&self) -> impl Iterator + '_ { self.up_substates.iter() } - pub fn into_up_iter(self) -> impl Iterator { + pub fn into_up_iter(self) -> impl Iterator { self.up_substates.into_iter() } - pub fn down_iter(&self) -> impl Iterator + '_ { + pub fn down_iter(&self) -> impl Iterator + '_ { self.down_substates.iter() } @@ -686,32 +689,32 @@ mod tests { #[test] fn it_parses_valid_substate_addresses() { - SubstateId::from_str("component_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5") + SubstateId::from_str("component_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff") .unwrap() .as_component_address() .unwrap(); - SubstateId::from_str("vault_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5") + SubstateId::from_str("vault_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff") .unwrap() .as_vault_id() .unwrap(); - SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5") + SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff") .unwrap() .as_resource_address() .unwrap(); SubstateId::from_str( - "resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5 nft_str:SpecialNft", + "resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff nft_str:SpecialNft", ) - .unwrap() - .as_non_fungible_address() - .unwrap(); + .unwrap() + .as_non_fungible_address() + .unwrap(); SubstateId::from_str( - "resource_a7cf4fd18ada7f367b1c102a9c158abc3754491665033231c5eb907f \ + "resource_a7cf4fd18ada7f367b1c102a9c158abc3754491665033231c5eb907fffffffff \ nft_uuid:7f19c3fe5fa13ff66a0d379fe5f9e3508acbd338db6bedd7350d8d565b2c5d32", ) - .unwrap() - .as_non_fungible_address() - .unwrap(); - SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5 index_0") + .unwrap() + .as_non_fungible_address() + .unwrap(); + SubstateId::from_str("resource_7cbfe29101c24924b1b6ccefbfff98986d648622272ae24f7585dab5ffffffff index_0") .unwrap() .as_non_fungible_index_address() .unwrap(); diff --git a/dan_layer/template_lib/src/models/resource.rs b/dan_layer/template_lib/src/models/resource.rs index 710401df1..a3c229cbf 100644 --- a/dan_layer/template_lib/src/models/resource.rs +++ b/dan_layer/template_lib/src/models/resource.rs @@ -113,7 +113,7 @@ mod tests { #[test] fn string_serialization_and_deserialization() { - let resx_str = "resource_00000000000000000000000000000000000000000000000000000000"; + let resx_str = "resource_0000000000000000000000000000000000000000000000000000000000000000"; let resource = ResourceAddress::from_str(resx_str).unwrap(); let json = serde_json::to_string_pretty(&resource).unwrap(); assert_eq!(json.trim_matches('"'), resx_str); diff --git a/dan_layer/transaction_manifest/src/value.rs b/dan_layer/transaction_manifest/src/value.rs index 3f73a3941..d05754882 100644 --- a/dan_layer/transaction_manifest/src/value.rs +++ b/dan_layer/transaction_manifest/src/value.rs @@ -74,32 +74,34 @@ mod tests { #[test] fn it_parses_address_strings() { - let addr = "component_00000000000000000000000000000000000000000000000000000000" + let addr = "component_0000000000000000000000000000000000000000000000000000000000000000" .parse::() .unwrap(); assert_eq!( *addr.as_address().unwrap(), SubstateId::Component( - ComponentAddress::from_hex("00000000000000000000000000000000000000000000000000000000").unwrap() + ComponentAddress::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap() ) ); - let addr = "resource_00000000000000000000000000000000000000000000000000000000" + let addr = "resource_0000000000000000000000000000000000000000000000000000000000000000" .parse::() .unwrap(); assert_eq!( *addr.as_address().unwrap(), SubstateId::Resource( - ResourceAddress::from_hex("00000000000000000000000000000000000000000000000000000000").unwrap() + ResourceAddress::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap() ) ); - let addr = "vault_00000000000000000000000000000000000000000000000000000000" + let addr = "vault_0000000000000000000000000000000000000000000000000000000000000000" .parse::() .unwrap(); assert_eq!( *addr.as_address().unwrap(), - SubstateId::Vault(VaultId::from_hex("00000000000000000000000000000000000000000000000000000000").unwrap()) + SubstateId::Vault( + VaultId::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap() + ) ); } }