difftreelog
tests: upgrade part of them in ascending naming order to use playgrounds
in: master
24 files changed
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';20import {usingPlaygrounds} from './util/playgrounds';20import {itSub, usingPlaygrounds} from './util/playgrounds';212122chai.use(chaiAsPromised);22chai.use(chaiAsPromised);23const expect = chai.expect;23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKeyWrapper) => {29 donor = privateKeyWrapper('//Alice');30 });31});322433describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {25describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {26 let donor: IKeyringPair;2728 before(async () => {29 await usingPlaygrounds(async (_, privateKeyWrapper) => {30 donor = privateKeyWrapper('//Alice');31 });32 });3334 it('Add collection admin.', async () => {34 itSub('Add collection admin.', async ({helper}) => {35 await usingPlaygrounds(async (helper) => {36 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);35 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);37 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});36 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});383739 const collection = await helper.collection.getData(collectionId);38 const collection = await helper.collection.getData(collectionId);40 expect(collection!.normalizedOwner!).to.be.equal(alice.address);39 expect(collection!.normalizedOwner!).to.be.equal(helper.address.normalizeSubstrate(alice.address));414042 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});41 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});434244 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);43 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);45 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});44 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});46 });47 });45 });48});46});494750describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {48describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {49 let donor: IKeyringPair;5051 before(async () => {52 await usingPlaygrounds(async (_, privateKeyWrapper) => {53 donor = privateKeyWrapper('//Alice');54 });55 });5651 it("Not owner can't add collection admin.", async () => {57 itSub("Not owner can't add collection admin.", async ({helper}) => {52 await usingPlaygrounds(async (helper) => {53 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);58 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);54 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});59 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});556056 const collection = await helper.collection.getData(collectionId);61 const collection = await helper.collection.getData(collectionId);57 expect(collection?.normalizedOwner).to.be.equal(alice.address);62 expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));586359 const changeAdminTxBob = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});64 const changeAdminTxBob = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});60 const changeAdminTxCharlie = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});65 const changeAdminTxCharlie = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});61 await expect(changeAdminTxCharlie()).to.be.rejected;66 await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);62 await expect(changeAdminTxBob()).to.be.rejected;67 await expect(changeAdminTxBob()).to.be.rejectedWith(/common\.NoPermission/);636864 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);69 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);65 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});70 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});66 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});71 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});67 });68 });72 });697370 it("Admin can't add collection admin.", async () => {74 itSub("Admin can't add collection admin.", async ({helper}) => {71 await usingPlaygrounds(async (helper) => {72 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);75 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);73 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});76 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});747778 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});81 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});798280 const changeAdminTxCharlie = async () => collection.addAdmin(bob, {Substrate: charlie.address});83 const changeAdminTxCharlie = async () => collection.addAdmin(bob, {Substrate: charlie.address});81 await expect(changeAdminTxCharlie()).to.be.rejected;84 await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);828583 const adminListAfterAddNewAdmin = await collection.getAdmins();86 const adminListAfterAddNewAdmin = await collection.getAdmins();84 expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});87 expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});85 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});88 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});86 });87 });89 });889089 it("Can't add collection admin of not existing collection.", async () => {91 itSub("Can't add collection admin of not existing collection.", async ({helper}) => {90 await usingPlaygrounds(async (helper) => {91 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);92 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);92 // tslint:disable-next-line: no-bitwise93 const collectionId = (1 << 32) - 1;93 const collectionId = (1 << 32) - 1;949495 const addAdminTx = async () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});95 const addAdminTx = async () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});96 await expect(addAdminTx()).to.be.rejected;96 await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);979798 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)98 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)99 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});99 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});100 });101 });100 });102101103 it("Can't add an admin to a destroyed collection.", async () => {102 itSub("Can't add an admin to a destroyed collection.", async ({helper}) => {104 await usingPlaygrounds(async (helper) => {105 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);103 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);106 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});104 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});107105108 await collection.burn(alice);106 await collection.burn(alice);109 const addAdminTx = async () => collection.addAdmin(alice, {Substrate: bob.address});107 const addAdminTx = async () => collection.addAdmin(alice, {Substrate: bob.address});110 await expect(addAdminTx()).to.be.rejected;108 await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);111109112 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)110 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)113 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});111 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});114 });115 });112 });116113117 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {114 itSub('Add an admin to a collection that has reached the maximum number of admins limit', async ({helper}) => {118 await usingPlaygrounds(async (helper) => {119 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);115 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);120 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});116 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});121117129 }125 }130126131 const addExtraAdminTx = async () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});127 const addExtraAdminTx = async () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});132 await expect(addExtraAdminTx()).to.be.rejected;128 await expect(addExtraAdminTx()).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);133 });134 });129 });135});130});136131tests/src/eth/nesting/nest.test.tsdiffbeforeafterboth20 let donor: IKeyringPair;20 let donor: IKeyringPair;212122 before(async function() {22 before(async function() {23 await usingEthPlaygrounds(async (helper, privateKey) => {23 await usingEthPlaygrounds(async (_, privateKey) => {24 donor = privateKey('//Alice');24 donor = privateKey('//Alice');25 });25 });26 });26 });tests/src/eth/payable.test.tsdiffbeforeafterboth22 let donor: IKeyringPair;22 let donor: IKeyringPair;232324 before(async function() {24 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {25 await usingEthPlaygrounds(async (_, privateKey) => {26 donor = privateKey('//Alice');26 donor = privateKey('//Alice');27 });27 });28 });28 });tests/src/fungible.test.tsdiffbeforeafterboth17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {U128_MAX} from './util/helpers';18import {U128_MAX} from './util/helpers';1920import {usingPlaygrounds} from './util/playgrounds';19import {itSub, usingPlaygrounds} from './util/playgrounds';2122import chai from 'chai';20import chai from 'chai';23import chaiAsPromised from 'chai-as-promised';21import chaiAsPromised from 'chai-as-promised';35 });34 });36 });35 });373638 it('Create fungible collection and token', async () => {37 itSub('Create fungible collection and token', async ({helper}) => {39 await usingPlaygrounds(async helper => {40 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});38 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});41 const defaultTokenId = await collection.getLastTokenId();39 const defaultTokenId = await collection.getLastTokenId();42 expect(defaultTokenId).to.be.equal(0);40 expect(defaultTokenId).to.be.equal(0);474548 expect(itemCountAfter).to.be.equal(defaultTokenId);46 expect(itemCountAfter).to.be.equal(defaultTokenId);49 expect(aliceBalance).to.be.equal(U128_MAX);47 expect(aliceBalance).to.be.equal(U128_MAX);50 });51 });48 });52 49 53 it('RPC method tokenOnewrs for fungible collection and token', async () => {50 itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper, privateKey}) => {54 await usingPlaygrounds(async (helper, privateKey) => {55 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};51 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};56 const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));52 const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));575375 const eleven = privateKey('//ALice+11');71 const eleven = privateKey('//ALice+11');76 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;72 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;77 expect((await collection.getTop10Owners()).length).to.be.equal(10);73 expect((await collection.getTop10Owners()).length).to.be.equal(10);78 });79 });74 });80 75 81 it('Transfer token', async () => {76 itSub('Transfer token', async ({helper}) => {82 await usingPlaygrounds(async helper => {83 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};77 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};84 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});78 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});85 await collection.mint(alice, {Substrate: alice.address}, 500n);79 await collection.mint(alice, {Substrate: alice.address}, 500n);93 expect(await collection.getBalance(ethAcc)).to.be.equal(140n);87 expect(await collection.getBalance(ethAcc)).to.be.equal(140n);948895 await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejected;89 await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejected;96 });97 });90 });989199 it('Tokens multiple creation', async () => {92 itSub('Tokens multiple creation', async ({helper}) => {100 await usingPlaygrounds(async helper => {101 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});93 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});10294103 await collection.mintWithOneOwner(alice, {Substrate: alice.address}, [95 await collection.mintWithOneOwner(alice, {Substrate: alice.address}, [107 ]);99 ]);108100109 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);101 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);110 });111 });102 });112103113 it('Burn some tokens ', async () => {104 itSub('Burn some tokens ', async ({helper}) => {114 await usingPlaygrounds(async helper => {115 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});105 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});116 await collection.mint(alice, {Substrate: alice.address}, 500n);106 await collection.mint(alice, {Substrate: alice.address}, 500n);117107120 expect(await collection.burnTokens(alice, 499n)).to.be.true;110 expect(await collection.burnTokens(alice, 499n)).to.be.true;121 expect(await collection.isTokenExists(0)).to.be.true;111 expect(await collection.isTokenExists(0)).to.be.true;122 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);112 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);123 });124 });113 });125 114 126 it('Burn all tokens ', async () => {115 itSub('Burn all tokens ', async ({helper}) => {127 await usingPlaygrounds(async helper => {128 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});116 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});129 await collection.mint(alice, {Substrate: alice.address}, 500n);117 await collection.mint(alice, {Substrate: alice.address}, 500n);130118134122135 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);123 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);136 expect(await collection.getTotalPieces()).to.be.equal(0n);124 expect(await collection.getTotalPieces()).to.be.equal(0n);137 });138 });125 });139126140 it('Set allowance for token', async () => {127 itSub('Set allowance for token', async ({helper}) => {141 await usingPlaygrounds(async helper => {142 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});128 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});143 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};129 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};144 await collection.mint(alice, {Substrate: alice.address}, 100n);130 await collection.mint(alice, {Substrate: alice.address}, 100n);160 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);146 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);161 expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;147 expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;162 expect(await collection.getBalance(ethAcc)).to.be.equal(10n);148 expect(await collection.getBalance(ethAcc)).to.be.equal(10n);163 });164 });149 });165});150});166151tests/src/overflow.test.tsdiffbeforeafterboth23chai.use(chaiAsPromised);23chai.use(chaiAsPromised);24const expect = chai.expect;24const expect = chai.expect;252526// todo:playgrounds skipped ~ postponed26describe.skip('Integration Test fungible overflows', () => {27describe.skip('Integration Test fungible overflows', () => {27 let alice: IKeyringPair;28 let alice: IKeyringPair;28 let bob: IKeyringPair;29 let bob: IKeyringPair;tests/src/pallet-presence.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {ApiPromise} from '@polkadot/api';18import {expect} from 'chai';17import {expect} from 'chai';19import usingApi from './substrate/substrate-api';18import {itSub, usingPlaygrounds} from './util/playgrounds';2021function getModuleNames(api: ApiPromise): string[] {22 return api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());23}241925// Pallets that must always be present20// Pallets that must always be present26const requiredPallets = [21const requiredPallets = [625763describe('Pallet presence', () => {58describe('Pallet presence', () => {64 before(async () => {59 before(async () => {65 await usingApi(async api => {60 await usingPlaygrounds(async helper => {66 const chain = await api.rpc.system.chain();61 const chain = await helper.api!.rpc.system.chain();676268 const refungible = 'refungible';63 const refungible = 'refungible';69 const scheduler = 'scheduler';64 const scheduler = 'scheduler';80 });75 });81 });76 });827783 it('Required pallets are present', async () => {78 itSub('Required pallets are present', async ({helper}) => {84 await usingApi(async api => {85 for (let i=0; i<requiredPallets.length; i++) {86 expect(getModuleNames(api)).to.include(requiredPallets[i]);79 expect(helper.fetchAllPalletNames()).to.contain.members([...requiredPallets]);87 }88 });89 });80 });8190 it('Governance and consensus pallets are present', async () => {82 itSub('Governance and consensus pallets are present', async ({helper}) => {91 await usingApi(async api => {92 for (let i=0; i<consensusPallets.length; i++) {93 expect(getModuleNames(api)).to.include(consensusPallets[i]);83 expect(helper.fetchAllPalletNames()).to.contain.members([...consensusPallets]);94 }95 });96 });84 });8597 it('No extra pallets are included', async () => {86 itSub('No extra pallets are included', async ({helper}) => {98 await usingApi(async api => {99 expect(getModuleNames(api).sort()).to.be.deep.equal([...requiredPallets, ...consensusPallets].sort());87 expect(helper.fetchAllPalletNames().sort()).to.be.deep.equal([...requiredPallets, ...consensusPallets].sort());100 });101 });88 });102});89});10390tests/src/refungible.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';1819import {usingPlaygrounds} from './util/playgrounds';20import {18import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util/playgrounds';21 getModuleNames,22 Pallets,23 requirePallets,24} from './util/helpers';251926import chai from 'chai';20import chai from 'chai';27import chaiAsPromised from 'chai-as-promised';21import chaiAsPromised from 'chai-as-promised';342835describe('integration test: Refungible functionality:', async () => {29describe('integration test: Refungible functionality:', async () => {36 before(async function() {30 before(async function() {37 await requirePallets(this, [Pallets.ReFungible]);3839 await usingPlaygrounds(async (helper, privateKey) => {31 await usingPlaygrounds(async (helper, privateKey) => {32 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3340 alice = privateKey('//Alice');34 alice = privateKey('//Alice');41 bob = privateKey('//Bob');35 bob = privateKey('//Bob');42 if (!getModuleNames(helper.api!).includes(Pallets.ReFungible)) this.skip();43 });36 });44 });37 });45 38 46 it('Create refungible collection and token', async () => {39 itSub('Create refungible collection and token', async ({helper}) => {47 await usingPlaygrounds(async helper => {48 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});40 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});494150 const itemCountBefore = await collection.getLastTokenId();42 const itemCountBefore = await collection.getLastTokenId();56 expect(token?.tokenId).to.be.gte(itemCountBefore);48 expect(token?.tokenId).to.be.gte(itemCountBefore);57 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);49 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);58 expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());50 expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());59 });60 });51 });61 52 62 it('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async () => {53 itSub('Checking RPC methods when interacting with maximum allowed values (MAX_REFUNGIBLE_PIECES)', async ({helper}) => {63 await usingPlaygrounds(async helper => {64 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});54 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});65 55 66 const token = await collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES);56 const token = await collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES);71 expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);61 expect(await collection.getTokenBalance(token.tokenId, {Substrate: bob.address})).to.be.equal(MAX_REFUNGIBLE_PIECES);72 expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);62 expect(await token.getTotalPieces()).to.be.equal(MAX_REFUNGIBLE_PIECES);73 63 74 await expect(collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES + 1n)).to.eventually.be.rejected;64 await expect(collection.mintToken(alice, {Substrate: alice.address}, MAX_REFUNGIBLE_PIECES + 1n))75 });65 .to.eventually.be.rejectedWith(/refungible\.WrongRefungiblePieces/);76 });66 });77 67 78 it('RPC method tokenOnewrs for refungible collection and token', async () => {68 itSub('RPC method tokenOnewrs for refungible collection and token', async ({helper, privateKey}) => {79 await usingPlaygrounds(async (helper, privateKey) => {80 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};69 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};81 const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));70 const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));8271100 const eleven = privateKey('//ALice+11');89 const eleven = privateKey('//ALice+11');101 expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;90 expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;102 expect((await token.getTop10Owners()).length).to.be.equal(10);91 expect((await token.getTop10Owners()).length).to.be.equal(10);103 });104 });92 });105 93 106 it('Transfer token pieces', async () => {94 itSub('Transfer token pieces', async ({helper}) => {107 await usingPlaygrounds(async helper => {108 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});95 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});109 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);96 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);11097114 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);101 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);115 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);102 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);116 103 117 await expect(token.transfer(alice, {Substrate: bob.address}, 41n)).to.eventually.be.rejected;104 await expect(token.transfer(alice, {Substrate: bob.address}, 41n))118 });105 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);119 });106 });120107121 it('Create multiple tokens', async () => {108 itSub('Create multiple tokens', async ({helper}) => {122 await usingPlaygrounds(async helper => {123 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});109 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});124 // TODO: fix mintMultipleTokens110 // TODO: fix mintMultipleTokens125 // await collection.mintMultipleTokens(alice, [111 // await collection.mintMultipleTokens(alice, [135 const lastTokenId = await collection.getLastTokenId();121 const lastTokenId = await collection.getLastTokenId();136 expect(lastTokenId).to.be.equal(3);122 expect(lastTokenId).to.be.equal(3);137 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);123 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);138 });139 });124 });140125141 it('Burn some pieces', async () => {126 itSub('Burn some pieces', async ({helper}) => {142 await usingPlaygrounds(async helper => {143 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});127 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});144 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);128 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);145 expect(await collection.isTokenExists(token.tokenId)).to.be.true;129 expect(await collection.isTokenExists(token.tokenId)).to.be.true;146 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);130 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);147 expect((await token.burn(alice, 99n)).success).to.be.true;131 expect((await token.burn(alice, 99n)).success).to.be.true;148 expect(await collection.isTokenExists(token.tokenId)).to.be.true;132 expect(await collection.isTokenExists(token.tokenId)).to.be.true;149 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);133 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);150 });151 });134 });152135153 it('Burn all pieces', async () => {136 itSub('Burn all pieces', async ({helper}) => {154 await usingPlaygrounds(async helper => { 155 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});137 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});156 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);138 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);157 139 160142161 expect((await token.burn(alice, 100n)).success).to.be.true;143 expect((await token.burn(alice, 100n)).success).to.be.true;162 expect(await collection.isTokenExists(token.tokenId)).to.be.false;144 expect(await collection.isTokenExists(token.tokenId)).to.be.false;163 });164 });145 });165146166 it('Burn some pieces for multiple users', async () => {147 itSub('Burn some pieces for multiple users', async ({helper}) => {167 await usingPlaygrounds(async helper => {168 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});148 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});169 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);149 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);170150189 expect((await token.burn(bob, 1n)).success).to.be.true;169 expect((await token.burn(bob, 1n)).success).to.be.true;190170191 expect(await collection.isTokenExists(token.tokenId)).to.be.false;171 expect(await collection.isTokenExists(token.tokenId)).to.be.false;192 });193 });172 });194173195 it('Set allowance for token', async () => {174 itSub('Set allowance for token', async ({helper}) => {196 await usingPlaygrounds(async helper => {197 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});175 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});198 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);176 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);199 177 206 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);184 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);207 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);185 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);208 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);186 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);209 });210 });187 });211188212 it('Repartition', async () => {189 itSub('Repartition', async ({helper}) => {213 await usingPlaygrounds(async helper => {214 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});190 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});215 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);191 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);216192222 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);198 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);223 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);199 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);224 200 225 await expect(token.repartition(alice, 80n)).to.eventually.be.rejected;201 await expect(token.repartition(alice, 80n))226 202 .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);203 227 expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;204 expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;228 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);205 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);229 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);206 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);230207231 expect(await token.repartition(bob, 150n)).to.be.true;208 expect(await token.repartition(bob, 150n)).to.be.true;232 await expect(token.transfer(bob, {Substrate: alice.address}, 160n)).to.eventually.be.rejected;209 await expect(token.transfer(bob, {Substrate: alice.address}, 160n))233210 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);234 });235 });211 });236212237 it('Repartition with increased amount', async () => {213 itSub('Repartition with increased amount', async ({helper}) => {238 await usingPlaygrounds(async helper => {239 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});214 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});240 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);215 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);241 await token.repartition(alice, 200n);216 await token.repartition(alice, 200n);251 '100',226 '100',252 ],227 ],253 }]);228 }]);254 });255 });229 });256230257 it('Repartition with decreased amount', async () => {231 itSub('Repartition with decreased amount', async ({helper}) => {258 await usingPlaygrounds(async helper => {259 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});232 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});260 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);233 const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);261 await token.repartition(alice, 50n);234 await token.repartition(alice, 50n);271 '50',244 '50',272 ],245 ],273 }]);246 }]);274 });275 });247 });276 248 277 it('Create new collection with properties', async () => {249 itSub('Create new collection with properties', async ({helper}) => {278 await usingPlaygrounds(async helper => {279 const properties = [{key: 'key1', value: 'val1'}];250 const properties = [{key: 'key1', value: 'val1'}];280 const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];251 const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];281 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});252 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});282 const info = await collection.getData();253 const info = await collection.getData();283 expect(info?.raw.properties).to.be.deep.equal(properties);254 expect(info?.raw.properties).to.be.deep.equal(properties);284 expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);255 expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);285 });286 });256 });287});257});288258tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth161617import chai from 'chai';17import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';19import {IKeyringPair} from '@polkadot/types/types';19import {usingPlaygrounds} from './util/playgrounds';20import {itSub, usingPlaygrounds} from './util/playgrounds';202121chai.use(chaiAsPromised);22chai.use(chaiAsPromised);22const expect = chai.expect;23const expect = chai.expect;232424describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {25describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {26 let alice: IKeyringPair;27 let bob: IKeyringPair;2829 before(async () => {30 await usingPlaygrounds(async (helper, privateKey) => {31 const donor = privateKey('//Alice');32 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);33 });34 });3525 it('Remove collection admin.', async () => {36 itSub('Remove collection admin', async ({helper}) => {26 await usingPlaygrounds(async (helper, privateKey) => {37 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});27 const alice = privateKey('//Alice');28 const bob = privateKey('//Bob');29 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});30 31 const collectionInfo = await collection.getData();38 const collectionInfo = await collection.getData();32 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);39 expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);33 // first - add collection admin Bob40 // first - add collection admin Bob34 await collection.addAdmin(alice, {Substrate: bob.address});41 await collection.addAdmin(alice, {Substrate: bob.address});354236 const adminListAfterAddAdmin = await collection.getAdmins();43 const adminListAfterAddAdmin = await collection.getAdmins();37 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});44 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});384539 // then remove bob from admins of collection46 // then remove bob from admins of collection40 await collection.removeAdmin(alice, {Substrate: bob.address});47 await collection.removeAdmin(alice, {Substrate: bob.address});414842 const adminListAfterRemoveAdmin = await collection.getAdmins();49 const adminListAfterRemoveAdmin = await collection.getAdmins();43 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});50 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});44 });45 });51 });465247 it('Remove admin from collection that has no admins', async () => {53 itSub('Remove admin from collection that has no admins', async ({helper}) => {48 await usingPlaygrounds(async (helper, privateKey) => {54 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});49 const alice = privateKey('//Alice');50 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});515552 const adminListBeforeAddAdmin = await collection.getAdmins();56 const adminListBeforeAddAdmin = await collection.getAdmins();53 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);57 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);545855 // await expect(collection.removeAdmin(alice, {Substrate: alice.address})).to.be.rejectedWith('Unable to remove collection admin');56 await collection.removeAdmin(alice, {Substrate: alice.address});59 await collection.removeAdmin(alice, {Substrate: alice.address});57 });58 });60 });59});61});606261describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {63describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {64 let alice: IKeyringPair;65 let bob: IKeyringPair;66 let charlie: IKeyringPair;6768 before(async () => {69 await usingPlaygrounds(async (helper, privateKey) => {70 const donor = privateKey('//Alice');71 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);72 });73 });7462 it('Can\'t remove collection admin from not existing collection', async () => {75 itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {63 await usingPlaygrounds(async (helper, privateKey) => {64 // tslint:disable-next-line: no-bitwise65 const collectionId = (1 << 32) - 1;76 const collectionId = (1 << 32) - 1;66 const alice = privateKey('//Alice');67 const bob = privateKey('//Bob');687769 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejected;78 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))7079 .to.be.rejectedWith(/common\.CollectionNotFound/);71 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)72 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});73 });74 });80 });758176 it('Can\'t remove collection admin from deleted collection', async () => {82 itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {77 await usingPlaygrounds(async (helper, privateKey) => {83 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});78 const alice = privateKey('//Alice');79 const bob = privateKey('//Bob');80 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});818482 expect(await collection.burn(alice)).to.be.true;85 expect(await collection.burn(alice)).to.be.true;838684 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address})).to.be.rejected;87 await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))8588 .to.be.rejectedWith(/common\.CollectionNotFound/);86 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)87 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});88 });89 });89 });909091 it('Regular user can\'t remove collection admin', async () => {91 itSub('Regular user can\'t remove collection admin', async ({helper}) => {92 await usingPlaygrounds(async (helper, privateKey) => {92 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});93 const alice = privateKey('//Alice');94 const bob = privateKey('//Bob');95 const charlie = privateKey('//Charlie');96 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});979398 await collection.addAdmin(alice, {Substrate: bob.address});94 await collection.addAdmin(alice, {Substrate: bob.address});9995100 await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;96 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))10197 .to.be.rejectedWith(/common\.NoPermission/);102 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)103 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});104 });105 });98 });10699107 it('Admin can\'t remove collection admin.', async () => {100 itSub('Admin can\'t remove collection admin.', async ({helper}) => {108 await usingPlaygrounds(async (helper, privateKey) => {101 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});109 const alice = privateKey('//Alice');102 110 const bob = privateKey('//Bob');111 const charlie = privateKey('//Charlie');112 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113 114 await collection.addAdmin(alice, {Substrate: bob.address});103 await collection.addAdmin(alice, {Substrate: bob.address});115 await collection.addAdmin(alice, {Substrate: charlie.address});104 await collection.addAdmin(alice, {Substrate: charlie.address});116105117 const adminListAfterAddAdmin = await collection.getAdmins();106 const adminListAfterAddAdmin = await collection.getAdmins();118 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});107 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});119 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});108 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});120109121 await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;110 await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))111 .to.be.rejectedWith(/common\.NoPermission/);122112123 const adminListAfterRemoveAdmin = await collection.getAdmins();113 const adminListAfterRemoveAdmin = await collection.getAdmins();124 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});114 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});125 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});115 expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});126 });127 });116 });128});117});129118tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth161617import chai from 'chai';17import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionExpectFailAsync} from './substrate/substrate-api';19import {IKeyringPair} from '@polkadot/types/types';20import {20import {itSub, usingPlaygrounds} from './util/playgrounds';21 createCollectionExpectSuccess,22 setCollectionSponsorExpectSuccess,23 destroyCollectionExpectSuccess,24 confirmSponsorshipExpectSuccess,25 confirmSponsorshipExpectFailure,26 createItemExpectSuccess,27 findUnusedAddress,28 removeCollectionSponsorExpectSuccess,29 removeCollectionSponsorExpectFailure,30 normalizeAccountId,31 addCollectionAdminExpectSuccess,32 getCreatedCollectionCount,33} from './util/helpers';34import {IKeyringPair} from '@polkadot/types/types';352136chai.use(chaiAsPromised);22chai.use(chaiAsPromised);37const expect = chai.expect;23const expect = chai.expect;3839let alice: IKeyringPair;40let bob: IKeyringPair;412442describe('integration test: ext. removeCollectionSponsor():', () => {25describe('integration test: ext. removeCollectionSponsor():', () => {26 let donor: IKeyringPair;27 let alice: IKeyringPair;28 let bob: IKeyringPair;432944 before(async () => {30 before(async () => {45 await usingApi(async (api, privateKeyWrapper) => {31 await usingPlaygrounds(async (helper, privateKey) => {46 alice = privateKeyWrapper('//Alice');32 donor = privateKey('//Alice');47 bob = privateKeyWrapper('//Bob');33 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);48 });34 });49 });35 });503651 it('Removing NFT collection sponsor stops sponsorship', async () => {37 itSub('Removing NFT collection sponsor stops sponsorship', async ({helper}) => {52 const collectionId = await createCollectionExpectSuccess();38 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-1', tokenPrefix: 'RCS'});53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);39 await collection.setSponsor(alice, bob.address);54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');40 await collection.confirmSponsorship(bob);55 await removeCollectionSponsorExpectSuccess(collectionId);41 await collection.removeSponsor(alice);564257 await usingApi(async (api, privateKeyWrapper) => {58 // Find unused address43 // Find unused address59 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);44 const [zeroBalance] = await helper.arrange.createAccounts([0n], donor);604561 // Mint token for unused address46 // Mint token for unused address62 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);47 const token = await collection.mintToken(alice, {Substrate: zeroBalance.address});634864 // Transfer this tokens from unused address to Alice - should fail49 // Transfer this tokens from unused address to Alice - should fail65 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();50 const sponsorBalanceBefore = await helper.balance.getSubstrate(bob.address);66 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);67 const badTransaction = async function () {68 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);69 };70 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');51 await expect(token.transfer(zeroBalance, {Substrate: alice.address}))52 .to.be.rejectedWith('Inability to pay some fees');71 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();53 const sponsorBalanceAfter = await helper.balance.getSubstrate(bob.address);725473 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);55 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);74 });75 });56 });765777 it('Remove a sponsor after it was already removed', async () => {58 itSub('Remove a sponsor after it was already removed', async ({helper}) => {78 const collectionId = await createCollectionExpectSuccess();59 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-2', tokenPrefix: 'RCS'});79 await setCollectionSponsorExpectSuccess(collectionId, bob.address);60 await collection.setSponsor(alice, bob.address);80 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');61 await collection.confirmSponsorship(bob);81 await removeCollectionSponsorExpectSuccess(collectionId);62 await expect(collection.removeSponsor(alice)).to.not.be.rejected;82 await removeCollectionSponsorExpectSuccess(collectionId);63 await expect(collection.removeSponsor(alice)).to.not.be.rejected;83 });64 });846585 it('Remove sponsor in a collection that never had the sponsor set', async () => {66 itSub('Remove sponsor in a collection that never had the sponsor set', async ({helper}) => {86 const collectionId = await createCollectionExpectSuccess();67 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-3', tokenPrefix: 'RCS'});87 await removeCollectionSponsorExpectSuccess(collectionId);68 await expect(collection.removeSponsor(alice)).to.not.be.rejected;88 });69 });897090 it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {71 itSub('Remove sponsor for a collection that had the sponsor set, but not confirmed', async ({helper}) => {91 const collectionId = await createCollectionExpectSuccess();72 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-4', tokenPrefix: 'RCS'});92 await setCollectionSponsorExpectSuccess(collectionId, bob.address);73 await collection.setSponsor(alice, bob.address);93 await removeCollectionSponsorExpectSuccess(collectionId);74 await expect(collection.removeSponsor(alice)).to.not.be.rejected;94 });75 });957696});77});977898describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {79describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {80 let alice: IKeyringPair;81 let bob: IKeyringPair;82 let charlie: IKeyringPair;8399 before(async () => {84 before(async () => {100 await usingApi(async (api, privateKeyWrapper) => {85 await usingPlaygrounds(async (helper, privateKey) => {101 alice = privateKeyWrapper('//Alice');86 const donor = privateKey('//Alice');102 bob = privateKeyWrapper('//Bob');87 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);103 });88 });104 });89 });10590106 it('(!negative test!) Remove sponsor for a collection that never existed', async () => {91 itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {107 // Find the collection that never existed108 let collectionId = 0;92 const collectionId = (1 << 32) - 1;109 await usingApi(async (api) => {93 await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);110 collectionId = await getCreatedCollectionCount(api) + 1;111 });112113 await removeCollectionSponsorExpectFailure(collectionId);114 });94 });11595116 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {96 itSub('(!negative test!) Remove sponsor for a collection with collection admin permissions', async ({helper}) => {117 const collectionId = await createCollectionExpectSuccess();97 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});118 await setCollectionSponsorExpectSuccess(collectionId, bob.address);98 await collection.setSponsor(alice, bob.address);119 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);99 await collection.addAdmin(alice, {Substrate: charlie.address});120 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');100 await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);121 });101 });122102123 it('(!negative test!) Remove sponsor for a collection by regular user', async () => {103 itSub('(!negative test!) Remove sponsor for a collection by regular user', async ({helper}) => {124 const collectionId = await createCollectionExpectSuccess();104 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-2', tokenPrefix: 'RCS'});125 await setCollectionSponsorExpectSuccess(collectionId, bob.address);105 await collection.setSponsor(alice, bob.address);126 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');106 await expect(collection.removeSponsor(charlie)).to.be.rejectedWith(/common\.NoPermission/);127 });107 });128108129 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {109 itSub('(!negative test!) Remove sponsor in a destroyed collection', async ({helper}) => {130 const collectionId = await createCollectionExpectSuccess();110 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-3', tokenPrefix: 'RCS'});131 await setCollectionSponsorExpectSuccess(collectionId, bob.address);111 await collection.setSponsor(alice, bob.address);132 await destroyCollectionExpectSuccess(collectionId);112 await collection.burn(alice);133 await removeCollectionSponsorExpectFailure(collectionId);113 await expect(collection.removeSponsor(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);134 });114 });135115136 it('Set - remove - confirm: fails', async () => {116 itSub('Set - remove - confirm: fails', async ({helper}) => {137 const collectionId = await createCollectionExpectSuccess();117 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});138 await setCollectionSponsorExpectSuccess(collectionId, bob.address);118 await collection.setSponsor(alice, bob.address);139 await removeCollectionSponsorExpectSuccess(collectionId);119 await collection.removeSponsor(alice);140 await confirmSponsorshipExpectFailure(collectionId, '//Bob');120 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);141 });121 });142122143 it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {123 itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {144 const collectionId = await createCollectionExpectSuccess();124 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-5', tokenPrefix: 'RCS'});145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);125 await collection.setSponsor(alice, bob.address);146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');126 await collection.confirmSponsorship(bob);147 await removeCollectionSponsorExpectSuccess(collectionId);127 await collection.removeSponsor(alice);148 await confirmSponsorshipExpectFailure(collectionId, '//Bob');128 await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);149 });129 });150151});130});tests/src/removeFromAllowList.test.tsdiffbeforeafterboth161617import chai from 'chai';17import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi} from './substrate/substrate-api';19import {IKeyringPair} from '@polkadot/types/types';20import {20import {itSub, usingPlaygrounds} from './util/playgrounds';21 createCollectionExpectSuccess,22 destroyCollectionExpectSuccess,23 enableAllowListExpectSuccess,24 addToAllowListExpectSuccess,25 removeFromAllowListExpectSuccess,26 isAllowlisted,27 findNotExistingCollection,28 removeFromAllowListExpectFailure,29 disableAllowListExpectSuccess,30 normalizeAccountId,31 addCollectionAdminExpectSuccess,32} from './util/helpers';33import {IKeyringPair} from '@polkadot/types/types';342135chai.use(chaiAsPromised);22chai.use(chaiAsPromised);36const expect = chai.expect;23const expect = chai.expect;40 let bob: IKeyringPair;27 let bob: IKeyringPair;412842 before(async () => {29 before(async () => {43 await usingApi(async (api, privateKeyWrapper) => {30 await usingPlaygrounds(async (helper, privateKey) => {44 alice = privateKeyWrapper('//Alice');31 const donor = privateKey('//Alice');45 bob = privateKeyWrapper('//Bob');32 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);46 });33 });47 });34 });483549 it('ensure bob is not in allowlist after removal', async () => {36 itSub('ensure bob is not in allowlist after removal', async ({helper}) => {50 await usingApi(async api => {37 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-1', tokenPrefix: 'RFAL'});3839 const collectionInfo = await collection.getData();51 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});40 expect(collectionInfo!.raw.permissions.access).to.not.equal('AllowList');4152 await enableAllowListExpectSuccess(alice, collectionId);42 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});53 await addToAllowListExpectSuccess(alice, collectionId, bob.address);43 await collection.addToAllowList(alice, {Substrate: bob.address});5444 expect(await collection.getAllowList()).to.deep.contains({Substrate: bob.address});45 55 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));46 await collection.removeFromAllowList(alice, {Substrate: bob.address});56 expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;47 expect(await collection.getAllowList()).to.be.empty;57 });58 });48 });594960 it('allows removal from collection with unset allowlist status', async () => {50 itSub('allows removal from collection with unset allowlist status', async ({helper}) => {61 await usingApi(async () => {51 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-2', tokenPrefix: 'RFAL'});5262 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();53 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});63 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);54 await collection.addToAllowList(alice, {Substrate: bob.address});64 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);55 expect(await collection.getAllowList()).to.deep.contains({Substrate: bob.address});5665 await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);57 await collection.setPermissions(alice, {access: 'Normal'});6658 67 await removeFromAllowListExpectSuccess(alice, collectionWithoutAllowlistId, normalizeAccountId(bob.address));59 await collection.removeFromAllowList(alice, {Substrate: bob.address});68 });60 expect(await collection.getAllowList()).to.be.empty;69 });61 });70});62});716374 let bob: IKeyringPair;66 let bob: IKeyringPair;756776 before(async () => {68 before(async () => {77 await usingApi(async (api, privateKeyWrapper) => {69 await usingPlaygrounds(async (helper, privateKey) => {78 alice = privateKeyWrapper('//Alice');70 const donor = privateKey('//Alice');79 bob = privateKeyWrapper('//Bob');71 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);80 });72 });81 });73 });827483 it('fails on removal from not existing collection', async () => {75 itSub('fails on removal from not existing collection', async ({helper}) => {76 const nonExistentCollectionId = (1 << 32) - 1;84 await usingApi(async (api) => {77 await expect(helper.collection.removeFromAllowList(alice, nonExistentCollectionId, {Substrate: alice.address}))85 const collectionId = await findNotExistingCollection(api);8687 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));88 });78 .to.be.rejectedWith(/common\.CollectionNotFound/);89 });79 });908091 it('fails on removal from removed collection', async () => {81 itSub('fails on removal from removed collection', async ({helper}) => {92 await usingApi(async () => {82 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-3', tokenPrefix: 'RFAL'});93 const collectionId = await createCollectionExpectSuccess();83 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});94 await enableAllowListExpectSuccess(alice, collectionId);95 await addToAllowListExpectSuccess(alice, collectionId, bob.address);84 await collection.addToAllowList(alice, {Substrate: bob.address});8596 await destroyCollectionExpectSuccess(collectionId);86 await collection.burn(alice);9798 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));87 await expect(collection.removeFromAllowList(alice, {Substrate: bob.address}))99 });88 .to.be.rejectedWith(/common\.CollectionNotFound/);100 });89 });101});90});10291106 let charlie: IKeyringPair;95 let charlie: IKeyringPair;10796108 before(async () => {97 before(async () => {109 await usingApi(async (api, privateKeyWrapper) => {98 await usingPlaygrounds(async (helper, privateKey) => {110 alice = privateKeyWrapper('//Alice');99 const donor = privateKey('//Alice');111 bob = privateKeyWrapper('//Bob');100 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);112 charlie = privateKeyWrapper('//Charlie');113 });101 });114 });102 });115103116 it('ensure address is not in allowlist after removal', async () => {104 itSub('ensure address is not in allowlist after removal', async ({helper}) => {117 await usingApi(async api => {105 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-4', tokenPrefix: 'RFAL'});106 118 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});107 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});119 await enableAllowListExpectSuccess(alice, collectionId);120 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);108 await collection.addAdmin(alice, {Substrate: bob.address});109121 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);110 await collection.addToAllowList(bob, {Substrate: charlie.address});122 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));111 await collection.removeFromAllowList(bob, {Substrate: charlie.address});112123 expect(await isAllowlisted(api, collectionId, charlie.address)).to.be.false;113 expect(await collection.getAllowList()).to.be.empty;124 });125 });114 });126115127 it('Collection admin allowed to remove from allowlist with unset allowlist status', async () => {116 itSub('Collection admin allowed to remove from allowlist with unset allowlist status', async ({helper}) => {128 await usingApi(async () => {117 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-5', tokenPrefix: 'RFAL'});118129 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();119 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});130 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);131 await addCollectionAdminExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);120 await collection.addAdmin(alice, {Substrate: bob.address});132 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);121 await collection.addToAllowList(alice, {Substrate: charlie.address});122133 await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);123 await collection.setPermissions(bob, {access: 'Normal'});134 await removeFromAllowListExpectSuccess(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));124 await collection.removeFromAllowList(bob, {Substrate: charlie.address});125135 });126 expect(await collection.getAllowList()).to.be.empty;136 });127 });137128138 it('Regular user can`t remove from allowlist', async () => {129 itSub('Regular user can`t remove from allowlist', async ({helper}) => {139 await usingApi(async () => {130 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-6', tokenPrefix: 'RFAL'});131140 const collectionWithoutAllowlistId = await createCollectionExpectSuccess();132 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});141 await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);133 await collection.addToAllowList(alice, {Substrate: charlie.address});134142 await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);135 await expect(collection.removeFromAllowList(bob, {Substrate: charlie.address}))136 .to.be.rejectedWith(/common\.NoPermission/);143 await removeFromAllowListExpectFailure(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));137 expect(await collection.getAllowList()).to.deep.contain({Substrate: charlie.address});144 });145 });138 });146});139});147140tests/src/removeFromContractAllowList.test.tsdiffbeforeafterboth20import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';21import {expect} from 'chai';21import {expect} from 'chai';222223// todo:playgrounds skipped again23describe.skip('Integration Test removeFromContractAllowList', () => {24describe.skip('Integration Test removeFromContractAllowList', () => {24 let bob: IKeyringPair;25 let bob: IKeyringPair;2526tests/src/rpc.test.tsdiffbeforeafterboth1import {IKeyringPair} from '@polkadot/types/types';1import {IKeyringPair} from '@polkadot/types/types';2import {expect} from 'chai';2import chai from 'chai';3import usingApi from './substrate/substrate-api';3import chaiAsPromised from 'chai-as-promised';4import {createCollection, createCollectionExpectSuccess, createFungibleItemExpectSuccess, CrossAccountId, getTokenOwner, normalizeAccountId, transfer, U128_MAX} from './util/helpers';4import {usingPlaygrounds, itSub} from './util/playgrounds';5import {crossAccountIdFromLower} from './util/playgrounds/unique';566let alice: IKeyringPair;7chai.use(chaiAsPromised);7let bob: IKeyringPair;8const expect = chai.expect;89910describe('integration test: RPC methods', () => {10describe('integration test: RPC methods', () => {11 let donor: IKeyringPair;12 let alice: IKeyringPair;13 let bob: IKeyringPair;1411 before(async () => {15 before(async () => {12 await usingApi(async (api, privateKeyWrapper) => {16 await usingPlaygrounds(async (helper, privateKey) => {13 alice = privateKeyWrapper('//Alice');17 donor = privateKey('//Alice');14 bob = privateKeyWrapper('//Bob');18 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);15 });19 });16 });20 });172118 19 it('returns None for fungible collection', async () => {22 itSub('returns None for fungible collection', async ({helper}) => {20 await usingApi(async api => {21 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});23 const collection = await helper.ft.mintCollection(alice, {name: 'RPC-1', tokenPrefix: 'RPC'});22 await expect(getTokenOwner(api, collection, 0)).to.be.rejectedWith(/^owner == null$/);23 });24 const owner = (await helper.callRpc('api.rpc.unique.tokenOwner', [collection.collectionId, 0])).toJSON() as any;25 expect(owner).to.be.null;24 });26 });25 27 26 it('RPC method tokenOwners for fungible collection and token', async () => {28 itSub('RPC method tokenOwners for fungible collection and token', async ({helper}) => {27 await usingApi(async (api, privateKeyWrapper) => {29 // Set-up a few token owners of all stripes28 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};30 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};29 const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));31 const facelessCrowd = (await helper.arrange.createAccounts([0n, 0n, 0n, 0n, 0n, 0n, 0n], donor))30 32 .map(i => {return {Substrate: i.address};});33 31 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});34 const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});32 const collectionId = createCollectionResult.collectionId;35 // mint some maximum (u128) amounts of tokens possible33 const aliceTokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: U128_MAX}, alice.address);36 await collection.mint(alice, {Substrate: alice.address}, (1n << 128n) - 1n);34 37 35 await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);38 await collection.transfer(alice, {Substrate: bob.address}, 1000n);36 await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);39 await collection.transfer(alice, ethAcc, 900n);37 40 38 for (let i = 0; i < 7; i++) {41 for (let i = 0; i < facelessCrowd.length; i++) {39 await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 1);42 await collection.transfer(alice, facelessCrowd[i], 1n);40 } 43 }41 44 // Set-up over4542 const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);46 const owners = await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0]);43 const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));47 const ids = (owners.toJSON() as any[]).map(crossAccountIdFromLower);44 const aliceID = normalizeAccountId(alice);4845 const bobId = normalizeAccountId(bob);4647 // What to expect48 // tslint:disable-next-line:no-unused-expression49 expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);49 expect(ids).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);50 expect(owners.length == 10).to.be.true;50 expect(owners.length == 10).to.be.true;51 51 52 // Make sure only 10 results are returned with this RPC52 const eleven = privateKeyWrapper('11');53 const [eleven] = await helper.arrange.createAccounts([0n], donor);53 expect(await transfer(api, collectionId, aliceTokenId, alice, eleven, 10n)).to.be.true;54 expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;54 expect((await api.rpc.unique.tokenOwners(collectionId, aliceTokenId)).length).to.be.equal(10);55 expect((await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0])).length).to.be.equal(10);55 });56 });56 });57});57});tests/src/scheduler.test.tsdiffbeforeafterboth444445chai.use(chaiAsPromised);45chai.use(chaiAsPromised);464647// todo:playgrounds skipped ~ postponed47describe.skip('Scheduling token and balance transfers', () => {48describe.skip('Scheduling token and balance transfers', () => {48 let alice: IKeyringPair;49 let alice: IKeyringPair;49 let bob: IKeyringPair;50 let bob: IKeyringPair;tests/src/setChainLimits.test.tsdiffbeforeafterboth23 IChainLimits,23 IChainLimits,24} from './util/helpers';24} from './util/helpers';252526// todo:playgrounds skipped ~ postponed26describe.skip('Negative Integration Test setChainLimits', () => {27describe.skip('Negative Integration Test setChainLimits', () => {27 let alice: IKeyringPair;28 let alice: IKeyringPair;28 let bob: IKeyringPair;29 let bob: IKeyringPair;tests/src/setCollectionLimits.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits18import {ApiPromise} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';20import chai from 'chai';19import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';20import chaiAsPromised from 'chai-as-promised';22import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';23import {21import {itSub, usingPlaygrounds} from './util/playgrounds';24 createCollectionExpectSuccess, getCreatedCollectionCount,25 getCreateItemResult,26 setCollectionLimitsExpectFailure,27 setCollectionLimitsExpectSuccess,28 addCollectionAdminExpectSuccess,29 queryCollectionExpectSuccess,30} from './util/helpers';312232chai.use(chaiAsPromised);23chai.use(chaiAsPromised);33const expect = chai.expect;24const expect = chai.expect;3435let alice: IKeyringPair;36let bob: IKeyringPair;37let collectionIdForTesting: number;382539const accountTokenOwnershipLimit = 0;26const accountTokenOwnershipLimit = 0;40const sponsoredDataSize = 0;27const sponsoredDataSize = 0;41const sponsorTransferTimeout = 1;28const sponsorTransferTimeout = 1;42const tokenLimit = 10;29const tokenLimit = 10;433044describe('setCollectionLimits positive', () => {31describe('setCollectionLimits positive', () => {45 let tx;32 let alice: IKeyringPair;33 let bob: IKeyringPair;3446 before(async () => {35 before(async () => {47 await usingApi(async (api, privateKeyWrapper) => {36 await usingPlaygrounds(async (helper, privateKey) => {48 alice = privateKeyWrapper('//Alice');37 const donor = privateKey('//Alice');49 bob = privateKeyWrapper('//Bob');50 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});38 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);51 });39 });52 });40 });4153 it('execute setCollectionLimits with predefined params ', async () => {42 itSub('execute setCollectionLimits with predefined params', async ({helper}) => {54 await usingApi(async (api: ApiPromise) => {55 tx = api.tx.unique.setCollectionLimits(56 collectionIdForTesting,57 {58 accountTokenOwnershipLimit: accountTokenOwnershipLimit,59 sponsoredDataSize: sponsoredDataSize,60 tokenLimit: tokenLimit,61 sponsorTransferTimeout,62 ownerCanTransfer: true,63 ownerCanDestroy: true,64 },65 );43 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-1', tokenPrefix: 'SCL'});4466 const events = await submitTransactionAsync(alice, tx);45 await collection.setLimits(67 const result = getCreateItemResult(events);46 alice,47 {48 accountTokenOwnershipLimit,49 sponsoredDataSize,50 tokenLimit,51 sponsorTransferTimeout,52 ownerCanTransfer: true,53 ownerCanDestroy: true,54 },55 );685669 // get collection limits defined previously57 // get collection limits defined previously70 const collectionInfo = await queryCollectionExpectSuccess(api, collectionIdForTesting);58 const collectionInfo = await collection.getEffectiveLimits();715972 // tslint:disable-next-line:no-unused-expression73 expect(result.success).to.be.true;74 expect(collectionInfo.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.equal(accountTokenOwnershipLimit);60 expect(collectionInfo.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);75 expect(collectionInfo.limits.sponsoredDataSize.unwrap().toNumber()).to.be.equal(sponsoredDataSize);61 expect(collectionInfo.sponsoredDataSize).to.be.equal(sponsoredDataSize);76 expect(collectionInfo.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);62 expect(collectionInfo.tokenLimit).to.be.equal(tokenLimit);77 expect(collectionInfo.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.equal(sponsorTransferTimeout);63 expect(collectionInfo.sponsorTransferTimeout).to.be.equal(sponsorTransferTimeout);78 expect(collectionInfo.limits.ownerCanTransfer.unwrap().toJSON()).to.be.true;64 expect(collectionInfo.ownerCanTransfer).to.be.true;79 expect(collectionInfo.limits.ownerCanDestroy.unwrap().toJSON()).to.be.true;65 expect(collectionInfo.ownerCanDestroy).to.be.true;80 });81 });66 });826783 it('Set the same token limit twice', async () => {68 itSub('Set the same token limit twice', async ({helper}) => {84 await usingApi(async (api: ApiPromise) => {69 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-2', tokenPrefix: 'SCL'});857086 const collectionLimits = {71 const collectionLimits = {87 accountTokenOwnershipLimit: accountTokenOwnershipLimit,72 accountTokenOwnershipLimit,88 sponsoredMintSize: sponsoredDataSize,73 sponsoredDataSize,89 tokenLimit: tokenLimit,74 tokenLimit,90 sponsorTransferTimeout,75 sponsorTransferTimeout,91 ownerCanTransfer: true,76 ownerCanTransfer: true,92 ownerCanDestroy: true,77 ownerCanDestroy: true,78 };7993 };80 await collection.setLimits(alice, collectionLimits);948195 // The first time96 const tx1 = api.tx.unique.setCollectionLimits(97 collectionIdForTesting,98 collectionLimits,99 );100 const events1 = await submitTransactionAsync(alice, tx1);101 const result1 = getCreateItemResult(events1);102 expect(result1.success).to.be.true;103 const collectionInfo1 = await queryCollectionExpectSuccess(api, collectionIdForTesting);82 const collectionInfo1 = await collection.getEffectiveLimits();83 104 expect(collectionInfo1.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);84 expect(collectionInfo1.tokenLimit).to.be.equal(tokenLimit);10585106 // The second time107 const tx2 = api.tx.unique.setCollectionLimits(86 await collection.setLimits(alice, collectionLimits);108 collectionIdForTesting,109 collectionLimits,110 );111 const events2 = await submitTransactionAsync(alice, tx2);112 const result2 = getCreateItemResult(events2);113 expect(result2.success).to.be.true;114 const collectionInfo2 = await queryCollectionExpectSuccess(api, collectionIdForTesting);87 const collectionInfo2 = await collection.getEffectiveLimits();115 expect(collectionInfo2.limits.tokenLimit.unwrap().toNumber()).to.be.equal(tokenLimit);88 expect(collectionInfo2.tokenLimit).to.be.equal(tokenLimit);116 });117 });89 });11890119 it('execute setCollectionLimits from admin collection', async () => {91 itSub('execute setCollectionLimits from admin collection', async ({helper}) => {92 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-3', tokenPrefix: 'SCL'});120 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);93 await collection.addAdmin(alice, {Substrate: bob.address});9495 const collectionLimits = {96 accountTokenOwnershipLimit,97 sponsoredDataSize,98 // sponsoredMintSize,99 tokenLimit,100 };101121 await usingApi(async (api: ApiPromise) => {102 await expect(collection.setLimits(alice, collectionLimits)).to.not.be.rejected;122 tx = api.tx.unique.setCollectionLimits(123 collectionIdForTesting,124 {125 accountTokenOwnershipLimit,126 sponsoredDataSize,127 // sponsoredMintSize,128 tokenLimit,129 },130 );131 await expect(submitTransactionAsync(bob, tx)).to.be.not.rejected;132 });133 });103 });134});104});135105136describe('setCollectionLimits negative', () => {106describe('setCollectionLimits negative', () => {137 let tx;107 let alice: IKeyringPair;108 let bob: IKeyringPair;109138 before(async () => {110 before(async () => {139 await usingApi(async (api, privateKeyWrapper) => {111 await usingPlaygrounds(async (helper, privateKey) => {140 alice = privateKeyWrapper('//Alice');112 const donor = privateKey('//Alice');141 bob = privateKeyWrapper('//Bob');142 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});113 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);143 });114 });144 });115 });116 145 it('execute setCollectionLimits for not exists collection', async () => {117 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {118 const nonExistentCollectionId = (1 << 32) - 1;146 await usingApi(async (api: ApiPromise) => {119 await expect(helper.collection.setLimits(147 const collectionCount = await getCreatedCollectionCount(api);120 alice,148 const nonExistedCollectionId = collectionCount + 1;149 tx = api.tx.unique.setCollectionLimits(150 nonExistedCollectionId,121 nonExistentCollectionId,151 {122 {152 accountTokenOwnershipLimit,123 accountTokenOwnershipLimit,153 sponsoredDataSize,124 sponsoredDataSize,154 // sponsoredMintSize,125 // sponsoredMintSize,155 tokenLimit,126 tokenLimit,156 },127 },157 );128 )).to.be.rejectedWith(/common\.CollectionNotFound/);158 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;159 });160 });129 });130161 it('execute setCollectionLimits from user who is not owner of this collection', async () => {131 itSub('execute setCollectionLimits from user who is not owner of this collection', async ({helper}) => {132 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-1', tokenPrefix: 'SCL'});133162 await usingApi(async (api: ApiPromise) => {134 await expect(collection.setLimits(bob, {163 tx = api.tx.unique.setCollectionLimits(164 collectionIdForTesting,165 {166 accountTokenOwnershipLimit,135 accountTokenOwnershipLimit,167 sponsoredDataSize,136 sponsoredDataSize,168 // sponsoredMintSize,137 // sponsoredMintSize,169 tokenLimit,138 tokenLimit,170 },139 })).to.be.rejectedWith(/common\.NoPermission/);171 );172 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;173 });174 });140 });175141176 it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {142 itSub('fails when trying to enable OwnerCanTransfer after it was disabled', async ({helper}) => {177 const collectionId = await createCollectionExpectSuccess();143 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-2', tokenPrefix: 'SCL'});144178 await setCollectionLimitsExpectSuccess(alice, collectionId, {145 await collection.setLimits(alice, {179 accountTokenOwnershipLimit: accountTokenOwnershipLimit,146 accountTokenOwnershipLimit,180 sponsoredMintSize: sponsoredDataSize,147 sponsoredDataSize,181 tokenLimit: tokenLimit,148 tokenLimit,182 sponsorTransferTimeout,149 sponsorTransferTimeout,183 ownerCanTransfer: false,150 ownerCanTransfer: false,184 ownerCanDestroy: true,151 ownerCanDestroy: true,185 });152 });153186 await setCollectionLimitsExpectFailure(alice, collectionId, {154 await expect(collection.setLimits(alice, {187 accountTokenOwnershipLimit: accountTokenOwnershipLimit,155 accountTokenOwnershipLimit,188 sponsoredMintSize: sponsoredDataSize,156 sponsoredDataSize,189 tokenLimit: tokenLimit,157 tokenLimit,190 sponsorTransferTimeout,158 sponsorTransferTimeout,191 ownerCanTransfer: true,159 ownerCanTransfer: true,192 ownerCanDestroy: true,160 ownerCanDestroy: true,193 });161 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);194 });162 });195163196 it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {164 itSub('fails when trying to enable OwnerCanDestroy after it was disabled', async ({helper}) => {197 const collectionId = await createCollectionExpectSuccess();165 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-3', tokenPrefix: 'SCL'});166198 await setCollectionLimitsExpectSuccess(alice, collectionId, {167 await collection.setLimits(alice, {199 accountTokenOwnershipLimit: accountTokenOwnershipLimit,168 accountTokenOwnershipLimit,200 sponsoredMintSize: sponsoredDataSize,169 sponsoredDataSize,201 tokenLimit: tokenLimit,170 tokenLimit,202 sponsorTransferTimeout,171 sponsorTransferTimeout,203 ownerCanTransfer: true,172 ownerCanTransfer: true,204 ownerCanDestroy: false,173 ownerCanDestroy: false,205 });174 });175206 await setCollectionLimitsExpectFailure(alice, collectionId, {176 await expect(collection.setLimits(alice, {207 accountTokenOwnershipLimit: accountTokenOwnershipLimit,177 accountTokenOwnershipLimit,208 sponsoredMintSize: sponsoredDataSize,178 sponsoredDataSize,209 tokenLimit: tokenLimit,179 tokenLimit,210 sponsorTransferTimeout,180 sponsorTransferTimeout,211 ownerCanTransfer: true,181 ownerCanTransfer: true,212 ownerCanDestroy: true,182 ownerCanDestroy: true,213 });183 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);214 });184 });215185216 it('Setting the higher token limit fails', async () => {186 itSub('Setting the higher token limit fails', async ({helper}) => {217 await usingApi(async () => {187 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-4', tokenPrefix: 'SCL'});218188 219 const collectionId = await createCollectionExpectSuccess();220 const collectionLimits = {189 const collectionLimits = {221 accountTokenOwnershipLimit: accountTokenOwnershipLimit,190 accountTokenOwnershipLimit: accountTokenOwnershipLimit,222 sponsoredMintSize: sponsoredDataSize,191 sponsoredMintSize: sponsoredDataSize,227 };196 };228197229 // The first time198 // The first time230 await setCollectionLimitsExpectSuccess(alice, collectionId, collectionLimits);199 await collection.setLimits(alice, collectionLimits);231200232 // The second time - higher token limit201 // The second time - higher token limit233 collectionLimits.tokenLimit += 1;202 collectionLimits.tokenLimit += 1;234 await setCollectionLimitsExpectFailure(alice, collectionId, collectionLimits);203 await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);235 });236 });204 });237238});205});tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth161617import chai from 'chai';17import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi} from './substrate/substrate-api';19import {IKeyringPair} from '@polkadot/types/types';20import {createCollectionExpectSuccess,20import {itSub, usingPlaygrounds, Pallets} from './util/playgrounds';21 setCollectionSponsorExpectSuccess,22 destroyCollectionExpectSuccess,23 setCollectionSponsorExpectFailure,24 addCollectionAdminExpectSuccess,25 getCreatedCollectionCount,26 requirePallets,27 Pallets,28} from './util/helpers';29import {IKeyringPair} from '@polkadot/types/types';302131chai.use(chaiAsPromised);22chai.use(chaiAsPromised);3233let alice: IKeyringPair;23const expect = chai.expect;34let bob: IKeyringPair;35let charlie: IKeyringPair;362437describe('integration test: ext. setCollectionSponsor():', () => {25describe('integration test: ext. setCollectionSponsor():', () => {26 let alice: IKeyringPair;27 let bob: IKeyringPair;28 let charlie: IKeyringPair;382939 before(async () => {30 before(async () => {40 await usingApi(async (api, privateKeyWrapper) => {31 await usingPlaygrounds(async (helper, privateKey) => {41 alice = privateKeyWrapper('//Alice');32 const donor = privateKey('//Alice');42 bob = privateKeyWrapper('//Bob');33 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);43 charlie = privateKeyWrapper('//Charlie');44 });34 });45 });35 });463647 it('Set NFT collection sponsor', async () => {37 itSub('Set NFT collection sponsor', async ({helper}) => {48 const collectionId = await createCollectionExpectSuccess();38 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});49 await setCollectionSponsorExpectSuccess(collectionId, bob.address);39 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4041 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({42 Unconfirmed: bob.address,43 });50 });44 });45 51 it('Set Fungible collection sponsor', async () => {46 itSub('Set Fungible collection sponsor', async ({helper}) => {52 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});47 const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);48 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4950 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({51 Unconfirmed: bob.address,52 });54 });53 });5455 it('Set ReFungible collection sponsor', async function() {55 itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {56 await requirePallets(this, [Pallets.ReFungible]);5758 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});56 const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});59 await setCollectionSponsorExpectSuccess(collectionId, bob.address);57 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5859 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({60 Unconfirmed: bob.address,61 });60 });62 });616362 it('Set the same sponsor repeatedly', async () => {64 itSub('Set the same sponsor repeatedly', async ({helper}) => {63 const collectionId = await createCollectionExpectSuccess();65 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});64 await setCollectionSponsorExpectSuccess(collectionId, bob.address);66 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);67 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6869 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({70 Unconfirmed: bob.address,71 });66 });72 });7367 it('Replace collection sponsor', async () => {74 itSub('Replace collection sponsor', async ({helper}) => {68 const collectionId = await createCollectionExpectSuccess();75 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);76 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;70 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);77 await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7879 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({80 Unconfirmed: charlie.address,81 });71 });82 });83 72 it('Collection admin add sponsor', async () => {84 itSub('Collection admin add sponsor', async ({helper}) => {73 const collectionId = await createCollectionExpectSuccess();85 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});74 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);86 await collection.addAdmin(alice, {Substrate: bob.address});75 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');87 await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8889 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({90 Unconfirmed: charlie.address,91 });76 });92 });77});93});789479describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {95describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {96 let alice: IKeyringPair;97 let bob: IKeyringPair;9880 before(async () => {99 before(async () => {81 await usingApi(async (api, privateKeyWrapper) => {100 await usingPlaygrounds(async (helper, privateKey) => {82 alice = privateKeyWrapper('//Alice');101 const donor = privateKey('//Alice');83 bob = privateKeyWrapper('//Bob');102 [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);84 charlie = privateKeyWrapper('//Charlie');85 });103 });86 });104 });8710588 it('(!negative test!) Add sponsor with a non-owner', async () => {106 itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {89 const collectionId = await createCollectionExpectSuccess();107 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});90 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');108 await expect(collection.setSponsor(bob, bob.address))109 .to.be.rejectedWith(/common\.NoPermission/);91 });110 });11192 it('(!negative test!) Add sponsor to a collection that never existed', async () => {112 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {93 // Find the collection that never existed94 let collectionId = 0;95 await usingApi(async (api) => {96 collectionId = await getCreatedCollectionCount(api) + 1;113 const collectionId = (1 << 32) - 1;97 });9899 await setCollectionSponsorExpectFailure(collectionId, bob.address);114 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))115 .to.be.rejectedWith(/common\.CollectionNotFound/);100 });116 });117101 it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {118 itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {102 const collectionId = await createCollectionExpectSuccess();119 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});103 await destroyCollectionExpectSuccess(collectionId);120 await collection.burn(alice);104 await setCollectionSponsorExpectFailure(collectionId, bob.address);121 await expect(collection.setSponsor(alice, bob.address))122 .to.be.rejectedWith(/common\.CollectionNotFound/);105 });123 });106});124});107125tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth25 setContractSponsoringRateLimitExpectSuccess,25 setContractSponsoringRateLimitExpectSuccess,26} from './util/helpers';26} from './util/helpers';272728// todo:playgrounds postponed skipped test28describe.skip('Integration Test setContractSponsoringRateLimit', () => {29describe.skip('Integration Test setContractSponsoringRateLimit', () => {29 it('ensure sponsored contract can\'t be called twice without pause for free', async () => {30 it('ensure sponsored contract can\'t be called twice without pause for free', async () => {30 await usingApi(async (api, privateKeyWrapper) => {31 await usingApi(async (api, privateKeyWrapper) => {tests/src/setMintPermission.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';18import usingApi from './substrate/substrate-api';19import chaiAsPromised from 'chai-as-promised';19import {20import {itSub, usingPlaygrounds} from './util/playgrounds';20 addToAllowListExpectSuccess,2121 createCollectionExpectSuccess,22chai.use(chaiAsPromised);22 createItemExpectFailure,23const expect = chai.expect;23 createItemExpectSuccess,24 destroyCollectionExpectSuccess,25 enableAllowListExpectSuccess,26 findNotExistingCollection,27 setMintPermissionExpectFailure,28 setMintPermissionExpectSuccess,29 addCollectionAdminExpectSuccess,30} from './util/helpers';312432describe('Integration Test setMintPermission', () => {25describe('Integration Test setMintPermission', () => {33 let alice: IKeyringPair;26 let alice: IKeyringPair;34 let bob: IKeyringPair;27 let bob: IKeyringPair;352836 before(async () => {29 before(async () => {37 await usingApi(async (api, privateKeyWrapper) => {30 await usingPlaygrounds(async (helper, privateKey) => {38 alice = privateKeyWrapper('//Alice');31 const donor = privateKey('//Alice');39 bob = privateKeyWrapper('//Bob');32 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);40 });33 });41 });34 });423543 it('ensure allow-listed non-privileged address can mint tokens', async () => {36 itSub('ensure allow-listed non-privileged address can mint tokens', async ({helper}) => {44 await usingApi(async () => {37 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-1', description: '', tokenPrefix: 'SMP'});45 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});38 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});46 await enableAllowListExpectSuccess(alice, collectionId);39 await collection.addToAllowList(alice, {Substrate: bob.address});47 await setMintPermissionExpectSuccess(alice, collectionId, true);4048 await addToAllowListExpectSuccess(alice, collectionId, bob.address);41 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;4950 await createItemExpectSuccess(bob, collectionId, 'NFT');51 });52 });42 });534354 it('can be enabled twice', async () => {44 itSub('can be enabled twice', async ({helper}) => {55 await usingApi(async () => {45 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-2', description: '', tokenPrefix: 'SMP'});56 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});46 expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');4757 await setMintPermissionExpectSuccess(alice, collectionId, true);48 await collection.setPermissions(alice, {mintMode: true});58 await setMintPermissionExpectSuccess(alice, collectionId, true);49 await collection.setPermissions(alice, {mintMode: true});59 });50 expect((await collection.getData())?.raw.permissions.mintMode).to.be.true;60 });51 });615262 it('can be disabled twice', async () => {53 itSub('can be disabled twice', async ({helper}) => {63 await usingApi(async () => {54 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-3', description: '', tokenPrefix: 'SMP'});55 expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');5657 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});58 expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');64 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});59 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);6065 await setMintPermissionExpectSuccess(alice, collectionId, true);61 await collection.setPermissions(alice, {access: 'Normal', mintMode: false});66 await setMintPermissionExpectSuccess(alice, collectionId, false);62 await collection.setPermissions(alice, {access: 'Normal', mintMode: false});67 await setMintPermissionExpectSuccess(alice, collectionId, false);63 expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');68 });64 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(false);69 });65 });706671 it('Collection admin success on set', async () => {67 itSub('Collection admin success on set', async ({helper}) => {68 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-4', description: '', tokenPrefix: 'SMP'});72 await usingApi(async () => {69 await collection.addAdmin(alice, {Substrate: bob.address});73 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});70 await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});74 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);71 75 await setMintPermissionExpectSuccess(bob, collectionId, true);72 expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');76 });73 expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);77 });74 });78});75});797682 let bob: IKeyringPair;79 let bob: IKeyringPair;838084 before(async () => {81 before(async () => {85 await usingApi(async (api, privateKeyWrapper) => {82 await usingPlaygrounds(async (helper, privateKey) => {86 alice = privateKeyWrapper('//Alice');83 const donor = privateKey('//Alice');87 bob = privateKeyWrapper('//Bob');84 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);88 });85 });89 });86 });908791 it('fails on not existing collection', async () => {88 itSub('fails on not existing collection', async ({helper}) => {89 const collectionId = (1 << 32) - 1;92 await usingApi(async (api) => {90 await expect(helper.collection.setPermissions(alice, collectionId, {mintMode: true}))93 const nonExistingCollection = await findNotExistingCollection(api);94 await setMintPermissionExpectFailure(alice, nonExistingCollection, true);95 });91 .to.be.rejectedWith(/common\.CollectionNotFound/);96 });92 });979398 it('fails on removed collection', async () => {94 itSub('fails on removed collection', async ({helper}) => {95 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-1', tokenPrefix: 'SMP'});96 await collection.burn(alice);9799 await usingApi(async () => {98 await expect(collection.setPermissions(alice, {mintMode: true}))100 const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});101 await destroyCollectionExpectSuccess(removedCollectionId);102103 await setMintPermissionExpectFailure(alice, removedCollectionId, true);104 });99 .to.be.rejectedWith(/common\.CollectionNotFound/);105 });100 });106101107 it('fails when not collection owner tries to set mint status', async () => {102 itSub('fails when non-owner tries to set mint status', async ({helper}) => {108 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});103 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-2', tokenPrefix: 'SMP'});109 await enableAllowListExpectSuccess(alice, collectionId);104110 await setMintPermissionExpectFailure(bob, collectionId, true);105 await expect(collection.setPermissions(bob, {mintMode: true}))106 .to.be.rejectedWith(/common\.NoPermission/);111 });107 });112108113 it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {109 itSub('ensure non-allow-listed non-privileged address can\'t mint tokens', async ({helper}) => {110 const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-3', tokenPrefix: 'SMP'});111 await collection.setPermissions(alice, {mintMode: true});112114 await usingApi(async () => {113 await expect(collection.mintToken(bob, {Substrate: bob.address}))115 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});116 await enableAllowListExpectSuccess(alice, collectionId);117 await setMintPermissionExpectSuccess(alice, collectionId, true);118119 await createItemExpectFailure(bob, collectionId, 'NFT');120 });114 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);121 });115 });122});116});123117tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion18import {ApiPromise} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';20import chai from 'chai';19import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';20import chaiAsPromised from 'chai-as-promised';22import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';23import {21import {itSub, usingPlaygrounds} from './util/playgrounds';24 addToAllowListExpectSuccess,25 createCollectionExpectSuccess,26 createItemExpectSuccess,27 destroyCollectionExpectSuccess,28 enablePublicMintingExpectSuccess,29 enableAllowListExpectSuccess,30 normalizeAccountId,31 addCollectionAdminExpectSuccess,32 getCreatedCollectionCount,33} from './util/helpers';342235chai.use(chaiAsPromised);23chai.use(chaiAsPromised);36const expect = chai.expect;24const expect = chai.expect;372526describe('Integration Test setPublicAccessMode(): ', () => {38let alice: IKeyringPair;27 let alice: IKeyringPair;39let bob: IKeyringPair;28 let bob: IKeyringPair;4029 41describe('Integration Test setPublicAccessMode(): ', () => {42 before(async () => {30 before(async () => {43 await usingApi(async (api, privateKeyWrapper) => {31 await usingPlaygrounds(async (helper, privateKey) => {44 alice = privateKeyWrapper('//Alice');32 const donor = privateKey('//Alice');45 bob = privateKeyWrapper('//Bob');33 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);46 });34 });47 });35 });483649 it('Run extrinsic with collection id parameters, set the allowlist mode for the collection', async () => {37 itSub('Runs extrinsic with collection id parameters, sets the allowlist mode for the collection', async ({helper}) => {50 await usingApi(async () => {38 const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-1', tokenPrefix: 'TF'});51 const collectionId: number = await createCollectionExpectSuccess();39 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});52 await enableAllowListExpectSuccess(alice, collectionId);53 await enablePublicMintingExpectSuccess(alice, collectionId);54 await addToAllowListExpectSuccess(alice, collectionId, bob.address);40 await collection.addToAllowList(alice, {Substrate: bob.address});41 55 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);42 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.be.not.rejected;56 });57 });43 });584459 it('Allowlisted collection limits', async () => {45 itSub('Allowlisted collection limits', async ({helper}) => {46 const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-2', tokenPrefix: 'TF'});47 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});48 60 await usingApi(async (api: ApiPromise) => {49 await expect(collection.mintToken(bob, {Substrate: bob.address}))61 const collectionId = await createCollectionExpectSuccess();62 await enableAllowListExpectSuccess(alice, collectionId);63 await enablePublicMintingExpectSuccess(alice, collectionId);64 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(bob.address), 'NFT');65 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;50 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);66 });67 });51 });5253 itSub('setPublicAccessMode by collection admin', async ({helper}) => {54 const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-4', tokenPrefix: 'TF'});55 await collection.addAdmin(alice, {Substrate: bob.address});5657 await expect(collection.setPermissions(bob, {access: 'AllowList'})).to.be.not.rejected;58 });68});59});696070describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {61describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {62 let alice: IKeyringPair;63 let bob: IKeyringPair;64 71 it('Set a non-existent collection', async () => {65 before(async () => {72 await usingApi(async (api: ApiPromise) => {66 await usingPlaygrounds(async (helper, privateKey) => {73 // tslint:disable-next-line: radix74 const collectionId = await getCreatedCollectionCount(api) + 1;67 const donor = privateKey('//Alice');75 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});68 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);76 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;77 });69 });78 });70 });797180 it('Set the collection that has been deleted', async () => {72 itSub('Sets a non-existent collection', async ({helper}) => {73 const collectionId = (1 << 32) - 1;81 await usingApi(async (api: ApiPromise) => {74 await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList'}))82 // tslint:disable-next-line: no-bitwise83 const collectionId = await createCollectionExpectSuccess();84 await destroyCollectionExpectSuccess(collectionId);85 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});86 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;75 .to.be.rejectedWith(/common\.CollectionNotFound/);87 });88 });76 });897790 it('Re-set the list mode already set in quantity', async () => {78 itSub('Sets the collection that has been deleted', async ({helper}) => {79 const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-1', tokenPrefix: 'TF'});80 await collection.burn(alice);8191 await usingApi(async () => {82 await expect(collection.setPermissions(alice, {access: 'AllowList'}))92 const collectionId: number = await createCollectionExpectSuccess();93 await enableAllowListExpectSuccess(alice, collectionId);94 await enableAllowListExpectSuccess(alice, collectionId);95 });83 .to.be.rejectedWith(/common\.CollectionNotFound/);96 });84 });978598 it('Execute method not on behalf of the collection owner', async () => {86 itSub('Re-sets the list mode already set in quantity', async ({helper}) => {99 await usingApi(async (api: ApiPromise) => {100 // tslint:disable-next-line: no-bitwise101 const collectionId = await createCollectionExpectSuccess();87 const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-2', tokenPrefix: 'TF'});102 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});103 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;104 });88 await collection.setPermissions(alice, {access: 'AllowList'});89 await collection.setPermissions(alice, {access: 'AllowList'});105 });90 });10691107 it('setPublicAccessMode by collection admin', async () => {92 itSub('Executes method as a malefactor', async ({helper}) => {93 const collection = await helper.nft.mintCollection(alice, {name: 'PublicAccess-Neg-3', tokenPrefix: 'TF'});94108 await usingApi(async (api: ApiPromise) => {95 await expect(collection.setPermissions(bob, {access: 'AllowList'}))109 // tslint:disable-next-line: no-bitwise110 const collectionId = await createCollectionExpectSuccess();111 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);112 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});113 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.not.rejected;96 .to.be.rejectedWith(/common\.NoPermission/);114 });115 });97 });116});98});117118describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {119 before(async () => {120 await usingApi(async (api, privateKeyWrapper) => {121 alice = privateKeyWrapper('//Alice');122 bob = privateKeyWrapper('//Bob');123 });124 });125});12699tests/src/toggleContractAllowList.test.tsdiffbeforeafterboth31const value = 0;31const value = 0;32const gasLimit = 3000n * 1000000n;32const gasLimit = 3000n * 1000000n;333334// todo:playgrounds skipped ~ postpone34describe.skip('Integration Test toggleContractAllowList', () => {35describe.skip('Integration Test toggleContractAllowList', () => {353636 it('Enable allow list contract mode', async () => {37 it('Enable allow list contract mode', async () => {tests/src/transfer.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';19import {expect} from 'chai';18import chai from 'chai';20import getBalance from './substrate/get-balance';19import chaiAsPromised from 'chai-as-promised';21import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';22import {20import {itEth, usingEthPlaygrounds} from './eth/util/playgrounds';23 burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,24 destroyCollectionExpectSuccess,25 findUnusedAddress,26 getCreateCollectionResult,27 getCreateItemResult,28 transferExpectFailure,29 transferExpectSuccess,30 addCollectionAdminExpectSuccess,31 getCreatedCollectionCount,32 toSubstrateAddress,33 getTokenOwner,34 normalizeAccountId,35 getBalance as getTokenBalance,36 transferFromExpectSuccess,37 transferFromExpectFail,38 requirePallets,39 Pallets,40} from './util/helpers';41import {21import {itSub, Pallets, usingPlaygrounds} from './util/playgrounds';42 subToEth,43 itWeb3, 44} from './eth/util/helpers';45import {request} from 'https';462247let alice: IKeyringPair;23chai.use(chaiAsPromised);48let bob: IKeyringPair;24const expect = chai.expect;49let charlie: IKeyringPair;502551describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {26describe.skip('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {27 let alice: IKeyringPair;28 let bob: IKeyringPair;2952 before(async () => {30 before(async () => {53 await usingApi(async (api, privateKeyWrapper) => {31 await usingPlaygrounds(async (helper, privateKey) => {54 alice = privateKeyWrapper('//Alice');32 const donor = privateKey('//Alice');55 bob = privateKeyWrapper('//Bob');33 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);56 });34 });57 });35 });58 36 59 it('Balance transfers and check balance', async () => {37 itSub('Balance transfers and check balance', async ({helper}) => {60 await usingApi(async (api, privateKeyWrapper) => {38 const alicesBalanceBefore = await helper.balance.getSubstrate(alice.address);61 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alice.address, bob.address]);39 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);624063 const transfer = api.tx.balances.transfer(bob.address, 1n);41 expect(await helper.balance.transferToSubstrate(alice, bob.address, 1n)).to.be.true;64 const events = await submitTransactionAsync(alice, transfer);65 const result = getCreateItemResult(events);66 // tslint:disable-next-line:no-unused-expression67 expect(result.success).to.be.true;684269 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alice.address, bob.address]);43 const alicesBalanceAfter = await helper.balance.getSubstrate(alice.address);44 const bobsBalanceAfter = await helper.balance.getSubstrate(bob.address);704571 // tslint:disable-next-line:no-unused-expression46 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;72 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;73 // tslint:disable-next-line:no-unused-expression47 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;74 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;75 });76 });48 });774978 it('Inability to pay fees error message is correct', async () => {50 itSub('Inability to pay fees error message is correct', async ({helper, privateKey}) => {79 await usingApi(async (api, privateKeyWrapper) => {80 // Find unused address51 const donor = privateKey('//Alice');81 const pk = await findUnusedAddress(api, privateKeyWrapper);52 const [zero] = await helper.arrange.createAccounts([0n], donor);825383 const badTransfer = api.tx.balances.transfer(bob.address, 1n);54 // console.error = () => {};84 // const events = await submitTransactionAsync(pk, badTransfer);85 const badTransaction = async () => {86 const events = await submitTransactionAsync(pk, badTransfer);55 // The following operation throws an error into the console and the logs. Pay it no heed as long as the test succeeds.87 const result = getCreateCollectionResult(events);88 // tslint:disable-next-line:no-unused-expression89 expect(result.success).to.be.false;56 await expect(helper.balance.transferToSubstrate(zero, donor.address, 1n))90 };91 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');57 .to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');92 });93 });58 });945995 it('[nft] User can transfer owned token', async () => {60 itSub('[nft] User can transfer owned token', async ({helper}) => {96 const nftCollectionId = await createCollectionExpectSuccess();61 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-1-NFT', description: '', tokenPrefix: 'T'});97 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');62 const nft = await collection.mintToken(alice, {Substrate: alice.address});6398 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 1, 'NFT');64 await nft.transfer(alice, {Substrate: bob.address});65 expect(await nft.getOwner()).to.be.deep.equal({Substrate: bob.address});99 });66 });10067101 it('[fungible] User can transfer owned token', async () => {68 itSub('[fungible] User can transfer owned token', async ({helper}) => {102 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});69 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-1-FT', description: '', tokenPrefix: 'T'});103 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');70 await collection.mint(alice, {Substrate: alice.address}, 10n);71104 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 1, 'Fungible');72 await collection.transfer(alice, {Substrate: bob.address}, 9n);73 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);74 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);105 });75 });10676107 it('[refungible] User can transfer owned token', async function() {77 itSub.ifWithPallets('[refungible] User can transfer owned token', [Pallets.ReFungible], async ({helper}) => {108 await requirePallets(this, [Pallets.ReFungible]);78 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});79 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);10980110 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});81 await rft.transfer(alice, {Substrate: bob.address}, 9n);111 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');82 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);112 await transferExpectSuccess(83 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);113 reFungibleCollectionId,114 newReFungibleTokenId,115 alice,116 bob,117 100,118 'ReFungible',119 );120 });84 });12185122 it('[nft] Collection admin can transfer owned token', async () => {86 itSub('[nft] Collection admin can transfer owned token', async ({helper}) => {123 const nftCollectionId = await createCollectionExpectSuccess();87 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-2-NFT', description: '', tokenPrefix: 'T'});124 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);88 await collection.addAdmin(alice, {Substrate: bob.address});89125 const newNftTokenId = await createItemExpectSuccess(bob, nftCollectionId, 'NFT', bob.address);90 const nft = await collection.mintToken(bob, {Substrate: bob.address});126 await transferExpectSuccess(nftCollectionId, newNftTokenId, bob, alice, 1, 'NFT');91 await nft.transfer(bob, {Substrate: alice.address});9293 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});127 });94 });12895129 it('[fungible] Collection admin can transfer owned token', async () => {96 itSub('[fungible] Collection admin can transfer owned token', async ({helper}) => {130 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});97 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-2-FT', description: '', tokenPrefix: 'T'});131 await addCollectionAdminExpectSuccess(alice, fungibleCollectionId, bob.address);98 await collection.addAdmin(alice, {Substrate: bob.address});99132 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible', bob.address);100 await collection.mint(bob, {Substrate: bob.address}, 10n);133 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, 1, 'Fungible');101 await collection.transfer(bob, {Substrate: alice.address}, 1n);102103 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);104 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);134 });105 });135106136 it('[refungible] Collection admin can transfer owned token', async function() {107 itSub.ifWithPallets('[refungible] Collection admin can transfer owned token', [Pallets.ReFungible], async ({helper}) => {137 await requirePallets(this, [Pallets.ReFungible]);108 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-2-RFT', description: '', tokenPrefix: 'T'});109 await collection.addAdmin(alice, {Substrate: bob.address});138110139 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});111 const rft = await collection.mintToken(bob, {Substrate: bob.address}, 10n);140 await addCollectionAdminExpectSuccess(alice, reFungibleCollectionId, bob.address);112 await rft.transfer(bob, {Substrate: alice.address}, 1n);113141 const newReFungibleTokenId = await createItemExpectSuccess(bob, reFungibleCollectionId, 'ReFungible', bob.address);114 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);142 await transferExpectSuccess(115 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);143 reFungibleCollectionId,144 newReFungibleTokenId,145 bob,146 alice,147 100,148 'ReFungible',149 );150 });116 });151});117});152118153describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {119describe.skip('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {120 let alice: IKeyringPair;121 let bob: IKeyringPair;122154 before(async () => {123 before(async () => {155 await usingApi(async (api, privateKeyWrapper) => {124 await usingPlaygrounds(async (helper, privateKey) => {156 alice = privateKeyWrapper('//Alice');125 const donor = privateKey('//Alice');157 bob = privateKeyWrapper('//Bob');126 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);158 charlie = privateKeyWrapper('//Charlie');159 });127 });160 });128 });161129162 it('[nft] Transfer with not existed collection_id', async () => {130 itSub('[nft] Transfer with not existed collection_id', async ({helper}) => {163 await usingApi(async (api) => {164 const nftCollectionCount = await getCreatedCollectionCount(api);131 const collectionId = (1 << 32) - 1;165 await transferExpectFailure(nftCollectionCount + 1, 1, alice, bob, 1);132 await expect(helper.nft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))166 });133 .to.be.rejectedWith(/common\.CollectionNotFound/);167 });134 });168135169 it('[fungible] Transfer with not existed collection_id', async () => {136 itSub('[fungible] Transfer with not existed collection_id', async ({helper}) => {170 await usingApi(async (api) => {171 const fungibleCollectionCount = await getCreatedCollectionCount(api);137 const collectionId = (1 << 32) - 1;172 await transferExpectFailure(fungibleCollectionCount + 1, 0, alice, bob, 1);138 await expect(helper.ft.transfer(alice, collectionId, {Substrate: bob.address}))173 });139 .to.be.rejectedWith(/common\.CollectionNotFound/);174 });140 });175141176 it('[refungible] Transfer with not existed collection_id', async function() {142 itSub.ifWithPallets('[refungible] Transfer with not existed collection_id', [Pallets.ReFungible], async ({helper}) => {177 await requirePallets(this, [Pallets.ReFungible]);178179 await usingApi(async (api) => {180 const reFungibleCollectionCount = await getCreatedCollectionCount(api);143 const collectionId = (1 << 32) - 1;181 await transferExpectFailure(reFungibleCollectionCount + 1, 1, alice, bob, 1);144 await expect(helper.rft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))182 });145 .to.be.rejectedWith(/common\.CollectionNotFound/);183 });146 });184147185 it('[nft] Transfer with deleted collection_id', async () => {148 itSub('[nft] Transfer with deleted collection_id', async ({helper}) => {186 const nftCollectionId = await createCollectionExpectSuccess();149 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-1-NFT', description: '', tokenPrefix: 'T'});187 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');150 const nft = await collection.mintToken(alice, {Substrate: alice.address});151188 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId);152 await nft.burn(alice);189 await destroyCollectionExpectSuccess(nftCollectionId);153 await collection.burn(alice);154190 await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);155 await expect(nft.transfer(alice, {Substrate: bob.address}))156 .to.be.rejectedWith(/common\.CollectionNotFound/);191 });157 });192158193 it('[fungible] Transfer with deleted collection_id', async () => {159 itSub('[fungible] Transfer with deleted collection_id', async ({helper}) => {194 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});160 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-1-FT', description: '', tokenPrefix: 'T'});195 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');161 await collection.mint(alice, {Substrate: alice.address}, 10n);162196 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);163 await collection.burnTokens(alice, 10n);197 await destroyCollectionExpectSuccess(fungibleCollectionId);164 await collection.burn(alice);165198 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, alice, bob, 1);166 await expect(collection.transfer(alice, {Substrate: bob.address}))167 .to.be.rejectedWith(/common\.CollectionNotFound/);199 });168 });169 170 itSub.ifWithPallets('[refungible] Transfer with deleted collection_id', [Pallets.ReFungible], async ({helper}) => {171 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-1-RFT', description: '', tokenPrefix: 'T'});172 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);200173201 it('[refungible] Transfer with deleted collection_id', async function() {174 await rft.burn(alice, 10n);202 await requirePallets(this, [Pallets.ReFungible]);175 await collection.burn(alice);203176204 const reFungibleCollectionId = await177 await expect(rft.transfer(alice, {Substrate: bob.address}))205 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});206 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');207 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);178 .to.be.rejectedWith(/common\.CollectionNotFound/);208 await destroyCollectionExpectSuccess(reFungibleCollectionId);209 await transferExpectFailure(210 reFungibleCollectionId,211 newReFungibleTokenId,212 alice,213 bob,214 1,215 );216 });179 });217180218 it('[nft] Transfer with not existed item_id', async () => {181 itSub('[nft] Transfer with not existed item_id', async ({helper}) => {219 const nftCollectionId = await createCollectionExpectSuccess();182 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-2-NFT', description: '', tokenPrefix: 'T'});220 await transferExpectFailure(nftCollectionId, 2, alice, bob, 1);183 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))184 .to.be.rejectedWith(/common\.TokenNotFound/);221 });185 });222186223 it('[fungible] Transfer with not existed item_id', async () => {187 itSub('[fungible] Transfer with not existed item_id', async ({helper}) => {224 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});188 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-2-FT', description: '', tokenPrefix: 'T'});225 await transferExpectFailure(fungibleCollectionId, 2, alice, bob, 1);189 await expect(collection.transfer(alice, {Substrate: bob.address}))190 .to.be.rejectedWith(/common\.TokenValueTooLow/);226 });191 });227192228 it('[refungible] Transfer with not existed item_id', async function() {193 itSub.ifWithPallets('[refungible] Transfer with not existed item_id', [Pallets.ReFungible], async ({helper}) => {229 await requirePallets(this, [Pallets.ReFungible]);194 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-2-RFT', description: '', tokenPrefix: 'T'});230231 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});232 await transferExpectFailure(195 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))233 reFungibleCollectionId,234 2,235 alice,236 bob,237 1,196 .to.be.rejectedWith(/common\.TokenValueTooLow/);238 );239 });197 });240198241 it('[nft] Transfer with deleted item_id', async () => {199 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {242 const nftCollectionId = await createCollectionExpectSuccess();200 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});243 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');201 const nft = await collection.mintToken(alice, {Substrate: alice.address});202244 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);203 await nft.burn(alice);204245 await transferExpectFailure(nftCollectionId, newNftTokenId, alice, bob, 1);205 await expect(nft.transfer(alice, {Substrate: bob.address}))206 .to.be.rejectedWith(/common\.TokenNotFound/);246 });207 });247208248 it('[fungible] Transfer with deleted item_id', async () => {209 itSub('[fungible] Transfer with deleted item_id', async ({helper}) => {249 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});210 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-3-FT', description: '', tokenPrefix: 'T'});250 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');211 await collection.mint(alice, {Substrate: alice.address}, 10n);212251 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);213 await collection.burnTokens(alice, 10n);214252 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, alice, bob, 1);215 await expect(collection.transfer(alice, {Substrate: bob.address}))216 .to.be.rejectedWith(/common\.TokenValueTooLow/);253 });217 });254218255 it('[refungible] Transfer with deleted item_id', async function() {219 itSub.ifWithPallets('[refungible] Transfer with deleted item_id', [Pallets.ReFungible], async ({helper}) => {256 await requirePallets(this, [Pallets.ReFungible]);220 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-3-RFT', description: '', tokenPrefix: 'T'});221 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);257222258 const reFungibleCollectionId = await223 await rft.burn(alice, 10n);259 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});224260 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');261 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);262 await transferExpectFailure(225 await expect(rft.transfer(alice, {Substrate: bob.address}))263 reFungibleCollectionId,264 newReFungibleTokenId,265 alice,266 bob,267 1,226 .to.be.rejectedWith(/common\.TokenValueTooLow/);268 );269 });227 });270228271 it('[nft] Transfer with recipient that is not owner', async () => {229 itSub('[nft] Transfer with recipient that is not owner', async ({helper}) => {272 const nftCollectionId = await createCollectionExpectSuccess();230 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-4-NFT', description: '', tokenPrefix: 'T'});273 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');231 const nft = await collection.mintToken(alice, {Substrate: alice.address});232274 await transferExpectFailure(nftCollectionId, newNftTokenId, charlie, bob, 1);233 await expect(nft.transfer(bob, {Substrate: bob.address}))234 .to.be.rejectedWith(/common\.NoPermission/);235 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});275 });236 });276237277 it('[fungible] Transfer with recipient that is not owner', async () => {238 itSub('[fungible] Transfer with recipient that is not owner', async ({helper}) => {278 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});239 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-4-FT', description: '', tokenPrefix: 'T'});279 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');240 await collection.mint(alice, {Substrate: alice.address}, 10n);241280 await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, charlie, bob, 1);242 await expect(collection.transfer(bob, {Substrate: bob.address}, 9n))243 .to.be.rejectedWith(/common\.TokenValueTooLow/);244 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);245 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(10n);281 });246 });282247283 it('[refungible] Transfer with recipient that is not owner', async function() {248 itSub.ifWithPallets('[refungible] Transfer with recipient that is not owner', [Pallets.ReFungible], async ({helper}) => {284 await requirePallets(this, [Pallets.ReFungible]);249 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});250 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);285251286 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});252 await expect(rft.transfer(bob, {Substrate: bob.address}, 9n))287 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');253 .to.be.rejectedWith(/common\.TokenValueTooLow/);288 await transferExpectFailure(254 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(0n);289 reFungibleCollectionId,290 newReFungibleTokenId,291 charlie,292 bob,293 1,255 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(10n);294 );295 });256 });296});257});297258298describe('Zero value transfer(From)', () => {259describe('Transfers to self (potentially over substrate-evm boundary)', () => {299 before(async () => {260 let donor: IKeyringPair;261262 before(async function() {300 await usingApi(async (api, privateKeyWrapper) => {263 await usingEthPlaygrounds(async (_, privateKey) => {301 alice = privateKeyWrapper('//Alice');264 donor = privateKey('//Alice');302 bob = privateKeyWrapper('//Bob');303 });265 });304 });266 });267 268 itEth('Transfers to self. In case of same frontend', async ({helper}) => {269 const [owner] = await helper.arrange.createAccounts([10n], donor);270 const collection = await helper.ft.mintCollection(owner, {});271 await collection.mint(owner, {Substrate: owner.address}, 100n);305272306 it('NFT', async () => {273 const ownerProxy = helper.address.substrateToEth(owner.address);307 await usingApi(async (api: ApiPromise) => {308 const nftCollectionId = await createCollectionExpectSuccess();309 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');310274311 const transferTx = api.tx.unique.transfer(normalizeAccountId(bob), nftCollectionId, newNftTokenId, 0);275 // transfer to own proxy276 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);312 await submitTransactionAsync(alice, transferTx);277 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);313 const address = normalizeAccountId(await getTokenOwner(api, nftCollectionId, newNftTokenId));278 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);314279315 expect(toSubstrateAddress(address)).to.be.equal(alice.address);280 // transfer-from own proxy to own proxy again281 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Ethereum: ownerProxy}, 5n);282 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);316 });283 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);317 });284 });318285319 it('RFT', async function() {286 itEth('Transfers to self. In case of substrate-evm boundary', async ({helper}) => {320 await requirePallets(this, [Pallets.ReFungible]);287 const [owner] = await helper.arrange.createAccounts([10n], donor);288 const collection = await helper.ft.mintCollection(owner, {});289 await collection.mint(owner, {Substrate: owner.address}, 100n);321290322 await usingApi(async (api: ApiPromise) => {291 const ownerProxy = helper.address.substrateToEth(owner.address);323 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});324 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');325 const balanceBeforeAlice = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(alice), newReFungibleTokenId);326 const balanceBeforeBob = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(bob), newReFungibleTokenId);327292328 const transferTx = api.tx.unique.transfer(normalizeAccountId(bob), reFungibleCollectionId, newReFungibleTokenId, 0);293 // transfer to own proxy294 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);329 await submitTransactionAsync(alice, transferTx);295 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);296 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);330297331 const balanceAfterAlice = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(alice), newReFungibleTokenId);298 // transfer-from own proxy to self332 const balanceAfterBob = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(bob), newReFungibleTokenId);299 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Substrate: owner.address}, 5n);333334 expect((balanceBeforeAlice)).to.be.equal(balanceAfterAlice);300 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(95n);335 expect((balanceBeforeBob)).to.be.equal(balanceAfterBob);301 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(5n);336 });337 });302 });338303339 it('Fungible', async () => {304 itEth('Transfers to self. In case of inside substrate-evm', async ({helper}) => {340 await usingApi(async (api: ApiPromise) => {341 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});305 const [owner] = await helper.arrange.createAccounts([10n], donor);342 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');306 const collection = await helper.ft.mintCollection(owner, {});343 const balanceBeforeAlice = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(alice), newFungibleTokenId);307 await collection.mint(owner, {Substrate: owner.address}, 100n);344 const balanceBeforeBob = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(bob), newFungibleTokenId);345308346 const transferTx = api.tx.unique.transfer(normalizeAccountId(bob), fungibleCollectionId, newFungibleTokenId, 0);309 // transfer to self again310 await collection.transfer(owner, {Substrate: owner.address}, 10n);347 await submitTransactionAsync(alice, transferTx);311 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);348312349 const balanceAfterAlice = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(alice), newFungibleTokenId);313 // transfer-from self to self again350 const balanceAfterBob = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(bob), newFungibleTokenId);314 await collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 5n);351352 expect((balanceBeforeAlice)).to.be.equal(balanceAfterAlice);315 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);353 expect((balanceBeforeBob)).to.be.equal(balanceAfterBob);354 });355 });316 });356});357317358describe('Transfers to self (potentially over substrate-evm boundary)', () => {318 itEth('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({helper}) => {359 itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {360 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});319 const [owner] = await helper.arrange.createAccounts([10n], donor);361 const aliceProxy = subToEth(alice.address);362 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});363 await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');364 const balanceAliceBefore = await getTokenBalance(api, collectionId, {Ethereum: aliceProxy}, tokenId);320 const collection = await helper.ft.mintCollection(owner, {});365 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, {Ethereum: aliceProxy}, 10, 'Fungible');321 await collection.mint(owner, {Substrate: owner.address}, 10n);366 const balanceAliceAfter = await getTokenBalance(api, collectionId, {Ethereum: aliceProxy}, tokenId);367 expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);368 });369322370 itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {323 // transfer to self again371 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});324 await expect(collection.transfer(owner, {Substrate: owner.address}, 11n))372 const aliceProxy = subToEth(alice.address);373 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});374 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);375 await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy} , 10, 'Fungible');376 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, alice, 10, 'Fungible');377 const balanceAliceAfter = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);378 expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);379 });380381 itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {382 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});383 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});384 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);385 await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');325 .to.be.rejectedWith(/common\.TokenValueTooLow/);386 await transferFromExpectSuccess(collectionId, tokenId, alice, alice, alice, 10, 'Fungible');387 const balanceAliceAfter = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);388 expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);389 });390326391 itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {327 // transfer-from self to self again392 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});328 await expect(collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 12n))393 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});394 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);395 await transferExpectFailure(collectionId, tokenId, alice, alice , 11);329 .to.be.rejectedWith(/common\.TokenValueTooLow/);396 await transferFromExpectFail(collectionId, tokenId, alice, alice, alice, 11);397 const balanceAliceAfter = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);330 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(10n);398 expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);399 });331 });400});332});401333tests/src/transferFrom.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';18import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';21import {default as usingApi} from './substrate/substrate-api';20import {itSub, Pallets, usingPlaygrounds} from './util/playgrounds';22import {23 approveExpectFail,24 approveExpectSuccess,25 createCollectionExpectSuccess,26 createFungibleItemExpectSuccess,27 createItemExpectSuccess,28 getAllowance,29 transferFromExpectFail,30 transferFromExpectSuccess,31 burnItemExpectSuccess,32 setCollectionLimitsExpectSuccess,33 getCreatedCollectionCount,34 requirePallets,35 Pallets,36} from './util/helpers';372138chai.use(chaiAsPromised);22chai.use(chaiAsPromised);39const expect = chai.expect;23const expect = chai.expect;44 let charlie: IKeyringPair;28 let charlie: IKeyringPair;452946 before(async () => {30 before(async () => {47 await usingApi(async (api, privateKeyWrapper) => {31 await usingPlaygrounds(async (helper, privateKey) => {48 alice = privateKeyWrapper('//Alice');32 const donor = privateKey('//Alice');49 bob = privateKeyWrapper('//Bob');33 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);50 charlie = privateKeyWrapper('//Charlie');51 });34 });52 });35 });533654 it('[nft] Execute the extrinsic and check nftItemList - owner of token', async () => {37 itSub('[nft] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {55 const nftCollectionId = await createCollectionExpectSuccess();38 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-1', description: '', tokenPrefix: 'TF'});56 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');39 const nft = await collection.mintToken(alice, {Substrate: alice.address});57 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);40 await nft.approve(alice, {Substrate: bob.address});41 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;584259 await transferFromExpectSuccess(nftCollectionId, newNftTokenId, bob, alice, charlie, 1, 'NFT');43 await nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address});44 expect(await nft.getOwner()).to.be.deep.equal({Substrate: charlie.address});60 });45 });614662 it('[fungible] Execute the extrinsic and check nftItemList - owner of token', async () => {47 itSub('[fungible] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {63 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});48 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-2', description: '', tokenPrefix: 'TF'});64 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');49 await collection.mint(alice, {Substrate: alice.address}, 10n);50 await collection.approveTokens(alice, {Substrate: bob.address}, 7n);65 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);51 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);66 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1, 'Fungible');52 53 await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 6n);54 expect(await collection.getBalance({Substrate: charlie.address})).to.be.equal(6n);55 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(4n);56 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(1n);67 });57 });685869 it('[refungible] Execute the extrinsic and check nftItemList - owner of token', async function() {59 itSub.ifWithPallets('[refungible] Execute the extrinsic and check nftItemList - owner of token', [Pallets.ReFungible], async ({helper}) => {70 await requirePallets(this, [Pallets.ReFungible]);60 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-3', description: '', tokenPrefix: 'TF'});7172 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});73 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');61 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);74 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 100);62 await rft.approve(alice, {Substrate: bob.address}, 7n);75 await transferFromExpectSuccess(63 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);76 reFungibleCollectionId,77 newReFungibleTokenId,64 78 bob,65 await rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 6n);79 alice,80 charlie,66 expect(await rft.getBalance({Substrate: charlie.address})).to.be.equal(6n);81 100,67 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(4n);82 'ReFungible',68 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(1n);83 );84 });69 });857086 it('Should reduce allowance if value is big', async () => {71 itSub('Should reduce allowance if value is big', async ({helper}) => {87 await usingApi(async (api, privateKeyWrapper) => {72 // fungible88 const alice = privateKeyWrapper('//Alice');73 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-4', description: '', tokenPrefix: 'TF'});89 const bob = privateKeyWrapper('//Bob');90 const charlie = privateKeyWrapper('//Charlie');74 await collection.mint(alice, {Substrate: alice.address}, 500000n);917592 // fungible76 await collection.approveTokens(alice, {Substrate: bob.address}, 500000n);93 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});94 const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, {Value: 500000n});77 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(500000n);9596 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 500000n);97 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');78 await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 500000n);98 expect(await getAllowance(api, fungibleCollectionId, alice.address, bob.address, newFungibleTokenId)).to.equal(0n);79 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(0n);99 });100 });80 });10181102 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {82 itSub('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async ({helper}) => {103 const collectionId = await createCollectionExpectSuccess();83 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-5', description: '', tokenPrefix: 'TF'});104 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: true});105 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);84 await collection.setLimits(alice, {ownerCanTransfer: true});10685107 await transferFromExpectSuccess(collectionId, itemId, alice, bob, charlie);86 const nft = await collection.mintToken(alice, {Substrate: bob.address});87 await nft.transferFrom(alice, {Substrate: bob.address}, {Substrate: charlie.address});88 expect(await nft.getOwner()).to.be.deep.equal({Substrate: charlie.address});108 });89 });109});90});11091114 let charlie: IKeyringPair;95 let charlie: IKeyringPair;11596116 before(async () => {97 before(async () => {117 await usingApi(async (api, privateKeyWrapper) => {98 await usingPlaygrounds(async (helper, privateKey) => {118 alice = privateKeyWrapper('//Alice');99 const donor = privateKey('//Alice');119 bob = privateKeyWrapper('//Bob');100 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);120 charlie = privateKeyWrapper('//Charlie');121 });101 });122 });102 });123103124 it('[nft] transferFrom for a collection that does not exist', async () => {104 itSub('transferFrom for a collection that does not exist', async ({helper}) => {125 await usingApi(async (api: ApiPromise) => {105 const collectionId = (1 << 32) - 1;126 const nftCollectionCount = await getCreatedCollectionCount(api);106 await expect(helper.collection.approveToken(alice, collectionId, 0, {Substrate: bob.address}, 1n))127 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);107 .to.be.rejectedWith(/common\.CollectionNotFound/);128129 await transferFromExpectFail(nftCollectionCount + 1, 1, bob, alice, charlie, 1);108 await expect(helper.collection.transferTokenFrom(bob, collectionId, 0, {Substrate: alice.address}, {Substrate: bob.address}, 1n))130 });109 .to.be.rejectedWith(/common\.CollectionNotFound/);131 });110 });132111133 it('[fungible] transferFrom for a collection that does not exist', async () => {112 /* itSub('transferFrom for a collection that was destroyed', async ({helper}) => {134 await usingApi(async (api: ApiPromise) => {135 const fungibleCollectionCount = await getCreatedCollectionCount(api);113 this test copies approve negative test136 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);114 }); */137115138 await transferFromExpectFail(fungibleCollectionCount + 1, 0, bob, alice, charlie, 1);116 /* itSub('transferFrom a token that does not exist', async ({helper}) => {117 this test copies approve negative test118 }); */119120 /* itSub('transferFrom a token that was deleted', async ({helper}) => {121 this test copies approve negative test122 }); */123124 itSub('[nft] transferFrom for not approved address', async ({helper}) => {125 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});126 const nft = await collection.mintToken(alice, {Substrate: alice.address});127128 await expect(nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))129 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);139 });130 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});140 });131 });141132142 it('[refungible] transferFrom for a collection that does not exist', async function() {133 itSub('[fungible] transferFrom for not approved address', async ({helper}) => {143 await requirePallets(this, [Pallets.ReFungible]);134 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});135 await collection.mint(alice, {Substrate: alice.address}, 10n);144136145 await usingApi(async (api: ApiPromise) => {137 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))146 const reFungibleCollectionCount = await getCreatedCollectionCount(api);138 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);139 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);147 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);140 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);141 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);142 });148143149 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, bob, alice, charlie, 1);144 itSub.ifWithPallets('[refungible] transferFrom for not approved address', [Pallets.ReFungible], async({helper}) => {145 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-3', description: '', tokenPrefix: 'TF'});146 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);147148 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))149 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);150 });150 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);151 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);152 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);151 });153 });152154153 /* it('transferFrom for a collection that was destroyed', async () => {155 itSub('[nft] transferFrom incorrect token count', async ({helper}) => {154 await usingApi(async (api: ApiPromise) => {156 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-4', description: '', tokenPrefix: 'TF'});155 this test copies approve negative test157 const nft = await collection.mintToken(alice, {Substrate: alice.address});156 });157 }); */158158159 /* it('transferFrom a token that does not exist', async () => {159 await nft.approve(alice, {Substrate: bob.address});160 await usingApi(async (api: ApiPromise) => {160 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;161 this test copies approve negative test162 });163 }); */164161165 /* it('transferFrom a token that was deleted', async () => {162 await expect(helper.collection.transferTokenFrom(163 bob, 164 collection.collectionId, 166 await usingApi(async (api: ApiPromise) => {165 nft.tokenId, 166 {Substrate: alice.address}, 167 this test copies approve negative test167 {Substrate: charlie.address}, 168 2n,168 });169 )).to.be.rejectedWith(/nonfungible\.NonfungibleItemsHaveNoAmount/);170 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});169 }); */171 });170172171 it('[nft] transferFrom for not approved address', async () => {173 itSub('[fungible] transferFrom incorrect token count', async ({helper}) => {172 const nftCollectionId = await createCollectionExpectSuccess();174 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-5', description: '', tokenPrefix: 'TF'});173 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');175 await collection.mint(alice, {Substrate: alice.address}, 10n);174176175 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);177 await collection.approveTokens(alice, {Substrate: bob.address}, 2n);178 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(2n);179180 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))181 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);182 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);183 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);184 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);176 });185 });177186178 it('[fungible] transferFrom for not approved address', async () => {187 itSub.ifWithPallets('[refungible] transferFrom incorrect token count', [Pallets.ReFungible], async ({helper}) => {179 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});188 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-6', description: '', tokenPrefix: 'TF'});180 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');189 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);190181 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);191 await rft.approve(alice, {Substrate: bob.address}, 5n);192 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(5n);193194 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 7n))195 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);196 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);197 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);198 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);182 });199 });183200184 it('[refungible] transferFrom for not approved address', async function() {201 itSub('[nft] execute transferFrom from account that is not owner of collection', async ({helper}) => {185 await requirePallets(this, [Pallets.ReFungible]);202 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-7', description: '', tokenPrefix: 'TF'});203 const nft = await collection.mintToken(alice, {Substrate: alice.address});186204187 const reFungibleCollectionId = await205 await expect(nft.approve(charlie, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);188 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});189 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');206 expect(await nft.isApproved({Substrate: bob.address})).to.be.false;207190 await transferFromExpectFail(208 await expect(nft.transferFrom(191 reFungibleCollectionId,192 newReFungibleTokenId,193 bob,194 alice,195 charlie,209 charlie,196 1,210 {Substrate: alice.address}, 197 );211 {Substrate: charlie.address},212 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);213 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});198 });214 });199215200 it('[nft] transferFrom incorrect token count', async () => {216 itSub('[fungible] execute transferFrom from account that is not owner of collection', async ({helper}) => {201 const nftCollectionId = await createCollectionExpectSuccess();217 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-8', description: '', tokenPrefix: 'TF'});202 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');203 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);218 await collection.mint(alice, {Substrate: alice.address}, 10000n);204219205 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 2);220 await expect(collection.approveTokens(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);221 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);206 });222 expect(await collection.getApprovedTokens({Substrate: charlie.address}, {Substrate: bob.address})).to.be.eq(0n);207223208 it('[fungible] transferFrom incorrect token count', async () => {224 await expect(collection.transferFrom(225 charlie,209 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});226 {Substrate: alice.address}, 227 {Substrate: charlie.address},228 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);210 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');229 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10000n);211 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);230 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);212 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 2);231 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);213 });232 });214233215 it('[refungible] transferFrom incorrect token count', async function() {234 itSub.ifWithPallets('[refungible] execute transferFrom from account that is not owner of collection', [Pallets.ReFungible], async ({helper}) => {216 await requirePallets(this, [Pallets.ReFungible]);235 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-9', description: '', tokenPrefix: 'TF'});236 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10000n);217237218 const reFungibleCollectionId = await238 await expect(rft.approve(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);219 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});220 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');239 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);221 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);240 expect(await rft.getApprovedPieces({Substrate: charlie.address}, {Substrate: bob.address})).to.be.eq(0n);241222 await transferFromExpectFail(242 await expect(rft.transferFrom(223 reFungibleCollectionId,224 newReFungibleTokenId,225 bob,226 alice,227 charlie,243 charlie,228 2,244 {Substrate: alice.address}, 229 );245 {Substrate: charlie.address},246 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);247 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10000n);248 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);249 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);230 });250 });231251232 it('[nft] execute transferFrom from account that is not owner of collection', async () => {252 itSub('transferFrom burnt token before approve NFT', async ({helper}) => {233 await usingApi(async (api, privateKeyWrapper) => {234 const dave = privateKeyWrapper('//Dave');253 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-10', description: '', tokenPrefix: 'TF'});235 const nftCollectionId = await createCollectionExpectSuccess();236 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');237 try {254 await collection.setLimits(alice, {ownerCanTransfer: true});238 await approveExpectFail(nftCollectionId, newNftTokenId, dave, bob);239 await transferFromExpectFail(nftCollectionId, newNftTokenId, dave, alice, charlie, 1);255 const nft = await collection.mintToken(alice, {Substrate: alice.address});240 } catch (e) {241 // tslint:disable-next-line:no-unused-expression242 expect(e).to.be.exist;243 }244256245 // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);257 await nft.burn(alice);258 await expect(nft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.TokenNotFound/);259260 await expect(nft.transferFrom(261 bob,262 {Substrate: alice.address}, 246 });263 {Substrate: charlie.address},264 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);247 });265 });248266249 it('[fungible] execute transferFrom from account that is not owner of collection', async () => {267 itSub('transferFrom burnt token before approve Fungible', async ({helper}) => {250 await usingApi(async (api, privateKeyWrapper) => {268 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-11', description: '', tokenPrefix: 'TF'});269 await collection.setLimits(alice, {ownerCanTransfer: true});251 const dave = privateKeyWrapper('//Dave');270 await collection.mint(alice, {Substrate: alice.address}, 10n);252271253 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});272 await collection.burnTokens(alice, 10n);254 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');273 await expect(collection.approveTokens(alice, {Substrate: bob.address})).to.be.not.rejected;255 try {274256 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, dave, bob);275 await expect(collection.transferFrom(257 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, dave, alice, charlie, 1);276 alice,258 } catch (e) {277 {Substrate: alice.address}, 259 // tslint:disable-next-line:no-unused-expression278 {Substrate: charlie.address},260 expect(e).to.be.exist;279 )).to.be.rejectedWith(/common\.TokenValueTooLow/);261 }262 });263 });280 });264281265 it('[refungible] execute transferFrom from account that is not owner of collection', async function() {282 itSub.ifWithPallets('transferFrom burnt token before approve ReFungible', [Pallets.ReFungible], async ({helper}) => {283 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-12', description: '', tokenPrefix: 'TF'});284 await collection.setLimits(alice, {ownerCanTransfer: true});266 await requirePallets(this, [Pallets.ReFungible]);285 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);267286268 await usingApi(async (api, privateKeyWrapper) => {287 await rft.burn(alice, 10n);269 const dave = privateKeyWrapper('//Dave');270 const reFungibleCollectionId = await288 await expect(rft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);271 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});272 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');273 try {274 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, dave, bob);275 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, dave, alice, charlie, 1);276 } catch (e) {277 // tslint:disable-next-line:no-unused-expression278 expect(e).to.be.exist;279 }280 });281 });282 it('transferFrom burnt token before approve NFT', async () => {283 await usingApi(async () => {284 // nft285 const nftCollectionId = await createCollectionExpectSuccess();286 await setCollectionLimitsExpectSuccess(alice, nftCollectionId, {ownerCanTransfer: true});287 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');288 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);289 await approveExpectFail(nftCollectionId, newNftTokenId, alice, bob);290 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);291 });292 });293 it('transferFrom burnt token before approve Fungible', async () => {294 await usingApi(async () => {295 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});296 await setCollectionLimitsExpectSuccess(alice, fungibleCollectionId, {ownerCanTransfer: true});297 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');298 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);299 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);300 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);301289302 });290 await expect(rft.transferFrom(291 alice,292 {Substrate: alice.address}, 293 {Substrate: charlie.address},294 )).to.be.rejectedWith(/common\.TokenValueTooLow/);303 });295 });304 it('transferFrom burnt token before approve ReFungible', async function() {305 await requirePallets(this, [Pallets.ReFungible]);306296307 await usingApi(async () => {297 itSub('transferFrom burnt token after approve NFT', async ({helper}) => {308 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});298 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-13', description: '', tokenPrefix: 'TF'});309 await setCollectionLimitsExpectSuccess(alice, reFungibleCollectionId, {ownerCanTransfer: true});310 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');299 const nft = await collection.mintToken(alice, {Substrate: alice.address});311 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);312 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, alice, bob);313 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice, charlie, 1);314300315 });301 await nft.approve(alice, {Substrate: bob.address});316 });302 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;317303318 it('transferFrom burnt token after approve NFT', async () => {304 await nft.burn(alice);319 await usingApi(async () => {305320 // nft321 const nftCollectionId = await createCollectionExpectSuccess();306 await expect(nft.transferFrom(322 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');307 bob,323 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);308 {Substrate: alice.address}, 324 await burnItemExpectSuccess(alice, nftCollectionId, newNftTokenId, 1);325 await transferFromExpectFail(nftCollectionId, newNftTokenId, bob, alice, charlie, 1);309 {Substrate: charlie.address},326 });310 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);327 });311 });328 it('transferFrom burnt token after approve Fungible', async () => {329 await usingApi(async () => {330 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});331 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');332 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);333 await burnItemExpectSuccess(alice, fungibleCollectionId, newFungibleTokenId, 10);334 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 1);335312336 });313 itSub('transferFrom burnt token after approve Fungible', async ({helper}) => {314 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-14', description: '', tokenPrefix: 'TF'});315 await collection.mint(alice, {Substrate: alice.address}, 10n);316317 await collection.approveTokens(alice, {Substrate: bob.address});318 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(1n);319320 await collection.burnTokens(alice, 10n);321322 await expect(collection.transferFrom(323 bob,324 {Substrate: alice.address}, 325 {Substrate: charlie.address},326 )).to.be.rejectedWith(/common\.TokenValueTooLow/);337 });327 });338 it('transferFrom burnt token after approve ReFungible', async function() {339 await requirePallets(this, [Pallets.ReFungible]);340328341 await usingApi(async () => {329 itSub.ifWithPallets('transferFrom burnt token after approve ReFungible', [Pallets.ReFungible], async ({helper}) => {342 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});330 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-15', description: '', tokenPrefix: 'TF'});343 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');344 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);345 await burnItemExpectSuccess(alice, reFungibleCollectionId, newReFungibleTokenId, 100);331 const rft = await collection.mintToken(alice, {Substrate: alice.address}, 10n);346 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice, charlie, 1);347332348 });333 await rft.approve(alice, {Substrate: bob.address}, 10n);334 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(10n);335336 await rft.burn(alice, 10n);337338 await expect(rft.transferFrom(339 bob,340 {Substrate: alice.address}, 341 {Substrate: charlie.address},342 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);349 });343 });350344351 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {345 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {352 const collectionId = await createCollectionExpectSuccess();346 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-16', description: '', tokenPrefix: 'TF'});353 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);354 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});347 const nft = await collection.mintToken(alice, {Substrate: bob.address});355348356 await transferFromExpectFail(collectionId, itemId, alice, bob, charlie);349 await collection.setLimits(alice, {ownerCanTransfer: false});350351 await expect(nft.transferFrom(352 alice,353 {Substrate: bob.address}, 354 {Substrate: charlie.address},355 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);357 });356 });358});357});359358tests/src/util/playgrounds/unique.tsdiffbeforeafterboth2128 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj);2128 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj);2129 }2129 }21302131 async enableCertainPermissions(signer: TSigner, accessMode: 'AllowList' | 'Normal' | undefined = 'AllowList', mintMode: boolean | undefined = true) {2132 return await this.setPermissions(signer, {access: accessMode, mintMode: mintMode});2133 }213421302135 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId) {2131 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId) {2136 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj);2132 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj);tests/src/xcmTransfer.test.tsdiffbeforeafterboth33const KARURA_PORT = '9946';33const KARURA_PORT = '9946';34const TRANSFER_AMOUNT = 2000000000000000000000000n;34const TRANSFER_AMOUNT = 2000000000000000000000000n;353536// todo:playgrounds refit when XCM drops36describe.skip('Integration test: Exchanging QTZ with Karura', () => {37describe.skip('Integration test: Exchanging QTZ with Karura', () => {37 let alice: IKeyringPair;38 let alice: IKeyringPair;3839