difftreelog
Add transferCross tests
in: master
3 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth232 });232 });233233234 itEth('Can perform transferCross()', async ({helper}) => {234 itEth('Can perform transferCross()', async ({helper}) => {235 const owner = await helper.eth.createAccountWithBalance(donor);235 const sender = await helper.eth.createAccountWithBalance(donor);236 const receiver = await helper.eth.createAccountWithBalance(donor);236 const receiverEth = await helper.eth.createAccountWithBalance(donor);237 const to = helper.ethCrossAccount.fromAddress(receiver);237 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);238 const toSubstrate = helper.ethCrossAccount.fromKeyringPair(donor);238 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);239 const collection = await helper.ft.mintCollection(alice);239 const collection = await helper.ft.mintCollection(alice);240 await collection.mint(alice, 200n, {Ethereum: owner});240 await collection.mint(alice, 200n, {Ethereum: sender});241241242 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);242 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);243 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);243 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);244244245 {245 {246 // Can transferCross to ethereum address:246 const result = await contract.methods.transferCross(to, 50).send({from: owner});247 const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});247 248 // Check events:248 const event = result.events.Transfer;249 const event = result.events.Transfer;249 expect(event.address).to.be.equal(collectionAddress);250 expect(event.address).to.be.equal(collectionAddress);250 expect(event.returnValues.from).to.be.equal(owner);251 expect(event.returnValues.from).to.be.equal(sender);251 expect(event.returnValues.to).to.be.equal(receiver);252 expect(event.returnValues.to).to.be.equal(receiverEth);252 expect(event.returnValues.value).to.be.equal('50');253 expect(event.returnValues.value).to.be.equal('50');254 // Sender's balance decreased:255 const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();256 expect(+ownerBalance).to.equal(150);257 // Receiver's balance increased:258 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();259 expect(+receiverBalance).to.equal(50);253 }260 }254261 255 {262 {256 const balance = await contract.methods.balanceOf(owner).call();263 // Can transferCross to substrate address:257 expect(+balance).to.equal(150);258 }259260 {264 const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});261 const balance = await contract.methods.balanceOf(receiver).call();265 // Check events:262 expect(+balance).to.equal(50);263 }264 265 {266 const result = await contract.methods.transferCross(toSubstrate, 50).send({from: owner});267 268 const event = result.events.Transfer;266 const event = result.events.Transfer;269 expect(event.address).to.be.equal(collectionAddress);267 expect(event.address).to.be.equal(collectionAddress);270 expect(event.returnValues.from).to.be.equal(owner);268 expect(event.returnValues.from).to.be.equal(sender);271 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));269 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));272 expect(event.returnValues.value).to.be.equal('50');270 expect(event.returnValues.value).to.be.equal('50');273 }271 // Sender's balance decreased:274275 {276 const balance = await collection.getBalance({Ethereum: owner});272 const senderBalance = await collection.getBalance({Ethereum: sender});277 expect(balance).to.equal(100n);273 expect(senderBalance).to.equal(100n);278 }274 // Receiver's balance increased:279280 {281 const balance = await collection.getBalance({Substrate: donor.address});275 const balance = await collection.getBalance({Substrate: donor.address});282 expect(balance).to.equal(50n);276 expect(balance).to.equal(50n);283 }277 }284 285 });278 });286 279 tests/src/eth/nonFungible.test.tsdiffbeforeafterboth252 itEth('Can perform burnFromCross()', async ({helper}) => {252 itEth('Can perform burnFromCross()', async ({helper}) => {253 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});253 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});254 const ownerSub = bob;254 const ownerSub = bob;255 const ownerCross = helper.ethCrossAccount.fromKeyringPair(ownerSub);255 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);256 const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);256 const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);257 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);257258258 const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);259 const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);259 const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);260 const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);269 await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});270 await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});270271271 // can burnFromCross:272 // can burnFromCross:272 const result1 = await collectionEvm.methods.burnFromCross(ownerCross, token1.tokenId).send({from: burnerEth});273 const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});273 // FIXME Error No Permission?:274 const result2 = await collectionEvm.methods.burnFromCross(ownerCross, token2.tokenId).send({from: burnerEth});274 const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});275 const events1 = result1.events.Transfer;275 const events1 = result1.events.Transfer;276 const events2 = result2.events.Transfer;276 const events2 = result2.events.Transfer;277277278 // Check events for burnFromCross (substrate and ethereum):278 [[events1, token1], [events2, token2]].map(burnEvents => {279 [280 [events1, token1, helper.address.substrateToEth(ownerSub.address)], 281 [events2, token2, ownerEth],282 ].map(burnData => {279 expect(burnEvents[0]).to.be.like({283 expect(burnData[0]).to.be.like({280 address: collectionAddress,284 address: collectionAddress,281 event: 'Transfer',285 event: 'Transfer',282 returnValues: {286 returnValues: {283 from: helper.address.substrateToEth(ownerSub.address),287 from: burnData[2],284 to: '0x0000000000000000000000000000000000000000',288 to: '0x0000000000000000000000000000000000000000',285 tokenId: burnEvents[1].tokenId.toString(),289 tokenId: burnData[1].tokenId.toString(),286 },290 },287 });291 });288 });292 });341345342 itEth('Can reaffirm approved address', async ({helper}) => {346 itEth('Can reaffirm approved address', async ({helper}) => {343 const owner = await helper.eth.createAccountWithBalance(donor, 100n);347 const owner = await helper.eth.createAccountWithBalance(donor, 100n);348 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);344 const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);349 const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);345 const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);350 const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);346 const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);351 const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);358 // receiver2 can transferFrom:363 // receiver2 can transferFrom:359 await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});364 await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});360365361 // can set approved address to zero address:366 // can set approved address to self address to remove approval:362 await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});367 await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});363364 // FIXME how to remove approval?:365 await collectionEvm.methods.approveCross({eth: '0x0000000000000000000000000000000000000000', sub: '0'}, token2.tokenId).call({from: owner});368 await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});366 await collectionEvm.methods.approve('0x0000000000000000000000000000000000000000', token2.tokenId).call({from: owner});367369368 // receiver1 cannot transfer token anymore:370 // receiver1 cannot transfer token anymore:369 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;371 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;469 itEth('Can perform transferCross()', async ({helper}) => {471 itEth('Can perform transferCross()', async ({helper}) => {470 const collection = await helper.nft.mintCollection(minter, {});472 const collection = await helper.nft.mintCollection(minter, {});471 const owner = await helper.eth.createAccountWithBalance(donor);473 const owner = await helper.eth.createAccountWithBalance(donor);472 const receiver = await helper.eth.createAccountWithBalance(donor);474 const receiverEth = await helper.eth.createAccountWithBalance(donor);473 const to = helper.ethCrossAccount.fromAddress(receiver);475 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);474 const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);476 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);475 477 476 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});478 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});477479478 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);480 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);479 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);481 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);480482481 {483 {482 const result = await contract.methods.transferCross(to, tokenId).send({from: owner});484 // Can transferCross to ethereum address:483485 const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});486 // Check events:484 const event = result.events.Transfer;487 const event = result.events.Transfer;485 expect(event.address).to.be.equal(collectionAddress);488 expect(event.address).to.be.equal(collectionAddress);486 expect(event.returnValues.from).to.be.equal(owner);489 expect(event.returnValues.from).to.be.equal(owner);487 expect(event.returnValues.to).to.be.equal(receiver);490 expect(event.returnValues.to).to.be.equal(receiverEth);488 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);491 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);489 }492 490493 // owner has balance = 0:491 {492 const balance = await contract.methods.balanceOf(owner).call();494 const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();493 expect(+balance).to.equal(0);495 expect(+ownerBalance).to.equal(0);494 }496 // receiver owns token:495496 {497 const balance = await contract.methods.balanceOf(receiver).call();497 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();498 expect(+balance).to.equal(1);498 expect(+receiverBalance).to.equal(1);499 }500 501 {502 const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});499 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});503 500 }504501 502 {503 // Can transferCross to substrate address:504 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});505 // Check events:505 const event = substrateResult.events.Transfer;506 const event = substrateResult.events.Transfer;506 expect(event.address).to.be.equal(collectionAddress);507 expect(event.address).to.be.equal(collectionAddress);507 expect(event.returnValues.from).to.be.equal(receiver);508 expect(event.returnValues.from).to.be.equal(receiverEth);508 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));509 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));509 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);510 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);510 }511 511512 // owner has balance = 0:512 {513 const balance = await contract.methods.balanceOf(receiver).call();513 const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();514 expect(+balance).to.equal(0);514 expect(+ownerBalance).to.equal(0);515 }515 // receiver owns token:516517 {518 const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});516 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});519 expect(balance).to.be.contain(tokenId);517 expect(receiverBalance).to.contain(tokenId);520 }518 }521 });519 });522});520});523521tests/src/eth/reFungible.test.tsdiffbeforeafterboth363 });363 });364 364 365 itEth('Can perform transferCross()', async ({helper}) => {365 itEth('Can perform transferCross()', async ({helper}) => {366 const caller = await helper.eth.createAccountWithBalance(donor);366 const sender = await helper.eth.createAccountWithBalance(donor);367 const receiver = await helper.eth.createAccountWithBalance(donor);367 const receiverEth = await helper.eth.createAccountWithBalance(donor);368 const to = helper.ethCrossAccount.fromAddress(receiver);368 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);369 const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);369 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);370370 const collection = await helper.rft.mintCollection(minter, {});371 const collection = await helper.rft.mintCollection(minter, {});371 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);372 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);372 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);373 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);373374374 const {tokenId} = await collection.mintToken(minter, 1n, {Ethereum: caller});375 const token = await collection.mintToken(minter, 50n, {Ethereum: sender});375376376 {377 {378 // Can transferCross to ethereum address:377 const result = await contract.methods.transferCross(to, tokenId).send({from: caller});379 const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});378380 // Check events:379 const event = result.events.Transfer;381 const event = result.events.Transfer;380 expect(event.address).to.equal(collectionAddress);382 expect(event.address).to.equal(collectionAddress);381 expect(event.returnValues.from).to.equal(caller);383 expect(event.returnValues.from).to.equal(sender);382 expect(event.returnValues.to).to.equal(receiver);384 expect(event.returnValues.to).to.equal(receiverEth);383 expect(event.returnValues.tokenId).to.equal(tokenId.toString());385 expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());386 // Sender's balance decreased:387 const senderBalance = await collectionEvm.methods.balanceOf(sender).call();388 expect(+senderBalance).to.equal(0);389 expect(await token.getBalance({Ethereum: sender})).to.eq(0n);390 // Receiver's balance increased:391 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();392 expect(+receiverBalance).to.equal(1);393 expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);384 }394 }385395 386 {396 {387 const balance = await contract.methods.balanceOf(caller).call();397 // Can transferCross to substrate address:388 expect(+balance).to.equal(0);389 }390391 {398 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});392 const balance = await contract.methods.balanceOf(receiver).call();399 // Check events:393 expect(+balance).to.equal(1);394 }395 396 {397 const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});398 399400 const event = substrateResult.events.Transfer;400 const event = substrateResult.events.Transfer;401 expect(event.address).to.be.equal(collectionAddress);401 expect(event.address).to.be.equal(collectionAddress);402 expect(event.returnValues.from).to.be.equal(receiver);402 expect(event.returnValues.from).to.be.equal(receiverEth);403 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));403 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));404 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);404 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);405 }405 // Sender's balance decreased:406407 {408 const balance = await contract.methods.balanceOf(receiver).call();406 const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();409 expect(+balance).to.equal(0);407 expect(+senderBalance).to.equal(0);410 }408 expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);411409 // Receiver's balance increased:412 {413 const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});410 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});414 expect(balance).to.be.contain(tokenId);411 expect(receiverBalance).to.contain(token.tokenId);415 }412 expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);413 }416 });414 });415416 itEth('Cannot transferCross with invalid params', async ({helper}) => {417 const sender = await helper.eth.createAccountWithBalance(donor);418 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);419420 const collection = await helper.rft.mintCollection(minter, {});421 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);422 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);423424 const {tokenId} = await collection.mintToken(minter, 50n, {Ethereum: sender});425 // FIXME (transaction successful): Cannot transfer token if it does not exist:426 await expect(collectionEvm.methods.transferCross(receiverCrossSub, tokenId + 1).send({from: sender})).to.be.rejected;427 });417428418 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {429 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {419 const caller = await helper.eth.createAccountWithBalance(donor);430 const caller = await helper.eth.createAccountWithBalance(donor);