Skip to content

Commit

Permalink
[EVM] Fix contract deploy receipts (#1618)
Browse files Browse the repository at this point in the history
fix contract deploy receipts
  • Loading branch information
stevenlanders authored May 2, 2024
1 parent 7f1037f commit 2427f30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions evmrpc/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ func encodeReceipt(receipt *types.Receipt, decoder sdk.TxDecoder, block *coretyp
}
bloom := ethtypes.Bloom{}
bloom.SetBytes(receipt.LogsBloom)

fields := map[string]interface{}{
"blockHash": bh,
"blockNumber": hexutil.Uint64(receipt.BlockNumber),
"transactionHash": common.HexToHash(receipt.TxHashHex),
"transactionIndex": hexutil.Uint64(evmTxIndex),
"from": common.HexToAddress(receipt.From),
"to": common.HexToAddress(receipt.To),
"gasUsed": hexutil.Uint64(receipt.GasUsed),
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
"logs": logs,
Expand All @@ -283,10 +283,13 @@ func encodeReceipt(receipt *types.Receipt, decoder sdk.TxDecoder, block *coretyp
"effectiveGasPrice": (*hexutil.Big)(big.NewInt(int64(receipt.EffectiveGasPrice))),
"status": hexutil.Uint(receipt.Status),
}
if receipt.ContractAddress != "" {
if receipt.ContractAddress != "" && receipt.To == "" {
fields["contractAddress"] = common.HexToAddress(receipt.ContractAddress)
} else {
fields["contractAddress"] = nil
}
if receipt.To != "" {
fields["to"] = common.HexToAddress(receipt.To)
}
return fields, nil
}
11 changes: 9 additions & 2 deletions evmrpc/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
)

func TestGetTxReceipt(t *testing.T) {
receipt, err := EVMKeeper.GetReceipt(Ctx, common.HexToHash("0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e"))
require.Nil(t, err)
receipt.To = ""
EVMKeeper.SetReceipt(Ctx, common.HexToHash("0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e"), receipt)

body := "{\"jsonrpc\": \"2.0\",\"method\": \"eth_getTransactionReceipt\",\"params\":[\"0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e\"],\"id\":\"test\"}"
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s:%d", TestAddr, TestPort), strings.NewReader(body))
require.Nil(t, err)
Expand Down Expand Up @@ -53,15 +58,16 @@ func TestGetTxReceipt(t *testing.T) {
require.Equal(t, "0x0", log["logIndex"].(string))
require.False(t, log["removed"].(bool))
require.Equal(t, "0x0", resObj["status"].(string))
require.Equal(t, "0x1234567890123456789012345678901234567890", resObj["to"].(string))
require.Equal(t, nil, resObj["to"])
require.Equal(t, "0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e", resObj["transactionHash"].(string))
require.Equal(t, "0x0", resObj["transactionIndex"].(string))
require.Equal(t, "0x1", resObj["type"].(string))
require.Equal(t, "0x1234567890123456789012345678901234567890", resObj["contractAddress"].(string))

receipt, err := EVMKeeper.GetReceipt(Ctx, common.HexToHash("0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e"))
receipt, err = EVMKeeper.GetReceipt(Ctx, common.HexToHash("0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e"))
require.Nil(t, err)
receipt.ContractAddress = ""
receipt.To = "0x1234567890123456789012345678901234567890"
EVMKeeper.SetReceipt(Ctx, common.HexToHash("0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e"), receipt)
body = "{\"jsonrpc\": \"2.0\",\"method\": \"eth_getTransactionReceipt\",\"params\":[\"0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e\"],\"id\":\"test\"}"
req, err = http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s:%d", TestAddr, TestPort), strings.NewReader(body))
Expand All @@ -75,6 +81,7 @@ func TestGetTxReceipt(t *testing.T) {
require.Nil(t, json.Unmarshal(resBody, &resObj))
resObj = resObj["result"].(map[string]interface{})
require.Nil(t, resObj["contractAddress"])
require.Equal(t, "0x1234567890123456789012345678901234567890", resObj["to"].(string))

req, err = http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s:%d", TestAddr, TestBadPort), strings.NewReader(body))
require.Nil(t, err)
Expand Down

0 comments on commit 2427f30

Please sign in to comment.