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

difftreelog

source

js-packages/tests/sub/refungible/transfer.test.ts3.8 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 type {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '@unique/test-utils/util.js';1920describe('Refungible transfer tests', () => {21  let donor: IKeyringPair;22  let alice: IKeyringPair;23  let bob: IKeyringPair;24  let charlie: IKeyringPair;2526  before(async function() {27    await usingPlaygrounds(async (helper, privateKey) => {28      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2930      donor = await privateKey({url: import.meta.url});31      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);32    });33  });3435  itSub('Can transfer token pieces', async ({helper}) => {36    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});37    const token = await collection.mintToken(alice, 100n);3839    expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;40    // 1. Can transfer less or equal than have:41    expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);42    expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);43  });4445  itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {46    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});47    const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});48    const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});4950    // 1. Alice cannot transfer Bob's token:51    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');52    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');53    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');54    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');5556    // 2. Alice cannot transfer non-existing token:57    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');58    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');5960    // 3. Cannot transfer more than have:61    await expect(tokenAlice.transfer(alice, {Substrate: bob.address}, 11n))62      .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);6364    // 4. Zero transfer allowed (EIP-20):65    await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);6667    expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);68    expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);69    expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);70    expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);71    expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);72  });73});