diff --git a/crates/radix-engine-toolkit-uniffi/src/transaction_v1/manifest.rs b/crates/radix-engine-toolkit-uniffi/src/transaction_v1/manifest.rs index 43aca4c1..7186e0c8 100644 --- a/crates/radix-engine-toolkit-uniffi/src/transaction_v1/manifest.rs +++ b/crates/radix-engine-toolkit-uniffi/src/transaction_v1/manifest.rs @@ -392,6 +392,7 @@ impl From for ReservedInstruction { #[derive(Clone, Debug, Enum)] pub enum ManifestClass { + GeneralNonEnclosed, General, Transfer, PoolContribution, @@ -405,6 +406,7 @@ pub enum ManifestClass { impl From for ManifestClass { fn from(value: CoreManifestClass) -> Self { match value { + CoreManifestClass::GeneralNonEnclosed => Self::GeneralNonEnclosed, CoreManifestClass::General => Self::General, CoreManifestClass::Transfer => Self::Transfer, CoreManifestClass::PoolContribution => Self::PoolContribution, diff --git a/crates/radix-engine-toolkit/Cargo.toml b/crates/radix-engine-toolkit/Cargo.toml index e0ffc177..5e8e8a44 100644 --- a/crates/radix-engine-toolkit/Cargo.toml +++ b/crates/radix-engine-toolkit/Cargo.toml @@ -42,6 +42,7 @@ cargo_toml = { version = "0.15.3" } [dev-dependencies] scrypto-test = { workspace = true } +radix-transactions = { workspace = true } [features] default = [] diff --git a/crates/radix-engine-toolkit/src/transaction_types/interface.rs b/crates/radix-engine-toolkit/src/transaction_types/interface.rs index 7be8f9c2..62367c54 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/interface.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/interface.rs @@ -43,6 +43,8 @@ pub fn statically_analyze( let mut account_resource_movements_detector = StaticAccountResourceMovementsDetector::default(); + let mut general_non_enclosed_transaction_detector = + GeneralNonEnclosedDetector::default(); let mut general_transaction_detector = GeneralDetector::default(); let mut transfer_transaction_detector = TransferDetector::default(); let mut pool_contribution_detector = PoolContributionDetector::default(); @@ -62,6 +64,7 @@ pub fn statically_analyze( &mut reserved_instructions_detector, &mut account_resource_movements_detector, &mut general_transaction_detector, + &mut general_non_enclosed_transaction_detector, &mut transfer_transaction_detector, &mut pool_contribution_detector, &mut pool_redemption_detector, @@ -82,9 +85,15 @@ pub fn statically_analyze( let (account_withdraws, account_deposits) = account_resource_movements_detector.output(); let classification = [ + ( + ManifestClass::GeneralNonEnclosed, + general_non_enclosed_transaction_detector.is_valid() + && !general_transaction_detector.is_valid(), + ), ( ManifestClass::General, - general_transaction_detector.is_valid(), + general_transaction_detector.is_valid() + && !general_non_enclosed_transaction_detector.is_valid(), ), ( ManifestClass::Transfer, @@ -145,6 +154,8 @@ pub fn statically_analyze_and_validate( let mut account_resource_movements_detector = StaticAccountResourceMovementsDetector::default(); + let mut general_non_enclosed_transaction_detector = + GeneralNonEnclosedDetector::default(); let mut general_transaction_detector = GeneralDetector::default(); let mut transfer_transaction_detector = TransferDetector::default(); let mut pool_contribution_detector = PoolContributionDetector::default(); @@ -164,6 +175,7 @@ pub fn statically_analyze_and_validate( &mut reserved_instructions_detector, &mut account_resource_movements_detector, &mut general_transaction_detector, + &mut general_non_enclosed_transaction_detector, &mut transfer_transaction_detector, &mut pool_contribution_detector, &mut pool_redemption_detector, @@ -184,9 +196,15 @@ pub fn statically_analyze_and_validate( let (account_withdraws, account_deposits) = account_resource_movements_detector.output(); let classification = [ + ( + ManifestClass::GeneralNonEnclosed, + general_non_enclosed_transaction_detector.is_valid() + && !general_transaction_detector.is_valid(), + ), ( ManifestClass::General, - general_transaction_detector.is_valid(), + general_transaction_detector.is_valid() + && !general_non_enclosed_transaction_detector.is_valid(), ), ( ManifestClass::Transfer, @@ -261,6 +279,8 @@ pub fn classify_manifest( let mut account_resource_movements_detector = StaticAccountResourceMovementsDetector::default(); + let mut general_non_enclosed_transaction_detector = + GeneralNonEnclosedDetector::default(); let mut general_transaction_detector = GeneralDetector::default(); let mut transfer_transaction_detector = TransferDetector::default(); let mut pool_contribution_detector = PoolContributionDetector::default(); @@ -279,6 +299,7 @@ pub fn classify_manifest( &mut requiring_auth_detector, &mut reserved_instructions_detector, &mut account_resource_movements_detector, + &mut general_non_enclosed_transaction_detector, &mut general_transaction_detector, &mut transfer_transaction_detector, &mut pool_contribution_detector, @@ -293,9 +314,15 @@ pub fn classify_manifest( // Extracting the data out of the detectors and into the ManifestSummary [ + ( + ManifestClass::GeneralNonEnclosed, + general_non_enclosed_transaction_detector.is_valid() + && !general_transaction_detector.is_valid(), + ), ( ManifestClass::General, - general_transaction_detector.is_valid(), + general_transaction_detector.is_valid() + && !general_non_enclosed_transaction_detector.is_valid(), ), ( ManifestClass::Transfer, @@ -486,17 +513,14 @@ pub fn dynamically_analyze( k, v.into_iter() .map(|(badge, operation)| { - ( - badge, - match operation { - Update::Set(()) => { - Operation::Added - } - Update::Remove => { - Operation::Removed - } - }, - ) + (badge, match operation { + Update::Set(()) => { + Operation::Added + } + Update::Remove => { + Operation::Removed + } + }) }) .collect(), ) diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general.rs index 4738191d..b26fd4f5 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general.rs @@ -154,6 +154,9 @@ impl GeneralDetector { | EntityType::InternalNonFungibleVault | EntityType::InternalKeyValueStore | EntityType::GlobalTransactionTracker + // TODO: Will be a problem once we do MFA and we + // need to allow for creation of proofs from the + // access controller. | EntityType::GlobalAccessController | EntityType::GlobalOneResourcePool | EntityType::GlobalTwoResourcePool diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general_non_enclosed.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general_non_enclosed.rs new file mode 100644 index 00000000..66588477 --- /dev/null +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/types/general_non_enclosed.rs @@ -0,0 +1,178 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use radix_transactions::manifest::*; +use radix_transactions::prelude::*; +use scrypto::prelude::*; + +use radix_engine_interface::blueprints::account::*; + +use crate::transaction_types::*; + +pub struct GeneralNonEnclosedDetector { + is_valid: bool, +} + +impl GeneralNonEnclosedDetector { + pub fn is_valid(&self) -> bool { + self.is_valid + } + + pub fn output(self) -> Option<()> { + if self.is_valid() { Some(()) } else { None } + } +} + +impl StaticAnalysisCallback for GeneralNonEnclosedDetector { + fn on_finish(&mut self, instructions_count: usize) { + if instructions_count == 0 { + self.is_valid = false + } + } + + fn on_instruction(&mut self, instruction: &InstructionV2, _: usize) { + // Control whether or not this is allowed or not based on: + // 1. Whether the instruction is allowed. + // 2. Whether the instruction contents are allowed. + self.is_valid &= match instruction { + /* Maybe Permitted - Need more info */ + InstructionV2::CallMethod(CallMethod { + address, + method_name, + .. + }) => { + Self::construct_fn_rules(address).is_fn_permitted(method_name) + } + /* Permitted */ + InstructionV2::TakeFromWorktop(..) + | InstructionV2::TakeNonFungiblesFromWorktop(..) + | InstructionV2::TakeAllFromWorktop(..) + | InstructionV2::ReturnToWorktop(..) + | InstructionV2::AssertWorktopContainsAny(..) + | InstructionV2::AssertWorktopContains(..) + | InstructionV2::AssertWorktopContainsNonFungibles(..) + | InstructionV2::AssertWorktopResourcesOnly(..) + | InstructionV2::AssertWorktopResourcesInclude(..) + | InstructionV2::AssertNextCallReturnsOnly(..) + | InstructionV2::AssertNextCallReturnsInclude(..) + | InstructionV2::AssertBucketContents(..) + | InstructionV2::PopFromAuthZone(..) + | InstructionV2::PushToAuthZone(..) + | InstructionV2::CreateProofFromAuthZoneOfAmount(..) + | InstructionV2::CreateProofFromAuthZoneOfNonFungibles(..) + | InstructionV2::CreateProofFromAuthZoneOfAll(..) + | InstructionV2::DropAuthZoneProofs(..) + | InstructionV2::DropAuthZoneRegularProofs(..) + | InstructionV2::DropAuthZoneSignatureProofs(..) + | InstructionV2::CreateProofFromBucketOfAmount(..) + | InstructionV2::CreateProofFromBucketOfNonFungibles(..) + | InstructionV2::CreateProofFromBucketOfAll(..) + | InstructionV2::CloneProof(..) + | InstructionV2::DropProof(..) + | InstructionV2::DropNamedProofs(..) + | InstructionV2::DropAllProofs(..) + | InstructionV2::CallFunction(..) + | InstructionV2::YieldToParent(_) + | InstructionV2::YieldToChild(_) + | InstructionV2::VerifyParent(_) => true, + /* Not Permitted */ + InstructionV2::BurnResource(..) + | InstructionV2::CallRoyaltyMethod(..) + | InstructionV2::CallMetadataMethod(..) + | InstructionV2::CallRoleAssignmentMethod(..) + | InstructionV2::CallDirectVaultMethod(..) + | InstructionV2::AllocateGlobalAddress(..) => false, + } + } +} + +impl DynamicAnalysisCallback for GeneralNonEnclosedDetector {} + +impl GeneralNonEnclosedDetector { + fn construct_fn_rules(address: &DynamicGlobalAddress) -> FnRules { + match address { + DynamicGlobalAddress::Named(..) => FnRules::all_disallowed(), + DynamicGlobalAddress::Static(address) => { + address + .as_node_id() + .entity_type() + .map(|entity_type| { + match entity_type { + EntityType::GlobalAccount + | EntityType::GlobalPreallocatedSecp256k1Account + | EntityType::GlobalPreallocatedEd25519Account => { + FnRules { + allowed: &[ + /* All withdraw methods */ + ACCOUNT_WITHDRAW_IDENT, + ACCOUNT_WITHDRAW_NON_FUNGIBLES_IDENT, + /* All deposit methods */ + ACCOUNT_DEPOSIT_IDENT, + ACCOUNT_DEPOSIT_BATCH_IDENT, + ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, + ACCOUNT_TRY_DEPOSIT_BATCH_OR_ABORT_IDENT, + /* All proof creation methods */ + ACCOUNT_CREATE_PROOF_OF_AMOUNT_IDENT, + ACCOUNT_CREATE_PROOF_OF_NON_FUNGIBLES_IDENT, + /* Locking of fees */ + ACCOUNT_LOCK_FEE_IDENT, + ACCOUNT_LOCK_CONTINGENT_FEE_IDENT, + ACCOUNT_LOCK_FEE_AND_WITHDRAW_IDENT, + ACCOUNT_LOCK_FEE_AND_WITHDRAW_NON_FUNGIBLES_IDENT, + ], + disallowed: &[], + default: FnRule::Disallowed, + } + } + EntityType::GlobalGenericComponent + | EntityType::GlobalIdentity + | EntityType::GlobalPreallocatedSecp256k1Identity + | EntityType::GlobalPreallocatedEd25519Identity + | EntityType::InternalGenericComponent + | EntityType::GlobalAccountLocker => FnRules::all_allowed(), + /* Disallowed */ + EntityType::GlobalPackage + | EntityType::GlobalValidator + | EntityType::GlobalFungibleResourceManager + | EntityType::GlobalNonFungibleResourceManager + | EntityType::GlobalConsensusManager + | EntityType::InternalFungibleVault + | EntityType::InternalNonFungibleVault + | EntityType::InternalKeyValueStore + | EntityType::GlobalTransactionTracker + // TODO: Will be a problem once we do MFA and we + // need to allow for creation of proofs from the + // access controller. + | EntityType::GlobalAccessController + | EntityType::GlobalOneResourcePool + | EntityType::GlobalTwoResourcePool + | EntityType::GlobalMultiResourcePool => { + FnRules::all_disallowed() + } + } + }) + .unwrap_or(FnRules::all_disallowed()) + } + } + } +} + +impl Default for GeneralNonEnclosedDetector { + fn default() -> Self { + Self { is_valid: true } + } +} diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/types/mod.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/types/mod.rs index c7365dca..0ee794b6 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/types/mod.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/types/mod.rs @@ -18,6 +18,7 @@ mod account_resource_movements; mod account_settings; mod general; +mod general_non_enclosed; mod pool_contribution; mod pool_redemption; mod transfer; @@ -28,6 +29,7 @@ mod validator_unstake; pub use account_resource_movements::*; pub use account_settings::*; pub use general::*; +pub use general_non_enclosed::*; pub use pool_contribution::*; pub use pool_redemption::*; pub use transfer::*; diff --git a/crates/radix-engine-toolkit/src/transaction_types/types.rs b/crates/radix-engine-toolkit/src/transaction_types/types.rs index 7ba5e500..446c6bf1 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/types.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/types.rs @@ -129,6 +129,9 @@ pub struct DynamicAnalysis { /// are the classes that the Radix Engine Toolkit supports. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum ManifestClass { + /// A general manifest that is not enclosed which means that it belongs to + /// a subintent. + GeneralNonEnclosed, /// A general manifest that involves any amount of arbitrary components /// and packages where nothing more concrete can be said about the manifest /// and its nature. diff --git a/crates/radix-engine-toolkit/tests/manifest.rs b/crates/radix-engine-toolkit/tests/manifest.rs index 34617112..caba6835 100644 --- a/crates/radix-engine-toolkit/tests/manifest.rs +++ b/crates/radix-engine-toolkit/tests/manifest.rs @@ -15,7 +15,11 @@ // specific language governing permissions and limitations // under the License. +use radix_engine_toolkit::functions::transaction_v2::subintent_manifest::statically_analyze_and_validate; +use radix_engine_toolkit::transaction_types::ManifestClass; +use radix_transactions::manifest::{MockBlobProvider, compile_manifest}; use scrypto::prelude::*; +use scrypto_test::prelude::SubintentManifestV2; mod test_data; @@ -70,3 +74,89 @@ fn manifest_can_be_statically_validated() { // Assert assert!(validation_result.is_ok()) } + +#[test] +fn transfer_subintent_has_general_non_enclosed_type() { + // Arrange + let manifest = r#" + CALL_METHOD + Address("account_tdx_2_128rl4glqhuf6gm5vv6769hppt3u35mrrz4mshqc4qjqms45nranynd") + "withdraw" + Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") + Decimal("10"); + TAKE_FROM_WORKTOP + Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") + Decimal("10") + Bucket("bucket"); + CALL_METHOD + Address("account_tdx_2_12yj94f9g3dpn9x36l7wf8tjndp4nt53r5hj8ks8y9mf4ul3fgq7agl") + "try_deposit_or_abort" + Bucket("bucket") + None; + YIELD_TO_PARENT; + "#; + + let manifest = compile_manifest::( + manifest, + &NetworkDefinition::stokenet(), + MockBlobProvider::new(), + ) + .unwrap(); + + // Act + let analysis = statically_analyze_and_validate(&manifest); + + // Assert + assert!( + analysis + .unwrap() + .classification + .contains(&ManifestClass::GeneralNonEnclosed) + ); +} + +#[test] +fn transfer_subintent_with_metadata_update_has_general_non_enclosed_type() { + // Arrange + let manifest = r#" + CALL_METHOD + Address("account_tdx_2_128rl4glqhuf6gm5vv6769hppt3u35mrrz4mshqc4qjqms45nranynd") + "withdraw" + Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") + Decimal("10"); + TAKE_FROM_WORKTOP + Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") + Decimal("10") + Bucket("bucket"); + CALL_METHOD + Address("account_tdx_2_12yj94f9g3dpn9x36l7wf8tjndp4nt53r5hj8ks8y9mf4ul3fgq7agl") + "try_deposit_or_abort" + Bucket("bucket") + None; + SET_METADATA + Address("account_tdx_2_128rl4glqhuf6gm5vv6769hppt3u35mrrz4mshqc4qjqms45nranynd") + "account_type" + Enum<0u8>( + "dapp definition" + ); + YIELD_TO_PARENT; + "#; + + let manifest = compile_manifest::( + manifest, + &NetworkDefinition::stokenet(), + MockBlobProvider::new(), + ) + .unwrap(); + + // Act + let analysis = statically_analyze_and_validate(&manifest); + + // Assert + assert!( + !analysis + .unwrap() + .classification + .contains(&ManifestClass::GeneralNonEnclosed) + ); +} diff --git a/crates/radix-engine-toolkit/tests/transaction_types.rs b/crates/radix-engine-toolkit/tests/transaction_types.rs index 00c03139..c51178e7 100644 --- a/crates/radix-engine-toolkit/tests/transaction_types.rs +++ b/crates/radix-engine-toolkit/tests/transaction_types.rs @@ -21,8 +21,6 @@ use radix_engine_interface::blueprints::account::*; use radix_engine_interface::blueprints::consensus_manager::*; use radix_engine_interface::blueprints::pool::*; use radix_engine_toolkit::transaction_types::*; -use radix_engine_toolkit::utils::network_definition_from_network_id; -use radix_transactions::manifest::{compile, MockBlobProvider}; use radix_transactions::prelude::*; use scrypto_test::prelude::*; @@ -122,27 +120,21 @@ fn lock_fee_still_keeps_the_transfer_classification_but_adds_a_reserved_instruct assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account1]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account2]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::Transfer, ManifestClass::General] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account2 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::Transfer, + ManifestClass::General + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account2 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( &dynamic_analysis.detailed_classification[0], @@ -214,27 +206,21 @@ fn simple_transfer_satisfies_the_transfer_and_general_transaction_types() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account1]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account2]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::Transfer, ManifestClass::General] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account2 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::Transfer, + ManifestClass::General + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account2 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( dynamic_analysis.detailed_classification[0], @@ -309,29 +295,23 @@ fn non_simple_transfer_satisfies_the_transfer_and_general_transaction_types() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account1]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account2]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::Transfer, ManifestClass::General] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account2 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), - ] - } - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::Transfer, + ManifestClass::General + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account2 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( dynamic_analysis.detailed_classification[0], @@ -405,22 +385,16 @@ fn transfers_with_try_deposit_or_refund_are_invalid() { assert_eq!(static_analysis.accounts_deposited_into, indexset![account2]); assert_eq!(static_analysis.classification, indexset![]); - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account2 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account2 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert_eq!(dynamic_analysis.newly_created_non_fungibles.len(), 0); @@ -485,22 +459,16 @@ fn lock_fee_is_recognized_as_a_reserved_instruction1() { assert_eq!(static_analysis.accounts_deposited_into, indexset![account2]); assert_eq!(static_analysis.classification, indexset![]); - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account2 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account2 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert_eq!(dynamic_analysis.newly_created_non_fungibles.len(), 0); @@ -564,22 +532,16 @@ fn lock_fee_is_recognized_as_a_reserved_instruction2() { assert_eq!(static_analysis.accounts_deposited_into, indexset![account2]); assert_eq!(static_analysis.classification, indexset![]); - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account2 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) - ] - } - ); + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account2 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10))) + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert_eq!(dynamic_analysis.newly_created_non_fungibles.len(), 0); @@ -640,20 +602,16 @@ fn faucet_fee_xrd_is_recognized_as_a_general_transaction() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account1]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::General] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::General + ]); assert!(dynamic_analysis.account_withdraws.is_empty()); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10_000))), - ] - } - ); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10_000))), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( dynamic_analysis.detailed_classification[0], @@ -718,20 +676,16 @@ fn account_deposit_is_recognized_as_a_method_that_requires_auth() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account1]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::General] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::General + ]); assert!(dynamic_analysis.account_withdraws.is_empty()); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10_000))), - ] - } - ); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Guaranteed(dec!(10_000))), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( dynamic_analysis.detailed_classification[0], @@ -791,20 +745,16 @@ fn account_deposit_batch_is_recognized_as_a_method_that_requires_auth() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account1]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::General] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::General + ]); assert!(dynamic_analysis.account_withdraws.is_empty()); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Predicted(Predicted { value: dec!(10_000), instruction_index: 1 })), - ] - } - ); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Predicted(Predicted { value: dec!(10_000), instruction_index: 1 })), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( dynamic_analysis.detailed_classification[0], @@ -869,20 +819,16 @@ fn instruction_index_of_predicted_bucket_is_its_creation_instruction() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account1]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::General] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::General + ]); assert!(dynamic_analysis.account_withdraws.is_empty()); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account1 => vec![ - ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Predicted(Predicted { value: dec!(10_000), instruction_index: 1 })), - ] - } - ); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account1 => vec![ + ResourceIndicator::Fungible(XRD, FungibleResourceIndicator::Predicted(Predicted { value: dec!(10_000), instruction_index: 1 })), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert!(matches!( dynamic_analysis.detailed_classification[0], @@ -995,86 +941,79 @@ fn pool_contribution_transactions_are_recognized() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::PoolContribution] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account => vec![ - /* One pool contribution */ - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - /* Two pool contribution */ - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource2, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - /* Multi pool contribution */ - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource2, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource3, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource4, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account => vec![ - /* One Pool Units */ - ResourceIndicator::Fungible( - one_pool_unit, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(100), - instruction_index: 3 - } - ) - ), - /* Two Pool Units */ - ResourceIndicator::Fungible( - two_pool_unit, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(100), - instruction_index: 9 - } - ) - ), - /* Multi Pool Units */ - ResourceIndicator::Fungible( - multi_pool_unit, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(100), - instruction_index: 15 - } - ) - ), - ] - } - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::PoolContribution + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account => vec![ + /* One pool contribution */ + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + /* Two pool contribution */ + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource2, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + /* Multi pool contribution */ + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource2, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource3, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource4, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account => vec![ + /* One Pool Units */ + ResourceIndicator::Fungible( + one_pool_unit, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(100), + instruction_index: 3 + } + ) + ), + /* Two Pool Units */ + ResourceIndicator::Fungible( + two_pool_unit, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(100), + instruction_index: 9 + } + ) + ), + /* Multi Pool Units */ + ResourceIndicator::Fungible( + multi_pool_unit, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(100), + instruction_index: 15 + } + ) + ), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); let [ @@ -1086,43 +1025,39 @@ fn pool_contribution_transactions_are_recognized() { else { panic!("Unexpected contents") }; - assert_eq!( - pool_addresses.clone(), - indexset![one_pool, two_pool, multi_pool,] - ); - assert_eq!( - pool_contributions.clone(), - vec![ - TrackedPoolContribution { - pool_address: one_pool, - contributed_resources: indexmap! { - resource1 => dec!(100) - }, - pool_units_resource_address: one_pool_unit, - pool_units_amount: dec!(100) + assert_eq!(pool_addresses.clone(), indexset![ + one_pool, two_pool, multi_pool, + ]); + assert_eq!(pool_contributions.clone(), vec![ + TrackedPoolContribution { + pool_address: one_pool, + contributed_resources: indexmap! { + resource1 => dec!(100) }, - TrackedPoolContribution { - pool_address: two_pool, - contributed_resources: indexmap! { - resource1 => dec!(100), - resource2 => dec!(100) - }, - pool_units_resource_address: two_pool_unit, - pool_units_amount: dec!(100) + pool_units_resource_address: one_pool_unit, + pool_units_amount: dec!(100) + }, + TrackedPoolContribution { + pool_address: two_pool, + contributed_resources: indexmap! { + resource1 => dec!(100), + resource2 => dec!(100) }, - TrackedPoolContribution { - pool_address: multi_pool, - contributed_resources: indexmap! { - resource1 => dec!(100), - resource2 => dec!(100), - resource3 => dec!(100), - resource4 => dec!(100) - }, - pool_units_resource_address: multi_pool_unit, - pool_units_amount: dec!(100) + pool_units_resource_address: two_pool_unit, + pool_units_amount: dec!(100) + }, + TrackedPoolContribution { + pool_address: multi_pool, + contributed_resources: indexmap! { + resource1 => dec!(100), + resource2 => dec!(100), + resource3 => dec!(100), + resource4 => dec!(100) }, - ] - ); + pool_units_resource_address: multi_pool_unit, + pool_units_amount: dec!(100) + }, + ]); assert_eq!(dynamic_analysis.newly_created_non_fungibles.len(), 0); } @@ -1206,102 +1141,95 @@ fn multi_resource_pool_contribution_with_change_is_correctly_handled() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::PoolContribution] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource2, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource3, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource4, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource2, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource3, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - resource4, - FungibleResourceIndicator::Guaranteed(dec!(50)) - ), - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - multi_pool_unit, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(100), - instruction_index: 5 - } - ) - ), - ResourceIndicator::Fungible( - multi_pool_unit, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(50), - instruction_index: 11 - } - ) - ), - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(50), - instruction_index: 11 - } - ) - ), - ResourceIndicator::Fungible( - resource2, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(50), - instruction_index: 11 - } - ) - ), - ResourceIndicator::Fungible( - resource3, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(50), - instruction_index: 11 - } - ) - ), - ] - } - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::PoolContribution + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource2, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource3, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource4, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource2, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource3, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + resource4, + FungibleResourceIndicator::Guaranteed(dec!(50)) + ), + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + multi_pool_unit, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(100), + instruction_index: 5 + } + ) + ), + ResourceIndicator::Fungible( + multi_pool_unit, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(50), + instruction_index: 11 + } + ) + ), + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(50), + instruction_index: 11 + } + ) + ), + ResourceIndicator::Fungible( + resource2, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(50), + instruction_index: 11 + } + ) + ), + ResourceIndicator::Fungible( + resource3, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(50), + instruction_index: 11 + } + ) + ), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); let [ @@ -1314,33 +1242,30 @@ fn multi_resource_pool_contribution_with_change_is_correctly_handled() { panic!("Unexpected contents") }; assert_eq!(pool_addresses.clone(), indexset![multi_pool,]); - assert_eq!( - pool_contributions.clone(), - vec![ - TrackedPoolContribution { - pool_address: multi_pool, - contributed_resources: indexmap! { - resource1 => dec!(100), - resource2 => dec!(100), - resource3 => dec!(100), - resource4 => dec!(100) - }, - pool_units_resource_address: multi_pool_unit, - pool_units_amount: dec!(100) + assert_eq!(pool_contributions.clone(), vec![ + TrackedPoolContribution { + pool_address: multi_pool, + contributed_resources: indexmap! { + resource1 => dec!(100), + resource2 => dec!(100), + resource3 => dec!(100), + resource4 => dec!(100) }, - TrackedPoolContribution { - pool_address: multi_pool, - contributed_resources: indexmap! { - resource1 => dec!(50), - resource2 => dec!(50), - resource3 => dec!(50), - resource4 => dec!(50) - }, - pool_units_resource_address: multi_pool_unit, - pool_units_amount: dec!(50) - } - ] - ); + pool_units_resource_address: multi_pool_unit, + pool_units_amount: dec!(100) + }, + TrackedPoolContribution { + pool_address: multi_pool, + contributed_resources: indexmap! { + resource1 => dec!(50), + resource2 => dec!(50), + resource3 => dec!(50), + resource4 => dec!(50) + }, + pool_units_resource_address: multi_pool_unit, + pool_units_amount: dec!(50) + } + ]); assert_eq!(dynamic_analysis.newly_created_non_fungibles.len(), 0); } @@ -1405,10 +1330,9 @@ fn pool_redemption_transactions_are_recognized() { .try_deposit_entire_worktop_or_abort(account, None) .build(); ledger - .execute_manifest( - manifest, - vec![NonFungibleGlobalId::from_public_key(&pk)], - ) + .execute_manifest(manifest, vec![NonFungibleGlobalId::from_public_key( + &pk, + )]) .expect_commit_success(); let manifest = ManifestBuilder::new() @@ -1489,74 +1413,67 @@ fn pool_redemption_transactions_are_recognized() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::PoolRedemption] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - one_pool_unit, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - two_pool_unit, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - multi_pool_unit, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account => vec![ - /* One pool contribution */ - ResourceIndicator::Fungible( - resource1, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(300), - instruction_index: 9 - } - ) - ), - ResourceIndicator::Fungible( - resource2, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(200), - instruction_index: 9 - } - ) - ), - ResourceIndicator::Fungible( - resource3, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(100), - instruction_index: 9 - } - ) - ), - ResourceIndicator::Fungible( - resource4, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(100), - instruction_index: 9 - } - ) - ), - ] - } - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::PoolRedemption + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + one_pool_unit, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + two_pool_unit, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + multi_pool_unit, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account => vec![ + /* One pool contribution */ + ResourceIndicator::Fungible( + resource1, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(300), + instruction_index: 9 + } + ) + ), + ResourceIndicator::Fungible( + resource2, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(200), + instruction_index: 9 + } + ) + ), + ResourceIndicator::Fungible( + resource3, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(100), + instruction_index: 9 + } + ) + ), + ResourceIndicator::Fungible( + resource4, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(100), + instruction_index: 9 + } + ) + ), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); let [ @@ -1568,43 +1485,39 @@ fn pool_redemption_transactions_are_recognized() { else { panic!("Unexpected contents") }; - assert_eq!( - pool_addresses.clone(), - indexset![one_pool, two_pool, multi_pool,] - ); - assert_eq!( - pool_redemptions.clone(), - vec![ - TrackedPoolRedemption { - pool_address: one_pool, - redeemed_resources: indexmap! { - resource1 => dec!(100) - }, - pool_units_resource_address: one_pool_unit, - pool_units_amount: dec!(100) + assert_eq!(pool_addresses.clone(), indexset![ + one_pool, two_pool, multi_pool, + ]); + assert_eq!(pool_redemptions.clone(), vec![ + TrackedPoolRedemption { + pool_address: one_pool, + redeemed_resources: indexmap! { + resource1 => dec!(100) }, - TrackedPoolRedemption { - pool_address: two_pool, - redeemed_resources: indexmap! { - resource1 => dec!(100), - resource2 => dec!(100) - }, - pool_units_resource_address: two_pool_unit, - pool_units_amount: dec!(100) + pool_units_resource_address: one_pool_unit, + pool_units_amount: dec!(100) + }, + TrackedPoolRedemption { + pool_address: two_pool, + redeemed_resources: indexmap! { + resource1 => dec!(100), + resource2 => dec!(100) }, - TrackedPoolRedemption { - pool_address: multi_pool, - redeemed_resources: indexmap! { - resource1 => dec!(100), - resource2 => dec!(100), - resource3 => dec!(100), - resource4 => dec!(100) - }, - pool_units_resource_address: multi_pool_unit, - pool_units_amount: dec!(100) + pool_units_resource_address: two_pool_unit, + pool_units_amount: dec!(100) + }, + TrackedPoolRedemption { + pool_address: multi_pool, + redeemed_resources: indexmap! { + resource1 => dec!(100), + resource2 => dec!(100), + resource3 => dec!(100), + resource4 => dec!(100) }, - ] - ); + pool_units_resource_address: multi_pool_unit, + pool_units_amount: dec!(100) + }, + ]); assert_eq!(dynamic_analysis.newly_created_non_fungibles.len(), 0); } @@ -1670,41 +1583,34 @@ fn validator_stake_transactions_are_recognized() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::ValidatorStake] - ); - - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - XRD, - FungibleResourceIndicator::Guaranteed(dec!(200)) + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::ValidatorStake + ]); + + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + XRD, + FungibleResourceIndicator::Guaranteed(dec!(200)) + ) + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + stake_unit1, + FungibleResourceIndicator::Predicted( + Predicted { value: dec!(100), instruction_index: 5 } ) - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - stake_unit1, - FungibleResourceIndicator::Predicted( - Predicted { value: dec!(100), instruction_index: 5 } - ) - ), - ResourceIndicator::Fungible( - stake_unit2, - FungibleResourceIndicator::Predicted( - Predicted { value: dec!(100), instruction_index: 5 } - ) - ), - ] - } - ); + ), + ResourceIndicator::Fungible( + stake_unit2, + FungibleResourceIndicator::Predicted( + Predicted { value: dec!(100), instruction_index: 5 } + ) + ), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert_eq!( dynamic_analysis.detailed_classification[0], @@ -1810,10 +1716,9 @@ fn validator_unstake_transactions_are_recognized() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::ValidatorUnstake] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::ValidatorUnstake + ]); let nf_id_local_1 = NonFungibleLocalId::from_str( "{9da60161aa56f3dc-b05ee091e6e496eb-926b11ceb384a4cb-16af5319924a3426}", @@ -1824,58 +1729,52 @@ fn validator_unstake_transactions_are_recognized() { ) .unwrap(); - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - stake_unit1, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ResourceIndicator::Fungible( - stake_unit2, - FungibleResourceIndicator::Guaranteed(dec!(100)) - ), - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account => vec![ - ResourceIndicator::NonFungible( - claim_nft1, - NonFungibleResourceIndicator::ByAll { - predicted_amount: Predicted { - value: dec!(1), - instruction_index: 6 - }, - predicted_ids: Predicted { - value: indexset![ - nf_id_local_1.clone() - ], - instruction_index: 6 - }, - } - ), - ResourceIndicator::NonFungible( - claim_nft2, - NonFungibleResourceIndicator::ByAll { - predicted_amount: Predicted { - value: dec!(1), - instruction_index: 6 - }, - predicted_ids: Predicted { - value: indexset![ - nf_id_local_2.clone() - ], - instruction_index: 6 - }, - } - ), - ] - } - ); + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + stake_unit1, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ResourceIndicator::Fungible( + stake_unit2, + FungibleResourceIndicator::Guaranteed(dec!(100)) + ), + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account => vec![ + ResourceIndicator::NonFungible( + claim_nft1, + NonFungibleResourceIndicator::ByAll { + predicted_amount: Predicted { + value: dec!(1), + instruction_index: 6 + }, + predicted_ids: Predicted { + value: indexset![ + nf_id_local_1.clone() + ], + instruction_index: 6 + }, + } + ), + ResourceIndicator::NonFungible( + claim_nft2, + NonFungibleResourceIndicator::ByAll { + predicted_amount: Predicted { + value: dec!(1), + instruction_index: 6 + }, + predicted_ids: Predicted { + value: indexset![ + nf_id_local_2.clone() + ], + instruction_index: 6 + }, + } + ), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert_eq!( dynamic_analysis.detailed_classification[0], @@ -2040,10 +1939,9 @@ fn validator_claim_transactions_are_recognized() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![account]); assert_eq!(static_analysis.accounts_deposited_into, indexset![account]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::ValidatorClaim] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::ValidatorClaim + ]); let nf_id_local_1 = NonFungibleLocalId::from_str( "{88187e7fec84a59c-9713f20d4bdd245a-90c9c04347db595f-07a038d384ce12a4}", @@ -2054,53 +1952,47 @@ fn validator_claim_transactions_are_recognized() { ) .unwrap(); - assert_eq!( - dynamic_analysis.account_withdraws, - indexmap! { - account => vec![ - ResourceIndicator::NonFungible( - claim_nft1, - NonFungibleResourceIndicator::ByAmount { - amount: dec!(1), - predicted_ids: Predicted { - value: indexset![ - nf_id_local_1.clone() - ], - instruction_index: 0 - }, - } - ), - ResourceIndicator::NonFungible( - claim_nft2, - NonFungibleResourceIndicator::ByAmount { - amount: dec!(1), - predicted_ids: Predicted { - value: indexset![ - nf_id_local_2.clone() - ], - instruction_index: 1 - }, + assert_eq!(dynamic_analysis.account_withdraws, indexmap! { + account => vec![ + ResourceIndicator::NonFungible( + claim_nft1, + NonFungibleResourceIndicator::ByAmount { + amount: dec!(1), + predicted_ids: Predicted { + value: indexset![ + nf_id_local_1.clone() + ], + instruction_index: 0 + }, + } + ), + ResourceIndicator::NonFungible( + claim_nft2, + NonFungibleResourceIndicator::ByAmount { + amount: dec!(1), + predicted_ids: Predicted { + value: indexset![ + nf_id_local_2.clone() + ], + instruction_index: 1 + }, + } + ), + ] + }); + assert_eq!(dynamic_analysis.account_deposits, indexmap! { + account => vec![ + ResourceIndicator::Fungible( + XRD, + FungibleResourceIndicator::Predicted( + Predicted { + value: dec!(200), + instruction_index: 6 } - ), - ] - } - ); - assert_eq!( - dynamic_analysis.account_deposits, - indexmap! { - account => vec![ - ResourceIndicator::Fungible( - XRD, - FungibleResourceIndicator::Predicted( - Predicted { - value: dec!(200), - instruction_index: 6 - } - ) - ), - ] - } - ); + ) + ), + ] + }); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); assert_eq!( dynamic_analysis.detailed_classification[0], @@ -2235,10 +2127,9 @@ fn account_deposit_settings_changes_are_recognized() { assert_eq!(static_analysis.accounts_withdrawn_from, indexset![]); assert_eq!(static_analysis.accounts_deposited_into, indexset![]); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::AccountDepositSettingsUpdate] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::AccountDepositSettingsUpdate + ]); assert!(dynamic_analysis.account_withdraws.is_empty()); assert!(dynamic_analysis.account_deposits.is_empty()); assert_eq!(dynamic_analysis.new_entities, NewEntities::default()); @@ -2335,37 +2226,23 @@ fn presented_proofs_non_fungible() { //Act let manifest = ManifestBuilder::new() .lock_fee_from_faucet() - .create_proof_from_account_of_non_fungibles( - account_1, - address_1, - [NonFungibleLocalId::integer(1)], - ) - .create_proof_from_account_of_non_fungibles( - account_1, - address_2, - [NonFungibleLocalId::integer(3)], - ) - .create_proof_from_account_of_non_fungibles( - account_2, - address_3, - [ - NonFungibleLocalId::integer(2), - NonFungibleLocalId::integer(3), - ], - ) - .create_proof_from_account_of_non_fungibles( - account_1, - address_1, - [ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2), - ], - ) - .create_proof_from_account_of_non_fungibles( - account_2, - address_3, - [NonFungibleLocalId::integer(2)], - ) + .create_proof_from_account_of_non_fungibles(account_1, address_1, [ + NonFungibleLocalId::integer(1), + ]) + .create_proof_from_account_of_non_fungibles(account_1, address_2, [ + NonFungibleLocalId::integer(3), + ]) + .create_proof_from_account_of_non_fungibles(account_2, address_3, [ + NonFungibleLocalId::integer(2), + NonFungibleLocalId::integer(3), + ]) + .create_proof_from_account_of_non_fungibles(account_1, address_1, [ + NonFungibleLocalId::integer(1), + NonFungibleLocalId::integer(2), + ]) + .create_proof_from_account_of_non_fungibles(account_2, address_3, [ + NonFungibleLocalId::integer(2), + ]) .build(); let (static_analysis, _) = ledger.summarize(manifest); @@ -2577,10 +2454,9 @@ fn account_locker_is_recognized_as_general_transaction() { dynamic_analysis.detailed_classification.len(), 1 ); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::General] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::General + ]); assert_eq_three!( static_analysis.presented_proofs.len(), dynamic_analysis.presented_proofs.len(), @@ -2645,8 +2521,7 @@ fn lock_fee_manifest_has_no_classification_except_general() { dynamic_analysis.detailed_classification.len(), 1 ); - assert_eq!( - static_analysis.classification, - indexset![ManifestClass::General] - ); + assert_eq!(static_analysis.classification, indexset![ + ManifestClass::General + ]); }