Skip to content

Commit

Permalink
Fix the header type
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed May 31, 2024
1 parent a453ca1 commit df27493
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion espresso-sequencer
18 changes: 12 additions & 6 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,23 @@ func (i *EitherChainConfig) MarshalJSON() ([]byte, error) {
}

type ChainConfig struct {
ChainId U256Decimal `json:"chain_id"`
MaxBlockSize uint64 `json:"max_block_size"`
BaseFee U256Decimal `json:"base_fee"`
ChainId U256Decimal `json:"chain_id"`
MaxBlockSize U256Decimal `json:"max_block_size"`
BaseFee U256Decimal `json:"base_fee"`
FeeContract *common.Address `json:"fee_contract"`
FeeRecipient common.Address `json:"fee_recipient"`
}

func (self *ChainConfig) Commit() Commitment {
return NewRawCommitmentBuilder("CHAIN_CONFIG").
builder := NewRawCommitmentBuilder("CHAIN_CONFIG").
Uint256Field("chain_id", self.ChainId.ToU256()).
Uint64Field("max_block_size", self.MaxBlockSize).
Uint64Field("max_block_size", self.MaxBlockSize.Uint64()).
Uint256Field("base_fee", self.BaseFee.ToU256()).
Finalize()
FixedSizeField("fee_recipient", self.FeeRecipient.Bytes())
if self.FeeContract == nil {
return builder.Finalize()
}
return builder.Uint64Field("fee_contract", 1).FixedSizeBytes(self.FeeContract.Bytes()).Finalize()
}

type L1BlockInfo struct {
Expand Down
22 changes: 19 additions & 3 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ var ReferenceNsTable NsTable = NsTable{

var ReferenceChainConfig = &ResolvableChainConfig{
EitherChainConfig{
Left: &ChainConfig{ChainId: *NewU256().SetUint64(0x8a19).ToDecimal(), MaxBlockSize: 10240, BaseFee: *NewU256().SetUint64(0).ToDecimal()},
Left: &ChainConfig{
ChainId: *NewU256().SetUint64(0x8a19).ToDecimal(),
MaxBlockSize: *NewU256().SetUint64(10240).ToDecimal(),
BaseFee: *NewU256().SetUint64(0).ToDecimal(),
FeeContract: &common.Address{},
FeeRecipient: common.Address{},
},
},
}

Expand Down Expand Up @@ -86,7 +92,17 @@ func TestEspressoTypesL1BLockInfoJson(t *testing.T) {

func TestEspressoTypesHeaderJson(t *testing.T) {
data := []byte(removeWhitespace(`{
"chain_config": { "chain_config": { "Left": { "chain_id": "35353", "max_block_size": 10240, "base_fee": "0" } } },
"chain_config": {
"chain_config": {
"Left": {
"chain_id": "35353",
"max_block_size": "10240",
"base_fee": "0",
"fee_contract": "0x0000000000000000000000000000000000000000",
"fee_recipient": "0x0000000000000000000000000000000000000000"
}
}
},
"height": 42,
"timestamp": 789,
"l1_head": 124,
Expand Down Expand Up @@ -158,7 +174,7 @@ func TestEspressoTypesNsTable(t *testing.T) {
}

func TestEspressoTypesHeaderCommit(t *testing.T) {
require.Equal(t, ReferenceHeader.Commit(), Commitment{211, 66, 18, 166, 237, 163, 29, 181, 195, 235, 63, 129, 192, 201, 48, 71, 136, 163, 25, 216, 20, 74, 133, 203, 167, 253, 163, 33, 43, 102, 168, 26})
require.Equal(t, ReferenceHeader.Commit(), Commitment{108, 66, 152, 60, 96, 143, 195, 17, 58, 161, 229, 97, 42, 65, 218, 52, 73, 30, 164, 118, 5, 26, 70, 222, 184, 71, 228, 1, 92, 215, 177, 152})
}

func TestEspressoTypesTransaction(t *testing.T) {
Expand Down

0 comments on commit df27493

Please sign in to comment.