2022-02-02 03:30:35 +00:00
|
|
|
package enginev1_test
|
2022-02-01 01:47:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-01-17 23:44:59 +00:00
|
|
|
"fmt"
|
2022-02-09 20:54:56 +00:00
|
|
|
"math/big"
|
2022-02-01 01:47:34 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-07-06 22:06:00 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2022-12-14 13:42:48 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2022-07-06 22:06:00 +00:00
|
|
|
gethtypes "github.com/ethereum/go-ethereum/core/types"
|
2024-02-15 05:46:47 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
|
|
|
|
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2022-02-01 01:47:34 +00:00
|
|
|
)
|
|
|
|
|
2022-12-14 13:42:48 +00:00
|
|
|
type withdrawalJSON struct {
|
|
|
|
Index *hexutil.Uint64 `json:"index"`
|
|
|
|
Validator *hexutil.Uint64 `json:"validatorIndex"`
|
|
|
|
Address *common.Address `json:"address"`
|
2023-01-16 21:25:16 +00:00
|
|
|
Amount *hexutil.Uint64 `json:"amount"`
|
2022-12-14 13:42:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 01:47:34 +00:00
|
|
|
func TestJsonMarshalUnmarshal(t *testing.T) {
|
|
|
|
t.Run("payload attributes", func(t *testing.T) {
|
2022-02-12 01:58:09 +00:00
|
|
|
random := bytesutil.PadTo([]byte("random"), fieldparams.RootLength)
|
|
|
|
feeRecipient := bytesutil.PadTo([]byte("feeRecipient"), fieldparams.FeeRecipientLength)
|
2022-02-07 17:13:01 +00:00
|
|
|
jsonPayload := &enginev1.PayloadAttributes{
|
|
|
|
Timestamp: 1,
|
2022-02-26 03:47:16 +00:00
|
|
|
PrevRandao: random,
|
2022-02-12 01:58:09 +00:00
|
|
|
SuggestedFeeRecipient: feeRecipient,
|
2022-02-01 01:47:34 +00:00
|
|
|
}
|
|
|
|
enc, err := json.Marshal(jsonPayload)
|
|
|
|
require.NoError(t, err)
|
2022-02-02 03:30:35 +00:00
|
|
|
payloadPb := &enginev1.PayloadAttributes{}
|
2022-02-01 01:47:34 +00:00
|
|
|
require.NoError(t, json.Unmarshal(enc, payloadPb))
|
|
|
|
require.DeepEqual(t, uint64(1), payloadPb.Timestamp)
|
2022-02-26 03:47:16 +00:00
|
|
|
require.DeepEqual(t, random, payloadPb.PrevRandao)
|
2022-02-12 01:58:09 +00:00
|
|
|
require.DeepEqual(t, feeRecipient, payloadPb.SuggestedFeeRecipient)
|
2022-02-01 01:47:34 +00:00
|
|
|
})
|
|
|
|
t.Run("payload status", func(t *testing.T) {
|
2022-02-12 01:58:09 +00:00
|
|
|
hash := bytesutil.PadTo([]byte("hash"), fieldparams.RootLength)
|
2022-02-07 17:13:01 +00:00
|
|
|
jsonPayload := &enginev1.PayloadStatus{
|
|
|
|
Status: enginev1.PayloadStatus_INVALID,
|
2022-02-12 01:58:09 +00:00
|
|
|
LatestValidHash: hash,
|
2022-02-07 17:13:01 +00:00
|
|
|
ValidationError: "failed validation",
|
2022-02-01 01:47:34 +00:00
|
|
|
}
|
|
|
|
enc, err := json.Marshal(jsonPayload)
|
|
|
|
require.NoError(t, err)
|
2022-02-02 03:30:35 +00:00
|
|
|
payloadPb := &enginev1.PayloadStatus{}
|
2022-02-01 01:47:34 +00:00
|
|
|
require.NoError(t, json.Unmarshal(enc, payloadPb))
|
|
|
|
require.DeepEqual(t, "INVALID", payloadPb.Status.String())
|
2022-02-12 01:58:09 +00:00
|
|
|
require.DeepEqual(t, hash, payloadPb.LatestValidHash)
|
2022-02-01 01:47:34 +00:00
|
|
|
require.DeepEqual(t, "failed validation", payloadPb.ValidationError)
|
|
|
|
})
|
|
|
|
t.Run("forkchoice state", func(t *testing.T) {
|
2022-02-12 01:58:09 +00:00
|
|
|
head := bytesutil.PadTo([]byte("head"), fieldparams.RootLength)
|
|
|
|
safe := bytesutil.PadTo([]byte("safe"), fieldparams.RootLength)
|
|
|
|
finalized := bytesutil.PadTo([]byte("finalized"), fieldparams.RootLength)
|
2022-02-07 17:13:01 +00:00
|
|
|
jsonPayload := &enginev1.ForkchoiceState{
|
2022-02-12 01:58:09 +00:00
|
|
|
HeadBlockHash: head,
|
|
|
|
SafeBlockHash: safe,
|
|
|
|
FinalizedBlockHash: finalized,
|
2022-02-01 01:47:34 +00:00
|
|
|
}
|
|
|
|
enc, err := json.Marshal(jsonPayload)
|
|
|
|
require.NoError(t, err)
|
2022-02-02 03:30:35 +00:00
|
|
|
payloadPb := &enginev1.ForkchoiceState{}
|
2022-02-01 01:47:34 +00:00
|
|
|
require.NoError(t, json.Unmarshal(enc, payloadPb))
|
2022-02-12 01:58:09 +00:00
|
|
|
require.DeepEqual(t, head, payloadPb.HeadBlockHash)
|
|
|
|
require.DeepEqual(t, safe, payloadPb.SafeBlockHash)
|
|
|
|
require.DeepEqual(t, finalized, payloadPb.FinalizedBlockHash)
|
2022-02-01 01:47:34 +00:00
|
|
|
})
|
|
|
|
t.Run("execution payload", func(t *testing.T) {
|
2022-03-16 22:12:08 +00:00
|
|
|
baseFeePerGas := big.NewInt(1770307273)
|
2022-02-12 01:58:09 +00:00
|
|
|
parentHash := bytesutil.PadTo([]byte("parent"), fieldparams.RootLength)
|
|
|
|
feeRecipient := bytesutil.PadTo([]byte("feeRecipient"), fieldparams.FeeRecipientLength)
|
|
|
|
stateRoot := bytesutil.PadTo([]byte("stateRoot"), fieldparams.RootLength)
|
|
|
|
receiptsRoot := bytesutil.PadTo([]byte("receiptsRoot"), fieldparams.RootLength)
|
|
|
|
logsBloom := bytesutil.PadTo([]byte("logs"), fieldparams.LogsBloomLength)
|
|
|
|
random := bytesutil.PadTo([]byte("random"), fieldparams.RootLength)
|
|
|
|
extra := bytesutil.PadTo([]byte("extraData"), fieldparams.RootLength)
|
|
|
|
hash := bytesutil.PadTo([]byte("hash"), fieldparams.RootLength)
|
2022-02-07 17:13:01 +00:00
|
|
|
jsonPayload := &enginev1.ExecutionPayload{
|
2022-02-12 01:58:09 +00:00
|
|
|
ParentHash: parentHash,
|
|
|
|
FeeRecipient: feeRecipient,
|
|
|
|
StateRoot: stateRoot,
|
|
|
|
ReceiptsRoot: receiptsRoot,
|
|
|
|
LogsBloom: logsBloom,
|
2022-02-26 03:47:16 +00:00
|
|
|
PrevRandao: random,
|
2022-02-07 17:13:01 +00:00
|
|
|
BlockNumber: 1,
|
|
|
|
GasLimit: 2,
|
|
|
|
GasUsed: 3,
|
|
|
|
Timestamp: 4,
|
2022-02-12 01:58:09 +00:00
|
|
|
ExtraData: extra,
|
2022-02-21 14:03:12 +00:00
|
|
|
BaseFeePerGas: baseFeePerGas.Bytes(),
|
2022-02-12 01:58:09 +00:00
|
|
|
BlockHash: hash,
|
2022-02-07 17:13:01 +00:00
|
|
|
Transactions: [][]byte{[]byte("hi")},
|
2022-02-01 01:47:34 +00:00
|
|
|
}
|
|
|
|
enc, err := json.Marshal(jsonPayload)
|
|
|
|
require.NoError(t, err)
|
2022-02-02 03:30:35 +00:00
|
|
|
payloadPb := &enginev1.ExecutionPayload{}
|
2022-02-01 01:47:34 +00:00
|
|
|
require.NoError(t, json.Unmarshal(enc, payloadPb))
|
2022-02-12 01:58:09 +00:00
|
|
|
require.DeepEqual(t, parentHash, payloadPb.ParentHash)
|
|
|
|
require.DeepEqual(t, feeRecipient, payloadPb.FeeRecipient)
|
|
|
|
require.DeepEqual(t, stateRoot, payloadPb.StateRoot)
|
|
|
|
require.DeepEqual(t, receiptsRoot, payloadPb.ReceiptsRoot)
|
|
|
|
require.DeepEqual(t, logsBloom, payloadPb.LogsBloom)
|
2022-02-26 03:47:16 +00:00
|
|
|
require.DeepEqual(t, random, payloadPb.PrevRandao)
|
2022-02-01 01:47:34 +00:00
|
|
|
require.DeepEqual(t, uint64(1), payloadPb.BlockNumber)
|
2022-02-07 17:13:01 +00:00
|
|
|
require.DeepEqual(t, uint64(2), payloadPb.GasLimit)
|
|
|
|
require.DeepEqual(t, uint64(3), payloadPb.GasUsed)
|
|
|
|
require.DeepEqual(t, uint64(4), payloadPb.Timestamp)
|
2022-02-12 01:58:09 +00:00
|
|
|
require.DeepEqual(t, extra, payloadPb.ExtraData)
|
|
|
|
require.DeepEqual(t, bytesutil.PadTo(baseFeePerGas.Bytes(), fieldparams.RootLength), payloadPb.BaseFeePerGas)
|
|
|
|
require.DeepEqual(t, hash, payloadPb.BlockHash)
|
2022-02-07 17:13:01 +00:00
|
|
|
require.DeepEqual(t, [][]byte{[]byte("hi")}, payloadPb.Transactions)
|
2022-02-01 01:47:34 +00:00
|
|
|
})
|
2023-01-17 23:44:59 +00:00
|
|
|
t.Run("execution payload Capella", func(t *testing.T) {
|
|
|
|
parentHash := common.BytesToHash([]byte("parent"))
|
|
|
|
feeRecipient := common.BytesToAddress([]byte("feeRecipient"))
|
|
|
|
stateRoot := common.BytesToHash([]byte("stateRoot"))
|
|
|
|
receiptsRoot := common.BytesToHash([]byte("receiptsRoot"))
|
|
|
|
logsBloom := hexutil.Bytes(bytesutil.PadTo([]byte("logs"), fieldparams.LogsBloomLength))
|
|
|
|
random := common.BytesToHash([]byte("random"))
|
|
|
|
extra := common.BytesToHash([]byte("extra"))
|
|
|
|
hash := common.BytesToHash([]byte("hash"))
|
|
|
|
bn := hexutil.Uint64(1)
|
|
|
|
gl := hexutil.Uint64(2)
|
|
|
|
gu := hexutil.Uint64(3)
|
|
|
|
ts := hexutil.Uint64(4)
|
|
|
|
|
|
|
|
resp := &enginev1.GetPayloadV2ResponseJson{
|
2023-02-10 19:36:19 +00:00
|
|
|
BlockValue: fmt.Sprint("0x123"),
|
2023-01-17 23:44:59 +00:00
|
|
|
ExecutionPayload: &enginev1.ExecutionPayloadCapellaJSON{
|
|
|
|
ParentHash: &parentHash,
|
|
|
|
FeeRecipient: &feeRecipient,
|
|
|
|
StateRoot: &stateRoot,
|
|
|
|
ReceiptsRoot: &receiptsRoot,
|
|
|
|
LogsBloom: &logsBloom,
|
|
|
|
PrevRandao: &random,
|
|
|
|
BlockNumber: &bn,
|
|
|
|
GasLimit: &gl,
|
|
|
|
GasUsed: &gu,
|
|
|
|
Timestamp: &ts,
|
|
|
|
ExtraData: hexutil.Bytes(extra[:]),
|
|
|
|
BaseFeePerGas: "0x123",
|
|
|
|
BlockHash: &hash,
|
|
|
|
Transactions: []hexutil.Bytes{{}},
|
|
|
|
Withdrawals: []*enginev1.Withdrawal{{
|
|
|
|
Index: 1,
|
|
|
|
ValidatorIndex: 1,
|
|
|
|
Address: bytesutil.PadTo([]byte("address"), 20),
|
|
|
|
Amount: 1,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(resp)
|
|
|
|
require.NoError(t, err)
|
2023-02-10 19:36:19 +00:00
|
|
|
pb := &enginev1.ExecutionPayloadCapellaWithValue{}
|
|
|
|
require.NoError(t, json.Unmarshal(enc, pb))
|
|
|
|
require.DeepEqual(t, parentHash.Bytes(), pb.Payload.ParentHash)
|
|
|
|
require.DeepEqual(t, feeRecipient.Bytes(), pb.Payload.FeeRecipient)
|
|
|
|
require.DeepEqual(t, stateRoot.Bytes(), pb.Payload.StateRoot)
|
|
|
|
require.DeepEqual(t, receiptsRoot.Bytes(), pb.Payload.ReceiptsRoot)
|
|
|
|
require.DeepEqual(t, logsBloom, hexutil.Bytes(pb.Payload.LogsBloom))
|
|
|
|
require.DeepEqual(t, random.Bytes(), pb.Payload.PrevRandao)
|
|
|
|
require.DeepEqual(t, uint64(1), pb.Payload.BlockNumber)
|
|
|
|
require.DeepEqual(t, uint64(2), pb.Payload.GasLimit)
|
|
|
|
require.DeepEqual(t, uint64(3), pb.Payload.GasUsed)
|
|
|
|
require.DeepEqual(t, uint64(4), pb.Payload.Timestamp)
|
|
|
|
require.DeepEqual(t, extra.Bytes(), pb.Payload.ExtraData)
|
|
|
|
feePerGas := new(big.Int).SetBytes(pb.Payload.BaseFeePerGas)
|
2023-01-17 23:44:59 +00:00
|
|
|
require.Equal(t, "15832716547479101977395928904157292820330083199902421483727713169783165812736", feePerGas.String())
|
2023-02-10 19:36:19 +00:00
|
|
|
require.DeepEqual(t, hash.Bytes(), pb.Payload.BlockHash)
|
|
|
|
require.DeepEqual(t, [][]byte{{}}, pb.Payload.Transactions)
|
|
|
|
require.Equal(t, 1, len(pb.Payload.Withdrawals))
|
|
|
|
withdrawal := pb.Payload.Withdrawals[0]
|
2023-01-17 23:44:59 +00:00
|
|
|
require.Equal(t, uint64(1), withdrawal.Index)
|
2023-01-26 14:40:12 +00:00
|
|
|
require.Equal(t, primitives.ValidatorIndex(1), withdrawal.ValidatorIndex)
|
2023-01-17 23:44:59 +00:00
|
|
|
require.DeepEqual(t, bytesutil.PadTo([]byte("address"), 20), withdrawal.Address)
|
|
|
|
require.Equal(t, uint64(1), withdrawal.Amount)
|
|
|
|
})
|
2023-05-26 18:09:16 +00:00
|
|
|
t.Run("execution payload deneb", func(t *testing.T) {
|
|
|
|
parentHash := common.BytesToHash([]byte("parent"))
|
|
|
|
feeRecipient := common.BytesToAddress([]byte("feeRecipient"))
|
|
|
|
stateRoot := common.BytesToHash([]byte("stateRoot"))
|
|
|
|
receiptsRoot := common.BytesToHash([]byte("receiptsRoot"))
|
|
|
|
logsBloom := hexutil.Bytes(bytesutil.PadTo([]byte("logs"), fieldparams.LogsBloomLength))
|
|
|
|
random := common.BytesToHash([]byte("random"))
|
|
|
|
extra := common.BytesToHash([]byte("extra"))
|
|
|
|
hash := common.BytesToHash([]byte("hash"))
|
|
|
|
bn := hexutil.Uint64(1)
|
|
|
|
gl := hexutil.Uint64(2)
|
|
|
|
gu := hexutil.Uint64(3)
|
|
|
|
ts := hexutil.Uint64(4)
|
2023-07-31 15:02:42 +00:00
|
|
|
bgu := hexutil.Uint64(5)
|
|
|
|
ebg := hexutil.Uint64(6)
|
2023-05-26 18:09:16 +00:00
|
|
|
|
|
|
|
resp := &enginev1.GetPayloadV3ResponseJson{
|
|
|
|
BlobsBundle: &enginev1.BlobBundleJSON{
|
2023-07-17 10:54:18 +00:00
|
|
|
Commitments: []hexutil.Bytes{{'a'}, {'b'}, {'c'}, {'d'}},
|
|
|
|
Proofs: []hexutil.Bytes{{'e'}, {'f'}, {'g'}, {'h'}},
|
|
|
|
Blobs: []hexutil.Bytes{{'i'}, {'j'}, {'k'}, {'l'}},
|
2023-05-26 18:09:16 +00:00
|
|
|
},
|
|
|
|
BlockValue: fmt.Sprint("0x123"),
|
|
|
|
ExecutionPayload: &enginev1.ExecutionPayloadDenebJSON{
|
|
|
|
ParentHash: &parentHash,
|
|
|
|
FeeRecipient: &feeRecipient,
|
|
|
|
StateRoot: &stateRoot,
|
|
|
|
ReceiptsRoot: &receiptsRoot,
|
|
|
|
LogsBloom: &logsBloom,
|
|
|
|
PrevRandao: &random,
|
|
|
|
BlockNumber: &bn,
|
|
|
|
GasLimit: &gl,
|
|
|
|
GasUsed: &gu,
|
|
|
|
Timestamp: &ts,
|
|
|
|
ExtraData: hexutil.Bytes(extra[:]),
|
|
|
|
BaseFeePerGas: "0x123",
|
|
|
|
BlockHash: &hash,
|
|
|
|
Transactions: []hexutil.Bytes{{}},
|
|
|
|
Withdrawals: []*enginev1.Withdrawal{{
|
|
|
|
Index: 1,
|
|
|
|
ValidatorIndex: 1,
|
|
|
|
Address: bytesutil.PadTo([]byte("address"), 20),
|
|
|
|
Amount: 1,
|
|
|
|
}},
|
2023-07-31 15:02:42 +00:00
|
|
|
BlobGasUsed: &bgu,
|
|
|
|
ExcessBlobGas: &ebg,
|
2023-05-26 18:09:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
pb := &enginev1.ExecutionPayloadDenebWithValueAndBlobsBundle{}
|
|
|
|
require.NoError(t, json.Unmarshal(enc, pb))
|
|
|
|
require.DeepEqual(t, parentHash.Bytes(), pb.Payload.ParentHash)
|
|
|
|
require.DeepEqual(t, feeRecipient.Bytes(), pb.Payload.FeeRecipient)
|
|
|
|
require.DeepEqual(t, stateRoot.Bytes(), pb.Payload.StateRoot)
|
|
|
|
require.DeepEqual(t, receiptsRoot.Bytes(), pb.Payload.ReceiptsRoot)
|
|
|
|
require.DeepEqual(t, logsBloom, hexutil.Bytes(pb.Payload.LogsBloom))
|
|
|
|
require.DeepEqual(t, random.Bytes(), pb.Payload.PrevRandao)
|
|
|
|
require.DeepEqual(t, uint64(1), pb.Payload.BlockNumber)
|
|
|
|
require.DeepEqual(t, uint64(2), pb.Payload.GasLimit)
|
|
|
|
require.DeepEqual(t, uint64(3), pb.Payload.GasUsed)
|
|
|
|
require.DeepEqual(t, uint64(4), pb.Payload.Timestamp)
|
2023-07-31 15:02:42 +00:00
|
|
|
require.DeepEqual(t, uint64(5), pb.Payload.BlobGasUsed)
|
|
|
|
require.DeepEqual(t, uint64(6), pb.Payload.ExcessBlobGas)
|
2023-05-26 18:09:16 +00:00
|
|
|
require.DeepEqual(t, extra.Bytes(), pb.Payload.ExtraData)
|
|
|
|
feePerGas := new(big.Int).SetBytes(pb.Payload.BaseFeePerGas)
|
|
|
|
require.Equal(t, "15832716547479101977395928904157292820330083199902421483727713169783165812736", feePerGas.String())
|
|
|
|
require.DeepEqual(t, hash.Bytes(), pb.Payload.BlockHash)
|
|
|
|
require.DeepEqual(t, [][]byte{{}}, pb.Payload.Transactions)
|
|
|
|
require.Equal(t, 1, len(pb.Payload.Withdrawals))
|
|
|
|
withdrawal := pb.Payload.Withdrawals[0]
|
|
|
|
require.Equal(t, uint64(1), withdrawal.Index)
|
|
|
|
require.Equal(t, primitives.ValidatorIndex(1), withdrawal.ValidatorIndex)
|
|
|
|
require.DeepEqual(t, bytesutil.PadTo([]byte("address"), 20), withdrawal.Address)
|
|
|
|
require.Equal(t, uint64(1), withdrawal.Amount)
|
|
|
|
require.DeepEqual(t, [][]byte{
|
|
|
|
bytesutil.PadTo([]byte{'e'}, 48),
|
|
|
|
bytesutil.PadTo([]byte{'f'}, 48),
|
|
|
|
bytesutil.PadTo([]byte{'g'}, 48),
|
|
|
|
bytesutil.PadTo([]byte{'h'}, 48)}, pb.BlobsBundle.Proofs)
|
|
|
|
require.DeepEqual(t, [][]byte{
|
|
|
|
bytesutil.PadTo([]byte{'a'}, 48),
|
|
|
|
bytesutil.PadTo([]byte{'b'}, 48),
|
|
|
|
bytesutil.PadTo([]byte{'c'}, 48),
|
|
|
|
bytesutil.PadTo([]byte{'d'}, 48)}, pb.BlobsBundle.KzgCommitments)
|
|
|
|
require.DeepEqual(t, [][]byte{
|
|
|
|
bytesutil.PadTo([]byte{'i'}, 131072),
|
|
|
|
bytesutil.PadTo([]byte{'j'}, 131072),
|
|
|
|
bytesutil.PadTo([]byte{'k'}, 131072),
|
|
|
|
bytesutil.PadTo([]byte{'l'}, 131072)}, pb.BlobsBundle.Blobs)
|
|
|
|
})
|
|
|
|
|
2022-02-08 18:06:02 +00:00
|
|
|
t.Run("execution block", func(t *testing.T) {
|
2022-03-30 17:17:18 +00:00
|
|
|
baseFeePerGas := big.NewInt(1770307273)
|
2022-07-06 22:06:00 +00:00
|
|
|
want := &gethtypes.Header{
|
|
|
|
Number: big.NewInt(1),
|
|
|
|
ParentHash: common.BytesToHash([]byte("parent")),
|
|
|
|
UncleHash: common.BytesToHash([]byte("uncle")),
|
|
|
|
Coinbase: common.BytesToAddress([]byte("coinbase")),
|
|
|
|
Root: common.BytesToHash([]byte("uncle")),
|
|
|
|
TxHash: common.BytesToHash([]byte("txHash")),
|
|
|
|
ReceiptHash: common.BytesToHash([]byte("receiptHash")),
|
|
|
|
Bloom: gethtypes.BytesToBloom([]byte("bloom")),
|
|
|
|
Difficulty: big.NewInt(2),
|
|
|
|
GasLimit: 3,
|
|
|
|
GasUsed: 4,
|
|
|
|
Time: 5,
|
|
|
|
BaseFee: baseFeePerGas,
|
|
|
|
Extra: []byte("extraData"),
|
|
|
|
MixDigest: common.BytesToHash([]byte("mix")),
|
|
|
|
Nonce: gethtypes.EncodeNonce(6),
|
2022-02-08 18:06:02 +00:00
|
|
|
}
|
2022-07-06 22:06:00 +00:00
|
|
|
enc, err := json.Marshal(want)
|
2022-02-08 18:06:02 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 22:06:00 +00:00
|
|
|
|
|
|
|
payloadItems := make(map[string]interface{})
|
|
|
|
require.NoError(t, json.Unmarshal(enc, &payloadItems))
|
|
|
|
|
|
|
|
blockHash := want.Hash()
|
|
|
|
payloadItems["hash"] = blockHash.String()
|
|
|
|
payloadItems["totalDifficulty"] = "0x393a2e53de197c"
|
|
|
|
|
|
|
|
encodedPayloadItems, err := json.Marshal(payloadItems)
|
2022-04-14 02:47:04 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 22:06:00 +00:00
|
|
|
|
2022-04-14 02:47:04 +00:00
|
|
|
payloadPb := &enginev1.ExecutionBlock{}
|
2022-07-06 22:06:00 +00:00
|
|
|
require.NoError(t, json.Unmarshal(encodedPayloadItems, payloadPb))
|
|
|
|
|
|
|
|
require.DeepEqual(t, blockHash, payloadPb.Hash)
|
|
|
|
require.DeepEqual(t, want.Number, payloadPb.Number)
|
|
|
|
require.DeepEqual(t, want.ParentHash, payloadPb.ParentHash)
|
|
|
|
require.DeepEqual(t, want.UncleHash, payloadPb.UncleHash)
|
|
|
|
require.DeepEqual(t, want.Coinbase, payloadPb.Coinbase)
|
|
|
|
require.DeepEqual(t, want.Root, payloadPb.Root)
|
|
|
|
require.DeepEqual(t, want.TxHash, payloadPb.TxHash)
|
|
|
|
require.DeepEqual(t, want.ReceiptHash, payloadPb.ReceiptHash)
|
|
|
|
require.DeepEqual(t, want.Bloom, payloadPb.Bloom)
|
|
|
|
require.DeepEqual(t, want.Difficulty, payloadPb.Difficulty)
|
|
|
|
require.DeepEqual(t, payloadItems["totalDifficulty"], payloadPb.TotalDifficulty)
|
|
|
|
require.DeepEqual(t, want.GasUsed, payloadPb.GasUsed)
|
|
|
|
require.DeepEqual(t, want.GasLimit, payloadPb.GasLimit)
|
|
|
|
require.DeepEqual(t, want.Time, payloadPb.Time)
|
|
|
|
require.DeepEqual(t, want.BaseFee, payloadPb.BaseFee)
|
|
|
|
require.DeepEqual(t, want.Extra, payloadPb.Extra)
|
|
|
|
require.DeepEqual(t, want.MixDigest, payloadPb.MixDigest)
|
|
|
|
require.DeepEqual(t, want.Nonce, payloadPb.Nonce)
|
2022-04-14 02:47:04 +00:00
|
|
|
})
|
2022-07-07 23:08:44 +00:00
|
|
|
t.Run("execution block with txs as hashes", func(t *testing.T) {
|
|
|
|
baseFeePerGas := big.NewInt(1770307273)
|
|
|
|
want := &gethtypes.Header{
|
|
|
|
Number: big.NewInt(1),
|
|
|
|
ParentHash: common.BytesToHash([]byte("parent")),
|
|
|
|
UncleHash: common.BytesToHash([]byte("uncle")),
|
|
|
|
Coinbase: common.BytesToAddress([]byte("coinbase")),
|
|
|
|
Root: common.BytesToHash([]byte("uncle")),
|
|
|
|
TxHash: common.BytesToHash([]byte("txHash")),
|
|
|
|
ReceiptHash: common.BytesToHash([]byte("receiptHash")),
|
|
|
|
Bloom: gethtypes.BytesToBloom([]byte("bloom")),
|
|
|
|
Difficulty: big.NewInt(2),
|
|
|
|
GasLimit: 3,
|
|
|
|
GasUsed: 4,
|
|
|
|
Time: 5,
|
|
|
|
BaseFee: baseFeePerGas,
|
|
|
|
Extra: []byte("extraData"),
|
|
|
|
MixDigest: common.BytesToHash([]byte("mix")),
|
|
|
|
Nonce: gethtypes.EncodeNonce(6),
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadItems := make(map[string]interface{})
|
|
|
|
require.NoError(t, json.Unmarshal(enc, &payloadItems))
|
|
|
|
|
|
|
|
blockHash := want.Hash()
|
|
|
|
payloadItems["hash"] = blockHash.String()
|
|
|
|
payloadItems["totalDifficulty"] = "0x393a2e53de197c"
|
|
|
|
payloadItems["transactions"] = []string{"0xd57870623ea84ac3e2ffafbee9417fd1263b825b1107b8d606c25460dabeb693"}
|
|
|
|
|
|
|
|
encodedPayloadItems, err := json.Marshal(payloadItems)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadPb := &enginev1.ExecutionBlock{}
|
|
|
|
require.NoError(t, json.Unmarshal(encodedPayloadItems, payloadPb))
|
|
|
|
|
|
|
|
require.DeepEqual(t, blockHash, payloadPb.Hash)
|
|
|
|
require.DeepEqual(t, want.Number, payloadPb.Number)
|
|
|
|
require.DeepEqual(t, want.ParentHash, payloadPb.ParentHash)
|
|
|
|
require.DeepEqual(t, want.UncleHash, payloadPb.UncleHash)
|
|
|
|
require.DeepEqual(t, want.Coinbase, payloadPb.Coinbase)
|
|
|
|
require.DeepEqual(t, want.Root, payloadPb.Root)
|
|
|
|
require.DeepEqual(t, want.TxHash, payloadPb.TxHash)
|
|
|
|
require.DeepEqual(t, want.ReceiptHash, payloadPb.ReceiptHash)
|
|
|
|
require.DeepEqual(t, want.Bloom, payloadPb.Bloom)
|
|
|
|
require.DeepEqual(t, want.Difficulty, payloadPb.Difficulty)
|
|
|
|
require.DeepEqual(t, payloadItems["totalDifficulty"], payloadPb.TotalDifficulty)
|
|
|
|
require.DeepEqual(t, want.GasUsed, payloadPb.GasUsed)
|
|
|
|
require.DeepEqual(t, want.GasLimit, payloadPb.GasLimit)
|
|
|
|
require.DeepEqual(t, want.Time, payloadPb.Time)
|
|
|
|
require.DeepEqual(t, want.BaseFee, payloadPb.BaseFee)
|
|
|
|
require.DeepEqual(t, want.Extra, payloadPb.Extra)
|
|
|
|
require.DeepEqual(t, want.MixDigest, payloadPb.MixDigest)
|
|
|
|
require.DeepEqual(t, want.Nonce, payloadPb.Nonce)
|
|
|
|
|
|
|
|
// Expect no transaction objects in the unmarshaled data.
|
|
|
|
require.Equal(t, 0, len(payloadPb.Transactions))
|
|
|
|
})
|
|
|
|
t.Run("execution block with full transaction data", func(t *testing.T) {
|
|
|
|
baseFeePerGas := big.NewInt(1770307273)
|
|
|
|
want := &gethtypes.Header{
|
|
|
|
Number: big.NewInt(1),
|
|
|
|
ParentHash: common.BytesToHash([]byte("parent")),
|
|
|
|
UncleHash: common.BytesToHash([]byte("uncle")),
|
|
|
|
Coinbase: common.BytesToAddress([]byte("coinbase")),
|
|
|
|
Root: common.BytesToHash([]byte("uncle")),
|
|
|
|
TxHash: common.BytesToHash([]byte("txHash")),
|
|
|
|
ReceiptHash: common.BytesToHash([]byte("receiptHash")),
|
|
|
|
Bloom: gethtypes.BytesToBloom([]byte("bloom")),
|
|
|
|
Difficulty: big.NewInt(2),
|
|
|
|
GasLimit: 3,
|
|
|
|
GasUsed: 4,
|
|
|
|
Time: 5,
|
|
|
|
BaseFee: baseFeePerGas,
|
|
|
|
Extra: []byte("extraData"),
|
|
|
|
MixDigest: common.BytesToHash([]byte("mix")),
|
|
|
|
Nonce: gethtypes.EncodeNonce(6),
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadItems := make(map[string]interface{})
|
|
|
|
require.NoError(t, json.Unmarshal(enc, &payloadItems))
|
|
|
|
|
|
|
|
tx := gethtypes.NewTransaction(
|
|
|
|
1,
|
|
|
|
common.BytesToAddress([]byte("hi")),
|
|
|
|
big.NewInt(0),
|
|
|
|
21000,
|
|
|
|
big.NewInt(1e6),
|
|
|
|
[]byte{},
|
|
|
|
)
|
|
|
|
txs := []*gethtypes.Transaction{tx}
|
|
|
|
|
|
|
|
blockHash := want.Hash()
|
|
|
|
payloadItems["hash"] = blockHash.String()
|
|
|
|
payloadItems["totalDifficulty"] = "0x393a2e53de197c"
|
|
|
|
payloadItems["transactions"] = txs
|
|
|
|
|
|
|
|
encodedPayloadItems, err := json.Marshal(payloadItems)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadPb := &enginev1.ExecutionBlock{}
|
|
|
|
require.NoError(t, json.Unmarshal(encodedPayloadItems, payloadPb))
|
|
|
|
|
|
|
|
require.DeepEqual(t, blockHash, payloadPb.Hash)
|
|
|
|
require.DeepEqual(t, want.Number, payloadPb.Number)
|
|
|
|
require.DeepEqual(t, want.ParentHash, payloadPb.ParentHash)
|
|
|
|
require.DeepEqual(t, want.UncleHash, payloadPb.UncleHash)
|
|
|
|
require.DeepEqual(t, want.Coinbase, payloadPb.Coinbase)
|
|
|
|
require.DeepEqual(t, want.Root, payloadPb.Root)
|
|
|
|
require.DeepEqual(t, want.TxHash, payloadPb.TxHash)
|
|
|
|
require.DeepEqual(t, want.ReceiptHash, payloadPb.ReceiptHash)
|
|
|
|
require.DeepEqual(t, want.Bloom, payloadPb.Bloom)
|
|
|
|
require.DeepEqual(t, want.Difficulty, payloadPb.Difficulty)
|
|
|
|
require.DeepEqual(t, payloadItems["totalDifficulty"], payloadPb.TotalDifficulty)
|
|
|
|
require.DeepEqual(t, want.GasUsed, payloadPb.GasUsed)
|
|
|
|
require.DeepEqual(t, want.GasLimit, payloadPb.GasLimit)
|
|
|
|
require.DeepEqual(t, want.Time, payloadPb.Time)
|
|
|
|
require.DeepEqual(t, want.BaseFee, payloadPb.BaseFee)
|
|
|
|
require.DeepEqual(t, want.Extra, payloadPb.Extra)
|
|
|
|
require.DeepEqual(t, want.MixDigest, payloadPb.MixDigest)
|
|
|
|
require.DeepEqual(t, want.Nonce, payloadPb.Nonce)
|
|
|
|
require.Equal(t, 1, len(payloadPb.Transactions))
|
|
|
|
require.DeepEqual(t, txs[0].Hash(), payloadPb.Transactions[0].Hash())
|
|
|
|
})
|
2022-12-14 13:42:48 +00:00
|
|
|
t.Run("execution block with withdrawals", func(t *testing.T) {
|
|
|
|
baseFeePerGas := big.NewInt(1770307273)
|
|
|
|
want := &gethtypes.Header{
|
|
|
|
Number: big.NewInt(1),
|
|
|
|
ParentHash: common.BytesToHash([]byte("parent")),
|
|
|
|
UncleHash: common.BytesToHash([]byte("uncle")),
|
|
|
|
Coinbase: common.BytesToAddress([]byte("coinbase")),
|
|
|
|
Root: common.BytesToHash([]byte("uncle")),
|
|
|
|
TxHash: common.BytesToHash([]byte("txHash")),
|
|
|
|
ReceiptHash: common.BytesToHash([]byte("receiptHash")),
|
|
|
|
Bloom: gethtypes.BytesToBloom([]byte("bloom")),
|
|
|
|
Difficulty: big.NewInt(2),
|
|
|
|
GasLimit: 3,
|
|
|
|
GasUsed: 4,
|
|
|
|
Time: 5,
|
|
|
|
BaseFee: baseFeePerGas,
|
|
|
|
Extra: []byte("extraData"),
|
|
|
|
MixDigest: common.BytesToHash([]byte("mix")),
|
|
|
|
Nonce: gethtypes.EncodeNonce(6),
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadItems := make(map[string]interface{})
|
|
|
|
require.NoError(t, json.Unmarshal(enc, &payloadItems))
|
|
|
|
|
|
|
|
blockHash := want.Hash()
|
|
|
|
payloadItems["hash"] = blockHash.String()
|
|
|
|
payloadItems["totalDifficulty"] = "0x393a2e53de197c"
|
|
|
|
|
|
|
|
withdrawalIndex1 := hexutil.Uint64(1)
|
|
|
|
withdrawalIndex2 := hexutil.Uint64(2)
|
2023-01-16 21:25:16 +00:00
|
|
|
withdrawalAmount1 := hexutil.Uint64(100)
|
|
|
|
withdrawalAmount2 := hexutil.Uint64(200)
|
2022-12-14 13:42:48 +00:00
|
|
|
withdrawalValidator1 := hexutil.Uint64(1)
|
|
|
|
withdrawalValidator2 := hexutil.Uint64(2)
|
|
|
|
address1 := common.Address(bytesutil.ToBytes20([]byte("address1")))
|
|
|
|
address2 := common.Address(bytesutil.ToBytes20([]byte("address2")))
|
|
|
|
payloadItems["withdrawals"] = []*withdrawalJSON{
|
|
|
|
{
|
|
|
|
Index: &withdrawalIndex1,
|
|
|
|
Validator: &withdrawalValidator1,
|
|
|
|
Address: &address1,
|
2023-01-16 21:25:16 +00:00
|
|
|
Amount: &withdrawalAmount1,
|
2022-12-14 13:42:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Index: &withdrawalIndex2,
|
|
|
|
Validator: &withdrawalValidator2,
|
|
|
|
Address: &address2,
|
2023-01-16 21:25:16 +00:00
|
|
|
Amount: &withdrawalAmount2,
|
2022-12-14 13:42:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
encodedPayloadItems, err := json.Marshal(payloadItems)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadPb := &enginev1.ExecutionBlock{}
|
|
|
|
require.NoError(t, json.Unmarshal(encodedPayloadItems, payloadPb))
|
|
|
|
|
|
|
|
require.DeepEqual(t, blockHash, payloadPb.Hash)
|
|
|
|
require.DeepEqual(t, want.Number, payloadPb.Number)
|
|
|
|
require.DeepEqual(t, want.ParentHash, payloadPb.ParentHash)
|
|
|
|
require.DeepEqual(t, want.UncleHash, payloadPb.UncleHash)
|
|
|
|
require.DeepEqual(t, want.Coinbase, payloadPb.Coinbase)
|
|
|
|
require.DeepEqual(t, want.Root, payloadPb.Root)
|
|
|
|
require.DeepEqual(t, want.TxHash, payloadPb.TxHash)
|
|
|
|
require.DeepEqual(t, want.ReceiptHash, payloadPb.ReceiptHash)
|
|
|
|
require.DeepEqual(t, want.Bloom, payloadPb.Bloom)
|
|
|
|
require.DeepEqual(t, want.Difficulty, payloadPb.Difficulty)
|
|
|
|
require.DeepEqual(t, payloadItems["totalDifficulty"], payloadPb.TotalDifficulty)
|
|
|
|
require.DeepEqual(t, want.GasUsed, payloadPb.GasUsed)
|
|
|
|
require.DeepEqual(t, want.GasLimit, payloadPb.GasLimit)
|
|
|
|
require.DeepEqual(t, want.Time, payloadPb.Time)
|
|
|
|
require.DeepEqual(t, want.BaseFee, payloadPb.BaseFee)
|
|
|
|
require.DeepEqual(t, want.Extra, payloadPb.Extra)
|
|
|
|
require.DeepEqual(t, want.MixDigest, payloadPb.MixDigest)
|
|
|
|
require.DeepEqual(t, want.Nonce, payloadPb.Nonce)
|
|
|
|
require.Equal(t, 2, len(payloadPb.Withdrawals))
|
2022-12-15 23:42:07 +00:00
|
|
|
require.Equal(t, uint64(1), payloadPb.Withdrawals[0].Index)
|
2023-01-26 14:40:12 +00:00
|
|
|
require.Equal(t, primitives.ValidatorIndex(1), payloadPb.Withdrawals[0].ValidatorIndex)
|
2022-12-15 23:42:07 +00:00
|
|
|
require.DeepEqual(t, bytesutil.PadTo([]byte("address1"), 20), payloadPb.Withdrawals[0].Address)
|
2023-01-16 21:25:16 +00:00
|
|
|
require.Equal(t, uint64(100), payloadPb.Withdrawals[0].Amount)
|
2022-12-15 23:42:07 +00:00
|
|
|
require.Equal(t, uint64(2), payloadPb.Withdrawals[1].Index)
|
2023-01-26 14:40:12 +00:00
|
|
|
require.Equal(t, primitives.ValidatorIndex(2), payloadPb.Withdrawals[1].ValidatorIndex)
|
2022-12-15 23:42:07 +00:00
|
|
|
require.DeepEqual(t, bytesutil.PadTo([]byte("address2"), 20), payloadPb.Withdrawals[1].Address)
|
2023-01-16 21:25:16 +00:00
|
|
|
require.Equal(t, uint64(200), payloadPb.Withdrawals[1].Amount)
|
2022-12-14 13:42:48 +00:00
|
|
|
})
|
2023-09-07 16:52:02 +00:00
|
|
|
t.Run("execution block with deneb blob data", func(t *testing.T) {
|
|
|
|
baseFeePerGas := big.NewInt(1770307273)
|
|
|
|
blobGas := uint64(3000)
|
|
|
|
excessGas := uint64(7000)
|
|
|
|
want := &gethtypes.Header{
|
|
|
|
Number: big.NewInt(1),
|
|
|
|
ParentHash: common.BytesToHash([]byte("parent")),
|
|
|
|
UncleHash: common.BytesToHash([]byte("uncle")),
|
|
|
|
Coinbase: common.BytesToAddress([]byte("coinbase")),
|
|
|
|
Root: common.BytesToHash([]byte("uncle")),
|
|
|
|
TxHash: common.BytesToHash([]byte("txHash")),
|
|
|
|
ReceiptHash: common.BytesToHash([]byte("receiptHash")),
|
|
|
|
Bloom: gethtypes.BytesToBloom([]byte("bloom")),
|
|
|
|
Difficulty: big.NewInt(2),
|
|
|
|
GasLimit: 3,
|
|
|
|
GasUsed: 4,
|
|
|
|
Time: 5,
|
|
|
|
BaseFee: baseFeePerGas,
|
|
|
|
Extra: []byte("extraData"),
|
|
|
|
MixDigest: common.BytesToHash([]byte("mix")),
|
|
|
|
Nonce: gethtypes.EncodeNonce(6),
|
|
|
|
BlobGasUsed: &blobGas,
|
|
|
|
ExcessBlobGas: &excessGas,
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadItems := make(map[string]interface{})
|
|
|
|
require.NoError(t, json.Unmarshal(enc, &payloadItems))
|
|
|
|
|
|
|
|
blockHash := want.Hash()
|
|
|
|
payloadItems["hash"] = blockHash.String()
|
|
|
|
payloadItems["totalDifficulty"] = "0x393a2e53de197c"
|
|
|
|
payloadItems["transactions"] = []string{"0xd57870623ea84ac3e2ffafbee9417fd1263b825b1107b8d606c25460dabeb693"}
|
|
|
|
|
|
|
|
encodedPayloadItems, err := json.Marshal(payloadItems)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
payloadPb := &enginev1.ExecutionBlock{}
|
|
|
|
require.NoError(t, json.Unmarshal(encodedPayloadItems, payloadPb))
|
|
|
|
|
|
|
|
require.DeepEqual(t, blockHash, payloadPb.Hash)
|
|
|
|
require.DeepEqual(t, want.Number, payloadPb.Number)
|
|
|
|
require.DeepEqual(t, want.ParentHash, payloadPb.ParentHash)
|
|
|
|
require.DeepEqual(t, want.UncleHash, payloadPb.UncleHash)
|
|
|
|
require.DeepEqual(t, want.Coinbase, payloadPb.Coinbase)
|
|
|
|
require.DeepEqual(t, want.Root, payloadPb.Root)
|
|
|
|
require.DeepEqual(t, want.TxHash, payloadPb.TxHash)
|
|
|
|
require.DeepEqual(t, want.ReceiptHash, payloadPb.ReceiptHash)
|
|
|
|
require.DeepEqual(t, want.Bloom, payloadPb.Bloom)
|
|
|
|
require.DeepEqual(t, want.Difficulty, payloadPb.Difficulty)
|
|
|
|
require.DeepEqual(t, payloadItems["totalDifficulty"], payloadPb.TotalDifficulty)
|
|
|
|
require.DeepEqual(t, want.GasUsed, payloadPb.GasUsed)
|
|
|
|
require.DeepEqual(t, want.GasLimit, payloadPb.GasLimit)
|
|
|
|
require.DeepEqual(t, want.Time, payloadPb.Time)
|
|
|
|
require.DeepEqual(t, want.BaseFee, payloadPb.BaseFee)
|
|
|
|
require.DeepEqual(t, want.Extra, payloadPb.Extra)
|
|
|
|
require.DeepEqual(t, want.MixDigest, payloadPb.MixDigest)
|
|
|
|
require.DeepEqual(t, want.Nonce, payloadPb.Nonce)
|
|
|
|
require.DeepEqual(t, want.BlobGasUsed, payloadPb.BlobGasUsed)
|
|
|
|
require.DeepEqual(t, want.ExcessBlobGas, payloadPb.ExcessBlobGas)
|
|
|
|
|
|
|
|
// Expect no transaction objects in the unmarshaled data.
|
|
|
|
require.Equal(t, 0, len(payloadPb.Transactions))
|
|
|
|
})
|
2022-02-01 01:47:34 +00:00
|
|
|
}
|
2022-02-07 17:13:01 +00:00
|
|
|
|
2022-02-09 20:54:56 +00:00
|
|
|
func TestPayloadIDBytes_MarshalUnmarshalJSON(t *testing.T) {
|
|
|
|
item := [8]byte{1, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
enc, err := json.Marshal(enginev1.PayloadIDBytes(item))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, "\"0x0100000000000000\"", string(enc))
|
|
|
|
res := &enginev1.PayloadIDBytes{}
|
|
|
|
err = res.UnmarshalJSON(enc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, item == *res)
|
2022-02-07 17:13:01 +00:00
|
|
|
}
|
2022-07-14 15:33:32 +00:00
|
|
|
|
2023-07-18 15:46:23 +00:00
|
|
|
func TestExecutionPayloadBody_MarshalUnmarshalJSON(t *testing.T) {
|
|
|
|
pBody := &enginev1.ExecutionPayloadBodyV1{
|
|
|
|
Transactions: [][]byte{[]byte("random1"), []byte("random2"), []byte("random3")},
|
|
|
|
Withdrawals: []*enginev1.Withdrawal{
|
2023-07-31 15:02:42 +00:00
|
|
|
{
|
2023-07-18 15:46:23 +00:00
|
|
|
Index: 200,
|
|
|
|
ValidatorIndex: 20303,
|
|
|
|
Amount: 3200000000,
|
|
|
|
Address: bytesutil.PadTo([]byte("junk"), 20),
|
|
|
|
},
|
2023-07-31 15:02:42 +00:00
|
|
|
{
|
2023-07-18 15:46:23 +00:00
|
|
|
Index: 200,
|
|
|
|
ValidatorIndex: 70303,
|
|
|
|
Amount: 3200000800,
|
|
|
|
Address: bytesutil.PadTo([]byte("junk2"), 20),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
enc, err := json.Marshal(pBody)
|
|
|
|
require.NoError(t, err)
|
|
|
|
res := &enginev1.ExecutionPayloadBodyV1{}
|
|
|
|
err = res.UnmarshalJSON(enc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, pBody, res)
|
|
|
|
}
|
|
|
|
|
2022-07-14 15:33:32 +00:00
|
|
|
func TestExecutionBlock_MarshalUnmarshalJSON_MainnetBlock(t *testing.T) {
|
|
|
|
newBlock := &enginev1.ExecutionBlock{}
|
|
|
|
require.NoError(t, newBlock.UnmarshalJSON([]byte(blockJson)))
|
|
|
|
_, err := newBlock.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
newBlock = &enginev1.ExecutionBlock{}
|
|
|
|
require.NoError(t, newBlock.UnmarshalJSON([]byte(blockNoTxJson)))
|
|
|
|
_, err = newBlock.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var blockJson = `{"baseFeePerGas":"0x42110b4f7","difficulty":"0x280ae66012087c","extraData":"0xe4b883e5bda9e7a59ee4bb99e9b1bc4b3021","gasLimit":"0x1c9c380","gasUsed":"0xf829e","hash":"0xf5bda634715a9d8af2693b600a725a0db285f0267f25b7f60f5b9c502691aef8","logsBloom":"0x002000000010100110000000800008200000000000000000000020001000200000040104000000000000101000000100820080800800080000a008000a01200000000000000001202042000c000000200841000000002001200004008000102002000000000200000000010440000042000000000000080000000010001000002000020000020000000000000000000002000001000010080020004008100000880001080000400000004080060200000800010000040002204000000000020000000002000000000000000001000008000000400000001002010804000000000020a40800000000070000000401080000000000000880400000000000001000","miner":"0x829bd824b016326a401d083b33d092293333a830","mixHash":"0xc1bcfb6dc83cdc106faad9870ab697dd6c7a5a05ca00b3a5f3c2e021b22e0747","nonce":"0xf09ffce459ff4a07","number":"0xe6f8db","parentHash":"0x5749469a59b1207d4b6d42dd9e31c059aa1586fe070573bf6e5442a626726959","receiptsRoot":"0x3b131e70a5d2e013c5946d6bf0290732ad1d195b05abd72bc0bfb7ed4be202b0","sha3Uncles":"0x4df8516d92fd18ca040f0af06d31afaa3a62dbc6ec7ec758336c81b719782a07","size":"0x18ad","stateRoot":"0xdff0d06049e5a7d5b4249eb2aa4b7c626f7a957733913786912441b89d20a3e1","timestamp":"0x62cf48c6","totalDifficulty":"0xb6c08f1eb97fd70fc5f","transactions":[{"blockHash":"0xf5bda634715a9d8af2693b600a725a0db285f0267f25b7f60f5b9c502691aef8","blockNumber":"0xe6f8db","from":"0x10121cb2b3f64f0a6231178336aca3e3b87d5ca5","gas":"0x222e0","gasPrice":"0x6be56a00f","hash":"0x7d503dbb3661532e9bf51a23eeb284bb0d3a1cb99212108ceae70730a2617d7c","input":"0xb31c01fb66054fe7e80881e2dfed6bdd67d09c6a50461013b2ff4b3e9684f57fb58a9f07543c63a826a769aad2d6e3bfacdda2a930f25782caeeb3b6a66c7e6cc5a4811c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000419bb97c858f8c9d2ca3cf28f0236e15fa68a74c4263c28baecd00f603690dbf1c17bf2f4ad0767dbb92118e479b7a716ed465ed27a5b7decbcf9ba5cc1e911ae41b00000000000000000000000000000000000000000000000000000000000000","nonce":"0xc5f","to":"0x049b51e531fd8f90da6d92ea83dc4125002f20ef","transactionIndex":"0x0","value":"0x0","type":"0x0","v":"0x25","r":"0x8cb6e54a332bce463b2184ff252c35d400b5548fb5d5e1a711bf64d6bec5cd55","s":"0x42d5c57f90f5394814b10f1046e4188eebb72aff7f9c8e838b28159b9c47985f"},{"blockHash":"0xf5bda634715a9d8af2693b600a725a0db285f0267f25b7f60f5b9c502691aef8","blockNumber":"0xe6f8db","from":"0xc8231eb0f6be12cca4e8de38fbd36382f827b615","gas":"0x33f9d","gasPrice":"0x4b613adf7","maxFeePerGas":"0x8dffb706a","maxPriorityFeePerGas":"0x9502f900","hash":"0x3a3d2c7624c0029d4865ca8e92ff737d971bcee393a22f4e231a801774ae5cda","input":"0xfb0f3ee100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000393bf5ab54e000000000000000000000000000e476199b37e70258d144a53d9522747c9d9cc82b000000000000000000000000004c00500000ad104d7dbd00e3ae0a5c00560c00000000000000000000000000dcaf23e44639daf29f6532da213999d737f15aa40000000000000000000000000000000000000000000000000000000000000937000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000062cf47430000000000000000000000000000000000000000000000000000000062f81edd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120bbba61bdc2df0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000
|
|
|
|
var blockNoTxJson = `{"baseFeePerGas":"0x42110b4f7","difficulty":"0x280ae66012087c","extraData":"0xe4b883e5bda9e7a59ee4bb99e9b1bc4b3021","gasLimit":"0x1c9c380","gasUsed":"0xf829e","hash":"0xf5bda634715a9d8af2693b600a725a0db285f0267f25b7f60f5b9c502691aef8","logsBloom":"0x002000000010100110000000800008200000000000000000000020001000200000040104000000000000101000000100820080800800080000a008000a01200000000000000001202042000c000000200841000000002001200004008000102002000000000200000000010440000042000000000000080000000010001000002000020000020000000000000000000002000001000010080020004008100000880001080000400000004080060200000800010000040002204000000000020000000002000000000000000001000008000000400000001002010804000000000020a40800000000070000000401080000000000000880400000000000001000","miner":"0x829bd824b016326a401d083b33d092293333a830","mixHash":"0xc1bcfb6dc83cdc106faad9870ab697dd6c7a5a05ca00b3a5f3c2e021b22e0747","nonce":"0xf09ffce459ff4a07","number":"0xe6f8db","parentHash":"0x5749469a59b1207d4b6d42dd9e31c059aa1586fe070573bf6e5442a626726959","receiptsRoot":"0x3b131e70a5d2e013c5946d6bf0290732ad1d195b05abd72bc0bfb7ed4be202b0","sha3Uncles":"0x4df8516d92fd18ca040f0af06d31afaa3a62dbc6ec7ec758336c81b719782a07","size":"0x18ad","stateRoot":"0xdff0d06049e5a7d5b4249eb2aa4b7c626f7a957733913786912441b89d20a3e1","timestamp":"0x62cf48c6","totalDifficulty":"0xb6c08f1eb97fd70fc5f","transactions":["0x7d503dbb3661532e9bf51a23eeb284bb0d3a1cb99212108ceae70730a2617d7c","0x3a3d2c7624c0029d4865ca8e92ff737d971bcee393a22f4e231a801774ae5cda","0xe0bd91c32bc87146514a64f2cea7528a9d4e73d847a7ca03667a503cf52ba2cb","0x843f21fe25a934099f6f311665d1e211ff09d4dc8de02b589ddf6eac74d3dfcb","0xbf084d9e3a885bce9a27902aa394f572a1d3382eea003a19393aed9eb5a20be2","0x388fc716a00c94beae24f7e0b52aad43ac34060733890e9ea286273c7787a676","0xcf0e55b95af41c681d92a249a92f0aef8f023da25799efd7442b5c3ef6a52de6","0xa94eaf385588e9596a61851a1d25b0a0007c0e565ad4112bc7d0e91f83888cda","0xb360475e21e44e4d6b982387347c099ea8f2305773724db273128bbfdf82a1db","0xa95eba47cc617f16fa00735bd75cc245511e77c08efa8155ece7e59004265c2f","0xb7ca5adc1ba774c31d551d04aad1fb3c63729fdffe39d8cadf7305413df22f4c","0xa27ccc3bf5dca531769c79795dc74ffeb1161963eeeebaa7ef365303b47b697d","0x42bfe585b3c4974206570b01e01e904ad8e3be8f6ae021acf645116549ef56b3","0x03d033a7910eb2b5023ef9102805c06e30449b9926af32b47c6de3f5ccf45634"],"transactionsRoot":"0x46e27176677a4b37c1fa9bae97ffb48b86a316f9e6568b3320e10dd6954b5d1a","uncles":["0x0b15f885d283bb8044350ccb9b88fa42192926abb41302fefe0179051e4deadb"]}`
|