git.delta.rocks / unique-network / refs/commits / 54811ce8b19d

difftreelog

source

tests/src/eth/contractSponsoring.test.ts4.4 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { expect } from 'chai';8import { createCollectionExpectSuccess, 9  createFungibleItemExpectSuccess, 10  transferExpectSuccess, 11  transferFromExpectSuccess, 12  createItemExpectSuccess, 13  setContractSponsoringRateLimitExpectSuccess,14  enableContractSponsoringExpectSuccess,15  setCollectionSponsorExpectSuccess,16  confirmSponsorshipExpectSuccess,17  enableContractSponsoringExpectFailure} from '../util/helpers';18import { collectionIdToAddress, 19  contractHelpers,20  createEthAccountWithBalance,21  createEthAccount,22  transferBalanceToEth,23  subToEth,24  deployFlipper,25  usingWeb3Http,26  deployFungibleContract,27  GAS_ARGS, itWeb3 } from './util/helpers';28import waitNewBlocks from '../substrate/wait-new-blocks';29import fungibleAbi from './fungibleAbi.json';30import nonFungibleAbi from './nonFungibleAbi.json';3132describe.only('Sponsoring EVM contracts', () => {33  itWeb3.skip('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {34    await usingWeb3Http(async web3Http => {35      const owner = await createEthAccountWithBalance(api, web3Http);36      const fungible = await deployFungibleContract(web3Http, owner);37      await waitNewBlocks(api, 1);38      const helpers = contractHelpers(web3Http, owner);39      await waitNewBlocks(api, 1);40      expect(await helpers.methods.sponsoringEnabled(fungible.options.address).call()).to.be.false;41      await waitNewBlocks(api, 1);42      await helpers.methods.toggleSponsoring(fungible.options.address, true).send({from: owner});43      await waitNewBlocks(api, 1);44      expect(await helpers.methods.sponsoringEnabled(fungible.options.address).call()).to.be.true;45    });46  });4748  itWeb3.skip('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3}) => {49    await usingWeb3Http(async web3Http => {50      const owner = await createEthAccountWithBalance(api, web3Http);51      const notOwner = await createEthAccountWithBalance(api, web3Http);52      const fungible = await deployFungibleContract(web3Http, owner);53      await waitNewBlocks(api, 1);54      const helpers = contractHelpers(web3Http, owner);55      await waitNewBlocks(api, 1);56      expect(await helpers.methods.sponsoringEnabled(fungible.options.address).call()).to.be.false;57      await waitNewBlocks(api, 1);58      await expect(helpers.methods.toggleSponsoring(notOwner, true).send({from: notOwner})).to.rejected;59      await waitNewBlocks(api, 1);60      expect(await helpers.methods.sponsoringEnabled(fungible.options.address).call()).to.be.false;61    });62  });6364  itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works', async ({api, web3}) => {65    await usingWeb3Http(async web3Http => {66      const alice = privateKey('//Alice');67      const bob = privateKey('//Bob');68      const collection = await createCollectionExpectSuccess({69        mode: { type: 'Fungible', decimalPoints: 0 },70      });71      await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, alice.address);72      const owner = await createEthAccountWithBalance(api, web3Http);73      const notOwner = await createEthAccountWithBalance(api, web3Http);74      await transferExpectSuccess(collection, 0, alice, { ethereum: notOwner } , 200, 'Fungible');75      const address = collectionIdToAddress(collection);76      const fungible = await deployFungibleContract(web3Http, address);77      await transferBalanceToEth(api, alice, fungible.options.address);78      await waitNewBlocks(api, 1);79      const balanceBefore = await web3.eth.getBalance(fungible.options.address);8081      const helpers = contractHelpers(web3Http, address);82      await waitNewBlocks(api, 1);83      expect(await helpers.methods.sponsoringEnabled(fungible.options.address).call()).to.be.false;84      await waitNewBlocks(api, 1);85      await helpers.methods.toggleSponsoring(fungible.options.address, true).send({from: owner});86      await waitNewBlocks(api, 1);87      expect(await helpers.methods.sponsoringEnabled(fungible.options.address).call()).to.be.true;8889//      await fungible.methods.approve(owner, 50).send({ from: owner });90      await fungible.methods.transferFrom(notOwner, owner, 50).send({ from: notOwner });91      const balanceAfter = await web3.eth.getBalance(fungible.options.address);92      expect(+balanceAfter).to.lessThan(+balanceBefore);93    });94  });9596});