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

difftreelog

test support alternative forms of addresses in helpers

Yaroslav Bolyukin2021-06-04parent: #9351b9f.patch.diff
in: master

1 file changed

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
634634
635export async function635export async function
636approveExpectSuccess(collectionId: number,636approveExpectSuccess(collectionId: number,
637 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1) {637 tokenId: number, owner: IKeyringPair, approved: IKeyringPair | string, amount: number | bigint = 1) {
638 if (typeof approved !== 'string')
639 approved = approved.address;
638 await usingApi(async (api: ApiPromise) => {640 await usingApi(async (api: ApiPromise) => {
639 const allowanceBefore =641 const allowanceBefore =
640 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;642 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved] as any) as unknown as BN;
641 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);643 const approveNftTx = await api.tx.nft.approve(approved, collectionId, tokenId, amount);
642 const events = await submitTransactionAsync(owner, approveNftTx);644 const events = await submitTransactionAsync(owner, approveNftTx);
643 const result = getCreateItemResult(events);645 const result = getCreateItemResult(events);
644 // tslint:disable-next-line:no-unused-expression646 // tslint:disable-next-line:no-unused-expression
645 expect(result.success).to.be.true;647 expect(result.success).to.be.true;
646 const allowanceAfter =648 const allowanceAfter =
647 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;649 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved] as any) as unknown as BN;
648 expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());650 expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());
649 });651 });
650}652}
653transferFromExpectSuccess(collectionId: number,655transferFromExpectSuccess(collectionId: number,
654 tokenId: number,656 tokenId: number,
655 accountApproved: IKeyringPair,657 accountApproved: IKeyringPair,
656 accountFrom: IKeyringPair,658 accountFrom: IKeyringPair | string,
657 accountTo: IKeyringPair,659 accountTo: IKeyringPair,
658 value: number | bigint = 1,660 value: number | bigint = 1,
659 type: string = 'NFT') {661 type: string = 'NFT') {
662 if (typeof accountFrom !== 'string')
663 accountFrom = accountFrom.address;
660 await usingApi(async (api: ApiPromise) => {664 await usingApi(async (api: ApiPromise) => {
661 let balanceBefore = new BN(0);665 let balanceBefore = new BN(0);
662 if (type === 'Fungible') {666 if (type === 'Fungible') {
663 balanceBefore = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;667 balanceBefore = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;
664 }668 }
665 const transferFromTx = await api.tx.nft.transferFrom(669 const transferFromTx = await api.tx.nft.transferFrom(
666 accountFrom.address, accountTo.address, collectionId, tokenId, value);670 accountFrom, accountTo.address, collectionId, tokenId, value);
667 const events = await submitTransactionAsync(accountApproved, transferFromTx);671 const events = await submitTransactionAsync(accountApproved, transferFromTx);
668 const result = getCreateItemResult(events);672 const result = getCreateItemResult(events);
669 // tslint:disable-next-line:no-unused-expression673 // tslint:disable-next-line:no-unused-expression
799}803}
800804
801export async function createItemExpectSuccess(805export async function createItemExpectSuccess(
802 sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {806 sender: IKeyringPair, collectionId: number, createMode: string, owner: string | AccountId = sender.address) {
803 let newItemId: number = 0;807 let newItemId: number = 0;
804 await usingApi(async (api) => {808 await usingApi(async (api) => {
805 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);809 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
806 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();810 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();
807 const AItemBalance = new BigNumber(Aitem.Value);811 const AItemBalance = new BigNumber(Aitem.Value);
808
809 if (owner === '') {
810 owner = sender.address;
811 }
812812
813 let tx;813 let tx;
814 if (createMode === 'Fungible') {814 if (createMode === 'Fungible') {
837 }837 }
838 expect(collectionId).to.be.equal(result.collectionId);838 expect(collectionId).to.be.equal(result.collectionId);
839 expect(BItemCount).to.be.equal(result.itemId);839 expect(BItemCount).to.be.equal(result.itemId);
840 expect(owner).to.be.equal(result.recipient);840 expect(owner.toString()).to.be.equal(result.recipient);
841 newItemId = result.itemId;841 newItemId = result.itemId;
842 });842 });
843 return newItemId;843 return newItemId;
924 return whitelisted;924 return whitelisted;
925}925}
926926
927export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {927export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
928 await usingApi(async (api) => {928 await usingApi(async (api) => {
929929
930 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();930 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();