From a2fc3dec9e07de6a3732c5d51f45031ea88d7671 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:17:44 +0200 Subject: [PATCH 01/30] ownership chain has pallet evolution --- Cargo.lock | 1 + ownership-chain/runtime/Cargo.toml | 1 + ownership-chain/runtime/src/lib.rs | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b811922c5..f1e304c13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6219,6 +6219,7 @@ dependencies = [ "pallet-evm-living-assets-ownership", "pallet-evm-precompile-modexp", "pallet-evm-precompile-simple", + "pallet-laos-evolution", "pallet-living-assets-ownership", "pallet-session", "pallet-sudo", diff --git a/ownership-chain/runtime/Cargo.toml b/ownership-chain/runtime/Cargo.toml index 1f03d31d4..d52e73903 100644 --- a/ownership-chain/runtime/Cargo.toml +++ b/ownership-chain/runtime/Cargo.toml @@ -54,6 +54,7 @@ sp-transaction-pool = { workspace = true } sp-version = { workspace = true } pallet-living-assets-ownership = { workspace = true } +pallet-laos-evolution = { workspace = true } pallet-evm-living-assets-ownership = { workspace = true } pallet-evm-erc721 = { workspace = true } diff --git a/ownership-chain/runtime/src/lib.rs b/ownership-chain/runtime/src/lib.rs index db2e62f4a..a3c33da37 100644 --- a/ownership-chain/runtime/src/lib.rs +++ b/ownership-chain/runtime/src/lib.rs @@ -479,6 +479,26 @@ impl pallet_living_assets_ownership::Config for Runtime { type AssetIdToInitialOwner = AssetIdToInitialOwner; } +parameter_types! { + /// Max length of the `TokenUri` + pub const MaxTokenUriLength: u32 = 512; +} + +/// Converts [`AccountId`] to [`H160`] +pub struct AccountIdToH160; + +impl sp_runtime::traits::Convert for AccountIdToH160 { + fn convert(account_id: AccountId) -> H160 { + H160(account_id.0) + } +} + +impl pallet_laos_evolution::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AccountIdToH160 = AccountIdToH160; + type MaxTokenUriLength = MaxTokenUriLength; +} + impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -703,6 +723,7 @@ construct_runtime!( // Local pallets LaosLivingAssetsOwnership: pallet_living_assets_ownership = 41, + LaosEvolution: pallet_laos_evolution = 42, // Frontier Ethereum: pallet_ethereum = 50, From 72e554ecadd1cda28ac61bde9c5dbec4577b11c3 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:30:02 +0200 Subject: [PATCH 02/30] using evolution precompiled --- Cargo.lock | 1 + ownership-chain/runtime/Cargo.toml | 1 + ownership-chain/runtime/src/precompiles/mod.rs | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1e304c13..e2fb7499f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6216,6 +6216,7 @@ dependencies = [ "pallet-evm", "pallet-evm-chain-id", "pallet-evm-erc721", + "pallet-evm-laos-evolution", "pallet-evm-living-assets-ownership", "pallet-evm-precompile-modexp", "pallet-evm-precompile-simple", diff --git a/ownership-chain/runtime/Cargo.toml b/ownership-chain/runtime/Cargo.toml index d52e73903..09d055a48 100644 --- a/ownership-chain/runtime/Cargo.toml +++ b/ownership-chain/runtime/Cargo.toml @@ -57,6 +57,7 @@ pallet-living-assets-ownership = { workspace = true } pallet-laos-evolution = { workspace = true } pallet-evm-living-assets-ownership = { workspace = true } pallet-evm-erc721 = { workspace = true } +pallet-evm-laos-evolution = { workspace = true } # Polkadot pallet-xcm = { workspace = true } diff --git a/ownership-chain/runtime/src/precompiles/mod.rs b/ownership-chain/runtime/src/precompiles/mod.rs index 1d0635ff7..72ae5137a 100644 --- a/ownership-chain/runtime/src/precompiles/mod.rs +++ b/ownership-chain/runtime/src/precompiles/mod.rs @@ -8,9 +8,11 @@ use sp_std::marker::PhantomData; use pallet_evm_erc721::Erc721Precompile; use pallet_evm_living_assets_ownership::CollectionManagerPrecompile; +use pallet_evm_laos_evolution::LaosEvolutionPrecompile; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; use pallet_living_assets_ownership::{is_collection_address, BaseURIOf}; +use pallet_laos_evolution::TokenUriOf; use crate::{AccountId, Runtime}; @@ -23,8 +25,8 @@ where pub fn new() -> Self { Self(Default::default()) } - pub fn used_addresses() -> [H160; 7] { - [hash(1), hash(2), hash(3), hash(4), hash(5), hash(1025), hash(1026)] + pub fn used_addresses() -> [H160; 8] { + [hash(1), hash(2), hash(3), hash(4), hash(5), hash(1025), hash(1026), hash(1027)] } } @@ -37,6 +39,13 @@ type LivingAssetsPrecompile = CollectionManagerPrecompile< type Erc721 = Erc721Precompile>; +type LaosEvolution = LaosEvolutionPrecompile< + pallet_evm::IdentityAddressMapping, + AccountId, + TokenUriOf, + pallet_laos_evolution::Pallet, +>; + impl PrecompileSet for FrontierPrecompiles where Runtime: pallet_evm::Config + pallet_living_assets_ownership::Config, @@ -53,6 +62,7 @@ where // a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)), a if a == hash(1025) => Some(ECRecoverPublicKey::execute(handle)), a if a == hash(1026) => Some(LivingAssetsPrecompile::execute(handle)), + a if a == hash(1027) => Some(LaosEvolution::execute(handle)), a if is_collection_address(a) => Some(Erc721::execute(handle)), _ => None, } From d8da80f5c152aedcd54e03ddf8a8c9911ee33b56 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:30:14 +0200 Subject: [PATCH 03/30] fmt --- ownership-chain/runtime/src/precompiles/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ownership-chain/runtime/src/precompiles/mod.rs b/ownership-chain/runtime/src/precompiles/mod.rs index 72ae5137a..a530292a2 100644 --- a/ownership-chain/runtime/src/precompiles/mod.rs +++ b/ownership-chain/runtime/src/precompiles/mod.rs @@ -7,12 +7,12 @@ use sp_core::H160; use sp_std::marker::PhantomData; use pallet_evm_erc721::Erc721Precompile; -use pallet_evm_living_assets_ownership::CollectionManagerPrecompile; use pallet_evm_laos_evolution::LaosEvolutionPrecompile; +use pallet_evm_living_assets_ownership::CollectionManagerPrecompile; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; -use pallet_living_assets_ownership::{is_collection_address, BaseURIOf}; use pallet_laos_evolution::TokenUriOf; +use pallet_living_assets_ownership::{is_collection_address, BaseURIOf}; use crate::{AccountId, Runtime}; From 94d6a2e03e8ffaf192373bfb9e9fb28e589692f8 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:30:40 +0200 Subject: [PATCH 04/30] add test --- ownership-chain/runtime/src/precompiles/test.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ownership-chain/runtime/src/precompiles/test.rs b/ownership-chain/runtime/src/precompiles/test.rs index 1f9d25da6..0da0bd617 100644 --- a/ownership-chain/runtime/src/precompiles/test.rs +++ b/ownership-chain/runtime/src/precompiles/test.rs @@ -24,6 +24,7 @@ fn ethereum_precompiled_addresses_are_precompile() { assert!(is_precompile(hash(4)).unwrap()); assert!(is_precompile(hash(5)).unwrap()); assert!(is_precompile(hash(1026)).unwrap()); + assert!(is_precompile(hash(1027)).unwrap()); assert!(is_precompile(H160::from_str("0xffffffffffffffffffffffff0000000000000005").unwrap()) .unwrap()); } From 13e32c54d7ddc922226b734079e39209ff725e3f Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:38:06 +0200 Subject: [PATCH 05/30] evm evolution precomoile moved to ownership --- Cargo.toml | 3 +-- .../precompile/laos-evolution/Cargo.toml | 0 .../precompile/laos-evolution/contracts/LaosEvolution.sol | 0 .../precompile/laos-evolution/src/lib.rs | 0 .../precompile/laos-evolution/src/tests.rs | 0 5 files changed, 1 insertion(+), 2 deletions(-) rename {evolution-chain => ownership-chain}/precompile/laos-evolution/Cargo.toml (100%) rename {evolution-chain => ownership-chain}/precompile/laos-evolution/contracts/LaosEvolution.sol (100%) rename {evolution-chain => ownership-chain}/precompile/laos-evolution/src/lib.rs (100%) rename {evolution-chain => ownership-chain}/precompile/laos-evolution/src/tests.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 92e9d3dbe..9d62af66c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ members = [ "evolution-chain/node", "evolution-chain/pallets/*", "evolution-chain/primitives", - "evolution-chain/precompile/*", ] [workspace.dependencies] @@ -248,7 +247,7 @@ bp-test-utils = { git = "https://github.com/freeverseio/parity-bridges-common.gi pallet-living-assets-ownership = { path = "./ownership-chain/pallets/living-assets-ownership", default-features = false } pallet-laos-evolution = { path = "./evolution-chain/pallets/laos-evolution", default-features = false } pallet-evm-living-assets-ownership = { path = "./ownership-chain/precompile/living-assets", default-features = false } -pallet-evm-laos-evolution = { path = "./evolution-chain/precompile/laos-evolution", default-features = false } +pallet-evm-laos-evolution = { path = "./ownership-chain/precompile/laos-evolution", default-features = false } pallet-evm-erc721 = { path = "./ownership-chain/precompile/erc721", default-features = false } # Utils diff --git a/evolution-chain/precompile/laos-evolution/Cargo.toml b/ownership-chain/precompile/laos-evolution/Cargo.toml similarity index 100% rename from evolution-chain/precompile/laos-evolution/Cargo.toml rename to ownership-chain/precompile/laos-evolution/Cargo.toml diff --git a/evolution-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol similarity index 100% rename from evolution-chain/precompile/laos-evolution/contracts/LaosEvolution.sol rename to ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol diff --git a/evolution-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs similarity index 100% rename from evolution-chain/precompile/laos-evolution/src/lib.rs rename to ownership-chain/precompile/laos-evolution/src/lib.rs diff --git a/evolution-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs similarity index 100% rename from evolution-chain/precompile/laos-evolution/src/tests.rs rename to ownership-chain/precompile/laos-evolution/src/tests.rs From 33936ed24c897bd60e7fb399d8c78653dba83417 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:40:44 +0200 Subject: [PATCH 06/30] moved evolution pallet to ownership chain --- Cargo.toml | 3 +-- .../pallets/laos-evolution/Cargo.toml | 0 .../pallets/laos-evolution/README.md | 0 .../pallets/laos-evolution/src/lib.rs | 0 .../pallets/laos-evolution/src/mock.rs | 0 .../pallets/laos-evolution/src/tests.rs | 0 .../pallets/laos-evolution/src/traits.rs | 0 .../pallets/laos-evolution/src/types.rs | 0 8 files changed, 1 insertion(+), 2 deletions(-) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/Cargo.toml (100%) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/README.md (100%) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/src/lib.rs (100%) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/src/mock.rs (100%) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/src/tests.rs (100%) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/src/traits.rs (100%) rename {evolution-chain => ownership-chain}/pallets/laos-evolution/src/types.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 9d62af66c..e087412c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ members = [ "bridge/primitives/*", "evolution-chain/runtime", "evolution-chain/node", - "evolution-chain/pallets/*", "evolution-chain/primitives", ] @@ -245,7 +244,7 @@ bp-test-utils = { git = "https://github.com/freeverseio/parity-bridges-common.gi # LAOS pallets pallet-living-assets-ownership = { path = "./ownership-chain/pallets/living-assets-ownership", default-features = false } -pallet-laos-evolution = { path = "./evolution-chain/pallets/laos-evolution", default-features = false } +pallet-laos-evolution = { path = "./ownership-chain/pallets/laos-evolution", default-features = false } pallet-evm-living-assets-ownership = { path = "./ownership-chain/precompile/living-assets", default-features = false } pallet-evm-laos-evolution = { path = "./ownership-chain/precompile/laos-evolution", default-features = false } pallet-evm-erc721 = { path = "./ownership-chain/precompile/erc721", default-features = false } diff --git a/evolution-chain/pallets/laos-evolution/Cargo.toml b/ownership-chain/pallets/laos-evolution/Cargo.toml similarity index 100% rename from evolution-chain/pallets/laos-evolution/Cargo.toml rename to ownership-chain/pallets/laos-evolution/Cargo.toml diff --git a/evolution-chain/pallets/laos-evolution/README.md b/ownership-chain/pallets/laos-evolution/README.md similarity index 100% rename from evolution-chain/pallets/laos-evolution/README.md rename to ownership-chain/pallets/laos-evolution/README.md diff --git a/evolution-chain/pallets/laos-evolution/src/lib.rs b/ownership-chain/pallets/laos-evolution/src/lib.rs similarity index 100% rename from evolution-chain/pallets/laos-evolution/src/lib.rs rename to ownership-chain/pallets/laos-evolution/src/lib.rs diff --git a/evolution-chain/pallets/laos-evolution/src/mock.rs b/ownership-chain/pallets/laos-evolution/src/mock.rs similarity index 100% rename from evolution-chain/pallets/laos-evolution/src/mock.rs rename to ownership-chain/pallets/laos-evolution/src/mock.rs diff --git a/evolution-chain/pallets/laos-evolution/src/tests.rs b/ownership-chain/pallets/laos-evolution/src/tests.rs similarity index 100% rename from evolution-chain/pallets/laos-evolution/src/tests.rs rename to ownership-chain/pallets/laos-evolution/src/tests.rs diff --git a/evolution-chain/pallets/laos-evolution/src/traits.rs b/ownership-chain/pallets/laos-evolution/src/traits.rs similarity index 100% rename from evolution-chain/pallets/laos-evolution/src/traits.rs rename to ownership-chain/pallets/laos-evolution/src/traits.rs diff --git a/evolution-chain/pallets/laos-evolution/src/types.rs b/ownership-chain/pallets/laos-evolution/src/types.rs similarity index 100% rename from evolution-chain/pallets/laos-evolution/src/types.rs rename to ownership-chain/pallets/laos-evolution/src/types.rs From 4e8ce8a856563ad6e2e552227ea6d1837e689ee6 Mon Sep 17 00:00:00 2001 From: magecnion Date: Thu, 26 Oct 2023 15:57:16 +0200 Subject: [PATCH 07/30] add evolve_with_external_uri fn and first test --- .../pallets/laos-evolution/src/lib.rs | 33 +++++++++++++++++++ .../pallets/laos-evolution/src/tests.rs | 23 +++++++++++++ .../pallets/laos-evolution/src/traits.rs | 8 +++++ 3 files changed, 64 insertions(+) diff --git a/evolution-chain/pallets/laos-evolution/src/lib.rs b/evolution-chain/pallets/laos-evolution/src/lib.rs index 9edaaeeef..01e3cf5de 100644 --- a/evolution-chain/pallets/laos-evolution/src/lib.rs +++ b/evolution-chain/pallets/laos-evolution/src/lib.rs @@ -158,6 +158,39 @@ impl LaosEvolution, TokenUriOf> for Pallet { fn token_uri(collection_id: CollectionId, token_id: TokenId) -> Option> { TokenURI::::get(collection_id, token_id) } + + fn evolve_with_external_uri( + who: AccountIdOf, + collection_id: CollectionId, + token_id: TokenId, + token_uri: TokenUriOf, + ) -> Result<(), DispatchError> { + ensure!( + CollectionOwner::::contains_key(collection_id), + Error::::CollectionDoesNotExist + ); + // ensure!(CollectionOwner::::get(collection_id) == Some(who), Error::::NoPermission); + + // let to_as_h160 = T::AccountIdToH160::convert(to.clone()); + // // compose asset_id from slot and owner + // let token_id = + // slot_and_owner_to_token_id(slot, to_as_h160).ok_or(Error::::SlotOverflow)?; + + // ensure!(TokenURI::::get(collection_id, token_id).is_none(), + // Error::::AlreadyMinted); + + // TokenURI::::insert(collection_id, token_id, token_uri.clone()); + + // Self::deposit_event(Event::MintedWithExternalTokenURI { + // collection_id, + // slot, + // to, + // token_id, + // token_uri, + // }); + + Ok(()) + } } /// Converts `Slot` and `H160` to `TokenId` diff --git a/evolution-chain/pallets/laos-evolution/src/tests.rs b/evolution-chain/pallets/laos-evolution/src/tests.rs index 91fb0df7b..dbd733aeb 100644 --- a/evolution-chain/pallets/laos-evolution/src/tests.rs +++ b/evolution-chain/pallets/laos-evolution/src/tests.rs @@ -306,3 +306,26 @@ fn token_uri_of_existent_token_returns_correct_token_uri() { assert_eq!(LaosEvolution::token_uri(collection_id, token_id), Some(token_uri)); }); } + +#[test] +// collectionId does not exist +fn evolve_with_external_uri_with_unexistent_collection_id_should_fail() { + new_test_ext().execute_with(|| { + let who = AccountId::from_str(ALICE).unwrap(); + let collection_id = LaosEvolution::collection_counter(); + let slot = 0; + let owner = AccountId::from_str(ALICE).unwrap(); + let token_id = slot_and_owner_to_token_id(slot, owner).unwrap(); + let new_token_uri: TokenUriOf = + vec![1, MaxTokenUriLength::get() as u8].try_into().unwrap(); + + assert_noop!( + LaosEvolution::evolve_with_external_uri(who, collection_id, token_id, new_token_uri), + Error::::CollectionDoesNotExist + ); + }); +} +// msg.sender != collectionOwner, +// asset is not already created +// tokenURI.length > 1 KB +// event is emitted diff --git a/evolution-chain/pallets/laos-evolution/src/traits.rs b/evolution-chain/pallets/laos-evolution/src/traits.rs index affea4c5e..e1ca39b0c 100644 --- a/evolution-chain/pallets/laos-evolution/src/traits.rs +++ b/evolution-chain/pallets/laos-evolution/src/traits.rs @@ -22,4 +22,12 @@ pub trait LaosEvolution { /// Get token URI of a token in a collection fn token_uri(collection_id: CollectionId, token_id: TokenId) -> Option; + + /// Evolve token with external URI + fn evolve_with_external_uri( + who: AccountId, + collection_id: CollectionId, + token_id: TokenId, + token_uri: TokenUri, + ) -> Result<(), DispatchError>; } From 679fdc63f36a193ad7c17cd2400486936bfd4b55 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 26 Oct 2023 15:57:24 +0200 Subject: [PATCH 08/30] fix clippy --- ownership-chain/runtime/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ownership-chain/runtime/Cargo.toml b/ownership-chain/runtime/Cargo.toml index 09d055a48..72715dd5f 100644 --- a/ownership-chain/runtime/Cargo.toml +++ b/ownership-chain/runtime/Cargo.toml @@ -132,6 +132,7 @@ std = [ "pallet-session/std", "pallet-sudo/std", "pallet-living-assets-ownership/std", + "pallet-laos-evolution/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", @@ -164,6 +165,7 @@ std = [ "pallet-ethereum/std", "pallet-evm/std", "pallet-evm-erc721/std", + "pallet-evm-laos-evolution/std", "pallet-evm-chain-id/std", "pallet-evm-precompile-modexp/std", "pallet-evm-precompile-simple/std", @@ -190,6 +192,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-living-assets-ownership/runtime-benchmarks", + "pallet-laos-evolution/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", @@ -224,6 +227,7 @@ try-runtime = [ "pallet-session/try-runtime", "pallet-sudo/try-runtime", "pallet-living-assets-ownership/try-runtime", + "pallet-laos-evolution/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-xcm/try-runtime", From 1c26f4d867c1346f758387e5de02037d7cadc3ac Mon Sep 17 00:00:00 2001 From: magecnion Date: Thu, 26 Oct 2023 16:54:30 +0200 Subject: [PATCH 09/30] finish pallet implementation --- .../pallets/laos-evolution/src/lib.rs | 37 ++++---- .../pallets/laos-evolution/src/tests.rs | 90 +++++++++++++++++-- 2 files changed, 104 insertions(+), 23 deletions(-) diff --git a/evolution-chain/pallets/laos-evolution/src/lib.rs b/evolution-chain/pallets/laos-evolution/src/lib.rs index 01e3cf5de..97c3e50a7 100644 --- a/evolution-chain/pallets/laos-evolution/src/lib.rs +++ b/evolution-chain/pallets/laos-evolution/src/lib.rs @@ -81,6 +81,13 @@ pub mod pallet { token_uri: TokenUriOf, token_id: TokenId, }, + /// Asset evolved + /// [collection_id, token_uri, token_id] + EvolvedWithExternalTokenURI { + collection_id: CollectionId, + token_uri: TokenUriOf, + token_id: TokenId, + }, } // Errors inform users that something went wrong. @@ -95,6 +102,8 @@ pub mod pallet { AlreadyMinted, /// This happens when `Slot` is larger than 96 bits SlotOverflow, + /// Asset does not exist + AssetDoesNotExist, } #[pallet::call] @@ -169,25 +178,19 @@ impl LaosEvolution, TokenUriOf> for Pallet { CollectionOwner::::contains_key(collection_id), Error::::CollectionDoesNotExist ); - // ensure!(CollectionOwner::::get(collection_id) == Some(who), Error::::NoPermission); - - // let to_as_h160 = T::AccountIdToH160::convert(to.clone()); - // // compose asset_id from slot and owner - // let token_id = - // slot_and_owner_to_token_id(slot, to_as_h160).ok_or(Error::::SlotOverflow)?; - - // ensure!(TokenURI::::get(collection_id, token_id).is_none(), - // Error::::AlreadyMinted); + ensure!(CollectionOwner::::get(collection_id) == Some(who), Error::::NoPermission); + ensure!( + TokenURI::::contains_key(collection_id, token_id), + Error::::AssetDoesNotExist + ); - // TokenURI::::insert(collection_id, token_id, token_uri.clone()); + TokenURI::::insert(collection_id, token_id, token_uri.clone()); - // Self::deposit_event(Event::MintedWithExternalTokenURI { - // collection_id, - // slot, - // to, - // token_id, - // token_uri, - // }); + Self::deposit_event(Event::EvolvedWithExternalTokenURI { + collection_id, + token_id, + token_uri, + }); Ok(()) } diff --git a/evolution-chain/pallets/laos-evolution/src/tests.rs b/evolution-chain/pallets/laos-evolution/src/tests.rs index dbd733aeb..b242c3c9c 100644 --- a/evolution-chain/pallets/laos-evolution/src/tests.rs +++ b/evolution-chain/pallets/laos-evolution/src/tests.rs @@ -308,8 +308,7 @@ fn token_uri_of_existent_token_returns_correct_token_uri() { } #[test] -// collectionId does not exist -fn evolve_with_external_uri_with_unexistent_collection_id_should_fail() { +fn evolve_with_external_uri_when_unexistent_collection_id_should_fail() { new_test_ext().execute_with(|| { let who = AccountId::from_str(ALICE).unwrap(); let collection_id = LaosEvolution::collection_counter(); @@ -325,7 +324,86 @@ fn evolve_with_external_uri_with_unexistent_collection_id_should_fail() { ); }); } -// msg.sender != collectionOwner, -// asset is not already created -// tokenURI.length > 1 KB -// event is emitted + +#[test] +fn evolve_with_external_uri_when_sender_is_not_collection_owner_should_fail() { + new_test_ext().execute_with(|| { + let who = AccountId::from_str(ALICE).unwrap(); + let owner = AccountId::from_str(BOB).unwrap(); + let collection_id = create_collection(BOB); + let slot = 0; + let token_id = slot_and_owner_to_token_id(slot, owner).unwrap(); + let new_token_uri: TokenUriOf = + vec![1, MaxTokenUriLength::get() as u8].try_into().unwrap(); + + assert_noop!( + LaosEvolution::evolve_with_external_uri(who, collection_id, token_id, new_token_uri), + Error::::NoPermission + ); + }); +} + +#[test] +fn evolve_with_external_uri_when_asset_doesnt_exist_should_fail() { + new_test_ext().execute_with(|| { + let who = AccountId::from_str(ALICE).unwrap(); + let owner = AccountId::from_str(BOB).unwrap(); + let collection_id = create_collection(ALICE); + let slot = 0; + let token_id = slot_and_owner_to_token_id(slot, owner).unwrap(); + let new_token_uri: TokenUriOf = + vec![1, MaxTokenUriLength::get() as u8].try_into().unwrap(); + + assert_noop!( + LaosEvolution::evolve_with_external_uri(who, collection_id, token_id, new_token_uri), + Error::::AssetDoesNotExist + ); + }); +} + +#[test] +fn evolve_with_external_uri_happy_path() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + + let owner = AccountId::from_str(BOB).unwrap(); + let collection_id = create_collection(BOB); + let slot = 0; + let token_id = slot_and_owner_to_token_id(slot, owner).unwrap(); + let token_uri: TokenUriOf = + vec![1, MaxTokenUriLength::get() as u8].try_into().unwrap(); + let new_token_uri: TokenUriOf = + vec![1, MaxTokenUriLength::get() as u8].try_into().unwrap(); + + assert_ok!(LaosEvolution::mint_with_external_uri( + owner, + collection_id, + slot, + owner, + token_uri.clone() + )); + // token uri is set + assert_eq!(LaosEvolution::token_uri(collection_id, token_id), Some(token_uri.clone())); + + assert_eq!( + LaosEvolution::evolve_with_external_uri( + owner, + collection_id, + token_id, + new_token_uri.clone() + ), + Ok(()) + ); + + // token uri is updated and event is emitted + assert_eq!(LaosEvolution::token_uri(collection_id, token_id), Some(new_token_uri.clone())); + System::assert_has_event( + Event::EvolvedWithExternalTokenURI { + collection_id, + token_id, + token_uri: new_token_uri.clone(), + } + .into(), + ); + }); +} From ad07e9103d5a4023ab2648794a24459dff7a3336 Mon Sep 17 00:00:00 2001 From: magecnion Date: Thu, 26 Oct 2023 17:47:50 +0200 Subject: [PATCH 10/30] WIP add evolve to precompiles --- .../contracts/LaosEvolution.sol | 11 ++ .../precompile/laos-evolution/src/lib.rs | 43 +++++++ .../precompile/laos-evolution/src/tests.rs | 113 +++++++++++++++--- 3 files changed, 152 insertions(+), 15 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index f819ca7b9..1f0f41598 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -58,4 +58,15 @@ interface LaosEvolution { address to, string calldata tokenURI ) external returns (uint256); + + /// @notice Evolve an existing token + /// @dev Call this function to evolve an existing token, the caller must be the owner of the collection + /// @param collectionId the id of the collection + /// @param tokenId the id of the token + /// @param tokenURI the new tokenURI of the token + function evolveWithExternalUri( + uint64 collectionId, + uint256 tokenId, + string calldata tokenURI + ) external returns (uint256); } diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 5cab6296e..719c838fd 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -17,6 +17,8 @@ pub const SELECTOR_LOG_NEW_COLLECTION: [u8; 32] = keccak256!("NewCollection(uint /// Solidity selector of the Transfer log, which is the Keccak of the Log signature. pub const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = keccak256!("MintedWithExternalTokenURI(uint64,uint96,address,string,uint256)"); +pub const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = + keccak256!("EvolvedWithExternalTokenURI(uint64,uint256,string)"); #[precompile_utils_macro::generate_function_selector] #[derive(Debug, PartialEq)] @@ -29,6 +31,8 @@ pub enum Action { TokenURI = "tokenURI(uint64,uint256)", /// Mint token Mint = "mintWithExternalUri(uint64,uint96,address,string)", + /// Evolve token + Evolve = "evolveWithExternalUri(uint64,uint256,string)", } /// Wrapper for the precompile function. @@ -143,6 +147,44 @@ where Err(err) => Err(revert_dispatch_error(err)), } }, + Action::Evolve => { + let caller = context.caller; + + input.expect_arguments(4)?; + + let collection_id = input.read::()?; + let token_id = input.read::()?; + let token_uri_raw = input.read::()?.0; + let token_uri = + token_uri_raw.try_into().map_err(|_| revert("invalid token uri length"))?; + + match LaosEvolution::evolve_with_external_uri( + caller.into(), + collection_id, + token_id, + token_uri, + ) { + Ok(()) => { + let mut token_id_bytes = [0u8; 32]; + token_id.to_big_endian(&mut token_id_bytes); + + Log { + address: context.address, + topics: sp_std::vec![ + H256(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), + H256::from_low_u64_be(collection_id), + H256(token_id_bytes), + H256(token_id_bytes), + ], + data: Vec::new(), + } + .record(handle)?; + + Ok(succeed(EvmDataWriter::new().build())) + }, + Err(err) => Err(revert_dispatch_error(err)), + } + }, } } } @@ -163,6 +205,7 @@ where Action::Mint => FunctionModifier::NonPayable, Action::OwnerOfCollection => FunctionModifier::View, Action::TokenURI => FunctionModifier::View, + Action::Evolve => FunctionModifier::NonPayable, })?; Self::inner_execute(handle, &selector) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 4192fadb5..f8577dcf0 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -47,7 +47,8 @@ fn failing_create_collection_should_return_error() { Err(DispatchError::Other("this is an error")), None, Ok(0.into()), - None + None, + Ok(()) ); let input = EvmDataWriter::new_with_selector(Action::CreateCollection) @@ -65,7 +66,7 @@ fn failing_create_collection_should_return_error() { #[test] fn create_collection_should_return_collection_id() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); let input = EvmDataWriter::new_with_selector(Action::CreateCollection) .write(Address(H160([1u8; 20]))) @@ -78,7 +79,7 @@ fn create_collection_should_return_collection_id() { #[test] fn create_collection_should_generate_log() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); let input = EvmDataWriter::new_with_selector(Action::CreateCollection) .write(Address(H160([1u8; 20]))) @@ -98,7 +99,7 @@ fn create_collection_should_generate_log() { #[test] fn create_collection_on_mock_with_nonzero_value_fails() { - impl_precompile_mock_simple!(Mock, Ok(5), None, Ok(0.into()), None); + impl_precompile_mock_simple!(Mock, Ok(5), None, Ok(0.into()), None, Ok(())); let input = EvmDataWriter::new_with_selector(Action::CreateCollection) .write(Address(H160([1u8; 20]))) @@ -120,7 +121,8 @@ fn create_collection_assign_collection_to_caller() { }, // Closure for create_collection result |_| { None }, // Closure for collection_owner result |_, _, _, _, _| { Ok(0.into()) }, // Closure for mint result - |_, _| { None } // Closure for token_uri result + |_, _| { None }, // Closure for token_uri result + |_, _, _, _| { Ok(()) } // Closure for evolve result ); let input = EvmDataWriter::new_with_selector(Action::CreateCollection) @@ -134,7 +136,7 @@ fn create_collection_assign_collection_to_caller() { #[test] fn call_unexistent_selector_should_fail() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); let nonexistent_selector = hex::decode("fb24ae530000000000000000000000000000000000000000000000000000000000000000") @@ -146,7 +148,7 @@ fn call_unexistent_selector_should_fail() { #[test] fn call_owner_of_non_existent_collection() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); let input = EvmDataWriter::new_with_selector(Action::OwnerOfCollection) .write(U256::from(0)) @@ -163,7 +165,8 @@ fn call_owner_of_collection_works() { Ok(0), Some(H160::from_low_u64_be(0x1234)), Ok(0.into()), - None + None, + Ok(()) ); let owner = H160::from_low_u64_be(0x1234); @@ -179,7 +182,7 @@ fn call_owner_of_collection_works() { #[test] fn token_uri_returns_nothing_when_source_token_uri_is_none() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); let input = EvmDataWriter::new_with_selector(Action::TokenURI) .write(0_u64) @@ -193,7 +196,7 @@ fn token_uri_returns_nothing_when_source_token_uri_is_none() { #[test] fn token_uri_returns_the_result_from_source() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), Some(vec![1_u8, 10])); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), Some(vec![1_u8, 10]), Ok(())); let input = EvmDataWriter::new_with_selector(Action::TokenURI) .write(0_u64) @@ -212,7 +215,8 @@ fn mint_works() { Ok(0), Some(H160::from_low_u64_be(0x1234)), Ok(1.into()), - None + None, + Ok(()) ); let to = H160::from_low_u64_be(1); @@ -237,7 +241,8 @@ fn failing_mint_should_return_error() { Ok(0), Some(H160::from_low_u64_be(0x1234)), Err(DispatchError::Other("this is error")), - None + None, + Ok(()) ); let to = H160::from_low_u64_be(1); @@ -255,6 +260,74 @@ fn failing_mint_should_return_error() { assert_eq!(result, revert("this is error")); } +#[test] +fn evolve_works() { + impl_precompile_mock_simple!( + Mock, + Ok(0), + Some(H160::from_low_u64_be(0x1234)), + Ok(1.into()), + None, + Ok(()) + ); + + let input = EvmDataWriter::new_with_selector(Action::Evolve) + .write(U256::from(0)) + .write(U256::from(1)) + .write(Bytes([1u8; 20].to_vec())) + .build(); + + let mut handle = create_mock_handle_from_input(input); + let result = Mock::execute(&mut handle).unwrap(); + + assert_eq!(result, succeed(EvmDataWriter::new().build())); +} + +#[test] +fn evolve_should_generate_log() { + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); + + let input = EvmDataWriter::new_with_selector(Action::Evolve) + .write(U256::from(0)) + .write(U256::from(1)) + .write(Bytes([1u8; 20].to_vec())) + .build(); + let mut handle = create_mock_handle_from_input(input); + + let result = Mock::execute(&mut handle); + assert!(result.is_ok()); + let logs = handle.logs; + assert_eq!(logs.len(), 1); + assert_eq!(logs[0].address, H160::zero()); + assert_eq!(logs[0].topics.len(), 4); + assert_eq!(logs[0].topics[0], SELECTOR_LOG_NEW_COLLECTION.into()); + assert_eq!(logs[0].topics[1], H256::from_low_u64_be(0)); + assert_eq!(logs[0].data, Vec::::new()); +} + +#[test] +fn evolve_failing_should_return_error() { + impl_precompile_mock_simple!( + Mock, + Ok(0), + Some(H160::from_low_u64_be(0x1234)), + Ok(1.into()), + None, + Err(DispatchError::Other("this is error")) + ); + + let input = EvmDataWriter::new_with_selector(Action::Evolve) + .write(U256::from(0)) + .write(U256::from(1)) + .write(Bytes([1u8; 20].to_vec())) + .build(); + + let mut handle = create_mock_handle_from_input(input); + let result = Mock::execute(&mut handle).unwrap_err(); + + assert_eq!(result, revert("this is error")); +} + mod helpers { /// Macro to define a precompile mock for testing. /// @@ -276,7 +349,7 @@ mod helpers { /// ``` #[macro_export] macro_rules! impl_precompile_mock { - ($name:ident, $create_collection_result:expr, $collection_owner_result:expr, $mint_result:expr, $token_uri_result:expr ) => { + ($name:ident, $create_collection_result:expr, $collection_owner_result:expr, $mint_result:expr, $token_uri_result:expr, $evolve_result:expr ) => { use pallet_laos_evolution::types::*; use sp_runtime::DispatchError; type TokenUri = Vec; @@ -307,6 +380,15 @@ mod helpers { fn token_uri(_collection_id: CollectionId, _token_id: TokenId) -> Option { ($token_uri_result)(_collection_id, _token_id) } + + fn evolve_with_external_uri( + who: AccountId, + collection_id: CollectionId, + token_id: TokenId, + token_uri: TokenUri, + ) -> Result<(), DispatchError> { + ($evolve_result)(who, collection_id, token_id, token_uri) + } } type $name = @@ -332,13 +414,14 @@ mod helpers { /// ``` #[macro_export] macro_rules! impl_precompile_mock_simple { - ($name:ident, $create_collection_result:expr, $collection_owner_result:expr, $mint_result:expr, $token_uri_result:expr) => { + ($name:ident, $create_collection_result:expr, $collection_owner_result:expr, $mint_result:expr, $token_uri_result:expr, $evolve_result:expr) => { impl_precompile_mock!( $name, |_owner| { $create_collection_result }, |_collection_id| { $collection_owner_result }, |_who, _collection_id, _slot, _to, _token_uri| { $mint_result }, - |_collection_id, _token_id| { $token_uri_result } + |_collection_id, _token_id| { $token_uri_result }, + |_who, _collection_id, _token_id, _token_uri| { $evolve_result } ); }; } From 500847030574bf573f154241d866a5a5c4e60d24 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 10:21:06 +0200 Subject: [PATCH 11/30] add MetadataUpdate test --- .../contracts/LaosEvolution.sol | 8 ++++++++ .../precompile/laos-evolution/src/lib.rs | 3 +-- .../precompile/laos-evolution/src/tests.rs | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index 1f0f41598..d4e4efad6 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -26,6 +26,14 @@ interface LaosEvolution { uint256 tokenId ); + /// @notice Emitted when a token metadata is updated + /// @param tokenId the resulting id of the newly minted token + /// @param collectionId the id of the collection + event MetadataUpdate( + uint256 tokenId + uint64 collectionId, + ); + /// @notice Creates a new collection /// @dev Call this function to create a new collection /// @param owner the owner of the newly created collection diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 719c838fd..cbb6a3e6a 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -172,9 +172,8 @@ where address: context.address, topics: sp_std::vec![ H256(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), - H256::from_low_u64_be(collection_id), - H256(token_id_bytes), H256(token_id_bytes), + H256::from_low_u64_be(collection_id), ], data: Vec::new(), } diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index f8577dcf0..996fc9062 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -285,12 +285,16 @@ fn evolve_works() { #[test] fn evolve_should_generate_log() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); // TODO refactor me + + let collection_id = 0; + let token_id = 1; + let token_uri = Bytes([1u8; 20].to_vec()); let input = EvmDataWriter::new_with_selector(Action::Evolve) - .write(U256::from(0)) - .write(U256::from(1)) - .write(Bytes([1u8; 20].to_vec())) + .write(U256::from(collection_id)) + .write(U256::from(token_id)) + .write(token_uri.clone()) .build(); let mut handle = create_mock_handle_from_input(input); @@ -299,9 +303,10 @@ fn evolve_should_generate_log() { let logs = handle.logs; assert_eq!(logs.len(), 1); assert_eq!(logs[0].address, H160::zero()); - assert_eq!(logs[0].topics.len(), 4); - assert_eq!(logs[0].topics[0], SELECTOR_LOG_NEW_COLLECTION.into()); - assert_eq!(logs[0].topics[1], H256::from_low_u64_be(0)); + assert_eq!(logs[0].topics.len(), 3); + assert_eq!(logs[0].topics[0], SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI.into()); + assert_eq!(logs[0].topics[1], H256::from_low_u64_be(token_id)); + assert_eq!(logs[0].topics[2], H256::from_low_u64_be(collection_id)); assert_eq!(logs[0].data, Vec::::new()); } From 20fd0e207fa7d4bc0dca4b9f6550409443ddec1a Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 10:22:30 +0200 Subject: [PATCH 12/30] clean --- ownership-chain/precompile/laos-evolution/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 996fc9062..bed63cdab 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -285,7 +285,7 @@ fn evolve_works() { #[test] fn evolve_should_generate_log() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); // TODO refactor me + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); let collection_id = 0; let token_id = 1; From 0b95bb703a31b62f8019af4986b8762f2606f8e9 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 11:21:30 +0200 Subject: [PATCH 13/30] fix signature fn LaosEvolution.sol file --- .../precompile/laos-evolution/contracts/LaosEvolution.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index d4e4efad6..ba2fa9205 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -30,8 +30,8 @@ interface LaosEvolution { /// @param tokenId the resulting id of the newly minted token /// @param collectionId the id of the collection event MetadataUpdate( - uint256 tokenId - uint64 collectionId, + uint256 tokenId, + uint64 collectionId ); /// @notice Creates a new collection From 98cbece15c4b269181280e1c93989def4a3e7e13 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 12:34:48 +0200 Subject: [PATCH 14/30] add token uri to evolve event --- .../precompile/laos-evolution/contracts/LaosEvolution.sol | 4 +++- ownership-chain/precompile/laos-evolution/src/lib.rs | 7 +++++-- ownership-chain/precompile/laos-evolution/src/tests.rs | 7 ++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index ba2fa9205..b6ebc7aa7 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -29,9 +29,11 @@ interface LaosEvolution { /// @notice Emitted when a token metadata is updated /// @param tokenId the resulting id of the newly minted token /// @param collectionId the id of the collection + /// @param tokenURI the URI of the newly evolved token event MetadataUpdate( uint256 tokenId, - uint64 collectionId + uint64 collectionId, + string tokenURI ); /// @notice Creates a new collection diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index cbb6a3e6a..79ee1c601 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -155,8 +155,10 @@ where let collection_id = input.read::()?; let token_id = input.read::()?; let token_uri_raw = input.read::()?.0; - let token_uri = - token_uri_raw.try_into().map_err(|_| revert("invalid token uri length"))?; + let token_uri = token_uri_raw + .clone() + .try_into() + .map_err(|_| revert("invalid token uri length"))?; match LaosEvolution::evolve_with_external_uri( caller.into(), @@ -174,6 +176,7 @@ where H256(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), H256(token_id_bytes), H256::from_low_u64_be(collection_id), + H256::from_slice(token_uri_raw.as_slice()), ], data: Vec::new(), } diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index bed63cdab..aa78f09eb 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -274,7 +274,7 @@ fn evolve_works() { let input = EvmDataWriter::new_with_selector(Action::Evolve) .write(U256::from(0)) .write(U256::from(1)) - .write(Bytes([1u8; 20].to_vec())) + .write(Bytes([1u8; 32].to_vec())) .build(); let mut handle = create_mock_handle_from_input(input); @@ -289,7 +289,7 @@ fn evolve_should_generate_log() { let collection_id = 0; let token_id = 1; - let token_uri = Bytes([1u8; 20].to_vec()); + let token_uri = Bytes([1u8; 32].to_vec()); let input = EvmDataWriter::new_with_selector(Action::Evolve) .write(U256::from(collection_id)) @@ -303,10 +303,11 @@ fn evolve_should_generate_log() { let logs = handle.logs; assert_eq!(logs.len(), 1); assert_eq!(logs[0].address, H160::zero()); - assert_eq!(logs[0].topics.len(), 3); + assert_eq!(logs[0].topics.len(), 4); assert_eq!(logs[0].topics[0], SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI.into()); assert_eq!(logs[0].topics[1], H256::from_low_u64_be(token_id)); assert_eq!(logs[0].topics[2], H256::from_low_u64_be(collection_id)); + assert_eq!(logs[0].topics[3], H256::from_slice(token_uri.0.as_slice())); assert_eq!(logs[0].data, Vec::::new()); } From 6025a7fe7a65449d18f93071401b1d5ed586b467 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 13:22:37 +0200 Subject: [PATCH 15/30] fix events log --- .../precompile/laos-evolution/src/lib.rs | 18 ++++++++---------- .../precompile/laos-evolution/src/tests.rs | 18 +++++++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 79ee1c601..58dc8859e 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -167,18 +167,16 @@ where token_uri, ) { Ok(()) => { - let mut token_id_bytes = [0u8; 32]; - token_id.to_big_endian(&mut token_id_bytes); - Log { address: context.address, - topics: sp_std::vec![ - H256(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), - H256(token_id_bytes), - H256::from_low_u64_be(collection_id), - H256::from_slice(token_uri_raw.as_slice()), - ], - data: Vec::new(), + topics: sp_std::vec![H256( + SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI + ),], + data: EvmDataWriter::new() + .write(token_id) + .write(collection_id) + .write(token_uri_raw) + .build(), } .record(handle)?; diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index aa78f09eb..27c501a1e 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -274,7 +274,7 @@ fn evolve_works() { let input = EvmDataWriter::new_with_selector(Action::Evolve) .write(U256::from(0)) .write(U256::from(1)) - .write(Bytes([1u8; 32].to_vec())) + .write(Bytes([1u8; 20].to_vec())) .build(); let mut handle = create_mock_handle_from_input(input); @@ -289,7 +289,7 @@ fn evolve_should_generate_log() { let collection_id = 0; let token_id = 1; - let token_uri = Bytes([1u8; 32].to_vec()); + let token_uri = Bytes([1u8; 20].to_vec()); let input = EvmDataWriter::new_with_selector(Action::Evolve) .write(U256::from(collection_id)) @@ -303,12 +303,16 @@ fn evolve_should_generate_log() { let logs = handle.logs; assert_eq!(logs.len(), 1); assert_eq!(logs[0].address, H160::zero()); - assert_eq!(logs[0].topics.len(), 4); + assert_eq!(logs[0].topics.len(), 1); assert_eq!(logs[0].topics[0], SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI.into()); - assert_eq!(logs[0].topics[1], H256::from_low_u64_be(token_id)); - assert_eq!(logs[0].topics[2], H256::from_low_u64_be(collection_id)); - assert_eq!(logs[0].topics[3], H256::from_slice(token_uri.0.as_slice())); - assert_eq!(logs[0].data, Vec::::new()); + assert_eq!( + logs[0].data, + EvmDataWriter::new() + .write(U256::from(token_id)) + .write(U256::from(collection_id)) + .write(token_uri.0) + .build() + ); } #[test] From 74bcb4c5fb7fb98419051387fff7dff14c87b4b7 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 14:59:59 +0200 Subject: [PATCH 16/30] typos in solidity LaosEvolution.sol --- .../precompile/laos-evolution/contracts/LaosEvolution.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index b6ebc7aa7..516a03d3d 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -27,9 +27,9 @@ interface LaosEvolution { ); /// @notice Emitted when a token metadata is updated - /// @param tokenId the resulting id of the newly minted token + /// @param tokenId the id for which the metadata has changed /// @param collectionId the id of the collection - /// @param tokenURI the URI of the newly evolved token + /// @param tokenURI the new URI of the token event MetadataUpdate( uint256 tokenId, uint64 collectionId, @@ -69,7 +69,7 @@ interface LaosEvolution { string calldata tokenURI ) external returns (uint256); - /// @notice Evolve an existing token + /// @notice Changes the tokenURI of an existing token /// @dev Call this function to evolve an existing token, the caller must be the owner of the collection /// @param collectionId the id of the collection /// @param tokenId the id of the token From f74df462c8a305afc320ab1bfacff280bbf98351 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 15:08:10 +0200 Subject: [PATCH 17/30] fix typo in solidity contracts --- .../precompile/laos-evolution/contracts/LaosEvolution.sol | 4 ++-- ownership-chain/precompile/laos-evolution/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index 516a03d3d..74da9bf64 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -62,7 +62,7 @@ interface LaosEvolution { /// @param to the owner of the newly minted token /// @param tokenURI the tokenURI of the newly minted token /// @return the id of the newly minted token - function mintWithExternalUri( + function mintWithExternalURI( uint64 collectionId, uint96 slot, address to, @@ -74,7 +74,7 @@ interface LaosEvolution { /// @param collectionId the id of the collection /// @param tokenId the id of the token /// @param tokenURI the new tokenURI of the token - function evolveWithExternalUri( + function evolveWithExternalURI( uint64 collectionId, uint256 tokenId, string calldata tokenURI diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 58dc8859e..419acd34b 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -30,9 +30,9 @@ pub enum Action { /// Get tokenURI of the token in collection TokenURI = "tokenURI(uint64,uint256)", /// Mint token - Mint = "mintWithExternalUri(uint64,uint96,address,string)", + Mint = "mintWithExternalURI(uint64,uint96,address,string)", /// Evolve token - Evolve = "evolveWithExternalUri(uint64,uint256,string)", + Evolve = "evolveWithExternalURI(uint64,uint256,string)", } /// Wrapper for the precompile function. From 976dd40648c8e26633ab0f22f06f93dc8f193a2d Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 15:09:21 +0200 Subject: [PATCH 18/30] typos in solidity LaosEvolution.sol --- .../precompile/laos-evolution/contracts/LaosEvolution.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index 74da9bf64..112a40236 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -27,7 +27,7 @@ interface LaosEvolution { ); /// @notice Emitted when a token metadata is updated - /// @param tokenId the id for which the metadata has changed + /// @param tokenId the id of the token for which the metadata has changed /// @param collectionId the id of the collection /// @param tokenURI the new URI of the token event MetadataUpdate( From 72aa4397ece785a4869693894dbbe47104b83373 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 15:19:22 +0200 Subject: [PATCH 19/30] fix function selectors --- ownership-chain/precompile/laos-evolution/src/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 27c501a1e..7771a9dc5 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -37,7 +37,8 @@ fn function_selectors() { assert_eq!(Action::CreateCollection as u32, 0x2069E953); assert_eq!(Action::OwnerOfCollection as u32, 0xFB34AE53); assert_eq!(Action::TokenURI as u32, 0xC8A3F102); - assert_eq!(Action::Mint as u32, 0xEAD3F711); + assert_eq!(Action::Mint as u32, 0xD4AF5BBB); + assert_eq!(Action::Evolve as u32, 0xEF2629F); } #[test] From 21f9b1251e3d6a10907ecc371d2287f591dbecd8 Mon Sep 17 00:00:00 2001 From: magecnion Date: Fri, 27 Oct 2023 15:44:16 +0200 Subject: [PATCH 20/30] EvolvedWithExternalTokenURI => MetadataUpdate --- ownership-chain/pallets/laos-evolution/src/lib.rs | 12 ++---------- ownership-chain/pallets/laos-evolution/src/tests.rs | 8 ++------ ownership-chain/precompile/laos-evolution/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/ownership-chain/pallets/laos-evolution/src/lib.rs b/ownership-chain/pallets/laos-evolution/src/lib.rs index 97c3e50a7..91bae858a 100644 --- a/ownership-chain/pallets/laos-evolution/src/lib.rs +++ b/ownership-chain/pallets/laos-evolution/src/lib.rs @@ -83,11 +83,7 @@ pub mod pallet { }, /// Asset evolved /// [collection_id, token_uri, token_id] - EvolvedWithExternalTokenURI { - collection_id: CollectionId, - token_uri: TokenUriOf, - token_id: TokenId, - }, + MetadataUpdate { token_id: TokenId, collection_id: CollectionId, token_uri: TokenUriOf }, } // Errors inform users that something went wrong. @@ -186,11 +182,7 @@ impl LaosEvolution, TokenUriOf> for Pallet { TokenURI::::insert(collection_id, token_id, token_uri.clone()); - Self::deposit_event(Event::EvolvedWithExternalTokenURI { - collection_id, - token_id, - token_uri, - }); + Self::deposit_event(Event::MetadataUpdate { token_id, collection_id, token_uri }); Ok(()) } diff --git a/ownership-chain/pallets/laos-evolution/src/tests.rs b/ownership-chain/pallets/laos-evolution/src/tests.rs index b242c3c9c..586290d5c 100644 --- a/ownership-chain/pallets/laos-evolution/src/tests.rs +++ b/ownership-chain/pallets/laos-evolution/src/tests.rs @@ -398,12 +398,8 @@ fn evolve_with_external_uri_happy_path() { // token uri is updated and event is emitted assert_eq!(LaosEvolution::token_uri(collection_id, token_id), Some(new_token_uri.clone())); System::assert_has_event( - Event::EvolvedWithExternalTokenURI { - collection_id, - token_id, - token_uri: new_token_uri.clone(), - } - .into(), + Event::MetadataUpdate { token_id, collection_id, token_uri: new_token_uri.clone() } + .into(), ); }); } diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 419acd34b..2d131939b 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -18,7 +18,7 @@ pub const SELECTOR_LOG_NEW_COLLECTION: [u8; 32] = keccak256!("NewCollection(uint pub const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = keccak256!("MintedWithExternalTokenURI(uint64,uint96,address,string,uint256)"); pub const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = - keccak256!("EvolvedWithExternalTokenURI(uint64,uint256,string)"); + keccak256!("MetadataUpdate(uint256,uint64,string)"); #[precompile_utils_macro::generate_function_selector] #[derive(Debug, PartialEq)] From 7d25016693d915c8e90d9ff11e6aeafb4f44fe74 Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 09:37:39 +0100 Subject: [PATCH 21/30] make token_id as indexed --- .../precompile/laos-evolution/contracts/LaosEvolution.sol | 2 +- ownership-chain/precompile/laos-evolution/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index 112a40236..c2826f0c5 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -31,7 +31,7 @@ interface LaosEvolution { /// @param collectionId the id of the collection /// @param tokenURI the new URI of the token event MetadataUpdate( - uint256 tokenId, + uint256 indexed tokenId, uint64 collectionId, string tokenURI ); diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 2d131939b..b220bb706 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -32,7 +32,7 @@ pub enum Action { /// Mint token Mint = "mintWithExternalURI(uint64,uint96,address,string)", /// Evolve token - Evolve = "evolveWithExternalURI(uint64,uint256,string)", + Evolve = "metadataUpdate(uint256,uint64,string)", } /// Wrapper for the precompile function. From 6d8abafb1a7280c984c4c83c091a98c3a60987d5 Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 09:53:52 +0100 Subject: [PATCH 22/30] fix signature --- ownership-chain/precompile/laos-evolution/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index d354207b2..c656dfda7 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -40,7 +40,7 @@ fn function_selectors() { assert_eq!(Action::OwnerOfCollection as u32, 0xFB34AE53); assert_eq!(Action::TokenURI as u32, 0xC8A3F102); assert_eq!(Action::Mint as u32, 0xD4AF5BBB); - assert_eq!(Action::Evolve as u32, 0xEF2629F); + assert_eq!(Action::Evolve as u32, 0xA28FB3FF); } #[test] From dd01c438ce0783dc8f56da16b561445e7d873114 Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 10:16:00 +0100 Subject: [PATCH 23/30] fix signature --- ownership-chain/precompile/laos-evolution/src/lib.rs | 2 +- ownership-chain/precompile/laos-evolution/src/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index dfd098842..17303570c 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -32,7 +32,7 @@ pub enum Action { /// Mint token Mint = "mintWithExternalURI(uint64,uint96,address,string)", /// Evolve token - Evolve = "metadataUpdate(uint256,uint64,string)", + Evolve = "evolveWithExternalURI(uint64,uint256,string)", } /// Wrapper for the precompile function. diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index c656dfda7..d354207b2 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -40,7 +40,7 @@ fn function_selectors() { assert_eq!(Action::OwnerOfCollection as u32, 0xFB34AE53); assert_eq!(Action::TokenURI as u32, 0xC8A3F102); assert_eq!(Action::Mint as u32, 0xD4AF5BBB); - assert_eq!(Action::Evolve as u32, 0xA28FB3FF); + assert_eq!(Action::Evolve as u32, 0xEF2629F); } #[test] From 2600c111577357cb6cd4c580a26b2f2872842600 Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 10:20:24 +0100 Subject: [PATCH 24/30] fix signature --- ownership-chain/precompile/laos-evolution/src/tests.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index d354207b2..755c7e655 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -32,6 +32,10 @@ fn check_log_selectors() { hex::encode(SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI), "e7cd937c6c8e9d8316a3f190b7c68fd1b5df77145952da131c29122b85e0b317" ); + assert_eq!( + hex::encode(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), + "09a20653c78577ad8badd62a293acce201428ba7a56159acaed6130a1c7d4e70" + ); } #[test] @@ -40,7 +44,7 @@ fn function_selectors() { assert_eq!(Action::OwnerOfCollection as u32, 0xFB34AE53); assert_eq!(Action::TokenURI as u32, 0xC8A3F102); assert_eq!(Action::Mint as u32, 0xD4AF5BBB); - assert_eq!(Action::Evolve as u32, 0xEF2629F); + assert_eq!(Action::Evolve as u32, 0x0EF2629F); } #[test] From 8980eb3b46bba4e4f05df053ee82261da76706ee Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 10:32:26 +0100 Subject: [PATCH 25/30] add topic to event --- .../precompile/laos-evolution/src/lib.rs | 27 ++++++++++--------- .../precompile/laos-evolution/src/tests.rs | 12 +++------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 17303570c..7f764d4de 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -17,7 +17,7 @@ pub const SELECTOR_LOG_NEW_COLLECTION: [u8; 32] = keccak256!("NewCollection(uint /// Solidity selector of the Transfer log, which is the Keccak of the Log signature. pub const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = keccak256!("MintedWithExternalTokenURI(uint64,uint96,address,string,uint256)"); -pub const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = +pub const SELECTOR_LOG_METADATA_UPDATE: [u8; 32] = keccak256!("MetadataUpdate(uint256,uint64,string)"); #[precompile_utils_macro::generate_function_selector] @@ -166,18 +166,19 @@ where token_uri, ) { Ok(()) => { - Log { - address: context.address, - topics: sp_std::vec![H256( - SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI - ),], - data: EvmDataWriter::new() - .write(token_id) - .write(collection_id) - .write(token_uri_raw) - .build(), - } - .record(handle)?; + let mut token_id_bytes = [0u8; 32]; + token_id.to_big_endian(&mut token_id_bytes); + + LogsBuilder::new(context.address) + .log2( + SELECTOR_LOG_METADATA_UPDATE, + token_id_bytes, + EvmDataWriter::new() + .write(collection_id) + .write(token_uri_raw) + .build(), + ) + .record(handle)?; Ok(succeed(EvmDataWriter::new().build())) }, diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 755c7e655..3029f978a 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -33,7 +33,7 @@ fn check_log_selectors() { "e7cd937c6c8e9d8316a3f190b7c68fd1b5df77145952da131c29122b85e0b317" ); assert_eq!( - hex::encode(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), + hex::encode(SELECTOR_LOG_METADATA_UPDATE), "09a20653c78577ad8badd62a293acce201428ba7a56159acaed6130a1c7d4e70" ); } @@ -320,15 +320,11 @@ fn evolve_should_generate_log() { let logs = handle.logs; assert_eq!(logs.len(), 1); assert_eq!(logs[0].address, H160::zero()); - assert_eq!(logs[0].topics.len(), 1); - assert_eq!(logs[0].topics[0], SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI.into()); + assert_eq!(logs[0].topics.len(), 2); + assert_eq!(logs[0].topics[0], SELECTOR_LOG_METADATA_UPDATE.into()); assert_eq!( logs[0].data, - EvmDataWriter::new() - .write(U256::from(token_id)) - .write(U256::from(collection_id)) - .write(token_uri.0) - .build() + EvmDataWriter::new().write(U256::from(collection_id)).write(token_uri.0).build() ); } From be9f9222b88f77e6a915e52d5cf06abf3edf6e1e Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 10:38:02 +0100 Subject: [PATCH 26/30] include return type --- ownership-chain/precompile/laos-evolution/src/lib.rs | 2 +- ownership-chain/precompile/laos-evolution/src/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 7f764d4de..4dbd1c5f9 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -180,7 +180,7 @@ where ) .record(handle)?; - Ok(succeed(EvmDataWriter::new().build())) + Ok(succeed(EvmDataWriter::new().write(token_id).build())) }, Err(err) => Err(revert_dispatch_error(err)), } diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 3029f978a..6f4b07a34 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -297,7 +297,7 @@ fn evolve_works() { let mut handle = create_mock_handle_from_input(input); let result = Mock::execute(&mut handle).unwrap(); - assert_eq!(result, succeed(EvmDataWriter::new().build())); + assert_eq!(result, succeed(EvmDataWriter::new().write(H256::from_low_u64_be(1)).build())); } #[test] From a0c31ea1d71cc62e0f159bf5142b9179651237a9 Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 12:21:07 +0100 Subject: [PATCH 27/30] improve test readbility --- .../precompile/laos-evolution/src/tests.rs | 175 +++++++++++------- 1 file changed, 105 insertions(+), 70 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 6f4b07a34..69abea0e1 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -277,78 +277,113 @@ fn failing_mint_should_return_error() { assert_eq!(result, revert("this is error")); } -#[test] -fn evolve_works() { - impl_precompile_mock_simple!( - Mock, - Ok(0), - Some(H160::from_low_u64_be(0x1234)), - Ok(1.into()), - None, - Ok(()) - ); - - let input = EvmDataWriter::new_with_selector(Action::Evolve) - .write(U256::from(0)) - .write(U256::from(1)) - .write(Bytes([1u8; 20].to_vec())) - .build(); - - let mut handle = create_mock_handle_from_input(input); - let result = Mock::execute(&mut handle).unwrap(); - - assert_eq!(result, succeed(EvmDataWriter::new().write(H256::from_low_u64_be(1)).build())); -} - -#[test] -fn evolve_should_generate_log() { - impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); - - let collection_id = 0; - let token_id = 1; - let token_uri = Bytes([1u8; 20].to_vec()); - - let input = EvmDataWriter::new_with_selector(Action::Evolve) - .write(U256::from(collection_id)) - .write(U256::from(token_id)) - .write(token_uri.clone()) - .build(); - let mut handle = create_mock_handle_from_input(input); - - let result = Mock::execute(&mut handle); - assert!(result.is_ok()); - let logs = handle.logs; - assert_eq!(logs.len(), 1); - assert_eq!(logs[0].address, H160::zero()); - assert_eq!(logs[0].topics.len(), 2); - assert_eq!(logs[0].topics[0], SELECTOR_LOG_METADATA_UPDATE.into()); - assert_eq!( - logs[0].data, - EvmDataWriter::new().write(U256::from(collection_id)).write(token_uri.0).build() - ); -} - -#[test] -fn evolve_failing_should_return_error() { - impl_precompile_mock_simple!( - Mock, - Ok(0), - Some(H160::from_low_u64_be(0x1234)), - Ok(1.into()), - None, - Err(DispatchError::Other("this is error")) - ); - - let input = EvmDataWriter::new_with_selector(Action::Evolve) - .write(U256::from(0)) - .write(U256::from(1)) - .write(Bytes([1u8; 20].to_vec())) - .build(); +mod evolve { + use super::*; + + #[test] + fn happy_path() { + impl_precompile_mock_simple!( + Mock, + Ok(0), + Some(H160::from_low_u64_be(0x1234)), + Ok(1.into()), + None, + Ok(()) + ); + + let input = EvmDataWriter::new_with_selector(Action::Evolve) + .write(U256::from(0)) + .write(U256::from(1)) + .write(Bytes([1u8; 20].to_vec())) + .build(); + + let mut handle = create_mock_handle_from_input(input); + let result = Mock::execute(&mut handle).unwrap(); + + assert_eq!(result, succeed(EvmDataWriter::new().write(H256::from_low_u64_be(1)).build())); + } - let mut handle = create_mock_handle_from_input(input); - let result = Mock::execute(&mut handle).unwrap_err(); + #[test] + fn when_succeeds_should_generate_log() { + impl_precompile_mock_simple!(Mock, Ok(0), None, Ok(0.into()), None, Ok(())); + + let collection_id = 2; + let token_id = 1; + let token_uri = Bytes([1u8; 20].to_vec()); + + let input = EvmDataWriter::new_with_selector(Action::Evolve) + .write(U256::from(collection_id)) + .write(U256::from(token_id)) + .write(token_uri.clone()) + .build(); + let mut handle = create_mock_handle_from_input(input); + + let result = Mock::execute(&mut handle); + assert!(result.is_ok()); + let logs = handle.logs; + assert_eq!(logs.len(), 1); + assert_eq!(logs[0].address, H160::zero()); + assert_eq!(logs[0].topics.len(), 2); + assert_eq!(logs[0].topics[0], SELECTOR_LOG_METADATA_UPDATE.into()); + assert_eq!( + logs[0].data, + vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, // collection_id + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 64, // offset + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 20, // lenght of token_uri + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1 // token_uri + ] + ); + } - assert_eq!(result, revert("this is error")); + #[test] + fn when_fails_should_return_error() { + impl_precompile_mock_simple!( + Mock, + Ok(0), + Some(H160::from_low_u64_be(0x1234)), + Ok(1.into()), + None, + Err(DispatchError::Other("this is error")) + ); + + let input = EvmDataWriter::new_with_selector(Action::Evolve) + .write(U256::from(0)) + .write(U256::from(1)) + .write(Bytes([1u8; 20].to_vec())) + .build(); + + let mut handle = create_mock_handle_from_input(input); + let result = Mock::execute(&mut handle).unwrap_err(); + + assert_eq!(result, revert("this is error")); + } } mod helpers { From 898ccb318e096ac5e9559aea00de1053659195fa Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 16:07:20 +0100 Subject: [PATCH 28/30] change requested: unify solidity interface events --- ownership-chain/pallets/laos-evolution/src/lib.rs | 12 ++++++++---- ownership-chain/pallets/laos-evolution/src/tests.rs | 10 +++++++--- .../laos-evolution/contracts/LaosEvolution.sol | 6 +++--- ownership-chain/precompile/laos-evolution/src/lib.rs | 8 ++++---- .../precompile/laos-evolution/src/tests.rs | 8 ++++---- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ownership-chain/pallets/laos-evolution/src/lib.rs b/ownership-chain/pallets/laos-evolution/src/lib.rs index 91bae858a..594cf1351 100644 --- a/ownership-chain/pallets/laos-evolution/src/lib.rs +++ b/ownership-chain/pallets/laos-evolution/src/lib.rs @@ -74,7 +74,7 @@ pub mod pallet { CollectionCreated { collection_id: CollectionId, owner: AccountIdOf }, /// Asset minted /// [collection_id, slot, to, token_uri] - MintedWithExternalTokenURI { + MintedWithExternalURI { collection_id: CollectionId, slot: Slot, to: AccountIdOf, @@ -83,7 +83,11 @@ pub mod pallet { }, /// Asset evolved /// [collection_id, token_uri, token_id] - MetadataUpdate { token_id: TokenId, collection_id: CollectionId, token_uri: TokenUriOf }, + EvolvedWithExternalURI { + collection_id: CollectionId, + token_id: TokenId, + token_uri: TokenUriOf, + }, } // Errors inform users that something went wrong. @@ -145,7 +149,7 @@ impl LaosEvolution, TokenUriOf> for Pallet { TokenURI::::insert(collection_id, token_id, token_uri.clone()); - Self::deposit_event(Event::MintedWithExternalTokenURI { + Self::deposit_event(Event::MintedWithExternalURI { collection_id, slot, to, @@ -182,7 +186,7 @@ impl LaosEvolution, TokenUriOf> for Pallet { TokenURI::::insert(collection_id, token_id, token_uri.clone()); - Self::deposit_event(Event::MetadataUpdate { token_id, collection_id, token_uri }); + Self::deposit_event(Event::EvolvedWithExternalURI { collection_id, token_id, token_uri }); Ok(()) } diff --git a/ownership-chain/pallets/laos-evolution/src/tests.rs b/ownership-chain/pallets/laos-evolution/src/tests.rs index 586290d5c..1b77a45b5 100644 --- a/ownership-chain/pallets/laos-evolution/src/tests.rs +++ b/ownership-chain/pallets/laos-evolution/src/tests.rs @@ -108,7 +108,7 @@ fn mint_with_external_uri_works() { assert_eq!(LaosEvolution::token_uri(collection_id, token_id), Some(token_uri.clone())); System::assert_has_event( - Event::MintedWithExternalTokenURI { + Event::MintedWithExternalURI { collection_id, slot, to: owner, @@ -398,8 +398,12 @@ fn evolve_with_external_uri_happy_path() { // token uri is updated and event is emitted assert_eq!(LaosEvolution::token_uri(collection_id, token_id), Some(new_token_uri.clone())); System::assert_has_event( - Event::MetadataUpdate { token_id, collection_id, token_uri: new_token_uri.clone() } - .into(), + Event::EvolvedWithExternalURI { + token_id, + collection_id, + token_uri: new_token_uri.clone(), + } + .into(), ); }); } diff --git a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol index c2826f0c5..83582be01 100644 --- a/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol +++ b/ownership-chain/precompile/laos-evolution/contracts/LaosEvolution.sol @@ -18,7 +18,7 @@ interface LaosEvolution { /// @param to the initial owner of the newly minted token /// @param tokenURI the URI of the newly minted token /// @param tokenId the resulting id of the newly minted token - event MintedWithExternalTokenURI( + event MintedWithExternalURI( uint64 collectionId, uint96 slot, address indexed to, @@ -30,9 +30,9 @@ interface LaosEvolution { /// @param tokenId the id of the token for which the metadata has changed /// @param collectionId the id of the collection /// @param tokenURI the new URI of the token - event MetadataUpdate( - uint256 indexed tokenId, + event EvolvedWithExternalURI( uint64 collectionId, + uint256 indexed tokenId, string tokenURI ); diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 4dbd1c5f9..2547e9b79 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -16,9 +16,9 @@ use sp_std::{fmt::Debug, marker::PhantomData, vec::Vec}; pub const SELECTOR_LOG_NEW_COLLECTION: [u8; 32] = keccak256!("NewCollection(uint64,address)"); /// Solidity selector of the Transfer log, which is the Keccak of the Log signature. pub const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = - keccak256!("MintedWithExternalTokenURI(uint64,uint96,address,string,uint256)"); -pub const SELECTOR_LOG_METADATA_UPDATE: [u8; 32] = - keccak256!("MetadataUpdate(uint256,uint64,string)"); + keccak256!("MintedWithExternalURI(uint64,uint96,address,string,uint256)"); +pub const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] = + keccak256!("EvolvedWithExternalURI(uint256,uint64,string)"); #[precompile_utils_macro::generate_function_selector] #[derive(Debug, PartialEq)] @@ -171,7 +171,7 @@ where LogsBuilder::new(context.address) .log2( - SELECTOR_LOG_METADATA_UPDATE, + SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI, token_id_bytes, EvmDataWriter::new() .write(collection_id) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index 69abea0e1..f06d99e4a 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -30,11 +30,11 @@ fn check_log_selectors() { ); assert_eq!( hex::encode(SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI), - "e7cd937c6c8e9d8316a3f190b7c68fd1b5df77145952da131c29122b85e0b317" + "4b3b5da28a351f8bb73b960d7c80b2cef3e3570cb03448234dee173942c74786" ); assert_eq!( - hex::encode(SELECTOR_LOG_METADATA_UPDATE), - "09a20653c78577ad8badd62a293acce201428ba7a56159acaed6130a1c7d4e70" + hex::encode(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI), + "568b059e9377ea804907ac57dc8d56446b17dbf9f4b30dfe1935b9c8815ae7e1" ); } @@ -324,7 +324,7 @@ mod evolve { assert_eq!(logs.len(), 1); assert_eq!(logs[0].address, H160::zero()); assert_eq!(logs[0].topics.len(), 2); - assert_eq!(logs[0].topics[0], SELECTOR_LOG_METADATA_UPDATE.into()); + assert_eq!(logs[0].topics[0], SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI.into()); assert_eq!( logs[0].data, vec![ From 20883fff5f0b90601ec04177edf7d393c8784cd0 Mon Sep 17 00:00:00 2001 From: magecnion Date: Mon, 30 Oct 2023 16:29:31 +0100 Subject: [PATCH 29/30] change requested: use Bytes() --- .../precompile/laos-evolution/src/lib.rs | 2 +- .../precompile/laos-evolution/src/tests.rs | 26 ++----------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/ownership-chain/precompile/laos-evolution/src/lib.rs b/ownership-chain/precompile/laos-evolution/src/lib.rs index 2547e9b79..bdbb343d6 100644 --- a/ownership-chain/precompile/laos-evolution/src/lib.rs +++ b/ownership-chain/precompile/laos-evolution/src/lib.rs @@ -175,7 +175,7 @@ where token_id_bytes, EvmDataWriter::new() .write(collection_id) - .write(token_uri_raw) + .write(Bytes(token_uri_raw)) .build(), ) .record(handle)?; diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index f06d99e4a..b07158ac4 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -334,30 +334,8 @@ mod evolve { 0, 0, 0, 64, // offset 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, // lenght of token_uri - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1 // token_uri + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 // token_uri ] ); } From ca6c3dbba60f7b958d92e5ef7cc58dd9700cec16 Mon Sep 17 00:00:00 2001 From: magecnion Date: Tue, 31 Oct 2023 09:37:49 +0100 Subject: [PATCH 30/30] fix test --- ownership-chain/precompile/laos-evolution/src/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ownership-chain/precompile/laos-evolution/src/tests.rs b/ownership-chain/precompile/laos-evolution/src/tests.rs index cfcf7f34b..c8f4bc693 100644 --- a/ownership-chain/precompile/laos-evolution/src/tests.rs +++ b/ownership-chain/precompile/laos-evolution/src/tests.rs @@ -123,7 +123,8 @@ fn mint_with_external_uri_should_generate_log() { Ok(0), None, Ok(U256::from_str("0x010203").unwrap()), // return token id - None + None, + Ok(()) ); let input = EvmDataWriter::new_with_selector(Action::Mint)