Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Error while calling addLiquidity in Ganache: "VM Exception while processing transaction: invalid JUMP" #27

Closed
juniset opened this issue Mar 22, 2019 · 1 comment

Comments

@juniset
Copy link

juniset commented Mar 22, 2019

Hey,

This issue is similar to #25 except I'm using Etherlime instead of Truffle. Note that the solution applied in #25 (initial ETH value above 1000000000 wei) does not apply in my case.

In a nutshell I want to test a contract that will interact directly with Uniswap. My contract is written in Solidity and I want to do my tests on Ganache. I've imported the abi and bytecodes of the factory and the exchange from the Github repository and put them in UniswapFactory.json and UniswapExchange.json files. The 2 files have the same format as if they had been compiled by Etherlime (i.e. the json looks like {"contractName": , "abi": , "bytecode": } .

My test file is

const etherlime = require('etherlime');
const UniswapFactory = require("../contracts/test/compiled/UniswapFactory");
const UniswapExchange = require("../contracts/test/compiled/UniswapExchange");
const ERC20 = require("../build/TestERC20");
const TestManager = require("../utils/test-manager");

describe("Test Uniswap", function () {
    this.timeout(1000000);
    const manager = new TestManager(accounts, 'ganache');
    let infrastructure = accounts[0].signer;

   describe("Add liquidity ", () => {
        it('should create a liquidity pool with an initial liquidity', async () => {
            deployer = manager.newDeployer();
            // create factory
            const uniswapFactory = await deployer.deploy(UniswapFactory);
            const uniswapTemplateExchange = await deployer.deploy(UniswapExchange);
            await uniswapFactory.initializeFactory(uniswapTemplateExchange.contractAddress); 
            const erc20 = await deployer.deploy(ERC20, {}, [infrastructure.address], 1000, 18); 
            // create liquidity pool
            await uniswapFactory.from(infrastructure).createExchange(erc20.contractAddress); 
            const exchangeAddress = await uniswapFactory.getExchange(erc20.contractAddress); 
            const liquidityPool = await etherlime.ContractAt(UniswapExchange, exchangeAddress); 
            // add initial liquidity
            await erc20.from(infrastructure).approve(liquidityPool.contractAddress, 200000000000); 
            const currentBlock = await manager.getCurrentBlock(); 
            await liquidityPool.from(infrastructure).addLiquidity(1, 2000000000, currentBlock + 3000, {value: 2000000000});
        });
    });
}

The addLiquidity call fails with

1) Test Uniswap
       Add liquidity
         should create a liquidity pool with an initial liquidity:
     Error: VM Exception while processing transaction: invalid JUMP at 84f606a3a88732ef1ca37d72c04534e11d86fa43ccafd8759c3920f51b690aae/4398e3a71c988a9a4db928bc819681b95918a3bf:39
      at getResult (node_modules/etherlime/node_modules/ethers/providers/json-rpc-provider.js:40:21)
      at exports.XMLHttpRequest.request.onreadystatechange (node_modules/etherlime/node_modules/ethers/utils/web.js:111:30)
      at exports.XMLHttpRequest.dispatchEvent (node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
      at setState (node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14)
      at IncomingMessage.<anonymous> (node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
      at endReadableNT (_stream_readable.js:1064:12)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Some of the test scenarios failed!

I have of course tested every property of the liquidity pool (token address, factory address, tokenSupply, ERC20 allowance) to make sure the contract is properly initialised before I call addLiquidity, as well as the ETH and ERC20 balance of the infrastructure account to make sure that none of the assert of the addLiquidity method throws.

What am I missing?

@juniset
Copy link
Author

juniset commented Mar 25, 2019

Issue solved.

For those interested there where 2 reasons why the test failed:

  1. I was passing the block number while the addLiquidity method requires a timestamp.
  2. The ABI generated by Vyper underestimates the gas consumed by the method (at least on Ganache) and the gasLimit needs to be increased

@juniset juniset closed this as completed Mar 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant