difftreelog
Add more approve tests
in: master
4 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -186,6 +186,68 @@
}
});
+ itEth('Can perform approveCross()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];
+ const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);
+ const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);
+
+
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+ {
+ const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('100');
+ }
+
+ {
+ const allowance = await contract.methods.allowance(owner, spender).call();
+ expect(+allowance).to.equal(100);
+ }
+
+
+ {
+ const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));
+ expect(event.returnValues.value).to.be.equal('100');
+ }
+
+ {
+ const allowance = await collection.getApprovedTokens({Ethereum: owner}, {Substrate: spenderSub.address});
+ expect(allowance).to.equal(100n);
+ }
+
+ {
+ //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()
+ }
+ });
+
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ await collection.mint(alice, 100n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+ await expect(collectionEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
+
itEth('Can perform burnFromCross()', async ({helper}) => {
const sender = await helper.eth.createAccountWithBalance(donor, 100n);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth194 .map(p => {194 .map(p => {195 return {195 return {196 key: p.key, permission: {196 key: p.key, permission: {197 tokenOwner: true,197 tokenOwner: false,198 collectionAdmin: true,198 collectionAdmin: true,199 mutable: true,199 mutable: false,200 },200 },201 };201 };202 });202 });482 expect(await token2.doesExist()).to.be.false;482 expect(await token2.doesExist()).to.be.false;483 });483 });484484485 // TODO combine all approve tests in one place485 itEth('Can perform approveCross()', async ({helper}) => {486 itEth('Can perform approveCross()', async ({helper}) => {486 // arrange: create accounts487 // arrange: create accounts487 const owner = await helper.eth.createAccountWithBalance(donor, 100n);488 const owner = await helper.eth.createAccountWithBalance(donor, 100n);530 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});531 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});531 });532 });533534 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {535 const nonOwner = await helper.eth.createAccountWithBalance(donor);536 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);537 const owner = await helper.eth.createAccountWithBalance(donor);538 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});539 const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');540 const token = await collection.mintToken(minter, {Ethereum: owner});541542 await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');543 });532544533 itEth('Can reaffirm approved address', async ({helper}) => {545 itEth('Can reaffirm approved address', async ({helper}) => {534 const owner = await helper.eth.createAccountWithBalance(donor, 100n);546 const owner = await helper.eth.createAccountWithBalance(donor, 100n);tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -150,9 +150,11 @@
const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
+ const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {
+ tokenOwner: false,
collectionAdmin: true,
- mutable: true}}; });
+ mutable: false}};
+ });
const collection = await helper.rft.mintCollection(minter, {
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -207,7 +207,20 @@
//TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()
}
});
-
+
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const token = await collection.mintToken(alice, 100n, {Ethereum: owner});
+
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);
+ const tokenEvm = helper.ethNativeContract.rftToken(tokenAddress, owner);
+
+ await expect(tokenEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
[
'transferFrom',
'transferFromCross',