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.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -49,6 +49,46 @@
expect(data.description).to.be.eq(description);
expect(data.raw.tokenPrefix).to.be.eq(prefix);
expect(data.raw.mode).to.be.eq('NFT');
+
+ 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.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri);
+ const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
+
+ const collection = helper.nft.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('NFT');
+
+ 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.
tests/src/eth/createRFTCollection.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 {Pallets, requirePalletsOrSkip} from '../util/playgrounds';20import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';212223describe('Create RFT collection from EVM', () => {24 let donor: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);29 donor = privateKey('//Alice');30 });31 });3233 itEth('Create collection', async ({helper}) => {34 const owner = await helper.eth.createAccountWithBalance(donor);35 36 const name = 'CollectionEVM';37 const description = 'Some description';38 const prefix = 'token prefix';39 40 // todo:playgrounds this might fail when in async environment.41 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;42 const {collectionId} = await helper.eth.createRFTCollection(owner, name, description, prefix);43 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;44 45 const data = (await helper.rft.getData(collectionId))!;4647 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);48 expect(collectionId).to.be.eq(collectionCountAfter);49 expect(data.name).to.be.eq(name);50 expect(data.description).to.be.eq(description);51 expect(data.raw.tokenPrefix).to.be.eq(prefix);52 expect(data.raw.mode).to.be.eq('ReFungible');53 });5455 // todo:playgrounds this test will fail when in async environment.56 itEth('Check collection address exist', async ({helper}) => {57 const owner = await helper.eth.createAccountWithBalance(donor);5859 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;60 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);61 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);6263 expect(await collectionHelpers.methods64 .isCollectionExist(expectedCollectionAddress)65 .call()).to.be.false;6667 await collectionHelpers.methods68 .createRFTCollection('A', 'A', 'A')69 .send({value: Number(2n * helper.balance.getOneTokenNominal())});70 71 expect(await collectionHelpers.methods72 .isCollectionExist(expectedCollectionAddress)73 .call()).to.be.true;74 });75 76 itEth('Set sponsorship', async ({helper}) => {77 const owner = await helper.eth.createAccountWithBalance(donor);78 const sponsor = await helper.eth.createAccountWithBalance(donor);79 const ss58Format = helper.chain.getChainProperties().ss58Format;80 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');8182 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);83 await collection.methods.setCollectionSponsor(sponsor).send();8485 let data = (await helper.rft.getData(collectionId))!;86 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));8788 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');8990 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);91 await sponsorCollection.methods.confirmCollectionSponsorship().send();9293 data = (await helper.rft.getData(collectionId))!;94 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));95 });9697 itEth('Set limits', async ({helper}) => {98 const owner = await helper.eth.createAccountWithBalance(donor);99 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'INSI');100 const limits = {101 accountTokenOwnershipLimit: 1000,102 sponsoredDataSize: 1024,103 sponsoredDataRateLimit: 30,104 tokenLimit: 1000000,105 sponsorTransferTimeout: 6,106 sponsorApproveTimeout: 6,107 ownerCanTransfer: false,108 ownerCanDestroy: false,109 transfersEnabled: false,110 };111112 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);113 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();114 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();115 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();116 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();117 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();118 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();119 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();120 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();121 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();122 123 const data = (await helper.rft.getData(collectionId))!;124 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);125 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);126 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);127 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);128 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);129 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);130 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);131 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);132 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);133 });134135 itEth('Collection address exist', async ({helper}) => {136 const owner = await helper.eth.createAccountWithBalance(donor);137 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';138 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)139 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())140 .to.be.false;141 142 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Exister', 'absolutely anything', 'WIWT');143 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)144 .methods.isCollectionExist(collectionAddress).call())145 .to.be.true;146 });147});148149describe('(!negative tests!) Create RFT collection from EVM', () => {150 let donor: IKeyringPair;151 let nominal: bigint;152153 before(async function() {154 await usingEthPlaygrounds(async (helper, privateKey) => {155 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);156 donor = privateKey('//Alice');157 nominal = helper.balance.getOneTokenNominal();158 });159 });160161 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {162 const owner = await helper.eth.createAccountWithBalance(donor);163 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);164 {165 const MAX_NAME_LENGTH = 64;166 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);167 const description = 'A';168 const tokenPrefix = 'A';169170 await expect(collectionHelper.methods171 .createRFTCollection(collectionName, description, tokenPrefix)172 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);173 }174 {175 const MAX_DESCRIPTION_LENGTH = 256;176 const collectionName = 'A';177 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);178 const tokenPrefix = 'A';179 await expect(collectionHelper.methods180 .createRFTCollection(collectionName, description, tokenPrefix)181 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);182 }183 {184 const MAX_TOKEN_PREFIX_LENGTH = 16;185 const collectionName = 'A';186 const description = 'A';187 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);188 await expect(collectionHelper.methods189 .createRFTCollection(collectionName, description, tokenPrefix)190 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);191 }192 });193 194 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {195 const owner = await helper.eth.createAccountWithBalance(donor);196 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);197 await expect(collectionHelper.methods198 .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')199 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');200 });201202 itEth('(!negative test!) Check owner', async ({helper}) => {203 const owner = await helper.eth.createAccountWithBalance(donor);204 const peasant = helper.eth.createAccount();205 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');206 const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);207 const EXPECTED_ERROR = 'NoPermission';208 {209 const sponsor = await helper.eth.createAccountWithBalance(donor);210 await expect(peasantCollection.methods211 .setCollectionSponsor(sponsor)212 .call()).to.be.rejectedWith(EXPECTED_ERROR);213 214 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);215 await expect(sponsorCollection.methods216 .confirmCollectionSponsorship()217 .call()).to.be.rejectedWith('caller is not set as sponsor');218 }219 {220 await expect(peasantCollection.methods221 .setCollectionLimit('account_token_ownership_limit', '1000')222 .call()).to.be.rejectedWith(EXPECTED_ERROR);223 }224 });225226 itEth('(!negative test!) Set limits', async ({helper}) => {227 const owner = await helper.eth.createAccountWithBalance(donor);228 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'ISNI');229 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);230 await expect(collectionEvm.methods231 .setCollectionLimit('badLimit', 'true')232 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');233 });234});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 {Pallets, requirePalletsOrSkip} from '../util/playgrounds';20import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';212223describe('Create RFT collection from EVM', () => {24 let donor: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);29 donor = privateKey('//Alice');30 });31 });3233 itEth('Create collection', async ({helper}) => {34 const owner = await helper.eth.createAccountWithBalance(donor);35 36 const name = 'CollectionEVM';37 const description = 'Some description';38 const prefix = 'token prefix';39 40 // todo:playgrounds this might fail when in async environment.41 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;42 const {collectionId} = await helper.eth.createRFTCollection(owner, name, description, prefix);43 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;44 45 const collection = helper.rft.getCollectionObject(collectionId);46 const data = (await collection.getData())!;4748 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);49 expect(collectionId).to.be.eq(collectionCountAfter);50 expect(data.name).to.be.eq(name);51 expect(data.description).to.be.eq(description);52 expect(data.raw.tokenPrefix).to.be.eq(prefix);53 expect(data.raw.mode).to.be.eq('ReFungible');5455 const options = await collection.getOptions();5657 expect(options.tokenPropertyPermissions).to.be.empty;58 });5960 6162 itEth('Create collection with properties', async ({helper}) => {63 const owner = await helper.eth.createAccountWithBalance(donor);6465 const name = 'CollectionEVM';66 const description = 'Some description';67 const prefix = 'token prefix';68 const baseUri = 'BaseURI';6970 // todo:playgrounds this might fail when in async environment.71 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;72 const {collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, name, description, prefix, baseUri);73 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;7475 const collection = helper.rft.getCollectionObject(collectionId);76 const data = (await collection.getData())!;77 78 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);79 expect(collectionId).to.be.eq(collectionCountAfter);80 expect(data.name).to.be.eq(name);81 expect(data.description).to.be.eq(description);82 expect(data.raw.tokenPrefix).to.be.eq(prefix);83 expect(data.raw.mode).to.be.eq('ReFungible');8485 const options = await collection.getOptions();86 expect(options.tokenPropertyPermissions).to.be.deep.equal([87 {88 key: 'URI',89 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},90 },91 {92 key: 'URISuffix',93 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},94 },95 ]);96 });9798 // todo:playgrounds this test will fail when in async environment.99 itEth('Check collection address exist', async ({helper}) => {100 const owner = await helper.eth.createAccountWithBalance(donor);101102 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;103 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);104 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);105106 expect(await collectionHelpers.methods107 .isCollectionExist(expectedCollectionAddress)108 .call()).to.be.false;109110 await collectionHelpers.methods111 .createRFTCollection('A', 'A', 'A')112 .send({value: Number(2n * helper.balance.getOneTokenNominal())});113 114 expect(await collectionHelpers.methods115 .isCollectionExist(expectedCollectionAddress)116 .call()).to.be.true;117 });118 119 itEth('Set sponsorship', async ({helper}) => {120 const owner = await helper.eth.createAccountWithBalance(donor);121 const sponsor = await helper.eth.createAccountWithBalance(donor);122 const ss58Format = helper.chain.getChainProperties().ss58Format;123 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');124125 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);126 await collection.methods.setCollectionSponsor(sponsor).send();127128 let data = (await helper.rft.getData(collectionId))!;129 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));130131 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');132133 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);134 await sponsorCollection.methods.confirmCollectionSponsorship().send();135136 data = (await helper.rft.getData(collectionId))!;137 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));138 });139140 itEth('Set limits', async ({helper}) => {141 const owner = await helper.eth.createAccountWithBalance(donor);142 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'INSI');143 const limits = {144 accountTokenOwnershipLimit: 1000,145 sponsoredDataSize: 1024,146 sponsoredDataRateLimit: 30,147 tokenLimit: 1000000,148 sponsorTransferTimeout: 6,149 sponsorApproveTimeout: 6,150 ownerCanTransfer: false,151 ownerCanDestroy: false,152 transfersEnabled: false,153 };154155 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);156 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();157 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();158 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();159 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();160 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();161 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();162 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();163 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();164 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();165 166 const data = (await helper.rft.getData(collectionId))!;167 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);168 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);169 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);170 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);171 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);172 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);173 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);174 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);175 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);176 });177178 itEth('Collection address exist', async ({helper}) => {179 const owner = await helper.eth.createAccountWithBalance(donor);180 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';181 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)182 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())183 .to.be.false;184 185 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Exister', 'absolutely anything', 'WIWT');186 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)187 .methods.isCollectionExist(collectionAddress).call())188 .to.be.true;189 });190});191192describe('(!negative tests!) Create RFT collection from EVM', () => {193 let donor: IKeyringPair;194 let nominal: bigint;195196 before(async function() {197 await usingEthPlaygrounds(async (helper, privateKey) => {198 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);199 donor = privateKey('//Alice');200 nominal = helper.balance.getOneTokenNominal();201 });202 });203204 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {205 const owner = await helper.eth.createAccountWithBalance(donor);206 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);207 {208 const MAX_NAME_LENGTH = 64;209 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);210 const description = 'A';211 const tokenPrefix = 'A';212213 await expect(collectionHelper.methods214 .createRFTCollection(collectionName, description, tokenPrefix)215 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);216 }217 {218 const MAX_DESCRIPTION_LENGTH = 256;219 const collectionName = 'A';220 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);221 const tokenPrefix = 'A';222 await expect(collectionHelper.methods223 .createRFTCollection(collectionName, description, tokenPrefix)224 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);225 }226 {227 const MAX_TOKEN_PREFIX_LENGTH = 16;228 const collectionName = 'A';229 const description = 'A';230 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);231 await expect(collectionHelper.methods232 .createRFTCollection(collectionName, description, tokenPrefix)233 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);234 }235 });236 237 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {238 const owner = await helper.eth.createAccountWithBalance(donor);239 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);240 await expect(collectionHelper.methods241 .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')242 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');243 });244245 itEth('(!negative test!) Check owner', async ({helper}) => {246 const owner = await helper.eth.createAccountWithBalance(donor);247 const peasant = helper.eth.createAccount();248 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');249 const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);250 const EXPECTED_ERROR = 'NoPermission';251 {252 const sponsor = await helper.eth.createAccountWithBalance(donor);253 await expect(peasantCollection.methods254 .setCollectionSponsor(sponsor)255 .call()).to.be.rejectedWith(EXPECTED_ERROR);256 257 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);258 await expect(sponsorCollection.methods259 .confirmCollectionSponsorship()260 .call()).to.be.rejectedWith('caller is not set as sponsor');261 }262 {263 await expect(peasantCollection.methods264 .setCollectionLimit('account_token_ownership_limit', '1000')265 .call()).to.be.rejectedWith(EXPECTED_ERROR);266 }267 });268269 itEth('(!negative test!) Set limits', async ({helper}) => {270 const owner = await helper.eth.createAccountWithBalance(donor);271 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'ISNI');272 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);273 await expect(collectionEvm.methods274 .setCollectionLimit('badLimit', 'true')275 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');276 });277});