Skip to content

Commit

Permalink
RPC API: ensure hash field included in batches json
Browse files Browse the repository at this point in the history
  • Loading branch information
BedrockSquirrel committed Dec 7, 2023
1 parent ca7f91b commit f904c8f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type BatchHeader struct {
}

type batchHeaderEncoding struct {
Hash common.Hash `json:"hash"`
ParentHash L2BatchHash `json:"parentHash"`
Root common.Hash `json:"stateRoot"`
TxHash common.Hash `json:"transactionsRoot"`
Expand All @@ -72,6 +73,7 @@ type batchHeaderEncoding struct {
// MarshalJSON custom marshals the BatchHeader into a json
func (b *BatchHeader) MarshalJSON() ([]byte, error) {
return json.Marshal(batchHeaderEncoding{
b.Hash(),
b.ParentHash,
b.Root,
b.TxHash,
Expand Down
41 changes: 41 additions & 0 deletions integration/networktest/actions/publicdata/tenscan_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package publicdata

import (
"context"
"fmt"

"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/obsclient"
"github.com/ten-protocol/go-ten/integration/networktest"
"github.com/ten-protocol/go-ten/integration/networktest/actions"
)

// VerifyBatchesDataAction tests the batches data RPC endpoint
func VerifyBatchesDataAction() networktest.Action {
return actions.VerifyOnlyAction(func(ctx context.Context, network networktest.NetworkConnector) error {
client, err := obsclient.Dial(network.ValidatorRPCAddress(0))
if err != nil {
return err
}

pagination := common.QueryPagination{
Offset: 0,
Size: 20,
}
batchListing, err := client.GetBatchesListing(&pagination)
if err != nil {
return err
}
if len(batchListing.BatchesData) != 20 {
return fmt.Errorf("expected 20 batches, got %d", len(batchListing.BatchesData))
}
if batchListing.Total <= 10 {
return fmt.Errorf("expected more than 10 batches, got %d", batchListing.Total)
}
if batchListing.BatchesData[0].Number.Cmp(batchListing.BatchesData[1].Number) < 0 {
return fmt.Errorf("expected batches to be sorted by height descending")
}

return nil
})
}
24 changes: 24 additions & 0 deletions integration/networktest/tests/tenscan/tenscan_rpc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tenscan

import (
"testing"

"github.com/ten-protocol/go-ten/integration/networktest"
"github.com/ten-protocol/go-ten/integration/networktest/actions"
"github.com/ten-protocol/go-ten/integration/networktest/actions/publicdata"
"github.com/ten-protocol/go-ten/integration/networktest/env"
)

// Verify and debug the RPC endpoints that Tenscan relies on for data in various environments

func TestRPC(t *testing.T) {
networktest.TestOnlyRunsInIDE(t)
networktest.Run(
"tenscan-rpc-data",
t,
env.LocalDevNetwork(),
actions.Series(
publicdata.VerifyBatchesDataAction(),
),
)
}

0 comments on commit f904c8f

Please sign in to comment.