Skip to content

Commit

Permalink
test ToStd
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Sep 12, 2024
1 parent f09cba2 commit 250cbd9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
28 changes: 27 additions & 1 deletion prover/lib/compressor/blob/encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,31 @@ func (d *DecodedBlockData) ToStd() *types.Block {
}
}

return types.NewBlock(&header, &body, nil, nil)
return types.NewBlock(&header, &body, nil, emptyTrieHasher{})
}

type fixedTrieHasher common.Hash

func (e fixedTrieHasher) Reset() {
}

func (e fixedTrieHasher) Update(_, _ []byte) error {
return nil
}

func (e fixedTrieHasher) Hash() common.Hash {
return common.Hash(e)
}

type emptyTrieHasher struct{}

func (h emptyTrieHasher) Reset() {
}

func (h emptyTrieHasher) Update(_, _ []byte) error {
return nil
}

func (h emptyTrieHasher) Hash() common.Hash {
return common.Hash{}
}
36 changes: 27 additions & 9 deletions prover/lib/compressor/blob/v1/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"fmt"
"testing"

"github.com/consensys/zkevm-monorepo/prover/lib/compressor/blob/encode"

v1 "github.com/consensys/zkevm-monorepo/prover/lib/compressor/blob/v1"
"github.com/consensys/zkevm-monorepo/prover/lib/compressor/blob/v1/test_utils"
"github.com/consensys/zkevm-monorepo/prover/utils/types"
Expand All @@ -36,10 +34,6 @@ func TestEncodeDecode(t *testing.T) {
}

var buf bytes.Buffer
expected := encode.DecodedBlockData{
BlockHash: block.Hash(),
Timestamp: block.Time(),
}

if err := v1.EncodeBlockForCompression(&block, &buf); err != nil {
t.Fatalf("failed encoding the block: %s", err.Error())
Expand All @@ -54,16 +48,40 @@ func TestEncodeDecode(t *testing.T) {
assert.NotZero(t, size, "scanned a block size of zero")

require.NoError(t, err)
assert.Equal(t, expected.BlockHash, decoded.BlockHash)
assert.Equal(t, expected.Timestamp, decoded.Timestamp)
assert.Equal(t, block.Hash(), decoded.BlockHash)
assert.Equal(t, block.Time(), decoded.Timestamp)
assert.Equal(t, len(block.Transactions()), len(decoded.Txs))

for i := range expected.Txs {
for i := range block.Transactions() {
checkSameTx(t, block.Transactions()[i], ethtypes.NewTx(decoded.Txs[i]), decoded.Froms[i])
if t.Failed() {
return
}
}

t.Log("attempting RLP serialization")

encoded, err = rlp.EncodeToBytes(decoded.ToStd())
assert.NoError(t, err)

var blockBack ethtypes.Block
assert.NoError(t, rlp.Decode(bytes.NewReader(encoded), &blockBack))

assert.Equal(t, block.Hash(), blockBack.ParentHash())
assert.Equal(t, block.Time(), blockBack.Time())
assert.Equal(t, len(block.Transactions()), len(blockBack.Transactions()))

for i := range block.Transactions() {
tx := blockBack.Transactions()[i]
_, fromInt, _ := tx.RawSignatureValues()
var from common.Address
fromInt.FillBytes(from[:])
checkSameTx(t, block.Transactions()[i], ethtypes.NewTx(decoded.Txs[i]), from)
if t.Failed() {
return
}
}

})
}

Expand Down

0 comments on commit 250cbd9

Please sign in to comment.