From ba711a7b1711360113b3d99cd9777c18ae9f0562 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 06 Dec 2022 12:23:24 +0000 Subject: [PATCH] added `collectionNestingPermissions` funtion in `Collection` interface --- --- a/pallets/common/src/erc.rs +++ b/pallets/common/src/erc.rs @@ -26,7 +26,7 @@ weight, }; use pallet_evm_coder_substrate::dispatch_to_evm; -use sp_std::vec::Vec; +use sp_std::{vec, vec::Vec}; use up_data_structs::{ AccessMode, CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property, SponsoringRateLimit, SponsorshipState, @@ -35,7 +35,9 @@ use crate::{ Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf, - eth::{EthCrossAccount, convert_cross_account_to_uint256}, + eth::{ + EthCrossAccount, convert_cross_account_to_uint256, CollectionPermissions as EvmPermissions, + }, weights::WeightInfo, }; @@ -508,6 +510,14 @@ )) } + /// Returns permissions for a collection + fn collection_nesting_permissions(&self) -> Result> { + let nesting = self.collection.permissions.nesting(); + Ok(vec![ + (EvmPermissions::CollectionAdmin, nesting.collection_admin), + (EvmPermissions::TokenOwner, nesting.token_owner), + ]) + } /// Set the collection access method. /// @param mode Access mode /// 0 for Normal --- a/pallets/common/src/eth.rs +++ b/pallets/common/src/eth.rs @@ -155,3 +155,10 @@ } } } +#[derive(Default, Debug, Clone, Copy, AbiCoder)] +#[repr(u8)] +pub enum CollectionPermissions { + #[default] + CollectionAdmin, + TokenOwner, +} --- a/pallets/fungible/src/stubs/UniqueFungible.sol +++ b/pallets/fungible/src/stubs/UniqueFungible.sol @@ -18,7 +18,7 @@ } /// @title A contract that allows you to work with collections. -/// @dev the ERC-165 identifier for this interface is 0xeecfdb34 +/// @dev the ERC-165 identifier for this interface is 0xb5e1747f contract Collection is Dummy, ERC165 { // /// Set collection property. // /// @@ -263,6 +263,15 @@ return Tuple21(false, new uint256[](0)); } + /// Returns permissions for a collection + /// @dev EVM selector for this function is: 0x5b2eaf4b, + /// or in textual repr: collectionNestingPermissions() + function collectionNestingPermissions() public view returns (Tuple24[] memory) { + require(false, stub_error); + dummy; + return new Tuple24[](0); + } + /// Set the collection access method. /// @param mode Access mode /// 0 for Normal @@ -434,6 +443,17 @@ uint256 sub; } +enum CollectionPermissions { + CollectionAdmin, + TokenOwner +} + +/// @dev anonymous struct +struct Tuple24 { + CollectionPermissions field_0; + bool field_1; +} + /// @dev anonymous struct struct Tuple21 { bool field_0; --- a/pallets/nonfungible/src/stubs/UniqueNFT.sol +++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol @@ -119,7 +119,7 @@ } /// @title A contract that allows you to work with collections. -/// @dev the ERC-165 identifier for this interface is 0xeecfdb34 +/// @dev the ERC-165 identifier for this interface is 0xb5e1747f contract Collection is Dummy, ERC165 { // /// Set collection property. // /// @@ -364,6 +364,15 @@ return Tuple34(false, new uint256[](0)); } + /// Returns permissions for a collection + /// @dev EVM selector for this function is: 0x5b2eaf4b, + /// or in textual repr: collectionNestingPermissions() + function collectionNestingPermissions() public view returns (Tuple37[] memory) { + require(false, stub_error); + dummy; + return new Tuple37[](0); + } + /// Set the collection access method. /// @param mode Access mode /// 0 for Normal @@ -535,6 +544,17 @@ uint256 sub; } +enum CollectionPermissions { + CollectionAdmin, + TokenOwner +} + +/// @dev anonymous struct +struct Tuple37 { + CollectionPermissions field_0; + bool field_1; +} + /// @dev anonymous struct struct Tuple34 { bool field_0; --- a/pallets/refungible/src/stubs/UniqueRefungible.sol +++ b/pallets/refungible/src/stubs/UniqueRefungible.sol @@ -119,7 +119,7 @@ } /// @title A contract that allows you to work with collections. -/// @dev the ERC-165 identifier for this interface is 0xeecfdb34 +/// @dev the ERC-165 identifier for this interface is 0xb5e1747f contract Collection is Dummy, ERC165 { // /// Set collection property. // /// @@ -364,6 +364,15 @@ return Tuple33(false, new uint256[](0)); } + /// Returns permissions for a collection + /// @dev EVM selector for this function is: 0x5b2eaf4b, + /// or in textual repr: collectionNestingPermissions() + function collectionNestingPermissions() public view returns (Tuple36[] memory) { + require(false, stub_error); + dummy; + return new Tuple36[](0); + } + /// Set the collection access method. /// @param mode Access mode /// 0 for Normal @@ -535,6 +544,17 @@ uint256 sub; } +enum CollectionPermissions { + CollectionAdmin, + TokenOwner +} + +/// @dev anonymous struct +struct Tuple36 { + CollectionPermissions field_0; + bool field_1; +} + /// @dev anonymous struct struct Tuple33 { bool field_0; --- a/tests/src/eth/abi/fungible.json +++ b/tests/src/eth/abi/fungible.json @@ -208,6 +208,27 @@ }, { "inputs": [], + "name": "collectionNestingPermissions", + "outputs": [ + { + "components": [ + { + "internalType": "enum CollectionPermissions", + "name": "field_0", + "type": "uint8" + }, + { "internalType": "bool", "name": "field_1", "type": "bool" } + ], + "internalType": "struct Tuple24[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], "name": "collectionNestingRestrictedCollectionIds", "outputs": [ { --- a/tests/src/eth/abi/nonFungible.json +++ b/tests/src/eth/abi/nonFungible.json @@ -238,6 +238,27 @@ }, { "inputs": [], + "name": "collectionNestingPermissions", + "outputs": [ + { + "components": [ + { + "internalType": "enum CollectionPermissions", + "name": "field_0", + "type": "uint8" + }, + { "internalType": "bool", "name": "field_1", "type": "bool" } + ], + "internalType": "struct Tuple37[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], "name": "collectionNestingRestrictedCollectionIds", "outputs": [ { --- a/tests/src/eth/abi/reFungible.json +++ b/tests/src/eth/abi/reFungible.json @@ -220,6 +220,27 @@ }, { "inputs": [], + "name": "collectionNestingPermissions", + "outputs": [ + { + "components": [ + { + "internalType": "enum CollectionPermissions", + "name": "field_0", + "type": "uint8" + }, + { "internalType": "bool", "name": "field_1", "type": "bool" } + ], + "internalType": "struct Tuple36[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], "name": "collectionNestingRestrictedCollectionIds", "outputs": [ { --- a/tests/src/eth/api/UniqueFungible.sol +++ b/tests/src/eth/api/UniqueFungible.sol @@ -13,7 +13,7 @@ } /// @title A contract that allows you to work with collections. -/// @dev the ERC-165 identifier for this interface is 0xeecfdb34 +/// @dev the ERC-165 identifier for this interface is 0xb5e1747f interface Collection is Dummy, ERC165 { // /// Set collection property. // /// @@ -171,6 +171,11 @@ /// or in textual repr: collectionNestingRestrictedCollectionIds() function collectionNestingRestrictedCollectionIds() external view returns (Tuple20 memory); + /// Returns permissions for a collection + /// @dev EVM selector for this function is: 0x5b2eaf4b, + /// or in textual repr: collectionNestingPermissions() + function collectionNestingPermissions() external view returns (Tuple23[] memory); + /// Set the collection access method. /// @param mode Access mode /// 0 for Normal @@ -284,6 +289,17 @@ } /// @dev anonymous struct +struct Tuple23 { + CollectionPermissions field_0; + bool field_1; +} + +enum CollectionPermissions { + CollectionAdmin, + TokenOwner +} + +/// @dev anonymous struct struct Tuple20 { bool field_0; uint256[] field_1; --- a/tests/src/eth/api/UniqueNFT.sol +++ b/tests/src/eth/api/UniqueNFT.sol @@ -80,7 +80,7 @@ } /// @title A contract that allows you to work with collections. -/// @dev the ERC-165 identifier for this interface is 0xeecfdb34 +/// @dev the ERC-165 identifier for this interface is 0xb5e1747f interface Collection is Dummy, ERC165 { // /// Set collection property. // /// @@ -238,6 +238,11 @@ /// or in textual repr: collectionNestingRestrictedCollectionIds() function collectionNestingRestrictedCollectionIds() external view returns (Tuple31 memory); + /// Returns permissions for a collection + /// @dev EVM selector for this function is: 0x5b2eaf4b, + /// or in textual repr: collectionNestingPermissions() + function collectionNestingPermissions() external view returns (Tuple34[] memory); + /// Set the collection access method. /// @param mode Access mode /// 0 for Normal @@ -351,6 +356,17 @@ } /// @dev anonymous struct +struct Tuple34 { + CollectionPermissions field_0; + bool field_1; +} + +enum CollectionPermissions { + CollectionAdmin, + TokenOwner +} + +/// @dev anonymous struct struct Tuple31 { bool field_0; uint256[] field_1; --- a/tests/src/eth/api/UniqueRefungible.sol +++ b/tests/src/eth/api/UniqueRefungible.sol @@ -80,7 +80,7 @@ } /// @title A contract that allows you to work with collections. -/// @dev the ERC-165 identifier for this interface is 0xeecfdb34 +/// @dev the ERC-165 identifier for this interface is 0xb5e1747f interface Collection is Dummy, ERC165 { // /// Set collection property. // /// @@ -238,6 +238,11 @@ /// or in textual repr: collectionNestingRestrictedCollectionIds() function collectionNestingRestrictedCollectionIds() external view returns (Tuple30 memory); + /// Returns permissions for a collection + /// @dev EVM selector for this function is: 0x5b2eaf4b, + /// or in textual repr: collectionNestingPermissions() + function collectionNestingPermissions() external view returns (Tuple33[] memory); + /// Set the collection access method. /// @param mode Access mode /// 0 for Normal @@ -351,6 +356,17 @@ } /// @dev anonymous struct +struct Tuple33 { + CollectionPermissions field_0; + bool field_1; +} + +enum CollectionPermissions { + CollectionAdmin, + TokenOwner +} + +/// @dev anonymous struct struct Tuple30 { bool field_0; uint256[] field_1; --- a/tests/src/eth/nesting/nest.test.ts +++ b/tests/src/eth/nesting/nest.test.ts @@ -52,7 +52,7 @@ expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(owner); }); - itEth('NFT: collectionNestingRestrictedCollectionIds()', async ({helper}) => { + itEth('NFT: collectionNestingRestrictedCollectionIds() & collectionNestingPermissions', async ({helper}) => { const owner = await helper.eth.createAccountWithBalance(donor); const {collectionId: unnestedCollsectionId, collectionAddress: unnsetedCollectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C'); const unnestedContract = helper.ethNativeContract.collection(unnsetedCollectionAddress, 'nft', owner); @@ -62,7 +62,9 @@ expect(await contract.methods.collectionNestingRestrictedCollectionIds().call({from: owner})).to.be.like([true, []]); await contract.methods.setCollectionNesting(true, [unnsetedCollectionAddress]).send({from: owner}); expect(await contract.methods.collectionNestingRestrictedCollectionIds().call({from: owner})).to.be.like([true, [unnestedCollsectionId.toString()]]); - + expect(await contract.methods.collectionNestingPermissions().call({from: owner})).to.be.like([['0', false], ['1', true]]); + await contract.methods.setCollectionNesting(false).send({from: owner}); + expect(await contract.methods.collectionNestingPermissions().call({from: owner})).to.be.like([['0', false], ['1', false]]); }); itEth('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => { -- gitstuff