diff --git a/config/json/deploy.go b/config/json/deploy.go index 157ac389..16810e2b 100644 --- a/config/json/deploy.go +++ b/config/json/deploy.go @@ -20,7 +20,6 @@ package json import ( "encoding/json" - "fmt" "github.com/invopop/jsonschema" "github.com/onflow/cadence" @@ -103,18 +102,18 @@ func transformDeploymentsToJSON(configDeployments config.Deployments) jsonDeploy } else { args := make([]map[string]any, 0) for _, arg := range c.Args { - switch arg.Type().ID() { - case "Bool": - args = append(args, map[string]any{ - "type": arg.Type().ID(), - "value": arg.ToGoValue(), - }) - default: - args = append(args, map[string]any{ - "type": arg.Type().ID(), - "value": fmt.Sprintf("%v", arg.ToGoValue()), - }) + jsonEncoded, err := jsoncdc.Encode(arg) + if err != nil { + panic(err) } + + jsonMap := make(map[string]any) + err = json.Unmarshal(jsonEncoded, &jsonMap) + if err != nil { + panic(err) + } + + args = append(args, jsonMap) } deployments = append(deployments, deployment{ diff --git a/config/json/deploy_test.go b/config/json/deploy_test.go index 41b0c880..95eb3988 100644 --- a/config/json/deploy_test.go +++ b/config/json/deploy_test.go @@ -23,6 +23,7 @@ import ( "strings" "testing" + "github.com/onflow/cadence" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -147,7 +148,7 @@ func Test_DeploymentAdvanced(t *testing.T) { assert.Equal(t, `"Hello World"`, alice.Contracts[0].Args[0].String()) assert.Equal(t, "10", alice.Contracts[0].Args[1].String()) assert.Equal(t, "Bool", alice.Contracts[0].Args[2].Type().ID()) - assert.False(t, alice.Contracts[0].Args[2].ToGoValue().(bool)) + assert.False(t, bool(alice.Contracts[0].Args[2].(cadence.Bool))) assert.Equal(t, "KittyItemsMarket", alice.Contracts[1].Name) assert.Len(t, alice.Contracts[1].Args, 0) } diff --git a/events.go b/events.go index 7cf6e767..7137dadb 100644 --- a/events.go +++ b/events.go @@ -49,19 +49,9 @@ func EventsFromTransaction(tx *flow.TransactionResult) Events { } func NewEvent(event flow.Event) Event { - var names []string - - for _, eventType := range event.Value.EventType.Fields { - names = append(names, eventType.Identifier) - } - values := make(map[string]cadence.Value) - for id, field := range event.Value.Fields { - values[names[id]] = field - } - return Event{ Type: event.Type, - Values: values, + Values: cadence.FieldsMappedByName(event.Value), } } diff --git a/flowkit_test.go b/flowkit_test.go index 7eae437c..1617d505 100644 --- a/flowkit_test.go +++ b/flowkit_test.go @@ -1096,12 +1096,12 @@ func TestProject(t *testing.T) { argCode := tx.Arguments[1] decodeCode, _ := jsoncdc.Decode(nil, argCode) - code := decodeCode.ToGoValue().(string) + code := string(decodeCode.(cadence.String)) argName := tx.Arguments[0] decodeName, _ := jsoncdc.Decode(nil, argName) - testCode, found := resolved[decodeName.ToGoValue().(string)] + testCode, found := resolved[string(decodeName.(cadence.String))] require.True(t, found) assert.True(t, strings.Contains(string(code), testCode)) @@ -1173,12 +1173,12 @@ func TestProject(t *testing.T) { argCode := tx.Arguments[1] decodeCode, _ := jsoncdc.Decode(nil, argCode) - code, _ := decodeCode.ToGoValue().(string) + code := string(decodeCode.(cadence.String)) argName := tx.Arguments[0] decodeName, _ := jsoncdc.Decode(nil, argName) - testCode, found := resolved[decodeName.ToGoValue().(string)] + testCode, found := resolved[string(decodeName.(cadence.String))] require.True(t, found) assert.True(t, strings.Contains(string(code), testCode)) @@ -1372,7 +1372,7 @@ func TestScripts(t *testing.T) { gw.ExecuteScript.Run(func(args mock.Arguments) { assert.Len(t, string(args.Get(1).([]byte)), 86) assert.Equal(t, "\"Foo\"", args.Get(2).([]cadence.Value)[0].String()) - gw.ExecuteScript.Return(cadence.MustConvertValue(""), nil) + gw.ExecuteScript.Return(cadence.String(""), nil) }) args := []cadence.Value{cadence.String("Foo")} diff --git a/gateway/grpc.go b/gateway/grpc.go index b0e0e7e4..68072609 100644 --- a/gateway/grpc.go +++ b/gateway/grpc.go @@ -54,7 +54,9 @@ func NewGrpcGateway(network config.Network, opts ...grpc.DialOption) (*GrpcGatew options = append(options, opts...) gClient, err := grpcAccess.NewClient( network.Host, - options..., + grpcAccess.WithGRPCDialOptions( + options..., + ), ) if err != nil || gClient == nil { @@ -82,7 +84,9 @@ func NewSecureGrpcGateway(network config.Network, opts ...grpc.DialOption) (*Grp gClient, err := grpcAccess.NewClient( network.Host, - options..., + grpcAccess.WithGRPCDialOptions( + options..., + ), ) if err != nil || gClient == nil { diff --git a/gateway/mocks/gateway_mock.go b/gateway/mocks/gateway_mock.go index 0e351f13..17b54f8b 100644 --- a/gateway/mocks/gateway_mock.go +++ b/gateway/mocks/gateway_mock.go @@ -120,7 +120,7 @@ func DefaultMockGateway() *TestGateway { }) t.ExecuteScript.Run(func(args mock.Arguments) { - t.ExecuteScript.Return(cadence.MustConvertValue(""), nil) + t.ExecuteScript.Return(cadence.String(""), nil) }) t.GetTransaction.Return(tests.NewTransaction(), nil) diff --git a/go.mod b/go.mod index b1786d7c..04066875 100644 --- a/go.mod +++ b/go.mod @@ -7,11 +7,11 @@ require ( github.com/gosuri/uilive v0.0.4 github.com/invopop/jsonschema v0.7.0 github.com/lmars/go-slip10 v0.0.0-20190606092855-400ba44fee12 - github.com/onflow/cadence v1.0.0-preview.23 + github.com/onflow/cadence v1.0.0-preview.25 github.com/onflow/crypto v0.25.1 - github.com/onflow/flow-emulator v1.0.0-preview.21 - github.com/onflow/flow-go v0.34.0-crescendo-preview.17 - github.com/onflow/flow-go-sdk v1.0.0-preview.22 + github.com/onflow/flow-emulator v1.0.0-preview.22 + github.com/onflow/flow-go v0.34.0-crescendo-preview.18 + github.com/onflow/flow-go-sdk v1.0.0-preview.25 github.com/onflow/go-ethereum v1.13.4 github.com/pkg/errors v0.9.1 github.com/rs/zerolog v1.29.0 @@ -136,7 +136,7 @@ require ( github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/onflow/atree v0.6.1-0.20240416233652-f4568c0c03df // indirect + github.com/onflow/atree v0.7.0-rc.1 // indirect github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240429192223-e696a8e439b5 // indirect github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240429192223-e696a8e439b5 // indirect github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240424211859-3ff4c0fe2a1e // indirect diff --git a/go.sum b/go.sum index 87218487..ed9298e6 100644 --- a/go.sum +++ b/go.sum @@ -1936,11 +1936,11 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= -github.com/onflow/atree v0.6.1-0.20240416233652-f4568c0c03df h1:9dmE37nSKCV1obdPFtUgjKFH2yUHmfSkULX5h35l8yo= -github.com/onflow/atree v0.6.1-0.20240416233652-f4568c0c03df/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= +github.com/onflow/atree v0.7.0-rc.1 h1:g2DFhC3JeaA+L7/HZOp4NwE+OfxvfJ8nibymHHw7i3g= +github.com/onflow/atree v0.7.0-rc.1/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.23 h1:2YgRu+e3MQRiz4HBwTj1NrT2nY9rD6wiyrM10JLjbWA= -github.com/onflow/cadence v1.0.0-preview.23/go.mod h1:3UHGl+T7JjK2S8P+FHOjWwBoTYwAimN0QXW/UYb2PjQ= +github.com/onflow/cadence v1.0.0-preview.25 h1:kSmWjxmg9PS+bsk8C3j1NUTkFAl/jNrintVhlh6miM0= +github.com/onflow/cadence v1.0.0-preview.25/go.mod h1:fGhLBbuEmv5rh48qv0ZS0tUz53gxWsHpB4dPsF09h6E= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A= github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= @@ -1948,17 +1948,17 @@ github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240429192223- github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240429192223-e696a8e439b5/go.mod h1:+4JWLclBOT+emyBh6NAZSEbqEwzHcWHpIbfsXmRASgY= github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240429192223-e696a8e439b5 h1:6Cg0h+8Iyy/Nnefk5j0gdeVoMTNpUooAMjyV8sk6zoA= github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240429192223-e696a8e439b5/go.mod h1:0oTx6Nkc+LdOXaZe3PRtV1cY+J5z5ig08alR8d+OPHs= -github.com/onflow/flow-emulator v1.0.0-preview.21 h1:ysrlVUPyvhojvaWLQsTGbpgLgR7h3f7Hjcwm9GuFn+U= -github.com/onflow/flow-emulator v1.0.0-preview.21/go.mod h1:Q9tMIfY3p0SLaoNJ/4GRxnm0LRGXRk4ElsvzOeX2Xvc= +github.com/onflow/flow-emulator v1.0.0-preview.22 h1:l0BPXlDvK0gZDqQhY3Kc7pBm38pE/FbfefiZe7j6Ngg= +github.com/onflow/flow-emulator v1.0.0-preview.22/go.mod h1:60M4QPVpdpEhEdz6NGOtLule+jcRLLKID1gYv2ehLvw= github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240424211859-3ff4c0fe2a1e h1:2LO6Rtmz2PVfH+ZXnMwvTwVeIz3PCy0fs3lQraqog14= github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240424211859-3ff4c0fe2a1e/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v0.7.1-0.20240424211859-3ff4c0fe2a1e h1:jl7SYAui/gYRmBofrY//Ln8ixRJwvLzvwLstNfRKmWY= github.com/onflow/flow-ft/lib/go/templates v0.7.1-0.20240424211859-3ff4c0fe2a1e/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE= -github.com/onflow/flow-go v0.34.0-crescendo-preview.17 h1:HnISCj+nZkfwDHmVF1VmbmyuVbOH76GNGKFTMbthD7c= -github.com/onflow/flow-go v0.34.0-crescendo-preview.17/go.mod h1:WbsDXtDBGRil+pQevdxTlP2r3a67/Aq5Y7+ab/P0aFw= +github.com/onflow/flow-go v0.34.0-crescendo-preview.18 h1:Bre7uU/n1PjOEcIkTtaJDo4T5tngjKcr/cAOvxr3se4= +github.com/onflow/flow-go v0.34.0-crescendo-preview.18/go.mod h1:bwjzi2kSev1emRVN685FqYfCLYcZ6t2A5z5ztYXfvH8= github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo= -github.com/onflow/flow-go-sdk v1.0.0-preview.22 h1:ahHlppdDd4TjHMfnE73SD15AR16KTgbczdhFjGjAtFM= -github.com/onflow/flow-go-sdk v1.0.0-preview.22/go.mod h1:0hJfpIajLtBvaAUfJAdvWx6WBVp5hS0DJidc0NJLgE4= +github.com/onflow/flow-go-sdk v1.0.0-preview.25 h1:wL/+cK7oxSww31qSqTpt1Yfr26c8hJ8YHh9nIdq6PlI= +github.com/onflow/flow-go-sdk v1.0.0-preview.25/go.mod h1:Px1fQdB7WFC0yhYsEM3rhKzuE+Zi8GpBjR4qVuDAwMA= github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240429184308-40c3de711140 h1:oTj4RGgfuJSSBE1aDVrlh6avxKBMraucpNtRg0K+yhg= github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240429184308-40c3de711140/go.mod h1:2gpbza+uzs1k7x31hkpBPlggIRkI53Suo0n2AyA2HcE= github.com/onflow/flow-nft/lib/go/templates v0.0.0-20240429184308-40c3de711140 h1:7NwSIG4SEdm+96gr+Aaqx291jZ/Bqkxk/ghVnens9CU= diff --git a/mocks/services_mock.go b/mocks/services_mock.go index 8790b2c5..b19c676e 100644 --- a/mocks/services_mock.go +++ b/mocks/services_mock.go @@ -207,7 +207,7 @@ func DefaultMockServices() *MockServices { }) t.ExecuteScript.Run(func(args mock.Arguments) { - t.ExecuteScript.Return(cadence.MustConvertValue(""), nil) + t.ExecuteScript.Return(cadence.String(""), nil) }) t.GetTransactionByID.Return(tests.NewTransaction(), nil) diff --git a/tests/resources.go b/tests/resources.go index e7aae37f..f24f16e7 100644 --- a/tests/resources.go +++ b/tests/resources.go @@ -640,20 +640,23 @@ func NewTransactionResult(events []flow.Event) *flow.TransactionResult { } func NewAccountCreateResult(address flow.Address) *flow.TransactionResult { + eventType := cadence.NewEventType( + common.NewStringLocation(nil, flow.EventAccountCreated), + "", + []cadence.Field{{ + Identifier: "address", + Type: cadence.AddressType, + }}, + nil, + ) events := []flow.Event{{ Type: flow.EventAccountCreated, TransactionID: flow.Identifier{}, TransactionIndex: 0, EventIndex: 0, - Value: cadence.Event{ - EventType: cadence.NewEventType(common.NewStringLocation(nil, flow.EventAccountCreated), "", []cadence.Field{{ - Identifier: "address", - Type: cadence.AddressType, - }}, nil), - Fields: []cadence.Value{ - cadence.NewAddress(address), - }, - }, + Value: cadence.NewEvent([]cadence.Value{ + cadence.NewAddress(address), + }).WithType(eventType), Payload: nil, }}