1

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

  • Hi, can you check that you have not ran out of gas by checking the transaction receipt, and see if the gas used matches the gas sent? – Juan Blanco Jun 23 '17 at 20:47
  • Hi, thanks for your quick response. Yes when I send gas with SendTransactionAsync the gas used in the receipt matches the gas sent. But the EstimateGasAsync says that the estimated gas is: 146174. I tried to send a really big amout of gas but it always fails. – Sydney Shown Jun 24 '17 at 12:18
  • EstimateGas is not reliable on geth, but also it might be an error on your code. Have you checked on remix? or use debug on geth to get the error (it will be the last entry on the transaction output) github.com/ethereum/go-ethereum/wiki/… – Juan Blanco Jun 24 '17 at 16:00
  • yes it works in remix. Also I don't see any error when I call: web3.DebugGeth.TraceTransaction. – Sydney Shown Jun 25 '17 at 15:18
  • I'm using geth version 1.5.5 on windows. But I think that the problem is: 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
0

After few days of trying, I finally found what was the problem. The declaration of the function method multiply was missing the payable definition.

function multiply(int a) payable returns (int r) { ... }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.