Skip to content

Cardano blueprint localstate query tests #992

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

Closed

Conversation

ch1bo
Copy link
Contributor

@ch1bo ch1bo commented Apr 17, 2025

Explores how we could test the LocalStatQuery API that is being created in course of the blueprint initiative.

  • This is adding a cardano-blueprint submodule from which local state query and result cbor examples are taken to test serialization roundtrips.

  • Changes SystemStartResult to hold big.Int for Year and Picoseconds as the CDDL (and at least the Haskell server) are using unbounded integers

    type SystemStartResult struct {
        // Tells the CBOR decoder to convert to/from a struct and a CBOR array
        _           struct{} `cbor:",toarray"`
        Year        big.Int
        Day         int
        Picoseconds big.Int
    }
    • This required a few additional custom methods on SystemStartResult to make roundtrips work. Happy for some feedback in how to improve / avoid those changes.

@agaffney
Copy link
Contributor

That failing test you noted is due to pointer vs. non-pointer in the DeepEqual() comparison

@agaffney
Copy link
Contributor

@ch1bo it took a bit of playing around, but I figured out how to fix the test failure. Reflection is fun!

diff --git a/protocol/localstatequery/messages_test.go b/protocol/localstatequery/messages_test.go
index 4156f5f..cbe1fba 100644
--- a/protocol/localstatequery/messages_test.go
+++ b/protocol/localstatequery/messages_test.go
@@ -135,10 +135,10 @@ func TestDecode(t *testing.T) {
                        if err != nil {
                                t.Fatalf("failed to decode result: %s", err)
                        }
-                       if !reflect.DeepEqual(decoded.Interface(), test.Result) {
+                       if !reflect.DeepEqual(reflect.Indirect(decoded).Interface(), test.Result) {
                                t.Fatalf(
                                        "MsgResult content did not decode to expected Result object\n  got:    %#v\n  wanted: %#v",
-                                       decoded.Interface(),
+                                       reflect.Indirect(decoded).Interface(),
                                        test.Result,
                                )
                        }

Adds cardano-blueprint submodule that contains first examples of local
state query query and result data.

The included getSystemStart result example was generated using the
actual data type used by the haskell server implementation. To make the
example roundtrip, big integers (> int64) must be supported.

Signed-off-by: Sebastian Nagel <[email protected]>
@ch1bo ch1bo force-pushed the cardano-blueprint-tests branch from e36727b to 9cf8983 Compare April 28, 2025 11:08
@ch1bo
Copy link
Contributor Author

ch1bo commented Apr 28, 2025

Squashed into a single commit following https://www.conventionalcommits.org/en/v1.0.0/ as suggested by @wolf31o2. Only found these contributing guidelines using the github UI. Originally I was looking for a CONTRIBUTING.md in the repo but did not find one.

@wolf31o2
Copy link
Member

Thanks for the contribution. We had per-repo contributing files, but they were redundant to maintain, especially remembering them in new repos. I'll look at adding them back to each repo.

@wolf31o2
Copy link
Member

I have no idea why this is still not processing on the GitHub side. Since it's acting so weird, I decided to make a new branch, cherry-pick your changes, rebase them on main, and add json struct tags to make golangci-lint happy.

The pull request in #1001 replaces this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants