From 53adbeac673d3d66500e53641dd397105c686d00 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Wed, 19 Jun 2024 16:22:42 +0530 Subject: [PATCH] pallet/asset: Add tests for AssetIdNotFound Signed-off-by: Adi Bhagavath --- pallets/asset/src/tests.rs | 1055 +++++++++++++++++++++++++++--------- 1 file changed, 792 insertions(+), 263 deletions(-) diff --git a/pallets/asset/src/tests.rs b/pallets/asset/src/tests.rs index 1e417fb9..e5186068 100644 --- a/pallets/asset/src/tests.rs +++ b/pallets/asset/src/tests.rs @@ -1,33 +1,32 @@ use super::*; use crate::mock::*; use codec::Encode; -use cord_utilities::mock::{mock_origin::DoubleOrigin, SubjectId}; -use frame_support::{assert_err, assert_ok, BoundedVec}; +use cord_utilities::mock::{ mock_origin::DoubleOrigin, SubjectId }; +use frame_support::{ assert_err, assert_ok, BoundedVec }; use frame_system::RawOrigin; -use pallet_chain_space::{SpaceCodeOf, SpaceIdOf}; -use sp_runtime::{traits::Hash, AccountId32}; +use pallet_chain_space::{ SpaceCodeOf, SpaceIdOf }; +use sp_runtime::{ traits::Hash, AccountId32 }; use sp_std::prelude::*; +// use crate::Error; /// Generates a space ID from a digest. pub fn generate_space_id(digest: &SpaceCodeOf) -> SpaceIdOf { - Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Space).unwrap() + Ss58Identifier::create_identifier(&digest.encode()[..], IdentifierType::Space).unwrap() } /// Generates an authorization ID from a digest. pub fn generate_authorization_id(digest: &SpaceCodeOf) -> AuthorizationIdOf { - Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Authorization) - .unwrap() + Ss58Identifier::create_identifier(&digest.encode()[..], IdentifierType::Authorization).unwrap() } /// Generates a asset ID from a digest. pub fn generate_asset_id(digest: &SpaceCodeOf) -> AssetIdOf { - Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Asset).unwrap() + Ss58Identifier::create_identifier(&digest.encode()[..], IdentifierType::Asset).unwrap() } /// Generates a asset instance ID from a digest pub fn generate_asset_instance_id(digest: &SpaceCodeOf) -> AssetInstanceIdOf { - Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::AssetInstance) - .unwrap() + Ss58Identifier::create_identifier(&digest.encode()[..], IdentifierType::AssetInstance).unwrap() } pub(crate) const DID_00: SubjectId = SubjectId(AccountId32::new([1u8; 32])); @@ -43,12 +42,12 @@ fn asset_create_should_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -71,19 +70,13 @@ fn asset_create_should_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - entry, - digest, - authorization_id - )); + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id) + ); }); } @@ -96,12 +89,12 @@ fn asset_issue_should_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -125,7 +118,7 @@ fn asset_issue_should_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -136,30 +129,25 @@ fn asset_issue_should_succeed() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - entry, - digest, - authorization_id.clone() - )); - - assert_ok!(Asset::issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); + + assert_ok!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); }); } @@ -172,12 +160,12 @@ fn asset_vc_create_should_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -200,19 +188,13 @@ fn asset_vc_create_should_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id - )); + assert_ok!( + Asset::vc_create(DoubleOrigin(author.clone(), creator.clone()).into(), asset_qty, digest, authorization_id) + ); }); } @@ -225,12 +207,12 @@ fn asset_vc_issue_should_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -254,7 +236,7 @@ fn asset_vc_issue_should_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -265,30 +247,30 @@ fn asset_vc_issue_should_succeed() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id.clone() - )); - - assert_ok!(Asset::vc_issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); + + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); }); } @@ -303,12 +285,12 @@ fn asset_vc_transfer_should_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -332,7 +314,7 @@ fn asset_vc_transfer_should_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -343,8 +325,7 @@ fn asset_vc_transfer_should_succeed() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); let instance_id_digest = ::Hashing::hash( &[ @@ -353,8 +334,7 @@ fn asset_vc_transfer_should_succeed() { &space_id.encode()[..], &creator.encode()[..], &issue_entry_digest.encode()[..], - ] - .concat()[..], + ].concat()[..] ); let instance_id = generate_asset_instance_id::(&instance_id_digest); @@ -366,36 +346,40 @@ fn asset_vc_transfer_should_succeed() { new_asset_owner: new_owner.clone(), }; - let transfer_entry_digest = - ::Hashing::hash(&[&transfer_entry.encode()[..]].concat()[..]); + let transfer_entry_digest = ::Hashing::hash( + &[&transfer_entry.encode()[..]].concat()[..] + ); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id.clone() - )); - - assert_ok!(Asset::vc_issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); - - assert_ok!(Asset::vc_transfer( - DoubleOrigin(author.clone(), creator.clone()).into(), - transfer_entry.clone(), - transfer_entry_digest, - )); + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); + + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); + + assert_ok!( + Asset::vc_transfer( + DoubleOrigin(author.clone(), creator.clone()).into(), + transfer_entry.clone(), + transfer_entry_digest + ) + ); }); } @@ -409,12 +393,12 @@ fn asset_vc_status_change_should_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -438,7 +422,7 @@ fn asset_vc_status_change_should_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -449,8 +433,7 @@ fn asset_vc_status_change_should_succeed() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); let instance_id_digest = ::Hashing::hash( &[ @@ -459,40 +442,42 @@ fn asset_vc_status_change_should_succeed() { &space_id.encode()[..], &creator.encode()[..], &issue_entry_digest.encode()[..], - ] - .concat()[..], + ].concat()[..] ); let instance_id = generate_asset_instance_id::(&instance_id_digest); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id.clone() - )); - - assert_ok!(Asset::vc_issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); - - assert_ok!(Asset::vc_status_change( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_id.clone(), - Some(instance_id.clone()), - AssetStatusOf::INACTIVE - )); + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); + + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); + + assert_ok!( + Asset::vc_status_change( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_id.clone(), + Some(instance_id.clone()), + AssetStatusOf::INACTIVE + ) + ); }); } @@ -507,12 +492,12 @@ fn changing_status_of_asset_instance_with_same_status_should_fail() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -536,7 +521,7 @@ fn changing_status_of_asset_instance_with_same_status_should_fail() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -547,8 +532,7 @@ fn changing_status_of_asset_instance_with_same_status_should_fail() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); let instance_id_digest = ::Hashing::hash( &[ @@ -557,34 +541,29 @@ fn changing_status_of_asset_instance_with_same_status_should_fail() { &space_id.encode()[..], &creator.encode()[..], &issue_entry_digest.encode()[..], - ] - .concat()[..], + ].concat()[..] ); let instance_id = generate_asset_instance_id::(&instance_id_digest); new_test_ext().execute_with(|| { // Create space and asset - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - entry, - digest, - authorization_id.clone() - )); + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); - assert_ok!(Asset::issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); + assert_ok!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); // Call status_change with the same status as the current asset status assert_err!( @@ -592,7 +571,7 @@ fn changing_status_of_asset_instance_with_same_status_should_fail() { DoubleOrigin(author.clone(), creator.clone()).into(), asset_id, Some(instance_id), - AssetStatusOf::ACTIVE, + AssetStatusOf::ACTIVE ), Error::::AssetInSameState ); @@ -609,12 +588,12 @@ fn changing_status_of_vc_asset_instance_with_same_status_should_fail() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -638,7 +617,7 @@ fn changing_status_of_vc_asset_instance_with_same_status_should_fail() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -649,8 +628,7 @@ fn changing_status_of_vc_asset_instance_with_same_status_should_fail() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); let instance_id_digest = ::Hashing::hash( &[ @@ -659,33 +637,33 @@ fn changing_status_of_vc_asset_instance_with_same_status_should_fail() { &space_id.encode()[..], &creator.encode()[..], &issue_entry_digest.encode()[..], - ] - .concat()[..], + ].concat()[..] ); let instance_id = generate_asset_instance_id::(&instance_id_digest); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id.clone() - )); + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); - assert_ok!(Asset::vc_issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); assert_err!( Asset::vc_status_change( @@ -710,12 +688,12 @@ fn changing_status_of_asset_with_same_status_should_fail() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -739,7 +717,7 @@ fn changing_status_of_asset_with_same_status_should_fail() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -750,31 +728,26 @@ fn changing_status_of_asset_with_same_status_should_fail() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { // Create space and asset - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - entry, - digest, - authorization_id.clone() - )); + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); - assert_ok!(Asset::issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); + assert_ok!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); // Call status_change with the same status as the current asset status assert_err!( @@ -782,7 +755,7 @@ fn changing_status_of_asset_with_same_status_should_fail() { DoubleOrigin(author.clone(), creator.clone()).into(), asset_id, None, - AssetStatusOf::ACTIVE, + AssetStatusOf::ACTIVE ), Error::::AssetInSameState ); @@ -799,12 +772,12 @@ fn changing_status_of_vc_asset_with_same_status_should_fail() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -828,7 +801,7 @@ fn changing_status_of_vc_asset_with_same_status_should_fail() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -839,30 +812,30 @@ fn changing_status_of_vc_asset_with_same_status_should_fail() { asset_issuance_qty: Some(10), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id.clone() - )); + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); - assert_ok!(Asset::vc_issue( - DoubleOrigin(author.clone(), creator.clone()).into(), - issue_entry.clone(), - issue_entry_digest, - authorization_id - )); + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); assert_err!( Asset::vc_status_change( @@ -885,12 +858,12 @@ fn asset_over_issuance_should_not_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -914,7 +887,7 @@ fn asset_over_issuance_should_not_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -925,23 +898,16 @@ fn asset_over_issuance_should_not_succeed() { asset_issuance_qty: Some(20), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - entry, - digest, - authorization_id.clone() - )); + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); assert_err!( Asset::issue( @@ -965,12 +931,12 @@ fn asset_over_issuance_vc_status_change_should_not_succeed() { let raw_space = [2u8; 256].to_vec(); let space_digest = ::Hashing::hash(&raw_space.encode()[..]); let space_id_digest = ::Hashing::hash( - &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] ); let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); let auth_digest = ::Hashing::hash( - &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); @@ -994,7 +960,7 @@ fn asset_over_issuance_vc_status_change_should_not_succeed() { let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); let issue_id_digest = ::Hashing::hash( - &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..], + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] ); let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); @@ -1005,8 +971,7 @@ fn asset_over_issuance_vc_status_change_should_not_succeed() { asset_issuance_qty: Some(30), }; - let issue_entry_digest = - ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); let instance_id_digest = ::Hashing::hash( &[ @@ -1015,26 +980,24 @@ fn asset_over_issuance_vc_status_change_should_not_succeed() { &space_id.encode()[..], &creator.encode()[..], &issue_entry_digest.encode()[..], - ] - .concat()[..], + ].concat()[..] ); let instance_id = generate_asset_instance_id::(&instance_id_digest); new_test_ext().execute_with(|| { - assert_ok!(Space::create( - DoubleOrigin(author.clone(), creator.clone()).into(), - space_digest, - )); + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); - assert_ok!(Asset::vc_create( - DoubleOrigin(author.clone(), creator.clone()).into(), - asset_qty, - digest, - authorization_id.clone() - )); + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); assert_err!( Asset::vc_issue( @@ -1057,3 +1020,569 @@ fn asset_over_issuance_vc_status_change_should_not_succeed() { ); }); } + +#[test] +fn asset_issue_with_wrong_asset_id_should_fail() { + let creator = DID_00; + let author = ACCOUNT_00; + let capacity = 5u64; + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); + + let wrong_issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let asset_id: Ss58Identifier = generate_asset_id::(&wrong_issue_id_digest); + + let issue_entry = AssetIssuanceEntryOf:: { + asset_id, + asset_owner: creator.clone(), + asset_issuance_qty: Some(10), + }; + + let issue_entry_digest = ::Hashing::hash( + &[&issue_entry.encode()[..]].concat()[..] + ); + + assert_err!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ), + Error::::AssetIdNotFound + ); + }); +} + +#[test] +fn asset_transfer_with_wrong_asset_id_should_fail() { + let creator = DID_00; + let new_owner = DID_01; + let author = ACCOUNT_00; + let capacity = 5u64; + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + let issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); + + let issue_entry = AssetIssuanceEntryOf:: { + asset_id: asset_id.clone(), + asset_owner: creator.clone(), + asset_issuance_qty: Some(10), + }; + + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + + let instance_id_digest = ::Hashing::hash( + &[ + &asset_id.encode()[..], + &creator.encode()[..], + &space_id.encode()[..], + &creator.encode()[..], + &issue_entry_digest.encode()[..], + ].concat()[..] + ); + + let instance_id = generate_asset_instance_id::(&instance_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); + + assert_ok!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); + let wrong_entry_digest = ::Hashing::hash( + &[&issue_entry.encode()[..]].concat()[..] + ); + let asset_id: Ss58Identifier = generate_asset_id::(&wrong_entry_digest); + + let transfer_entry = AssetTransferEntryOf:: { + asset_id: asset_id.clone(), + asset_instance_id: instance_id.clone(), + asset_owner: creator.clone(), + new_asset_owner: new_owner.clone(), + }; + + let transfer_entry_digest = ::Hashing::hash( + &[&transfer_entry.encode()[..]].concat()[..] + ); + + assert_err!( + Asset::transfer( + DoubleOrigin(author.clone(), creator.clone()).into(), + transfer_entry.clone(), + transfer_entry_digest + ), + Error::::AssetIdNotFound + ); + }); +} + +#[test] +fn asset_status_change_with_wrong_asset_id_should_fail() { + let creator = DID_00; + let author = ACCOUNT_00; + let capacity = 5u64; + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + let issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); + + let issue_entry = AssetIssuanceEntryOf:: { + asset_id: asset_id.clone(), + asset_owner: creator.clone(), + asset_issuance_qty: Some(10), + }; + + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + + let instance_id_digest = ::Hashing::hash( + &[ + &asset_id.encode()[..], + &creator.encode()[..], + &space_id.encode()[..], + &creator.encode()[..], + &issue_entry_digest.encode()[..], + ].concat()[..] + ); + + let instance_id = generate_asset_instance_id::(&instance_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_ok!( + Asset::create(DoubleOrigin(author.clone(), creator.clone()).into(), entry, digest, authorization_id.clone()) + ); + + assert_ok!( + Asset::issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); + let wrong_issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let asset_id: Ss58Identifier = generate_asset_id::(&wrong_issue_id_digest); + + assert_err!( + Asset::status_change( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_id.clone(), + Some(instance_id.clone()), + AssetStatusOf::INACTIVE + ), + Error::::AssetIdNotFound + ); + }); +} + +#[test] +fn asset_vc_issue_with_wrong_asset_id_should_fail() { + let creator = DID_00; + let author = ACCOUNT_00; + let capacity = 5u64; + + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); + let wrong_issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let asset_id: Ss58Identifier = generate_asset_id::(&wrong_issue_id_digest); + + let issue_entry = AssetIssuanceEntryOf:: { + asset_id, + asset_owner: creator.clone(), + asset_issuance_qty: Some(10), + }; + + let issue_entry_digest = ::Hashing::hash( + &[&issue_entry.encode()[..]].concat()[..] + ); + + assert_err!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ), + Error::::AssetIdNotFound + ); + }); +} + +#[test] +fn asset_vc_transfer_with_wrong_asset_id_should_fail() { + let creator = DID_00; + let new_owner = DID_01; + + let author = ACCOUNT_00; + let capacity = 5u64; + + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + let issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); + + let issue_entry = AssetIssuanceEntryOf:: { + asset_id: asset_id.clone(), + asset_owner: creator.clone(), + asset_issuance_qty: Some(10), + }; + + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + + let instance_id_digest = ::Hashing::hash( + &[ + &asset_id.encode()[..], + &creator.encode()[..], + &space_id.encode()[..], + &creator.encode()[..], + &issue_entry_digest.encode()[..], + ].concat()[..] + ); + + let instance_id = generate_asset_instance_id::(&instance_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); + + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); + + let wrong_issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let asset_id: Ss58Identifier = generate_asset_id::(&wrong_issue_id_digest); + + let transfer_entry = AssetTransferEntryOf:: { + asset_id: asset_id.clone(), + asset_instance_id: instance_id.clone(), + asset_owner: creator.clone(), + new_asset_owner: new_owner.clone(), + }; + + let transfer_entry_digest = ::Hashing::hash( + &[&transfer_entry.encode()[..]].concat()[..] + ); + + assert_err!( + Asset::vc_transfer( + DoubleOrigin(author.clone(), creator.clone()).into(), + transfer_entry.clone(), + transfer_entry_digest + ), + Error::::AssetIdNotFound + ); + }); +} + +#[test] +fn asset_vc_status_change_with_wrong_asset_id_should_fail() { + let creator = DID_00; + let author = ACCOUNT_00; + + let capacity = 5u64; + + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let authorization_id: Ss58Identifier = generate_authorization_id::(&auth_digest); + + let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap(); + let asset_qty = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + let issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..] + ); + + let asset_id: Ss58Identifier = generate_asset_id::(&issue_id_digest); + + let issue_entry = AssetIssuanceEntryOf:: { + asset_id: asset_id.clone(), + asset_owner: creator.clone(), + asset_issuance_qty: Some(10), + }; + + let issue_entry_digest = ::Hashing::hash(&[&issue_entry.encode()[..]].concat()[..]); + + let instance_id_digest = ::Hashing::hash( + &[ + &asset_id.encode()[..], + &creator.encode()[..], + &space_id.encode()[..], + &creator.encode()[..], + &issue_entry_digest.encode()[..], + ].concat()[..] + ); + + let instance_id = generate_asset_instance_id::(&instance_id_digest); + + new_test_ext().execute_with(|| { + assert_ok!(Space::create(DoubleOrigin(author.clone(), creator.clone()).into(), space_digest)); + + assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity)); + + assert_ok!( + Asset::vc_create( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_qty, + digest, + authorization_id.clone() + ) + ); + + assert_ok!( + Asset::vc_issue( + DoubleOrigin(author.clone(), creator.clone()).into(), + issue_entry.clone(), + issue_entry_digest, + authorization_id + ) + ); + + let wrong_issue_id_digest = ::Hashing::hash( + &[&digest.encode()[..], &creator.encode()[..]].concat()[..] + ); + let asset_id: Ss58Identifier = generate_asset_id::(&wrong_issue_id_digest); + + assert_err!( + Asset::vc_status_change( + DoubleOrigin(author.clone(), creator.clone()).into(), + asset_id.clone(), + Some(instance_id.clone()), + AssetStatusOf::INACTIVE + ), + Error::::AssetIdNotFound + ); + }); +}