1import {IKeyringPair} from '@polkadot/types/types';2import {expect} from 'chai';3import usingApi from './substrate/substrate-api';4import {createCollection, createCollectionExpectSuccess, createFungibleItemExpectSuccess, CrossAccountId, getTokenOwner, normalizeAccountId, transfer, U128_MAX} from './util/helpers';56let alice: IKeyringPair;7let bob: IKeyringPair;8910describe('integration test: RPC methods', () => {11 before(async () => {12 await usingApi(async (api, privateKeyWrapper) => {13 alice = privateKeyWrapper('//Alice');14 bob = privateKeyWrapper('//Bob');15 });16 });1718 19 it('returns None for fungible collection', async () => {20 await usingApi(async api => {21 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});22 await expect(getTokenOwner(api, collection, 0)).to.be.rejectedWith(/^owner == null$/);23 });24 });25 26 it('RPC method tokenOnewrs for fungible collection and token', async () => {27 await usingApi(async (api, privateKeyWrapper) => {28 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};29 const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));30 31 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});32 const collectionId = createCollectionResult.collectionId;33 const aliceTokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: U128_MAX}, alice.address);34 35 await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);36 await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);37 38 for (let i = 0; i < 7; i++) {39 await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 1);40 } 41 42 const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);43 const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));44 const aliceID = normalizeAccountId(alice);45 const bobId = normalizeAccountId(bob);4647 48 49 expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);50 expect(owners.length == 10).to.be.true;51 });52 });53});