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

difftreelog

Add permission and zero transfer tests

Max Andreev2022-12-05parent: #98f7ab5.patch.diff
in: master

3 files changed

modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
277 }277 }
278 });278 });
279279
280 itEth('Cannot transferCross() more than have', async ({helper}) => {280 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} incorrect amount`, async ({helper}) => {
281 const sender = await helper.eth.createAccountWithBalance(donor);281 const sender = await helper.eth.createAccountWithBalance(donor);
282 const receiverEth = await helper.eth.createAccountWithBalance(donor);282 const receiverEth = await helper.eth.createAccountWithBalance(donor);
283 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);283 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
289 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);289 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
290 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);290 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
291291
292 // 1. Cannot transfer more than have
293 const receiver = testCase === 'transfer' ? receiverEth : receiverCrossEth;
292 await expect(collectionEvm.methods.transferCross(receiverCrossEth, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;294 await expect(collectionEvm.methods[testCase](receiver, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;
295 // 2. Zero transfer not allowed
296 await expect(collectionEvm.methods[testCase](receiver, 0n).send({from: sender})).to.be.rejected;
293 });297 }));
294 298
299
295 itEth('Can perform transfer()', async ({helper}) => {300 itEth('Can perform transfer()', async ({helper}) => {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
518 }518 }
519 });519 });
520
521 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {
522 const sender = await helper.eth.createAccountWithBalance(donor);
523 const tokenOwner = await helper.eth.createAccountWithBalance(donor);
524 const receiverSub = minter;
525 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
526
527 const collection = await helper.nft.mintCollection(minter, {});
528 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
529 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', sender);
530
531 await collection.mintToken(minter, {Ethereum: sender});
532 const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});
533
534 // Cannot transferCross someone else's token:
535 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;
536 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;
537 // Cannot transfer token if it does not exist:
538 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;
539 }));
520});540});
521541
522describe('NFT: Fees', () => {542describe('NFT: Fees', () => {
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
413 }413 }
414 });414 });
415415
416 itEth.skip('Cannot transferCross with invalid params', async ({helper}) => {416 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {
417 const sender = await helper.eth.createAccountWithBalance(donor);417 const sender = await helper.eth.createAccountWithBalance(donor);
418 const tokenOwner = await helper.eth.createAccountWithBalance(donor);418 const tokenOwner = await helper.eth.createAccountWithBalance(donor);
419 const receiverSub = minter;
419 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);420 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
420421
421 const collection = await helper.rft.mintCollection(minter, {});422 const collection = await helper.rft.mintCollection(minter, {});
422 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);423 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
423 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);424 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
424425
425 await collection.mintToken(minter, 50n, {Ethereum: sender});426 await collection.mintToken(minter, 50n, {Ethereum: sender});
426 const notSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});427 const nonSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});
428
427 // Cannot transferCross someone else's token:429 // Cannot transferCross someone else's token:
430 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;
428 await expect(collectionEvm.methods.transferCross(receiverCrossSub, notSendersToken.tokenId).send({from: sender})).to.be.rejected;431 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;
429 // FIXME: (transaction successful): Cannot transfer token if it does not exist:432 // Cannot transfer token if it does not exist:
430 await expect(collectionEvm.methods.transferCross(receiverCrossSub, 999999).send({from: sender})).to.be.rejected;433 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;
431 });434 }));
432435
433 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {436 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {
434 const caller = await helper.eth.createAccountWithBalance(donor);437 const caller = await helper.eth.createAccountWithBalance(donor);