0

I have a really simple contract. The tests run great on Ganache, but on Geth I get strange runtime errors.

Solidity contract:

pragma solidity ^0.4.17;

contract SimpleStorage {
  mapping(address => uint256) public favoriteNumbers;

  function setFavorite(uint x) public {
    favoriteNumbers[msg.sender] = x;
  }
}

Test:

const SimpleStorage = artifacts.require("SimpleStorage") 

contract('SimpleStorage', (accounts) => {
    const [bob, alice] = accounts
    it("should verify bob and alice's favorite numbers default to 0", async () => {
        const ssContract = await SimpleStorage.deployed()
        const bobNum = await ssContract.favoriteNumbers.call(bob)
        assert.equal(bobNum, 0,
            "bob's default value was non-zero")

        const aliceNum = await ssContract.favoriteNumbers.call(alice)
        assert.equal(aliceNum, 0,
            "alice's default value was non-zero")
    })

Everything is great in Ganache:

$ truffle test --network ganache  --reset --compile-all
Using network 'ganache'.

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/SimpleStorage.sol...


  Contract: SimpleStorage
    ✓ should verify bob and alice's favorite numbers default to 0 (85ms)


  1 passing (168ms)

When I run the same contract on Geth I get:

$ truffle test --network devlocal  --reset --compile-all
Using network 'devlocal'.

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/SimpleStorage.sol...


  Contract: SimpleStorage
    1) should verify bob and alice's favorite numbers default to 0
    > No events were emitted


  0 passing (27ms)
  1 failing

  1) Contract: SimpleStorage
       should verify bob and alice's favorite numbers default to 0:
     Error: Invalid number of arguments to Solidity function
      at Object.InvalidNumberOfSolidityArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:25:1)
      at SolidityFunction.validateArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:74:1)
      at SolidityFunction.toPayload (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:90:1)
      at SolidityFunction.call (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:131:1)
      at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:135:1
      at new Promise (<anonymous>)
      at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:126:1
      at process._tickCallback (internal/process/next_tick.js:68:7)

Interestingly, if I change the second call to favouriteNumbers on line 11 to const aliceNum = await ssContract.favoriteNumbers.call(alice, 0), then the test passes in Geth (but fails in Ganache obviously).

Another observation:

ssContract.setFavorite(33, {from: bob})
const newBobNum = await ssContract.favoriteNumbers.call(bob)

Does what you would expect in Ganache by setting newBobNum to 33. In Geth, the value stays as 1.

My Geth command looks like this: geth --datadir node1/ --syncmode 'full' --port 30310 --rpc --rpcaddr 'localhost' --rpcport 8501 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://3fb9ff124dc8a51ef4b70bc1204efd0a4f3421965c396e027a9774aa0b9ee322e c9215c5440f695a059b96a98c2ed175ffb114f586cd002700bc2857ebdd3d59@127.0.0.1:30304' --networkid 1515 --gasprice '1' -unlock '0xa94 2cf835a063c110ee5ebd80277ef6a87c7e7cc' --password node1/password.txt --mine

I have tried setting up Geth using Docker as well as locally. Exact same error in both https://medium.com/@javahippie/building-a-local-ethereum-network-with-docker-and-geth-5b9326b85f37 https://hackernoon.com/setup-your-own-private-proof-of-authority-ethereum-network-with-geth-9a0a3750cda8

My genesis file with 2 accounts:

 {
  "config": {
    "chainId": 555,
    "homesteadBlock": 1,
    "eip150Block": 2,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 3,
    "eip158Block": 3,
    "byzantiumBlock": 4,
    "clique": {
      "period": 2,
      "epoch": 30000
    }
  },
  "nonce": "0x0",
  "timestamp": "0x5b97603b",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000370c66e48e5d3e4eef6c9f1cd8e060107a02c60aa942cf835a063c110ee5ebd80277ef6a87c7e7cc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {

    "370c66e48e5d3e4eef6c9f1cd8e060107a02c60a": {
      "balance": "0x2000000000000000000000000000000000000000000000000000000000000"
    },
    "a942cf835a063c110ee5ebd80277ef6a87c7e7cc": {
      "balance": "0x2000000000000000000000000000000000000000000000000000000000000"
    }
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

What am I doing wrong? This feels like a Geth issue. But two guides can't both be wrong, so I'm probably missing something really basic.

Thank you for the help, Pavel

1

Simple logic:

In the 1st case - [bob, alice] == [accounts[0], accounts[1]]

In the 2nd case - [bob, alice] == [accounts[0], undefined] or [undefined, undefined]

Ganache allocates 10 accounts by default, unless you explicitly state otherwise, for example:

ganache-cli
--account=0x0000000000000000000000000000000000000000000000000000000000000001,99999999999
--account=0x0000000000000000000000000000000000000000000000000000000000000002,99999999999

However, when you run Geth, you need to explicitly state how many accounts you want have.

So in your Geth genesis.json file, make sure that you allocate at least 2 accounts, for example:

"alloc": {
     "bf9fa87bc92581a1512c658557451965af5316a5": {"balance": "99999999999"},
     "0ab1cec1b01b5034b763956b920f9ce8b0afbcec": {"balance": "99999999999"}
 }
  • Thanks for the feedback. I have two accounts in my genesis file. – Pavel Sep 17 '18 at 5:36
  • @Pavel: Make sure you unlock them (as Ganache does internally). – goodvibration Sep 17 '18 at 5:38
  • I think they are unlocked. I see this in Geth output early on: INFO [09-17|14:42:23.387] Unlocked account address=0xa942Cf835a063c110eE5eBd80277EF6A87C7E7cc INFO [09-17|14:42:23.387] Transaction pool price threshold updated price=1 INFO [09-17|14:42:23.387] Etherbase automatically configured address=0xa942Cf835a063c110eE5eBd80277EF6A87C7E7cc INFO [09-17|14:42:23.387] Commit new mining work number=1 uncles=0 txs=0 gas=0 fees=0 elapsed=181.481µs – Pavel Sep 17 '18 at 5:45
  • @Pavel: add console.log(accounts) and see what you get. – goodvibration Sep 17 '18 at 5:46
  • Thanks. That was it. I was unlocking only 1 account per Geth instance. After creating a couple of more accounts and passing them to each instance of Geth, it no longer complains about this part. – Pavel Sep 17 '18 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.