6

I've got some code that's ultimately destined to run on a private network. I'm testing it with the lovely pyethereum, doing things like:

from ethereum import tester as t

class testMyContract(TestCase):
   def setUp(self):
      self.s = t.state()
      code = open('../mycontract.sol').read()
      self.mycontract = self.s.abi_contract(code, language='solidity', sender=t.k0)

   def testExpensiveThing(self):
     mydata = [1000, 3000, 2000, 8000]
     self.mycontract.doExpensiveThing(mydata)

This blows up with

  File "/usr/local/lib/python2.7/dist-packages/ethereum/tester.py", line 201, in _send
    raise TransactionFailed()
TransactionFailed

It doesn't blow up when I pass it less data, and the contract looks quite expensive, so I'm assuming it's breaking because it's running out of gas. Is there a way to pass pyethereum some settings that will allow the transaction to use more gas?

Edmund Edgar
  • 16,897
  • 1
  • 29
  • 58

2 Answers2

5

Use t.gas_limit and t.gas_price.

For gas limit, since you usually only want to set it once:

Set t.gas_limit before t.state(). Example t.gas_limit = 3000000

Otherwise can do self.s.abi_contract(code, gas=3000000,...

(You can set the gas_limit much higher for testing purposes so that you can deploy a very big contract, but best to keep it lower than the real network's block gas limit so that contracts will be deployable on the real network.)

eth
  • 85,679
  • 53
  • 285
  • 406
4

You can change the start gas here:

self.mycontract = self.s.abi_contract(code, gas=3000000, language='solidity', sender=t.k0)

But I'm not sure if that's the actual problem

dbryson
  • 6,403
  • 2
  • 27
  • 37