pipermerriam / eth-testrpc

Used for testing all maner of Ethereum JSON-RPC interactions.
MIT License
163 stars 46 forks source link

Sending value to a contract doesn't seem to work #113

Open agroce opened 6 years ago

agroce commented 6 years ago

This code gives a TransactionFailed. If I change value to 0, it works, but then I can't actually have contracts use send/transfer. It also doesn't work to do a send transaction with the to being the contractAddress.

from testrpc.client import EthTesterClient
from solc import *
from solc.exceptions import SolcError

c = EthTesterClient()

ac = sorted(c.get_accounts())

contract = """
contract c {

function f() returns (int) {
  return 10;
}

}
"""

bin = compile_source(contract,optimize=True).values()[0]['bin']

txnHash = c.send_transaction(_from = ac[0], data = bytes(bin), value=1000)

txnReceipt = c.get_transaction_receipt(txnHash)
contractAddress = txnReceipt['contractAddress']

print (contractAddress), c.get_balance(contractAddress)
agroce commented 6 years ago

(not using solc-py and just including the contract bin, even the one from tests/client/test_call.py, doesn't help)