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

difftreelog

test refungible

Grigoriy Simonov2022-06-22parent: #421f362.patch.diff
in: master

2 files changed

addedtests/src/refungible.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
800 ReFungible: CreateReFungibleData;800 ReFungible: CreateReFungibleData;
801};801};
802802
803export 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 adminButnItemExpectSuccess
1084 const to = normalizeAccountId(recipient);1084 const to = normalizeAccountId(recipient);
10851085
1086 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}
11161113
1226 });1223 });
1227}1224}
1225
1226export 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);
1230
1231 const events = await submitTransactionAsync(sender, tx);
1232 const result = getCreateItemsResult(events);
1233 });
1234}
12281235
1229export 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) => {