git.delta.rocks / unique-network / refs/commits / 792a004ac69c

difftreelog

createCollection migrated

rkv2022-09-12parent: #8df2058.patch.diff
in: master

1 file changed

modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
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 {expect} from 'chai';17import chai from 'chai';
18import chaiAsPromised from 'chai-as-promised';
18import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';19import {usingPlaygrounds} from './util/playgrounds';
20import {IKeyringPair} from '@polkadot/types/types';
19import {createCollectionWithPropsExpectFailure, createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo, createCollectionWithPropsExpectSuccess, requirePallets, Pallets} from './util/helpers';21import {IProperty} from './util/playgrounds/types';
22
23chai.use(chaiAsPromised);
24const expect = chai.expect;
25
26let donor: IKeyringPair;
27
28before(async () => {
29 await usingPlaygrounds(async (_, privateKey) => {
30 donor = privateKey('//Alice');
31 });
32});
33
34let alice: IKeyringPair;
2035
21describe('integration test: ext. createCollection():', () => {36describe('integration test: ext. createCollection():', () => {
37 before(async () => {
38 await usingPlaygrounds(async (helper) => {
39 [alice] = await helper.arrange.createAccounts([100n], donor);
40 });
41 });
22 it('Create new NFT collection', async () => {42 it('Create new NFT collection', async () => {
23 await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});43 await usingPlaygrounds(async (helper) => {
44 await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
45 });
24 });46 });
25 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {47 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {
26 await createCollectionExpectSuccess({name: 'A'.repeat(64)});48 await usingPlaygrounds(async (helper) => {
49 await helper.nft.mintCollection(alice, {name: 'A'.repeat(64), description: 'descr', tokenPrefix: 'COL'});
50 });
27 });51 });
28 it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {52 it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {
29 await createCollectionExpectSuccess({description: 'A'.repeat(256)});53 await usingPlaygrounds(async (helper) => {
54 await helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(256), tokenPrefix: 'COL'});
55 });
30 });56 });
31 it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {57 it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {
32 await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});58 await usingPlaygrounds(async (helper) => {
59 await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(16)});
60 });
33 });61 });
34 it('Create new Fungible collection', async () => {
35 await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
36 });
37 it('Create new ReFungible collection', async function() {
38 await requirePallets(this, [Pallets.ReFungible]);
39
40 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
41 });
42
43 it('create new collection with properties #1', async () => {62 it('Create new Fungible collection', async () => {
44 await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},63 await usingPlaygrounds(async (helper) => {
45 properties: [{key: 'key1', value: 'val1'}],
46 propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});64 await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 0);
65 });
47 });66 });
48
49 it('create new collection with properties #2', async () => {67 it('Create new ReFungible collection', async function() {
68 await usingPlaygrounds(async (helper) => {
50 await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},69 await helper.rft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
51 properties: [{key: 'key1', value: 'val1'}],
52 propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});
53 });70 });
71 });
5472
55 it('create new collection with properties #3', async () => {73 it('create new collection with properties', async () => {
56 await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'},74 await usingPlaygrounds(async (helper) => {
75 await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL',
57 properties: [{key: 'key1', value: 'val1'}],76 properties: [{key: 'key1', value: 'val1'}],
58 propPerm: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}]});77 tokenPropertyPermissions: [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}],
78 });
79 });
59 });80 });
6081
61 it('Create new collection with extra fields', async () => {82 it('Create new collection with extra fields', async () => {
62 await usingApi(async (api, privateKeyWrapper) => {83 await usingPlaygrounds(async (helper) => {
63 const alice = privateKeyWrapper('//Alice');
64 const bob = privateKeyWrapper('//Bob');
65 const tx = api.tx.unique.createCollectionEx({84 const collection = await helper.ft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'}, 8);
66 mode: {Fungible: 8},
67 permissions: {
68 access: 'AllowList',
69 },
70 name: [1],
71 description: [2],
72 tokenPrefix: '0x000000',
73 pendingSponsor: bob.address,
74 limits: {
75 accountTokenOwnershipLimit: 3,
76 },
77 });
78 const events = await submitTransactionAsync(alice, tx);85 await collection.setPermissions(alice, {access: 'AllowList'});
79 const result = getCreateCollectionResult(events);86 await collection.setLimits(alice, {accountTokenOwnershipLimit: 3});
80
81 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;87 const data = await collection.getData();
82 expect(collection.owner.toString()).to.equal(alice.address);88 const limits = await collection.getEffectiveLimits();
83 expect(collection.mode.asFungible.toNumber()).to.equal(8);89 const raw = data?.raw;
90
84 expect(collection.permissions.access.toHuman()).to.equal('AllowList');91 expect(data?.normalizedOwner).to.be.equal(alice.address);
85 expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);92 expect(data?.name).to.be.equal('name');
86 expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);93 expect(data?.description).to.be.equal('descr');
87 expect(collection.tokenPrefix.toString()).to.equal('0x000000');94 expect(raw.permissions.access).to.be.equal('AllowList');
88 expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);95 expect(raw.mode).to.be.deep.equal({Fungible: '8'});
89 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);96 expect(limits.accountTokenOwnershipLimit).to.be.equal(3);
90 });97 });
91 });98 });
9299
93 it('New collection is not external', async () => {100 it('New collection is not external', async () => {
94 await usingApi(async (api, privateKeyWrapper) => {101 await usingPlaygrounds(async (helper) => {
95 const alice = privateKeyWrapper('//Alice');
96 const tx = api.tx.unique.createCollectionEx({ });
97 const events = await submitTransactionAsync(alice, tx);102 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
98 const result = getCreateCollectionResult(events);
99
100 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;103 const data = await collection.getData();
101 expect(collection.readOnly.toHuman()).to.be.false;104 expect(data?.raw.readOnly).to.be.false;
102 });105 });
103 });106 });
104});107});
105108
106describe('(!negative test!) integration test: ext. createCollection():', () => {109describe('(!negative test!) integration test: ext. createCollection():', () => {
107 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {110 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
108 await createCollectionExpectFailure({name: 'A'.repeat(65), mode: {type: 'NFT'}});111 await usingPlaygrounds(async (helper) => {
112 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'A'.repeat(65), description: 'descr', tokenPrefix: 'COL'});
113 await expect(mintCollectionTx()).to.be.rejected;
114 });
109 });115 });
110 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {116 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {
111 await createCollectionExpectFailure({description: 'A'.repeat(257), mode: {type: 'NFT'}});117 await usingPlaygrounds(async (helper) => {
118 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'A'.repeat(257), tokenPrefix: 'COL'});
119 await expect(mintCollectionTx()).to.be.rejected;
120 });
112 });121 });
113 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {122 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {
114 await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});123 await usingPlaygrounds(async (helper) => {
124 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'A'.repeat(17)});
125 await expect(mintCollectionTx()).to.be.rejected;
126 });
115 });127 });
116 it('fails when bad limits are set', async () => {128 it('(!negative test!) fails when bad limits are set', async () => {
117 await usingApi(async (api, privateKeyWrapper) => {129 await usingPlaygrounds(async (helper) => {
118 const alice = privateKeyWrapper('//Alice');
119 const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});130 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', limits: {tokenLimit: 0}});
120 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);131 await expect(mintCollectionTx()).to.be.rejected;
121 });132 });
122 });133 });
123134
124 it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {135 it('(!negative test!) create collection with incorrect property limit (64 elements)', async () => {
125 const props = [];136 const props: IProperty[] = [];
126137
127 for (let i = 0; i < 65; i++) {138 for (let i = 0; i < 65; i++) {
128 props.push({key: `key${i}`, value: `value${i}`});139 props.push({key: `key${i}`, value: `value${i}`});
129 }140 }
130
131 await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});141 await usingPlaygrounds(async (helper) => {
142 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});
143 await expect(mintCollectionTx()).to.be.rejected;
144 });
132 });145 });
133146
134 it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {147 it('(!negative test!) create collection with incorrect property limit (40 kb)', async () => {
135 const props = [];148 const props: IProperty[] = [];
136149
137 for (let i = 0; i < 32; i++) {150 for (let i = 0; i < 32; i++) {
138 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});151 props.push({key: `key${i}`.repeat(80), value: `value${i}`.repeat(80)});
139 }152 }
140
141 await createCollectionWithPropsExpectFailure({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}, properties: props});153 await usingPlaygrounds(async (helper) => {
154 const mintCollectionTx = async () => helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL', properties: props});
155 await expect(mintCollectionTx()).to.be.rejected;
156 });
142 });157 });
143});158});