itests: Test EVM bytecode getters, check bytecode hash
This commit is contained in:
parent
8d6aa2477c
commit
554dd2f1ee
@ -50,6 +50,7 @@ type State interface {
|
|||||||
Nonce() (uint64, error)
|
Nonce() (uint64, error)
|
||||||
GetState() interface{}
|
GetState() interface{}
|
||||||
|
|
||||||
|
GetBytecode() ([]byte, error)
|
||||||
GetBytecodeCID() (cid.Cid, error)
|
GetBytecodeCID() (cid.Cid, error)
|
||||||
GetBytecodeHash() ([32]byte, error)
|
GetBytecodeHash() ([32]byte, error)
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ type State interface {
|
|||||||
Nonce() (uint64, error)
|
Nonce() (uint64, error)
|
||||||
GetState() interface{}
|
GetState() interface{}
|
||||||
|
|
||||||
|
GetBytecode() ([]byte, error)
|
||||||
GetBytecodeCID() (cid.Cid, error)
|
GetBytecodeCID() (cid.Cid, error)
|
||||||
GetBytecodeHash() ([32]byte, error)
|
GetBytecodeHash() ([32]byte, error)
|
||||||
}
|
}
|
||||||
|
@ -51,3 +51,17 @@ func (s *state{{.v}}) GetBytecodeCID() (cid.Cid, error) {
|
|||||||
func (s *state{{.v}}) GetBytecodeHash() ([32]byte, error) {
|
func (s *state{{.v}}) GetBytecodeHash() ([32]byte, error) {
|
||||||
return s.State.BytecodeHash, nil
|
return s.State.BytecodeHash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) GetBytecode() ([]byte, error) {
|
||||||
|
bc, err := s.GetBytecodeCID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var byteCode abi.CborBytesTransparent
|
||||||
|
if err := s.store.Get(s.store.Context(), bc, &byteCode); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return byteCode, nil
|
||||||
|
}
|
||||||
|
15
chain/actors/builtin/evm/v10.go
generated
15
chain/actors/builtin/evm/v10.go
generated
@ -3,6 +3,7 @@ package evm
|
|||||||
import (
|
import (
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
evm10 "github.com/filecoin-project/go-state-types/builtin/v10/evm"
|
evm10 "github.com/filecoin-project/go-state-types/builtin/v10/evm"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
@ -51,3 +52,17 @@ func (s *state10) GetBytecodeCID() (cid.Cid, error) {
|
|||||||
func (s *state10) GetBytecodeHash() ([32]byte, error) {
|
func (s *state10) GetBytecodeHash() ([32]byte, error) {
|
||||||
return s.State.BytecodeHash, nil
|
return s.State.BytecodeHash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *state10) GetBytecode() ([]byte, error) {
|
||||||
|
bc, err := s.GetBytecodeCID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var byteCode abi.CborBytesTransparent
|
||||||
|
if err := s.store.Get(s.store.Context(), bc, &byteCode); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return byteCode, nil
|
||||||
|
}
|
||||||
|
@ -11,12 +11,16 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"golang.org/x/crypto/sha3"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
"github.com/filecoin-project/go-state-types/manifest"
|
"github.com/filecoin-project/go-state-types/manifest"
|
||||||
|
gstStore "github.com/filecoin-project/go-state-types/store"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
"github.com/filecoin-project/lotus/blockstore"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/builtin/evm"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||||
"github.com/filecoin-project/lotus/itests/kit"
|
"github.com/filecoin-project/lotus/itests/kit"
|
||||||
@ -219,4 +223,32 @@ func TestDeployment(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
client.AssertActorType(ctx, contractAddr, "evm")
|
client.AssertActorType(ctx, contractAddr, "evm")
|
||||||
|
|
||||||
|
// Check bytecode and bytecode hash match.
|
||||||
|
contractAct, err := client.StateGetActor(ctx, contractAddr, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
bs := blockstore.NewAPIBlockstore(client)
|
||||||
|
ctxStore := gstStore.WrapBlockStore(ctx, bs)
|
||||||
|
|
||||||
|
evmSt, err := evm.Load(ctxStore, contractAct)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
byteCodeCid, err := evmSt.GetBytecodeCID()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
byteCode, err := bs.Get(ctx, byteCodeCid)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
byteCodeHashChain, err := evmSt.GetBytecodeHash()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
hasher := sha3.NewLegacyKeccak256()
|
||||||
|
hasher.Write(byteCode.RawData())
|
||||||
|
byteCodeHash := hasher.Sum(nil)
|
||||||
|
require.Equal(t, byteCodeHashChain[:], byteCodeHash)
|
||||||
|
|
||||||
|
byteCodeSt, err := evmSt.GetBytecode()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, byteCode.RawData(), byteCodeSt)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user