difftreelog
Add more approve tests
in: master
4 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth186 }186 }187 });187 });188189 itEth('Can perform approveCross()', async ({helper}) => {190 const owner = await helper.eth.createAccountWithBalance(donor);191 const spender = helper.eth.createAccount();192 const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];193 const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);194 const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);195 196197 const collection = await helper.ft.mintCollection(alice);198 await collection.mint(alice, 200n, {Ethereum: owner});199200 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);201 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);202203 {204 const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});205 const event = result.events.Approval;206 expect(event.address).to.be.equal(collectionAddress);207 expect(event.returnValues.owner).to.be.equal(owner);208 expect(event.returnValues.spender).to.be.equal(spender);209 expect(event.returnValues.value).to.be.equal('100');210 }211212 {213 const allowance = await contract.methods.allowance(owner, spender).call();214 expect(+allowance).to.equal(100);215 }216 217 218 {219 const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});220 const event = result.events.Approval;221 expect(event.address).to.be.equal(collectionAddress);222 expect(event.returnValues.owner).to.be.equal(owner);223 expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));224 expect(event.returnValues.value).to.be.equal('100');225 }226227 {228 const allowance = await collection.getApprovedTokens({Ethereum: owner}, {Substrate: spenderSub.address});229 expect(allowance).to.equal(100n);230 }231 232 {233 //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()234 }235 });236237 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {238 const nonOwner = await helper.eth.createAccountWithBalance(donor);239 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);240 const owner = await helper.eth.createAccountWithBalance(donor);241 const collection = await helper.ft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});242 await collection.mint(alice, 100n, {Ethereum: owner});243244 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);245 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);246247 await expect(collectionEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');248 });249188250189 itEth('Can perform burnFromCross()', async ({helper}) => {251 itEth('Can perform burnFromCross()', async ({helper}) => {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.tsdiffbeforeafterboth150 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);150 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);151151152 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });152 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });153 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,153 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {154 tokenOwner: false,154 collectionAdmin: true,155 collectionAdmin: true,155 mutable: true}}; });156 mutable: false}};156 157 });157 158 159 tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth208 }208 }209 });209 });210 210211 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {212 const nonOwner = await helper.eth.createAccountWithBalance(donor);213 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);214 const owner = await helper.eth.createAccountWithBalance(donor);215 const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});216 const token = await collection.mintToken(alice, 100n, {Ethereum: owner});217218 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);219 const tokenEvm = helper.ethNativeContract.rftToken(tokenAddress, owner);220221 await expect(tokenEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');222 });223211 [224 [212 'transferFrom',225 'transferFrom',