git.delta.rocks / unique-network / refs/commits / 1bdec8235cab

difftreelog

source

tests/src/createMultipleItemsEx.test.ts2.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 {expect} from 'chai';18import privateKey from './substrate/privateKey';19import usingApi, {executeTransaction} from './substrate/substrate-api';20import {createCollectionExpectSuccess} from './util/helpers';2122describe('createMultipleItemsEx', () => {23  it('can initialize multiple NFT with different owners', async () => {24    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});25    const alice = privateKey('//Alice');26    const bob = privateKey('//Bob');27    const charlie = privateKey('//Charlie');28    await usingApi(async (api) => {29      const data = [30        {31          owner: {substrate: alice.address},32          constData: '0x0000',33          variableData: '0x1111',34        }, {35          owner: {substrate: bob.address},36          constData: '0x2222',37          variableData: '0x3333',38        }, {39          owner: {substrate: charlie.address},40          constData: '0x4444',41          variableData: '0x5555',42        },43      ];4445      await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {46        NFT: data,47      }));48      const tokens = await api.query.nonfungible.tokenData.entries(collection);49      const json = tokens.map(([, token]) => token.toJSON());50      expect(json).to.be.deep.equal(data);51    });52  });5354  it('fails when trying to set multiple owners when creating multiple refungibles', async () => {55    const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});56    const alice = privateKey('//Alice');57    const bob = privateKey('//Bob');5859    await usingApi(async (api) => {60      // Polkadot requires map, and yet requires keys to be JSON encoded61      const users = new Map();62      users.set(JSON.stringify({substrate: alice.address}), 1);63      users.set(JSON.stringify({substrate: bob.address}), 1);6465      // TODO: better error message?66      await expect(executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, {67        RefungibleMultipleItems: [68          {users},69          {users},70        ],71      }))).to.be.rejectedWith(/^refungible\.NotRefungibleDataUsedToMintFungibleCollectionToken$/);72    });73  });74});