git.delta.rocks / unique-network / refs/commits / 1ada10d29826

difftreelog

added tests for `createRTCollection` , refactor `Unique` pallet code

PraetorP2022-10-24parent: #ac8dcbb.patch.diff
in: master

9 files changed

modifiedpallets/unique/CHANGELOG.mddiffbeforeafterboth
88
9### Changes9### Changes
1010
11- Addded **CollectionHelpers** method `destroyCollection`.11- Added `destroyCollection` and `createFTCollection` methods to **CollectionHelpers**.
1212
13## [v0.2.0] 2022-09-1313## [v0.2.0] 2022-09-13
1414
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
1818
19use core::marker::PhantomData;19use core::marker::PhantomData;
20use ethereum as _;20use ethereum as _;
21use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*};21use evm_coder::{execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
22use frame_support::traits::Get;22use frame_support::traits::Get;
2323
24use crate::Pallet;24use crate::Pallet;
27 CollectionById,27 CollectionById,
28 dispatch::CollectionDispatch,28 dispatch::CollectionDispatch,
29 erc::{29 erc::{
30 CollectionHelpersEvents,
31 static_property::{key},30 static_property::key,
31 CollectionHelpersEvents,
32 },32 },
33 Pallet as PalletCommon,33 Pallet as PalletCommon,
34
34};35};
35use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
36use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};36use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
37use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
37use sp_std::vec;38use sp_std::vec;
38use up_data_structs::{39use up_data_structs::{
39 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,40 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
40 CollectionMode, PropertyValue,41 CreateCollectionData, PropertyValue,
41};42};
4243
43use crate::{Config, SelfWeightOf, weights::WeightInfo};44use crate::{weights::WeightInfo, Config, SelfWeightOf};
4445
46use alloc::format;
45use sp_std::vec::Vec;47use sp_std::vec::Vec;
46use alloc::format;
4748
48/// See [`CollectionHelpersCall`]49/// See [`CollectionHelpersCall`]
49pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);50pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);
104 )105 )
105}106}
106107
108#[inline(always)]
107fn create_collection_internal<T: Config>(109fn create_collection_internal<T: Config>(
108 caller: caller,110 caller: caller,
109 value: value,111 value: value,
212 description: string,214 description: string,
213 token_prefix: string,215 token_prefix: string,
214 ) -> Result<address> {216 ) -> Result<address> {
215 self.create_nft_collection(caller, value, name, description, token_prefix)217 create_collection_internal::<T>(
218 caller,
219 value,
220 name,
221 CollectionMode::NFT,
222 description,
223 token_prefix,
224 )
216 }225 }
217226
225 description: string,234 description: string,
226 token_prefix: string,235 token_prefix: string,
227 ) -> Result<address> {236 ) -> Result<address> {
228 create_refungible_collection_internal::<T>(caller, value, name, description, token_prefix)237 create_collection_internal::<T>(
238 caller,
239 value,
240 name,
241 CollectionMode::ReFungible,
242 description,
243 token_prefix,
244 )
229 }245 }
246
247 #[weight(<SelfWeightOf<T>>::create_collection())]
248 #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]
249 fn create_refungible_collection_with_properties(
250 &mut self,
251 caller: caller,
252 value: value,
253 name: string,
254 description: string,
255 token_prefix: string,
256 base_uri: string,
257 ) -> Result<address> {
258 create_collection_internal::<T>(
259 caller,
260 value,
261 name,
262 CollectionMode::ReFungible,
263 description,
264 token_prefix,
265 )
266 }
230267
231 #[weight(<SelfWeightOf<T>>::create_collection())]268 #[weight(<SelfWeightOf<T>>::create_collection())]
232 #[solidity(rename_selector = "createRTCollection")]269 #[solidity(rename_selector = "createFTCollection")]
233 fn create_fungible_collection(270 fn create_fungible_collection(
234 &mut self,271 &mut self,
235 caller: caller,272 caller: caller,
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
24}24}
2525
26/// @title Contract, which allows users to operate with collections26/// @title Contract, which allows users to operate with collections
27/// @dev the ERC-165 identifier for this interface is 0xa2c196ab27/// @dev the ERC-165 identifier for this interface is 0xd8b36039
28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
29 /// Create an NFT collection29 /// Create an NFT collection
30 /// @param name Name of the collection30 /// @param name Name of the collection
77 return 0x0000000000000000000000000000000000000000;77 return 0x0000000000000000000000000000000000000000;
78 }78 }
7979
80 /// @dev EVM selector for this function is: 0xac1e2285,80 /// @dev EVM selector for this function is: 0xa5596388,
81 /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
82 function createERC721MetadataCompatibleRFTCollection(
83 string memory name,
84 string memory description,
85 string memory tokenPrefix,
86 string memory baseUri
87 ) public payable returns (address) {
88 require(false, stub_error);
89 name;
90 description;
91 tokenPrefix;
92 baseUri;
93 dummy = 0;
94 return 0x0000000000000000000000000000000000000000;
95 }
96
97 /// @dev EVM selector for this function is: 0x7335b79f,
81 /// or in textual repr: createRTCollection(string,uint8,string,string)98 /// or in textual repr: createFTCollection(string,uint8,string,string)
82 function createRTCollection(99 function createFTCollection(
83 string memory name,100 string memory name,
84 uint8 decimals,101 uint8 decimals,
85 string memory description,102 string memory description,
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
19}19}
2020
21/// @title Contract, which allows users to operate with collections21/// @title Contract, which allows users to operate with collections
22/// @dev the ERC-165 identifier for this interface is 0xa2c196ab22/// @dev the ERC-165 identifier for this interface is 0xd8b36039
23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
24 /// Create an NFT collection24 /// Create an NFT collection
25 /// @param name Name of the collection25 /// @param name Name of the collection
51 string memory tokenPrefix51 string memory tokenPrefix
52 ) external payable returns (address);52 ) external payable returns (address);
5353
54 /// @dev EVM selector for this function is: 0xac1e2285,54 /// @dev EVM selector for this function is: 0xa5596388,
55 /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
56 function createERC721MetadataCompatibleRFTCollection(
57 string memory name,
58 string memory description,
59 string memory tokenPrefix,
60 string memory baseUri
61 ) external payable returns (address);
62
63 /// @dev EVM selector for this function is: 0x7335b79f,
55 /// or in textual repr: createRTCollection(string,uint8,string,string)64 /// or in textual repr: createFTCollection(string,uint8,string,string)
56 function createRTCollection(65 function createFTCollection(
57 string memory name,66 string memory name,
58 uint8 decimals,67 uint8 decimals,
59 string memory description,68 string memory description,
modifiedtests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth
38 "stateMutability": "view",38 "stateMutability": "view",
39 "type": "function"39 "type": "function"
40 },40 },
41 {
42 "inputs": [
43 { "internalType": "string", "name": "name", "type": "string" },
44 { "internalType": "string", "name": "description", "type": "string" },
45 { "internalType": "string", "name": "tokenPrefix", "type": "string" },
46 { "internalType": "string", "name": "baseUri", "type": "string" }
47 ],
48 "name": "createERC721MetadataCompatibleRFTCollection",
49 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
50 "stateMutability": "payable",
51 "type": "function"
52 },
53 {
54 "inputs": [
55 { "internalType": "string", "name": "name", "type": "string" },
56 { "internalType": "uint8", "name": "decimals", "type": "uint8" },
57 { "internalType": "string", "name": "description", "type": "string" },
58 { "internalType": "string", "name": "tokenPrefix", "type": "string" }
59 ],
60 "name": "createFTCollection",
61 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
62 "stateMutability": "payable",
63 "type": "function"
64 },
41 {65 {
42 "inputs": [66 "inputs": [
43 { "internalType": "string", "name": "name", "type": "string" },67 { "internalType": "string", "name": "name", "type": "string" },
60 "stateMutability": "payable",84 "stateMutability": "payable",
61 "type": "function"85 "type": "function"
62 },86 },
63 {
64 "inputs": [
65 { "internalType": "string", "name": "name", "type": "string" },
66 { "internalType": "uint8", "name": "decimals", "type": "uint8" },
67 { "internalType": "string", "name": "description", "type": "string" },
68 { "internalType": "string", "name": "tokenPrefix", "type": "string" }
69 ],
70 "name": "createRTCollection",
71 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
72 "stateMutability": "payable",
73 "type": "function"
74 },
75 {87 {
76 "inputs": [88 "inputs": [
77 {89 {
modifiedtests/src/eth/createFTCollection.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import { evmToAddress } from '@polkadot/util-crypto';
18import {Pallets, requirePalletsOrSkip} from '../util';19import {Pallets, requirePalletsOrSkip} from '../util';
19import {expect, itEth, usingEthPlaygrounds} from './util';20import {expect, itEth, usingEthPlaygrounds} from './util';
2021
2526
26 before(async function() {27 before(async function() {
27 await usingEthPlaygrounds(async (helper, privateKey) => {28 await usingEthPlaygrounds(async (helper, privateKey) => {
28 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);29 requirePalletsOrSkip(this, helper, [Pallets.Fungible]);
29 donor = await privateKey('//Alice');30 donor = await privateKey('//Alice');
30 });31 });
31 });32 });
40 // todo:playgrounds this might fail when in async environment.41 // todo:playgrounds this might fail when in async environment.
41 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;42 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
42 43
43 const collectionCreationPrice = helper.balance.getCollectionCreationPrice();
44 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
45
46 const result = await collectionHelper.methods.createRTCollection(name, DECIMALS, description, prefix).call({value: Number(collectionCreationPrice)});
47 console.log(result);
48 const {collectionId} = await helper.eth.createFungibleCollection(owner, name, DECIMALS, description, prefix);44 const {collectionId} = await helper.eth.createFungibleCollection(owner, name, DECIMALS, description, prefix);
45
49 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;46 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
58 expect(data.raw.mode).to.be.deep.eq({Fungible: DECIMALS.toString()});54 expect(data.raw.mode).to.be.deep.eq({Fungible: DECIMALS.toString()});
59 });55 });
6056
61 // // todo:playgrounds this test will fail when in async environment.57 // todo:playgrounds this test will fail when in async environment.
62 // itEth('Check collection address exist', async ({helper}) => {58 itEth('Check collection address exist', async ({helper}) => {
63 // const owner = await helper.eth.createAccountWithBalance(donor);59 const owner = await helper.eth.createAccountWithBalance(donor);
6460
65 // const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;61 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
66 // const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);62 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
67 // const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);63 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
6864
69 // expect(await collectionHelpers.methods65 expect(await collectionHelpers.methods
70 // .isCollectionExist(expectedCollectionAddress)66 .isCollectionExist(expectedCollectionAddress)
71 // .call()).to.be.false;67 .call()).to.be.false;
7268
73 // await collectionHelpers.methods69
74 // .createRFTCollection('A', 'A', 'A')70 await helper.eth.createFungibleCollection(owner, 'A', DECIMALS, 'A', 'A');
75 // .send({value: Number(2n * helper.balance.getOneTokenNominal())});71
76 72
77 // expect(await collectionHelpers.methods73 expect(await collectionHelpers.methods
78 // .isCollectionExist(expectedCollectionAddress)74 .isCollectionExist(expectedCollectionAddress)
79 // .call()).to.be.true;75 .call()).to.be.true;
80 // });76 });
81 77
82 // itEth('Set sponsorship', async ({helper}) => {78 itEth('Set sponsorship', async ({helper}) => {
83 // const owner = await helper.eth.createAccountWithBalance(donor);79 const owner = await helper.eth.createAccountWithBalance(donor);
84 // const sponsor = await helper.eth.createAccountWithBalance(donor);80 const sponsor = await helper.eth.createAccountWithBalance(donor);
85 // const ss58Format = helper.chain.getChainProperties().ss58Format;81 const ss58Format = helper.chain.getChainProperties().ss58Format;
86 // const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');82 const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Sponsor', DECIMALS, 'absolutely anything', 'ENVY');
8783
88 // const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);84 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
89 // await collection.methods.setCollectionSponsor(sponsor).send();85 await collection.methods.setCollectionSponsor(sponsor).send();
9086
91 // let data = (await helper.rft.getData(collectionId))!;87 let data = (await helper.rft.getData(collectionId))!;
92 // expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));88 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
9389
94 // await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');90 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
9591
96 // const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);92 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
97 // await sponsorCollection.methods.confirmCollectionSponsorship().send();93 await sponsorCollection.methods.confirmCollectionSponsorship().send();
9894
99 // data = (await helper.rft.getData(collectionId))!;95 data = (await helper.rft.getData(collectionId))!;
100 // expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));96 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
101 // });97 });
10298
103 // itEth('Set limits', async ({helper}) => {99 itEth('Set limits', async ({helper}) => {
104 // const owner = await helper.eth.createAccountWithBalance(donor);100 const owner = await helper.eth.createAccountWithBalance(donor);
105 // const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'INSI');101 const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'INSI');
106 // const limits = {102 const limits = {
107 // accountTokenOwnershipLimit: 1000,103 accountTokenOwnershipLimit: 1000,
108 // sponsoredDataSize: 1024,104 sponsoredDataSize: 1024,
109 // sponsoredDataRateLimit: 30,105 sponsoredDataRateLimit: 30,
110 // tokenLimit: 1000000,106 tokenLimit: 1000000,
111 // sponsorTransferTimeout: 6,107 sponsorTransferTimeout: 6,
112 // sponsorApproveTimeout: 6,108 sponsorApproveTimeout: 6,
113 // ownerCanTransfer: false,109 ownerCanTransfer: false,
114 // ownerCanDestroy: false,110 ownerCanDestroy: false,
115 // transfersEnabled: false,111 transfersEnabled: false,
116 // };112 };
117113
118 // const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);114 const collection = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
119 // await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();115 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
120 // await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();116 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();
121 // await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();117 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
122 // await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();118 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();
123 // await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();119 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
124 // await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();120 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
125 // await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();121 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();
126 // await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();122 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();
127 // await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();123 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();
128 124
129 // const data = (await helper.rft.getData(collectionId))!;125 const data = (await helper.rft.getData(collectionId))!;
130 // expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);126 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);
131 // expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);127 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);
132 // expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);128 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);
133 // expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);129 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);
134 // expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);130 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);
135 // expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);131 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);
136 // expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);132 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);
137 // expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);133 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);
138 // expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);134 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);
139 // });135 });
140136
141 // itEth('Collection address exist', async ({helper}) => {137 itEth('Collection address exist', async ({helper}) => {
142 // const owner = await helper.eth.createAccountWithBalance(donor);138 const owner = await helper.eth.createAccountWithBalance(donor);
143 // const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';139 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
144 // expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)140 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)
145 // .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())141 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
146 // .to.be.false;142 .to.be.false;
147 143
148 // const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Exister', 'absolutely anything', 'WIWT');144 const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
149 // expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)145 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)
150 // .methods.isCollectionExist(collectionAddress).call())146 .methods.isCollectionExist(collectionAddress).call())
151 // .to.be.true;147 .to.be.true;
152 // });148 });
149
150 itEth('destroyCollection', async ({helper}) => {
151 const owner = await helper.eth.createAccountWithBalance(donor);
152 const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
153 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
154
155 const result = await collectionHelper.methods
156 .destroyCollection(collectionAddress)
157 .send({from: owner});
158
159 const events = helper.eth.normalizeEvents(result.events);
160
161 expect(events).to.be.deep.equal([
162 {
163 address: collectionHelper.options.address,
164 event: 'CollectionDestroyed',
165 args: {
166 collectionId: collectionAddress,
167 },
168 },
169 ]);
170
171 expect(await collectionHelper.methods
172 .isCollectionExist(collectionAddress)
173 .call()).to.be.false;
174 });
153});175});
154176
155// describe('(!negative tests!) Create RFT collection from EVM', () => {177describe('(!negative tests!) Create FT collection from EVM', () => {
156// let donor: IKeyringPair;178 let donor: IKeyringPair;
157// let nominal: bigint;179 let nominal: bigint;
158180
159// before(async function() {181 before(async function() {
160// await usingEthPlaygrounds(async (helper, privateKey) => {182 await usingEthPlaygrounds(async (helper, privateKey) => {
161// requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);183 requirePalletsOrSkip(this, helper, [Pallets.Fungible]);
162// donor = privateKey('//Alice');184 donor = await privateKey('//Alice');
163// nominal = helper.balance.getOneTokenNominal();185 nominal = helper.balance.getOneTokenNominal();
164// });186 });
165// });187 });
166188
167// itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {189 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
168// const owner = await helper.eth.createAccountWithBalance(donor);190 const owner = await helper.eth.createAccountWithBalance(donor);
169// const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);191 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
170// {192 {
171// const MAX_NAME_LENGTH = 64;193 const MAX_NAME_LENGTH = 64;
172// const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);194 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
173// const description = 'A';195 const description = 'A';
174// const tokenPrefix = 'A';196 const tokenPrefix = 'A';
175197
176// await expect(collectionHelper.methods198 await expect(collectionHelper.methods
177// .createRFTCollection(collectionName, description, tokenPrefix)199 .createFTCollection(collectionName, DECIMALS, description, tokenPrefix)
178// .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);200 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
179// }201 }
180// {202 {
181// const MAX_DESCRIPTION_LENGTH = 256;203 const MAX_DESCRIPTION_LENGTH = 256;
182// const collectionName = 'A';204 const collectionName = 'A';
183// const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);205 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);
184// const tokenPrefix = 'A';206 const tokenPrefix = 'A';
185// await expect(collectionHelper.methods207 await expect(collectionHelper.methods
186// .createRFTCollection(collectionName, description, tokenPrefix)208 .createFTCollection(collectionName, DECIMALS, description, tokenPrefix)
187// .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);209 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
188// }210 }
189// {211 {
190// const MAX_TOKEN_PREFIX_LENGTH = 16;212 const MAX_TOKEN_PREFIX_LENGTH = 16;
191// const collectionName = 'A';213 const collectionName = 'A';
192// const description = 'A';214 const description = 'A';
193// const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);215 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
194// await expect(collectionHelper.methods216 await expect(collectionHelper.methods
195// .createRFTCollection(collectionName, description, tokenPrefix)217 .createFTCollection(collectionName, DECIMALS, description, tokenPrefix)
196// .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);218 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
197// }219 }
198// });220 });
199 221
200// itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {222 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
201// const owner = await helper.eth.createAccountWithBalance(donor);223 const owner = await helper.eth.createAccountWithBalance(donor);
202// const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);224 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
203// await expect(collectionHelper.methods225 await expect(collectionHelper.methods
204// .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')226 .createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
205// .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');227 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
206// });228 });
207229
208// itEth('(!negative test!) Check owner', async ({helper}) => {230 itEth('(!negative test!) Check owner', async ({helper}) => {
209// const owner = await helper.eth.createAccountWithBalance(donor);231 const owner = await helper.eth.createAccountWithBalance(donor);
210// const peasant = helper.eth.createAccount();232 const peasant = helper.eth.createAccount();
211// const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');233 const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Transgressed', DECIMALS, 'absolutely anything', 'YVNE');
212// const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);234 const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', peasant);
213// const EXPECTED_ERROR = 'NoPermission';235 const EXPECTED_ERROR = 'NoPermission';
214// {236 {
215// const sponsor = await helper.eth.createAccountWithBalance(donor);237 const sponsor = await helper.eth.createAccountWithBalance(donor);
216// await expect(peasantCollection.methods238 await expect(peasantCollection.methods
217// .setCollectionSponsor(sponsor)239 .setCollectionSponsor(sponsor)
218// .call()).to.be.rejectedWith(EXPECTED_ERROR);240 .call()).to.be.rejectedWith(EXPECTED_ERROR);
219 241
220// const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);242 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor);
221// await expect(sponsorCollection.methods243 await expect(sponsorCollection.methods
222// .confirmCollectionSponsorship()244 .confirmCollectionSponsorship()
223// .call()).to.be.rejectedWith('caller is not set as sponsor');245 .call()).to.be.rejectedWith('caller is not set as sponsor');
224// }246 }
225// {247 {
226// await expect(peasantCollection.methods248 await expect(peasantCollection.methods
227// .setCollectionLimit('account_token_ownership_limit', '1000')249 .setCollectionLimit('account_token_ownership_limit', '1000')
228// .call()).to.be.rejectedWith(EXPECTED_ERROR);250 .call()).to.be.rejectedWith(EXPECTED_ERROR);
229// }251 }
230// });252 });
231253
232// itEth('(!negative test!) Set limits', async ({helper}) => {254 itEth('(!negative test!) Set limits', async ({helper}) => {
233// const owner = await helper.eth.createAccountWithBalance(donor);255 const owner = await helper.eth.createAccountWithBalance(donor);
234// const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'ISNI');256 const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'ISNI');
235// const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);257 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
236// await expect(collectionEvm.methods258 await expect(collectionEvm.methods
237// .setCollectionLimit('badLimit', 'true')259 .setCollectionLimit('badLimit', 'true')
238// .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');260 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');
239// });261 });
240 262});
241// itEth('destroyCollection test', async ({helper}) => {
242// const owner = await helper.eth.createAccountWithBalance(donor);
243// const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'OLF');
244// const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
245
246// await expect(collectionHelper.methods
247// .destroyCollection(collectionAddress)
248// .send({from: owner})).to.be.fulfilled;
249
250// expect(await collectionHelper.methods
251// .isCollectionExist(collectionAddress)
252// .call()).to.be.false;
253// });
254// });
255263
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
264 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');264 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');
265 });265 });
266 266
267 itEth('destroyCollection test', async ({helper}) => {267 itEth('destroyCollection', async ({helper}) => {
268 const owner = await helper.eth.createAccountWithBalance(donor);268 const owner = await helper.eth.createAccountWithBalance(donor);
269 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');269 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
270 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);270 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
210 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();210 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
211 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);211 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
212 212
213 const result = await collectionHelper.methods.createRTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});213 const result = await collectionHelper.methods.createFTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
214
215 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);214 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
216 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);215 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);