Skip to content

Commit

Permalink
Merge pull request #40 from onflow/auto-update-onflow-cadence-v1.0.0-…
Browse files Browse the repository at this point in the history
…preview.25
  • Loading branch information
turbolent authored May 2, 2024
2 parents 14bff7b + a1765cd commit 7b6316a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 57 deletions.
23 changes: 11 additions & 12 deletions config/json/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package json

import (
"encoding/json"
"fmt"

"github.com/invopop/jsonschema"
"github.com/onflow/cadence"
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion config/json/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"testing"

"github.com/onflow/cadence"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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)
}
12 changes: 1 addition & 11 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
10 changes: 5 additions & 5 deletions flowkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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")}
Expand Down
8 changes: 6 additions & 2 deletions gateway/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gateway/mocks/gateway_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1936,29 +1936,29 @@ 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=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240429192223-e696a8e439b5 h1:by3a+8p2kUUjnxfbRYRd78bDEeXAc3PK2LzyBEQqkV4=
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=
Expand Down
2 changes: 1 addition & 1 deletion mocks/services_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions tests/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}}

Expand Down

0 comments on commit 7b6316a

Please sign in to comment.