git.delta.rocks / unique-network / refs/commits / 09a417ba5601

difftreelog

Add approveCross and trasferFromCross checks

Max Andreev2022-12-01parent: #71e7d44.patch.diff
in: master

2 files changed

modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
91 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 });
9393
94 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 removeFromCollectionAllowListCross
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Contract} from 'web3-eth-contract';19import {Contract} from 'web3-eth-contract';
20import exp from 'constants';
2120
2221
23describe('NFT: Information getting', () => {22describe('NFT: Information getting', () => {
280 });279 });
281280
282 itEth('Can perform approveCross()', async ({helper}) => {281 itEth('Can perform approveCross()', async ({helper}) => {
282 // arrange: create accounts
283 const owner = await helper.eth.createAccountWithBalance(donor, 100n);
284 const ownerCross = helper.ethCrossAccount.fromAddress(owner);
285 const receiverSub = charlie;
286 const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
287 const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);
288 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
289
290 // arrange: create collection and tokens:
283 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});291 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
284
285 const owner = await helper.eth.createAccountWithBalance(donor, 100n);292 const token1 = await collection.mintToken(minter, {Ethereum: owner});
286 const receiver = charlie;
287
288 const token = await collection.mintToken(minter, {Ethereum: owner});293 const token2 = await collection.mintToken(minter, {Ethereum: owner});
289294
290 const address = helper.ethAddress.fromCollectionId(collection.collectionId);295 const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
291 const contract = helper.ethNativeContract.collection(address, 'nft');296
292297 // Can approveCross substrate and ethereum address:
293 {
294 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);298 const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});
295 const result = await contract.methods.approveCross(recieverCross, token.tokenId).send({from: owner});299 const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});
296 const event = result.events.Approval;300 const eventSub = resultSub.events.Approval;
301 const eventEth = resultEth.events.Approval;
297 expect(event).to.be.like({302 expect(eventSub).to.be.like({
298 address: helper.ethAddress.fromCollectionId(collection.collectionId),303 address: helper.ethAddress.fromCollectionId(collection.collectionId),
299 event: 'Approval',304 event: 'Approval',
300 returnValues: {305 returnValues: {
301 owner,306 owner,
302 approved: helper.address.substrateToEth(receiver.address),307 approved: helper.address.substrateToEth(receiverSub.address),
303 tokenId: token.tokenId.toString(),308 tokenId: token1.tokenId.toString(),
304 },309 },
305 });310 });
306 }311 expect(eventEth).to.be.like({
312 address: helper.ethAddress.fromCollectionId(collection.collectionId),
313 event: 'Approval',
314 returnValues: {
315 owner,
316 approved: receiverEth,
317 tokenId: token2.tokenId.toString(),
318 },
319 });
320
321 // Substrate address can transferFrom approved tokens:
322 await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});
323 expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});
324 // Ethereum address can transferFromCross approved tokens:
325 await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});
326 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
307 });327 });
308328
309 itEth('Can perform transferFrom()', async ({helper}) => {329 itEth('Can perform transferFrom()', async ({helper}) => {
501 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));521 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
502 });522 });
503523
504 itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {524 itEth('Can perform transferFromCross()', async ({helper}) => {
505 const collectionMinter = alice;525 const collectionMinter = alice;
506 const owner = bob;526 const owner = bob;
507 const receiver = charlie;527 const receiver = charlie;