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

difftreelog

tests(eth-rft): fix double contract event checking

Fahrrader2022-10-24parent: #a848b6b.patch.diff
in: master

1 file changed

modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
after · tests/src/eth/reFungible.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {Pallets, requirePalletsOrSkip} from '../util';18import {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';2021describe('Refungible: Information getting', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728      donor = await privateKey({filename: __filename});29    });30  });3132  itEth('totalSupply', async ({helper}) => {33    const caller = await helper.eth.createAccountWithBalance(donor);34    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');35    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);3637    await contract.methods.mint(caller).send();3839    const totalSupply = await contract.methods.totalSupply().call();40    expect(totalSupply).to.equal('1');41  });4243  itEth('balanceOf', async ({helper}) => {44    const caller = await helper.eth.createAccountWithBalance(donor);45    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');46    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4748    await contract.methods.mint(caller).send();49    await contract.methods.mint(caller).send();50    await contract.methods.mint(caller).send();5152    const balance = await contract.methods.balanceOf(caller).call();53    expect(balance).to.equal('3');54  });5556  itEth('ownerOf', async ({helper}) => {57    const caller = await helper.eth.createAccountWithBalance(donor);58    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');59    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6061    const result = await contract.methods.mint(caller).send();62    const tokenId = result.events.Transfer.returnValues.tokenId;6364    const owner = await contract.methods.ownerOf(tokenId).call();65    expect(owner).to.equal(caller);66  });6768  itEth('ownerOf after burn', async ({helper}) => {69    const caller = await helper.eth.createAccountWithBalance(donor);70    const receiver = helper.eth.createAccount();71    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');72    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);7374    const result = await contract.methods.mint(caller).send();75    const tokenId = result.events.Transfer.returnValues.tokenId;76    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);7778    await tokenContract.methods.repartition(2).send();79    await tokenContract.methods.transfer(receiver, 1).send();8081    await tokenContract.methods.burnFrom(caller, 1).send();8283    const owner = await contract.methods.ownerOf(tokenId).call();84    expect(owner).to.equal(receiver);85  });8687  itEth('ownerOf for partial ownership', async ({helper}) => {88    const caller = await helper.eth.createAccountWithBalance(donor);89    const receiver = helper.eth.createAccount();90    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');91    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9293    const result = await contract.methods.mint(caller).send();94    const tokenId = result.events.Transfer.returnValues.tokenId;95    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);9697    await tokenContract.methods.repartition(2).send();98    await tokenContract.methods.transfer(receiver, 1).send();99100    const owner = await contract.methods.ownerOf(tokenId).call();101    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');102  });103});104105describe('Refungible: Plain calls', () => {106  let donor: IKeyringPair;107108  before(async function() {109    await usingEthPlaygrounds(async (helper, privateKey) => {110      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);111112      donor = await privateKey({filename: __filename});113    });114  });115116  itEth('Can perform mint()', async ({helper}) => {117    const owner = await helper.eth.createAccountWithBalance(donor);118    const receiver = helper.eth.createAccount();119    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');120    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);121122    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();123124    const event = result.events.Transfer;125    expect(event.address).to.equal(collectionAddress);126    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');127    expect(event.returnValues.to).to.equal(receiver);128    const tokenId = event.returnValues.tokenId;129    expect(tokenId).to.be.equal('1');130131    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');132  });133134  itEth.skip('Can perform mintBulk()', async ({helper}) => {135    const owner = await helper.eth.createAccountWithBalance(donor);136    const receiver = helper.eth.createAccount();137    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');138    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);139140    {141      const nextTokenId = await contract.methods.nextTokenId().call();142      expect(nextTokenId).to.be.equal('1');143      const result = await contract.methods.mintBulkWithTokenURI(144        receiver,145        [146          [nextTokenId, 'Test URI 0'],147          [+nextTokenId + 1, 'Test URI 1'],148          [+nextTokenId + 2, 'Test URI 2'],149        ],150      ).send();151152      const events = result.events.Transfer;153      for (let i = 0; i < 2; i++) {154        const event = events[i];155        expect(event.address).to.equal(collectionAddress);156        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');157        expect(event.returnValues.to).to.equal(receiver);158        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));159      }160161      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');162      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');163      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');164    }165  });166167  itEth('Can perform burn()', async ({helper}) => {168    const caller = await helper.eth.createAccountWithBalance(donor);169    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');170    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);171172    const result = await contract.methods.mint(caller).send();173    const tokenId = result.events.Transfer.returnValues.tokenId;174    {175      const result = await contract.methods.burn(tokenId).send();176      const event = result.events.Transfer;177      expect(event.address).to.equal(collectionAddress);178      expect(event.returnValues.from).to.equal(caller);179      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');180      expect(event.returnValues.tokenId).to.equal(tokenId.toString());181    }182  });183184  itEth('Can perform transferFrom()', async ({helper}) => {185    const caller = await helper.eth.createAccountWithBalance(donor);186    const receiver = helper.eth.createAccount();187    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');188    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);189190    const result = await contract.methods.mint(caller).send();191    const tokenId = result.events.Transfer.returnValues.tokenId;192193    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);194195    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);196    await tokenContract.methods.repartition(15).send();197198    {199      const tokenEvents: any = [];200      tokenContract.events.allEvents((_: any, event: any) => {201        tokenEvents.push(event);202      });203      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();204      if (tokenEvents.length == 0) await helper.wait.newBlocks(1);205206      let event = result.events.Transfer;207      expect(event.address).to.equal(collectionAddress);208      expect(event.returnValues.from).to.equal(caller);209      expect(event.returnValues.to).to.equal(receiver);210      expect(event.returnValues.tokenId).to.equal(tokenId.toString());211212      event = tokenEvents[0];213      expect(event.address).to.equal(tokenAddress);214      expect(event.returnValues.from).to.equal(caller);215      expect(event.returnValues.to).to.equal(receiver);216      expect(event.returnValues.value).to.equal('15');217    }218219    {220      const balance = await contract.methods.balanceOf(receiver).call();221      expect(+balance).to.equal(1);222    }223224    {225      const balance = await contract.methods.balanceOf(caller).call();226      expect(+balance).to.equal(0);227    }228  });229230  itEth('Can perform transfer()', async ({helper}) => {231    const caller = await helper.eth.createAccountWithBalance(donor);232    const receiver = helper.eth.createAccount();233    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');234    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);235236    const result = await contract.methods.mint(caller).send();237    const tokenId = result.events.Transfer.returnValues.tokenId;238239    {240      const result = await contract.methods.transfer(receiver, tokenId).send();241242      const event = result.events.Transfer;243      expect(event.address).to.equal(collectionAddress);244      expect(event.returnValues.from).to.equal(caller);245      expect(event.returnValues.to).to.equal(receiver);246      expect(event.returnValues.tokenId).to.equal(tokenId.toString());247    }248249    {250      const balance = await contract.methods.balanceOf(caller).call();251      expect(+balance).to.equal(0);252    }253254    {255      const balance = await contract.methods.balanceOf(receiver).call();256      expect(+balance).to.equal(1);257    }258  });259260  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {261    const caller = await helper.eth.createAccountWithBalance(donor);262    const receiver = helper.eth.createAccount();263    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');264    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);265266    const result = await contract.methods.mint(caller).send();267    const tokenId = result.events.Transfer.returnValues.tokenId;268269    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);270271    await tokenContract.methods.repartition(2).send();272    await tokenContract.methods.transfer(receiver, 1).send();273274    const events: any = [];275    contract.events.allEvents((_: any, event: any) => {276      events.push(event);277    });278279    await tokenContract.methods.transfer(receiver, 1).send();280    if (events.length == 0) await helper.wait.newBlocks(1);281    const event = events[0];282283    expect(event.address).to.equal(collectionAddress);284    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');285    expect(event.returnValues.to).to.equal(receiver);286    expect(event.returnValues.tokenId).to.equal(tokenId.toString());287  });288289  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {290    const caller = await helper.eth.createAccountWithBalance(donor);291    const receiver = helper.eth.createAccount();292    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');293    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);294295    const result = await contract.methods.mint(caller).send();296    const tokenId = result.events.Transfer.returnValues.tokenId;297298    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);299300    await tokenContract.methods.repartition(2).send();301302    const events: any = [];303    contract.events.allEvents((_: any, event: any) => {304      events.push(event);305    });306307    await tokenContract.methods.transfer(receiver, 1).send();308    if (events.length == 0) await helper.wait.newBlocks(1);309    const event = events[0];310311    expect(event.address).to.equal(collectionAddress);312    expect(event.returnValues.from).to.equal(caller);313    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');314    expect(event.returnValues.tokenId).to.equal(tokenId.toString());315  });316});317318describe('RFT: Fees', () => {319  let donor: IKeyringPair;320321  before(async function() {322    await usingEthPlaygrounds(async (helper, privateKey) => {323      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);324325      donor = await privateKey({filename: __filename});326    });327  });328329  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {330    const caller = await helper.eth.createAccountWithBalance(donor);331    const receiver = helper.eth.createAccount();332    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');333    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);334335    const result = await contract.methods.mint(caller).send();336    const tokenId = result.events.Transfer.returnValues.tokenId;337338    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());339    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));340    expect(cost > 0n);341  });342343  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {344    const caller = await helper.eth.createAccountWithBalance(donor);345    const receiver = helper.eth.createAccount();346    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');347    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);348349    const result = await contract.methods.mint(caller).send();350    const tokenId = result.events.Transfer.returnValues.tokenId;351352    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());353    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));354    expect(cost > 0n);355  });356});357358describe('Common metadata', () => {359  let donor: IKeyringPair;360  let alice: IKeyringPair;361362  before(async function() {363    await usingEthPlaygrounds(async (helper, privateKey) => {364      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);365366      donor = await privateKey({filename: __filename});367      [alice] = await helper.arrange.createAccounts([20n], donor);368    });369  });370371  itEth('Returns collection name', async ({helper}) => {372    const caller = helper.eth.createAccount();373    const tokenPropertyPermissions = [{374      key: 'URI',375      permission: {376        mutable: true,377        collectionAdmin: true,378        tokenOwner: false,379      },380    }];381    const collection = await helper.rft.mintCollection(382      alice,383      {384        name: 'Leviathan',385        tokenPrefix: '11',386        properties: [{key: 'ERC721Metadata', value: '1'}],387        tokenPropertyPermissions,388      },389    );390391    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);392    const name = await contract.methods.name().call();393    expect(name).to.equal('Leviathan');394  });395396  itEth('Returns symbol name', async ({helper}) => {397    const caller = await helper.eth.createAccountWithBalance(donor);398    const tokenPropertyPermissions = [{399      key: 'URI',400      permission: {401        mutable: true,402        collectionAdmin: true,403        tokenOwner: false,404      },405    }];406    const {collectionId} = await helper.rft.mintCollection(407      alice,408      {409        name: 'Leviathan',410        tokenPrefix: '12',411        properties: [{key: 'ERC721Metadata', value: '1'}],412        tokenPropertyPermissions,413      },414    );415416    const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);417    const symbol = await contract.methods.symbol().call();418    expect(symbol).to.equal('12');419  });420});