From 2b5d30b1f8028b58c1261c7d8a34f2140fe6397b Mon Sep 17 00:00:00 2001 From: Quint Daenen Date: Wed, 6 Dec 2023 23:11:39 +0100 Subject: [PATCH] Fix variant structs. --- candid/idl/convert.go | 25 ++- candid/idl/encode_test.go | 33 ++++ candid/idl/null.go | 2 +- candid/idl/optional.go | 4 + candid/idl/variant.go | 48 +++++- gen/generator.go | 157 ++++++++++++++++-- gen/templates/agent_test.gotmpl | 6 +- ic/assetstorage/agent.go | 6 +- ic/assetstorage/agent_test.go | 273 +++++++++++++++++++++++++------- ic/cmc/agent.go | 4 +- ic/cmc/agent_test.go | 42 ++++- ic/icparchive/agent_test.go | 26 ++- ic/icpledger/agent.go | 2 +- ic/icpledger/agent_test.go | 94 +++++++++-- ic/icrc1/agent.go | 4 +- ic/icrc1/agent_test.go | 49 ++++-- ic/wallet/agent.go | 6 +- ic/wallet/agent_test.go | 273 +++++++++++++++++++++++++------- 18 files changed, 875 insertions(+), 179 deletions(-) create mode 100644 candid/idl/encode_test.go diff --git a/candid/idl/convert.go b/candid/idl/convert.go index 60b433c..a9e49fd 100644 --- a/candid/idl/convert.go +++ b/candid/idl/convert.go @@ -95,14 +95,6 @@ func EmptyOf(t Type) (any, error) { return nil, UnknownTypeError{Type: t} } -func IsType(v any, t Type) bool { - typ, err := TypeOf(v) - if err != nil { - return false - } - return typ.String() == t.String() -} - func TypeOf(v any) (Type, error) { switch v := v.(type) { case Null: @@ -183,6 +175,23 @@ func TypeOf(v any) (Type, error) { if err != nil { return nil, err } + if isVariantType(v) { + fields := make(map[string]Type) + for k, v := range m { + typ, err := TypeOf(v) + if err != nil { + return nil, err + } + switch t := typ.(type) { + case *OptionalType: + typ = t.Type + default: + return nil, UnknownValueTypeError{Value: v} + } + fields[k] = typ + } + return NewVariantType(fields), nil + } return TypeOf(m) case reflect.Ptr: indirect := reflect.Indirect(reflect.ValueOf(v)) diff --git a/candid/idl/encode_test.go b/candid/idl/encode_test.go new file mode 100644 index 0000000..42bae16 --- /dev/null +++ b/candid/idl/encode_test.go @@ -0,0 +1,33 @@ +package idl + +import ( + "testing" +) + +func TestEncode_issue7(t *testing.T) { + type ConsumerPermissionEnum = struct { + ReadOnly *Null `ic:"ReadOnly,variant"` + ReadAndWrite *Null `ic:"ReadAndWrite,variant"` + } + + type SecretConsumer = struct { + Name string `ic:"name"` + PermissionType ConsumerPermissionEnum `ic:"permission_type"` + } + + raw, err := Marshal([]any{ + []SecretConsumer{ + { + Name: "test", + PermissionType: ConsumerPermissionEnum{ReadAndWrite: new(Null)}, + }, + }, + }) + if err != nil { + t.Fatal(err) + } + var v []SecretConsumer + if err := Unmarshal(raw, []any{&v}); err != nil { + t.Fatal(err) + } +} diff --git a/candid/idl/null.go b/candid/idl/null.go index e09ec6a..6d9bcb3 100644 --- a/candid/idl/null.go +++ b/candid/idl/null.go @@ -22,7 +22,7 @@ func (NullType) EncodeType(_ *TypeDefinitionTable) ([]byte, error) { } func (NullType) EncodeValue(v any) ([]byte, error) { - if v != nil { + if _, ok := v.(Null); !ok && v != nil { return nil, NewEncodeValueError(v, nullType) } return []byte{}, nil diff --git a/candid/idl/optional.go b/candid/idl/optional.go index 7bbb116..79a8c7f 100644 --- a/candid/idl/optional.go +++ b/candid/idl/optional.go @@ -8,6 +8,10 @@ import ( "reflect" ) +func Ptr[a any](v a) *a { + return &v +} + // OptionalType is the type of an optional value. type OptionalType struct { Type Type diff --git a/candid/idl/variant.go b/candid/idl/variant.go index b4c17f6..df5ae1e 100644 --- a/candid/idl/variant.go +++ b/candid/idl/variant.go @@ -11,6 +11,25 @@ import ( "github.com/aviate-labs/leb128" ) +func isVariantType(value any) bool { + v := reflect.ValueOf(value) + switch v.Kind() { + case reflect.Struct: + for i := 0; i < v.NumField(); i++ { + field := v.Type().Field(i) + if !field.IsExported() { + continue + } + + tag := ParseTags(field) + if tag.VariantType { + return true + } + } + } + return false +} + type Variant struct { Name string Value any @@ -98,7 +117,11 @@ func (variant VariantType) EncodeType(tdt *TypeDefinitionTable) ([]byte, error) func (variant VariantType) EncodeValue(value any) ([]byte, error) { fs, ok := value.(Variant) if !ok { - return nil, NewEncodeValueError(variant, varType) + v, err := variant.structToVariant(value) + if err != nil { + return nil, err + } + return variant.EncodeValue(*v) } for i, f := range variant.Fields { if f.Name == fs.Name { @@ -176,6 +199,29 @@ func (variant VariantType) UnmarshalGo(raw any, _v any) error { return variant.unmarshalStruct(name, value, v) } +func (variant VariantType) structToVariant(value any) (*Variant, error) { + v := reflect.ValueOf(value) + switch v.Kind() { + case reflect.Struct: + for i := 0; i < v.NumField(); i++ { + field := v.Type().Field(i) + if !field.IsExported() { + continue + } + + tag := ParseTags(field) + if !v.Field(i).IsNil() { + return &Variant{ + Name: tag.Name, + Value: v.Field(i).Elem().Interface(), + }, nil + } + } + } + fmt.Printf("%#v\n", value) + return nil, fmt.Errorf("invalid value kind: %s", v.Kind()) +} + func (variant VariantType) unmarshalMap(name string, value any, _v *map[string]any) error { for _, f := range variant.Fields { if f.Name != name { diff --git a/gen/generator.go b/gen/generator.go index 8fe96f6..a0c8cc5 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -250,6 +250,13 @@ func (g *Generator) GenerateActorTypes() ([]byte, error) { } func (g *Generator) GenerateMock() ([]byte, error) { + definitions := make(map[string]did.Data) + for _, definition := range g.ServiceDescription.Definitions { + switch definition := definition.(type) { + case did.Type: + definitions[definition.Id] = definition.Data + } + } var methods []agentArgsMethod for _, service := range g.ServiceDescription.Services { for _, method := range service.Methods { @@ -257,6 +264,7 @@ func (g *Generator) GenerateMock() ([]byte, error) { f := method.Func var argumentTypes []agentArgsMethodArgument + var filledArgumentTypes []agentArgsMethodArgument for i, t := range f.ArgTypes { var n string if (t.Name != nil) && (*t.Name != "") { @@ -268,11 +276,15 @@ func (g *Generator) GenerateMock() ([]byte, error) { Name: n, Type: g.dataToString(g.PackageName, t.Data), }) + filledArgumentTypes = append(filledArgumentTypes, agentArgsMethodArgument{ + Name: n, + Type: g.dataToGoReturnValue(definitions, g.PackageName, t.Data), + }) } var returnTypes []string for _, t := range f.ResTypes { - returnTypes = append(returnTypes, g.dataToString(g.PackageName, t.Data)) + returnTypes = append(returnTypes, g.dataToGoReturnValue(definitions, g.PackageName, t.Data)) } typ := "Call" @@ -281,11 +293,12 @@ func (g *Generator) GenerateMock() ([]byte, error) { } methods = append(methods, agentArgsMethod{ - RawName: name, - Name: funcName("", name), - Type: typ, - ArgumentTypes: argumentTypes, - ReturnTypes: returnTypes, + RawName: name, + Name: funcName("", name), + Type: typ, + ArgumentTypes: argumentTypes, + FilledArgumentTypes: filledArgumentTypes, + ReturnTypes: returnTypes, }) } } @@ -307,6 +320,121 @@ func (g *Generator) GenerateMock() ([]byte, error) { return io.ReadAll(&tmpl) } +func (g *Generator) dataToGoReturnValue(definitions map[string]did.Data, prefix string, data did.Data) string { + switch t := data.(type) { + case did.Primitive: + switch t { + case "nat": + g.usedIDL = true + return "idl.NewNat(uint(0))" + case "int": + g.usedIDL = true + return "idl.NewInt(0)" + default: + return fmt.Sprintf("*new(%s)", g.dataToString(prefix, data)) + } + case did.DataId: + switch data := definitions[t.String()].(type) { + case did.Record: + var fields []string + for _, f := range data { + var data did.Data + if f.Data != nil { + data = *f.Data + } else { + data = did.DataId(*f.NameData) + } + fields = append(fields, g.dataToGoReturnValue(definitions, prefix, data)) + } + if len(fields) == 0 { + return fmt.Sprintf("%s{}", g.dataToString(prefix, t)) + } + return fmt.Sprintf("%s{\n%s,\n}", g.dataToString(prefix, t), strings.Join(fields, ",\n")) + case did.Variant: + f := data[0] + var d did.Data + if f.Data != nil { + d = *f.Data + } else { + d = did.DataId(*f.NameData) + } + field := g.dataToGoReturnValue(definitions, prefix, d) + if !strings.HasPrefix(field, "*") { + g.usedIDL = true + field = fmt.Sprintf("idl.Ptr(%s)", field) + } else { + field = strings.TrimPrefix(field, "*") + } + var name string + if f.Name != nil { + name = *f.Name + } else { + name = *f.NameData + } + return fmt.Sprintf("%s{\n%s: %s,\n}", g.dataToString(prefix, t), name, field) + default: + switch data := data.(type) { + case did.Primitive: + switch data { + case "nat": + g.usedIDL = true + return "idl.NewNat(uint(0))" + case "int": + g.usedIDL = true + return "idl.NewInt(0)" + } + } + if data != nil { + return fmt.Sprintf("*new(%s)", g.dataToString(prefix, data)) + } + return "*new(idl.Null)" + } + case did.Record: + var fields []string + for _, f := range t { + var data did.Data + if f.Data != nil { + data = *f.Data + } else { + data = did.DataId(*f.NameData) + } + fields = append(fields, g.dataToGoReturnValue(definitions, prefix, data)) + } + if len(fields) == 0 { + return fmt.Sprintf("%s{}", g.dataToString(prefix, data)) + } + return fmt.Sprintf("%s{\n%s,\n}", g.dataToString(prefix, data), strings.Join(fields, ",\n")) + case did.Variant: + f := t[0] + var name string + var d did.Data + if f.Data != nil { + name = *f.Name + d = *f.Data + } else { + name = *f.NameData + d = did.DataId(*f.NameData) + } + field := g.dataToGoReturnValue(definitions, prefix, d) + if !strings.HasPrefix(field, "*") { + g.usedIDL = true + field = fmt.Sprintf("idl.Ptr(%s)", field) + } else { + field = strings.TrimPrefix(field, "*") + } + return fmt.Sprintf("%s{\n%s: %s,\n}", g.dataToString(prefix, data), name, field) + case did.Vector: + switch t.Data.(type) { + case did.DataId: + return fmt.Sprintf("[]%s{%s}", funcName(prefix, t.Data.String()), g.dataToGoReturnValue(definitions, prefix, t.Data)) + default: + return fmt.Sprintf("[]%s{%s}", g.dataToString(prefix, t.Data), g.dataToGoReturnValue(definitions, prefix, t.Data)) + } + default: + return fmt.Sprintf("*new(%s)", g.dataToString(prefix, data)) + } +} + func (g *Generator) dataToMotokoReturnValue(s rand.Source, definitions map[string]did.Data, data did.Data) string { r := rand.New(s) switch t := data.(type) { @@ -496,7 +624,8 @@ func (g *Generator) dataToString(prefix string, data did.Data) string { case "text": return "string" case "null": - return "struct{}" + g.usedIDL = true + return "idl.Null" default: panic(fmt.Sprintf("unknown primitive: %s", t)) } @@ -572,11 +701,12 @@ func (g *Generator) dataToString(prefix string, data did.Data) string { if 8 > sizeType { sizeType = 8 } + g.usedIDL = true records = append(records, struct { originalName string name string typ string - }{originalName: name, name: name, typ: "struct{}"}) + }{originalName: name, name: name, typ: "idl.Null"}) } else { name := funcName("", *field.Name) if l := len(name); l > sizeName { @@ -649,11 +779,12 @@ type agentArgsDefinition struct { } type agentArgsMethod struct { - RawName string - Name string - Type string - ArgumentTypes []agentArgsMethodArgument - ReturnTypes []string + RawName string + Name string + Type string + ArgumentTypes []agentArgsMethodArgument + FilledArgumentTypes []agentArgsMethodArgument + ReturnTypes []string } type agentArgsMethodArgument struct { diff --git a/gen/templates/agent_test.gotmpl b/gen/templates/agent_test.gotmpl index 2c72caa..6051bd8 100644 --- a/gen/templates/agent_test.gotmpl +++ b/gen/templates/agent_test.gotmpl @@ -39,15 +39,15 @@ func Test_{{ .Name }}(t *testing.T) { Name: "{{ .RawName }}", Arguments: []any{{ "{" }}{{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}new({{ $e.Type }}){{ end }}{{ "}" }}, Handler: func (request mock.Request) ([]any, error) { - return []any{{ "{" }}{{ range $i, $e := .ReturnTypes }}{{ if $i }}, {{ end }}*new({{ $e }}){{ end }}{{ "}" }}, nil + return []any{{ "{" }}{{ range $i, $e := .ReturnTypes }}{{ if $i }}, {{ end }}{{ $e }}{{ end }}{{ "}" }}, nil }, }, }) if err != nil { t.Fatal(err) } - {{ range $i, $e := .ArgumentTypes }} - var a{{ $i }} {{ $e.Type }} + {{ range $i, $e := .FilledArgumentTypes }} + var a{{ $i }} = {{ $e.Type }} {{- end }} if {{ range .ReturnTypes }}_, {{ end }}err := a.{{ .Name }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}a{{ $i }}{{ end }}); err != nil { t.Fatal(err) diff --git a/ic/assetstorage/agent.go b/ic/assetstorage/agent.go index 9e486a3..1549bae 100755 --- a/ic/assetstorage/agent.go +++ b/ic/assetstorage/agent.go @@ -630,9 +630,9 @@ type ListPermitted struct { } type Permission struct { - Commit *struct{} `ic:"Commit,variant"` - ManagePermissions *struct{} `ic:"ManagePermissions,variant"` - Prepare *struct{} `ic:"Prepare,variant"` + Commit *idl.Null `ic:"Commit,variant"` + ManagePermissions *idl.Null `ic:"ManagePermissions,variant"` + Prepare *idl.Null `ic:"Prepare,variant"` } type RevokePermission struct { diff --git a/ic/assetstorage/agent_test.go b/ic/assetstorage/agent_test.go index 220fcf5..2df10e7 100755 --- a/ic/assetstorage/agent_test.go +++ b/ic/assetstorage/agent_test.go @@ -49,7 +49,7 @@ func Test_Authorize(t *testing.T) { t.Fatal(err) } - var a0 principal.Principal + var a0 = *new(principal.Principal) if err := a.Authorize(a0); err != nil { t.Fatal(err) } @@ -64,10 +64,13 @@ func Test_CertifiedTree(t *testing.T) { Arguments: []any{new(struct { })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Certificate []byte `ic:"certificate"` Tree []byte `ic:"tree"` - })}, nil + }{ + *new([]byte), + *new([]byte), + }}, nil }, }, }) @@ -75,8 +78,8 @@ func Test_CertifiedTree(t *testing.T) { t.Fatal(err) } - var a0 struct { - } + var a0 = struct { + }{} if _, err := a.CertifiedTree(a0); err != nil { t.Fatal(err) } @@ -98,7 +101,7 @@ func Test_Clear(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.ClearArguments + var a0 = assetstorage.ClearArguments{} if err := a.Clear(a0); err != nil { t.Fatal(err) } @@ -120,7 +123,19 @@ func Test_CommitBatch(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.CommitBatchArguments + var a0 = assetstorage.CommitBatchArguments{ + idl.NewNat(uint(0)), + []assetstorage.BatchOperationKind{{ + CreateAsset: idl.Ptr(assetstorage.CreateAssetArguments{ + *new(string), + *new(string), + *new(*uint64), + *new(*[]assetstorage.HeaderField), + *new(*bool), + *new(*bool), + }), + }}, + } if err := a.CommitBatch(a0); err != nil { t.Fatal(err) } @@ -142,7 +157,10 @@ func Test_CommitProposedBatch(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.CommitProposedBatchArguments + var a0 = assetstorage.CommitProposedBatchArguments{ + idl.NewNat(uint(0)), + *new([]byte), + } if err := a.CommitProposedBatch(a0); err != nil { t.Fatal(err) } @@ -164,7 +182,10 @@ func Test_ComputeEvidence(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.ComputeEvidenceArguments + var a0 = assetstorage.ComputeEvidenceArguments{ + idl.NewNat(uint(0)), + *new(*uint16), + } if _, err := a.ComputeEvidence(a0); err != nil { t.Fatal(err) } @@ -186,7 +207,14 @@ func Test_CreateAsset(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.CreateAssetArguments + var a0 = assetstorage.CreateAssetArguments{ + *new(string), + *new(string), + *new(*uint64), + *new(*[]assetstorage.HeaderField), + *new(*bool), + *new(*bool), + } if err := a.CreateAsset(a0); err != nil { t.Fatal(err) } @@ -201,9 +229,11 @@ func Test_CreateBatch(t *testing.T) { Arguments: []any{new(struct { })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { BatchId assetstorage.BatchId `ic:"batch_id"` - })}, nil + }{ + idl.NewNat(uint(0)), + }}, nil }, }, }) @@ -211,8 +241,8 @@ func Test_CreateBatch(t *testing.T) { t.Fatal(err) } - var a0 struct { - } + var a0 = struct { + }{} if _, err := a.CreateBatch(a0); err != nil { t.Fatal(err) } @@ -229,9 +259,11 @@ func Test_CreateChunk(t *testing.T) { Content []byte `ic:"content"` })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { ChunkId assetstorage.ChunkId `ic:"chunk_id"` - })}, nil + }{ + idl.NewNat(uint(0)), + }}, nil }, }, }) @@ -239,9 +271,12 @@ func Test_CreateChunk(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { BatchId assetstorage.BatchId `ic:"batch_id"` Content []byte `ic:"content"` + }{ + idl.NewNat(uint(0)), + *new([]byte), } if _, err := a.CreateChunk(a0); err != nil { t.Fatal(err) @@ -264,7 +299,7 @@ func Test_Deauthorize(t *testing.T) { t.Fatal(err) } - var a0 principal.Principal + var a0 = *new(principal.Principal) if err := a.Deauthorize(a0); err != nil { t.Fatal(err) } @@ -286,7 +321,9 @@ func Test_DeleteAsset(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.DeleteAssetArguments + var a0 = assetstorage.DeleteAssetArguments{ + *new(string), + } if err := a.DeleteAsset(a0); err != nil { t.Fatal(err) } @@ -308,7 +345,9 @@ func Test_DeleteBatch(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.DeleteBatchArguments + var a0 = assetstorage.DeleteBatchArguments{ + idl.NewNat(uint(0)), + } if err := a.DeleteBatch(a0); err != nil { t.Fatal(err) } @@ -325,13 +364,19 @@ func Test_Get(t *testing.T) { AcceptEncodings []string `ic:"accept_encodings"` })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Content []byte `ic:"content"` ContentType string `ic:"content_type"` ContentEncoding string `ic:"content_encoding"` Sha256 *[]byte `ic:"sha256,omitempty"` TotalLength idl.Nat `ic:"total_length"` - })}, nil + }{ + *new([]byte), + *new(string), + *new(string), + *new(*[]byte), + idl.NewNat(uint(0)), + }}, nil }, }, }) @@ -339,9 +384,12 @@ func Test_Get(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { Key assetstorage.Key `ic:"key"` AcceptEncodings []string `ic:"accept_encodings"` + }{ + *new(string), + []string{*new(string)}, } if _, err := a.Get(a0); err != nil { t.Fatal(err) @@ -356,12 +404,17 @@ func Test_GetAssetProperties(t *testing.T) { Name: "get_asset_properties", Arguments: []any{new(assetstorage.Key)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { MaxAge *uint64 `ic:"max_age,omitempty"` Headers *[]assetstorage.HeaderField `ic:"headers,omitempty"` AllowRawAccess *bool `ic:"allow_raw_access,omitempty"` IsAliased *bool `ic:"is_aliased,omitempty"` - })}, nil + }{ + *new(*uint64), + *new(*[]assetstorage.HeaderField), + *new(*bool), + *new(*bool), + }}, nil }, }, }) @@ -369,7 +422,7 @@ func Test_GetAssetProperties(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.Key + var a0 = *new(string) if _, err := a.GetAssetProperties(a0); err != nil { t.Fatal(err) } @@ -388,9 +441,11 @@ func Test_GetChunk(t *testing.T) { Sha256 *[]byte `ic:"sha256,omitempty"` })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Content []byte `ic:"content"` - })}, nil + }{ + *new([]byte), + }}, nil }, }, }) @@ -398,11 +453,16 @@ func Test_GetChunk(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { Key assetstorage.Key `ic:"key"` ContentEncoding string `ic:"content_encoding"` Index idl.Nat `ic:"index"` Sha256 *[]byte `ic:"sha256,omitempty"` + }{ + *new(string), + *new(string), + idl.NewNat(uint(0)), + *new(*[]byte), } if _, err := a.GetChunk(a0); err != nil { t.Fatal(err) @@ -425,7 +485,12 @@ func Test_GrantPermission(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.GrantPermission + var a0 = assetstorage.GrantPermission{ + *new(principal.Principal), + assetstorage.Permission{ + Commit: new(idl.Null), + }, + } if err := a.GrantPermission(a0); err != nil { t.Fatal(err) } @@ -439,7 +504,15 @@ func Test_HttpRequest(t *testing.T) { Name: "http_request", Arguments: []any{new(assetstorage.HttpRequest)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(assetstorage.HttpResponse)}, nil + return []any{assetstorage.HttpResponse{ + *new(uint16), + []assetstorage.HeaderField{{ + *new(string), + *new(string), + }}, + *new([]byte), + *new(*assetstorage.StreamingStrategy), + }}, nil }, }, }) @@ -447,7 +520,16 @@ func Test_HttpRequest(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.HttpRequest + var a0 = assetstorage.HttpRequest{ + *new(string), + *new(string), + []assetstorage.HeaderField{{ + *new(string), + *new(string), + }}, + *new([]byte), + *new(*uint16), + } if _, err := a.HttpRequest(a0); err != nil { t.Fatal(err) } @@ -469,7 +551,12 @@ func Test_HttpRequestStreamingCallback(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.StreamingCallbackToken + var a0 = assetstorage.StreamingCallbackToken{ + *new(string), + *new(string), + idl.NewNat(uint(0)), + *new(*[]byte), + } if _, err := a.HttpRequestStreamingCallback(a0); err != nil { t.Fatal(err) } @@ -484,7 +571,7 @@ func Test_List(t *testing.T) { Arguments: []any{new(struct { })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]struct { + return []any{[]struct { Key assetstorage.Key `ic:"key"` ContentType string `ic:"content_type"` Encodings []struct { @@ -493,7 +580,25 @@ func Test_List(t *testing.T) { Length idl.Nat `ic:"length"` Modified assetstorage.Time `ic:"modified"` } `ic:"encodings"` - })}, nil + }{ + + { + *new(string), + *new(string), + []struct { + ContentEncoding string `ic:"content_encoding"` + Sha256 *[]byte `ic:"sha256,omitempty"` + Length idl.Nat `ic:"length"` + Modified assetstorage.Time `ic:"modified"` + }{ + + { + *new(string), + *new(*[]byte), + idl.NewNat(uint(0)), + idl.NewInt(0), + }}, + }}}, nil }, }, }) @@ -501,8 +606,8 @@ func Test_List(t *testing.T) { t.Fatal(err) } - var a0 struct { - } + var a0 = struct { + }{} if _, err := a.List(a0); err != nil { t.Fatal(err) } @@ -516,7 +621,7 @@ func Test_ListAuthorized(t *testing.T) { Name: "list_authorized", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]principal.Principal)}, nil + return []any{[]principal.Principal{*new(principal.Principal)}}, nil }, }, }) @@ -537,7 +642,7 @@ func Test_ListPermitted(t *testing.T) { Name: "list_permitted", Arguments: []any{new(assetstorage.ListPermitted)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]principal.Principal)}, nil + return []any{[]principal.Principal{*new(principal.Principal)}}, nil }, }, }) @@ -545,7 +650,11 @@ func Test_ListPermitted(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.ListPermitted + var a0 = assetstorage.ListPermitted{ + assetstorage.Permission{ + Commit: new(idl.Null), + }, + } if _, err := a.ListPermitted(a0); err != nil { t.Fatal(err) } @@ -567,7 +676,19 @@ func Test_ProposeCommitBatch(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.CommitBatchArguments + var a0 = assetstorage.CommitBatchArguments{ + idl.NewNat(uint(0)), + []assetstorage.BatchOperationKind{{ + CreateAsset: idl.Ptr(assetstorage.CreateAssetArguments{ + *new(string), + *new(string), + *new(*uint64), + *new(*[]assetstorage.HeaderField), + *new(*bool), + *new(*bool), + }), + }}, + } if err := a.ProposeCommitBatch(a0); err != nil { t.Fatal(err) } @@ -589,7 +710,12 @@ func Test_RevokePermission(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.RevokePermission + var a0 = assetstorage.RevokePermission{ + *new(principal.Principal), + assetstorage.Permission{ + Commit: new(idl.Null), + }, + } if err := a.RevokePermission(a0); err != nil { t.Fatal(err) } @@ -611,7 +737,12 @@ func Test_SetAssetContent(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.SetAssetContentArguments + var a0 = assetstorage.SetAssetContentArguments{ + *new(string), + *new(string), + []assetstorage.ChunkId{idl.NewNat(uint(0))}, + *new(*[]byte), + } if err := a.SetAssetContent(a0); err != nil { t.Fatal(err) } @@ -633,7 +764,13 @@ func Test_SetAssetProperties(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.SetAssetPropertiesArguments + var a0 = assetstorage.SetAssetPropertiesArguments{ + *new(string), + *new(**uint64), + *new(**[]assetstorage.HeaderField), + *new(**bool), + *new(**bool), + } if err := a.SetAssetProperties(a0); err != nil { t.Fatal(err) } @@ -661,12 +798,18 @@ func Test_Store(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { Key assetstorage.Key `ic:"key"` ContentType string `ic:"content_type"` ContentEncoding string `ic:"content_encoding"` Content []byte `ic:"content"` Sha256 *[]byte `ic:"sha256,omitempty"` + }{ + *new(string), + *new(string), + *new(string), + *new([]byte), + *new(*[]byte), } if err := a.Store(a0); err != nil { t.Fatal(err) @@ -710,7 +853,10 @@ func Test_UnsetAssetContent(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.UnsetAssetContentArguments + var a0 = assetstorage.UnsetAssetContentArguments{ + *new(string), + *new(string), + } if err := a.UnsetAssetContent(a0); err != nil { t.Fatal(err) } @@ -724,7 +870,9 @@ func Test_ValidateCommitProposedBatch(t *testing.T) { Name: "validate_commit_proposed_batch", Arguments: []any{new(assetstorage.CommitProposedBatchArguments)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(assetstorage.ValidationResult)}, nil + return []any{assetstorage.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) @@ -732,7 +880,10 @@ func Test_ValidateCommitProposedBatch(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.CommitProposedBatchArguments + var a0 = assetstorage.CommitProposedBatchArguments{ + idl.NewNat(uint(0)), + *new([]byte), + } if _, err := a.ValidateCommitProposedBatch(a0); err != nil { t.Fatal(err) } @@ -746,7 +897,9 @@ func Test_ValidateGrantPermission(t *testing.T) { Name: "validate_grant_permission", Arguments: []any{new(assetstorage.GrantPermission)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(assetstorage.ValidationResult)}, nil + return []any{assetstorage.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) @@ -754,7 +907,12 @@ func Test_ValidateGrantPermission(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.GrantPermission + var a0 = assetstorage.GrantPermission{ + *new(principal.Principal), + assetstorage.Permission{ + Commit: new(idl.Null), + }, + } if _, err := a.ValidateGrantPermission(a0); err != nil { t.Fatal(err) } @@ -768,7 +926,9 @@ func Test_ValidateRevokePermission(t *testing.T) { Name: "validate_revoke_permission", Arguments: []any{new(assetstorage.RevokePermission)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(assetstorage.ValidationResult)}, nil + return []any{assetstorage.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) @@ -776,7 +936,12 @@ func Test_ValidateRevokePermission(t *testing.T) { t.Fatal(err) } - var a0 assetstorage.RevokePermission + var a0 = assetstorage.RevokePermission{ + *new(principal.Principal), + assetstorage.Permission{ + Commit: new(idl.Null), + }, + } if _, err := a.ValidateRevokePermission(a0); err != nil { t.Fatal(err) } @@ -790,7 +955,9 @@ func Test_ValidateTakeOwnership(t *testing.T) { Name: "validate_take_ownership", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(assetstorage.ValidationResult)}, nil + return []any{assetstorage.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) diff --git a/ic/cmc/agent.go b/ic/cmc/agent.go index 41e8241..7c1aba4 100755 --- a/ic/cmc/agent.go +++ b/ic/cmc/agent.go @@ -100,7 +100,7 @@ type CyclesCanisterInitPayload struct { type ExchangeRateCanister struct { Set *principal.Principal `ic:"Set,variant"` - Unset *struct{} `ic:"Unset,variant"` + Unset *idl.Null `ic:"Unset,variant"` } type IcpXdrConversionRate struct { @@ -130,7 +130,7 @@ type NotifyError struct { Reason string `ic:"reason"` BlockIndex *BlockIndex `ic:"block_index,omitempty"` } `ic:"Refunded,variant"` - Processing *struct{} `ic:"Processing,variant"` + Processing *idl.Null `ic:"Processing,variant"` TransactionTooOld *BlockIndex `ic:"TransactionTooOld,variant"` InvalidTransaction *string `ic:"InvalidTransaction,variant"` Other *struct { diff --git a/ic/cmc/agent_test.go b/ic/cmc/agent_test.go index 3b0cc5e..326852e 100755 --- a/ic/cmc/agent_test.go +++ b/ic/cmc/agent_test.go @@ -3,7 +3,7 @@ package cmc_test import ( "github.com/aviate-labs/agent-go" - + "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/mock" "github.com/aviate-labs/agent-go/principal" "net/http/httptest" @@ -20,7 +20,14 @@ func Test_GetIcpXdrConversionRate(t *testing.T) { Name: "get_icp_xdr_conversion_rate", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(cmc.IcpXdrConversionRateResponse)}, nil + return []any{cmc.IcpXdrConversionRateResponse{ + cmc.IcpXdrConversionRate{ + *new(uint64), + *new(uint64), + }, + *new([]byte), + *new([]byte), + }}, nil }, }, }) @@ -41,7 +48,17 @@ func Test_GetSubnetTypesToSubnets(t *testing.T) { Name: "get_subnet_types_to_subnets", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(cmc.SubnetTypesToSubnetsResponse)}, nil + return []any{cmc.SubnetTypesToSubnetsResponse{ + []struct { + Field0 string `ic:"0"` + Field1 []principal.Principal `ic:"1"` + }{ + + { + *new(string), + []principal.Principal{*new(principal.Principal)}, + }}, + }}, nil }, }, }) @@ -62,7 +79,9 @@ func Test_NotifyCreateCanister(t *testing.T) { Name: "notify_create_canister", Arguments: []any{new(cmc.NotifyCreateCanisterArg)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(cmc.NotifyCreateCanisterResult)}, nil + return []any{cmc.NotifyCreateCanisterResult{ + Ok: new(principal.Principal), + }}, nil }, }, }) @@ -70,7 +89,11 @@ func Test_NotifyCreateCanister(t *testing.T) { t.Fatal(err) } - var a0 cmc.NotifyCreateCanisterArg + var a0 = cmc.NotifyCreateCanisterArg{ + *new(uint64), + *new(principal.Principal), + *new(*string), + } if _, err := a.NotifyCreateCanister(a0); err != nil { t.Fatal(err) } @@ -84,7 +107,9 @@ func Test_NotifyTopUp(t *testing.T) { Name: "notify_top_up", Arguments: []any{new(cmc.NotifyTopUpArg)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(cmc.NotifyTopUpResult)}, nil + return []any{cmc.NotifyTopUpResult{ + Ok: idl.Ptr(idl.NewNat(uint(0))), + }}, nil }, }, }) @@ -92,7 +117,10 @@ func Test_NotifyTopUp(t *testing.T) { t.Fatal(err) } - var a0 cmc.NotifyTopUpArg + var a0 = cmc.NotifyTopUpArg{ + *new(uint64), + *new(principal.Principal), + } if _, err := a.NotifyTopUp(a0); err != nil { t.Fatal(err) } diff --git a/ic/icparchive/agent_test.go b/ic/icparchive/agent_test.go index fa94a33..52b0b3d 100644 --- a/ic/icparchive/agent_test.go +++ b/ic/icparchive/agent_test.go @@ -3,7 +3,7 @@ package icparchive_test import ( "github.com/aviate-labs/agent-go" - + "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/mock" "github.com/aviate-labs/agent-go/principal" "net/http/httptest" @@ -20,7 +20,24 @@ func Test_GetBlocks(t *testing.T) { Name: "get_blocks", Arguments: []any{new(icparchive.GetBlocksArgs)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(icparchive.GetBlocksResult)}, nil + return []any{icparchive.GetBlocksResult{ + Ok: idl.Ptr(icparchive.BlockRange{ + []icparchive.Block{{ + *new(*[]byte), + icparchive.Transaction{ + *new(uint64), + *new(*[]byte), + *new(*icparchive.Operation), + icparchive.Timestamp{ + *new(uint64), + }, + }, + icparchive.Timestamp{ + *new(uint64), + }, + }}, + }), + }}, nil }, }, }) @@ -28,7 +45,10 @@ func Test_GetBlocks(t *testing.T) { t.Fatal(err) } - var a0 icparchive.GetBlocksArgs + var a0 = icparchive.GetBlocksArgs{ + *new(uint64), + *new(uint64), + } if _, err := a.GetBlocks(a0); err != nil { t.Fatal(err) } diff --git a/ic/icpledger/agent.go b/ic/icpledger/agent.go index 97498c3..5901cd9 100755 --- a/ic/icpledger/agent.go +++ b/ic/icpledger/agent.go @@ -281,7 +281,7 @@ type TransferError struct { TxTooOld *struct { AllowedWindowNanos uint64 `ic:"allowed_window_nanos"` } `ic:"TxTooOld,variant"` - TxCreatedInFuture *struct{} `ic:"TxCreatedInFuture,variant"` + TxCreatedInFuture *idl.Null `ic:"TxCreatedInFuture,variant"` TxDuplicate *struct { DuplicateOf BlockIndex `ic:"duplicate_of"` } `ic:"TxDuplicate,variant"` diff --git a/ic/icpledger/agent_test.go b/ic/icpledger/agent_test.go index f7eee47..7e0d383 100644 --- a/ic/icpledger/agent_test.go +++ b/ic/icpledger/agent_test.go @@ -20,7 +20,9 @@ func Test_AccountBalance(t *testing.T) { Name: "account_balance", Arguments: []any{new(icpledger.AccountBalanceArgs)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(icpledger.Tokens)}, nil + return []any{icpledger.Tokens{ + *new(uint64), + }}, nil }, }, }) @@ -28,7 +30,9 @@ func Test_AccountBalance(t *testing.T) { t.Fatal(err) } - var a0 icpledger.AccountBalanceArgs + var a0 = icpledger.AccountBalanceArgs{ + *new([]byte), + } if _, err := a.AccountBalance(a0); err != nil { t.Fatal(err) } @@ -42,7 +46,11 @@ func Test_Archives(t *testing.T) { Name: "archives", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(icpledger.Archives)}, nil + return []any{icpledger.Archives{ + []icpledger.Archive{{ + *new(principal.Principal), + }}, + }}, nil }, }, }) @@ -63,9 +71,11 @@ func Test_Decimals(t *testing.T) { Name: "decimals", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Decimals uint32 `ic:"decimals"` - })}, nil + }{ + *new(uint32), + }}, nil }, }, }) @@ -86,9 +96,11 @@ func Test_Name(t *testing.T) { Name: "name", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Name string `ic:"name"` - })}, nil + }{ + *new(string), + }}, nil }, }, }) @@ -109,7 +121,37 @@ func Test_QueryBlocks(t *testing.T) { Name: "query_blocks", Arguments: []any{new(icpledger.GetBlocksArgs)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(icpledger.QueryBlocksResponse)}, nil + return []any{icpledger.QueryBlocksResponse{ + *new(uint64), + *new(*[]byte), + []icpledger.Block{{ + *new(*[]byte), + icpledger.Transaction{ + *new(uint64), + *new(*[]byte), + *new(*icpledger.Operation), + icpledger.TimeStamp{ + *new(uint64), + }, + }, + icpledger.TimeStamp{ + *new(uint64), + }, + }}, + *new(uint64), + []struct { + Start icpledger.BlockIndex `ic:"start"` + Length uint64 `ic:"length"` + Callback icpledger.QueryArchiveFn `ic:"callback"` + }{ + + { + *new(uint64), + *new(uint64), + *new(struct { /* NOT SUPPORTED */ + }), + }}, + }}, nil }, }, }) @@ -117,7 +159,10 @@ func Test_QueryBlocks(t *testing.T) { t.Fatal(err) } - var a0 icpledger.GetBlocksArgs + var a0 = icpledger.GetBlocksArgs{ + *new(uint64), + *new(uint64), + } if _, err := a.QueryBlocks(a0); err != nil { t.Fatal(err) } @@ -131,9 +176,11 @@ func Test_Symbol(t *testing.T) { Name: "symbol", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Symbol string `ic:"symbol"` - })}, nil + }{ + *new(string), + }}, nil }, }, }) @@ -154,7 +201,9 @@ func Test_Transfer(t *testing.T) { Name: "transfer", Arguments: []any{new(icpledger.TransferArgs)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(icpledger.TransferResult)}, nil + return []any{icpledger.TransferResult{ + Ok: new(uint64), + }}, nil }, }, }) @@ -162,7 +211,18 @@ func Test_Transfer(t *testing.T) { t.Fatal(err) } - var a0 icpledger.TransferArgs + var a0 = icpledger.TransferArgs{ + *new(uint64), + icpledger.Tokens{ + *new(uint64), + }, + icpledger.Tokens{ + *new(uint64), + }, + *new(*icpledger.SubAccount), + *new([]byte), + *new(*icpledger.TimeStamp), + } if _, err := a.Transfer(a0); err != nil { t.Fatal(err) } @@ -176,7 +236,11 @@ func Test_TransferFee(t *testing.T) { Name: "transfer_fee", Arguments: []any{new(icpledger.TransferFeeArg)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(icpledger.TransferFee)}, nil + return []any{icpledger.TransferFee{ + icpledger.Tokens{ + *new(uint64), + }, + }}, nil }, }, }) @@ -184,7 +248,7 @@ func Test_TransferFee(t *testing.T) { t.Fatal(err) } - var a0 icpledger.TransferFeeArg + var a0 = icpledger.TransferFeeArg{} if _, err := a.TransferFee(a0); err != nil { t.Fatal(err) } diff --git a/ic/icrc1/agent.go b/ic/icrc1/agent.go index 7fd6c1e..6012fa1 100755 --- a/ic/icrc1/agent.go +++ b/ic/icrc1/agent.go @@ -214,14 +214,14 @@ type TransferError struct { InsufficientFunds *struct { Balance idl.Nat `ic:"balance"` } `ic:"InsufficientFunds,variant"` - TooOld *struct{} `ic:"TooOld,variant"` + TooOld *idl.Null `ic:"TooOld,variant"` CreatedInFuture *struct { LedgerTime Timestamp `ic:"ledger_time"` } `ic:"CreatedInFuture,variant"` Duplicate *struct { DuplicateOf idl.Nat `ic:"duplicate_of"` } `ic:"Duplicate,variant"` - TemporarilyUnavailable *struct{} `ic:"TemporarilyUnavailable,variant"` + TemporarilyUnavailable *idl.Null `ic:"TemporarilyUnavailable,variant"` GenericError *struct { ErrorCode idl.Nat `ic:"error_code"` Message string `ic:"message"` diff --git a/ic/icrc1/agent_test.go b/ic/icrc1/agent_test.go index a08cc87..c7cf6e2 100755 --- a/ic/icrc1/agent_test.go +++ b/ic/icrc1/agent_test.go @@ -20,7 +20,7 @@ func Test_Icrc1BalanceOf(t *testing.T) { Name: "icrc1_balance_of", Arguments: []any{new(icrc1.Account)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(idl.Nat)}, nil + return []any{idl.NewNat(uint(0))}, nil }, }, }) @@ -28,7 +28,10 @@ func Test_Icrc1BalanceOf(t *testing.T) { t.Fatal(err) } - var a0 icrc1.Account + var a0 = icrc1.Account{ + *new(principal.Principal), + *new(*icrc1.Subaccount), + } if _, err := a.Icrc1BalanceOf(a0); err != nil { t.Fatal(err) } @@ -63,7 +66,7 @@ func Test_Icrc1Fee(t *testing.T) { Name: "icrc1_fee", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(idl.Nat)}, nil + return []any{idl.NewNat(uint(0))}, nil }, }, }) @@ -84,10 +87,17 @@ func Test_Icrc1Metadata(t *testing.T) { Name: "icrc1_metadata", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]struct { + return []any{[]struct { Field0 string `ic:"0"` Field1 icrc1.Value `ic:"1"` - })}, nil + }{ + + { + *new(string), + icrc1.Value{ + Nat: idl.Ptr(idl.NewNat(uint(0))), + }, + }}}, nil }, }, }) @@ -150,10 +160,15 @@ func Test_Icrc1SupportedStandards(t *testing.T) { Name: "icrc1_supported_standards", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]struct { + return []any{[]struct { Name string `ic:"name"` Url string `ic:"url"` - })}, nil + }{ + + { + *new(string), + *new(string), + }}}, nil }, }, }) @@ -195,7 +210,7 @@ func Test_Icrc1TotalSupply(t *testing.T) { Name: "icrc1_total_supply", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(idl.Nat)}, nil + return []any{idl.NewNat(uint(0))}, nil }, }, }) @@ -216,10 +231,12 @@ func Test_Icrc1Transfer(t *testing.T) { Name: "icrc1_transfer", Arguments: []any{new(icrc1.TransferArgs)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Ok *idl.Nat `ic:"Ok,variant"` Err *icrc1.TransferError `ic:"Err,variant"` - })}, nil + }{ + Ok: idl.Ptr(idl.NewNat(uint(0))), + }}, nil }, }, }) @@ -227,7 +244,17 @@ func Test_Icrc1Transfer(t *testing.T) { t.Fatal(err) } - var a0 icrc1.TransferArgs + var a0 = icrc1.TransferArgs{ + *new(*icrc1.Subaccount), + icrc1.Account{ + *new(principal.Principal), + *new(*icrc1.Subaccount), + }, + idl.NewNat(uint(0)), + *new(*idl.Nat), + *new(*[]byte), + *new(*icrc1.Timestamp), + } if _, err := a.Icrc1Transfer(a0); err != nil { t.Fatal(err) } diff --git a/ic/wallet/agent.go b/ic/wallet/agent.go index f11d9b3..8f0a408 100755 --- a/ic/wallet/agent.go +++ b/ic/wallet/agent.go @@ -630,9 +630,9 @@ type ListPermitted struct { } type Permission struct { - Commit *struct{} `ic:"Commit,variant"` - ManagePermissions *struct{} `ic:"ManagePermissions,variant"` - Prepare *struct{} `ic:"Prepare,variant"` + Commit *idl.Null `ic:"Commit,variant"` + ManagePermissions *idl.Null `ic:"ManagePermissions,variant"` + Prepare *idl.Null `ic:"Prepare,variant"` } type RevokePermission struct { diff --git a/ic/wallet/agent_test.go b/ic/wallet/agent_test.go index c14f1b0..7e760fe 100755 --- a/ic/wallet/agent_test.go +++ b/ic/wallet/agent_test.go @@ -49,7 +49,7 @@ func Test_Authorize(t *testing.T) { t.Fatal(err) } - var a0 principal.Principal + var a0 = *new(principal.Principal) if err := a.Authorize(a0); err != nil { t.Fatal(err) } @@ -64,10 +64,13 @@ func Test_CertifiedTree(t *testing.T) { Arguments: []any{new(struct { })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Certificate []byte `ic:"certificate"` Tree []byte `ic:"tree"` - })}, nil + }{ + *new([]byte), + *new([]byte), + }}, nil }, }, }) @@ -75,8 +78,8 @@ func Test_CertifiedTree(t *testing.T) { t.Fatal(err) } - var a0 struct { - } + var a0 = struct { + }{} if _, err := a.CertifiedTree(a0); err != nil { t.Fatal(err) } @@ -98,7 +101,7 @@ func Test_Clear(t *testing.T) { t.Fatal(err) } - var a0 wallet.ClearArguments + var a0 = wallet.ClearArguments{} if err := a.Clear(a0); err != nil { t.Fatal(err) } @@ -120,7 +123,19 @@ func Test_CommitBatch(t *testing.T) { t.Fatal(err) } - var a0 wallet.CommitBatchArguments + var a0 = wallet.CommitBatchArguments{ + idl.NewNat(uint(0)), + []wallet.BatchOperationKind{{ + CreateAsset: idl.Ptr(wallet.CreateAssetArguments{ + *new(string), + *new(string), + *new(*uint64), + *new(*[]wallet.HeaderField), + *new(*bool), + *new(*bool), + }), + }}, + } if err := a.CommitBatch(a0); err != nil { t.Fatal(err) } @@ -142,7 +157,10 @@ func Test_CommitProposedBatch(t *testing.T) { t.Fatal(err) } - var a0 wallet.CommitProposedBatchArguments + var a0 = wallet.CommitProposedBatchArguments{ + idl.NewNat(uint(0)), + *new([]byte), + } if err := a.CommitProposedBatch(a0); err != nil { t.Fatal(err) } @@ -164,7 +182,10 @@ func Test_ComputeEvidence(t *testing.T) { t.Fatal(err) } - var a0 wallet.ComputeEvidenceArguments + var a0 = wallet.ComputeEvidenceArguments{ + idl.NewNat(uint(0)), + *new(*uint16), + } if _, err := a.ComputeEvidence(a0); err != nil { t.Fatal(err) } @@ -186,7 +207,14 @@ func Test_CreateAsset(t *testing.T) { t.Fatal(err) } - var a0 wallet.CreateAssetArguments + var a0 = wallet.CreateAssetArguments{ + *new(string), + *new(string), + *new(*uint64), + *new(*[]wallet.HeaderField), + *new(*bool), + *new(*bool), + } if err := a.CreateAsset(a0); err != nil { t.Fatal(err) } @@ -201,9 +229,11 @@ func Test_CreateBatch(t *testing.T) { Arguments: []any{new(struct { })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { BatchId wallet.BatchId `ic:"batch_id"` - })}, nil + }{ + idl.NewNat(uint(0)), + }}, nil }, }, }) @@ -211,8 +241,8 @@ func Test_CreateBatch(t *testing.T) { t.Fatal(err) } - var a0 struct { - } + var a0 = struct { + }{} if _, err := a.CreateBatch(a0); err != nil { t.Fatal(err) } @@ -229,9 +259,11 @@ func Test_CreateChunk(t *testing.T) { Content []byte `ic:"content"` })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { ChunkId wallet.ChunkId `ic:"chunk_id"` - })}, nil + }{ + idl.NewNat(uint(0)), + }}, nil }, }, }) @@ -239,9 +271,12 @@ func Test_CreateChunk(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { BatchId wallet.BatchId `ic:"batch_id"` Content []byte `ic:"content"` + }{ + idl.NewNat(uint(0)), + *new([]byte), } if _, err := a.CreateChunk(a0); err != nil { t.Fatal(err) @@ -264,7 +299,7 @@ func Test_Deauthorize(t *testing.T) { t.Fatal(err) } - var a0 principal.Principal + var a0 = *new(principal.Principal) if err := a.Deauthorize(a0); err != nil { t.Fatal(err) } @@ -286,7 +321,9 @@ func Test_DeleteAsset(t *testing.T) { t.Fatal(err) } - var a0 wallet.DeleteAssetArguments + var a0 = wallet.DeleteAssetArguments{ + *new(string), + } if err := a.DeleteAsset(a0); err != nil { t.Fatal(err) } @@ -308,7 +345,9 @@ func Test_DeleteBatch(t *testing.T) { t.Fatal(err) } - var a0 wallet.DeleteBatchArguments + var a0 = wallet.DeleteBatchArguments{ + idl.NewNat(uint(0)), + } if err := a.DeleteBatch(a0); err != nil { t.Fatal(err) } @@ -325,13 +364,19 @@ func Test_Get(t *testing.T) { AcceptEncodings []string `ic:"accept_encodings"` })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Content []byte `ic:"content"` ContentType string `ic:"content_type"` ContentEncoding string `ic:"content_encoding"` Sha256 *[]byte `ic:"sha256,omitempty"` TotalLength idl.Nat `ic:"total_length"` - })}, nil + }{ + *new([]byte), + *new(string), + *new(string), + *new(*[]byte), + idl.NewNat(uint(0)), + }}, nil }, }, }) @@ -339,9 +384,12 @@ func Test_Get(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { Key wallet.Key `ic:"key"` AcceptEncodings []string `ic:"accept_encodings"` + }{ + *new(string), + []string{*new(string)}, } if _, err := a.Get(a0); err != nil { t.Fatal(err) @@ -356,12 +404,17 @@ func Test_GetAssetProperties(t *testing.T) { Name: "get_asset_properties", Arguments: []any{new(wallet.Key)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { MaxAge *uint64 `ic:"max_age,omitempty"` Headers *[]wallet.HeaderField `ic:"headers,omitempty"` AllowRawAccess *bool `ic:"allow_raw_access,omitempty"` IsAliased *bool `ic:"is_aliased,omitempty"` - })}, nil + }{ + *new(*uint64), + *new(*[]wallet.HeaderField), + *new(*bool), + *new(*bool), + }}, nil }, }, }) @@ -369,7 +422,7 @@ func Test_GetAssetProperties(t *testing.T) { t.Fatal(err) } - var a0 wallet.Key + var a0 = *new(string) if _, err := a.GetAssetProperties(a0); err != nil { t.Fatal(err) } @@ -388,9 +441,11 @@ func Test_GetChunk(t *testing.T) { Sha256 *[]byte `ic:"sha256,omitempty"` })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(struct { + return []any{struct { Content []byte `ic:"content"` - })}, nil + }{ + *new([]byte), + }}, nil }, }, }) @@ -398,11 +453,16 @@ func Test_GetChunk(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { Key wallet.Key `ic:"key"` ContentEncoding string `ic:"content_encoding"` Index idl.Nat `ic:"index"` Sha256 *[]byte `ic:"sha256,omitempty"` + }{ + *new(string), + *new(string), + idl.NewNat(uint(0)), + *new(*[]byte), } if _, err := a.GetChunk(a0); err != nil { t.Fatal(err) @@ -425,7 +485,12 @@ func Test_GrantPermission(t *testing.T) { t.Fatal(err) } - var a0 wallet.GrantPermission + var a0 = wallet.GrantPermission{ + *new(principal.Principal), + wallet.Permission{ + Commit: new(idl.Null), + }, + } if err := a.GrantPermission(a0); err != nil { t.Fatal(err) } @@ -439,7 +504,15 @@ func Test_HttpRequest(t *testing.T) { Name: "http_request", Arguments: []any{new(wallet.HttpRequest)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(wallet.HttpResponse)}, nil + return []any{wallet.HttpResponse{ + *new(uint16), + []wallet.HeaderField{{ + *new(string), + *new(string), + }}, + *new([]byte), + *new(*wallet.StreamingStrategy), + }}, nil }, }, }) @@ -447,7 +520,16 @@ func Test_HttpRequest(t *testing.T) { t.Fatal(err) } - var a0 wallet.HttpRequest + var a0 = wallet.HttpRequest{ + *new(string), + *new(string), + []wallet.HeaderField{{ + *new(string), + *new(string), + }}, + *new([]byte), + *new(*uint16), + } if _, err := a.HttpRequest(a0); err != nil { t.Fatal(err) } @@ -469,7 +551,12 @@ func Test_HttpRequestStreamingCallback(t *testing.T) { t.Fatal(err) } - var a0 wallet.StreamingCallbackToken + var a0 = wallet.StreamingCallbackToken{ + *new(string), + *new(string), + idl.NewNat(uint(0)), + *new(*[]byte), + } if _, err := a.HttpRequestStreamingCallback(a0); err != nil { t.Fatal(err) } @@ -484,7 +571,7 @@ func Test_List(t *testing.T) { Arguments: []any{new(struct { })}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]struct { + return []any{[]struct { Key wallet.Key `ic:"key"` ContentType string `ic:"content_type"` Encodings []struct { @@ -493,7 +580,25 @@ func Test_List(t *testing.T) { Length idl.Nat `ic:"length"` Modified wallet.Time `ic:"modified"` } `ic:"encodings"` - })}, nil + }{ + + { + *new(string), + *new(string), + []struct { + ContentEncoding string `ic:"content_encoding"` + Sha256 *[]byte `ic:"sha256,omitempty"` + Length idl.Nat `ic:"length"` + Modified wallet.Time `ic:"modified"` + }{ + + { + *new(string), + *new(*[]byte), + idl.NewNat(uint(0)), + idl.NewInt(0), + }}, + }}}, nil }, }, }) @@ -501,8 +606,8 @@ func Test_List(t *testing.T) { t.Fatal(err) } - var a0 struct { - } + var a0 = struct { + }{} if _, err := a.List(a0); err != nil { t.Fatal(err) } @@ -516,7 +621,7 @@ func Test_ListAuthorized(t *testing.T) { Name: "list_authorized", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]principal.Principal)}, nil + return []any{[]principal.Principal{*new(principal.Principal)}}, nil }, }, }) @@ -537,7 +642,7 @@ func Test_ListPermitted(t *testing.T) { Name: "list_permitted", Arguments: []any{new(wallet.ListPermitted)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]principal.Principal)}, nil + return []any{[]principal.Principal{*new(principal.Principal)}}, nil }, }, }) @@ -545,7 +650,11 @@ func Test_ListPermitted(t *testing.T) { t.Fatal(err) } - var a0 wallet.ListPermitted + var a0 = wallet.ListPermitted{ + wallet.Permission{ + Commit: new(idl.Null), + }, + } if _, err := a.ListPermitted(a0); err != nil { t.Fatal(err) } @@ -567,7 +676,19 @@ func Test_ProposeCommitBatch(t *testing.T) { t.Fatal(err) } - var a0 wallet.CommitBatchArguments + var a0 = wallet.CommitBatchArguments{ + idl.NewNat(uint(0)), + []wallet.BatchOperationKind{{ + CreateAsset: idl.Ptr(wallet.CreateAssetArguments{ + *new(string), + *new(string), + *new(*uint64), + *new(*[]wallet.HeaderField), + *new(*bool), + *new(*bool), + }), + }}, + } if err := a.ProposeCommitBatch(a0); err != nil { t.Fatal(err) } @@ -589,7 +710,12 @@ func Test_RevokePermission(t *testing.T) { t.Fatal(err) } - var a0 wallet.RevokePermission + var a0 = wallet.RevokePermission{ + *new(principal.Principal), + wallet.Permission{ + Commit: new(idl.Null), + }, + } if err := a.RevokePermission(a0); err != nil { t.Fatal(err) } @@ -611,7 +737,12 @@ func Test_SetAssetContent(t *testing.T) { t.Fatal(err) } - var a0 wallet.SetAssetContentArguments + var a0 = wallet.SetAssetContentArguments{ + *new(string), + *new(string), + []wallet.ChunkId{idl.NewNat(uint(0))}, + *new(*[]byte), + } if err := a.SetAssetContent(a0); err != nil { t.Fatal(err) } @@ -633,7 +764,13 @@ func Test_SetAssetProperties(t *testing.T) { t.Fatal(err) } - var a0 wallet.SetAssetPropertiesArguments + var a0 = wallet.SetAssetPropertiesArguments{ + *new(string), + *new(**uint64), + *new(**[]wallet.HeaderField), + *new(**bool), + *new(**bool), + } if err := a.SetAssetProperties(a0); err != nil { t.Fatal(err) } @@ -661,12 +798,18 @@ func Test_Store(t *testing.T) { t.Fatal(err) } - var a0 struct { + var a0 = struct { Key wallet.Key `ic:"key"` ContentType string `ic:"content_type"` ContentEncoding string `ic:"content_encoding"` Content []byte `ic:"content"` Sha256 *[]byte `ic:"sha256,omitempty"` + }{ + *new(string), + *new(string), + *new(string), + *new([]byte), + *new(*[]byte), } if err := a.Store(a0); err != nil { t.Fatal(err) @@ -710,7 +853,10 @@ func Test_UnsetAssetContent(t *testing.T) { t.Fatal(err) } - var a0 wallet.UnsetAssetContentArguments + var a0 = wallet.UnsetAssetContentArguments{ + *new(string), + *new(string), + } if err := a.UnsetAssetContent(a0); err != nil { t.Fatal(err) } @@ -724,7 +870,9 @@ func Test_ValidateCommitProposedBatch(t *testing.T) { Name: "validate_commit_proposed_batch", Arguments: []any{new(wallet.CommitProposedBatchArguments)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(wallet.ValidationResult)}, nil + return []any{wallet.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) @@ -732,7 +880,10 @@ func Test_ValidateCommitProposedBatch(t *testing.T) { t.Fatal(err) } - var a0 wallet.CommitProposedBatchArguments + var a0 = wallet.CommitProposedBatchArguments{ + idl.NewNat(uint(0)), + *new([]byte), + } if _, err := a.ValidateCommitProposedBatch(a0); err != nil { t.Fatal(err) } @@ -746,7 +897,9 @@ func Test_ValidateGrantPermission(t *testing.T) { Name: "validate_grant_permission", Arguments: []any{new(wallet.GrantPermission)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(wallet.ValidationResult)}, nil + return []any{wallet.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) @@ -754,7 +907,12 @@ func Test_ValidateGrantPermission(t *testing.T) { t.Fatal(err) } - var a0 wallet.GrantPermission + var a0 = wallet.GrantPermission{ + *new(principal.Principal), + wallet.Permission{ + Commit: new(idl.Null), + }, + } if _, err := a.ValidateGrantPermission(a0); err != nil { t.Fatal(err) } @@ -768,7 +926,9 @@ func Test_ValidateRevokePermission(t *testing.T) { Name: "validate_revoke_permission", Arguments: []any{new(wallet.RevokePermission)}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(wallet.ValidationResult)}, nil + return []any{wallet.ValidationResult{ + Ok: new(string), + }}, nil }, }, }) @@ -776,7 +936,12 @@ func Test_ValidateRevokePermission(t *testing.T) { t.Fatal(err) } - var a0 wallet.RevokePermission + var a0 = wallet.RevokePermission{ + *new(principal.Principal), + wallet.Permission{ + Commit: new(idl.Null), + }, + } if _, err := a.ValidateRevokePermission(a0); err != nil { t.Fatal(err) } @@ -790,7 +955,9 @@ func Test_ValidateTakeOwnership(t *testing.T) { Name: "validate_take_ownership", Arguments: []any{}, Handler: func(request mock.Request) ([]any, error) { - return []any{*new(wallet.ValidationResult)}, nil + return []any{wallet.ValidationResult{ + Ok: new(string), + }}, nil }, }, })