Been testing Nethereum and attempting to get a basic test class running as per the Nethereum documentation, but having trouble when running the mining command.
- I am using Geth v1.6.6
- Running the Nethereum testchain via
https://github.com/Nethereum/Nethereum/tree/master/testchain
Issue
Miner.Start was always bringing back "false" to begin with. Then I stumbled on to this question Nethereum 2.0.0-rc5 Miner which mentions that I should try using the pre-release where Web3Geth is the new way to call mining, trying both ways, I am still unable to get a true value to then continue with my test.
var mineResult = await web3Geth.Miner.Start.SendRequestAsync(6); //var mineResult = await web3.Miner.Start.SendRequestAsync(6);
This is my XUnit test class where the issue is happening.
using System.Threading;
using System.Threading.Tasks;
using Nethereum.Geth;
using Nethereum.Hex.HexTypes;
using Nethereum.Web3;
using Xunit;
namespace BasicTurorial
{
public class TestClass
{
[Fact]
public async Task ShouldBeAbleToDeployAContract()
{
var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
var password = "password";
var abi = @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""payable"":false,""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""payable"":false,""type"":""constructor""}]";
var byteCode =
"0x60606040523415600b57fe5b6040516020806100ac83398101604052515b60008190555b505b6079806100336000396000f300606060405263ffffffff60e060020a6000350416631df4f14481146020575bfe5b3415602757fe5b60306004356042565b60408051918252519081900360200190f35b60005481025b9190505600a165627a7a72305820ec2cf1c300fa92e0ccd1f5ce518cc43c9578fe9007797024f1424d07f491020a0029";
var multiplier = 7;
var web3 = new Web3();
var web3Geth = new Web3Geth();
var unlockAccountResult =
await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, 120);
Assert.True(unlockAccountResult);
var transactionHash =
await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, multiplier);
var mineResult = await web3Geth.Miner.Start.SendRequestAsync(6);
//var mineResult = await web3.Miner.Start.SendRequestAsync(6);
Assert.True(mineResult);
var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
while (receipt == null)
{
Thread.Sleep(5000);
receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
}
var contractAddress = receipt.ContractAddress;
var contract = web3.Eth.GetContract(abi, contractAddress);
var multiplyFunction = contract.GetFunction("multiply");
var result = await multiplyFunction.CallAsync<int>(7);
Assert.Equal(49, result);
}
}
}
Full sourcecode can be found here https://github.com/stradled/NethereumTest