@ -25,13 +25,13 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus"
beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon"
beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth"
@ -105,7 +105,7 @@ func TestEth2AssembleBlock(t *testing.T) {
t . Fatalf ( "error signing transaction, err=%v" , err )
t . Fatalf ( "error signing transaction, err=%v" , err )
}
}
ethservice . TxPool ( ) . AddLocal ( tx )
ethservice . TxPool ( ) . AddLocal ( tx )
blockParams := b eaco n. PayloadAttributes {
blockParams := engine . PayloadAttributes {
Timestamp : blocks [ 9 ] . Time ( ) + 5 ,
Timestamp : blocks [ 9 ] . Time ( ) + 5 ,
}
}
// The miner needs to pick up on the txs in the pool, so a few retries might be
// The miner needs to pick up on the txs in the pool, so a few retries might be
@ -117,7 +117,7 @@ func TestEth2AssembleBlock(t *testing.T) {
// assembleWithTransactions tries to assemble a block, retrying until it has 'want',
// assembleWithTransactions tries to assemble a block, retrying until it has 'want',
// number of transactions in it, or it has retried three times.
// number of transactions in it, or it has retried three times.
func assembleWithTransactions ( api * ConsensusAPI , parentHash common . Hash , params * b eaco n. PayloadAttributes , want int ) ( execData * b eaco n. ExecutableData , err error ) {
func assembleWithTransactions ( api * ConsensusAPI , parentHash common . Hash , params * engine . PayloadAttributes , want int ) ( execData * engine . ExecutableData , err error ) {
for retries := 3 ; retries > 0 ; retries -- {
for retries := 3 ; retries > 0 ; retries -- {
execData , err = assembleBlock ( api , parentHash , params )
execData , err = assembleBlock ( api , parentHash , params )
if err != nil {
if err != nil {
@ -141,7 +141,7 @@ func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) {
// Put the 10th block's tx in the pool and produce a new block
// Put the 10th block's tx in the pool and produce a new block
api . eth . TxPool ( ) . AddRemotesSync ( blocks [ 9 ] . Transactions ( ) )
api . eth . TxPool ( ) . AddRemotesSync ( blocks [ 9 ] . Transactions ( ) )
blockParams := b eaco n. PayloadAttributes {
blockParams := engine . PayloadAttributes {
Timestamp : blocks [ 8 ] . Time ( ) + 5 ,
Timestamp : blocks [ 8 ] . Time ( ) + 5 ,
}
}
// The miner needs to pick up on the txs in the pool, so a few retries might be
// The miner needs to pick up on the txs in the pool, so a few retries might be
@ -157,14 +157,14 @@ func TestSetHeadBeforeTotalDifficulty(t *testing.T) {
defer n . Close ( )
defer n . Close ( )
api := NewConsensusAPI ( ethservice )
api := NewConsensusAPI ( ethservice )
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : blocks [ 5 ] . Hash ( ) ,
HeadBlockHash : blocks [ 5 ] . Hash ( ) ,
SafeBlockHash : common . Hash { } ,
SafeBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
}
}
if resp , err := api . ForkchoiceUpdatedV1 ( fcState , nil ) ; err != nil {
if resp , err := api . ForkchoiceUpdatedV1 ( fcState , nil ) ; err != nil {
t . Errorf ( "fork choice updated should not error: %v" , err )
t . Errorf ( "fork choice updated should not error: %v" , err )
} else if resp . PayloadStatus . Status != b eaco n. INVALID_TERMINAL_BLOCK . Status {
} else if resp . PayloadStatus . Status != engine . INVALID_TERMINAL_BLOCK . Status {
t . Errorf ( "fork choice updated before total terminal difficulty should be INVALID" )
t . Errorf ( "fork choice updated before total terminal difficulty should be INVALID" )
}
}
}
}
@ -180,10 +180,10 @@ func TestEth2PrepareAndGetPayload(t *testing.T) {
// Put the 10th block's tx in the pool and produce a new block
// Put the 10th block's tx in the pool and produce a new block
ethservice . TxPool ( ) . AddLocals ( blocks [ 9 ] . Transactions ( ) )
ethservice . TxPool ( ) . AddLocals ( blocks [ 9 ] . Transactions ( ) )
blockParams := b eaco n. PayloadAttributes {
blockParams := engine . PayloadAttributes {
Timestamp : blocks [ 8 ] . Time ( ) + 5 ,
Timestamp : blocks [ 8 ] . Time ( ) + 5 ,
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : blocks [ 8 ] . Hash ( ) ,
HeadBlockHash : blocks [ 8 ] . Hash ( ) ,
SafeBlockHash : common . Hash { } ,
SafeBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
@ -208,7 +208,7 @@ func TestEth2PrepareAndGetPayload(t *testing.T) {
t . Fatalf ( "invalid number of transactions %d != 1" , len ( execData . Transactions ) )
t . Fatalf ( "invalid number of transactions %d != 1" , len ( execData . Transactions ) )
}
}
// Test invalid payloadID
// Test invalid payloadID
var invPayload b eaco n. PayloadID
var invPayload engine . PayloadID
copy ( invPayload [ : ] , payloadID [ : ] )
copy ( invPayload [ : ] , payloadID [ : ] )
invPayload [ 0 ] = ^ invPayload [ 0 ]
invPayload [ 0 ] = ^ invPayload [ 0 ]
_ , err = api . GetPayloadV1 ( invPayload )
_ , err = api . GetPayloadV1 ( invPayload )
@ -259,12 +259,12 @@ func TestInvalidPayloadTimestamp(t *testing.T) {
for i , test := range tests {
for i , test := range tests {
t . Run ( fmt . Sprintf ( "Timestamp test: %v" , i ) , func ( t * testing . T ) {
t . Run ( fmt . Sprintf ( "Timestamp test: %v" , i ) , func ( t * testing . T ) {
params := b eaco n. PayloadAttributes {
params := engine . PayloadAttributes {
Timestamp : test . time ,
Timestamp : test . time ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( 123 ) } ) ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( 123 ) } ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : parent . Hash ( ) ,
HeadBlockHash : parent . Hash ( ) ,
SafeBlockHash : common . Hash { } ,
SafeBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
@ -303,13 +303,13 @@ func TestEth2NewBlock(t *testing.T) {
tx , _ := types . SignTx ( types . NewContractCreation ( nonce , new ( big . Int ) , 1000000 , big . NewInt ( 2 * params . InitialBaseFee ) , logCode ) , types . LatestSigner ( ethservice . BlockChain ( ) . Config ( ) ) , testKey )
tx , _ := types . SignTx ( types . NewContractCreation ( nonce , new ( big . Int ) , 1000000 , big . NewInt ( 2 * params . InitialBaseFee ) , logCode ) , types . LatestSigner ( ethservice . BlockChain ( ) . Config ( ) ) , testKey )
ethservice . TxPool ( ) . AddLocal ( tx )
ethservice . TxPool ( ) . AddLocal ( tx )
execData , err := assembleWithTransactions ( api , parent . Hash ( ) , & b eaco n. PayloadAttributes {
execData , err := assembleWithTransactions ( api , parent . Hash ( ) , & engine . PayloadAttributes {
Timestamp : parent . Time ( ) + 5 ,
Timestamp : parent . Time ( ) + 5 ,
} , 1 )
} , 1 )
if err != nil {
if err != nil {
t . Fatalf ( "Failed to create the executable data %v" , err )
t . Fatalf ( "Failed to create the executable data %v" , err )
}
}
block , err := b eaco n. ExecutableDataToBlock ( * execData )
block , err := engine . ExecutableDataToBlock ( * execData )
if err != nil {
if err != nil {
t . Fatalf ( "Failed to convert executable data to block %v" , err )
t . Fatalf ( "Failed to convert executable data to block %v" , err )
}
}
@ -323,7 +323,7 @@ func TestEth2NewBlock(t *testing.T) {
t . Fatalf ( "Chain head shouldn't be updated" )
t . Fatalf ( "Chain head shouldn't be updated" )
}
}
checkLogEvents ( t , newLogCh , rmLogsCh , 0 , 0 )
checkLogEvents ( t , newLogCh , rmLogsCh , 0 , 0 )
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : block . Hash ( ) ,
HeadBlockHash : block . Hash ( ) ,
SafeBlockHash : block . Hash ( ) ,
SafeBlockHash : block . Hash ( ) ,
FinalizedBlockHash : block . Hash ( ) ,
FinalizedBlockHash : block . Hash ( ) ,
@ -345,13 +345,13 @@ func TestEth2NewBlock(t *testing.T) {
)
)
parent = preMergeBlocks [ len ( preMergeBlocks ) - 1 ]
parent = preMergeBlocks [ len ( preMergeBlocks ) - 1 ]
for i := 0 ; i < 10 ; i ++ {
for i := 0 ; i < 10 ; i ++ {
execData , err := assembleBlock ( api , parent . Hash ( ) , & b eaco n. PayloadAttributes {
execData , err := assembleBlock ( api , parent . Hash ( ) , & engine . PayloadAttributes {
Timestamp : parent . Time ( ) + 6 ,
Timestamp : parent . Time ( ) + 6 ,
} )
} )
if err != nil {
if err != nil {
t . Fatalf ( "Failed to create the executable data %v" , err )
t . Fatalf ( "Failed to create the executable data %v" , err )
}
}
block , err := b eaco n. ExecutableDataToBlock ( * execData )
block , err := engine . ExecutableDataToBlock ( * execData )
if err != nil {
if err != nil {
t . Fatalf ( "Failed to convert executable data to block %v" , err )
t . Fatalf ( "Failed to convert executable data to block %v" , err )
}
}
@ -363,7 +363,7 @@ func TestEth2NewBlock(t *testing.T) {
t . Fatalf ( "Chain head shouldn't be updated" )
t . Fatalf ( "Chain head shouldn't be updated" )
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : block . Hash ( ) ,
HeadBlockHash : block . Hash ( ) ,
SafeBlockHash : block . Hash ( ) ,
SafeBlockHash : block . Hash ( ) ,
FinalizedBlockHash : block . Hash ( ) ,
FinalizedBlockHash : block . Hash ( ) ,
@ -488,10 +488,10 @@ func setupBlocks(t *testing.T, ethservice *eth.Ethereum, n int, parent *types.Bl
if err != nil {
if err != nil {
t . Fatalf ( "can't execute payload: %v" , err )
t . Fatalf ( "can't execute payload: %v" , err )
}
}
if execResp . Status != b eaco n. VALID {
if execResp . Status != engine . VALID {
t . Fatalf ( "invalid status: %v" , execResp . Status )
t . Fatalf ( "invalid status: %v" , execResp . Status )
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : payload . BlockHash ,
HeadBlockHash : payload . BlockHash ,
SafeBlockHash : payload . ParentHash ,
SafeBlockHash : payload . ParentHash ,
FinalizedBlockHash : payload . ParentHash ,
FinalizedBlockHash : payload . ParentHash ,
@ -518,7 +518,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
// invalid ttd
// invalid ttd
api := NewConsensusAPI ( ethservice )
api := NewConsensusAPI ( ethservice )
config := b eaco n. TransitionConfigurationV1 {
config := engine . TransitionConfigurationV1 {
TerminalTotalDifficulty : ( * hexutil . Big ) ( big . NewInt ( 0 ) ) ,
TerminalTotalDifficulty : ( * hexutil . Big ) ( big . NewInt ( 0 ) ) ,
TerminalBlockHash : common . Hash { } ,
TerminalBlockHash : common . Hash { } ,
TerminalBlockNumber : 0 ,
TerminalBlockNumber : 0 ,
@ -527,7 +527,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
t . Fatal ( "expected error on invalid config, invalid ttd" )
t . Fatal ( "expected error on invalid config, invalid ttd" )
}
}
// invalid terminal block hash
// invalid terminal block hash
config = b eaco n. TransitionConfigurationV1 {
config = engine . TransitionConfigurationV1 {
TerminalTotalDifficulty : ( * hexutil . Big ) ( genesis . Config . TerminalTotalDifficulty ) ,
TerminalTotalDifficulty : ( * hexutil . Big ) ( genesis . Config . TerminalTotalDifficulty ) ,
TerminalBlockHash : common . Hash { 1 } ,
TerminalBlockHash : common . Hash { 1 } ,
TerminalBlockNumber : 0 ,
TerminalBlockNumber : 0 ,
@ -536,7 +536,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
t . Fatal ( "expected error on invalid config, invalid hash" )
t . Fatal ( "expected error on invalid config, invalid hash" )
}
}
// valid config
// valid config
config = b eaco n. TransitionConfigurationV1 {
config = engine . TransitionConfigurationV1 {
TerminalTotalDifficulty : ( * hexutil . Big ) ( genesis . Config . TerminalTotalDifficulty ) ,
TerminalTotalDifficulty : ( * hexutil . Big ) ( genesis . Config . TerminalTotalDifficulty ) ,
TerminalBlockHash : common . Hash { } ,
TerminalBlockHash : common . Hash { } ,
TerminalBlockNumber : 0 ,
TerminalBlockNumber : 0 ,
@ -545,7 +545,7 @@ func TestExchangeTransitionConfig(t *testing.T) {
t . Fatalf ( "expected no error on valid config, got %v" , err )
t . Fatalf ( "expected no error on valid config, got %v" , err )
}
}
// valid config
// valid config
config = b eaco n. TransitionConfigurationV1 {
config = engine . TransitionConfigurationV1 {
TerminalTotalDifficulty : ( * hexutil . Big ) ( genesis . Config . TerminalTotalDifficulty ) ,
TerminalTotalDifficulty : ( * hexutil . Big ) ( genesis . Config . TerminalTotalDifficulty ) ,
TerminalBlockHash : preMergeBlocks [ 5 ] . Hash ( ) ,
TerminalBlockHash : preMergeBlocks [ 5 ] . Hash ( ) ,
TerminalBlockNumber : 6 ,
TerminalBlockNumber : 6 ,
@ -595,25 +595,25 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
} )
} )
ethservice . TxPool ( ) . AddRemotesSync ( [ ] * types . Transaction { tx } )
ethservice . TxPool ( ) . AddRemotesSync ( [ ] * types . Transaction { tx } )
var (
var (
params = b eaco n. PayloadAttributes {
params = engine . PayloadAttributes {
Timestamp : parent . Time ( ) + 1 ,
Timestamp : parent . Time ( ) + 1 ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( i ) } ) ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( i ) } ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
}
}
fcState = b eaco n. ForkchoiceStateV1 {
fcState = engine . ForkchoiceStateV1 {
HeadBlockHash : parent . Hash ( ) ,
HeadBlockHash : parent . Hash ( ) ,
SafeBlockHash : common . Hash { } ,
SafeBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
}
}
payload * b eaco n. ExecutableData
payload * engine . ExecutableData
resp b eaco n. ForkChoiceResponse
resp engine . ForkChoiceResponse
err error
err error
)
)
for i := 0 ; ; i ++ {
for i := 0 ; ; i ++ {
if resp , err = api . ForkchoiceUpdatedV1 ( fcState , & params ) ; err != nil {
if resp , err = api . ForkchoiceUpdatedV1 ( fcState , & params ) ; err != nil {
t . Fatalf ( "error preparing payload, err=%v" , err )
t . Fatalf ( "error preparing payload, err=%v" , err )
}
}
if resp . PayloadStatus . Status != b eaco n. VALID {
if resp . PayloadStatus . Status != engine . VALID {
t . Fatalf ( "error preparing payload, invalid status: %v" , resp . PayloadStatus . Status )
t . Fatalf ( "error preparing payload, invalid status: %v" , resp . PayloadStatus . Status )
}
}
// give the payload some time to be built
// give the payload some time to be built
@ -634,10 +634,10 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
if err != nil {
if err != nil {
t . Fatalf ( "can't execute payload: %v" , err )
t . Fatalf ( "can't execute payload: %v" , err )
}
}
if execResp . Status != b eaco n. VALID {
if execResp . Status != engine . VALID {
t . Fatalf ( "invalid status: %v" , execResp . Status )
t . Fatalf ( "invalid status: %v" , execResp . Status )
}
}
fcState = b eaco n. ForkchoiceStateV1 {
fcState = engine . ForkchoiceStateV1 {
HeadBlockHash : payload . BlockHash ,
HeadBlockHash : payload . BlockHash ,
SafeBlockHash : payload . ParentHash ,
SafeBlockHash : payload . ParentHash ,
FinalizedBlockHash : payload . ParentHash ,
FinalizedBlockHash : payload . ParentHash ,
@ -652,7 +652,7 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
}
}
}
}
func assembleBlock ( api * ConsensusAPI , parentHash common . Hash , params * b eaco n. PayloadAttributes ) ( * b eaco n. ExecutableData , error ) {
func assembleBlock ( api * ConsensusAPI , parentHash common . Hash , params * engine . PayloadAttributes ) ( * engine . ExecutableData , error ) {
args := & miner . BuildPayloadArgs {
args := & miner . BuildPayloadArgs {
Parent : parentHash ,
Parent : parentHash ,
Timestamp : params . Timestamp ,
Timestamp : params . Timestamp ,
@ -685,7 +685,7 @@ func TestEmptyBlocks(t *testing.T) {
if err != nil {
if err != nil {
t . Fatal ( err )
t . Fatal ( err )
}
}
if status . Status != b eaco n. VALID {
if status . Status != engine . VALID {
t . Errorf ( "invalid status: expected VALID got: %v" , status . Status )
t . Errorf ( "invalid status: expected VALID got: %v" , status . Status )
}
}
if ! bytes . Equal ( status . LatestValidHash [ : ] , payload . BlockHash [ : ] ) {
if ! bytes . Equal ( status . LatestValidHash [ : ] , payload . BlockHash [ : ] ) {
@ -701,7 +701,7 @@ func TestEmptyBlocks(t *testing.T) {
if err != nil {
if err != nil {
t . Fatal ( err )
t . Fatal ( err )
}
}
if status . Status != b eaco n. INVALID {
if status . Status != engine . INVALID {
t . Errorf ( "invalid status: expected INVALID got: %v" , status . Status )
t . Errorf ( "invalid status: expected INVALID got: %v" , status . Status )
}
}
// Expect 0x0 on INVALID block on top of PoW block
// Expect 0x0 on INVALID block on top of PoW block
@ -719,7 +719,7 @@ func TestEmptyBlocks(t *testing.T) {
if err != nil {
if err != nil {
t . Fatal ( err )
t . Fatal ( err )
}
}
if status . Status != b eaco n. SYNCING {
if status . Status != engine . SYNCING {
t . Errorf ( "invalid status: expected SYNCING got: %v" , status . Status )
t . Errorf ( "invalid status: expected SYNCING got: %v" , status . Status )
}
}
if status . LatestValidHash != nil {
if status . LatestValidHash != nil {
@ -727,8 +727,8 @@ func TestEmptyBlocks(t *testing.T) {
}
}
}
}
func getNewPayload ( t * testing . T , api * ConsensusAPI , parent * types . Block ) * b eaco n. ExecutableData {
func getNewPayload ( t * testing . T , api * ConsensusAPI , parent * types . Block ) * engine . ExecutableData {
params := b eaco n. PayloadAttributes {
params := engine . PayloadAttributes {
Timestamp : parent . Time ( ) + 1 ,
Timestamp : parent . Time ( ) + 1 ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( 1 ) } ) ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( 1 ) } ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
@ -743,7 +743,7 @@ func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Block) *beacon
// setBlockhash sets the blockhash of a modified ExecutableData.
// setBlockhash sets the blockhash of a modified ExecutableData.
// Can be used to make modified payloads look valid.
// Can be used to make modified payloads look valid.
func setBlockhash ( data * b eaco n. ExecutableData ) * b eaco n. ExecutableData {
func setBlockhash ( data * engine . ExecutableData ) * engine . ExecutableData {
txs , _ := decodeTransactions ( data . Transactions )
txs , _ := decodeTransactions ( data . Transactions )
number := big . NewInt ( 0 )
number := big . NewInt ( 0 )
number . SetUint64 ( data . Number )
number . SetUint64 ( data . Number )
@ -802,7 +802,7 @@ func TestTrickRemoteBlockCache(t *testing.T) {
setupBlocks ( t , ethserviceA , 10 , commonAncestor , func ( parent * types . Block ) { } )
setupBlocks ( t , ethserviceA , 10 , commonAncestor , func ( parent * types . Block ) { } )
commonAncestor = ethserviceA . BlockChain ( ) . CurrentBlock ( )
commonAncestor = ethserviceA . BlockChain ( ) . CurrentBlock ( )
var invalidChain [ ] * b eaco n. ExecutableData
var invalidChain [ ] * engine . ExecutableData
// create a valid payload (P1)
// create a valid payload (P1)
//payload1 := getNewPayload(t, apiA, commonAncestor)
//payload1 := getNewPayload(t, apiA, commonAncestor)
//invalidChain = append(invalidChain, payload1)
//invalidChain = append(invalidChain, payload1)
@ -830,15 +830,15 @@ func TestTrickRemoteBlockCache(t *testing.T) {
if err != nil {
if err != nil {
panic ( err )
panic ( err )
}
}
if status . Status == b eaco n. VALID {
if status . Status == engine . VALID {
t . Error ( "invalid status: VALID on an invalid chain" )
t . Error ( "invalid status: VALID on an invalid chain" )
}
}
// Now reorg to the head of the invalid chain
// Now reorg to the head of the invalid chain
resp , err := apiB . ForkchoiceUpdatedV1 ( b eaco n. ForkchoiceStateV1 { HeadBlockHash : payload . BlockHash , SafeBlockHash : payload . BlockHash , FinalizedBlockHash : payload . ParentHash } , nil )
resp , err := apiB . ForkchoiceUpdatedV1 ( engine . ForkchoiceStateV1 { HeadBlockHash : payload . BlockHash , SafeBlockHash : payload . BlockHash , FinalizedBlockHash : payload . ParentHash } , nil )
if err != nil {
if err != nil {
t . Fatal ( err )
t . Fatal ( err )
}
}
if resp . PayloadStatus . Status == b eaco n. VALID {
if resp . PayloadStatus . Status == engine . VALID {
t . Error ( "invalid status: VALID on an invalid chain" )
t . Error ( "invalid status: VALID on an invalid chain" )
}
}
time . Sleep ( 100 * time . Millisecond )
time . Sleep ( 100 * time . Millisecond )
@ -864,7 +864,7 @@ func TestInvalidBloom(t *testing.T) {
if err != nil {
if err != nil {
t . Fatal ( err )
t . Fatal ( err )
}
}
if status . Status != b eaco n. INVALIDBLOCKHASH {
if status . Status != engine . INVALIDBLOCKHASH {
t . Errorf ( "invalid status: expected VALID got: %v" , status . Status )
t . Errorf ( "invalid status: expected VALID got: %v" , status . Status )
}
}
}
}
@ -882,7 +882,7 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
)
)
// Test parent already post TTD in FCU
// Test parent already post TTD in FCU
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : parent . Hash ( ) ,
HeadBlockHash : parent . Hash ( ) ,
SafeBlockHash : common . Hash { } ,
SafeBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
@ -891,7 +891,7 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
if err != nil {
if err != nil {
t . Fatalf ( "error sending forkchoice, err=%v" , err )
t . Fatalf ( "error sending forkchoice, err=%v" , err )
}
}
if resp . PayloadStatus != b eaco n. INVALID_TERMINAL_BLOCK {
if resp . PayloadStatus != engine . INVALID_TERMINAL_BLOCK {
t . Fatalf ( "error sending invalid forkchoice, invalid status: %v" , resp . PayloadStatus . Status )
t . Fatalf ( "error sending invalid forkchoice, invalid status: %v" , resp . PayloadStatus . Status )
}
}
@ -911,7 +911,7 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
if err != nil {
if err != nil {
t . Fatalf ( "error sending NewPayload, err=%v" , err )
t . Fatalf ( "error sending NewPayload, err=%v" , err )
}
}
if resp2 != b eaco n. INVALID_TERMINAL_BLOCK {
if resp2 != engine . INVALID_TERMINAL_BLOCK {
t . Fatalf ( "error sending invalid forkchoice, invalid status: %v" , resp . PayloadStatus . Status )
t . Fatalf ( "error sending invalid forkchoice, invalid status: %v" , resp . PayloadStatus . Status )
}
}
}
}
@ -929,7 +929,7 @@ func TestSimultaneousNewBlock(t *testing.T) {
parent = preMergeBlocks [ len ( preMergeBlocks ) - 1 ]
parent = preMergeBlocks [ len ( preMergeBlocks ) - 1 ]
)
)
for i := 0 ; i < 10 ; i ++ {
for i := 0 ; i < 10 ; i ++ {
execData , err := assembleBlock ( api , parent . Hash ( ) , & b eaco n. PayloadAttributes {
execData , err := assembleBlock ( api , parent . Hash ( ) , & engine . PayloadAttributes {
Timestamp : parent . Time ( ) + 5 ,
Timestamp : parent . Time ( ) + 5 ,
} )
} )
if err != nil {
if err != nil {
@ -962,14 +962,14 @@ func TestSimultaneousNewBlock(t *testing.T) {
t . Fatal ( testErr )
t . Fatal ( testErr )
}
}
}
}
block , err := b eaco n. ExecutableDataToBlock ( * execData )
block , err := engine . ExecutableDataToBlock ( * execData )
if err != nil {
if err != nil {
t . Fatalf ( "Failed to convert executable data to block %v" , err )
t . Fatalf ( "Failed to convert executable data to block %v" , err )
}
}
if ethservice . BlockChain ( ) . CurrentBlock ( ) . NumberU64 ( ) != block . NumberU64 ( ) - 1 {
if ethservice . BlockChain ( ) . CurrentBlock ( ) . NumberU64 ( ) != block . NumberU64 ( ) - 1 {
t . Fatalf ( "Chain head shouldn't be updated" )
t . Fatalf ( "Chain head shouldn't be updated" )
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : block . Hash ( ) ,
HeadBlockHash : block . Hash ( ) ,
SafeBlockHash : block . Hash ( ) ,
SafeBlockHash : block . Hash ( ) ,
FinalizedBlockHash : block . Hash ( ) ,
FinalizedBlockHash : block . Hash ( ) ,
@ -1020,19 +1020,19 @@ func TestWithdrawals(t *testing.T) {
// 10: Build Shanghai block with no withdrawals.
// 10: Build Shanghai block with no withdrawals.
parent := ethservice . BlockChain ( ) . CurrentHeader ( )
parent := ethservice . BlockChain ( ) . CurrentHeader ( )
blockParams := b eaco n. PayloadAttributes {
blockParams := engine . PayloadAttributes {
Timestamp : parent . Time + 5 ,
Timestamp : parent . Time + 5 ,
Withdrawals : make ( [ ] * types . Withdrawal , 0 ) ,
Withdrawals : make ( [ ] * types . Withdrawal , 0 ) ,
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : parent . Hash ( ) ,
HeadBlockHash : parent . Hash ( ) ,
}
}
resp , err := api . ForkchoiceUpdatedV2 ( fcState , & blockParams )
resp , err := api . ForkchoiceUpdatedV2 ( fcState , & blockParams )
if err != nil {
if err != nil {
t . Fatalf ( "error preparing payload, err=%v" , err )
t . Fatalf ( "error preparing payload, err=%v" , err )
}
}
if resp . PayloadStatus . Status != b eaco n. VALID {
if resp . PayloadStatus . Status != engine . VALID {
t . Fatalf ( "unexpected status (got: %s, want: %s)" , resp . PayloadStatus . Status , b eaco n. VALID )
t . Fatalf ( "unexpected status (got: %s, want: %s)" , resp . PayloadStatus . Status , engine . VALID )
}
}
// 10: verify state root is the same as parent
// 10: verify state root is the same as parent
@ -1053,14 +1053,14 @@ func TestWithdrawals(t *testing.T) {
// 10: verify locally built block
// 10: verify locally built block
if status , err := api . NewPayloadV2 ( * execData . ExecutionPayload ) ; err != nil {
if status , err := api . NewPayloadV2 ( * execData . ExecutionPayload ) ; err != nil {
t . Fatalf ( "error validating payload: %v" , err )
t . Fatalf ( "error validating payload: %v" , err )
} else if status . Status != b eaco n. VALID {
} else if status . Status != engine . VALID {
t . Fatalf ( "invalid payload" )
t . Fatalf ( "invalid payload" )
}
}
// 11: build shanghai block with withdrawal
// 11: build shanghai block with withdrawal
aa := common . Address { 0xaa }
aa := common . Address { 0xaa }
bb := common . Address { 0xbb }
bb := common . Address { 0xbb }
blockParams = b eaco n. PayloadAttributes {
blockParams = engine . PayloadAttributes {
Timestamp : execData . ExecutionPayload . Timestamp + 5 ,
Timestamp : execData . ExecutionPayload . Timestamp + 5 ,
Withdrawals : [ ] * types . Withdrawal {
Withdrawals : [ ] * types . Withdrawal {
{
{
@ -1094,7 +1094,7 @@ func TestWithdrawals(t *testing.T) {
}
}
if status , err := api . NewPayloadV2 ( * execData . ExecutionPayload ) ; err != nil {
if status , err := api . NewPayloadV2 ( * execData . ExecutionPayload ) ; err != nil {
t . Fatalf ( "error validating payload: %v" , err )
t . Fatalf ( "error validating payload: %v" , err )
} else if status . Status != b eaco n. VALID {
} else if status . Status != engine . VALID {
t . Fatalf ( "invalid payload" )
t . Fatalf ( "invalid payload" )
}
}
@ -1133,27 +1133,27 @@ func TestNilWithdrawals(t *testing.T) {
aa := common . Address { 0xaa }
aa := common . Address { 0xaa }
type test struct {
type test struct {
blockParams b eaco n. PayloadAttributes
blockParams engine . PayloadAttributes
wantErr bool
wantErr bool
}
}
tests := [ ] test {
tests := [ ] test {
// Before Shanghai
// Before Shanghai
{
{
blockParams : b eaco n. PayloadAttributes {
blockParams : engine . PayloadAttributes {
Timestamp : parent . Time + 2 ,
Timestamp : parent . Time + 2 ,
Withdrawals : nil ,
Withdrawals : nil ,
} ,
} ,
wantErr : false ,
wantErr : false ,
} ,
} ,
{
{
blockParams : b eaco n. PayloadAttributes {
blockParams : engine . PayloadAttributes {
Timestamp : parent . Time + 2 ,
Timestamp : parent . Time + 2 ,
Withdrawals : make ( [ ] * types . Withdrawal , 0 ) ,
Withdrawals : make ( [ ] * types . Withdrawal , 0 ) ,
} ,
} ,
wantErr : true ,
wantErr : true ,
} ,
} ,
{
{
blockParams : b eaco n. PayloadAttributes {
blockParams : engine . PayloadAttributes {
Timestamp : parent . Time + 2 ,
Timestamp : parent . Time + 2 ,
Withdrawals : [ ] * types . Withdrawal {
Withdrawals : [ ] * types . Withdrawal {
{
{
@ -1167,21 +1167,21 @@ func TestNilWithdrawals(t *testing.T) {
} ,
} ,
// After Shanghai
// After Shanghai
{
{
blockParams : b eaco n. PayloadAttributes {
blockParams : engine . PayloadAttributes {
Timestamp : parent . Time + 5 ,
Timestamp : parent . Time + 5 ,
Withdrawals : nil ,
Withdrawals : nil ,
} ,
} ,
wantErr : true ,
wantErr : true ,
} ,
} ,
{
{
blockParams : b eaco n. PayloadAttributes {
blockParams : engine . PayloadAttributes {
Timestamp : parent . Time + 5 ,
Timestamp : parent . Time + 5 ,
Withdrawals : make ( [ ] * types . Withdrawal , 0 ) ,
Withdrawals : make ( [ ] * types . Withdrawal , 0 ) ,
} ,
} ,
wantErr : false ,
wantErr : false ,
} ,
} ,
{
{
blockParams : b eaco n. PayloadAttributes {
blockParams : engine . PayloadAttributes {
Timestamp : parent . Time + 5 ,
Timestamp : parent . Time + 5 ,
Withdrawals : [ ] * types . Withdrawal {
Withdrawals : [ ] * types . Withdrawal {
{
{
@ -1195,7 +1195,7 @@ func TestNilWithdrawals(t *testing.T) {
} ,
} ,
}
}
fcState := b eaco n. ForkchoiceStateV1 {
fcState := engine . ForkchoiceStateV1 {
HeadBlockHash : parent . Hash ( ) ,
HeadBlockHash : parent . Hash ( ) ,
}
}
@ -1224,7 +1224,7 @@ func TestNilWithdrawals(t *testing.T) {
}
}
if status , err := api . NewPayloadV2 ( * execData . ExecutionPayload ) ; err != nil {
if status , err := api . NewPayloadV2 ( * execData . ExecutionPayload ) ; err != nil {
t . Fatalf ( "error validating payload: %v" , err )
t . Fatalf ( "error validating payload: %v" , err )
} else if status . Status != b eaco n. VALID {
} else if status . Status != engine . VALID {
t . Fatalf ( "invalid payload" )
t . Fatalf ( "invalid payload" )
}
}
}
}
@ -1400,7 +1400,7 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
}
}
}
}
func equalBody ( a * types . Body , b * b eaco n. ExecutionPayloadBodyV1 ) bool {
func equalBody ( a * types . Body , b * engine . ExecutionPayloadBodyV1 ) bool {
if a == nil && b == nil {
if a == nil && b == nil {
return true
return true
} else if a == nil || b == nil {
} else if a == nil || b == nil {