difftreelog
Add transferCross tests
in: master
3 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth232 });232 });233233234 itEth('Can perform transferCross()', async ({helper}) => {234 itEth('Can perform transferCross()', async ({helper}) => {235 const owner = await helper.eth.createAccountWithBalance(donor);235 const sender = await helper.eth.createAccountWithBalance(donor);236 const receiver = await helper.eth.createAccountWithBalance(donor);236 const receiverEth = await helper.eth.createAccountWithBalance(donor);237 const to = helper.ethCrossAccount.fromAddress(receiver);237 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);238 const toSubstrate = helper.ethCrossAccount.fromKeyringPair(donor);238 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);239 const collection = await helper.ft.mintCollection(alice);239 const collection = await helper.ft.mintCollection(alice);240 await collection.mint(alice, 200n, {Ethereum: owner});240 await collection.mint(alice, 200n, {Ethereum: sender});241241242 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);242 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);243 const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);243 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);244244245 {245 {246 // Can transferCross to ethereum address:246 const result = await contract.methods.transferCross(to, 50).send({from: owner});247 const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});247 248 // Check events:248 const event = result.events.Transfer;249 const event = result.events.Transfer;249 expect(event.address).to.be.equal(collectionAddress);250 expect(event.address).to.be.equal(collectionAddress);250 expect(event.returnValues.from).to.be.equal(owner);251 expect(event.returnValues.from).to.be.equal(sender);251 expect(event.returnValues.to).to.be.equal(receiver);252 expect(event.returnValues.to).to.be.equal(receiverEth);252 expect(event.returnValues.value).to.be.equal('50');253 expect(event.returnValues.value).to.be.equal('50');254 // Sender's balance decreased:255 const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();256 expect(+ownerBalance).to.equal(150);257 // Receiver's balance increased:258 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();259 expect(+receiverBalance).to.equal(50);253 }260 }254261 255 {262 {256 const balance = await contract.methods.balanceOf(owner).call();263 // Can transferCross to substrate address:257 expect(+balance).to.equal(150);258 }259260 {264 const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});261 const balance = await contract.methods.balanceOf(receiver).call();265 // Check events:262 expect(+balance).to.equal(50);263 }264 265 {266 const result = await contract.methods.transferCross(toSubstrate, 50).send({from: owner});267 268 const event = result.events.Transfer;266 const event = result.events.Transfer;269 expect(event.address).to.be.equal(collectionAddress);267 expect(event.address).to.be.equal(collectionAddress);270 expect(event.returnValues.from).to.be.equal(owner);268 expect(event.returnValues.from).to.be.equal(sender);271 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));269 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));272 expect(event.returnValues.value).to.be.equal('50');270 expect(event.returnValues.value).to.be.equal('50');273 }271 // Sender's balance decreased:274275 {276 const balance = await collection.getBalance({Ethereum: owner});272 const senderBalance = await collection.getBalance({Ethereum: sender});277 expect(balance).to.equal(100n);273 expect(senderBalance).to.equal(100n);278 }274 // Receiver's balance increased:279280 {281 const balance = await collection.getBalance({Substrate: donor.address});275 const balance = await collection.getBalance({Substrate: donor.address});282 expect(balance).to.equal(50n);276 expect(balance).to.equal(50n);283 }277 }284 285 });278 });286 279 tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -252,8 +252,9 @@
itEth('Can perform burnFromCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
const ownerSub = bob;
- const ownerCross = helper.ethCrossAccount.fromKeyringPair(ownerSub);
+ const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);
const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);
const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);
const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);
@@ -269,20 +270,23 @@
await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});
// can burnFromCross:
- const result1 = await collectionEvm.methods.burnFromCross(ownerCross, token1.tokenId).send({from: burnerEth});
- // FIXME Error No Permission?:
- const result2 = await collectionEvm.methods.burnFromCross(ownerCross, token2.tokenId).send({from: burnerEth});
+ const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});
+ const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});
const events1 = result1.events.Transfer;
const events2 = result2.events.Transfer;
- [[events1, token1], [events2, token2]].map(burnEvents => {
- expect(burnEvents[0]).to.be.like({
+ // Check events for burnFromCross (substrate and ethereum):
+ [
+ [events1, token1, helper.address.substrateToEth(ownerSub.address)],
+ [events2, token2, ownerEth],
+ ].map(burnData => {
+ expect(burnData[0]).to.be.like({
address: collectionAddress,
event: 'Transfer',
returnValues: {
- from: helper.address.substrateToEth(ownerSub.address),
+ from: burnData[2],
to: '0x0000000000000000000000000000000000000000',
- tokenId: burnEvents[1].tokenId.toString(),
+ tokenId: burnData[1].tokenId.toString(),
},
});
});
@@ -341,6 +345,7 @@
itEth('Can reaffirm approved address', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);
const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);
const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);
@@ -358,12 +363,9 @@
// receiver2 can transferFrom:
await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});
- // can set approved address to zero address:
+ // can set approved address to self address to remove approval:
await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});
-
- // FIXME how to remove approval?:
- await collectionEvm.methods.approveCross({eth: '0x0000000000000000000000000000000000000000', sub: '0'}, token2.tokenId).call({from: owner});
- await collectionEvm.methods.approve('0x0000000000000000000000000000000000000000', token2.tokenId).call({from: owner});
+ await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});
// receiver1 cannot transfer token anymore:
await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;
@@ -469,54 +471,50 @@
itEth('Can perform transferCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {});
const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
{
- const result = await contract.methods.transferCross(to, tokenId).send({from: owner});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(owner);
- expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.to).to.be.equal(receiverEth);
expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
- }
-
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(0);
+
+ // owner has balance = 0:
+ const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();
+ expect(+ownerBalance).to.equal(0);
+ // receiver owns token:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(1);
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
}
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
- }
{
- const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});
-
-
+ // Can transferCross to substrate address:
+ const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});
+ // Check events:
const event = substrateResult.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(receiverEth);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));
expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(0);
- }
-
- {
- const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
- expect(balance).to.be.contain(tokenId);
+
+ // owner has balance = 0:
+ const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+ownerBalance).to.equal(0);
+ // receiver owns token:
+ const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
+ expect(receiverBalance).to.contain(tokenId);
}
});
});
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -363,56 +363,67 @@
});
itEth('Can perform transferCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
+
const collection = await helper.rft.mintCollection(minter, {});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
- const {tokenId} = await collection.mintToken(minter, 1n, {Ethereum: caller});
+ const token = await collection.mintToken(minter, 50n, {Ethereum: sender});
{
- const result = await contract.methods.transferCross(to, tokenId).send({from: caller});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal(caller);
- expect(event.returnValues.to).to.equal(receiver);
- expect(event.returnValues.tokenId).to.equal(tokenId.toString());
- }
-
- {
- const balance = await contract.methods.balanceOf(caller).call();
- expect(+balance).to.equal(0);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
+ expect(event.returnValues.from).to.equal(sender);
+ expect(event.returnValues.to).to.equal(receiverEth);
+ expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());
+ // Sender's balance decreased:
+ const senderBalance = await collectionEvm.methods.balanceOf(sender).call();
+ expect(+senderBalance).to.equal(0);
+ expect(await token.getBalance({Ethereum: sender})).to.eq(0n);
+ // Receiver's balance increased:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(1);
+ expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);
}
{
- const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});
-
-
+ // Can transferCross to substrate address:
+ const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});
+ // Check events:
const event = substrateResult.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(receiverEth);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));
- expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
+ expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);
+ // Sender's balance decreased:
+ const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+senderBalance).to.equal(0);
+ expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);
+ // Receiver's balance increased:
+ const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
+ expect(receiverBalance).to.contain(token.tokenId);
+ expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);
}
+ });
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(0);
- }
+ itEth('Cannot transferCross with invalid params', async ({helper}) => {
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
- {
- const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
- expect(balance).to.be.contain(tokenId);
- }
+ const collection = await helper.rft.mintCollection(minter, {});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
+
+ const {tokenId} = await collection.mintToken(minter, 50n, {Ethereum: sender});
+ // FIXME (transaction successful): Cannot transfer token if it does not exist:
+ await expect(collectionEvm.methods.transferCross(receiverCrossSub, tokenId + 1).send({from: sender})).to.be.rejected;
});
itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {