I have this simple contract
pragma solidity ^0.4.10;
contract test {
int _multiplier;
struct MyCustomData {
bool exists;
string Name1;
}
mapping(string => MyCustomData) myData;
event Multiplied(int indexed a, address indexed sender, int result );
function test(int multiplier) {
_multiplier = multiplier;
}
function multiply(int a) returns (int r) {
myData["a"] = MyCustomData(true, "aa1");
r = a * _multiplier;
Multiplied(a, msg.sender, r);
return r;
}
}
when I deploy and run the following code all looks good.
public async Task ContractTest()
{
var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
var password = "password";
var abi = @"[{'constant':false,'inputs':[{'name':'a','type':'int256'}],...";
var byteCode = "0x6060604052341...";
var multiplier = 7;
var web3 = new Web3();
var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, new HexBigInteger(120));
Assert.IsTrue(unlockResult);
var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), multiplier);
var receipt = await MineAndGetReceiptAsync(web3, transactionHash);
var contractAddress = receipt.ContractAddress;
var contract = web3.Eth.GetContract(abi, contractAddress);
var multiplyFunction = contract.GetFunction("multiply");
var multiplyEvent = contract.GetEvent("Multiplied");
var filterAll = await multiplyEvent.CreateFilterAsync();
var filter7 = await multiplyEvent.CreateFilterAsync(7);
var gas = await multiplyFunction.EstimateGasAsync(69) ;
transactionHash = await multiplyFunction.SendTransactionAsync(senderAddress, 7);
transactionHash = await multiplyFunction.SendTransactionAsync(senderAddress, 8);
receipt = await MineAndGetReceiptAsync(web3, transactionHash);
var debuginfo = await web3.DebugGeth.TraceTransaction.SendRequestAsync(transactionHash,
new TraceTransactionOptions { DisableMemory = true, DisableStorage = true, DisableStack = true });
var log = await multiplyEvent.GetFilterChanges<MultipliedEvent>(filterAll);
var log7 = await multiplyEvent.GetFilterChanges<MultipliedEvent>(filter7);
Assert.AreEqual(2, log.Count);
Assert.AreEqual(1, log7.Count);
Assert.AreEqual(7, log7[0].Event.MultiplicationInput);
Assert.AreEqual(49, log7[0].Event.Result);
}
public async Task<TransactionReceipt> MineAndGetReceiptAsync(Web3 web3, string transactionHash)
{
var miningResult = await web3.Miner.Start.SendRequestAsync(200);
Assert.IsTrue(miningResult);
var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
while (receipt == null)
{
Thread.Sleep(1000);
receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
}
miningResult = await web3.Miner.Stop.SendRequestAsync();
Assert.IsTrue(miningResult);
return receipt;
}
BUT when I try to change the struct to
struct MyCustomData {
bool exists;
string Name1;
string Name2;
string Name3;
string Name4;
string Name5;
}
the test fail: Message: Assert.AreEqual failed. Expected:<2>. Actual:<0>.
So looks like the method multiply is not executed. I'm guessing this is a problem with gas, but I tried to add gas to the transaction;transactionHash = await multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(200000), new HexBigInteger(120), 7);
but nothing changed.
Honestly I don't know what to do now. I think I tried everything... Is Nethereum even close to be ready for production?
Friday 12:15 am Any help would be much appreciated Thanks
multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(200000), new HexBigInteger(120), 7);Is it the right way to pass gas? It doesn't seem to work... – Sydney Shown Jun 25 '17 at 15:36