From 8c67c112d9dc1c4fa2252a828de88353d1d772c8 Mon Sep 17 00:00:00 2001 From: Quint Daenen Date: Wed, 10 Apr 2024 17:55:03 +0200 Subject: [PATCH] Get did from metadata instead with _tmp_hack. --- cmd/goic/main.go | 5 ++++- ic/ic_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/goic/main.go b/cmd/goic/main.go index b18ac59..203cd81 100644 --- a/cmd/goic/main.go +++ b/cmd/goic/main.go @@ -140,8 +140,11 @@ func fetchDID(canisterId principal.Principal) ([]byte, error) { return nil, err } var did string + // This endpoint has been deprecated and removed starting with moc v0.11.0. if err := a.Query(canisterId, "__get_candid_interface_tmp_hack", nil, []any{&did}); err != nil { - return nil, err + // It is recommended for the canister to have a custom section called "icp:public candid:service", which + // contains the UTF-8 encoding of the Candid interface for the canister. + return a.GetCanisterMetadata(canisterId, "candid:service") } return []byte(did), nil } diff --git a/ic/ic_test.go b/ic/ic_test.go index fe33066..3b03b67 100644 --- a/ic/ic_test.go +++ b/ic/ic_test.go @@ -81,6 +81,20 @@ func TestModules(t *testing.T) { if err := a.Authorize(principal.AnonymousID); err != nil { t.Fatal(err) } + + { + a, err := agent.New(config) + if err != nil { + t.Fatal(err) + } + did, err := a.GetCanisterMetadata(cId, "candid:service") + if err != nil { + t.Fatal(err) + } + if len(did) == 0 { + t.Error("empty did") + } + } }) t.Run("management canister", func(t *testing.T) {