Ich habe einen ganz einfachen Vertrag. Auf Ganache laufen die Tests super, aber auf Geth bekomme ich seltsame Laufzeitfehler.
Soliditätsvertrag:
pragma solidity ^0.4.17;
contract SimpleStorage {
mapping(address => uint256) public favoriteNumbers;
function setFavorite(uint x) public {
favoriteNumbers[msg.sender] = x;
}
}
Prüfen:
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")
})
Alles ist großartig 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)
Wenn ich denselben Vertrag auf Geth ausführe, erhalte ich:
$ 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)
Interessanterweise, wenn ich den zweiten Aufruf in favouriteNumbers
Zeile 11 zu ändere const aliceNum = await ssContract.favoriteNumbers.call(alice, 0)
, wird der Test in Geth bestanden (aber offensichtlich in Ganache fehlgeschlagen).
Eine weitere Beobachtung:
ssContract.setFavorite(33, {from: bob})
const newBobNum = await ssContract.favoriteNumbers.call(bob)
Tut das, was Sie in Ganache erwarten würden, indem Sie es newBobNum
auf 33 setzen. In Geth bleibt der Wert bei 1.
Mein Geth-Befehl sieht so aus: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
Ich habe versucht, Geth sowohl mit Docker als auch lokal einzurichten. Genau der gleiche Fehler in beiden 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
Meine Genesis-Datei mit 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"
}
Was mache ich falsch? Das fühlt sich an wie ein Geth-Problem. Aber zwei Anleitungen können nicht beide falsch sein, also fehlt mir wahrscheinlich etwas wirklich Grundlegendes.
Danke für die Hilfe, Pawel
Einfache Logik:
Im 1. Fall -[bob, alice] == [accounts[0], accounts[1]]
Im 2. Fall - [bob, alice] == [accounts[0], undefined]
bzw[undefined, undefined]
Ganache weist standardmäßig 10 Konten zu, sofern Sie nicht ausdrücklich etwas anderes angeben, zum Beispiel:
ganache-cli
--account=0x0000000000000000000000000000000000000000000000000000000000000001,99999999999
--account=0x0000000000000000000000000000000000000000000000000000000000000002,99999999999
Wenn Sie Geth ausführen, müssen Sie jedoch explizit angeben, wie viele Konten Sie haben möchten.
Stellen Sie also in Ihrer Geth- genesis.json
Datei sicher, dass Sie mindestens 2 Konten zuweisen, zum Beispiel:
"alloc": {
"bf9fa87bc92581a1512c658557451965af5316a5": {"balance": "99999999999"},
"0ab1cec1b01b5034b763956b920f9ce8b0afbcec": {"balance": "99999999999"}
}
Pavel
gute Stimmung
Pavel
gute Stimmung
console.log(accounts)
und sieh, was du bekommst.Pavel