Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

test(bindings): test TryParsingCustomErrorFromReceipt #758

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"

"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-client/bindings"
Expand Down Expand Up @@ -375,7 +374,7 @@ func (p *Proposer) ProposeTxLists(ctx context.Context, txListsBytes [][]byte) []
// If a transaction is reverted on chain, the error string returned by txSender will like this:
// fmt.Errorf("%w purpose: %v hash: %v", ErrTransactionReverted, txPurpose, rcpt.Receipt.TxHash)
// Then we try parsing the custom error for more details in log.
if strings.Contains("purpose: ", err.Error()) && strings.Contains("hash: ", err.Error()) {
if strings.Contains(err.Error(), "purpose: ") && strings.Contains(err.Error(), "hash: ") {
txHash := strings.Split(err.Error(), "hash: ")[1]
receipt, err := p.rpc.L1.TransactionReceipt(ctx, common.HexToHash(txHash))
if err != nil {
Expand Down
78 changes: 78 additions & 0 deletions proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package proposer
import (
"context"
"os"
"strings"
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-client/driver/chain_syncer/blob"
"github.com/taikoxyz/taiko-client/driver/state"
Expand All @@ -25,6 +28,7 @@ import (
"github.com/taikoxyz/taiko-client/internal/utils"
"github.com/taikoxyz/taiko-client/pkg/jwt"
"github.com/taikoxyz/taiko-client/pkg/rpc"
builder "github.com/taikoxyz/taiko-client/proposer/transaction_builder"
)

type ProposerTestSuite struct {
Expand Down Expand Up @@ -285,6 +289,80 @@ func (s *ProposerTestSuite) TestAssignProverSuccessFirstRound() {
s.Equal(fee.Uint64(), s.p.OptimisticTierFee.Uint64())
}

func (s *ProposerTestSuite) TestProposeTxLists() {
p := s.p
ctx := p.ctx
cfg := s.p.Config

txBuilder := builder.NewBlobTransactionBuilder(
p.rpc,
p.L1ProposerPrivKey,
p.proverSelector,
p.Config.L1BlockBuilderTip,
cfg.TaikoL1Address,
cfg.L2SuggestedFeeRecipient,
cfg.AssignmentHookAddress,
cfg.ProposeBlockTxGasLimit,
cfg.ExtraData,
)

emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{})
s.Nil(err)
txListsBytes := [][]byte{emptyTxListBytes}
txCandidates := make([]txmgr.TxCandidate, len(txListsBytes))
for i, txListBytes := range txListsBytes {
compressedTxListBytes, err := utils.Compress(txListBytes)
if err != nil {
log.Warn("Failed to compress transactions list", "index", i, "error", err)
break
}

candidate, err := txBuilder.Build(
p.ctx,
p.tierFees,
p.IncludeParentMetaHash,
compressedTxListBytes,
)
if err != nil {
log.Warn("Failed to build TaikoL1.proposeBlock transaction", "error", err)
break
}

// trigger the error
candidate.Blobs = []*eth.Blob{}
candidate.GasLimit = 10000000

txCandidates[i] = *candidate
}

// Send the transactions to the TaikoL1 contract, and if any of them fails, try
// to parse the custom error.
errors := p.txSender.SendAndWaitDetailed("proposeBlock", txCandidates...)
for i, err := range errors {
if err == nil {
continue
}

// If a transaction is reverted on chain, the error string returned by txSender will like this:
// fmt.Errorf("%w purpose: %v hash: %v", ErrTransactionReverted, txPurpose, rcpt.Receipt.TxHash)
// Then we try parsing the custom error for more details in log.
if strings.Contains(err.Error(), "purpose: ") && strings.Contains(err.Error(), "hash: ") {
txHash := strings.Split(err.Error(), "hash: ")[1]
receipt, err := p.rpc.L1.TransactionReceipt(ctx, common.HexToHash(txHash))
if err != nil {
log.Error("Failed to fetch receipt", "txHash", txHash, "error", err)
continue
}
errors[i] = encoding.TryParsingCustomErrorFromReceipt(ctx, p.rpc.L1, p.proposerAddress, receipt)
}
}

// confirm errors handled
for _, err := range errors {
s.Equal("L1_BLOB_NOT_AVAILABLE", err.Error())
}
}

func (s *ProposerTestSuite) TestUpdateProposingTicker() {
s.p.ProposeInterval = 1 * time.Hour
s.NotPanics(s.p.updateProposingTicker)
Expand Down
Loading