-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC API: ensure hash field included in batches json #1684
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
} | ||
Comment on lines
+21
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded values for pagination ( |
||
if batchListing.BatchesData[0].Number.Cmp(batchListing.BatchesData[1].Number) < 0 { | ||
return fmt.Errorf("expected batches to be sorted by height descending") | ||
} | ||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sorting check only compares the first two batches for descending order. To ensure robustness, consider iterating over the entire list of batches to verify that they are sorted correctly by height in descending order. |
||
|
||
return nil | ||
}) | ||
} | ||
Comment on lines
+13
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function |
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(), | ||
), | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
UnmarshalJSON
method should be updated to handle the newHash
field to maintain symmetry with theMarshalJSON
method.func (b *BatchHeader) UnmarshalJSON(data []byte) error { dec := new(batchHeaderEncoding) err := json.Unmarshal(data, dec) if err != nil { return err } + b.Hash = dec.Hash b.ParentHash = dec.ParentHash // ... rest of the fields ... return nil }
Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary because hash is a calculated field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BedrockSquirrel Understood, the
Hash
field is computed using theHash()
method and does not need to be unmarshaled from JSON. Thank you for the clarification.