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