git.delta.rocks / unique-network / refs/commits / d4b692346f53

difftreelog

test add fungible and refungible to createMultipleItemsEx

Farhad Hakimov2022-07-01parent: #66c5541.patch.diff
in: master

1 file changed

modifiedtests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth
1616
17import {expect} from 'chai';17import {expect} from 'chai';
18import usingApi, {executeTransaction} from './substrate/substrate-api';18import usingApi, {executeTransaction} from './substrate/substrate-api';
19import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess} from './util/helpers';19import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, getBalance, getLastTokenId} from './util/helpers';
2020
21describe('createMultipleItemsEx', () => {21describe('Integration Test: createMultipleItemsEx', () => {
22 it('can initialize multiple NFT with different owners', async () => {22 it('can initialize multiple NFT with different owners', async () => {
23 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});23 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
24 await usingApi(async (api, privateKeyWrapper) => {24 await usingApi(async (api, privateKeyWrapper) => {
128 });128 });
129 });129 });
130130
131 it('can initialize fungible with multiple owners', async () => {
132 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
133 await usingApi(async (api, privateKeyWrapper) => {
134 const alice = privateKeyWrapper('//Alice');
135 const bob = privateKeyWrapper('//Bob');
136
137 const users = new Map();
138 users.set(JSON.stringify({Substrate: alice.address}), 50);
139 users.set(JSON.stringify({Substrate: bob.address}), 100);
140
141 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
142 Fungible: users,
143 }));
144
145 expect(await getBalance(api, collection, alice.address, 0)).to.equal(50n);
146 expect(await getBalance(api, collection, bob.address, 0)).to.equal(100n);
147 });
148 });
149
150 it('can initialize an RFT with multiple owners', async () => {
151 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
152 await usingApi(async (api, privateKeyWrapper) => {
153 const alice = privateKeyWrapper('//Alice');
154 const bob = privateKeyWrapper('//Bob');
155
156 const users = new Map();
157 users.set(JSON.stringify({Substrate: alice.address}), 1);
158 users.set(JSON.stringify({Substrate: bob.address}), 2);
159
160 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
161 RefungibleMultipleOwners: {
162 users: users,
163 },
164 }));
165
166 const itemsListIndexAfter = await getLastTokenId(api, collection);
167 expect(itemsListIndexAfter).to.be.equal(1);
168
169 expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n);
170 expect(await getBalance(api, collection, bob.address, 1)).to.be.equal(2n);
171 });
172 });
173
174 it('can initialize multiple RFTs with the same owner', async () => {
175 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
176 await usingApi(async (api, privateKeyWrapper) => {
177 const alice = privateKeyWrapper('//Alice');
178
179 const item1User = new Map();
180 item1User.set(JSON.stringify({Substrate: alice.address}), 1);
181
182 const item2User = new Map();
183 item2User.set(JSON.stringify({Substrate: alice.address}), 3);
184
185 await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {
186 RefungibleMultipleItems: [
187 {users: item1User},
188 {users: item2User},
189 ],
190 }));
191
192 const itemsListIndexAfter = await getLastTokenId(api, collection);
193 expect(itemsListIndexAfter).to.be.equal(2);
194
195 expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n);
196 expect(await getBalance(api, collection, alice.address, 2)).to.be.equal(3n);
197 });
198 });
199});
200
201describe('Negative test: createMultipleItemsEx', () => {
131 it('No editing rights', async () => {202 it('No editing rights', async () => {
132 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],203 const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
133 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});204 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
321 });392 });
322 });393 });
323});394});
324'';
325395