Skip to content

Commit

Permalink
simulators/ethereum/engine: Refactor Legacy Engine API Tests (ethereu…
Browse files Browse the repository at this point in the history
…m#840)

* Refactor previous tests to run on new forks

* Fix configuration on Cancun

* Fix spec fork time

* Run all tests using blob transactions when possible

* Allow blob transaction modifications

* Add more Cancun invalid field tests

* Update expected invalid detection on versioned hashes

* Use multiple source accounts for test transactions by default

* Get full block only when necessary

* Fixes on some of the tests

* Update suggested fee recipient tests

* Update prev-randao tests

* NewPayload Tests Refactor

* Refactor last re-org tests

* Simplify ForkID tests

* Incorrect comment

* Fix pyspec

* More Versioned Hashes Tests
  • Loading branch information
marioevz authored and Eikix committed Mar 1, 2024
1 parent 992463d commit a323ae7
Show file tree
Hide file tree
Showing 57 changed files with 5,707 additions and 4,617 deletions.
98 changes: 0 additions & 98 deletions simulators/ethereum/engine/chains/README.md

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 12 additions & 5 deletions simulators/ethereum/engine/client/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Eth interface {
BlockNumber(ctx context.Context) (uint64, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
SendTransaction(ctx context.Context, tx typ.Transaction) error
SendTransactions(ctx context.Context, txs ...typ.Transaction) []error
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
Expand All @@ -39,10 +40,10 @@ type Engine interface {
GetPayloadV3(ctx context.Context, payloadId *api.PayloadID) (typ.ExecutableData, *big.Int, *typ.BlobsBundle, *bool, error)
GetPayload(ctx context.Context, version int, payloadId *api.PayloadID) (typ.ExecutableData, *big.Int, *typ.BlobsBundle, *bool, error)

NewPayload(ctx context.Context, version int, payload interface{}, versionedHashes *[]common.Hash, beaconRoot *common.Hash) (api.PayloadStatusV1, error)
NewPayloadV1(ctx context.Context, payload *typ.ExecutableDataV1) (api.PayloadStatusV1, error)
NewPayload(ctx context.Context, version int, payload *typ.ExecutableData) (api.PayloadStatusV1, error)
NewPayloadV1(ctx context.Context, payload *typ.ExecutableData) (api.PayloadStatusV1, error)
NewPayloadV2(ctx context.Context, payload *typ.ExecutableData) (api.PayloadStatusV1, error)
NewPayloadV3(ctx context.Context, payload *typ.ExecutableData, versionedHashes *[]common.Hash, beaconRoot *common.Hash) (api.PayloadStatusV1, error)
NewPayloadV3(ctx context.Context, payload *typ.ExecutableData) (api.PayloadStatusV1, error)

GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*typ.ExecutionPayloadBodyV1, error)
GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*typ.ExecutionPayloadBodyV1, error)
Expand All @@ -54,15 +55,21 @@ type Engine interface {
LatestNewPayloadResponse() (payloadResponse *api.PayloadStatusV1)
}

type EngineAPIVersionResolver interface {
ForkchoiceUpdatedVersion(headTimestamp uint64, payloadAttributesTimestamp *uint64) int
NewPayloadVersion(timestamp uint64) int
GetPayloadVersion(timestamp uint64) int
}

type EngineClient interface {
// General Methods
ID() string
Close() error
EnodeURL() (string, error)

// Local Test Account Management
GetLastAccountNonce(testCtx context.Context, account common.Address) (uint64, error)
GetNextAccountNonce(testCtx context.Context, account common.Address) (uint64, error)
GetLastAccountNonce(testCtx context.Context, account common.Address, head *types.Header) (uint64, error)
GetNextAccountNonce(testCtx context.Context, account common.Address, head *types.Header) (uint64, error)
UpdateNonce(testCtx context.Context, account common.Address, newNonce uint64) error

// TTD Methods
Expand Down
49 changes: 27 additions & 22 deletions simulators/ethereum/engine/client/hive_rpc/hive_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,34 +454,33 @@ func (ec *HiveRPCEngineClient) GetBlobsBundleV1(ctx context.Context, payloadId *
}

// New Payload API Call Methods
func (ec *HiveRPCEngineClient) NewPayload(ctx context.Context, version int, payload interface{}, versionedHashes *[]common.Hash, beaconRoot *common.Hash) (result api.PayloadStatusV1, err error) {
func (ec *HiveRPCEngineClient) NewPayload(ctx context.Context, version int, payload *typ.ExecutableData) (result api.PayloadStatusV1, err error) {
if err := ec.PrepareDefaultAuthCallToken(); err != nil {
return result, err
}

if version >= 3 {
err = ec.c.CallContext(ctx, &result, fmt.Sprintf("engine_newPayloadV%d", version), payload, versionedHashes, beaconRoot)
err = ec.c.CallContext(ctx, &result, fmt.Sprintf("engine_newPayloadV%d", version), payload, payload.VersionedHashes, payload.ParentBeaconBlockRoot)
} else {
err = ec.c.CallContext(ctx, &result, fmt.Sprintf("engine_newPayloadV%d", version), payload)
}
ec.latestPayloadStatusReponse = &result
return result, err
}

func (ec *HiveRPCEngineClient) NewPayloadV1(ctx context.Context, payload *typ.ExecutableDataV1) (api.PayloadStatusV1, error) {
ed := payload.ToExecutableData()
ec.latestPayloadSent = &ed
return ec.NewPayload(ctx, 1, payload, nil, nil)
func (ec *HiveRPCEngineClient) NewPayloadV1(ctx context.Context, payload *typ.ExecutableData) (api.PayloadStatusV1, error) {
ec.latestPayloadSent = payload
return ec.NewPayload(ctx, 1, payload)
}

func (ec *HiveRPCEngineClient) NewPayloadV2(ctx context.Context, payload *typ.ExecutableData) (api.PayloadStatusV1, error) {
ec.latestPayloadSent = payload
return ec.NewPayload(ctx, 2, payload, nil, nil)
return ec.NewPayload(ctx, 2, payload)
}

func (ec *HiveRPCEngineClient) NewPayloadV3(ctx context.Context, payload *typ.ExecutableData, versionedHashes *[]common.Hash, beaconRoot *common.Hash) (api.PayloadStatusV1, error) {
func (ec *HiveRPCEngineClient) NewPayloadV3(ctx context.Context, payload *typ.ExecutableData) (api.PayloadStatusV1, error) {
ec.latestPayloadSent = payload
return ec.NewPayload(ctx, 3, payload, versionedHashes, beaconRoot)
return ec.NewPayload(ctx, 3, payload)
}

// Exchange Transition Configuration API Call Methods
Expand All @@ -501,13 +500,16 @@ func (ec *HiveRPCEngineClient) ExchangeCapabilities(ctx context.Context, clCapab
}

// Account Nonce
func (ec *HiveRPCEngineClient) GetLastAccountNonce(testCtx context.Context, account common.Address) (uint64, error) {
func (ec *HiveRPCEngineClient) GetLastAccountNonce(testCtx context.Context, account common.Address, head *types.Header) (uint64, error) {
// First get the current head of the client where we will send the tx
ctx, cancel := context.WithTimeout(testCtx, globals.RPCTimeout)
defer cancel()
head, err := ec.HeaderByNumber(ctx, nil)
if err != nil {
return 0, err
if head == nil {
ctx, cancel := context.WithTimeout(testCtx, globals.RPCTimeout)
defer cancel()
var err error
head, err = ec.HeaderByNumber(ctx, nil)
if err != nil {
return 0, err
}
}

// Then check if we have any info about this account, and when it was last updated
Expand All @@ -520,13 +522,16 @@ func (ec *HiveRPCEngineClient) GetLastAccountNonce(testCtx context.Context, acco
return 0, fmt.Errorf("no previous nonce for account %s", account.String())
}

func (ec *HiveRPCEngineClient) GetNextAccountNonce(testCtx context.Context, account common.Address) (uint64, error) {
func (ec *HiveRPCEngineClient) GetNextAccountNonce(testCtx context.Context, account common.Address, head *types.Header) (uint64, error) {
// First get the current head of the client where we will send the tx
ctx, cancel := context.WithTimeout(testCtx, globals.RPCTimeout)
defer cancel()
head, err := ec.HeaderByNumber(ctx, nil)
if err != nil {
return 0, err
if head == nil {
ctx, cancel := context.WithTimeout(testCtx, globals.RPCTimeout)
defer cancel()
var err error
head, err = ec.HeaderByNumber(ctx, nil)
if err != nil {
return 0, err
}
}
// Then check if we have any info about this account, and when it was last updated
if accTxInfo, ok := ec.accTxInfoMap[account]; ok && accTxInfo != nil && (accTxInfo.PreviousBlock == head.Hash() || accTxInfo.PreviousBlock == head.ParentHash) {
Expand All @@ -537,7 +542,7 @@ func (ec *HiveRPCEngineClient) GetNextAccountNonce(testCtx context.Context, acco
return accTxInfo.PreviousNonce, nil
}
// We don't have info about this account, or is outdated, or we re-org'd, we must request the nonce
ctx, cancel = context.WithTimeout(testCtx, globals.RPCTimeout)
ctx, cancel := context.WithTimeout(testCtx, globals.RPCTimeout)
defer cancel()
nonce, err := ec.NonceAt(ctx, account, head.Number)
if err != nil {
Expand Down
Loading

0 comments on commit a323ae7

Please sign in to comment.