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

difftreelog

source

tests/src/rpc.test.ts3.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, itSub, expect} from './util';19import {CrossAccountId} from './util/playgrounds/unique';2021describe('integration test: RPC methods', () => {22  let donor: IKeyringPair;23  let alice: IKeyringPair;24  let bob: IKeyringPair;2526  before(async () => {27    await usingPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({url: import.meta.url});29      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);30    });31  });3233  itSub('returns None for fungible collection', async ({helper}) => {34    const collection = await helper.ft.mintCollection(alice, {name: 'RPC-1', tokenPrefix: 'RPC'});35    const owner = (await helper.callRpc('api.rpc.unique.tokenOwner', [collection.collectionId, 0])).toJSON() as any;36    expect(owner).to.be.null;37  });3839  itSub('RPC method tokenOwners for fungible collection and token', async ({helper}) => {40    // Set-up a few token owners of all stripes41    const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};42    const facelessCrowd = (await helper.arrange.createAccounts([0n, 0n, 0n, 0n, 0n, 0n, 0n], donor))43      .map(i => ({Substrate: i.address}));4445    const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});46    // mint some maximum (u128) amounts of tokens possible47    await collection.mint(alice, (1n << 128n) - 1n);4849    await collection.transfer(alice, {Substrate: bob.address}, 1000n);50    await collection.transfer(alice, ethAcc, 900n);5152    for(let i = 0; i < facelessCrowd.length; i++) {53      await collection.transfer(alice, facelessCrowd[i], 1n);54    }55    // Set-up over5657    const owners = await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0]);58    const ids = (owners.toJSON() as any[]).map(CrossAccountId.fromLowerCaseKeys);5960    expect(ids).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);61    expect(owners.length == 10).to.be.true;6263    // Make sure only 10 results are returned with this RPC64    const [eleven] = await helper.arrange.createAccounts([0n], donor);65    expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;66    expect((await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0])).length).to.be.equal(10);67  });68});