difftreelog
Add checks to mintCross tests
in: master
3 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth79 expect(event.returnValues.value).to.equal('100');79 expect(event.returnValues.value).to.equal('100');80 });80 });81 81 82 82 [83 'substrate' as const,84 'ethereum' as const,85 ].map(testCase => {83 itEth('Can perform mintCross()', async ({helper}) => {86 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {87 // 1. Create receiver depending on the test case:88 const receiverEth = helper.eth.createAccount();89 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);90 const receiverSub = owner;84 const receiverCross = helper.ethCrossAccount.fromKeyringPair(owner);91 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(owner);9285 const ethOwner = await helper.eth.createAccountWithBalance(donor);93 const ethOwner = await helper.eth.createAccountWithBalance(donor);86 const collection = await helper.ft.mintCollection(alice);94 const collection = await helper.ft.mintCollection(alice);87 await collection.addAdmin(alice, {Ethereum: ethOwner});95 await collection.addAdmin(alice, {Ethereum: ethOwner});8896 89 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);97 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);90 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);98 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);9199 100 // 2. Mint tokens:92 const result = await contract.methods.mintCross(receiverCross, 100).send();101 const result = await collectionEvm.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, 100).send();93 102 94 const event = result.events.Transfer;103 const event = result.events.Transfer;95 expect(event.address).to.equal(collectionAddress);104 expect(event.address).to.equal(collectionAddress);96 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');105 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');97 expect(event.returnValues.to).to.equal(helper.address.substrateToEth(owner.address));106 expect(event.returnValues.to).to.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(receiverSub.address));98 expect(event.returnValues.value).to.equal('100');107 expect(event.returnValues.value).to.equal('100');108109 // 3. Get balance depending on the test case:110 let balance;111 if (testCase === 'ethereum') balance = await collection.getBalance({Ethereum: receiverEth});112 else if (testCase === 'substrate') balance = await collection.getBalance({Substrate: receiverSub.address});113 // 3.1 Check balance:114 expect(balance).to.eq(100n);99 });115 });116 });100117101 itEth('Can perform mintBulk()', async ({helper}) => {118 itEth('Can perform mintBulk()', async ({helper}) => {102 const owner = await helper.eth.createAccountWithBalance(donor);119 const owner = await helper.eth.createAccountWithBalance(donor);tests/src/eth/nonFungible.test.tsdiffbeforeafterboth175 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);175 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);176 });176 });177 177 178 // TODO combine all minting tests in one place179 [180 'substrate' as const,181 'ethereum' as const,182 ].map(testCase => {178 itEth('Can perform mintCross()', async ({helper}) => {183 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {179 const caller = await helper.eth.createAccountWithBalance(donor);184 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);185186 const receiverEth = helper.eth.createAccount();187 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);188 const receiverSub = bob;180 const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);189 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);190191 // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);181 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });192 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });182 const permissions: ITokenPropertyPermission[] = properties193 const permissions: ITokenPropertyPermission[] = properties183 .map(p => {194 .map(p => {195 tokenPrefix: 'ethp',206 tokenPrefix: 'ethp',196 tokenPropertyPermissions: permissions,207 tokenPropertyPermissions: permissions,197 });208 });198 await collection.addAdmin(minter, {Ethereum: caller});209 await collection.addAdmin(minter, {Ethereum: collectionAdmin});199 210 200 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);211 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);201 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller, true);212 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);202 let expectedTokenId = await contract.methods.nextTokenId().call();213 let expectedTokenId = await contract.methods.nextTokenId().call();203 let result = await contract.methods.mintCross(receiverCross, []).send();214 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();204 let tokenId = result.events.Transfer.returnValues.tokenId;215 let tokenId = result.events.Transfer.returnValues.tokenId;205 expect(tokenId).to.be.equal(expectedTokenId);216 expect(tokenId).to.be.equal(expectedTokenId);206217207 let event = result.events.Transfer;218 let event = result.events.Transfer;208 expect(event.address).to.be.equal(collectionAddress);219 expect(event.address).to.be.equal(collectionAddress);209 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');220 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');210 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));221 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));211 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);222 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);212 223 213 expectedTokenId = await contract.methods.nextTokenId().call();224 expectedTokenId = await contract.methods.nextTokenId().call();214 result = await contract.methods.mintCross(receiverCross, properties).send();225 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();215 event = result.events.Transfer;226 event = result.events.Transfer;216 expect(event.address).to.be.equal(collectionAddress);227 expect(event.address).to.be.equal(collectionAddress);217 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');228 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');218 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));229 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));219 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);230 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);220 231 221 tokenId = result.events.Transfer.returnValues.tokenId;232 tokenId = result.events.Transfer.returnValues.tokenId;225 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties236 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties226 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));237 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));238 239 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))240 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});227 });241 });228 242 });243244 itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {245 const nonOwner = await helper.eth.createAccountWithBalance(donor);246 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);247248 const collection = await helper.nft.mintCollection(minter);249 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);250 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');251252 await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))253 .to.be.rejectedWith('PublicMintingNotAllowed');254 });255 229 //TODO: CORE-302 add eth methods256 //TODO: CORE-302 add eth methods230 itEth.skip('Can perform mintBulk()', async ({helper}) => {257 itEth.skip('Can perform mintBulk()', async ({helper}) => {tests/src/eth/reFungible.test.tsdiffbeforeafterboth137 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');137 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');138 });138 });139 139 140 [141 'substrate' as const,142 'ethereum' as const,143 ].map(testCase => {140 itEth('Can perform mintCross()', async ({helper}) => {144 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {141 const caller = await helper.eth.createAccountWithBalance(donor);145 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);146147 const receiverEth = helper.eth.createAccount();148 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);149 const receiverSub = bob;142 const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);150 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);151143 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });152 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });144 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,153 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,150 tokenPrefix: 'ethp',159 tokenPrefix: 'ethp',151 tokenPropertyPermissions: permissions,160 tokenPropertyPermissions: permissions,152 });161 });153 await collection.addAdmin(minter, {Ethereum: caller});162 await collection.addAdmin(minter, {Ethereum: collectionAdmin});154 163 155 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);164 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);156 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller, true);165 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);157 let expectedTokenId = await contract.methods.nextTokenId().call();166 let expectedTokenId = await contract.methods.nextTokenId().call();158 let result = await contract.methods.mintCross(receiverCross, []).send();167 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();159 let tokenId = result.events.Transfer.returnValues.tokenId;168 let tokenId = result.events.Transfer.returnValues.tokenId;160 expect(tokenId).to.be.equal(expectedTokenId);169 expect(tokenId).to.be.equal(expectedTokenId);161170162 let event = result.events.Transfer;171 let event = result.events.Transfer;163 expect(event.address).to.be.equal(collectionAddress);172 expect(event.address).to.be.equal(collectionAddress);164 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');173 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');165 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));174 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));166 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);175 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);167 176 168 expectedTokenId = await contract.methods.nextTokenId().call();177 expectedTokenId = await contract.methods.nextTokenId().call();169 result = await contract.methods.mintCross(receiverCross, properties).send();178 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();170 event = result.events.Transfer;179 event = result.events.Transfer;171 expect(event.address).to.be.equal(collectionAddress);180 expect(event.address).to.be.equal(collectionAddress);172 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');181 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');173 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));182 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));174 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);183 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);175 184 176 tokenId = result.events.Transfer.returnValues.tokenId;185 tokenId = result.events.Transfer.returnValues.tokenId;180 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties189 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties181 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));190 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));191192 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))193 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});182 });194 });195 });183196184 itEth.skip('Can perform mintBulk()', async ({helper}) => {197 itEth.skip('Can perform mintBulk()', async ({helper}) => {185 const owner = await helper.eth.createAccountWithBalance(donor);198 const owner = await helper.eth.createAccountWithBalance(donor);