1

Hey so I have been just messing around with truffle and I keep getting an out of gas error when I test out the commands after a certain point. Even if I uninstall and reinstall testrpc, the problem persists.

I apologize for the code formatting issues.

Keep in mind, all I want to do is just have unlimited gas in my test environment.

here is my code `

  contract Organization {



 struct Proposal {
   uint code;
   uint amount;
  string description;
  uint numberOfVotes;
  string name;
}

Proposal[] public proposals;
uint public numberOfProposals;


 event ProposalAdded(uint code, uint amount, string description, int 
 numberOfVotes , string name);


 function addProposal(uint amount, string description , string name) 
 returns (uint) {

proposals.push(Proposal(numberOfProposals,amount,description,0,name));
ProposalAdded(numberOfProposals,amount,description, 0, name);
numberOfProposals++;
return numberOfProposals;

}



 function proposalExists (uint code) returns (bool) {
   for(uint i = 0; i < proposals.length; i++) {
     if (proposals[i].code == code) {
        return true;
      }
    }
     return false;
 }

function numOfProposals() returns (uint){
    return numberOfProposals;
  }

function getProposalName(uint index) returns (string){
    return proposals[index].name;
}

function getProposalDescription(uint index) returns (string){
    return proposals[index].description;
}

function getProposalIndex(string name) returns (uint){
  for(uint i = 0; i < proposals.length; i++) {
      bytes memory a = bytes(proposals[i].name);
      bytes memory b = bytes(name);
    if (a.length == b.length) {
        return i;
    }
  }
  return 1000000;
}

function voteFotProposal(uint index) {
    proposals[index].numberOfVotes++;
  }

function getProposalVotesIndex(uint index) {
    proposals[index].numberOfVotes;
  }


struct Memmber {
  uint id;
  string name;
}

struct Commitee {
  uint id;
  string name;
  string missionStatement;
  uint balance;
  string [] memmbers;
}

event MemmberAdded(uint id, string name);
event CommiteeCreated(string name,string missionStatement );

string [] public memmbersArray;
string[] public comitees;
uint public numOfComitees = 0;
uint public numOfTotalMemmbers = 0;
Commitee [] fullComitees;




  function convertMemmberStrings (bytes32 [] values) internal returns 
  (string []){

        for(uint i=0;i<values.length;i++){
            MemmberAdded(numOfTotalMemmbers, 
            bytes32ToString(values[i]));
            memmbersArray.push(bytes32ToString(values[i]));
            numOfTotalMemmbers++;
    }
    return memmbersArray;
}


function addCommitee 
(string name, string missionStatement , uint funds, bytes32 [] values)
returns (string)
{
  comitees.push(name);
  CommiteeCreated(name,missionStatement );
  fullComitees.push(Commitee(numOfComitees, name, missionStatement, funds, convertMemmberStrings(values)));
  numOfComitees++;
  return name;
}

function getComitees (uint index) returns (string){
  return comitees[index];
}

function numberOfCommitees () returns (uint){
  return numOfComitees;
}

 function bytes32ToString(bytes32 x) constant returns (string) {
    bytes memory bytesString = new bytes(32);
    uint charCount = 0;
    for (uint j = 0; j < 32; j++) {
      byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
      if (char != 0) {
        bytesString[charCount] = char;
        charCount++;
     }
 }
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
    bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}

 function uintToBytes(uint v) constant returns (bytes32 ret) {
    if (v == 0) {
      ret = '0';
   }
   else {
    while (v > 0) {
        ret = bytes32(uint(ret) / (2 ** 8));
        ret |= bytes32(((v % 10) + 48) * 2 ** (8 * 31));
        v /= 10;
    }
 }
 return ret;
}


}

`

  • How are you running testrpc ? – 0xcaff Jun 16 '17 at 1:06
  • just via the command testrpc – Grant Herman Jun 16 '17 at 13:20
2

You can increase the gas limit of the block by starting testrpc with a higher limit

testrpc -l 4500000000000

0

I was facing the same errors. Strings a very expensive in the EVM. Try bytes or try to avoid strings. I had similar problems with my dApp and Smart Contract. I removed all strings (thus redesigned) and now all works just fine. Also your events are requesting a lot of parameters and hence a require a lot of gas. comment out your event calls and try your functions again. Testrpc has a limit on the amount of gas you can give each transaction. So try to execute your commands in multiple transactions. Use Remix online compiler to see if your functions are working correctly.That allows unlimited gas.

0

https://github.com/trufflesuite/ganache-cli/releases/tag/v3.0.0

TestRPC 3.0.0 Breaking Changes: Default gas limit for transactions is now 90000 gas instead of the full block gas limit.

To avoid these new out of gas errors, you can now pass a higher gas limit as a parameter to web3:

web3.eth.sendTransaction({..., gas: 3141592}) // choose your own gas limit suitable for you

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.