1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itEth, usingEthPlaygrounds} from './eth/util/playgrounds';19import {itSub, Pallets, usingPlaygrounds, expect} from './util/playgrounds';2021describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = privateKey('//Alice');28 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);29 });30 });31 32 itSub('Balance transfers and check balance', async ({helper}) => {33 const alicesBalanceBefore = await helper.balance.getSubstrate(alice.address);34 const bobsBalanceBefore = await helper.balance.getSubstrate(bob.address);3536 expect(await helper.balance.transferToSubstrate(alice, bob.address, 1n)).to.be.true;3738 const alicesBalanceAfter = await helper.balance.getSubstrate(alice.address);39 const bobsBalanceAfter = await helper.balance.getSubstrate(bob.address);4041 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;42 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;43 });4445 itSub('Inability to pay fees error message is correct', async ({helper, privateKey}) => {46 const donor = privateKey('//Alice');47 const [zero] = await helper.arrange.createAccounts([0n], donor);4849 50 51 await expect(helper.balance.transferToSubstrate(zero, donor.address, 1n))52 .to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');53 });5455 itSub('[nft] User can transfer owned token', async ({helper}) => {56 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-1-NFT', description: '', tokenPrefix: 'T'});57 const nft = await collection.mintToken(alice);5859 await nft.transfer(alice, {Substrate: bob.address});60 expect(await nft.getOwner()).to.be.deep.equal({Substrate: bob.address});61 });6263 itSub('[fungible] User can transfer owned token', async ({helper}) => {64 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-1-FT', description: '', tokenPrefix: 'T'});65 await collection.mint(alice, 10n);6667 await collection.transfer(alice, {Substrate: bob.address}, 9n);68 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);69 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);70 });7172 itSub.ifWithPallets('[refungible] User can transfer owned token', [Pallets.ReFungible], async ({helper}) => {73 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});74 const rft = await collection.mintToken(alice, 10n);7576 await rft.transfer(alice, {Substrate: bob.address}, 9n);77 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);78 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);79 });8081 itSub('[nft] Collection admin can transfer owned token', async ({helper}) => {82 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-2-NFT', description: '', tokenPrefix: 'T'});83 await collection.addAdmin(alice, {Substrate: bob.address});8485 const nft = await collection.mintToken(bob, {Substrate: bob.address});86 await nft.transfer(bob, {Substrate: alice.address});8788 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});89 });9091 itSub('[fungible] Collection admin can transfer owned token', async ({helper}) => {92 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-2-FT', description: '', tokenPrefix: 'T'});93 await collection.addAdmin(alice, {Substrate: bob.address});9495 await collection.mint(bob, 10n, {Substrate: bob.address});96 await collection.transfer(bob, {Substrate: alice.address}, 1n);9798 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(9n);99 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);100 });101102 itSub.ifWithPallets('[refungible] Collection admin can transfer owned token', [Pallets.ReFungible], async ({helper}) => {103 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-2-RFT', description: '', tokenPrefix: 'T'});104 await collection.addAdmin(alice, {Substrate: bob.address});105106 const rft = await collection.mintToken(bob, 10n, {Substrate: bob.address});107 await rft.transfer(bob, {Substrate: alice.address}, 1n);108109 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(9n);110 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(1n);111 });112});113114describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {115 let alice: IKeyringPair;116 let bob: IKeyringPair;117118 before(async () => {119 await usingPlaygrounds(async (helper, privateKey) => {120 const donor = privateKey('//Alice');121 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);122 });123 });124125 itSub('[nft] Transfer with not existed collection_id', async ({helper}) => {126 const collectionId = (1 << 32) - 1;127 await expect(helper.nft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))128 .to.be.rejectedWith(/common\.CollectionNotFound/);129 });130131 itSub('[fungible] Transfer with not existed collection_id', async ({helper}) => {132 const collectionId = (1 << 32) - 1;133 await expect(helper.ft.transfer(alice, collectionId, {Substrate: bob.address}))134 .to.be.rejectedWith(/common\.CollectionNotFound/);135 });136137 itSub.ifWithPallets('[refungible] Transfer with not existed collection_id', [Pallets.ReFungible], async ({helper}) => {138 const collectionId = (1 << 32) - 1;139 await expect(helper.rft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))140 .to.be.rejectedWith(/common\.CollectionNotFound/);141 });142143 itSub('[nft] Transfer with deleted collection_id', async ({helper}) => {144 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-1-NFT', description: '', tokenPrefix: 'T'});145 const nft = await collection.mintToken(alice);146147 await nft.burn(alice);148 await collection.burn(alice);149150 await expect(nft.transfer(alice, {Substrate: bob.address}))151 .to.be.rejectedWith(/common\.CollectionNotFound/);152 });153154 itSub('[fungible] Transfer with deleted collection_id', async ({helper}) => {155 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-1-FT', description: '', tokenPrefix: 'T'});156 await collection.mint(alice, 10n);157158 await collection.burnTokens(alice, 10n);159 await collection.burn(alice);160161 await expect(collection.transfer(alice, {Substrate: bob.address}))162 .to.be.rejectedWith(/common\.CollectionNotFound/);163 });164 165 itSub.ifWithPallets('[refungible] Transfer with deleted collection_id', [Pallets.ReFungible], async ({helper}) => {166 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-1-RFT', description: '', tokenPrefix: 'T'});167 const rft = await collection.mintToken(alice, 10n);168169 await rft.burn(alice, 10n);170 await collection.burn(alice);171172 await expect(rft.transfer(alice, {Substrate: bob.address}))173 .to.be.rejectedWith(/common\.CollectionNotFound/);174 });175176 itSub('[nft] Transfer with not existed item_id', async ({helper}) => {177 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-2-NFT', description: '', tokenPrefix: 'T'});178 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))179 .to.be.rejectedWith(/common\.TokenNotFound/);180 });181182 itSub('[fungible] Transfer with not existed item_id', async ({helper}) => {183 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-2-FT', description: '', tokenPrefix: 'T'});184 await expect(collection.transfer(alice, {Substrate: bob.address}))185 .to.be.rejectedWith(/common\.TokenValueTooLow/);186 });187188 itSub.ifWithPallets('[refungible] Transfer with not existed item_id', [Pallets.ReFungible], async ({helper}) => {189 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-2-RFT', description: '', tokenPrefix: 'T'});190 await expect(collection.transferToken(alice, 1, {Substrate: bob.address}))191 .to.be.rejectedWith(/common\.TokenValueTooLow/);192 });193194 itSub('[nft] Transfer with deleted item_id', async ({helper}) => {195 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});196 const nft = await collection.mintToken(alice);197198 await nft.burn(alice);199200 await expect(nft.transfer(alice, {Substrate: bob.address}))201 .to.be.rejectedWith(/common\.TokenNotFound/);202 });203204 itSub('[fungible] Transfer with deleted item_id', async ({helper}) => {205 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-3-FT', description: '', tokenPrefix: 'T'});206 await collection.mint(alice, 10n);207208 await collection.burnTokens(alice, 10n);209210 await expect(collection.transfer(alice, {Substrate: bob.address}))211 .to.be.rejectedWith(/common\.TokenValueTooLow/);212 });213214 itSub.ifWithPallets('[refungible] Transfer with deleted item_id', [Pallets.ReFungible], async ({helper}) => {215 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-Neg-3-RFT', description: '', tokenPrefix: 'T'});216 const rft = await collection.mintToken(alice, 10n);217218 await rft.burn(alice, 10n);219220 await expect(rft.transfer(alice, {Substrate: bob.address}))221 .to.be.rejectedWith(/common\.TokenValueTooLow/);222 });223224 itSub('[nft] Transfer with recipient that is not owner', async ({helper}) => {225 const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-4-NFT', description: '', tokenPrefix: 'T'});226 const nft = await collection.mintToken(alice);227228 await expect(nft.transfer(bob, {Substrate: bob.address}))229 .to.be.rejectedWith(/common\.NoPermission/);230 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});231 });232233 itSub('[fungible] Transfer with recipient that is not owner', async ({helper}) => {234 const collection = await helper.ft.mintCollection(alice, {name: 'Transfer-Neg-4-FT', description: '', tokenPrefix: 'T'});235 await collection.mint(alice, 10n);236237 await expect(collection.transfer(bob, {Substrate: bob.address}, 9n))238 .to.be.rejectedWith(/common\.TokenValueTooLow/);239 expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);240 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(10n);241 });242243 itSub.ifWithPallets('[refungible] Transfer with recipient that is not owner', [Pallets.ReFungible], async ({helper}) => {244 const collection = await helper.rft.mintCollection(alice, {name: 'Transfer-1-RFT', description: '', tokenPrefix: 'T'});245 const rft = await collection.mintToken(alice, 10n);246247 await expect(rft.transfer(bob, {Substrate: bob.address}, 9n))248 .to.be.rejectedWith(/common\.TokenValueTooLow/);249 expect(await rft.getBalance({Substrate: bob.address})).to.be.equal(0n);250 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(10n);251 });252});253254describe('Transfers to self (potentially over substrate-evm boundary)', () => {255 let donor: IKeyringPair;256257 before(async function() {258 await usingEthPlaygrounds(async (_, privateKey) => {259 donor = privateKey('//Alice');260 });261 });262 263 itEth('Transfers to self. In case of same frontend', async ({helper}) => {264 const [owner] = await helper.arrange.createAccounts([10n], donor);265 const collection = await helper.ft.mintCollection(owner, {});266 await collection.mint(owner, 100n);267268 const ownerProxy = helper.address.substrateToEth(owner.address);269270 271 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);272 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);273 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);274275 276 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Ethereum: ownerProxy}, 5n);277 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);278 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);279 });280281 itEth('Transfers to self. In case of substrate-evm boundary', async ({helper}) => {282 const [owner] = await helper.arrange.createAccounts([10n], donor);283 const collection = await helper.ft.mintCollection(owner, {});284 await collection.mint(owner, 100n);285286 const ownerProxy = helper.address.substrateToEth(owner.address);287288 289 await collection.transfer(owner, {Ethereum: ownerProxy}, 10n);290 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(90n);291 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(10n);292293 294 await collection.transferFrom(owner, {Ethereum: ownerProxy}, {Substrate: owner.address}, 5n);295 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(95n);296 expect(await collection.getBalance({Ethereum: ownerProxy})).to.be.equal(5n);297 });298299 itEth('Transfers to self. In case of inside substrate-evm', async ({helper}) => {300 const [owner] = await helper.arrange.createAccounts([10n], donor);301 const collection = await helper.ft.mintCollection(owner, {});302 await collection.mint(owner, 100n);303304 305 await collection.transfer(owner, {Substrate: owner.address}, 10n);306 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);307308 309 await collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 5n);310 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(100n);311 });312313 itEth('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({helper}) => {314 const [owner] = await helper.arrange.createAccounts([10n], donor);315 const collection = await helper.ft.mintCollection(owner, {});316 await collection.mint(owner, 10n);317318 319 await expect(collection.transfer(owner, {Substrate: owner.address}, 11n))320 .to.be.rejectedWith(/common\.TokenValueTooLow/);321322 323 await expect(collection.transferFrom(owner, {Substrate: owner.address}, {Substrate: owner.address}, 12n))324 .to.be.rejectedWith(/common\.TokenValueTooLow/);325 expect(await collection.getBalance({Substrate: owner.address})).to.be.equal(10n);326 });327});