git.delta.rocks / unique-network / refs/commits / 66f33e369405

difftreelog

Merge pull request #373 from UniqueNetwork/feature/CORE-302-ss58Format

kozyrevdev2022-06-09parents: #c557492 #5a8eeab.patch.diff
in: master
test(ss58Format): fix format address, remove accounts constants

21 files changed

deletedtests/src/accounts.tsdiffbeforeafterboth

no changes

modifiedtests/src/addToContractAllowList.test.tsdiffbeforeafterboth
32 it('Add an address to a contract allow list', async () => {32 it('Add an address to a contract allow list', async () => {
33 await usingApi(async (api, privateKeyWrapper) => {33 await usingApi(async (api, privateKeyWrapper) => {
34 const bob = privateKeyWrapper('//Bob');34 const bob = privateKeyWrapper('//Bob');
35 const [contract, deployer] = await deployFlipper(api);35 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
3636
37 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();37 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
38 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);38 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
48 it('Adding same address to allow list repeatedly should not produce errors', async () => {48 it('Adding same address to allow list repeatedly should not produce errors', async () => {
49 await usingApi(async (api, privateKeyWrapper) => {49 await usingApi(async (api, privateKeyWrapper) => {
50 const bob = privateKeyWrapper('//Bob');50 const bob = privateKeyWrapper('//Bob');
51 const [contract, deployer] = await deployFlipper(api);51 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
5252
53 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();53 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
54 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);54 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
87 it('Add to a contract allow list using a non-owner address', async () => {87 it('Add to a contract allow list using a non-owner address', async () => {
88 await usingApi(async (api, privateKeyWrapper) => {88 await usingApi(async (api, privateKeyWrapper) => {
89 const bob = privateKeyWrapper('//Bob');89 const bob = privateKeyWrapper('//Bob');
90 const [contract] = await deployFlipper(api);90 const [contract] = await deployFlipper(api, privateKeyWrapper);
9191
92 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();92 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
93 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);93 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
modifiedtests/src/burnItem.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 {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';17import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
18import {Keyring} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import {19import {
21 createCollectionExpectSuccess,20 createCollectionExpectSuccess,
3736
38describe('integration test: ext. burnItem():', () => {37describe('integration test: ext. burnItem():', () => {
39 before(async () => {38 before(async () => {
40 await usingApi(async () => {39 await usingApi(async (api, privateKeyWrapper) => {
41 const keyring = new Keyring({type: 'sr25519'});
42 alice = keyring.addFromUri('//Alice');40 alice = privateKeyWrapper('//Alice');
43 bob = keyring.addFromUri('//Bob');41 bob = privateKeyWrapper('//Bob');
44 });42 });
45 });43 });
4644
142140
143describe('integration test: ext. burnItem() with admin permissions:', () => {141describe('integration test: ext. burnItem() with admin permissions:', () => {
144 before(async () => {142 before(async () => {
145 await usingApi(async () => {143 await usingApi(async (api, privateKeyWrapper) => {
146 const keyring = new Keyring({type: 'sr25519'});
147 alice = keyring.addFromUri('//Alice');144 alice = privateKeyWrapper('//Alice');
148 bob = keyring.addFromUri('//Bob');145 bob = privateKeyWrapper('//Bob');
149 });146 });
150 });147 });
151148
209206
210describe('Negative integration test: ext. burnItem():', () => {207describe('Negative integration test: ext. burnItem():', () => {
211 before(async () => {208 before(async () => {
212 await usingApi(async () => {209 await usingApi(async (api, privateKeyWrapper) => {
213 const keyring = new Keyring({type: 'sr25519'});
214 alice = keyring.addFromUri('//Alice');210 alice = privateKeyWrapper('//Alice');
215 bob = keyring.addFromUri('//Bob');211 bob = privateKeyWrapper('//Bob');
216 });212 });
217 });213 });
218214
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
34 getCreatedCollectionCount,34 getCreatedCollectionCount,
35 UNIQUE,35 UNIQUE,
36} from './util/helpers';36} from './util/helpers';
37import {Keyring} from '@polkadot/api';
38import {IKeyringPair} from '@polkadot/types/types';37import {IKeyringPair} from '@polkadot/types/types';
3938
40chai.use(chaiAsPromised);39chai.use(chaiAsPromised);
47describe('integration test: ext. confirmSponsorship():', () => {46describe('integration test: ext. confirmSponsorship():', () => {
4847
49 before(async () => {48 before(async () => {
50 await usingApi(async () => {49 await usingApi(async (api, privateKeyWrapper) => {
51 const keyring = new Keyring({type: 'sr25519'});
52 alice = keyring.addFromUri('//Alice');50 alice = privateKeyWrapper('//Alice');
53 bob = keyring.addFromUri('//Bob');51 bob = privateKeyWrapper('//Bob');
54 charlie = keyring.addFromUri('//Charlie');52 charlie = privateKeyWrapper('//Charlie');
55 });53 });
56 });54 });
5755
78 await setCollectionSponsorExpectSuccess(collectionId, bob.address);76 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
79 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');77 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
8078
81 await usingApi(async (api) => {79 await usingApi(async (api, privateKeyWrapper) => {
82 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();80 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
8381
84 // Find unused address82 // Find unused address
85 const zeroBalance = await findUnusedAddress(api);83 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
8684
87 // Mint token for unused address85 // Mint token for unused address
88 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);86 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
105 await setCollectionSponsorExpectSuccess(collectionId, bob.address);103 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
106 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');104 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
107105
108 await usingApi(async (api) => {106 await usingApi(async (api, privateKeyWrapper) => {
109 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();107 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
110108
111 // Find unused address109 // Find unused address
112 const zeroBalance = await findUnusedAddress(api);110 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
113111
114 // Mint token for unused address112 // Mint token for unused address
115 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);113 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);
131 await setCollectionSponsorExpectSuccess(collectionId, bob.address);129 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
132 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');130 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
133131
134 await usingApi(async (api) => {132 await usingApi(async (api, privateKeyWrapper) => {
135 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();133 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
136134
137 // Find unused address135 // Find unused address
138 const zeroBalance = await findUnusedAddress(api);136 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
139137
140 // Mint token for unused address138 // Mint token for unused address
141 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);139 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);
164 await enablePublicMintingExpectSuccess(alice, collectionId);162 await enablePublicMintingExpectSuccess(alice, collectionId);
165163
166 // Create Item164 // Create Item
167 await usingApi(async (api) => {165 await usingApi(async (api, privateKeyWrapper) => {
168 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();166 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
169167
170 // Find unused address168 // Find unused address
171 const zeroBalance = await findUnusedAddress(api);169 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
172170
173 // Add zeroBalance address to allow list171 // Add zeroBalance address to allow list
174 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);172 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
187 await setCollectionSponsorExpectSuccess(collectionId, bob.address);185 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
188 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');186 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
189187
190 await usingApi(async (api) => {188 await usingApi(async (api, privateKeyWrapper) => {
191 // Find unused address189 // Find unused address
192 const zeroBalance = await findUnusedAddress(api);190 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
193191
194 // Mint token for alice192 // Mint token for alice
195 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);193 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
226 await setCollectionSponsorExpectSuccess(collectionId, bob.address);224 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
227 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');225 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
228226
229 await usingApi(async (api) => {227 await usingApi(async (api, privateKeyWrapper) => {
230 // Find unused address228 // Find unused address
231 const zeroBalance = await findUnusedAddress(api);229 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
232230
233 // Mint token for unused address231 // Mint token for unused address
234 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);232 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);
259 await setCollectionSponsorExpectSuccess(collectionId, bob.address);257 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
260 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');258 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
261259
262 await usingApi(async (api) => {260 await usingApi(async (api, privateKeyWrapper) => {
263 // Find unused address261 // Find unused address
264 const zeroBalance = await findUnusedAddress(api);262 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
265263
266 // Mint token for alice264 // Mint token for alice
267 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);265 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);
299 // Enable public minting297 // Enable public minting
300 await enablePublicMintingExpectSuccess(alice, collectionId);298 await enablePublicMintingExpectSuccess(alice, collectionId);
301299
302 await usingApi(async (api) => {300 await usingApi(async (api, privateKeyWrapper) => {
303 // Find unused address301 // Find unused address
304 const zeroBalance = await findUnusedAddress(api);302 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
305303
306 // Add zeroBalance address to allow list304 // Add zeroBalance address to allow list
307 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);305 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
331329
332describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {330describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {
333 before(async () => {331 before(async () => {
334 await usingApi(async () => {332 await usingApi(async (api, privateKeyWrapper) => {
335 const keyring = new Keyring({type: 'sr25519'});
336 alice = keyring.addFromUri('//Alice');333 alice = privateKeyWrapper('//Alice');
337 bob = keyring.addFromUri('//Bob');334 bob = privateKeyWrapper('//Bob');
338 charlie = keyring.addFromUri('//Charlie');335 charlie = privateKeyWrapper('//Charlie');
339 });336 });
340 });337 });
341338
390 await setCollectionSponsorExpectSuccess(collectionId, bob.address);387 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
391 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');388 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
392389
393 await usingApi(async (api) => {390 await usingApi(async (api, privateKeyWrapper) => {
394 // Find unused address391 // Find unused address
395 const ownerZeroBalance = await findUnusedAddress(api);392 const ownerZeroBalance = await findUnusedAddress(api, privateKeyWrapper);
396393
397 // Find another unused address394 // Find another unused address
398 const senderZeroBalance = await findUnusedAddress(api);395 const senderZeroBalance = await findUnusedAddress(api, privateKeyWrapper);
399396
400 // Mint token for an unused address397 // Mint token for an unused address
401 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);398 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
50describe.skip('Contracts', () => {50describe.skip('Contracts', () => {
51 it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {51 it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {
52 await usingApi(async (api, privateKeyWrapper) => {52 await usingApi(async (api, privateKeyWrapper) => {
53 const [contract, deployer] = await deployFlipper(api);53 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
54 const initialGetResponse = await getFlipValue(contract, deployer);54 const initialGetResponse = await getFlipValue(contract, deployer);
5555
56 const bob = privateKeyWrapper('//Bob');56 const bob = privateKeyWrapper('//Bob');
82 // Prep work82 // Prep work
83 const collectionId = await createCollectionExpectSuccess();83 const collectionId = await createCollectionExpectSuccess();
84 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');84 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
85 const [contract] = await deployTransferContract(api);85 const [contract] = await deployTransferContract(api, privateKeyWrapper);
86 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);86 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);
87 await submitTransactionAsync(alice, changeAdminTx);87 await submitTransactionAsync(alice, changeAdminTx);
8888
104 const bob = privateKeyWrapper('//Bob');104 const bob = privateKeyWrapper('//Bob');
105105
106 const collectionId = await createCollectionExpectSuccess();106 const collectionId = await createCollectionExpectSuccess();
107 const [contract] = await deployTransferContract(api);107 const [contract] = await deployTransferContract(api, privateKeyWrapper);
108 await enablePublicMintingExpectSuccess(alice, collectionId);108 await enablePublicMintingExpectSuccess(alice, collectionId);
109 await enableAllowListExpectSuccess(alice, collectionId);109 await enableAllowListExpectSuccess(alice, collectionId);
110 await addToAllowListExpectSuccess(alice, collectionId, contract.address);110 await addToAllowListExpectSuccess(alice, collectionId, contract.address);
131 const bob = privateKeyWrapper('//Bob');131 const bob = privateKeyWrapper('//Bob');
132132
133 const collectionId = await createCollectionExpectSuccess();133 const collectionId = await createCollectionExpectSuccess();
134 const [contract] = await deployTransferContract(api);134 const [contract] = await deployTransferContract(api, privateKeyWrapper);
135 await enablePublicMintingExpectSuccess(alice, collectionId);135 await enablePublicMintingExpectSuccess(alice, collectionId);
136 await enableAllowListExpectSuccess(alice, collectionId);136 await enableAllowListExpectSuccess(alice, collectionId);
137 await addToAllowListExpectSuccess(alice, collectionId, contract.address);137 await addToAllowListExpectSuccess(alice, collectionId, contract.address);
173 const charlie = privateKeyWrapper('//Charlie');173 const charlie = privateKeyWrapper('//Charlie');
174174
175 const collectionId = await createCollectionExpectSuccess();175 const collectionId = await createCollectionExpectSuccess();
176 const [contract] = await deployTransferContract(api);176 const [contract] = await deployTransferContract(api, privateKeyWrapper);
177 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());177 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());
178178
179 const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);179 const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);
192 const charlie = privateKeyWrapper('//Charlie');192 const charlie = privateKeyWrapper('//Charlie');
193193
194 const collectionId = await createCollectionExpectSuccess();194 const collectionId = await createCollectionExpectSuccess();
195 const [contract] = await deployTransferContract(api);195 const [contract] = await deployTransferContract(api, privateKeyWrapper);
196 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);196 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
197 await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);197 await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);
198198
212 const bob = privateKeyWrapper('//Bob');212 const bob = privateKeyWrapper('//Bob');
213213
214 const collectionId = await createCollectionExpectSuccess();214 const collectionId = await createCollectionExpectSuccess();
215 const [contract] = await deployTransferContract(api);215 const [contract] = await deployTransferContract(api, privateKeyWrapper);
216 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);216 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);
217 await submitTransactionAsync(alice, changeAdminTx);217 await submitTransactionAsync(alice, changeAdminTx);
218218
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
1616
17import {default as usingApi} from './substrate/substrate-api';17import {default as usingApi} from './substrate/substrate-api';
18import chai from 'chai';18import chai from 'chai';
19import {Keyring} from '@polkadot/api';
20import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';
21import {20import {
22 createCollectionExpectSuccess,21 createCollectionExpectSuccess,
3332
34describe('integration test: ext. ():', () => {33describe('integration test: ext. ():', () => {
35 before(async () => {34 before(async () => {
36 await usingApi(async () => {35 await usingApi(async (api, privateKeyWrapper) => {
37 const keyring = new Keyring({type: 'sr25519'});
38 alice = keyring.addFromUri('//Alice');36 alice = privateKeyWrapper('//Alice');
39 bob = keyring.addFromUri('//Bob');37 bob = privateKeyWrapper('//Bob');
40 });38 });
41 });39 });
4240
10199
102describe('Negative integration test: ext. createItem():', () => {100describe('Negative integration test: ext. createItem():', () => {
103 before(async () => {101 before(async () => {
104 await usingApi(async () => {102 await usingApi(async (api, privateKeyWrapper) => {
105 const keyring = new Keyring({type: 'sr25519'});
106 alice = keyring.addFromUri('//Alice');103 alice = privateKeyWrapper('//Alice');
107 bob = keyring.addFromUri('//Bob');104 bob = privateKeyWrapper('//Bob');
108 });105 });
109 });106 });
110107
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
18import chai from 'chai';18import chai from 'chai';
19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
21import {alicesPublicKey, bobsPublicKey} from './accounts';
22import {IKeyringPair} from '@polkadot/types/types';21import {IKeyringPair} from '@polkadot/types/types';
23import {22import {
24 createCollectionExpectSuccess,23 createCollectionExpectSuccess,
71 });70 });
7271
73 it('Total issuance does not change', async () => {72 it('Total issuance does not change', async () => {
74 await usingApi(async (api, privateKeyWrapper) => {73 await usingApi(async (api) => {
75 await skipInflationBlock(api);74 await skipInflationBlock(api);
76 await waitNewBlocks(api, 1);75 await waitNewBlocks(api, 1);
7776
78 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();77 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
7978
80 const alicePrivateKey = privateKeyWrapper('//Alice');
81 const amount = 1n;79 const amount = 1n;
82 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);80 const transfer = api.tx.balances.transfer(bob.address, amount);
8381
84 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));82 const result = getGenericResult(await submitTransactionAsync(alice, transfer));
8583
86 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();84 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();
8785
91 });89 });
9290
93 it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {91 it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {
94 await usingApi(async (api, privateKeyWrapper) => {92 await usingApi(async (api) => {
95 await skipInflationBlock(api);93 await skipInflationBlock(api);
96 await waitNewBlocks(api, 1);94 await waitNewBlocks(api, 1);
9795
98 const alicePrivateKey = privateKeyWrapper('//Alice');
99 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();96 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
100 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();97 const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
10198
102 const amount = 1n;99 const amount = 1n;
103 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);100 const transfer = api.tx.balances.transfer(bob.address, amount);
104 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));101 const result = getGenericResult(await submitTransactionAsync(alice, transfer));
105102
106 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();103 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
107 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();104 const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
108 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;105 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
109 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;106 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
110107
114 });111 });
115112
116 it('Treasury balance increased by failed tx fee', async () => {113 it('Treasury balance increased by failed tx fee', async () => {
117 await usingApi(async (api, privateKeyWrapper) => {114 await usingApi(async (api) => {
118 //await skipInflationBlock(api);115 //await skipInflationBlock(api);
119 await waitNewBlocks(api, 1);116 await waitNewBlocks(api, 1);
120117
121 const bobPrivateKey = privateKeyWrapper('//Bob');
122 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();118 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
123 const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();119 const bobBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
124120
125 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);121 const badTx = api.tx.balances.setBalance(alice.address, 0, 0);
126 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;122 await expect(submitTransactionExpectFailAsync(bob, badTx)).to.be.rejected;
127123
128 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();124 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
129 const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();125 const bobBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
130 const fee = bobBalanceBefore - bobBalanceAfter;126 const fee = bobBalanceBefore - bobBalanceAfter;
131 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;127 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
132128
140 await waitNewBlocks(api, 1);136 await waitNewBlocks(api, 1);
141137
142 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();138 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
143 const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();139 const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();
144140
145 await createCollectionExpectSuccess();141 await createCollectionExpectSuccess();
146142
147 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();143 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
148 const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();144 const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();
149 const fee = aliceBalanceBefore - aliceBalanceAfter;145 const fee = aliceBalanceBefore - aliceBalanceAfter;
150 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;146 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
151147
158 await skipInflationBlock(api);154 await skipInflationBlock(api);
159 await waitNewBlocks(api, 1);155 await waitNewBlocks(api, 1);
160156
161 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();157 const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
162158
163 await createCollectionExpectSuccess();159 await createCollectionExpectSuccess();
164160
165 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();161 const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
166 const fee = aliceBalanceBefore - aliceBalanceAfter;162 const fee = aliceBalanceBefore - aliceBalanceAfter;
167163
168 expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;164 expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
178 const collectionId = await createCollectionExpectSuccess();174 const collectionId = await createCollectionExpectSuccess();
179 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');175 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
180176
181 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();177 const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
182 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');178 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
183 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();179 const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
184180
185 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);181 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);
186 const expectedTransferFee = 0.1;182 const expectedTransferFee = 0.1;
modifiedtests/src/enableContractSponsoring.test.tsdiffbeforeafterboth
3131
32describe.skip('Integration Test enableContractSponsoring', () => {32describe.skip('Integration Test enableContractSponsoring', () => {
33 it('ensure tx fee is paid from endowment', async () => {33 it('ensure tx fee is paid from endowment', async () => {
34 await usingApi(async (api) => {34 await usingApi(async (api, privateKeyWrapper) => {
35 const user = await findUnusedAddress(api);35 const user = await findUnusedAddress(api, privateKeyWrapper);
3636
37 const [flipper, deployer] = await deployFlipper(api);37 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
38 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);38 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
39 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);39 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);
40 await toggleFlipValueExpectSuccess(user, flipper);40 await toggleFlipValueExpectSuccess(user, flipper);
44 });44 });
4545
46 it('ensure it can be enabled twice', async () => {46 it('ensure it can be enabled twice', async () => {
47 await usingApi(async (api) => {47 await usingApi(async (api, privateKeyWrapper) => {
48 const [flipper, deployer] = await deployFlipper(api);48 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
4949
50 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);50 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
51 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);51 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
52 });52 });
53 });53 });
5454
55 it('ensure it can be disabled twice', async () => {55 it('ensure it can be disabled twice', async () => {
56 await usingApi(async (api) => {56 await usingApi(async (api, privateKeyWrapper) => {
57 const [flipper, deployer] = await deployFlipper(api);57 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
5858
59 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);59 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
60 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);60 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);
63 });63 });
6464
65 it('ensure it can be re-enabled', async () => {65 it('ensure it can be re-enabled', async () => {
66 await usingApi(async (api) => {66 await usingApi(async (api, privateKeyWrapper) => {
67 const [flipper, deployer] = await deployFlipper(api);67 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
6868
69 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);69 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
70 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);70 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);
84 });84 });
8585
86 it('fails when called for non-contract address', async () => {86 it('fails when called for non-contract address', async () => {
87 await usingApi(async (api) => {87 await usingApi(async (api, privateKeyWrapper) => {
88 const user = await findUnusedAddress(api);88 const user = await findUnusedAddress(api, privateKeyWrapper);
8989
90 await enableContractSponsoringExpectFailure(alice, user.address, true);90 await enableContractSponsoringExpectFailure(alice, user.address, true);
91 });91 });
92 });92 });
9393
94 it('fails when called by non-owning user', async () => {94 it('fails when called by non-owning user', async () => {
95 await usingApi(async (api) => {95 await usingApi(async (api, privateKeyWrapper) => {
96 const [flipper] = await deployFlipper(api);96 const [flipper] = await deployFlipper(api, privateKeyWrapper);
9797
98 await enableContractSponsoringExpectFailure(alice, flipper.address, true);98 await enableContractSponsoringExpectFailure(alice, flipper.address, true);
99 });99 });
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
31 addCollectionAdminExpectSuccess,31 addCollectionAdminExpectSuccess,
32 getCreatedCollectionCount,32 getCreatedCollectionCount,
33} from './util/helpers';33} from './util/helpers';
34import {Keyring} from '@polkadot/api';
35import {IKeyringPair} from '@polkadot/types/types';34import {IKeyringPair} from '@polkadot/types/types';
3635
37chai.use(chaiAsPromised);36chai.use(chaiAsPromised);
43describe('integration test: ext. removeCollectionSponsor():', () => {42describe('integration test: ext. removeCollectionSponsor():', () => {
4443
45 before(async () => {44 before(async () => {
46 await usingApi(async () => {45 await usingApi(async (api, privateKeyWrapper) => {
47 const keyring = new Keyring({type: 'sr25519'});
48 alice = keyring.addFromUri('//Alice');46 alice = privateKeyWrapper('//Alice');
49 bob = keyring.addFromUri('//Bob');47 bob = privateKeyWrapper('//Bob');
50 });48 });
51 });49 });
5250
56 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
57 await removeCollectionSponsorExpectSuccess(collectionId);55 await removeCollectionSponsorExpectSuccess(collectionId);
5856
59 await usingApi(async (api) => {57 await usingApi(async (api, privateKeyWrapper) => {
60 // Find unused address58 // Find unused address
61 const zeroBalance = await findUnusedAddress(api);59 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
6260
63 // Mint token for unused address61 // Mint token for unused address
64 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);62 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
9997
100describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {98describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {
101 before(async () => {99 before(async () => {
102 await usingApi(async () => {100 await usingApi(async (api, privateKeyWrapper) => {
103 const keyring = new Keyring({type: 'sr25519'});
104 alice = keyring.addFromUri('//Alice');101 alice = privateKeyWrapper('//Alice');
105 bob = keyring.addFromUri('//Bob');102 bob = privateKeyWrapper('//Bob');
106 });103 });
107 });104 });
108105
modifiedtests/src/removeFromContractAllowList.test.tsdiffbeforeafterboth
30 });30 });
3131
32 it('user is no longer allowlisted after removal', async () => {32 it('user is no longer allowlisted after removal', async () => {
33 await usingApi(async (api) => {33 await usingApi(async (api, privateKeyWrapper) => {
34 const [flipper, deployer] = await deployFlipper(api);34 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
3535
36 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);36 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
37 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);37 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
41 });41 });
4242
43 it('user can\'t execute contract after removal', async () => {43 it('user can\'t execute contract after removal', async () => {
44 await usingApi(async (api) => {44 await usingApi(async (api, privateKeyWrapper) => {
45 const [flipper, deployer] = await deployFlipper(api);45 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
46 await toggleContractAllowlistExpectSuccess(deployer, flipper.address.toString(), true);46 await toggleContractAllowlistExpectSuccess(deployer, flipper.address.toString(), true);
4747
48 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);48 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
54 });54 });
5555
56 it('can be called twice', async () => {56 it('can be called twice', async () => {
57 await usingApi(async (api) => {57 await usingApi(async (api, privateKeyWrapper) => {
58 const [flipper, deployer] = await deployFlipper(api);58 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
5959
60 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);60 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
61 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);61 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
82 });82 });
8383
84 it('fails when executed by non owner', async () => {84 it('fails when executed by non owner', async () => {
85 await usingApi(async (api) => {85 await usingApi(async (api, privateKeyWrapper) => {
86 const [flipper] = await deployFlipper(api);86 const [flipper] = await deployFlipper(api, privateKeyWrapper);
8787
88 await removeFromContractAllowListExpectFailure(alice, flipper.address.toString(), bob.address);88 await removeFromContractAllowListExpectFailure(alice, flipper.address.toString(), bob.address);
89 });89 });
modifiedtests/src/rpc.load.tsdiffbeforeafterboth
54 });54 });
55}55}
5656
57async function prepareDeployer(api: ApiPromise) {57async function prepareDeployer(api: ApiPromise, privateKeyWrapper: ((account: string) => IKeyringPair)) {
58 // Find unused address58 // Find unused address
59 const deployer = await findUnusedAddress(api);59 const deployer = await findUnusedAddress(api, privateKeyWrapper);
6060
61 // Transfer balance to it61 // Transfer balance to it
62 const keyring = new Keyring({type: 'sr25519'});62 const keyring = new Keyring({type: 'sr25519'});
68 return deployer;68 return deployer;
69}69}
7070
71async function deployLoadTester(api: ApiPromise): Promise<[Contract, IKeyringPair]> {71async function deployLoadTester(api: ApiPromise, privateKeyWrapper: ((account: string) => IKeyringPair)): Promise<[Contract, IKeyringPair]> {
72 const metadata = JSON.parse(fs.readFileSync('./src/load_test_sc/metadata.json').toString('utf-8'));72 const metadata = JSON.parse(fs.readFileSync('./src/load_test_sc/metadata.json').toString('utf-8'));
73 const abi = new Abi(metadata);73 const abi = new Abi(metadata);
7474
75 const deployer = await prepareDeployer(api);75 const deployer = await prepareDeployer(api, privateKeyWrapper);
7676
77 const wasm = fs.readFileSync('./src/load_test_sc/loadtester.wasm');77 const wasm = fs.readFileSync('./src/load_test_sc/loadtester.wasm');
7878
123 await usingApi(async (api, privateKeyWrapper) => {123 await usingApi(async (api, privateKeyWrapper) => {
124124
125 // Deploy smart contract125 // Deploy smart contract
126 const [contract, deployer] = await deployLoadTester(api);126 const [contract, deployer] = await deployLoadTester(api, privateKeyWrapper);
127127
128 // Fill smart contract up with data128 // Fill smart contract up with data
129 const bob = privateKeyWrapper('//Bob');129 const bob = privateKeyWrapper('//Bob');
modifiedtests/src/scheduler.test.tsdiffbeforeafterboth
116 });116 });
117117
118 it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {118 it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {
119 await usingApi(async (api) => {119 await usingApi(async (api, privateKeyWrapper) => {
120 // Find an empty, unused account120 // Find an empty, unused account
121 const zeroBalance = await findUnusedAddress(api);121 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
122122
123 const collectionId = await createCollectionExpectSuccess();123 const collectionId = await createCollectionExpectSuccess();
124124
156 it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {156 it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {
157 const collectionId = await createCollectionExpectSuccess();157 const collectionId = await createCollectionExpectSuccess();
158158
159 await usingApi(async (api) => {159 await usingApi(async (api, privateKeyWrapper) => {
160 const zeroBalance = await findUnusedAddress(api);160 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
161 const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);161 const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
162 await submitTransactionAsync(alice, balanceTx);162 await submitTransactionAsync(alice, balanceTx);
163163
186 await setCollectionSponsorExpectSuccess(collectionId, bob.address);186 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
187 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');187 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
188188
189 await usingApi(async (api) => {189 await usingApi(async (api, privateKeyWrapper) => {
190 const zeroBalance = await findUnusedAddress(api);190 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
191191
192 await enablePublicMintingExpectSuccess(alice, collectionId);192 await enablePublicMintingExpectSuccess(alice, collectionId);
193 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);193 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
modifiedtests/src/setCollectionLimits.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
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise, Keyring} from '@polkadot/api';18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';21import chaiAsPromised from 'chai-as-promised';
44describe('setCollectionLimits positive', () => {44describe('setCollectionLimits positive', () => {
45 let tx;45 let tx;
46 before(async () => {46 before(async () => {
47 await usingApi(async () => {47 await usingApi(async (api, privateKeyWrapper) => {
48 const keyring = new Keyring({type: 'sr25519'});
49 alice = keyring.addFromUri('//Alice');48 alice = privateKeyWrapper('//Alice');
50 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});49 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
51 });50 });
52 });51 });
121describe('setCollectionLimits negative', () => {120describe('setCollectionLimits negative', () => {
122 let tx;121 let tx;
123 before(async () => {122 before(async () => {
124 await usingApi(async () => {123 await usingApi(async (api, privateKeyWrapper) => {
125 const keyring = new Keyring({type: 'sr25519'});
126 alice = keyring.addFromUri('//Alice');124 alice = privateKeyWrapper('//Alice');
127 bob = keyring.addFromUri('//Bob');125 bob = privateKeyWrapper('//Bob');
128 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});126 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
129 });127 });
130 });128 });
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
24 addCollectionAdminExpectSuccess,24 addCollectionAdminExpectSuccess,
25 getCreatedCollectionCount,25 getCreatedCollectionCount,
26} from './util/helpers';26} from './util/helpers';
27import {Keyring} from '@polkadot/api';
28import {IKeyringPair} from '@polkadot/types/types';27import {IKeyringPair} from '@polkadot/types/types';
2928
30chai.use(chaiAsPromised);29chai.use(chaiAsPromised);
36describe('integration test: ext. setCollectionSponsor():', () => {35describe('integration test: ext. setCollectionSponsor():', () => {
3736
38 before(async () => {37 before(async () => {
39 await usingApi(async () => {38 await usingApi(async (api, privateKeyWrapper) => {
40 const keyring = new Keyring({type: 'sr25519'});39 alice = privateKeyWrapper('//Alice');
41 alice = keyring.addFromUri('//Alice');40 bob = privateKeyWrapper('//Bob');
42 bob = keyring.addFromUri('//Bob');41 charlie = privateKeyWrapper('//Charlie');
43 });42 });
44 });43 });
4544
64 it('Replace collection sponsor', async () => {63 it('Replace collection sponsor', async () => {
65 const collectionId = await createCollectionExpectSuccess();64 const collectionId = await createCollectionExpectSuccess();
66
67 const keyring = new Keyring({type: 'sr25519'});
68 const charlie = keyring.addFromUri('//Charlie');
69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
70 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);66 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
71 });67 });
72});68});
7369
74describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {70describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
75 before(async () => {71 before(async () => {
76 await usingApi(async () => {72 await usingApi(async (api, privateKeyWrapper) => {
77 const keyring = new Keyring({type: 'sr25519'});
78 alice = keyring.addFromUri('//Alice');73 alice = privateKeyWrapper('//Alice');
79 bob = keyring.addFromUri('//Bob');74 bob = privateKeyWrapper('//Bob');
80 charlie = keyring.addFromUri('//Charlie');75 charlie = privateKeyWrapper('//Charlie');
81 });76 });
82 });77 });
8378
modifiedtests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth
2727
28describe.skip('Integration Test setContractSponsoringRateLimit', () => {28describe.skip('Integration Test setContractSponsoringRateLimit', () => {
29 it('ensure sponsored contract can\'t be called twice without pause for free', async () => {29 it('ensure sponsored contract can\'t be called twice without pause for free', async () => {
30 await usingApi(async (api) => {30 await usingApi(async (api, privateKeyWrapper) => {
31 const user = await findUnusedAddress(api);31 const user = await findUnusedAddress(api, privateKeyWrapper);
3232
33 const [flipper, deployer] = await deployFlipper(api);33 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
34 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);34 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
35 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 10);35 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 10);
36 await toggleFlipValueExpectSuccess(user, flipper);36 await toggleFlipValueExpectSuccess(user, flipper);
39 });39 });
4040
41 it('ensure sponsored contract can be called twice with pause for free', async () => {41 it('ensure sponsored contract can be called twice with pause for free', async () => {
42 await usingApi(async (api) => {42 await usingApi(async (api, privateKeyWrapper) => {
43 const user = await findUnusedAddress(api);43 const user = await findUnusedAddress(api, privateKeyWrapper);
4444
45 const [flipper, deployer] = await deployFlipper(api);45 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
46 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);46 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
47 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);47 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);
48 await toggleFlipValueExpectSuccess(user, flipper);48 await toggleFlipValueExpectSuccess(user, flipper);
62 });62 });
6363
64 it('fails when called for non-contract address', async () => {64 it('fails when called for non-contract address', async () => {
65 await usingApi(async (api) => {65 await usingApi(async (api, privateKeyWrapper) => {
66 const user = await findUnusedAddress(api);66 const user = await findUnusedAddress(api, privateKeyWrapper);
6767
68 await setContractSponsoringRateLimitExpectFailure(alice, user.address, 1);68 await setContractSponsoringRateLimitExpectFailure(alice, user.address, 1);
69 });69 });
70 });70 });
7171
72 it('fails when called by non-owning user', async () => {72 it('fails when called by non-owning user', async () => {
73 await usingApi(async (api) => {73 await usingApi(async (api, privateKeyWrapper) => {
74 const [flipper] = await deployFlipper(api);74 const [flipper] = await deployFlipper(api, privateKeyWrapper);
7575
76 await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);76 await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);
77 });77 });
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
88 await promisifySubstrate(api, async () => {88 await promisifySubstrate(api, async () => {
89 if (api) {89 if (api) {
90 await api.isReadyOrError;90 await api.isReadyOrError;
91 const ss58Format = (api.registry.getChainProperties())!.toHuman().ss58Format;91 const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;
92 const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));92 const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));
93 result = await action(api, privateKeyWrapper);93 result = await action(api, privateKeyWrapper);
94 }94 }
modifiedtests/src/toggleContractAllowList.test.tsdiffbeforeafterboth
34describe.skip('Integration Test toggleContractAllowList', () => {34describe.skip('Integration Test toggleContractAllowList', () => {
3535
36 it('Enable allow list contract mode', async () => {36 it('Enable allow list contract mode', async () => {
37 await usingApi(async api => {37 await usingApi(async (api, privateKeyWrapper) => {
38 const [contract, deployer] = await deployFlipper(api);38 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
3939
40 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();40 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
41 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);41 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
52 await usingApi(async (api, privateKeyWrapper) => {52 await usingApi(async (api, privateKeyWrapper) => {
53 const bob = privateKeyWrapper('//Bob');53 const bob = privateKeyWrapper('//Bob');
5454
55 const [contract, deployer] = await deployFlipper(api);55 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
5656
57 let flipValueBefore = await getFlipValue(contract, deployer);57 let flipValueBefore = await getFlipValue(contract, deployer);
58 const flip = contract.tx.flip(value, gasLimit);58 const flip = contract.tx.flip(value, gasLimit);
111 });111 });
112112
113 it('Enabling allow list repeatedly should not produce errors', async () => {113 it('Enabling allow list repeatedly should not produce errors', async () => {
114 await usingApi(async api => {114 await usingApi(async (api, privateKeyWrapper) => {
115 const [contract, deployer] = await deployFlipper(api);115 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
116116
117 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();117 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
118 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);118 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
151 it('Enable allow list using a non-owner address', async () => {151 it('Enable allow list using a non-owner address', async () => {
152 await usingApi(async (api, privateKeyWrapper) => {152 await usingApi(async (api, privateKeyWrapper) => {
153 const bob = privateKeyWrapper('//Bob');153 const bob = privateKeyWrapper('//Bob');
154 const [contract] = await deployFlipper(api);154 const [contract] = await deployFlipper(api, privateKeyWrapper);
155155
156 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();156 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
157 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);157 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
17import {ApiPromise} from '@polkadot/api';17import {ApiPromise} from '@polkadot/api';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {expect} from 'chai';19import {expect} from 'chai';
20import {alicesPublicKey, bobsPublicKey} from './accounts';
21import getBalance from './substrate/get-balance';20import getBalance from './substrate/get-balance';
22import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';21import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
23import {22import {
47let charlie: IKeyringPair;46let charlie: IKeyringPair;
4847
49describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {48describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
49 before(async () => {
50 await usingApi(async (api, privateKeyWrapper) => {
51 alice = privateKeyWrapper('//Alice');
52 bob = privateKeyWrapper('//Bob');
53 });
54 });
55
50 it('Balance transfers and check balance', async () => {56 it('Balance transfers and check balance', async () => {
51 await usingApi(async (api, privateKeyWrapper) => {57 await usingApi(async (api, privateKeyWrapper) => {
52 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);58 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alice.address, bob.address]);
53
54 const alicePrivateKey = privateKeyWrapper('//Alice');
5559
56 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);60 const transfer = api.tx.balances.transfer(bob.address, 1n);
57 const events = await submitTransactionAsync(alicePrivateKey, transfer);61 const events = await submitTransactionAsync(alice, transfer);
58 const result = getCreateItemResult(events);62 const result = getCreateItemResult(events);
59 // tslint:disable-next-line:no-unused-expression63 // tslint:disable-next-line:no-unused-expression
60 expect(result.success).to.be.true;64 expect(result.success).to.be.true;
6165
62 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);66 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alice.address, bob.address]);
6367
64 // tslint:disable-next-line:no-unused-expression68 // tslint:disable-next-line:no-unused-expression
65 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;69 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
69 });73 });
7074
71 it('Inability to pay fees error message is correct', async () => {75 it('Inability to pay fees error message is correct', async () => {
72 await usingApi(async (api) => {76 await usingApi(async (api, privateKeyWrapper) => {
73 // Find unused address77 // Find unused address
74 const pk = await findUnusedAddress(api);78 const pk = await findUnusedAddress(api, privateKeyWrapper);
7579
76 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);80 const badTransfer = api.tx.balances.transfer(bob.address, 1n);
77 // const events = await submitTransactionAsync(pk, badTransfer);81 // const events = await submitTransactionAsync(pk, badTransfer);
78 const badTransaction = async () => {82 const badTransaction = async () => {
79 const events = await submitTransactionAsync(pk, badTransfer);83 const events = await submitTransactionAsync(pk, badTransfer);
8791
88 it('User can transfer owned token', async () => {92 it('User can transfer owned token', async () => {
89 await usingApi(async (api, privateKeyWrapper) => {93 await usingApi(async (api, privateKeyWrapper) => {
90 const alice = privateKeyWrapper('//Alice');
91 const bob = privateKeyWrapper('//Bob');
92 // nft94 // nft
93 const nftCollectionId = await createCollectionExpectSuccess();95 const nftCollectionId = await createCollectionExpectSuccess();
94 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');96 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
114116
115 it('Collection admin can transfer owned token', async () => {117 it('Collection admin can transfer owned token', async () => {
116 await usingApi(async (api, privateKeyWrapper) => {118 await usingApi(async (api, privateKeyWrapper) => {
117 const alice = privateKeyWrapper('//Alice');
118 const bob = privateKeyWrapper('//Bob');
119 // nft119 // nft
120 const nftCollectionId = await createCollectionExpectSuccess();120 const nftCollectionId = await createCollectionExpectSuccess();
121 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);121 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
316describe('Transfers to self (potentially over substrate-evm boundary)', () => {316describe('Transfers to self (potentially over substrate-evm boundary)', () => {
317 itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {317 itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {
318 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});318 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
319 const alice = privateKeyWrapper('//Alice');
320 const aliceProxy = subToEth(alice.address);319 const aliceProxy = subToEth(alice.address);
321 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});320 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
322 await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');321 await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');
328327
329 itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {328 itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {
330 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});329 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
331 const alice = privateKeyWrapper('//Alice');
332 const aliceProxy = subToEth(alice.address);330 const aliceProxy = subToEth(alice.address);
333 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});331 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
334 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);332 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
340338
341 itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {339 itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {
342 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});340 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
343 const alice = privateKeyWrapper('//Alice');
344 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});341 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
345 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);342 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
346 await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');343 await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');
351348
352 itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {349 itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {
353 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});350 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
354 const alice = privateKeyWrapper('//Alice');
355 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});351 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
356 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);352 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
357 await transferExpectFailure(collectionId, tokenId, alice, alice , 11);353 await transferExpectFailure(collectionId, tokenId, alice, alice , 11);
modifiedtests/src/util/contracthelpers.tsdiffbeforeafterboth
20import fs from 'fs';20import fs from 'fs';
21import {Abi, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';21import {Abi, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';
22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';
23import {ApiPromise, Keyring} from '@polkadot/api';23import {ApiPromise} from '@polkadot/api';
2424
25chai.use(chaiAsPromised);25chai.use(chaiAsPromised);
26const expect = chai.expect;26const expect = chai.expect;
45 });45 });
46}46}
4747
48async function prepareDeployer(api: ApiPromise) {48async function prepareDeployer(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair) {
49 // Find unused address49 // Find unused address
50 const deployer = await findUnusedAddress(api);50 const deployer = await findUnusedAddress(api, privateKeyWrapper);
5151
52 // Transfer balance to it52 // Transfer balance to it
53 const keyring = new Keyring({type: 'sr25519'});
54 const alice = keyring.addFromUri('//Alice');53 const alice = privateKeyWrapper('//Alice');
55 const amount = BigInt(endowment) + 10n**15n;54 const amount = BigInt(endowment) + 10n**15n;
56 const tx = api.tx.balances.transfer(deployer.address, amount);55 const tx = api.tx.balances.transfer(deployer.address, amount);
57 await submitTransactionAsync(alice, tx);56 await submitTransactionAsync(alice, tx);
5857
59 return deployer;58 return deployer;
60}59}
6160
62export async function deployFlipper(api: ApiPromise): Promise<[Contract, IKeyringPair]> {61export async function deployFlipper(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair): Promise<[Contract, IKeyringPair]> {
63 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));62 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));
64 const abi = new Abi(metadata);63 const abi = new Abi(metadata);
6564
66 const deployer = await prepareDeployer(api);65 const deployer = await prepareDeployer(api, privateKeyWrapper);
6766
68 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');67 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');
6968
99 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;98 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
100}99}
101100
102export async function deployTransferContract(api: ApiPromise): Promise<[Contract, IKeyringPair]> {101export async function deployTransferContract(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair): Promise<[Contract, IKeyringPair]> {
103 const metadata = JSON.parse(fs.readFileSync('./src/transfer_contract/metadata.json').toString('utf-8'));102 const metadata = JSON.parse(fs.readFileSync('./src/transfer_contract/metadata.json').toString('utf-8'));
104 const abi = new Abi(metadata);103 const abi = new Abi(metadata);
105104
106 const deployer = await prepareDeployer(api);105 const deployer = await prepareDeployer(api, privateKeyWrapper);
107106
108 const wasm = fs.readFileSync('./src/transfer_contract/nft_transfer.wasm');107 const wasm = fs.readFileSync('./src/transfer_contract/nft_transfer.wasm');
109108
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
1616
17import '../interfaces/augment-api-rpc';17import '../interfaces/augment-api-rpc';
18import '../interfaces/augment-api-query';18import '../interfaces/augment-api-query';
19import {ApiPromise, Keyring} from '@polkadot/api';19import {ApiPromise} from '@polkadot/api';
20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';
21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';
22import {evmToAddress} from '@polkadot/util-crypto';22import {evmToAddress} from '@polkadot/util-crypto';
23import BN from 'bn.js';23import BN from 'bn.js';
24import chai from 'chai';24import chai from 'chai';
25import chaiAsPromised from 'chai-as-promised';25import chaiAsPromised from 'chai-as-promised';
26import {alicesPublicKey} from '../accounts';
27import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';26import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
28import {hexToStr, strToUTF16, utf16ToStr} from './util';27import {hexToStr, strToUTF16, utf16ToStr} from './util';
29import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';28import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';
4039
41export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {40export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
42 if (typeof input === 'string') {41 if (typeof input === 'string') {
43 if (input.length === 48 || input.length === 47) {42 if (input.length >= 47) {
44 return {Substrate: input};43 return {Substrate: input};
45 } else if (input.length === 42 && input.startsWith('0x')) {44 } else if (input.length === 42 && input.startsWith('0x')) {
46 return {Ethereum: input.toLowerCase()};45 return {Ethereum: input.toLowerCase()};
363 // tslint:disable-next-line:no-unused-expression362 // tslint:disable-next-line:no-unused-expression
364 expect(collection).to.be.not.null;363 expect(collection).to.be.not.null;
365 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');364 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
366 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));365 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));
367 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);366 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
368 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);367 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
369 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);368 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
411 // tslint:disable-next-line:no-unused-expression410 // tslint:disable-next-line:no-unused-expression
412 expect(collection).to.be.not.null;411 expect(collection).to.be.not.null;
413 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');412 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
414 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));413 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));
415 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);414 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
416 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);415 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
417 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);416 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
482 });481 });
483}482}
484483
485export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {484export async function findUnusedAddress(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, seedAddition = ''): Promise<IKeyringPair> {
486 let bal = 0n;485 let bal = 0n;
487 let unused;486 let unused;
488 do {487 do {
489 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;488 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;
490 const keyring = new Keyring({type: 'sr25519'});
491 unused = keyring.addFromUri(`//${randomSeed}`);489 unused = privateKeyWrapper(`//${randomSeed}`);
492 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();490 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();
493 } while (bal !== 0n);491 } while (bal !== 0n);
494 return unused;492 return unused;
498 return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();496 return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();
499}497}
500498
501export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {499export function findUnusedAddresses(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, amount: number): Promise<IKeyringPair[]> {
502 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));500 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, privateKeyWrapper, '_' + Date.now())));
503}501}
504502
505export async function findNotExistingCollection(api: ApiPromise): Promise<number> {503export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
modifiedtests/src/xcmTransfer.test.tsdiffbeforeafterboth
24import {getGenericResult} from './util/helpers';24import {getGenericResult} from './util/helpers';
25import waitNewBlocks from './substrate/wait-new-blocks';25import waitNewBlocks from './substrate/wait-new-blocks';
26import getBalance from './substrate/get-balance';26import getBalance from './substrate/get-balance';
27import {alicesPublicKey} from './accounts';
2827
29chai.use(chaiAsPromised);28chai.use(chaiAsPromised);
30const expect = chai.expect;29const expect = chai.expect;
144 let balanceBefore: bigint;143 let balanceBefore: bigint;
145 144
146 await usingApi(async (api) => {145 await usingApi(async (api) => {
147 [balanceBefore] = await getBalance(api, [alicesPublicKey]);146 [balanceBefore] = await getBalance(api, [alice.address]);
148 });147 });
149148
150 await usingApi(async (api) => {149 await usingApi(async (api) => {
181 await usingApi(async (api) => {180 await usingApi(async (api) => {
182 // todo do something about instant sealing, where there might not be any new blocks181 // todo do something about instant sealing, where there might not be any new blocks
183 await waitNewBlocks(api, 3);182 await waitNewBlocks(api, 3);
184 const [balanceAfter] = await getBalance(api, [alicesPublicKey]);183 const [balanceAfter] = await getBalance(api, [alice.address]);
185 expect(balanceAfter > balanceBefore).to.be.true;184 expect(balanceAfter > balanceBefore).to.be.true;
186 });185 });
187 });186 });