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

difftreelog

Merge pull request #632 from UniqueNetwork/tests/playgrounds-cleanup

ut-akuznetsov2022-10-06parents: #65f16a3 #f462fd9.patch.diff
in: master
Tests/playgrounds cleanup

69 files changed

modifiedtests/src/.outdated/addToContractAllowList.test.tsdiffbeforeafterboth
17import chai from 'chai';17import chai from 'chai';
18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';
19import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';19import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
20import {20import {deployFlipper} from '../deprecated-helpers/contracthelpers';
21 deployFlipper,
22} from '../util/contracthelpers';
23import {21import {getGenericResult} from '../deprecated-helpers/helpers';
24 getGenericResult,
25} from '../util/helpers';
2622
27chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
28const expect = chai.expect;24const expect = chai.expect;
modifiedtests/src/.outdated/contracts.test.tsdiffbeforeafterboth
19import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
20import fs from 'fs';20import fs from 'fs';
21import {Abi, ContractPromise as Contract} from '@polkadot/api-contract';21import {Abi, ContractPromise as Contract} from '@polkadot/api-contract';
22import {22import {deployFlipper, getFlipValue, deployTransferContract} from '../deprecated-helpers/contracthelpers';
23 deployFlipper,
24 getFlipValue,
25 deployTransferContract,
26} from '../util/contracthelpers';
2723
28import {24import {
29 addToAllowListExpectSuccess,25 addToAllowListExpectSuccess,
37 isAllowlisted,33 isAllowlisted,
38 transferFromExpectSuccess,34 transferFromExpectSuccess,
39 getTokenOwner,35 getTokenOwner,
40} from '../util/helpers';36} from '../deprecated-helpers/helpers';
4137
4238
43chai.use(chaiAsPromised);39chai.use(chaiAsPromised);
modifiedtests/src/.outdated/enableContractSponsoring.test.tsdiffbeforeafterboth
18import chai from 'chai';18import chai from 'chai';
19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
20import usingApi from '../substrate/substrate-api';20import usingApi from '../substrate/substrate-api';
21import {deployFlipper, getFlipValue, toggleFlipValueExpectSuccess} from '../util/contracthelpers';21import {deployFlipper, getFlipValue, toggleFlipValueExpectSuccess} from '../deprecated-helpers/contracthelpers';
22import {22import {
23 enableContractSponsoringExpectFailure,23 enableContractSponsoringExpectFailure,
24 enableContractSponsoringExpectSuccess,24 enableContractSponsoringExpectSuccess,
25 findUnusedAddress,25 findUnusedAddress,
26 setContractSponsoringRateLimitExpectSuccess,26 setContractSponsoringRateLimitExpectSuccess,
27} from '../util/helpers';27} from '../deprecated-helpers/helpers';
2828
29chai.use(chaiAsPromised);29chai.use(chaiAsPromised);
30const expect = chai.expect;30const expect = chai.expect;
addedtests/src/.outdated/eth/scheduling.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/.outdated/overflow.test.tsdiffbeforeafterboth
18import chai from 'chai';18import chai from 'chai';
19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
20import usingApi from '../substrate/substrate-api';20import usingApi from '../substrate/substrate-api';
21import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from '../util/helpers';21import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from '../deprecated-helpers/helpers';
2222
23chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
24const expect = chai.expect;24const expect = chai.expect;
modifiedtests/src/.outdated/removeFromContractAllowList.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 usingApi from '../substrate/substrate-api';17import usingApi from '../substrate/substrate-api';
18import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from '../util/contracthelpers';18import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from '../deprecated-helpers/contracthelpers';
19import {addToContractAllowListExpectSuccess, isAllowlistedInContract, removeFromContractAllowListExpectFailure, removeFromContractAllowListExpectSuccess, toggleContractAllowlistExpectSuccess} from '../util/helpers';19import {addToContractAllowListExpectSuccess, isAllowlistedInContract, removeFromContractAllowListExpectFailure, removeFromContractAllowListExpectSuccess, toggleContractAllowlistExpectSuccess} from '../deprecated-helpers/helpers';
20import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {expect} from 'chai';21import {expect} from 'chai';
2222
modifiedtests/src/.outdated/scheduler.test.tsdiffbeforeafterboth
39 getFreeBalance,39 getFreeBalance,
40 confirmSponsorshipByKeyExpectSuccess,40 confirmSponsorshipByKeyExpectSuccess,
41 scheduleExpectFailure,41 scheduleExpectFailure,
42} from '../util/helpers';42} from '../deprecated-helpers/helpers';
43import {IKeyringPair} from '@polkadot/types/types';43import {IKeyringPair} from '@polkadot/types/types';
4444
45chai.use(chaiAsPromised);45chai.use(chaiAsPromised);
modifiedtests/src/.outdated/setChainLimits.test.tsdiffbeforeafterboth
21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,
22 setChainLimitsExpectFailure,22 setChainLimitsExpectFailure,
23 IChainLimits,23 IChainLimits,
24} from '../util/helpers';24} from '../deprecated-helpers/helpers';
2525
26// todo:playgrounds skipped ~ postponed26// todo:playgrounds skipped ~ postponed
27describe.skip('Negative Integration Test setChainLimits', () => {27describe.skip('Negative Integration Test setChainLimits', () => {
modifiedtests/src/.outdated/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import usingApi from '../substrate/substrate-api';18import usingApi from '../substrate/substrate-api';
19import waitNewBlocks from '../substrate/wait-new-blocks';19import waitNewBlocks from '../substrate/wait-new-blocks';
20import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from '../util/contracthelpers';20import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from '../deprecated-helpers/contracthelpers';
21import {21import {
22 enableContractSponsoringExpectSuccess,22 enableContractSponsoringExpectSuccess,
23 findUnusedAddress,23 findUnusedAddress,
24 setContractSponsoringRateLimitExpectFailure,24 setContractSponsoringRateLimitExpectFailure,
25 setContractSponsoringRateLimitExpectSuccess,25 setContractSponsoringRateLimitExpectSuccess,
26} from '../util/helpers';26} from '../deprecated-helpers/helpers';
2727
28// todo:playgrounds skipped~postponed test28// todo:playgrounds skipped~postponed test
29describe.skip('Integration Test setContractSponsoringRateLimit', () => {29describe.skip('Integration Test setContractSponsoringRateLimit', () => {
modifiedtests/src/.outdated/toggleContractAllowList.test.tsdiffbeforeafterboth
20import {20import {
21 deployFlipper,21 deployFlipper,
22 getFlipValue,22 getFlipValue,
23} from '../util/contracthelpers';23} from '../deprecated-helpers/contracthelpers';
24import {24import {
25 getGenericResult,25 getGenericResult,
26} from '../util/helpers';26} from '../deprecated-helpers/helpers';
2727
28chai.use(chaiAsPromised);28chai.use(chaiAsPromised);
29const expect = chai.expect;29const expect = chai.expect;
modifiedtests/src/.outdated/xcmTransfer.test.tsdiffbeforeafterboth
21import {ApiOptions} from '@polkadot/api/types';21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
24import {getGenericResult} from '../util/helpers';24import {getGenericResult} from '../deprecated-helpers/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';
2727
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
110 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);110 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);
111 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});111 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});
112112
113 const chainAdminLimit = (helper.api!.consts.common.collectionAdminsLimit as any).toNumber();113 const chainAdminLimit = (helper.getApi().consts.common.collectionAdminsLimit as any).toNumber();
114 expect(chainAdminLimit).to.be.equal(5);114 expect(chainAdminLimit).to.be.equal(5);
115115
116 for (let i = 0; i < chainAdminLimit; i++) {116 for (let i = 0; i < chainAdminLimit; i++) {
modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {18import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util/playgrounds';
19 normalizeAccountId,
20 getModuleNames,
21 Pallets,
22} from './util/helpers';
23import {itSub, usingPlaygrounds} from './util/playgrounds';
24import {encodeAddress} from '@polkadot/util-crypto';19import {encodeAddress} from '@polkadot/util-crypto';
25import {stringToU8a} from '@polkadot/util';20import {stringToU8a} from '@polkadot/util';
26import {SponsoringMode} from './eth/util/helpers';
27import {DevUniqueHelper} from './util/playgrounds/unique.dev';21import {DevUniqueHelper} from './util/playgrounds/unique.dev';
28import {itEth, expect} from './eth/util/playgrounds';22import {itEth, expect, SponsoringMode} from './eth/util/playgrounds';
2923
30let alice: IKeyringPair;24let alice: IKeyringPair;
31let palletAdmin: IKeyringPair;25let palletAdmin: IKeyringPair;
42describe('App promotion', () => {36describe('App promotion', () => {
43 before(async function () {37 before(async function () {
44 await usingPlaygrounds(async (helper, privateKey) => {38 await usingPlaygrounds(async (helper, privateKey) => {
45 if (!getModuleNames(helper.api!).includes(Pallets.AppPromotion)) this.skip();39 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);
46 alice = privateKey('//Alice');40 alice = privateKey('//Alice');
47 palletAdmin = privateKey('//Charlie'); // TODO use custom address41 palletAdmin = privateKey('//Charlie'); // TODO use custom address
48 await helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));42 const api = helper.getApi();
43 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
49 nominal = helper.balance.getOneTokenNominal();44 nominal = helper.balance.getOneTokenNominal();
50 await helper.balance.transferToSubstrate(alice, palletAdmin.address, 1000n * nominal);45 await helper.balance.transferToSubstrate(alice, palletAdmin.address, 1000n * nominal);
51 await helper.balance.transferToSubstrate(alice, palletAddress, 1000n * nominal);46 await helper.balance.transferToSubstrate(alice, palletAddress, 1000n * nominal);
231 226
232 describe('admin adress', () => {227 describe('admin adress', () => {
233 itSub('can be set by sudo only', async ({helper}) => {228 itSub('can be set by sudo only', async ({helper}) => {
229 const api = helper.getApi();
234 const nonAdmin = accounts.pop()!;230 const nonAdmin = accounts.pop()!;
235 // nonAdmin can not set admin not from himself nor as a sudo231 // nonAdmin can not set admin not from himself nor as a sudo
236 await expect(helper.signTransaction(nonAdmin, helper.api!.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;232 await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;
237 await expect(helper.signTransaction(nonAdmin, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;233 await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;
238 234
239 // Alice can235 // Alice can
240 await expect(helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;236 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
241 });237 });
242 238
243 itSub('can be any valid CrossAccountId', async ({helper}) => {239 itSub('can be any valid CrossAccountId', async ({helper}) => {
244 // We are not going to set an eth address as a sponsor,240 // We are not going to set an eth address as a sponsor,
245 // but we do want to check, it doesn't break anything;241 // but we do want to check, it doesn't break anything;
242 const api = helper.getApi();
246 const account = accounts.pop()!;243 const account = accounts.pop()!;
247 const ethAccount = helper.address.substrateToEth(account.address); 244 const ethAccount = helper.address.substrateToEth(account.address);
248 // Alice sets Ethereum address as a sudo. Then Substrate address back...245 // Alice sets Ethereum address as a sudo. Then Substrate address back...
249 await expect(helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;246 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;
250 await expect(helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;247 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
251 248
252 // ...It doesn't break anything;249 // ...It doesn't break anything;
253 const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});250 const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
254 await expect(helper.signTransaction(account, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;251 await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
255 });252 });
256 253
257 itSub('can be reassigned', async ({helper}) => {254 itSub('can be reassigned', async ({helper}) => {
255 const api = helper.getApi();
258 const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];256 const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];
259 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});257 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
260 258
261 await expect(helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress(normalizeAccountId(oldAdmin))))).to.be.fulfilled;259 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;
262 await expect(helper.signTransaction(alice, helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress(normalizeAccountId(newAdmin))))).to.be.fulfilled;260 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;
263 await expect(helper.signTransaction(oldAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;261 await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
264 262
265 await expect(helper.signTransaction(newAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;263 await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;
266 });264 });
267 });265 });
268 266
269 describe('collection sponsoring', () => {267 describe('collection sponsoring', () => {
270 before(async function () {268 before(async function () {
271 await usingPlaygrounds(async (helper) => {269 await usingPlaygrounds(async (helper) => {
272 const tx = helper.api!.tx.sudo.sudo(helper.api!.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));270 const api = helper.getApi();
271 const tx = api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));
273 await helper.signTransaction(alice, tx);272 await helper.signTransaction(alice, tx);
274 });273 });
275 });274 });
276 275
277 itSub('should actually sponsor transactions', async ({helper}) => {276 itSub('should actually sponsor transactions', async ({helper}) => {
277 const api = helper.getApi();
278 const [collectionOwner, tokenSender, receiver] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];278 const [collectionOwner, tokenSender, receiver] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];
279 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'Name', description: 'Description', tokenPrefix: 'Prefix', limits: {sponsorTransferTimeout: 0}});279 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'Name', description: 'Description', tokenPrefix: 'Prefix', limits: {sponsorTransferTimeout: 0}});
280 const token = await collection.mintToken(collectionOwner, {Substrate: tokenSender.address});280 const token = await collection.mintToken(collectionOwner, {Substrate: tokenSender.address});
281 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId));281 await helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId));
282 const palletBalanceBefore = await helper.balance.getSubstrate(palletAddress);282 const palletBalanceBefore = await helper.balance.getSubstrate(palletAddress);
283 283
284 await token.transfer(tokenSender, {Substrate: receiver.address});284 await token.transfer(tokenSender, {Substrate: receiver.address});
291 });291 });
292 292
293 itSub('can not be set by non admin', async ({helper}) => {293 itSub('can not be set by non admin', async ({helper}) => {
294 const api = helper.getApi();
294 const [collectionOwner, nonAdmin] = [accounts.pop()!, accounts.pop()!];295 const [collectionOwner, nonAdmin] = [accounts.pop()!, accounts.pop()!];
295 296
296 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});297 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
297 298
298 await expect(helper.signTransaction(nonAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;299 await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
299 expect((await collection.getData())?.raw.sponsorship).to.equal('Disabled');300 expect((await collection.getData())?.raw.sponsorship).to.equal('Disabled');
300 });301 });
301 302
302 itSub('should set pallet address as confirmed admin', async ({helper}) => {303 itSub('should set pallet address as confirmed admin', async ({helper}) => {
304 const api = helper.getApi();
303 const [collectionOwner, oldSponsor] = [accounts.pop()!, accounts.pop()!];305 const [collectionOwner, oldSponsor] = [accounts.pop()!, accounts.pop()!];
304 306
305 // Can set sponsoring for collection without sponsor307 // Can set sponsoring for collection without sponsor
306 const collectionWithoutSponsor = await helper.nft.mintCollection(collectionOwner, {name: 'No-sponsor', description: 'New Collection', tokenPrefix: 'Promotion'});308 const collectionWithoutSponsor = await helper.nft.mintCollection(collectionOwner, {name: 'No-sponsor', description: 'New Collection', tokenPrefix: 'Promotion'});
307 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collectionWithoutSponsor.collectionId))).to.be.fulfilled;309 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithoutSponsor.collectionId))).to.be.fulfilled;
308 expect((await collectionWithoutSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});310 expect((await collectionWithoutSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});
309 311
310 // Can set sponsoring for collection with unconfirmed sponsor312 // Can set sponsoring for collection with unconfirmed sponsor
311 const collectionWithUnconfirmedSponsor = await helper.nft.mintCollection(collectionOwner, {name: 'Unconfirmed', description: 'New Collection', tokenPrefix: 'Promotion', pendingSponsor: oldSponsor.address});313 const collectionWithUnconfirmedSponsor = await helper.nft.mintCollection(collectionOwner, {name: 'Unconfirmed', description: 'New Collection', tokenPrefix: 'Promotion', pendingSponsor: oldSponsor.address});
312 expect((await collectionWithUnconfirmedSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Unconfirmed: oldSponsor.address});314 expect((await collectionWithUnconfirmedSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Unconfirmed: oldSponsor.address});
313 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collectionWithUnconfirmedSponsor.collectionId))).to.be.fulfilled;315 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithUnconfirmedSponsor.collectionId))).to.be.fulfilled;
314 expect((await collectionWithUnconfirmedSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});316 expect((await collectionWithUnconfirmedSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});
315 317
316 // Can set sponsoring for collection with confirmed sponsor318 // Can set sponsoring for collection with confirmed sponsor
317 const collectionWithConfirmedSponsor = await helper.nft.mintCollection(collectionOwner, {name: 'Confirmed', description: 'New Collection', tokenPrefix: 'Promotion', pendingSponsor: oldSponsor.address});319 const collectionWithConfirmedSponsor = await helper.nft.mintCollection(collectionOwner, {name: 'Confirmed', description: 'New Collection', tokenPrefix: 'Promotion', pendingSponsor: oldSponsor.address});
318 await collectionWithConfirmedSponsor.confirmSponsorship(oldSponsor);320 await collectionWithConfirmedSponsor.confirmSponsorship(oldSponsor);
319 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collectionWithConfirmedSponsor.collectionId))).to.be.fulfilled;321 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithConfirmedSponsor.collectionId))).to.be.fulfilled;
320 expect((await collectionWithConfirmedSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});322 expect((await collectionWithConfirmedSponsor.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});
321 });323 });
322 324
323 itSub('can be overwritten by collection owner', async ({helper}) => { 325 itSub('can be overwritten by collection owner', async ({helper}) => {
326 const api = helper.getApi();
324 const [collectionOwner, newSponsor] = [accounts.pop()!, accounts.pop()!];327 const [collectionOwner, newSponsor] = [accounts.pop()!, accounts.pop()!];
325 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});328 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
326 const collectionId = collection.collectionId;329 const collectionId = collection.collectionId;
327 330
328 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collectionId))).to.be.fulfilled;331 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionId))).to.be.fulfilled;
329 332
330 // Collection limits still can be changed by the owner333 // Collection limits still can be changed by the owner
331 expect(await collection.setLimits(collectionOwner, {sponsorTransferTimeout: 0})).to.be.true;334 expect(await collection.setLimits(collectionOwner, {sponsorTransferTimeout: 0})).to.be.true;
338 });341 });
339 342
340 itSub('should not overwrite collection limits set by the owner earlier', async ({helper}) => {343 itSub('should not overwrite collection limits set by the owner earlier', async ({helper}) => {
344 const api = helper.getApi();
341 const limits = {ownerCanDestroy: true, ownerCanTransfer: true, sponsorTransferTimeout: 0};345 const limits = {ownerCanDestroy: true, ownerCanTransfer: true, sponsorTransferTimeout: 0};
342 const collectionWithLimits = await helper.nft.mintCollection(alice, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits});346 const collectionWithLimits = await helper.nft.mintCollection(alice, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits});
343 347
344 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collectionWithLimits.collectionId))).to.be.fulfilled;348 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithLimits.collectionId))).to.be.fulfilled;
345 expect((await collectionWithLimits.getData())?.raw.limits).to.be.deep.contain(limits);349 expect((await collectionWithLimits.getData())?.raw.limits).to.be.deep.contain(limits);
346 });350 });
347 351
348 itSub('should reject transaction if collection doesn\'t exist', async ({helper}) => {352 itSub('should reject transaction if collection doesn\'t exist', async ({helper}) => {
353 const api = helper.getApi();
349 const collectionOwner = accounts.pop()!;354 const collectionOwner = accounts.pop()!;
350 355
351 // collection has never existed356 // collection has never existed
352 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(999999999))).to.be.rejected;357 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(999999999))).to.be.rejected;
353 // collection has been burned358 // collection has been burned
354 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});359 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
355 await collection.burn(collectionOwner);360 await collection.burn(collectionOwner);
356 361
357 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;362 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
358 });363 });
359 });364 });
360 365
361 describe('stopSponsoringCollection', () => {366 describe('stopSponsoringCollection', () => {
362 itSub('can not be called by non-admin', async ({helper}) => { 367 itSub('can not be called by non-admin', async ({helper}) => {
368 const api = helper.getApi();
363 const [collectionOwner, nonAdmin] = [accounts.pop()!, accounts.pop()!];369 const [collectionOwner, nonAdmin] = [accounts.pop()!, accounts.pop()!];
364 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});370 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
365 371
366 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;372 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;
367 373
368 await expect(helper.signTransaction(nonAdmin, helper.api!.tx.appPromotion.stopSponsoringCollection(collection.collectionId))).to.be.rejected;374 await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.stopSponsoringCollection(collection.collectionId))).to.be.rejected;
369 expect((await collection.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});375 expect((await collection.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: palletAddress});
370 });376 });
371 377
372 itSub('should set sponsoring as disabled', async ({helper}) => {378 itSub('should set sponsoring as disabled', async ({helper}) => {
379 const api = helper.getApi();
373 const [collectionOwner, recepient] = [accounts.pop()!, accounts.pop()!];380 const [collectionOwner, recepient] = [accounts.pop()!, accounts.pop()!];
374 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits: {sponsorTransferTimeout: 0}});381 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits: {sponsorTransferTimeout: 0}});
375 const token = await collection.mintToken(collectionOwner, {Substrate: collectionOwner.address});382 const token = await collection.mintToken(collectionOwner, {Substrate: collectionOwner.address});
376 383
377 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorCollection(collection.collectionId));384 await helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId));
378 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.stopSponsoringCollection(collection.collectionId));385 await helper.signTransaction(palletAdmin, api.tx.appPromotion.stopSponsoringCollection(collection.collectionId));
379 386
380 expect((await collection.getData())?.raw.sponsorship).to.be.equal('Disabled');387 expect((await collection.getData())?.raw.sponsorship).to.be.equal('Disabled');
381 388
387 });394 });
388 395
389 itSub('should not affect collection which is not sponsored by pallete', async ({helper}) => {396 itSub('should not affect collection which is not sponsored by pallete', async ({helper}) => {
397 const api = helper.getApi();
390 const collectionOwner = accounts.pop()!;398 const collectionOwner = accounts.pop()!;
391 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', pendingSponsor: collectionOwner.address});399 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', pendingSponsor: collectionOwner.address});
392 await collection.confirmSponsorship(collectionOwner);400 await collection.confirmSponsorship(collectionOwner);
393 401
394 await expect(helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.stopSponsoringCollection(collection.collectionId))).to.be.rejected;402 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.stopSponsoringCollection(collection.collectionId))).to.be.rejected;
395 403
396 expect((await collection.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: collectionOwner.address});404 expect((await collection.getData())?.raw.sponsorship).to.be.deep.equal({Confirmed: collectionOwner.address});
397 });405 });
415 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address]);423 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address]);
416 424
417 expect(await contractHelper.methods.hasSponsor(flipper.options.address).call()).to.be.true; 425 expect(await contractHelper.methods.hasSponsor(flipper.options.address).call()).to.be.true;
418 expect((await helper.api!.query.evmContractHelpers.owner(flipper.options.address)).toJSON()).to.be.equal(contractOwner); 426 expect((await helper.callRpc('api.query.evmContractHelpers.owner', [flipper.options.address])).toJSON()).to.be.equal(contractOwner);
419 expect((await helper.api!.query.evmContractHelpers.sponsoring(flipper.options.address)).toJSON()).to.deep.equal({427 expect((await helper.callRpc('api.query.evmContractHelpers.sponsoring', [flipper.options.address])).toJSON()).to.deep.equal({
420 confirmed: {428 confirmed: {
421 substrate: palletAddress,429 substrate: palletAddress,
422 },430 },
431 await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.fulfilled;439 await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.fulfilled;
432 440
433 // Contract is self sponsored441 // Contract is self sponsored
434 expect((await helper.api!.query.evmContractHelpers.sponsoring(flipper.options.address)).toJSON()).to.be.deep.equal({442 expect((await helper.callRpc('api.query.evmContractHelpers.sponsoring', [flipper.options.address])).toJSON()).to.be.deep.equal({
435 confirmed: {443 confirmed: {
436 ethereum: flipper.options.address.toLowerCase(),444 ethereum: flipper.options.address.toLowerCase(),
437 },445 },
462 await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;470 await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;
463 471
464 expect(await contractHelper.methods.hasSponsor(flipper.options.address).call()).to.be.true; 472 expect(await contractHelper.methods.hasSponsor(flipper.options.address).call()).to.be.true;
465 expect((await helper.api!.query.evmContractHelpers.owner(flipper.options.address)).toJSON()).to.be.equal(contractOwner); 473 expect((await helper.callRpc('api.query.evmContractHelpers.owner', [flipper.options.address])).toJSON()).to.be.equal(contractOwner);
466 expect((await helper.api!.query.evmContractHelpers.sponsoring(flipper.options.address)).toJSON()).to.deep.equal({474 expect((await helper.callRpc('api.query.evmContractHelpers.sponsoring', [flipper.options.address])).toJSON()).to.deep.equal({
467 confirmed: {475 confirmed: {
468 ethereum: flipper.options.address.toLowerCase(),476 ethereum: flipper.options.address.toLowerCase(),
469 },477 },
482 await expect(helper.executeExtrinsic(nonAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true)).to.be.rejectedWith('appPromotion.NoPermission');490 await expect(helper.executeExtrinsic(nonAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true)).to.be.rejectedWith('appPromotion.NoPermission');
483 491
484 // contract still self-sponsored 492 // contract still self-sponsored
485 expect((await helper.api!.query.evmContractHelpers.sponsoring(flipper.options.address)).toJSON()).to.deep.equal({493 expect((await helper.callRpc('api.query.evmContractHelpers.sponsoring', [flipper.options.address])).toJSON()).to.deep.equal({
486 confirmed: {494 confirmed: {
487 ethereum: flipper.options.address.toLowerCase(),495 ethereum: flipper.options.address.toLowerCase(),
488 },496 },
505 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n);513 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n);
506 514
507 // Set promotion to the Flipper515 // Set promotion to the Flipper
508 await helper.signTransaction(palletAdmin, helper.api!.tx.appPromotion.sponsorContract(flipper.options.address));516 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true);
509 517
510 // Caller calls Flipper518 // Caller calls Flipper
511 await flipper.methods.flip().send({from: caller});519 await flipper.methods.flip().send({from: caller});
536 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.stopSponsoringContract', [flipper.options.address], true);544 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.stopSponsoringContract', [flipper.options.address], true);
537 545
538 expect(await contractHelper.methods.hasSponsor(flipper.options.address).call()).to.be.false; 546 expect(await contractHelper.methods.hasSponsor(flipper.options.address).call()).to.be.false;
539 expect((await helper.api!.query.evmContractHelpers.owner(flipper.options.address)).toJSON()).to.be.equal(contractOwner); 547 expect((await helper.callRpc('api.query.evmContractHelpers.owner', [flipper.options.address])).toJSON()).to.be.equal(contractOwner);
540 expect((await helper.api!.query.evmContractHelpers.sponsoring(flipper.options.address)).toJSON()).to.deep.equal({548 expect((await helper.callRpc('api.query.evmContractHelpers.sponsoring', [flipper.options.address])).toJSON()).to.deep.equal({
541 disabled: null,549 disabled: null,
542 });550 });
543 551
717// Wait while promotion period less than specified block, to avoid boundary cases725// Wait while promotion period less than specified block, to avoid boundary cases
718// 0 if this should be the beginning of the period.726// 0 if this should be the beginning of the period.
719async function waitPromotionPeriodDoesntEnd(helper: DevUniqueHelper, waitBlockLessThan = LOCKING_PERIOD / 3n) {727async function waitPromotionPeriodDoesntEnd(helper: DevUniqueHelper, waitBlockLessThan = LOCKING_PERIOD / 3n) {
720 const relayBlockNumber = (await helper.api!.query.parachainSystem.validationData()).value.relayParentNumber.toNumber(); // await helper.chain.getLatestBlockNumber();728 const relayBlockNumber = (await helper.callRpc('api.query.parachainSystem.validationData', [])).value.relayParentNumber.toNumber(); // await helper.chain.getLatestBlockNumber();
721 const currentPeriodBlock = BigInt(relayBlockNumber) % LOCKING_PERIOD;729 const currentPeriodBlock = BigInt(relayBlockNumber) % LOCKING_PERIOD;
722730
723 if (currentPeriodBlock > waitBlockLessThan) {731 if (currentPeriodBlock > waitBlockLessThan) {
modifiedtests/src/approve.test.tsdiffbeforeafterboth
60 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});60 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
61 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});61 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
62 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;62 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
63 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));63 await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));
64 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;64 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
65 });65 });
6666
275 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});275 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
276 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});276 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
277 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;277 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
278 await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));278 await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));
279 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;279 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
280 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});280 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});
281 await expect(transferTokenFromTx()).to.be.rejected;281 await expect(transferTokenFromTx()).to.be.rejected;
328 itSub('1 for NFT', async ({helper}) => {328 itSub('1 for NFT', async ({helper}) => {
329 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});329 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
330 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});330 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
331 const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2));331 const approveTx = async () => helper.signTransaction(bob, helper.constructApiCall('api.tx.unique.approve', [{Substrate: charlie.address}, collectionId, tokenId, 2]));
332 await expect(approveTx()).to.be.rejected;332 await expect(approveTx()).to.be.rejected;
333 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;333 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
334 });334 });
modifiedtests/src/block-production.test.tsdiffbeforeafterboth
3737
38describe('Block Production smoke test', () => {38describe('Block Production smoke test', () => {
39 itSub('Node produces new blocks', async ({helper}) => {39 itSub('Node produces new blocks', async ({helper}) => {
40 const blocks: number[] | undefined = await getBlocks(helper.api!);40 const blocks: number[] | undefined = await getBlocks(helper.getApi());
41 expect(blocks[0]).to.be.lessThan(blocks[1]);41 expect(blocks[0]).to.be.lessThan(blocks[1]);
42 });42 });
43});43});
modifiedtests/src/calibrate.tsdiffbeforeafterboth
1import {ApiPromise} from '@polkadot/api';
2import {IKeyringPair} from '@polkadot/types/types';1import {IKeyringPair} from '@polkadot/types/types';
3import Web3 from 'web3';2
4import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, recordEthFee, usingWeb3} from './eth/util/helpers';3import {usingEthPlaygrounds, EthUniqueHelper} from './eth/util/playgrounds';
5import usingApi, {executeTransaction} from './substrate/substrate-api';4
6import {createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, UNIQUE, waitNewBlocks} from './util/helpers';
7import nonFungibleAbi from './eth/nonFungibleAbi.json';
85
9function linearRegression(points: { x: bigint, y: bigint }[]) {6function linearRegression(points: { x: bigint, y: bigint }[]) {
10 let sumxy = 0n;7 let sumxy = 0n;
59 }).reduce((a, b) => a + b, 0n) / BigInt(points.length));56 }).reduce((a, b) => a + b, 0n) / BigInt(points.length));
60}57}
6158
62async function calibrateWeightToFee(api: ApiPromise, privateKey: (account: string) => IKeyringPair) {59async function calibrateWeightToFee(helper: EthUniqueHelper, privateKey: (account: string) => IKeyringPair) {
63 const alice = privateKey('//Alice');60 const alice = privateKey('//Alice');
64 const bob = privateKey('//Bob');61 const bob = privateKey('//Bob');
65 const dataPoints = [];62 const dataPoints = [];
6663
67 {64 {
68 const collectionId = await createCollectionExpectSuccess();65 const collection = await helper.nft.mintCollection(alice, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
69 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');66 const token = await collection.mintToken(alice, {Substrate: alice.address});
70 const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();67 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
71 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');68 await token.transfer(alice, {Substrate: bob.address});
72 const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();69 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
7370
74 console.log(`Original price: ${Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE)} UNQ`);71 console.log(`Original price: ${Number(aliceBalanceBefore - aliceBalanceAfter) / Number(helper.balance.getOneTokenNominal())} UNQ`);
75 }72 }
7673
74 const api = helper.getApi();
77 const defaultCoeff = (api.consts.configuration.defaultWeightToFeeCoefficient as any).toBigInt();75 const defaultCoeff = (api.consts.configuration.defaultWeightToFeeCoefficient as any).toBigInt();
78 for (let i = -5; i < 5; i++) {76 for (let i = -5; i < 5; i++) {
79 await executeTransaction(api, alice, api.tx.sudo.sudo(api.tx.configuration.setWeightToFeeCoefficientOverride(defaultCoeff + defaultCoeff / 1000n * BigInt(i))));77 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.configuration.setWeightToFeeCoefficientOverride(defaultCoeff + defaultCoeff / 1000n * BigInt(i))));
8078
81 const coefficient = (await api.query.configuration.weightToFeeCoefficientOverride() as any).toBigInt();79 const coefficient = (await api.query.configuration.weightToFeeCoefficientOverride() as any).toBigInt();
82 const collectionId = await createCollectionExpectSuccess();80 const collection = await helper.nft.mintCollection(alice, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
83 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');81 const token = await collection.mintToken(alice, {Substrate: alice.address});
8482
85 const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();83 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
86 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');84 await token.transfer(alice, {Substrate: bob.address});
87 const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();85 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
8886
89 const transferPrice = aliceBalanceBefore - aliceBalanceAfter;87 const transferPrice = aliceBalanceBefore - aliceBalanceAfter;
9088
9492
95 // console.log(`Error: ${error(dataPoints, x => a*x+b)}`);93 // console.log(`Error: ${error(dataPoints, x => a*x+b)}`);
9694
97 const perfectValue = a * UNIQUE / 10n + b;95 const perfectValue = a * helper.balance.getOneTokenNominal() / 10n + b;
98 await executeTransaction(api, alice, api.tx.sudo.sudo(api.tx.configuration.setWeightToFeeCoefficientOverride(perfectValue.toString())));96 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.configuration.setWeightToFeeCoefficientOverride(perfectValue.toString())));
9997
100 {98 {
101 const collectionId = await createCollectionExpectSuccess();99 const collection = await helper.nft.mintCollection(alice, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
102 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');100 const token = await collection.mintToken(alice, {Substrate: alice.address});
103 const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();101 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
104 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');102 await token.transfer(alice, {Substrate: bob.address});
105 const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();103 const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
106104
107 console.log(`Calibrated price: ${Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE)} UNQ`);105 console.log(`Calibrated price: ${Number(aliceBalanceBefore - aliceBalanceAfter) / Number(helper.balance.getOneTokenNominal())} UNQ`);
108 }106 }
109}107}
110108
111async function calibrateMinGasPrice(api: ApiPromise, web3: Web3, privateKey: (account: string) => IKeyringPair) {109async function calibrateMinGasPrice(helper: EthUniqueHelper, privateKey: (account: string) => IKeyringPair) {
112 const alice = privateKey('//Alice');110 const alice = privateKey('//Alice');
113 const caller = await createEthAccountWithBalance(api, web3, privateKey);111 const caller = await helper.eth.createAccountWithBalance(alice);
114 const receiver = createEthAccount(web3);112 const receiver = helper.eth.createAccount();
115 const dataPoints = [];113 const dataPoints = [];
116114
117 {115 {
118 const collectionId = await createCollectionExpectSuccess();116 const collection = await helper.nft.mintCollection(alice, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
119 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Ethereum: caller});117 const token = await collection.mintToken(alice, {Ethereum: caller});
120118
121 const address = collectionIdToAddress(collectionId);119 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
122 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});120 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
123121
124 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));122 const cost = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, token.tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS}));
125123
126 console.log(`Original price: ${Number(cost) / Number(UNIQUE)} UNQ`);124 console.log(`Original price: ${Number(cost) / Number(helper.balance.getOneTokenNominal())} UNQ`);
127 }125 }
128126
127 const api = helper.getApi();
129 const defaultCoeff = (api.consts.configuration.defaultMinGasPrice as any).toBigInt();128 const defaultCoeff = (api.consts.configuration.defaultMinGasPrice as any).toBigInt();
130 for (let i = -8; i < 8; i++) {129 for (let i = -8; i < 8; i++) {
131 const gasPrice = defaultCoeff + defaultCoeff / 100000n * BigInt(i);130 const gasPrice = defaultCoeff + defaultCoeff / 100000n * BigInt(i);
132 const gasPriceStr = '0x' + gasPrice.toString(16);131 const gasPriceStr = '0x' + gasPrice.toString(16);
133 await executeTransaction(api, alice, api.tx.sudo.sudo(api.tx.configuration.setMinGasPriceOverride(gasPrice)));132 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.configuration.setMinGasPriceOverride(gasPrice)));
134133
135 const coefficient = (await api.query.configuration.minGasPriceOverride() as any).toBigInt();134 const coefficient = (await api.query.configuration.minGasPriceOverride() as any).toBigInt();
136 const collectionId = await createCollectionExpectSuccess();135 const collection = await helper.nft.mintCollection(alice, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
137 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Ethereum: caller});136 const token = await collection.mintToken(alice, {Ethereum: caller});
138137
139 const address = collectionIdToAddress(collectionId);138 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
140 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, gasPrice: gasPriceStr, ...GAS_ARGS});139 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
141140
142 const transferPrice = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));141 const transferPrice = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, token.tokenId).send({from: caller, gasPrice: gasPriceStr, gas: helper.eth.DEFAULT_GAS}));
143142
144 dataPoints.push({x: transferPrice, y: coefficient});143 dataPoints.push({x: transferPrice, y: coefficient});
145 }144 }
149 // console.log(`Error: ${error(dataPoints, x => a*x+b)}`);148 // console.log(`Error: ${error(dataPoints, x => a*x+b)}`);
150149
151 // * 0.15 = * 10000 / 66666150 // * 0.15 = * 10000 / 66666
152 const perfectValue = a * UNIQUE * 1000000n / 6666666n + b;151 const perfectValue = a * helper.balance.getOneTokenNominal() * 1000000n / 6666666n + b;
153 await executeTransaction(api, alice, api.tx.sudo.sudo(api.tx.configuration.setMinGasPriceOverride(perfectValue.toString())));152 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.configuration.setMinGasPriceOverride(perfectValue.toString())));
154153
155 {154 {
156 const collectionId = await createCollectionExpectSuccess();155 const collection = await helper.nft.mintCollection(alice, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
157 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', {Ethereum: caller});156 const token = await collection.mintToken(alice, {Ethereum: caller});
158157
159 const address = collectionIdToAddress(collectionId);158 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
160 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});159 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
161160
162 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));161 const cost = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, token.tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS}));
163162
164 console.log(`Calibrated price: ${Number(cost) / Number(UNIQUE)} UNQ`);163 console.log(`Calibrated price: ${Number(cost) / Number(helper.balance.getOneTokenNominal())} UNQ`);
165 }164 }
166}165}
167166
168(async () => {167(async () => {
169 await usingApi(async (api, privateKey) => {168 await usingEthPlaygrounds(async (helper: EthUniqueHelper, privateKey) => {
170 // Second run slightly reduces error sometimes, as price line is not actually straight, this is a curve169 // Second run slightly reduces error sometimes, as price line is not actually straight, this is a curve
171170
172 await calibrateWeightToFee(api, privateKey);171 await calibrateWeightToFee(helper, privateKey);
173 await calibrateWeightToFee(api, privateKey);172 await calibrateWeightToFee(helper, privateKey);
174173
175 await usingWeb3(async web3 => {174 await calibrateMinGasPrice(helper, privateKey);
176 await calibrateMinGasPrice(api, web3, privateKey);
177 await calibrateMinGasPrice(api, web3, privateKey);
178 });
179
180 await api.disconnect();175 await calibrateMinGasPrice(helper, privateKey);
181 });176 });
182})();177})();
183178
modifiedtests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth
178 tokenPrefix: 'COL',178 tokenPrefix: 'COL',
179 }, 0);179 }, 0);
180180
181 const api = helper.api;
182 await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, {181 await helper.executeExtrinsic(alice, 'api.tx.unique.createMultipleItemsEx',[collection.collectionId, {
183 Fungible: new Map([182 Fungible: new Map([
184 [JSON.stringify({Substrate: alice.address}), 50],183 [JSON.stringify({Substrate: alice.address}), 50],
185 [JSON.stringify({Substrate: bob.address}), 100],184 [JSON.stringify({Substrate: bob.address}), 100],
186 ]),185 ]),
187 }));186 }], true);
188187
189 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(50n);188 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(50n);
190 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(100n);189 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(100n);
200 ],199 ],
201 });200 });
202201
203 const api = helper.api;
204 await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, {202 await helper.executeExtrinsic(alice, 'api.tx.unique.createMultipleItemsEx', [collection.collectionId, {
205 RefungibleMultipleOwners: {203 RefungibleMultipleOwners: {
206 users: new Map([204 users: new Map([
207 [JSON.stringify({Substrate: alice.address}), 1],205 [JSON.stringify({Substrate: alice.address}), 1],
211 {key: 'k', value: 'v'},209 {key: 'k', value: 'v'},
212 ],210 ],
213 },211 },
214 }));212 }], true);
215 const tokenId = await collection.getLastTokenId();213 const tokenId = await collection.getLastTokenId();
216 expect(tokenId).to.be.equal(1);214 expect(tokenId).to.be.equal(1);
217 expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n);215 expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n);
228 ],226 ],
229 });227 });
230
231 const api = helper.api;
232228
233 await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, {229 await helper.executeExtrinsic(alice, 'api.tx.unique.createMultipleItemsEx', [collection.collectionId, {
234 RefungibleMultipleItems: [230 RefungibleMultipleItems: [
235 {231 {
236 user: {Substrate: alice.address}, pieces: 1,232 user: {Substrate: alice.address}, pieces: 1,
245 ],241 ],
246 },242 },
247 ],243 ],
248 }));244 }], true);
249245
250 expect(await collection.getLastTokenId()).to.be.equal(2);246 expect(await collection.getLastTokenId()).to.be.equal(2);
251 expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n);247 expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n);
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
29/*eslint no-async-promise-executor: "off"*/29/*eslint no-async-promise-executor: "off"*/
30function skipInflationBlock(api: ApiPromise): Promise<void> {30function skipInflationBlock(api: ApiPromise): Promise<void> {
31 const promise = new Promise<void>(async (resolve) => {31 const promise = new Promise<void>(async (resolve) => {
32 const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();32 const blockInterval = api.consts.inflation.inflationBlockInterval.toNumber();
33 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {33 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
34 const currentBlock = head.number.toNumber();34 const currentBlock = head.number.toNumber();
35 if (currentBlock % blockInterval < blockInterval - 10) {35 if (currentBlock % blockInterval < blockInterval - 10) {
56 });56 });
5757
58 itSub('Total issuance does not change', async ({helper}) => {58 itSub('Total issuance does not change', async ({helper}) => {
59 const api = helper.api!;59 const api = helper.getApi();
60 await skipInflationBlock(api);60 await skipInflationBlock(api);
61 await helper.wait.newBlocks(1);61 await helper.wait.newBlocks(1);
6262
63 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();63 const totalBefore = (await helper.callRpc('api.query.balances.totalIssuance', [])).toBigInt();
6464
65 await helper.balance.transferToSubstrate(alice, bob.address, 1n);65 await helper.balance.transferToSubstrate(alice, bob.address, 1n);
6666
67 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();67 const totalAfter = (await helper.callRpc('api.query.balances.totalIssuance', [])).toBigInt();
6868
69 expect(totalAfter).to.be.equal(totalBefore);69 expect(totalAfter).to.be.equal(totalBefore);
70 });70 });
7171
72 itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {72 itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {
73 await skipInflationBlock(helper.api!);73 await skipInflationBlock(helper.getApi());
74 await helper.wait.newBlocks(1);74 await helper.wait.newBlocks(1);
7575
76 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);76 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
89 });89 });
9090
91 itSub('Treasury balance increased by failed tx fee', async ({helper}) => {91 itSub('Treasury balance increased by failed tx fee', async ({helper}) => {
92 const api = helper.api!;92 const api = helper.getApi();
93 await helper.wait.newBlocks(1);93 await helper.wait.newBlocks(1);
9494
95 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);95 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
107 });107 });
108108
109 itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {109 itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {
110 await skipInflationBlock(helper.api!);110 await skipInflationBlock(helper.getApi());
111 await helper.wait.newBlocks(1);111 await helper.wait.newBlocks(1);
112112
113 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);113 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
125125
126 itSub('Fees are sane', async ({helper}) => {126 itSub('Fees are sane', async ({helper}) => {
127 const unique = helper.balance.getOneTokenNominal();127 const unique = helper.balance.getOneTokenNominal();
128 await skipInflationBlock(helper.api!);128 await skipInflationBlock(helper.getApi());
129 await helper.wait.newBlocks(1);129 await helper.wait.newBlocks(1);
130130
131 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);131 const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
140 });140 });
141141
142 itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {142 itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {
143 await skipInflationBlock(helper.api!);143 await skipInflationBlock(helper.getApi());
144 await helper.wait.newBlocks(1);144 await helper.wait.newBlocks(1);
145145
146 const collection = await helper.nft.mintCollection(alice, {146 const collection = await helper.nft.mintCollection(alice, {
addedtests/src/deprecated-helpers/contracthelpers.tsdiffbeforeafterboth

no changes

addedtests/src/deprecated-helpers/eth/helpers.d.tsdiffbeforeafterboth

no changes

addedtests/src/deprecated-helpers/eth/helpers.tsdiffbeforeafterboth

no changes

addedtests/src/deprecated-helpers/helpers.tsdiffbeforeafterboth

no changes

addedtests/src/deprecated-helpers/util.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/base.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 {
18 ethBalanceViaSub,
19 GAS_ARGS,
20 recordEthFee,
21} from './util/helpers';
22import {Contract} from 'web3-eth-contract';17import {Contract} from 'web3-eth-contract';
2318
24import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';
37 const deployer = await helper.eth.createAccountWithBalance(donor);33 const deployer = await helper.eth.createAccountWithBalance(donor);
38 const flipper = await helper.eth.deployFlipper(deployer);34 const flipper = await helper.eth.deployFlipper(deployer);
3935
40 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));36 const cost = await helper.eth.calculateFee({Ethereum: deployer}, () => flipper.methods.flip().send({from: deployer}));
41 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;37 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;
42 });38 });
4339
44 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {40 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {
45 const userA = await helper.eth.createAccountWithBalance(donor);41 const userA = await helper.eth.createAccountWithBalance(donor);
46 const userB = helper.eth.createAccount();42 const userB = helper.eth.createAccount();
47 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));43 const cost = await helper.eth.calculateFee({Ethereum: userA}, () => helper.getWeb3().eth.sendTransaction({from: userA, to: userB, value: '1000000', gas: helper.eth.DEFAULT_GAS}));
48 const balanceB = await ethBalanceViaSub(helper.api!, userB);44 const balanceB = await helper.balance.getEthereum(userB);
49 expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;45 expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;
50 });46 });
5147
60 const address = helper.ethAddress.fromCollectionId(collection.collectionId);56 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
61 const contract = helper.ethNativeContract.collection(address, 'nft', caller);57 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
6258
63 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));59 const cost = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, tokenId).send(caller));
6460
65 const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());61 const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());
66 const expectedFee = 0.15;62 const expectedFee = 0.15;
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
17import {evmToAddress} from '@polkadot/util-crypto';17import {evmToAddress} from '@polkadot/util-crypto';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';19import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
20import {UNIQUE} from '../util/helpers';20
2121
22describe('Create NFT collection from EVM', () => {22describe('Create NFT collection from EVM', () => {
23 let donor: IKeyringPair;23 let donor: IKeyringPair;
6565
66 await collectionHelpers.methods66 await collectionHelpers.methods
67 .createNonfungibleCollection('A', 'A', 'A')67 .createNonfungibleCollection('A', 'A', 'A')
68 .send({value: Number(2n * UNIQUE)});68 .send({value: Number(2n * helper.balance.getOneTokenNominal())});
69 69
70 expect(await collectionHelpers.methods70 expect(await collectionHelpers.methods
71 .isCollectionExist(expectedCollectionAddress)71 .isCollectionExist(expectedCollectionAddress)
147147
148describe('(!negative tests!) Create NFT collection from EVM', () => {148describe('(!negative tests!) Create NFT collection from EVM', () => {
149 let donor: IKeyringPair;149 let donor: IKeyringPair;
150 let nominal: bigint;
150151
151 before(async function() {152 before(async function() {
152 await usingEthPlaygrounds(async (_helper, privateKey) => {153 await usingEthPlaygrounds(async (helper, privateKey) => {
153 donor = privateKey('//Alice');154 donor = privateKey('//Alice');
155 nominal = helper.balance.getOneTokenNominal();
154 });156 });
155 });157 });
156158
165167
166 await expect(collectionHelper.methods168 await expect(collectionHelper.methods
167 .createNonfungibleCollection(collectionName, description, tokenPrefix)169 .createNonfungibleCollection(collectionName, description, tokenPrefix)
168 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);170 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
169 171
170 }172 }
171 {173 {
175 const tokenPrefix = 'A';177 const tokenPrefix = 'A';
176 await expect(collectionHelper.methods178 await expect(collectionHelper.methods
177 .createNonfungibleCollection(collectionName, description, tokenPrefix)179 .createNonfungibleCollection(collectionName, description, tokenPrefix)
178 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);180 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
179 }181 }
180 {182 {
181 const MAX_TOKEN_PREFIX_LENGTH = 16;183 const MAX_TOKEN_PREFIX_LENGTH = 16;
184 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);186 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
185 await expect(collectionHelper.methods187 await expect(collectionHelper.methods
186 .createNonfungibleCollection(collectionName, description, tokenPrefix)188 .createNonfungibleCollection(collectionName, description, tokenPrefix)
187 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);189 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
188 }190 }
189 });191 });
190 192
193 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);195 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
194 await expect(collectionHelper.methods196 await expect(collectionHelper.methods
195 .createNonfungibleCollection('Peasantry', 'absolutely anything', 'CVE')197 .createNonfungibleCollection('Peasantry', 'absolutely anything', 'CVE')
196 .call({value: Number(1n * UNIQUE)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');198 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
197 });199 });
198200
199 itEth('(!negative test!) Check owner', async ({helper}) => {201 itEth('(!negative test!) Check owner', async ({helper}) => {
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';19import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
20import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';20import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
21import {UNIQUE} from '../util/helpers';21
2222
23describe('Create RFT collection from EVM', () => {23describe('Create RFT collection from EVM', () => {
24 let donor: IKeyringPair;24 let donor: IKeyringPair;
6666
67 await collectionHelpers.methods67 await collectionHelpers.methods
68 .createRFTCollection('A', 'A', 'A')68 .createRFTCollection('A', 'A', 'A')
69 .send({value: Number(2n * UNIQUE)});69 .send({value: Number(2n * helper.balance.getOneTokenNominal())});
70 70
71 expect(await collectionHelpers.methods71 expect(await collectionHelpers.methods
72 .isCollectionExist(expectedCollectionAddress)72 .isCollectionExist(expectedCollectionAddress)
148148
149describe('(!negative tests!) Create RFT collection from EVM', () => {149describe('(!negative tests!) Create RFT collection from EVM', () => {
150 let donor: IKeyringPair;150 let donor: IKeyringPair;
151 let nominal: bigint;
151152
152 before(async function() {153 before(async function() {
153 await usingEthPlaygrounds(async (helper, privateKey) => {154 await usingEthPlaygrounds(async (helper, privateKey) => {
154 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);155 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
155 donor = privateKey('//Alice');156 donor = privateKey('//Alice');
157 nominal = helper.balance.getOneTokenNominal();
156 });158 });
157 });159 });
158160
167169
168 await expect(collectionHelper.methods170 await expect(collectionHelper.methods
169 .createRFTCollection(collectionName, description, tokenPrefix)171 .createRFTCollection(collectionName, description, tokenPrefix)
170 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);172 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
171 }173 }
172 {174 {
173 const MAX_DESCRIPTION_LENGTH = 256;175 const MAX_DESCRIPTION_LENGTH = 256;
176 const tokenPrefix = 'A';178 const tokenPrefix = 'A';
177 await expect(collectionHelper.methods179 await expect(collectionHelper.methods
178 .createRFTCollection(collectionName, description, tokenPrefix)180 .createRFTCollection(collectionName, description, tokenPrefix)
179 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);181 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
180 }182 }
181 {183 {
182 const MAX_TOKEN_PREFIX_LENGTH = 16;184 const MAX_TOKEN_PREFIX_LENGTH = 16;
185 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);187 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
186 await expect(collectionHelper.methods188 await expect(collectionHelper.methods
187 .createRFTCollection(collectionName, description, tokenPrefix)189 .createRFTCollection(collectionName, description, tokenPrefix)
188 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);190 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
189 }191 }
190 });192 });
191 193
194 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);196 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
195 await expect(collectionHelper.methods197 await expect(collectionHelper.methods
196 .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')198 .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')
197 .call({value: Number(1n * UNIQUE)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');199 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
198 });200 });
199201
200 itEth('(!negative test!) Check owner', async ({helper}) => {202 itEth('(!negative test!) Check owner', async ({helper}) => {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Contract} from 'web3-eth-contract';19import {Contract} from 'web3-eth-contract';
20import {UNIQUE} from '../util/helpers';20
2121
22describe('NFT: Information getting', () => {22describe('NFT: Information getting', () => {
23 let donor: IKeyringPair;23 let donor: IKeyringPair;
84 const receiver = helper.eth.createAccount();84 const receiver = helper.eth.createAccount();
8585
86 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);86 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
87 let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});87 let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});
88 const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);88 const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
89 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);89 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
90 90
modifiedtests/src/eth/proxy/fungibleProxy.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 {GAS_ARGS, normalizeEvents} from '../util/helpers';
18import {expect} from 'chai';17import {expect} from 'chai';
19import {readFile} from 'fs/promises';18import {readFile} from 'fs/promises';
20import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';
26 const web3 = helper.getWeb3();25 const web3 = helper.getWeb3();
27 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {26 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {
28 from: owner,27 from: owner,
29 ...GAS_ARGS,28 gas: helper.eth.DEFAULT_GAS,
30 });29 });
31 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueFungibleProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});30 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueFungibleProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});
32 return proxy;31 return proxy;
9493
95 {94 {
96 const result = await contract.methods.approve(spender, 100).send({from: caller});95 const result = await contract.methods.approve(spender, 100).send({from: caller});
97 const events = normalizeEvents(result.events);96 const events = helper.eth.normalizeEvents(result.events);
9897
99 expect(events).to.be.deep.equal([98 expect(events).to.be.deep.equal([
100 {99 {
131130
132 {131 {
133 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: caller});132 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: caller});
134 const events = normalizeEvents(result.events);133 const events = helper.eth.normalizeEvents(result.events);
135 expect(events).to.be.deep.equal([134 expect(events).to.be.deep.equal([
136 {135 {
137 address,136 address,
177176
178 {177 {
179 const result = await contract.methods.transfer(receiver, 50).send({from: caller});178 const result = await contract.methods.transfer(receiver, 50).send({from: caller});
180 const events = normalizeEvents(result.events);179 const events = helper.eth.normalizeEvents(result.events);
181 expect(events).to.be.deep.equal([180 expect(events).to.be.deep.equal([
182 {181 {
183 address,182 address,
modifiedtests/src/eth/proxy/nonFungibleProxy.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 {GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
18import {expect} from 'chai';
19import {readFile} from 'fs/promises';17import {readFile} from 'fs/promises';
20import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
21import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util/playgrounds';19import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util/playgrounds';
20
2221
23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {22async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
24 // Proxy owner has no special privilegies, we don't need to reuse them23 // Proxy owner has no special privilegies, we don't need to reuse them
25 const owner = await helper.eth.createAccountWithBalance(donor);24 const owner = await helper.eth.createAccountWithBalance(donor);
26 const web3 = helper.getWeb3();25 const web3 = helper.getWeb3();
27 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {26 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {
28 from: owner,27 from: owner,
29 ...GAS_ARGS,28 gas: helper.eth.DEFAULT_GAS,
30 });29 });
31 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});30 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});
32 return proxy;31 return proxy;
119 nextTokenId,118 nextTokenId,
120 'Test URI',119 'Test URI',
121 ).send({from: caller});120 ).send({from: caller});
122 const events = normalizeEvents(result.events);121 const events = helper.eth.normalizeEvents(result.events);
123 events[0].address = events[0].address.toLocaleLowerCase();122 events[0].address = events[0].address.toLocaleLowerCase();
124123
125 expect(events).to.be.deep.equal([124 expect(events).to.be.deep.equal([
139 });138 });
140139
141 //TODO: CORE-302 add eth methods140 //TODO: CORE-302 add eth methods
142 itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {141 itEth.skip('Can perform mintBulk()', async ({helper}) => {
143 /*142 const collection = await helper.nft.mintCollection(donor, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});
144 const collection = await createCollectionExpectSuccess({143
145 mode: {type: 'NFT'},144 const caller = await helper.eth.createAccountWithBalance(donor, 30n);
146 });145 const receiver = helper.eth.createAccount();
147 const alice = privateKeyWrapper('//Alice');146
148147 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
149 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);148 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
150 const receiver = createEthAccount(web3);149 const contract = await proxyWrap(helper, evmCollection, donor);
151150 await collection.addAdmin(donor, {Ethereum: contract.options.address});
152 const address = collectionIdToAddress(collection);151
153 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);152 {
154 const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: contract.options.address});153 const nextTokenId = await contract.methods.nextTokenId().call();
155 await submitTransactionAsync(alice, changeAdminTx);154 expect(nextTokenId).to.be.equal('1');
156155 const result = await contract.methods.mintBulkWithTokenURI(
157 {156 receiver,
158 const nextTokenId = await contract.methods.nextTokenId().call();157 [
159 expect(nextTokenId).to.be.equal('1');158 [nextTokenId, 'Test URI 0'],
160 const result = await contract.methods.mintBulkWithTokenURI(159 [+nextTokenId + 1, 'Test URI 1'],
161 receiver,160 [+nextTokenId + 2, 'Test URI 2'],
162 [161 ],
163 [nextTokenId, 'Test URI 0'],162 ).send({from: caller});
164 [+nextTokenId + 1, 'Test URI 1'],163 const events = helper.eth.normalizeEvents(result.events);
165 [+nextTokenId + 2, 'Test URI 2'],164
166 ],165 expect(events).to.be.deep.equal([
167 ).send({from: caller});166 {
168 const events = normalizeEvents(result.events);167 address,
169168 event: 'Transfer',
170 expect(events).to.be.deep.equal([169 args: {
171 {170 from: '0x0000000000000000000000000000000000000000',
172 address,171 to: receiver,
173 event: 'Transfer',172 tokenId: nextTokenId,
174 args: {173 },
175 from: '0x0000000000000000000000000000000000000000',174 },
176 to: receiver,175 {
177 tokenId: nextTokenId,176 address,
178 },177 event: 'Transfer',
179 },178 args: {
180 {179 from: '0x0000000000000000000000000000000000000000',
181 address,180 to: receiver,
182 event: 'Transfer',181 tokenId: String(+nextTokenId + 1),
183 args: {182 },
184 from: '0x0000000000000000000000000000000000000000',183 },
185 to: receiver,184 {
186 tokenId: String(+nextTokenId + 1),185 address,
187 },186 event: 'Transfer',
188 },187 args: {
189 {188 from: '0x0000000000000000000000000000000000000000',
190 address,189 to: receiver,
191 event: 'Transfer',190 tokenId: String(+nextTokenId + 2),
192 args: {191 },
193 from: '0x0000000000000000000000000000000000000000',192 },
194 to: receiver,193 ]);
195 tokenId: String(+nextTokenId + 2),194
196 },195 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
197 },196 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
198 ]);197 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
199
200 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
201 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
202 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
203 }
204 */
205 });198 }
199 });
206200
207 itEth('Can perform burn()', async ({helper}) => {201 itEth('Can perform burn()', async ({helper}) => {
208 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});202 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
216210
217 {211 {
218 const result = await contract.methods.burn(tokenId).send({from: caller});212 const result = await contract.methods.burn(tokenId).send({from: caller});
219 const events = normalizeEvents(result.events);213 const events = helper.eth.normalizeEvents(result.events);
220214
221 expect(events).to.be.deep.equal([215 expect(events).to.be.deep.equal([
222 {216 {
243 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});237 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
244238
245 {239 {
246 const result = await contract.methods.approve(spender, tokenId).send({from: caller, ...GAS_ARGS});240 const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS});
247 const events = normalizeEvents(result.events);241 const events = helper.eth.normalizeEvents(result.events);
248242
249 expect(events).to.be.deep.equal([243 expect(events).to.be.deep.equal([
250 {244 {
276270
277 {271 {
278 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});272 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});
279 const events = normalizeEvents(result.events);273 const events = helper.eth.normalizeEvents(result.events);
280 expect(events).to.be.deep.equal([274 expect(events).to.be.deep.equal([
281 {275 {
282 address,276 address,
313307
314 {308 {
315 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});309 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});
316 const events = normalizeEvents(result.events);310 const events = helper.eth.normalizeEvents(result.events);
317 expect(events).to.be.deep.equal([311 expect(events).to.be.deep.equal([
318 {312 {
319 address,313 address,
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
18import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util/playgrounds';18import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
19import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';
20import {Contract} from 'web3-eth-contract';20import {Contract} from 'web3-eth-contract';
21import {UNIQUE} from '../util/helpers';21
2222
23describe('Refungible token: Information getting', () => {23describe('Refungible token: Information getting', () => {
24 let donor: IKeyringPair;24 let donor: IKeyringPair;
81 const receiver = helper.eth.createAccount();81 const receiver = helper.eth.createAccount();
8282
83 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);83 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
84 let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});84 let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});
85 const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);85 const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
86 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);86 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
87 87
deletedtests/src/eth/scheduling.test.tsdiffbeforeafterboth

no changes

deletedtests/src/eth/util/helpers.d.tsdiffbeforeafterboth

no changes

deletedtests/src/eth/util/helpers.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
27import refungibleAbi from '../../reFungibleAbi.json';27import refungibleAbi from '../../reFungibleAbi.json';
28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';
29import contractHelpersAbi from './../contractHelpersAbi.json';29import contractHelpersAbi from './../contractHelpersAbi.json';
30import {TEthereumAccount} from '../../../util/playgrounds/types';30import {ICrossAccountId, TEthereumAccount} from '../../../util/playgrounds/types';
3131
32class EthGroupBase {32class EthGroupBase {
33 helper: EthUniqueHelper;33 helper: EthUniqueHelper;
280 });280 });
281 }281 }
282
283 async calculateFee(address: ICrossAccountId, code: () => Promise<any>): Promise<bigint> {
284 const wrappedCode = async () => {
285 await code();
286 // In dev mode, the transaction might not finish processing in time
287 await this.helper.wait.newBlocks(1);
288 };
289 return await this.helper.arrange.calculcateFee(address, wrappedCode);
290 }
282} 291}
283292
284class EthAddressGroup extends EthGroupBase {293class EthAddressGroup extends EthGroupBase {
modifiedtests/src/inflation.test.tsdiffbeforeafterboth
40 const tx = helper.constructApiCall('api.tx.inflation.startInflation', [1]);40 const tx = helper.constructApiCall('api.tx.inflation.startInflation', [1]);
41 await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [tx])).to.not.be.rejected;41 await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [tx])).to.not.be.rejected;
4242
43 const blockInterval = (helper.api!.consts.inflation.inflationBlockInterval as any).toBigInt();43 const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();
44 const totalIssuanceStart = ((await helper.api!.query.inflation.startingYearTotalIssuance()) as any).toBigInt();44 const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();
45 const blockInflation = (await helper.api!.query.inflation.blockInflation() as any).toBigInt();45 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();
4646
47 const YEAR = 5259600n; // 6-second block. Blocks in one year47 const YEAR = 5259600n; // 6-second block. Blocks in one year
48 // const YEAR = 2629800n; // 12-second block. Blocks in one year48 // const YEAR = 2629800n; // 12-second block. Blocks in one year
modifiedtests/src/nesting/properties.test.tsdiffbeforeafterboth
276 276
277 itSub('Reads access rights to properties of a collection', async ({helper}) => {277 itSub('Reads access rights to properties of a collection', async ({helper}) => {
278 const collection = await helper.nft.mintCollection(alice);278 const collection = await helper.nft.mintCollection(alice);
279 const propertyRights = (await helper.api!.query.common.collectionPropertyPermissions(collection.collectionId)).toJSON();279 const propertyRights = (await helper.callRpc('api.query.common.collectionPropertyPermissions', [collection.collectionId])).toJSON();
280 expect(propertyRights).to.be.empty;280 expect(propertyRights).to.be.empty;
281 });281 });
282 282
817 ).to.be.fulfilled;817 ).to.be.fulfilled;
818 }818 }
819819
820 const originalSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 820 const originalSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
821 return originalSpace;821 return originalSpace;
822 }822 }
823823
840 ).to.be.rejectedWith(/common\.NoPermission/);840 ).to.be.rejectedWith(/common\.NoPermission/);
841 }841 }
842842
843 const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 843 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
844 expect(consumedSpace).to.be.equal(originalSpace);844 expect(consumedSpace).to.be.equal(originalSpace);
845 }845 }
846846
875 ).to.be.rejectedWith(/common\.NoPermission/);875 ).to.be.rejectedWith(/common\.NoPermission/);
876 }876 }
877 877
878 const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 878 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
879 expect(consumedSpace).to.be.equal(originalSpace);879 expect(consumedSpace).to.be.equal(originalSpace);
880 }880 }
881881
911911
912 expect(await token.getProperties(['non-existent', 'now-existent'])).to.be.empty;912 expect(await token.getProperties(['non-existent', 'now-existent'])).to.be.empty;
913 913
914 const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 914 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
915 expect(consumedSpace).to.be.equal(originalSpace);915 expect(consumedSpace).to.be.equal(originalSpace);
916 }916 }
917917
951 ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);951 ])).to.be.rejectedWith(/common\.NoSpaceForProperty/);
952 952
953 expect(await token.getProperties(['a_holy_book', 'young_years'])).to.be.empty;953 expect(await token.getProperties(['a_holy_book', 'young_years'])).to.be.empty;
954 const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT'); 954 const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
955 expect(consumedSpace).to.be.equal(originalSpace);955 expect(consumedSpace).to.be.equal(originalSpace);
956 }956 }
957957
modifiedtests/src/pallet-presence.test.tsdiffbeforeafterboth
59describe('Pallet presence', () => {59describe('Pallet presence', () => {
60 before(async () => {60 before(async () => {
61 await usingPlaygrounds(async helper => {61 await usingPlaygrounds(async helper => {
62 const chain = await helper.api!.rpc.system.chain();62 const chain = await helper.callRpc('api.rpc.system.chain', []);
6363
64 const refungible = 'refungible';64 const refungible = 'refungible';
65 const scheduler = 'scheduler';65 const scheduler = 'scheduler';
modifiedtests/src/rmrk/acceptNft.test.tsdiffbeforeafterboth
8} from './util/tx';8} from './util/tx';
9import {NftIdTuple} from './util/fetch';9import {NftIdTuple} from './util/fetch';
10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
11import {requirePallets, Pallets} from '../util/helpers';11import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
1212
13describe('integration test: accept NFT', () => {13describe('integration test: accept NFT', () => {
14 let api: any;14 let api: any;
modifiedtests/src/rmrk/addResource.test.tsdiffbeforeafterboth
12 addNftComposableResource,12 addNftComposableResource,
13} from './util/tx';13} from './util/tx';
14import {RmrkTraitsResourceResourceInfo as ResourceInfo} from '@polkadot/types/lookup';14import {RmrkTraitsResourceResourceInfo as ResourceInfo} from '@polkadot/types/lookup';
15import {requirePallets, Pallets} from '../util/helpers';15import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
1616
17describe('integration test: add NFT resource', () => {17describe('integration test: add NFT resource', () => {
18 const Alice = '//Alice';18 const Alice = '//Alice';
modifiedtests/src/rmrk/addTheme.test.tsdiffbeforeafterboth
3import {createBase, addTheme} from './util/tx';3import {createBase, addTheme} from './util/tx';
4import {expectTxFailure} from './util/helpers';4import {expectTxFailure} from './util/helpers';
5import {getThemeNames} from './util/fetch';5import {getThemeNames} from './util/fetch';
6import {requirePallets, Pallets} from '../util/helpers';6import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
77
8describe('integration test: add Theme to Base', () => {8describe('integration test: add Theme to Base', () => {
9 let api: any;9 let api: any;
modifiedtests/src/rmrk/burnNft.test.tsdiffbeforeafterboth
55
6import chai from 'chai';6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
8import {requirePallets, Pallets} from '../util/helpers';8import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
99
10chai.use(chaiAsPromised);10chai.use(chaiAsPromised);
11const expect = chai.expect;11const expect = chai.expect;
modifiedtests/src/rmrk/changeCollectionIssuer.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {expectTxFailure} from './util/helpers';3import {expectTxFailure} from './util/helpers';
4import {4import {
5 changeIssuer,5 changeIssuer,
modifiedtests/src/rmrk/createBase.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {createCollection, createBase} from './util/tx';3import {createCollection, createBase} from './util/tx';
44
5describe('integration test: create new Base', () => {5describe('integration test: create new Base', () => {
modifiedtests/src/rmrk/createCollection.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {createCollection} from './util/tx';3import {createCollection} from './util/tx';
44
5describe('Integration test: create new collection', () => {5describe('Integration test: create new collection', () => {
modifiedtests/src/rmrk/deleteCollection.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {expectTxFailure} from './util/helpers';3import {expectTxFailure} from './util/helpers';
4import {createCollection, deleteCollection} from './util/tx';4import {createCollection, deleteCollection} from './util/tx';
55
modifiedtests/src/rmrk/equipNft.test.tsdiffbeforeafterboth
1import {ApiPromise} from '@polkadot/api';1import {ApiPromise} from '@polkadot/api';
2import {expect} from 'chai';2import {expect} from 'chai';
3import {getApiConnection} from '../substrate/substrate-api';3import {getApiConnection} from '../substrate/substrate-api';
4import {requirePallets, Pallets} from '../util/helpers';4import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
5import {getNft, getParts, NftIdTuple} from './util/fetch';5import {getNft, getParts, NftIdTuple} from './util/fetch';
6import {expectTxFailure} from './util/helpers';6import {expectTxFailure} from './util/helpers';
7import {7import {
modifiedtests/src/rmrk/getOwnedNfts.test.tsdiffbeforeafterboth
1import {expect} from 'chai';1import {expect} from 'chai';
2import {getApiConnection} from '../substrate/substrate-api';2import {getApiConnection} from '../substrate/substrate-api';
3import {requirePallets, Pallets} from '../util/helpers';3import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
4import {getOwnedNfts} from './util/fetch';4import {getOwnedNfts} from './util/fetch';
5import {mintNft, createCollection} from './util/tx';5import {mintNft, createCollection} from './util/tx';
66
modifiedtests/src/rmrk/lockCollection.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {expectTxFailure} from './util/helpers';3import {expectTxFailure} from './util/helpers';
4import {createCollection, lockCollection, mintNft} from './util/tx';4import {createCollection, lockCollection, mintNft} from './util/tx';
55
modifiedtests/src/rmrk/mintNft.test.tsdiffbeforeafterboth
1import {expect} from 'chai';1import {expect} from 'chai';
2import {getApiConnection} from '../substrate/substrate-api';2import {getApiConnection} from '../substrate/substrate-api';
3import {requirePallets, Pallets} from '../util/helpers';3import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
4import {getNft} from './util/fetch';4import {getNft} from './util/fetch';
5import {expectTxFailure} from './util/helpers';5import {expectTxFailure} from './util/helpers';
6import {createCollection, mintNft} from './util/tx';6import {createCollection, mintNft} from './util/tx';
modifiedtests/src/rmrk/rejectNft.test.tsdiffbeforeafterboth
8} from './util/tx';8} from './util/tx';
9import {getChildren, NftIdTuple} from './util/fetch';9import {getChildren, NftIdTuple} from './util/fetch';
10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
11import {requirePallets, Pallets} from '../util/helpers';11import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
1212
13describe('integration test: reject NFT', () => {13describe('integration test: reject NFT', () => {
14 let api: any;14 let api: any;
modifiedtests/src/rmrk/removeResource.test.tsdiffbeforeafterboth
1import {expect} from 'chai';1import {expect} from 'chai';
2import privateKey from '../substrate/privateKey';2import privateKey from '../substrate/privateKey';
3import {executeTransaction, getApiConnection} from '../substrate/substrate-api';3import {executeTransaction, getApiConnection} from '../substrate/substrate-api';
4import {requirePallets, Pallets} from '../util/helpers';4import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
5import {getNft, NftIdTuple} from './util/fetch';5import {getNft, NftIdTuple} from './util/fetch';
6import {expectTxFailure} from './util/helpers';6import {expectTxFailure} from './util/helpers';
7import {7import {
modifiedtests/src/rmrk/rmrkIsolation.test.tsdiffbeforeafterboth
9 requirePallets,9 requirePallets,
10 normalizeAccountId,10 normalizeAccountId,
11 Pallets,11 Pallets,
12} from '../util/helpers';12} from '../deprecated-helpers/helpers';
13import {IKeyringPair} from '@polkadot/types/types';13import {IKeyringPair} from '@polkadot/types/types';
14import {ApiPromise} from '@polkadot/api';14import {ApiPromise} from '@polkadot/api';
15import {it} from 'mocha';15import {it} from 'mocha';
modifiedtests/src/rmrk/sendNft.test.tsdiffbeforeafterboth
3import {createCollection, mintNft, sendNft} from './util/tx';3import {createCollection, mintNft, sendNft} from './util/tx';
4import {NftIdTuple} from './util/fetch';4import {NftIdTuple} from './util/fetch';
5import {isNftChildOfAnother, expectTxFailure} from './util/helpers';5import {isNftChildOfAnother, expectTxFailure} from './util/helpers';
6import {requirePallets, Pallets} from '../util/helpers';6import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
77
8describe('integration test: send NFT', () => {8describe('integration test: send NFT', () => {
9 let api: any;9 let api: any;
modifiedtests/src/rmrk/setCollectionProperty.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {expectTxFailure} from './util/helpers';3import {expectTxFailure} from './util/helpers';
4import {createCollection, setPropertyCollection} from './util/tx';4import {createCollection, setPropertyCollection} from './util/tx';
55
modifiedtests/src/rmrk/setEquippableList.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {expectTxFailure} from './util/helpers';3import {expectTxFailure} from './util/helpers';
4import {createCollection, createBase, setEquippableList} from './util/tx';4import {createCollection, createBase, setEquippableList} from './util/tx';
55
modifiedtests/src/rmrk/setNftProperty.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {NftIdTuple} from './util/fetch';3import {NftIdTuple} from './util/fetch';
4import {expectTxFailure} from './util/helpers';4import {expectTxFailure} from './util/helpers';
5import {createCollection, mintNft, sendNft, setNftProperty} from './util/tx';5import {createCollection, mintNft, sendNft, setNftProperty} from './util/tx';
modifiedtests/src/rmrk/setResourcePriorities.test.tsdiffbeforeafterboth
1import {getApiConnection} from '../substrate/substrate-api';1import {getApiConnection} from '../substrate/substrate-api';
2import {requirePallets, Pallets} from '../util/helpers';2import {requirePallets, Pallets} from '../deprecated-helpers/helpers';
3import {expectTxFailure} from './util/helpers';3import {expectTxFailure} from './util/helpers';
4import {mintNft, createCollection, setResourcePriorities} from './util/tx';4import {mintNft, createCollection, setResourcePriorities} from './util/tx';
55
modifiedtests/src/substrate/get-balance.tsdiffbeforeafterboth
19import promisifySubstrate from './promisify-substrate';19import promisifySubstrate from './promisify-substrate';
20import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {submitTransactionAsync} from './substrate-api';21import {submitTransactionAsync} from './substrate-api';
22import {getGenericResult} from '../util/helpers';22import {getGenericResult} from '../deprecated-helpers/helpers';
23import {expect} from 'chai';23import {expect} from 'chai';
2424
25export default async function getBalance(api: ApiPromise, accounts: string[]): Promise<Array<bigint>> {25export default async function getBalance(api: ApiPromise, accounts: string[]): Promise<Array<bigint>> {
modifiedtests/src/transfer.nload.tsdiffbeforeafterboth
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import usingApi, {submitTransactionAsync} from './substrate/substrate-api';19import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
20import waitNewBlocks from './substrate/wait-new-blocks';20import waitNewBlocks from './substrate/wait-new-blocks';
21import {findUnusedAddresses} from './util/helpers';
22import * as cluster from 'cluster';21import * as cluster from 'cluster';
23import os from 'os';22import os from 'os';
23
24async function findUnusedAddress(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, seedAddition = ''): Promise<IKeyringPair> {
25 let bal = 0n;
26 let unused;
27 do {
28 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;
29 unused = privateKeyWrapper(`//${randomSeed}`);
30 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();
31 } while (bal !== 0n);
32 return unused;
33}
34
35function findUnusedAddresses(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, amount: number): Promise<IKeyringPair[]> {
36 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, privateKeyWrapper, '_' + Date.now())));
37}
2438
25// Innacurate transfer fee39// Innacurate transfer fee
26const FEE = 10n ** 8n;40const FEE = 10n ** 8n;
modifiedtests/src/tx-version-presence.test.tsdiffbeforeafterboth
22describe('TxVersion is present', () => {22describe('TxVersion is present', () => {
23 before(async () => {23 before(async () => {
24 await usingPlaygrounds(async helper => {24 await usingPlaygrounds(async helper => {
25 metadata = await helper.api!.rpc.state.getMetadata();25 metadata = await helper.callRpc('api.rpc.state.getMetadata', []);
26 });26 });
27 });27 });
2828
deletedtests/src/util/contracthelpers.tsdiffbeforeafterboth

no changes

deletedtests/src/util/helpers.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/playgrounds/index.tsdiffbeforeafterboth
38 Fungible = 'fungible',38 Fungible = 'fungible',
39 NFT = 'nonfungible',39 NFT = 'nonfungible',
40 Scheduler = 'scheduler',40 Scheduler = 'scheduler',
41 AppPromotion = 'apppromotion',
41}42}
4243
43export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {44export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
215 };215 };
216216
217 isDevNode = async () => {217 isDevNode = async () => {
218 const block1 = await this.helper.api?.rpc.chain.getBlock(await this.helper.api?.rpc.chain.getBlockHash(1));218 const block1 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [1])]);
219 const block2 = await this.helper.api?.rpc.chain.getBlock(await this.helper.api?.rpc.chain.getBlockHash(2));219 const block2 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [2])]);
220 const findCreationDate = async (block: any) => {220 const findCreationDate = async (block: any) => {
221 const humanBlock = block.toHuman();221 const humanBlock = block.toHuman();
222 let date;222 let date;
259 async newBlocks(blocksCount = 1): Promise<void> {259 async newBlocks(blocksCount = 1): Promise<void> {
260 // eslint-disable-next-line no-async-promise-executor260 // eslint-disable-next-line no-async-promise-executor
261 const promise = new Promise<void>(async (resolve) => {261 const promise = new Promise<void>(async (resolve) => {
262 const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(() => {262 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(() => {
263 if (blocksCount > 0) {263 if (blocksCount > 0) {
264 blocksCount--;264 blocksCount--;
265 } else {265 } else {
274 async forParachainBlockNumber(blockNumber: bigint) {274 async forParachainBlockNumber(blockNumber: bigint) {
275 // eslint-disable-next-line no-async-promise-executor275 // eslint-disable-next-line no-async-promise-executor
276 return new Promise<void>(async (resolve) => {276 return new Promise<void>(async (resolve) => {
277 const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(async (data: any) => {277 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(async (data: any) => {
278 if (data.number.toNumber() >= blockNumber) {278 if (data.number.toNumber() >= blockNumber) {
279 unsubscribe();279 unsubscribe();
280 resolve();280 resolve();
286 async forRelayBlockNumber(blockNumber: bigint) {286 async forRelayBlockNumber(blockNumber: bigint) {
287 // eslint-disable-next-line no-async-promise-executor287 // eslint-disable-next-line no-async-promise-executor
288 return new Promise<void>(async (resolve) => {288 return new Promise<void>(async (resolve) => {
289 const unsubscribe = await this.helper.api!.query.parachainSystem.validationData(async (data: any) => {289 const unsubscribe = await this.helper.getApi().query.parachainSystem.validationData(async (data: any) => {
290 if (data.value.relayParentNumber.toNumber() >= blockNumber) {290 if (data.value.relayParentNumber.toNumber() >= blockNumber) {
291 // @ts-ignore291 // @ts-ignore
292 unsubscribe();292 unsubscribe();
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
330 this.chainLog = [];330 this.chainLog = [];
331 }331 }
332
333 getApi(): ApiPromise {
334 if(this.api === null) throw Error('API not initialized');
335 return this.api;
336 }
332337
333 clearChainLog(): void {338 clearChainLog(): void {
334 this.chainLog = [];339 this.chainLog = [];
1986 * @returns ss58Format, token decimals, and token symbol1991 * @returns ss58Format, token decimals, and token symbol
1987 */1992 */
1988 getChainProperties(): IChainProperties {1993 getChainProperties(): IChainProperties {
1989 const properties = (this.helper.api as any).registry.getChainProperties().toJSON();1994 const properties = (this.helper.getApi() as any).registry.getChainProperties().toJSON();
1990 return {1995 return {
1991 ss58Format: properties.ss58Format.toJSON(),1996 ss58Format: properties.ss58Format.toJSON(),
1992 tokenDecimals: properties.tokenDecimals.toJSON(),1997 tokenDecimals: properties.tokenDecimals.toJSON(),
2029 * @returns number, account's nonce2034 * @returns number, account's nonce
2030 */2035 */
2031 async getNonce(address: TSubstrateAccount): Promise<number> {2036 async getNonce(address: TSubstrateAccount): Promise<number> {
2032 return (await (this.helper.api as any).query.system.account(address)).nonce.toNumber();2037 return (await this.helper.callRpc('api.query.system.account', [address])).nonce.toNumber();
2033 }2038 }
2034}2039}
20352040
deletedtests/src/util/util.tsdiffbeforeafterboth

no changes

modifiedtests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth
21import {ApiOptions} from '@polkadot/api/types';21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {executeTransaction} from './../substrate/substrate-api';23import usingApi, {executeTransaction} from './../substrate/substrate-api';
24import {bigIntToDecimals, describe_xcm, getGenericResult, paraSiblingSovereignAccount} from './../util/helpers';24import {bigIntToDecimals, describe_xcm, getGenericResult, paraSiblingSovereignAccount, normalizeAccountId} from './../deprecated-helpers/helpers';
25import waitNewBlocks from './../substrate/wait-new-blocks';25import waitNewBlocks from './../substrate/wait-new-blocks';
26import {normalizeAccountId} from './../util/helpers';
27import getBalance from './../substrate/get-balance';26import getBalance from './../substrate/get-balance';
2827
2928
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
21import {ApiOptions} from '@polkadot/api/types';21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../util/helpers';24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';
25import {MultiLocation} from '@polkadot/types/interfaces';25import {MultiLocation} from '@polkadot/types/interfaces';
26import {blake2AsHex} from '@polkadot/util-crypto';26import {blake2AsHex} from '@polkadot/util-crypto';
27import waitNewBlocks from '../substrate/wait-new-blocks';27import waitNewBlocks from '../substrate/wait-new-blocks';
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
21import {ApiOptions} from '@polkadot/api/types';21import {ApiOptions} from '@polkadot/api/types';
22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';
23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../util/helpers';24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';
25import {MultiLocation} from '@polkadot/types/interfaces';25import {MultiLocation} from '@polkadot/types/interfaces';
26import {blake2AsHex} from '@polkadot/util-crypto';26import {blake2AsHex} from '@polkadot/util-crypto';
27import waitNewBlocks from '../substrate/wait-new-blocks';27import waitNewBlocks from '../substrate/wait-new-blocks';