From dd44f058f4d4c72f6ac824b3c2107f94c144ba03 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 12 Dec 2022 16:11:31 +0100 Subject: [PATCH] Add ContractInfoResponse.Checksum --- types/queries.go | 7 +++++-- types/queries_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/types/queries.go b/types/queries.go index d368d4f44..4d396b30b 100644 --- a/types/queries.go +++ b/types/queries.go @@ -374,8 +374,11 @@ type ContractInfoQuery struct { } type ContractInfoResponse struct { - CodeID uint64 `json:"code_id"` - Creator string `json:"creator"` + CodeID uint64 `json:"code_id"` + // Checksum is the checksum of the Wasm blob behind this code ID. + // This field was newly added in CosmWasm XX.YY. + Checksum string `json:"checksum,omitempty"` + Creator string `json:"creator"` // Set to the admin who can migrate contract, if any Admin string `json:"admin,omitempty"` Pinned bool `json:"pinned"` diff --git a/types/queries_test.go b/types/queries_test.go index edeca8d7e..37ed499b5 100644 --- a/types/queries_test.go +++ b/types/queries_test.go @@ -113,3 +113,39 @@ func TestQueryResponseWithEmptyData(t *testing.T) { }) } } + +func TestContractInfoResponse(t *testing.T) { + // No checksum + info := ContractInfoResponse{ + CodeID: 3456, + Creator: "tgrade1js7ezrm55fqgxu3p62d9xn6patjku2z7ne5dvg", + Admin: "tgrade1z363ulwcrxged4z5jswyt5dn5v3lzsemwz9ewj", + Pinned: false, + IBCPort: "wasm.abcdef", + } + bz, err := json.Marshal(&info) + t.Logf("Serialized: %s", string(bz)) + require.NoError(t, err) + + var deserialized ContractInfoResponse + err = json.Unmarshal(bz, &deserialized) + require.NoError(t, err) + assert.Equal(t, deserialized, info) + + // Checksum set + info = ContractInfoResponse{ + CodeID: 3456, + Checksum: "75b6183689b80a229ea27994a7c8cd9c17ddd29e947998f2734abda825eac3c0", + Creator: "tgrade1js7ezrm55fqgxu3p62d9xn6patjku2z7ne5dvg", + Admin: "tgrade1z363ulwcrxged4z5jswyt5dn5v3lzsemwz9ewj", + Pinned: false, + IBCPort: "wasm.abcdef", + } + bz, err = json.Marshal(&info) + t.Logf("Serialized: %s", string(bz)) + require.NoError(t, err) + + err = json.Unmarshal(bz, &deserialized) + require.NoError(t, err) + assert.Equal(t, deserialized, info) +}