difftreelog
Add approveCross and trasferFromCross checks
in: master
2 files changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth91 expect(await collectionEvm.methods.allowlistedCross(crossUser).call({from: owner})).to.be.false;91 expect(await collectionEvm.methods.allowlistedCross(crossUser).call({from: owner})).to.be.false;92 });92 });939394 itEth.only('Collection allowlist can be added and removed by [cross] address', async ({helper}) => {94 itEth('Collection allowlist can be added and removed by [cross] address', async ({helper}) => {95 const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();95 const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();96 const [userSub] = await helper.arrange.createAccounts([10n], donor);96 const [userSub] = await helper.arrange.createAccounts([10n], donor);97 const userEth = await helper.eth.createAccountWithBalance(donor);97 const userEth = await helper.eth.createAccountWithBalance(donor);100 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);100 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);101 const userCrossSub = helper.ethCrossAccount.fromKeyringPair(userSub);101 const userCrossSub = helper.ethCrossAccount.fromKeyringPair(userSub);102 const userCrossEth = helper.ethCrossAccount.fromAddress(userEth);102 const userCrossEth = helper.ethCrossAccount.fromAddress(userEth);103 103 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);104 104 // Can addToCollectionAllowListCross:105 // Can addToCollectionAllowListCross:105 expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.false;106 expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.false;114 await collectionEvm.methods.mint(userEth).send();115 await collectionEvm.methods.mint(userEth).send();115 await collectionEvm.methods.setCollectionAccess(1).send();116 await collectionEvm.methods.setCollectionAccess(1).send();116 await collectionEvm.methods.transfer(owner, 1).send({from: userEth}); // FIXME: why not?117 await collectionEvm.methods.transfer(owner, 1).send({from: userEth}); // FIXME: why not?118 // await collectionEvm.methods.transferCross(ownerCrossEth, 1).send({from: userEth}); // FIXME: why not?117 expect(await helper.nft.getTokenOwner(collectionId, 1)).to.eq({Ethereum: owner});119 expect(await helper.nft.getTokenOwner(collectionId, 1)).to.eq({Ethereum: owner});118 120 119 // can removeFromCollectionAllowListCross121 // can removeFromCollectionAllowListCrosstests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -17,7 +17,6 @@
import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-import exp from 'constants';
describe('NFT: Information getting', () => {
@@ -280,30 +279,51 @@
});
itEth('Can perform approveCross()', async ({helper}) => {
+ // arrange: create accounts
+ const owner = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCross = helper.ethCrossAccount.fromAddress(owner);
+ const receiverSub = charlie;
+ const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+
+ // arrange: create collection and tokens:
const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const token1 = await collection.mintToken(minter, {Ethereum: owner});
+ const token2 = await collection.mintToken(minter, {Ethereum: owner});
- const owner = await helper.eth.createAccountWithBalance(donor, 100n);
- const receiver = charlie;
+ const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
- const token = await collection.mintToken(minter, {Ethereum: owner});
+ // Can approveCross substrate and ethereum address:
+ const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});
+ const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});
+ const eventSub = resultSub.events.Approval;
+ const eventEth = resultEth.events.Approval;
+ expect(eventSub).to.be.like({
+ address: helper.ethAddress.fromCollectionId(collection.collectionId),
+ event: 'Approval',
+ returnValues: {
+ owner,
+ approved: helper.address.substrateToEth(receiverSub.address),
+ tokenId: token1.tokenId.toString(),
+ },
+ });
+ expect(eventEth).to.be.like({
+ address: helper.ethAddress.fromCollectionId(collection.collectionId),
+ event: 'Approval',
+ returnValues: {
+ owner,
+ approved: receiverEth,
+ tokenId: token2.tokenId.toString(),
+ },
+ });
- const address = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(address, 'nft');
-
- {
- const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);
- const result = await contract.methods.approveCross(recieverCross, token.tokenId).send({from: owner});
- const event = result.events.Approval;
- expect(event).to.be.like({
- address: helper.ethAddress.fromCollectionId(collection.collectionId),
- event: 'Approval',
- returnValues: {
- owner,
- approved: helper.address.substrateToEth(receiver.address),
- tokenId: token.tokenId.toString(),
- },
- });
- }
+ // Substrate address can transferFrom approved tokens:
+ await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});
+ expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});
+ // Ethereum address can transferFromCross approved tokens:
+ await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});
+ expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
});
itEth('Can perform transferFrom()', async ({helper}) => {
@@ -501,7 +521,7 @@
expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
+ itEth('Can perform transferFromCross()', async ({helper}) => {
const collectionMinter = alice;
const owner = bob;
const receiver = charlie;