difftreelog
fix collectionSponsoringTests
in: master
1 file changed
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth1import {collectionIdToAddress, normalizeEvents} from './util/helpers';1import {usingPlaygrounds} from './../util/playgrounds/index';2import {evmToAddress} from '@polkadot/util-crypto';2import {IKeyringPair} from '@polkadot/types/types';3import {normalizeEvents} from './util/helpers';3import {itEth, expect} from '../eth/util/playgrounds';4import {itEth, expect} from '../eth/util/playgrounds';455describe('evm collection sponsoring', () => {6describe('evm collection sponsoring', () => {7 let donor: IKeyringPair;8 let alice: IKeyringPair;9 let nominal: bigint;1011 before(async () => {12 await usingPlaygrounds(async (helper, privateKey) => {13 donor = privateKey('//Alice');14 nominal = helper.balance.getOneTokenNominal();15 });16 });1718 beforeEach(async () => {19 await usingPlaygrounds(async (helper) => {20 [alice] = await helper.arrange.createAccounts([1000n], donor);21 });22 });236 itEth('sponsors mint transactions', async ({helper, privateKey}) => {24 itEth('sponsors mint transactions', async ({helper}) => {7 const alice = privateKey('//Alice');89 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});25 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});10 await collection.setSponsor(alice, alice.address);26 await collection.setSponsor(alice, alice.address);13 const minter = helper.eth.createAccount();29 const minter = helper.eth.createAccount();14 expect(await helper.balance.getEthereum(minter)).to.equal(0n);30 expect(await helper.balance.getEthereum(minter)).to.equal(0n);153116 const address = helper.ethAddress.fromCollectionId(collection.collectionId);32 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);17 const contract = helper.ethNativeContract.collection(address, 'nft', minter);33 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);183419 await collection.addToAllowList(alice, {Ethereum: minter});35 await collection.addToAllowList(alice, {Ethereum: minter});203624 const events = normalizeEvents(result.events);40 const events = normalizeEvents(result.events);25 expect(events).to.be.deep.equal([41 expect(events).to.be.deep.equal([26 {42 {27 address,43 address: collectionAddress,28 event: 'Transfer',44 event: 'Transfer',29 args: {45 args: {30 from: '0x0000000000000000000000000000000000000000',46 from: '0x0000000000000000000000000000000000000000',56 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);72 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);57 // });73 // });587459 itEth('Remove sponsor', async ({helper, privateKey}) => {75 itEth('Remove sponsor', async ({helper}) => {60 const alice = privateKey('//Alice');6162 const owner = await helper.eth.createAccountWithBalance(alice);76 const owner = await helper.eth.createAccountWithBalance(donor);63 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);77 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);647865 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();79 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});66 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);80 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);67 const sponsor = await helper.eth.createAccountWithBalance(alice);81 const sponsor = await helper.eth.createAccountWithBalance(donor);68 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);82 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);698370 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;84 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;81 });95 });829683 itEth('Sponsoring collection from evm address via access list', async ({helper, privateKey}) => {97 itEth('Sponsoring collection from evm address via access list', async ({helper, privateKey}) => {84 const alice = privateKey('//Alice');8586 const owner = await helper.eth.createAccountWithBalance(alice);98 const owner = await helper.eth.createAccountWithBalance(donor);87 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);99 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);8810089 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();101 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});90 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);102 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);91 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);103 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);92 const collection = helper.nft.getCollectionObject(collectionId);104 const collection = helper.nft.getCollectionObject(collectionId);93 const sponsor = await helper.eth.createAccountWithBalance(alice);105 const sponsor = await helper.eth.createAccountWithBalance(donor);94 const collectionEvm = await helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);106 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);9510796 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});108 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});97 let collectionData = (await collection.getData())!;109 let collectionData = (await collection.getData())!;98 const ss58Format = helper.chain.getChainProperties().ss58Format;110 const ss58Format = helper.chain.getChainProperties().ss58Format;99 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));111 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));100 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');112 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');101113102 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});114 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});103 collectionData = (await collection.getData())!;115 collectionData = (await collection.getData())!;104 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));116 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));105117106 const user = helper.eth.createAccount();118 const user = helper.eth.createAccount();107 const nextTokenId = await collectionEvm.methods.nextTokenId().call();119 const nextTokenId = await collectionEvm.methods.nextTokenId().call();119 expect(newPermissions.mintMode).to.be.true;131 expect(newPermissions.mintMode).to.be.true;120 expect(newPermissions.access).to.be.equal('AllowList');132 expect(newPermissions.access).to.be.equal('AllowList');121133122 const ownerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));134 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));123 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));135 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));124136125 {137 {126 const nextTokenId = await collectionEvm.methods.nextTokenId().call();138 const nextTokenId = await collectionEvm.methods.nextTokenId().call();210 // });222 // });211223212 itEth('Check that transaction via EVM spend money from sponsor address', async ({helper, privateKey}) => {224 itEth('Check that transaction via EVM spend money from sponsor address', async ({helper, privateKey}) => {213 const alice = privateKey('//Alice');214215 const owner = await helper.eth.createAccountWithBalance(alice);225 const owner = await helper.eth.createAccountWithBalance(donor);216 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);226 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);217227218 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();228 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});219 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);229 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);220 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);230 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);221 const collection = helper.nft.getCollectionObject(collectionId);231 const collection = helper.nft.getCollectionObject(collectionId);222 const sponsor = await helper.eth.createAccountWithBalance(alice);232 const sponsor = await helper.eth.createAccountWithBalance(donor);223 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);233 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);224234225 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();235 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();226 let collectionData = (await collection.getData())!;236 let collectionData = (await collection.getData())!;227 const ss58Format = helper.chain.getChainProperties().ss58Format;228 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));237 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));229 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');238 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');230239231 const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);240 const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);232 await sponsorCollection.methods.confirmCollectionSponsorship().send();241 await sponsorCollection.methods.confirmCollectionSponsorship().send();233 collectionData = (await collection.getData())!;242 collectionData = (await collection.getData())!;234 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));243 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));235244236 const user = helper.eth.createAccount();245 const user = helper.eth.createAccount();237 await collectionEvm.methods.addCollectionAdmin(user).send();246 await collectionEvm.methods.addCollectionAdmin(user).send();238 247 239 const ownerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));248 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));240 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));249 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));241250242 const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);251 const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);243 const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();252 const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();249 ).send();258 ).send();250259251 const events = normalizeEvents(result.events);260 const events = normalizeEvents(result.events);252 const address = collectionIdToAddress(collectionId);261 const address = helper.ethAddress.fromCollectionId(collectionId);253262254 expect(events).to.be.deep.equal([263 expect(events).to.be.deep.equal([255 {264 {