difftreelog
chore remove URI ttp from clean collections
in: master
4 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -30,6 +30,7 @@
};
use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
+use sp_std::vec;
use up_data_structs::{
CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,
CollectionMode, PropertyValue,
@@ -96,63 +97,57 @@
base_uri_value: PropertyValue,
add_properties: bool,
) -> Result<CreateCollectionData<T::AccountId>> {
- let mut properties = up_data_structs::CollectionPropertiesVec::default();
- let mut token_property_permissions =
- up_data_structs::CollectionPropertiesPermissionsVec::default();
-
- token_property_permissions
- .try_push(up_data_structs::PropertyKeyPermission {
- key: key::url(),
- permission: up_data_structs::PropertyPermission {
- mutable: true,
- collection_admin: true,
- token_owner: false,
+ let token_property_permissions = if add_properties {
+ vec![
+ up_data_structs::PropertyKeyPermission {
+ key: key::url(),
+ permission: up_data_structs::PropertyPermission {
+ mutable: true,
+ collection_admin: true,
+ token_owner: false,
+ },
},
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
-
- if add_properties {
- token_property_permissions
- .try_push(up_data_structs::PropertyKeyPermission {
+ up_data_structs::PropertyKeyPermission {
key: key::suffix(),
permission: up_data_structs::PropertyPermission {
mutable: true,
collection_admin: true,
token_owner: false,
},
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
-
- properties
- .try_push(up_data_structs::Property {
+ },
+ ]
+ .try_into()
+ .map_err(|e| Error::Revert(format!("{:?}", e)))?
+ } else {
+ up_data_structs::CollectionPropertiesPermissionsVec::default()
+ };
+ let properties = if add_properties {
+ let mut properties = vec![
+ up_data_structs::Property {
key: key::schema_name(),
value: property_value::erc721(),
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
-
- properties
- .try_push(up_data_structs::Property {
+ },
+ up_data_structs::Property {
key: key::schema_version(),
value: property_value::schema_version(),
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
-
- properties
- .try_push(up_data_structs::Property {
+ },
+ up_data_structs::Property {
key: key::erc721_metadata(),
value: property_value::erc721_metadata_supported(),
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
-
+ },
+ ];
if !base_uri_value.is_empty() {
- properties
- .try_push(up_data_structs::Property {
- key: key::base_uri(),
- value: base_uri_value,
- })
- .map_err(|e| Error::Revert(format!("{:?}", e)))?;
+ properties.push(up_data_structs::Property {
+ key: key::base_uri(),
+ value: base_uri_value,
+ })
}
- }
+ properties
+ .try_into()
+ .map_err(|e| Error::Revert(format!("{:?}", e)))?
+ } else {
+ up_data_structs::CollectionPropertiesVec::default()
+ };
let data = CreateCollectionData {
name,
tests/src/eth/api/UniqueRFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRFT.sol
+++ /dev/null
@@ -1,163 +0,0 @@
-// SPDX-License-Identifier: OTHER
-// This code is automatically generated
-
-pragma solidity >=0.8.0 <0.9.0;
-
-// Common stubs holder
-interface Dummy {
-
-}
-
-interface ERC165 is Dummy {
- function supportsInterface(bytes4 interfaceID) external view returns (bool);
-}
-
-// Selector: 7d9262e6
-interface Collection is Dummy, ERC165 {
- // Set collection property.
- //
- // @param key Property key.
- // @param value Propery value.
- //
- // Selector: setCollectionProperty(string,bytes) 2f073f66
- function setCollectionProperty(string memory key, bytes memory value)
- external;
-
- // Delete collection property.
- //
- // @param key Property key.
- //
- // Selector: deleteCollectionProperty(string) 7b7debce
- function deleteCollectionProperty(string memory key) external;
-
- // Get collection property.
- //
- // @dev Throws error if key not found.
- //
- // @param key Property key.
- // @return bytes The property corresponding to the key.
- //
- // Selector: collectionProperty(string) cf24fd6d
- function collectionProperty(string memory key)
- external
- view
- returns (bytes memory);
-
- // Set the sponsor of the collection.
- //
- // @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
- //
- // @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
- //
- // Selector: setCollectionSponsor(address) 7623402e
- function setCollectionSponsor(address sponsor) external;
-
- // Collection sponsorship confirmation.
- //
- // @dev After setting the sponsor for the collection, it must be confirmed with this function.
- //
- // Selector: confirmCollectionSponsorship() 3c50e97a
- function confirmCollectionSponsorship() external;
-
- // Set limits for the collection.
- // @dev Throws error if limit not found.
- // @param limit Name of the limit. Valid names:
- // "accountTokenOwnershipLimit",
- // "sponsoredDataSize",
- // "sponsoredDataRateLimit",
- // "tokenLimit",
- // "sponsorTransferTimeout",
- // "sponsorApproveTimeout"
- // @param value Value of the limit.
- //
- // Selector: setCollectionLimit(string,uint32) 6a3841db
- function setCollectionLimit(string memory limit, uint32 value) external;
-
- // Set limits for the collection.
- // @dev Throws error if limit not found.
- // @param limit Name of the limit. Valid names:
- // "ownerCanTransfer",
- // "ownerCanDestroy",
- // "transfersEnabled"
- // @param value Value of the limit.
- //
- // Selector: setCollectionLimit(string,bool) 993b7fba
- function setCollectionLimit(string memory limit, bool value) external;
-
- // Get contract address.
- //
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() external view returns (address);
-
- // Add collection admin by substrate address.
- // @param new_admin Substrate administrator address.
- //
- // Selector: addCollectionAdminSubstrate(uint256) 5730062b
- function addCollectionAdminSubstrate(uint256 newAdmin) external;
-
- // Remove collection admin by substrate address.
- // @param admin Substrate administrator address.
- //
- // Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
- function removeCollectionAdminSubstrate(uint256 admin) external;
-
- // Add collection admin.
- // @param new_admin Address of the added administrator.
- //
- // Selector: addCollectionAdmin(address) 92e462c7
- function addCollectionAdmin(address newAdmin) external;
-
- // Remove collection admin.
- //
- // @param new_admin Address of the removed administrator.
- //
- // Selector: removeCollectionAdmin(address) fafd7b42
- function removeCollectionAdmin(address admin) external;
-
- // Toggle accessibility of collection nesting.
- //
- // @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
- //
- // Selector: setCollectionNesting(bool) 112d4586
- function setCollectionNesting(bool enable) external;
-
- // Toggle accessibility of collection nesting.
- //
- // @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
- // @param collections Addresses of collections that will be available for nesting.
- //
- // Selector: setCollectionNesting(bool,address[]) 64872396
- function setCollectionNesting(bool enable, address[] memory collections)
- external;
-
- // Set the collection access method.
- // @param mode Access mode
- // 0 for Normal
- // 1 for AllowList
- //
- // Selector: setCollectionAccess(uint8) 41835d4c
- function setCollectionAccess(uint8 mode) external;
-
- // Add the user to the allowed list.
- //
- // @param user Address of a trusted user.
- //
- // Selector: addToCollectionAllowList(address) 67844fe6
- function addToCollectionAllowList(address user) external;
-
- // Remove the user from the allowed list.
- //
- // @param user Address of a removed user.
- //
- // Selector: removeFromCollectionAllowList(address) 85c51acb
- function removeFromCollectionAllowList(address user) external;
-
- // Switch permission for minting.
- //
- // @param mode Enable if "true".
- //
- // Selector: setCollectionMintMode(bool) 00018e84
- function setCollectionMintMode(bool mode) external;
-}
-
-interface UniqueRFT is Dummy, ERC165, Collection {}
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {evmToAddress} from '@polkadot/util-crypto';18import {IKeyringPair} from '@polkadot/types/types';19import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';202122describe('Create NFT collection from EVM', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (_helper, privateKey) => {27 donor = privateKey('//Alice');28 });29 });3031 itEth('Create collection', async ({helper}) => {32 const owner = await helper.eth.createAccountWithBalance(donor);3334 const name = 'CollectionEVM';35 const description = 'Some description';36 const prefix = 'token prefix';3738 // todo:playgrounds this might fail when in async environment.39 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;40 const {collectionId} = await helper.eth.createNFTCollection(owner, name, description, prefix);41 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;4243 const collection = helper.nft.getCollectionObject(collectionId);44 const data = (await collection.getData())!;45 46 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);47 expect(collectionId).to.be.eq(collectionCountAfter);48 expect(data.name).to.be.eq(name);49 expect(data.description).to.be.eq(description);50 expect(data.raw.tokenPrefix).to.be.eq(prefix);51 expect(data.raw.mode).to.be.eq('NFT');52 });5354 // todo:playgrounds this test will fail when in async environment.55 itEth('Check collection address exist', async ({helper}) => {56 const owner = await helper.eth.createAccountWithBalance(donor);5758 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;59 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);60 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);6162 expect(await collectionHelpers.methods63 .isCollectionExist(expectedCollectionAddress)64 .call()).to.be.false;6566 await collectionHelpers.methods67 .createNFTCollection('A', 'A', 'A')68 .send({value: Number(2n * helper.balance.getOneTokenNominal())});69 70 expect(await collectionHelpers.methods71 .isCollectionExist(expectedCollectionAddress)72 .call()).to.be.true;73 });74 75 itEth('Set sponsorship', async ({helper}) => {76 const owner = await helper.eth.createAccountWithBalance(donor);77 const sponsor = await helper.eth.createAccountWithBalance(donor);78 const ss58Format = helper.chain.getChainProperties().ss58Format;79 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');8081 const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);82 await collection.methods.setCollectionSponsor(sponsor).send();8384 let data = (await helper.nft.getData(collectionId))!;85 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));8687 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');8889 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);90 await sponsorCollection.methods.confirmCollectionSponsorship().send();9192 data = (await helper.nft.getData(collectionId))!;93 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));94 });9596 itEth('Set limits', async ({helper}) => {97 const owner = await helper.eth.createAccountWithBalance(donor);98 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'FLO');99 const limits = {100 accountTokenOwnershipLimit: 1000,101 sponsoredDataSize: 1024,102 sponsoredDataRateLimit: 30,103 tokenLimit: 1000000,104 sponsorTransferTimeout: 6,105 sponsorApproveTimeout: 6,106 ownerCanTransfer: false,107 ownerCanDestroy: false,108 transfersEnabled: false,109 };110111 const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);112 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();113 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();114 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();115 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();116 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();117 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();118 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();119 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();120 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();121 122 const data = (await helper.nft.getData(collectionId))!;123 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);124 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);125 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);126 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);127 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);128 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);129 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);130 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);131 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);132 });133134 itEth('Collection address exist', async ({helper}) => {135 const owner = await helper.eth.createAccountWithBalance(donor);136 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';137 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)138 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())139 .to.be.false;140 141 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Exister', 'absolutely anything', 'EVC');142 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)143 .methods.isCollectionExist(collectionAddress).call())144 .to.be.true;145 });146});147148describe('(!negative tests!) Create NFT collection from EVM', () => {149 let donor: IKeyringPair;150 let nominal: bigint;151152 before(async function() {153 await usingEthPlaygrounds(async (helper, privateKey) => {154 donor = privateKey('//Alice');155 nominal = helper.balance.getOneTokenNominal();156 });157 });158159 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {160 const owner = await helper.eth.createAccountWithBalance(donor);161 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);162 {163 const MAX_NAME_LENGTH = 64;164 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);165 const description = 'A';166 const tokenPrefix = 'A';167168 await expect(collectionHelper.methods169 .createNFTCollection(collectionName, description, tokenPrefix)170 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);171 172 }173 {174 const MAX_DESCRIPTION_LENGTH = 256;175 const collectionName = 'A';176 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);177 const tokenPrefix = 'A';178 await expect(collectionHelper.methods179 .createNFTCollection(collectionName, description, tokenPrefix)180 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);181 }182 {183 const MAX_TOKEN_PREFIX_LENGTH = 16;184 const collectionName = 'A';185 const description = 'A';186 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);187 await expect(collectionHelper.methods188 .createNFTCollection(collectionName, description, tokenPrefix)189 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);190 }191 });192 193 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {194 const owner = await helper.eth.createAccountWithBalance(donor);195 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);196 await expect(collectionHelper.methods197 .createNFTCollection('Peasantry', 'absolutely anything', 'CVE')198 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');199 });200201 itEth('(!negative test!) Check owner', async ({helper}) => {202 const owner = await helper.eth.createAccountWithBalance(donor);203 const malfeasant = helper.eth.createAccount();204 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');205 const malfeasantCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant);206 const EXPECTED_ERROR = 'NoPermission';207 {208 const sponsor = await helper.eth.createAccountWithBalance(donor);209 await expect(malfeasantCollection.methods210 .setCollectionSponsor(sponsor)211 .call()).to.be.rejectedWith(EXPECTED_ERROR);212 213 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);214 await expect(sponsorCollection.methods215 .confirmCollectionSponsorship()216 .call()).to.be.rejectedWith('caller is not set as sponsor');217 }218 {219 await expect(malfeasantCollection.methods220 .setCollectionLimit('account_token_ownership_limit', '1000')221 .call()).to.be.rejectedWith(EXPECTED_ERROR);222 }223 });224225 itEth('(!negative test!) Set limits', async ({helper}) => {226 const owner = await helper.eth.createAccountWithBalance(donor);227 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');228 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);229 await expect(collectionEvm.methods230 .setCollectionLimit('badLimit', 'true')231 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');232 });233});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {evmToAddress} from '@polkadot/util-crypto';18import {IKeyringPair} from '@polkadot/types/types';19import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';202122describe('Create NFT collection from EVM', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (_helper, privateKey) => {27 donor = privateKey('//Alice');28 });29 });3031 itEth('Create collection', async ({helper}) => {32 const owner = await helper.eth.createAccountWithBalance(donor);3334 const name = 'CollectionEVM';35 const description = 'Some description';36 const prefix = 'token prefix';3738 // todo:playgrounds this might fail when in async environment.39 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;40 const {collectionId} = await helper.eth.createNFTCollection(owner, name, description, prefix);41 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;4243 const collection = helper.nft.getCollectionObject(collectionId);44 const data = (await collection.getData())!;45 46 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);47 expect(collectionId).to.be.eq(collectionCountAfter);48 expect(data.name).to.be.eq(name);49 expect(data.description).to.be.eq(description);50 expect(data.raw.tokenPrefix).to.be.eq(prefix);51 expect(data.raw.mode).to.be.eq('NFT');5253 const options = await collection.getOptions();5455 expect(options.tokenPropertyPermissions).to.be.empty;56 });5758 itEth('Create collection with properties', async ({helper}) => {59 const owner = await helper.eth.createAccountWithBalance(donor);6061 const name = 'CollectionEVM';62 const description = 'Some description';63 const prefix = 'token prefix';64 const baseUri = 'BaseURI';6566 // todo:playgrounds this might fail when in async environment.67 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;68 const {collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri);69 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;7071 const collection = helper.nft.getCollectionObject(collectionId);72 const data = (await collection.getData())!;73 74 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);75 expect(collectionId).to.be.eq(collectionCountAfter);76 expect(data.name).to.be.eq(name);77 expect(data.description).to.be.eq(description);78 expect(data.raw.tokenPrefix).to.be.eq(prefix);79 expect(data.raw.mode).to.be.eq('NFT');8081 const options = await collection.getOptions();82 expect(options.tokenPropertyPermissions).to.be.deep.equal([83 {84 key: 'URI',85 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},86 },87 {88 key: 'URISuffix',89 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},90 },91 ]);92 });9394 // todo:playgrounds this test will fail when in async environment.95 itEth('Check collection address exist', async ({helper}) => {96 const owner = await helper.eth.createAccountWithBalance(donor);9798 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;99 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);100 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);101102 expect(await collectionHelpers.methods103 .isCollectionExist(expectedCollectionAddress)104 .call()).to.be.false;105106 await collectionHelpers.methods107 .createNFTCollection('A', 'A', 'A')108 .send({value: Number(2n * helper.balance.getOneTokenNominal())});109 110 expect(await collectionHelpers.methods111 .isCollectionExist(expectedCollectionAddress)112 .call()).to.be.true;113 });114 115 itEth('Set sponsorship', async ({helper}) => {116 const owner = await helper.eth.createAccountWithBalance(donor);117 const sponsor = await helper.eth.createAccountWithBalance(donor);118 const ss58Format = helper.chain.getChainProperties().ss58Format;119 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');120121 const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);122 await collection.methods.setCollectionSponsor(sponsor).send();123124 let data = (await helper.nft.getData(collectionId))!;125 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));126127 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');128129 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);130 await sponsorCollection.methods.confirmCollectionSponsorship().send();131132 data = (await helper.nft.getData(collectionId))!;133 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));134 });135136 itEth('Set limits', async ({helper}) => {137 const owner = await helper.eth.createAccountWithBalance(donor);138 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'FLO');139 const limits = {140 accountTokenOwnershipLimit: 1000,141 sponsoredDataSize: 1024,142 sponsoredDataRateLimit: 30,143 tokenLimit: 1000000,144 sponsorTransferTimeout: 6,145 sponsorApproveTimeout: 6,146 ownerCanTransfer: false,147 ownerCanDestroy: false,148 transfersEnabled: false,149 };150151 const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);152 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();153 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();154 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();155 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();156 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();157 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();158 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();159 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();160 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();161 162 const data = (await helper.nft.getData(collectionId))!;163 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);164 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);165 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);166 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);167 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);168 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);169 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);170 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);171 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);172 });173174 itEth('Collection address exist', async ({helper}) => {175 const owner = await helper.eth.createAccountWithBalance(donor);176 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';177 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)178 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())179 .to.be.false;180 181 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Exister', 'absolutely anything', 'EVC');182 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)183 .methods.isCollectionExist(collectionAddress).call())184 .to.be.true;185 });186});187188describe('(!negative tests!) Create NFT collection from EVM', () => {189 let donor: IKeyringPair;190 let nominal: bigint;191192 before(async function() {193 await usingEthPlaygrounds(async (helper, privateKey) => {194 donor = privateKey('//Alice');195 nominal = helper.balance.getOneTokenNominal();196 });197 });198199 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {200 const owner = await helper.eth.createAccountWithBalance(donor);201 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);202 {203 const MAX_NAME_LENGTH = 64;204 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);205 const description = 'A';206 const tokenPrefix = 'A';207208 await expect(collectionHelper.methods209 .createNFTCollection(collectionName, description, tokenPrefix)210 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);211 212 }213 {214 const MAX_DESCRIPTION_LENGTH = 256;215 const collectionName = 'A';216 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);217 const tokenPrefix = 'A';218 await expect(collectionHelper.methods219 .createNFTCollection(collectionName, description, tokenPrefix)220 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);221 }222 {223 const MAX_TOKEN_PREFIX_LENGTH = 16;224 const collectionName = 'A';225 const description = 'A';226 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);227 await expect(collectionHelper.methods228 .createNFTCollection(collectionName, description, tokenPrefix)229 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);230 }231 });232 233 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {234 const owner = await helper.eth.createAccountWithBalance(donor);235 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);236 await expect(collectionHelper.methods237 .createNFTCollection('Peasantry', 'absolutely anything', 'CVE')238 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');239 });240241 itEth('(!negative test!) Check owner', async ({helper}) => {242 const owner = await helper.eth.createAccountWithBalance(donor);243 const malfeasant = helper.eth.createAccount();244 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');245 const malfeasantCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant);246 const EXPECTED_ERROR = 'NoPermission';247 {248 const sponsor = await helper.eth.createAccountWithBalance(donor);249 await expect(malfeasantCollection.methods250 .setCollectionSponsor(sponsor)251 .call()).to.be.rejectedWith(EXPECTED_ERROR);252 253 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);254 await expect(sponsorCollection.methods255 .confirmCollectionSponsorship()256 .call()).to.be.rejectedWith('caller is not set as sponsor');257 }258 {259 await expect(malfeasantCollection.methods260 .setCollectionLimit('account_token_ownership_limit', '1000')261 .call()).to.be.rejectedWith(EXPECTED_ERROR);262 }263 });264265 itEth('(!negative test!) Set limits', async ({helper}) => {266 const owner = await helper.eth.createAccountWithBalance(donor);267 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');268 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);269 await expect(collectionEvm.methods270 .setCollectionLimit('badLimit', 'true')271 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');272 });273});tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -42,7 +42,8 @@
const {collectionId} = await helper.eth.createRFTCollection(owner, name, description, prefix);
const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
- const data = (await helper.rft.getData(collectionId))!;
+ const collection = helper.rft.getCollectionObject(collectionId);
+ const data = (await collection.getData())!;
expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
expect(collectionId).to.be.eq(collectionCountAfter);
@@ -50,6 +51,48 @@
expect(data.description).to.be.eq(description);
expect(data.raw.tokenPrefix).to.be.eq(prefix);
expect(data.raw.mode).to.be.eq('ReFungible');
+
+ const options = await collection.getOptions();
+
+ expect(options.tokenPropertyPermissions).to.be.empty;
+ });
+
+
+
+ itEth('Create collection with properties', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const name = 'CollectionEVM';
+ const description = 'Some description';
+ const prefix = 'token prefix';
+ const baseUri = 'BaseURI';
+
+ // todo:playgrounds this might fail when in async environment.
+ const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
+ const {collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, name, description, prefix, baseUri);
+ const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
+
+ const collection = helper.rft.getCollectionObject(collectionId);
+ const data = (await collection.getData())!;
+
+ expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
+ expect(collectionId).to.be.eq(collectionCountAfter);
+ expect(data.name).to.be.eq(name);
+ expect(data.description).to.be.eq(description);
+ expect(data.raw.tokenPrefix).to.be.eq(prefix);
+ expect(data.raw.mode).to.be.eq('ReFungible');
+
+ const options = await collection.getOptions();
+ expect(options.tokenPropertyPermissions).to.be.deep.equal([
+ {
+ key: 'URI',
+ permission: {mutable: true, collectionAdmin: true, tokenOwner: false},
+ },
+ {
+ key: 'URISuffix',
+ permission: {mutable: true, collectionAdmin: true, tokenOwner: false},
+ },
+ ]);
});
// todo:playgrounds this test will fail when in async environment.