difftreelog
Merge develop and remove unneeded usingApi
in: master
(cherry picked from commit 0ccf6006f00210f190eb9d8393d86a6f68778bae)
6 files changed
tests/src/approve.test.tsdiffbeforeafterboth12 approveExpectFail,12 approveExpectFail,13 approveExpectSuccess,13 approveExpectSuccess,14 createCollectionExpectSuccess,14 createCollectionExpectSuccess,15 createFungibleItemExpectSuccess,15 createItemExpectSuccess,16 createItemExpectSuccess,16 destroyCollectionExpectSuccess,17 destroyCollectionExpectSuccess,18 transferFromExpectSuccess,19 U128_MAX,17} from './util/helpers';20} from './util/helpers';182119chai.use(chaiAsPromised);22chai.use(chaiAsPromised);tests/src/overflow.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import { IKeyringPair } from "@polkadot/types/types";6import { IKeyringPair } from "@polkadot/types/types";2import chai from 'chai';7import chai from 'chai';21 });26 });22 });27 });232824 it('fails when overflows on transfer', async () => {29 it('fails when overflows on transfer', async () => {25 await usingApi(async () => {26 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });30 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });273128 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });32 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });333734 expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);38 expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);35 expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);39 expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);36 });40 });37 });384139 it('fails on allowance overflow', async () => {42 it('fails on allowance overflow', async () => {40 await usingApi(async () => {41 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });43 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });424443 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });45 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });44 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);46 await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);45 await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);47 await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);46 });48 });47 });484949 it('fails when overflows on transferFrom', async () => {50 it('fails when overflows on transferFrom', async () => {50 await usingApi(async () => {51 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });51 const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });525253 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });53 await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });636364 expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);64 expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);65 expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);65 expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);66 });66 });67 });68});67});6968tests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//51import privateKey from "./substrate/privateKey";6import privateKey from "./substrate/privateKey";2import usingApi from "./substrate/substrate-api";7import usingApi from "./substrate/substrate-api";tests/src/transferFrom.test.tsdiffbeforeafterboth11 approveExpectFail,11 approveExpectFail,12 approveExpectSuccess,12 approveExpectSuccess,13 createCollectionExpectSuccess,13 createCollectionExpectSuccess,14 createFungibleItemExpectSuccess,14 createItemExpectSuccess,15 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 destroyCollectionExpectSuccess,17 getAllowance,16 transferFromExpectFail,18 transferFromExpectFail,17 transferFromExpectSuccess,19 transferFromExpectSuccess,18 burnItemExpectSuccess,20 burnItemExpectSuccess,49 });51 });50 });52 });5354 it('Should reduce allowance if value is big', async () => {55 await usingApi(async () => {56 const alice = privateKey('//Alice');57 const bob = privateKey('//Bob');58 const charlie = privateKey('//Charlie');5960 // fungible61 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});62 const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });6364 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);65 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');66 expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');67 });68 });51});69});527053describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {71describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {tests/src/util/helpers.tsdiffbeforeafterboth247 });247 });248}248}249250export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {251 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));252}249253250export async function findNotExistingCollection(api: ApiPromise): Promise<number> {254export async function findNotExistingCollection(api: ApiPromise): Promise<number> {251 const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;255 const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;517521518export async function522export async function519approveExpectSuccess(collectionId: number,523approveExpectSuccess(collectionId: number,520 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1) { //alice,bob524 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1) {521 await usingApi(async (api: ApiPromise) => {525 await usingApi(async (api: ApiPromise) => {522 const allowanceBefore =526 const allowanceBefore =523 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;527 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;535export async function539export async function536transferFromExpectSuccess(collectionId: number,540transferFromExpectSuccess(collectionId: number,537 tokenId: number,541 tokenId: number,538 accountApproved: IKeyringPair, //bob542 accountApproved: IKeyringPair,539 accountFrom: IKeyringPair, //alice543 accountFrom: IKeyringPair,540 accountTo: IKeyringPair, //charlie544 accountTo: IKeyringPair,541 value: number | bigint = 1,545 value: number | bigint = 1,542 type: string = 'NFT') {546 type: string = 'NFT') {543 await usingApi(async (api: ApiPromise) => {547 await usingApi(async (api: ApiPromise) => {tests/yarn.lockdiffbeforeafterboth4638 dependencies:4638 dependencies:4639 ci-info "^2.0.0"4639 ci-info "^2.0.0"464046404641is-core-module@^2.1.0:4641is-core-module@^2.2.0:4642 version "2.2.0"4642 version "2.2.0"4643 resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"4643 resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"4644 integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==4644 integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==7027 integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=7027 integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=702870287029resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0, resolve@^1.3.2:7029resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0, resolve@^1.3.2:7030 version "1.19.0"7030 version "1.20.0"7031 resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"7031 resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"7032 integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==7032 integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==7033 dependencies:7033 dependencies:7034 is-core-module "^2.1.0"7034 is-core-module "^2.2.0"7035 path-parse "^1.0.6"7035 path-parse "^1.0.6"703670367037responselike@^1.0.2:7037responselike@^1.0.2: