Tengo un contrato muy simple. Las pruebas funcionan muy bien en Ganache, pero en Geth obtengo errores de tiempo de ejecución extraños.
Contrato de solidez:
pragma solidity ^0.4.17;
contract SimpleStorage {
mapping(address => uint256) public favoriteNumbers;
function setFavorite(uint x) public {
favoriteNumbers[msg.sender] = x;
}
}
Prueba:
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")
})
Todo es genial en 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)
Cuando ejecuto el mismo contrato en Geth obtengo:
$ 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)
Curiosamente, si cambio la segunda llamada a favouriteNumbers
la línea 11 a const aliceNum = await ssContract.favoriteNumbers.call(alice, 0)
, la prueba pasa en Geth (pero obviamente falla en Ganache).
Otra observación:
ssContract.setFavorite(33, {from: bob})
const newBobNum = await ssContract.favoriteNumbers.call(bob)
Hace lo que esperarías en Ganache al configurarlo newBobNum
en 33. En Geth, el valor se mantiene en 1.
Mi comando Geth se ve así: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
Intenté configurar Geth usando Docker y localmente. Exactamente el mismo error en ambos https://medium.com/@javahippie/building-a-local-ethereum-network-with-docker-and-geth-5b9326b85f37 https://hackernoon.com/setup-your-own-private -prueba-de-autoridad-red-ethereum-con-geth-9a0a3750cda8
Mi archivo de génesis con 2 cuentas:
{
"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"
}
¿Qué estoy haciendo mal? Esto se siente como un problema Geth. Pero dos guías no pueden estar equivocadas, así que probablemente me esté perdiendo algo realmente básico.
Gracias por la ayuda, Pavel
Lógica sencilla:
En el 1er caso -[bob, alice] == [accounts[0], accounts[1]]
En el segundo caso - [bob, alice] == [accounts[0], undefined]
o[undefined, undefined]
Ganache asigna 10 cuentas de forma predeterminada, a menos que indique explícitamente lo contrario, por ejemplo:
ganache-cli
--account=0x0000000000000000000000000000000000000000000000000000000000000001,99999999999
--account=0x0000000000000000000000000000000000000000000000000000000000000002,99999999999
Sin embargo, cuando ejecuta Geth, debe indicar explícitamente cuántas cuentas desea tener.
Entonces, en su genesis.json
archivo Geth, asegúrese de asignar al menos 2 cuentas, por ejemplo:
"alloc": {
"bf9fa87bc92581a1512c658557451965af5316a5": {"balance": "99999999999"},
"0ab1cec1b01b5034b763956b920f9ce8b0afbcec": {"balance": "99999999999"}
}
pavel
buena vibración
pavel
buena vibración
console.log(accounts)
y vea lo que obtiene.pavel