difftreelog
test refungible
in: master
2 files changed
tests/src/refungible.test.tsdiffbeforeafterbothno changes
tests/src/util/helpers.tsdiffbeforeafterboth800 ReFungible: CreateReFungibleData;800 ReFungible: CreateReFungibleData;801};801};802802803export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {803export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value: number | bigint = 1) {804 await usingApi(async (api) => {804 await usingApi(async (api) => {805 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);805 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);806 // if burning token by admin - use adminButnItemExpectSuccess806 // if burning token by admin - use adminButnItemExpectSuccess1084 const to = normalizeAccountId(recipient);1084 const to = normalizeAccountId(recipient);108510851086 let balanceBefore = 0n;1086 let balanceBefore = 0n;1087 if (type === 'Fungible') {1087 if (type === 'Fungible' || type === 'ReFungible') {1088 balanceBefore = await getBalance(api, collectionId, to, tokenId);1088 balanceBefore = await getBalance(api, collectionId, to, tokenId);1089 }1089 }1090 const transferTx = api.tx.unique.transfer(to, collectionId, tokenId, value);1090 const transferTx = api.tx.unique.transfer(to, collectionId, tokenId, value);1100 if (type === 'NFT') {1100 if (type === 'NFT') {1101 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);1101 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);1102 }1102 }1103 if (type === 'Fungible') {1103 if (type === 'Fungible' || type === 'ReFungible') {1104 const balanceAfter = await getBalance(api, collectionId, to, tokenId);1104 const balanceAfter = await getBalance(api, collectionId, to, tokenId);1105 if (JSON.stringify(to) !== JSON.stringify(from)) {1105 if (JSON.stringify(to) !== JSON.stringify(from)) {1106 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));1106 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));1107 } else {1107 } else {1108 expect(balanceAfter).to.be.equal(balanceBefore);1108 expect(balanceAfter).to.be.equal(balanceBefore);1109 }1109 }1110 }1110 }1111 if (type === 'ReFungible') {1112 expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;1113 }1114 });1111 });1115}1112}111611131226 });1223 });1227}1224}12251226export async function createMultipleItemsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {1227 await usingApi(async (api) => {1228 const to = normalizeAccountId(owner);1229 const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);12301231 const events = await submitTransactionAsync(sender, tx);1232 const result = getCreateItemsResult(events);1233 });1234}122812351229export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {1236export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {1230 await usingApi(async (api) => {1237 await usingApi(async (api) => {