Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed May 2, 2024
1 parent dc655f4 commit d42df85
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 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
12 changes: 7 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,9 @@ 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)
retVal, err := cadence.NewString("")
require.NoError(t, err)
gw.ExecuteScript.Return(retVal, nil)
})

args := []cadence.Value{cadence.String("Foo")}
Expand Down
3 changes: 2 additions & 1 deletion mocks/services_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ func DefaultMockServices() *MockServices {
})

t.ExecuteScript.Run(func(args mock.Arguments) {
t.ExecuteScript.Return(cadence.MustConvertValue(""), nil)
retVal, err := cadence.NewString("")
t.ExecuteScript.Return(retVal, err)
})

t.GetTransactionByID.Return(tests.NewTransaction(), nil)
Expand Down

0 comments on commit d42df85

Please sign in to comment.