Skip to content

Commit

Permalink
Wrap candid marshalling within pocketic.UpdateCall.
Browse files Browse the repository at this point in the history
  • Loading branch information
q-uint committed May 6, 2024
1 parent 40dc28e commit fbd56e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions pocketic/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ func TestEndpoints(t *testing.T) {
}
})

t.Run("update", func(t *testing.T) {
if err := pic.UpdateCall(*canisterID, principal.AnonymousID, "void", nil, nil); err == nil {
t.Fatal()
}
var resp string
if err := pic.UpdateCall(*canisterID, principal.AnonymousID, "helloUpdate", []any{"world"}, []any{&resp}); err != nil {
t.Fatal(err)
}
if resp != "Hello, world!" {
t.Fatalf("unexpected response: %s", resp)
}
})

t.Run("get_time", func(t *testing.T) {
dt, err := pic.GetTime()
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions pocketic/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,16 @@ func (pic PocketIC) SubmitCallWithEP(
}

// UpdateCall executes an update call on a canister.
func (pic PocketIC) UpdateCall(canisterID principal.Principal, sender principal.Principal, method string, payload []byte) ([]byte, error) {
return pic.updateCallWithEP(canisterID, &RawEffectivePrincipalCanisterID{CanisterID: canisterID.Raw}, sender, method, payload)
func (pic PocketIC) UpdateCall(canisterID principal.Principal, sender principal.Principal, method string, args []any, ret []any) error {
payload, err := idl.Marshal(args)
if err != nil {
return err
}
raw, err := pic.updateCallWithEP(canisterID, &RawEffectivePrincipalCanisterID{CanisterID: canisterID.Raw}, sender, method, payload)
if err != nil {
return err
}
return idl.Unmarshal(raw, ret)
}

// canisterCall calls the canister endpoint with the provided arguments.
Expand Down

0 comments on commit fbd56e7

Please sign in to comment.