diff --git a/request.go b/request.go index e3355fc..35c6749 100644 --- a/request.go +++ b/request.go @@ -169,12 +169,12 @@ const ( ) type requestRaw struct { - Type RequestType `cbor:"request_type"` - Sender []byte `cbor:"sender"` - Nonce []byte `cbor:"nonce"` - IngressExpiry uint64 `cbor:"ingress_expiry"` - CanisterID []byte `cbor:"canister_id"` - MethodName string `cbor:"method_name"` - Arguments []byte `cbor:"arg"` + Type RequestType `cbor:"request_type,omitempty"` + Sender []byte `cbor:"sender,omitempty"` + Nonce []byte `cbor:"nonce,omitempty"` + IngressExpiry uint64 `cbor:"ingress_expiry,omitempty"` + CanisterID []byte `cbor:"canister_id,omitempty"` + MethodName string `cbor:"method_name,omitempty"` + Arguments []byte `cbor:"arg,omitempty"` Paths [][]hashtree.Label `cbor:"paths,omitempty"` } diff --git a/request_test.go b/request_test.go index ecc2ebd..c06d8bd 100644 --- a/request_test.go +++ b/request_test.go @@ -2,7 +2,9 @@ package agent_test import ( "fmt" + "github.com/fxamacker/cbor/v2" "testing" + "time" "github.com/aviate-labs/agent-go" "github.com/aviate-labs/agent-go/certification/hashtree" @@ -82,3 +84,23 @@ func TestRequestID_Sign(t *testing.T) { t.Error(h) } } + +func TestRequest_MarshalCBOR(t *testing.T) { + request := agent.Request{ + Type: agent.RequestTypeReadState, + Sender: principal.AnonymousID, + Paths: [][]hashtree.Label{{hashtree.Label("subnet")}}, + IngressExpiry: uint64(time.Now().Add(time.Minute).UnixNano()), + } + encoded, err := cbor.Marshal(request) + if err != nil { + t.Fatal(err) + } + var r map[string]any + if err := cbor.Unmarshal(encoded, &r); err != nil { + t.Fatal(err) + } + if len(r) != 4 { + t.Error(len(r)) + } +}