From 36f699966541389af97b3ed01a34a0bf73918dd7 Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:45:13 +0000 Subject: [PATCH] RPC API: ensure hash field included in batches json (#1684) (cherry picked from commit 0fd3773181c44e2a115cf282af721a7ca3619b3b) --- go/common/headers.go | 2 + .../actions/publicdata/tenscan_data.go | 41 +++++++++++++++++++ .../tests/tenscan/tenscan_rpc_test.go | 24 +++++++++++ integration/obscuroscan/obscuroscan_test.go | 4 ++ 4 files changed, 71 insertions(+) create mode 100644 integration/networktest/actions/publicdata/tenscan_data.go create mode 100644 integration/networktest/tests/tenscan/tenscan_rpc_test.go diff --git a/go/common/headers.go b/go/common/headers.go index 8052324bb7..ef5d392f59 100644 --- a/go/common/headers.go +++ b/go/common/headers.go @@ -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"` @@ -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, diff --git a/integration/networktest/actions/publicdata/tenscan_data.go b/integration/networktest/actions/publicdata/tenscan_data.go new file mode 100644 index 0000000000..c4c9e1d7f0 --- /dev/null +++ b/integration/networktest/actions/publicdata/tenscan_data.go @@ -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 + }) +} diff --git a/integration/networktest/tests/tenscan/tenscan_rpc_test.go b/integration/networktest/tests/tenscan/tenscan_rpc_test.go new file mode 100644 index 0000000000..fb4b4835c4 --- /dev/null +++ b/integration/networktest/tests/tenscan/tenscan_rpc_test.go @@ -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(), + ), + ) +} diff --git a/integration/obscuroscan/obscuroscan_test.go b/integration/obscuroscan/obscuroscan_test.go index a6424866e1..4d0ecf0589 100644 --- a/integration/obscuroscan/obscuroscan_test.go +++ b/integration/obscuroscan/obscuroscan_test.go @@ -136,6 +136,10 @@ func TestObscuroscan(t *testing.T) { assert.NoError(t, err) assert.LessOrEqual(t, 9, len(batchlistingObj.Result.BatchesData)) assert.LessOrEqual(t, uint64(9), batchlistingObj.Result.Total) + // check results are descending order (latest first) + assert.LessOrEqual(t, batchlistingObj.Result.BatchesData[1].Number.Cmp(batchlistingObj.Result.BatchesData[0].Number), 0) + // check "hash" field is included in json response + assert.Contains(t, string(body), "\"hash\"") statusCode, body, err = fasthttp.Get(nil, fmt.Sprintf("%s/items/blocks/?offset=0&size=10", serverAddress)) assert.NoError(t, err)