fix transaction receipts (#274)

* return ethtypes.Receipt in GetTransactionReceipt

* add PostState to receipts, test working

* add contract addr assert to tests

* update tests

* cleanup, working with web3

* remove print

* update tests
This commit is contained in:
noot
2020-05-02 13:39:26 -04:00
committed by GitHub
parent d3c802f99e
commit 86cd39defb
2 changed files with 47 additions and 9 deletions
+42 -5
View File
@@ -21,6 +21,7 @@ import (
"time"
"github.com/cosmos/ethermint/version"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
@@ -261,6 +262,36 @@ func TestEth_GetFilterChanges_WrongID(t *testing.T) {
require.NotNil(t, err)
}
// sendTestTransaction sends a dummy transaction
func sendTestTransaction(t *testing.T) hexutil.Bytes {
from := getAddress(t)
param := make([]map[string]string, 1)
param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["to"] = "0x1122334455667788990011223344556677889900"
rpcRes, err := call(t, "eth_sendTransaction", param)
require.NoError(t, err)
var hash hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &hash)
require.NoError(t, err)
return hash
}
func TestEth_GetTransactionReceipt(t *testing.T) {
hash := sendTestTransaction(t)
time.Sleep(time.Second * 5)
param := []string{hash.String()}
rpcRes, err := call(t, "eth_getTransactionReceipt", param)
require.NoError(t, err)
receipt := make(map[string]interface{})
err = json.Unmarshal(rpcRes.Result, &receipt)
require.NoError(t, err)
require.Equal(t, "0x1", receipt["status"].(string))
}
// deployTestContract deploys a contract that emits an event in the constructor
func deployTestContract(t *testing.T) hexutil.Bytes {
from := getAddress(t)
@@ -268,7 +299,8 @@ func deployTestContract(t *testing.T) hexutil.Bytes {
param := make([]map[string]string, 1)
param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029"
param[0]["data"] = "0x60806040526000805534801561001457600080fd5b5060d2806100236000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80634f2be91f1460415780636deebae31460495780638ada066e146051575b600080fd5b6047606d565b005b604f6080565b005b60576094565b6040518082815260200191505060405180910390f35b6000808154809291906001019190505550565b600080815480929190600190039190505550565b6000805490509056fea265627a7a723158207b1aaa18c3100d8aa67f26a53f3cb83d2c69342d17327bd11e1b17c248957bfa64736f6c634300050c0032"
param[0]["gas"] = "0x200000"
rpcRes, err := call(t, "eth_sendTransaction", param)
require.NoError(t, err)
@@ -280,17 +312,22 @@ func deployTestContract(t *testing.T) hexutil.Bytes {
return hash
}
func TestEth_GetTransactionReceipt(t *testing.T) {
func TestEth_GetTransactionReceipt_ContractDeployment(t *testing.T) {
hash := deployTestContract(t)
time.Sleep(time.Second * 2)
time.Sleep(time.Second * 5)
param := []string{hash.String()}
rpcRes, err := call(t, "eth_getTransactionReceipt", param)
require.NoError(t, err)
t.Log(rpcRes.Result)
// TODO: why does this not return a receipt?
receipt := make(map[string]interface{})
err = json.Unmarshal(rpcRes.Result, &receipt)
require.NoError(t, err)
require.Equal(t, "0x1", receipt["status"].(string))
require.NotEqual(t, ethcmn.Address{}.String(), receipt["contractAddress"].(string))
// TODO: assert logs exist
}
func TestEth_GetTxLogs(t *testing.T) {