Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract deployment args fix #42

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 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 @@ -101,20 +100,9 @@ func transformDeploymentsToJSON(configDeployments config.Deployments) jsonDeploy
simple: c.Name,
})
} else {
args := make([]map[string]any, 0)
args := make([]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()),
})
}
args = append(args, jsoncdc.Prepare(arg))
}

deployments = append(deployments, deployment{
Expand All @@ -140,8 +128,8 @@ func transformDeploymentsToJSON(configDeployments config.Deployments) jsonDeploy
}

type contractDeployment struct {
Name string `json:"name"`
Args []map[string]any `json:"args"`
Name string `json:"name"`
Args []any `json:"args"`
}

type deployment struct {
Expand Down
14 changes: 10 additions & 4 deletions config/json/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,23 @@ func Test_TransformDeployToJSON(t *testing.T) {
}
}`)

var jsonDeployments jsonDeployments
err := json.Unmarshal(b, &jsonDeployments)
var original jsonDeployments
err := json.Unmarshal(b, &original)
assert.NoError(t, err)

deployments, err := jsonDeployments.transformToConfig()
deployments, err := original.transformToConfig()
assert.NoError(t, err)

j := transformDeploymentsToJSON(deployments)
x, _ := json.Marshal(j)

assert.Equal(t, cleanSpecialChars(b), cleanSpecialChars(x))
// Unmarshal the config again to compare against the original
var result jsonDeployments
err = json.Unmarshal(x, &result)
assert.NoError(t, err)

// Check that result is same as original after transformation
assert.Equal(t, original, result)
}

func Test_DeploymentAdvanced(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@
"type": "string"
},
"args": {
"items": {
"type": "object"
},
"items": true,
"type": "array"
}
},
Expand Down
Loading