Skip to content

Commit

Permalink
feat(taiko-client): remove useless function and correct erorr handling (
Browse files Browse the repository at this point in the history
#17463)

Co-authored-by: Gavin Yu <[email protected]>
  • Loading branch information
mask-pp and YoGhurt111 authored Jun 4, 2024
1 parent 0e9d160 commit 4e93a57
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 63 deletions.
8 changes: 6 additions & 2 deletions packages/taiko-client/pkg/rpc/beaconclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,17 @@ func (c *BeaconClient) GetBlobs(ctx context.Context, time uint64) ([]*blob.Sidec
return nil, err
}

var sidecars *blob.SidecarsResponse
resBytes, err := c.Get(ctxWithTimeout, c.BaseURL().Path+fmt.Sprintf(sidecarsRequestURL, slot))
if err != nil {
return nil, err
}

return sidecars.Data, json.Unmarshal(resBytes, &sidecars)
var sidecars *blob.SidecarsResponse
if err = json.Unmarshal(resBytes, &sidecars); err != nil {
return nil, err
}

return sidecars.Data, nil
}

// timeToSlot returns the slots of the given timestamp.
Expand Down
22 changes: 0 additions & 22 deletions packages/taiko-client/pkg/rpc/blob_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,6 @@ import (
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
)

func TestGetBlobsFromSocialScan(t *testing.T) {
socialScanEndpoint, err := url.Parse("https://api.socialscan.io/blob-archive/v1/holesky-testnet")
require.Nil(t, err)
require.NotNil(t, socialScanEndpoint)
ds := NewBlobDataSource(
context.Background(),
&Client{},
nil,
socialScanEndpoint,
)
sidecars, err := ds.GetBlobs(
context.Background(),
&bindings.TaikoDataBlockMetadata{
BlobHash: common.HexToHash("0x0145185449c57dee4e6c921b702e5d572fbeb026f96c220a6a17b79d157d921b"),
BlobUsed: true,
},
)
require.Nil(t, err)
require.NotNil(t, sidecars)
require.NotNil(t, sidecars[0].Blob)
}

func TestGetBlobsFromBlobScan(t *testing.T) {
blobScanEndpoint, err := url.Parse("https://api.holesky.blobscan.com")
require.Nil(t, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package anchortxvalidator

import (
"context"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -48,30 +46,16 @@ func (v *AnchorTxValidator) ValidateAnchorTx(tx *types.Transaction) error {
}

method, err := encoding.TaikoL2ABI.MethodById(tx.Data())
if err != nil || method.Name != "anchor" {
return fmt.Errorf("invalid TaikoL2.anchor transaction selector, error: %w", err)
}

return nil
}

// GetAndValidateAnchorTxReceipt gets and validates the `TaikoL2.anchor` transaction's receipt.
func (v *AnchorTxValidator) GetAndValidateAnchorTxReceipt(
ctx context.Context,
tx *types.Transaction,
) (*types.Receipt, error) {
receipt, err := v.rpc.L2.TransactionReceipt(ctx, tx.Hash())
if err != nil {
return nil, fmt.Errorf("failed to get TaikoL2.anchor transaction receipt, error: %w", err)
return fmt.Errorf("failed to get TaikoL2.anchor transaction method: %w", err)
}

if receipt.Status != types.ReceiptStatusSuccessful {
return nil, fmt.Errorf("invalid TaikoL2.anchor transaction receipt status: %d", receipt.Status)
}

if len(receipt.Logs) == 0 {
return nil, errors.New("no event found in TaikoL2.anchor transaction receipt")
if method.Name != "anchor" {
return fmt.Errorf(
"invalid TaikoL2.anchor transaction selector, expect: %s, actual: %s",
"anchor",
method.Name,
)
}

return receipt, nil
return nil
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package anchortxvalidator

import (
"context"
"os"
"testing"

Expand Down Expand Up @@ -64,20 +63,7 @@ func (s *AnchorTxValidatorTestSuite) TestValidateAnchorTx() {

// invalid method selector
tx = types.MustSignNewTx(goldenTouchPriKey, signer, dynamicFeeTxTx)
s.ErrorContains(s.v.ValidateAnchorTx(tx), "invalid TaikoL2.anchor transaction selector")
}

func (s *AnchorTxValidatorTestSuite) TestGetAndValidateAnchorTxReceipt() {
tx := types.NewTransaction(
100,
common.BytesToAddress(testutils.RandomBytes(32)),
common.Big1,
100000,
common.Big1,
[]byte{},
)
_, err := s.v.GetAndValidateAnchorTxReceipt(context.Background(), tx)
s.NotNil(err)
s.ErrorContains(s.v.ValidateAnchorTx(tx), "failed to get TaikoL2.anchor transaction method")
}

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

0 comments on commit 4e93a57

Please sign in to comment.