Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Sep 13, 2024
1 parent b53fb4c commit d390153
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
18 changes: 8 additions & 10 deletions prover/lib/compressor/blob/v1/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/consensys/zkevm-monorepo/prover/lib/compressor/blob/encode"
"io"

"github.com/consensys/linea-monorepo/prover/backend/ethereum"
"github.com/consensys/linea-monorepo/prover/lib/compressor/blob/encode"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
Expand Down Expand Up @@ -186,28 +187,25 @@ func DecodeBlockFromUncompressed(r *bytes.Reader) (encode.DecodedBlockData, erro
numTxs := int(decNumTxs)
decodedBlk := encode.DecodedBlockData{
Froms: make([]common.Address, numTxs),
Txs: make([]types.Transaction, numTxs),
Txs: make([]types.TxData, numTxs),
Timestamp: uint64(decTimestamp),
BlockHash: blockHash,
}

var err error
for i := 0; i < int(decNumTxs); i++ {
if err := DecodeTxFromUncompressed(r, &decodedBlk.Txs[i], &decodedBlk.Froms[i]); err != nil {
if decodedBlk.Txs[i], err = DecodeTxFromUncompressed(r, &decodedBlk.Froms[i]); err != nil {
return encode.DecodedBlockData{}, fmt.Errorf("could not decode transaction #%v: %w", i, err)
}
}

return decodedBlk, nil
}

func DecodeTxFromUncompressed(r *bytes.Reader, tx *types.Transaction, from *common.Address) (err error) {
func DecodeTxFromUncompressed(r *bytes.Reader, from *common.Address) (types.TxData, error) {
if _, err := r.Read(from[:]); err != nil {
return fmt.Errorf("could not read from address: %w", err)
}

if err := ethereum.DecodeTxFromBytes(r, tx); err != nil {
return fmt.Errorf("could not deserialize transaction")
return nil, fmt.Errorf("could not read from address: %w", err)
}

return nil
return ethereum.DecodeTxFromBytes(r)
}
11 changes: 3 additions & 8 deletions prover/lib/compressor/blob/v1/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"bytes"
"encoding/hex"
"fmt"
"github.com/consensys/zkevm-monorepo/prover/lib/compressor/blob/encode"
"testing"

"github.com/consensys/linea-monorepo/prover/lib/compressor/blob/encode"
v1 "github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v1"
"github.com/consensys/linea-monorepo/prover/lib/compressor/blob/v1/test_utils"
"github.com/consensys/linea-monorepo/prover/utils/types"
Expand Down Expand Up @@ -37,14 +37,9 @@ func TestEncodeDecode(t *testing.T) {
var buf bytes.Buffer
expected := encode.DecodedBlockData{
BlockHash: block.Hash(),
Txs: make([]ethtypes.Transaction, len(block.Transactions())),
Timestamp: block.Time(),
}

for i := range expected.Txs {
expected.Txs[i] = *block.Transactions()[i]
}

if err := v1.EncodeBlockForCompression(&block, &buf); err != nil {
t.Fatalf("failed encoding the block: %s", err.Error())
}
Expand All @@ -60,10 +55,10 @@ func TestEncodeDecode(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expected.BlockHash, decoded.BlockHash)
assert.Equal(t, expected.Timestamp, decoded.Timestamp)
assert.Equal(t, len(expected.Txs), len(decoded.Txs))
assert.Equal(t, len(block.Transactions()), len(decoded.Txs))

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

0 comments on commit d390153

Please sign in to comment.