1import {IKeyringPair} from '@polkadot/types/types';2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import {usingPlaygrounds, itSub} from './util/playgrounds';5import {crossAccountIdFromLower} from './util/playgrounds/unique';67chai.use(chaiAsPromised);8const expect = chai.expect;910describe('integration test: RPC methods', () => {11 let donor: IKeyringPair;12 let alice: IKeyringPair;13 let bob: IKeyringPair;1415 before(async () => {16 await usingPlaygrounds(async (helper, privateKey) => {17 donor = privateKey('//Alice');18 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);19 });20 });2122 itSub('returns None for fungible collection', async ({helper}) => {23 const collection = await helper.ft.mintCollection(alice, {name: 'RPC-1', tokenPrefix: 'RPC'});24 const owner = (await helper.callRpc('api.rpc.unique.tokenOwner', [collection.collectionId, 0])).toJSON() as any;25 expect(owner).to.be.null;26 });27 28 itSub('RPC method tokenOwners for fungible collection and token', async ({helper}) => {29 30 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};31 const facelessCrowd = (await helper.arrange.createAccounts([0n, 0n, 0n, 0n, 0n, 0n, 0n], donor))32 .map(i => {return {Substrate: i.address};});33 34 const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});35 36 await collection.mint(alice, {Substrate: alice.address}, (1n << 128n) - 1n);37 38 await collection.transfer(alice, {Substrate: bob.address}, 1000n);39 await collection.transfer(alice, ethAcc, 900n);40 41 for (let i = 0; i < facelessCrowd.length; i++) {42 await collection.transfer(alice, facelessCrowd[i], 1n);43 }44 4546 const owners = await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0]);47 const ids = (owners.toJSON() as any[]).map(crossAccountIdFromLower);4849 expect(ids).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);50 expect(owners.length == 10).to.be.true;51 52 53 const [eleven] = await helper.arrange.createAccounts([0n], donor);54 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;55 expect((await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0])).length).to.be.equal(10);56 });57});