fix: contract address in contract creation receipt (#851)

* Problem: contract address in contract creation receipt is wrong

Closes: #850
- decrease nonce before evm.create
- add unit tests and rpc tests

* add changelog
This commit is contained in:
yihuang
2021-12-28 08:55:40 +01:00
committed by GitHub
parent 8bc3cc471b
commit d822fee5c1
7 changed files with 42 additions and 19 deletions
+13 -9
View File
@@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
const (
@@ -634,18 +635,21 @@ func deployTestContract(t *testing.T) (hexutil.Bytes, map[string]interface{}) {
}
func TestEth_GetTransactionReceipt_ContractDeployment(t *testing.T) {
hash, _ := deployTestContract(t)
nonce := getNonce(t)
_, receipt := deployTestContract(t)
param := []string{hash.String()}
rpcRes := call(t, "eth_getTransactionReceipt", param)
receipt := make(map[string]interface{})
err := json.Unmarshal(rpcRes.Result, &receipt)
addrBz, err := hexutil.Decode(receipt["contractAddress"].(string))
require.NoError(t, err)
require.Equal(t, "0x1", receipt["status"].(string))
require.NotEqual(t, common.Address{}.String(), receipt["contractAddress"].(string))
require.NotNil(t, receipt["logs"])
addr := common.BytesToAddress(addrBz)
require.Equal(t, crypto.CreateAddress(common.BytesToAddress(from), uint64(nonce)), addr)
require.Greater(t, len(receipt["logs"].([]interface{})), 0)
rpcRes := call(t, "eth_getCode", []string{addr.Hex(), "latest"})
var code hexutil.Bytes
err = code.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err)
require.NotEmpty(t, code)
}
func getTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {