difftreelog
Sponsoring tests
in: master
3 files changed
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth1//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});tests/src/eth/util/ERC721.soldiffbeforeafterboth--- a/tests/src/eth/util/ERC721.sol
+++ /dev/null
@@ -1,159 +0,0 @@
-contract ERC721 {
- uint8 _dummy = 0;
- address _dummy_addr = 0x0000000000000000000000000000000000000000;
- string _dummy_string = "";
- string stub_error =
- "this contract does not exists, code for collections is implemented at pallet side";
-
- event Transfer(
- address indexed from,
- address indexed to,
- uint256 indexed tokenId
- );
-
- event Approval(
- address indexed owner,
- address indexed approved,
- uint256 indexed tokenId
- );
-
- event ApprovalForAll(
- address indexed owner,
- address indexed operator,
- bool approved
- );
-
- // 0x18160ddd
- function totalSupply() external view returns (uint256) {
- require(false, stub_error);
- return 0;
- }
-
- function name() external view returns (string memory res_name) {
- require(false, stub_error);
- res_name = _dummy_string;
- }
-
- function symbol() external view returns (string memory res_symbol) {
- require(false, stub_error);
- res_symbol = _dummy_string;
- }
-
- function tokenURI(uint256 tokenId) external view returns (string memory) {
- require(false, stub_error);
- tokenId;
- return _dummy_string;
- }
-
- function tokenByIndex(uint256 index) external view returns (uint256) {
- require(false, stub_error);
- index;
- return 0;
- }
-
- function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256) {
- require(false, stub_error);
- owner;
- index;
- return 0;
- }
-
- // 0x70a08231
- function balanceOf(address owner) external view returns (uint256) {
- require(false, stub_error);
- owner;
- return 0;
- }
-
- // 0x6352211e
- function ownerOf(uint256 tokenId) external view returns (address) {
- require(false, stub_error);
- tokenId;
- return _dummy_addr;
- }
-
- // 0xb88d4fde
- function safeTransferFrom(
- address from,
- address to,
- uint256 tokenId,
- bytes calldata data
- ) external payable {
- require(false, stub_error);
- from;
- to;
- tokenId;
- data;
- }
-
- // 0x42842e0e
- function safeTransferFrom(
- address from,
- address to,
- uint256 tokenId
- ) external payable {
- require(false, stub_error);
- from;
- to;
- tokenId;
- }
-
- // 0x23b872dd
- function transferFrom(
- address from,
- address to,
- uint256 tokenId
- ) external payable {
- require(false, stub_error);
- from;
- to;
- tokenId;
- }
-
- // 0x095ea7b3
- function approve(address approved, uint256 tokenId) external payable {
- require(false, stub_error);
- approved;
- tokenId;
- }
-
- // 0xa22cb465
- function setApprovalForAll(address operator, bool approved) external {
- require(false, stub_error);
- operator;
- approved;
- _dummy = 0;
- }
-
- // 0x081812fc
- function getApproved(uint256 tokenId) external view returns (address) {
- require(false, stub_error);
- tokenId;
- return _dummy_addr;
- }
-
- // 0xe985e9c5
- function isApprovedForAll(address owner, address operator)
- external
- view
- returns (bool)
- {
- require(false, stub_error);
- owner;
- operator;
- return false;
- }
-
- // 0x01ffc9a7
- function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
- return
- // ERC721
- interfaceID == 0x80ac58cd ||
- // ERC721Metadata
- interfaceID == 0x5b5e139f ||
- // ERC721Enumerable
- interfaceID == 0x780e9d63 ||
- // ERC165
- interfaceID == 0x01ffc9a7;
- }
-}
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -17,7 +17,6 @@
import config from '../../config';
import privateKey from '../../substrate/privateKey';
import contractHelpersAbi from './contractHelpersAbi.json';
-import fs from 'fs';
export const GAS_ARGS = { gas: 0x1000000, gasPrice: '0x01' };
@@ -176,20 +175,20 @@
};
}
-export async function deployFungibleContract(web3: Web3 & Web3HttpMarker, deployer: string) {
+// export async function deployFungibleContract(web3: Web3 & Web3HttpMarker, deployer: string) {
- const sol = fs.readFileSync(__dirname + '/ERC721.sol').toString();
+// const sol = fs.readFileSync(__dirname + '/ERC721.sol').toString();
- const compiled = compileContract('ERC721', sol);
- const ERC721 = new web3.eth.Contract(compiled.abi, undefined, {
- data: compiled.object,
- from: deployer,
- ...GAS_ARGS,
- });
- const fungible = await ERC721.deploy({ data: compiled.object }).send({from: deployer});
+// const compiled = compileContract('ERC721', sol);
+// const ERC721 = new web3.eth.Contract(compiled.abi, undefined, {
+// data: compiled.object,
+// from: deployer,
+// ...GAS_ARGS,
+// });
+// const fungible = await ERC721.deploy({ data: compiled.object }).send({from: deployer});
- return fungible;
-}
+// return fungible;
+// }
export async function deployFlipper(web3: Web3 & Web3HttpMarker, deployer: string) {
const compiled = compileContract('Flipper', `