fix send then deploy test
We changed how we compute addresses. It's still broken due to a bug in the EAM, but the _test_ is now correct(ly failing).
This commit is contained in:
parent
51d77d408b
commit
b4714c6f3e
@ -3,13 +3,14 @@ package itests
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"golang.org/x/crypto/sha3"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@ -26,6 +27,24 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/itests/kit"
|
"github.com/filecoin-project/lotus/itests/kit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func effectiveEthAddressForCreate(t *testing.T, sender address.Address) ethtypes.EthAddress {
|
||||||
|
switch sender.Protocol() {
|
||||||
|
case address.SECP256K1, address.BLS:
|
||||||
|
hasher := sha3.NewLegacyKeccak256()
|
||||||
|
hasher.Write(sender.Bytes())
|
||||||
|
addr, err := ethtypes.CastEthAddress(hasher.Sum(nil)[12:])
|
||||||
|
require.NoError(t, err)
|
||||||
|
return addr
|
||||||
|
case address.Delegated:
|
||||||
|
addr, err := ethtypes.EthAddressFromFilecoinAddress(sender)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return addr
|
||||||
|
default:
|
||||||
|
require.FailNow(t, "unsupported protocol %d", sender.Protocol())
|
||||||
|
}
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddressCreationBeforeDeploy(t *testing.T) {
|
func TestAddressCreationBeforeDeploy(t *testing.T) {
|
||||||
kit.QuietMiningLogs()
|
kit.QuietMiningLogs()
|
||||||
|
|
||||||
@ -45,18 +64,11 @@ func TestAddressCreationBeforeDeploy(t *testing.T) {
|
|||||||
|
|
||||||
fromAddr, err := client.WalletDefaultAddress(ctx)
|
fromAddr, err := client.WalletDefaultAddress(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fromId, err := client.StateLookupID(ctx, fromAddr, types.EmptyTSK)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
senderEthAddr, err := ethtypes.EthAddressFromFilecoinAddress(fromId)
|
// We hash the f1/f3 address into the EVM's address space when deploying contracts from
|
||||||
require.NoError(t, err)
|
// accounts.
|
||||||
|
effectiveEvmAddress := effectiveEthAddressForCreate(t, fromAddr)
|
||||||
var salt [32]byte
|
ethAddr := client.EVM().ComputeContractAddress(effectiveEvmAddress, 1)
|
||||||
binary.BigEndian.PutUint64(salt[:], 1)
|
|
||||||
|
|
||||||
// Generate contract address before actually deploying contract
|
|
||||||
ethAddr, err := ethtypes.GetContractEthAddressFromCode(senderEthAddr, salt, contract)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
contractFilAddr, err := ethAddr.ToFilecoinAddress()
|
contractFilAddr, err := ethAddr.ToFilecoinAddress()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -105,11 +117,11 @@ func TestAddressCreationBeforeDeploy(t *testing.T) {
|
|||||||
require.Equal(t, exitcode.Ok, wait.Receipt.ExitCode)
|
require.Equal(t, exitcode.Ok, wait.Receipt.ExitCode)
|
||||||
|
|
||||||
// Check if eth address returned from Create2 is the same as eth address predicted at the start
|
// Check if eth address returned from Create2 is the same as eth address predicted at the start
|
||||||
var create2Return eam.Create2Return
|
var createExternalReturn eam.CreateExternalReturn
|
||||||
err = create2Return.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return))
|
err = createExternalReturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
createdEthAddr, err := ethtypes.CastEthAddress(create2Return.EthAddress[:])
|
createdEthAddr, err := ethtypes.CastEthAddress(createExternalReturn.EthAddress[:])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, ethAddr, createdEthAddr)
|
require.Equal(t, ethAddr, createdEthAddr)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user