From 02fdc4cc1b13fd6149088fa0dee724152bade885 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 2 May 2024 22:13:30 -0700 Subject: [PATCH 1/4] Contract deployment args fix --- config/json/deploy.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/config/json/deploy.go b/config/json/deploy.go index 9d91e1c7..e3905328 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,7 @@ 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()), - }) - } + args = append(args, jsoncdc.Prepare(arg).(map[string]any)) } deployments = append(deployments, deployment{ From e4333277d1d578f959c1250cd557dca7d72e5651 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 2 May 2024 22:31:27 -0700 Subject: [PATCH 2/4] fix --- config/json/deploy.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/json/deploy.go b/config/json/deploy.go index e3905328..d13897e8 100644 --- a/config/json/deploy.go +++ b/config/json/deploy.go @@ -100,9 +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 { - args = append(args, jsoncdc.Prepare(arg).(map[string]any)) + args = append(args, jsoncdc.Prepare(arg)) } deployments = append(deployments, deployment{ @@ -128,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 { From b6257c6aebcf5b2dded7bd5f273db1729753a5de Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 2 May 2024 22:38:19 -0700 Subject: [PATCH 3/4] fix broken test (fixes ordering issue) --- config/json/deploy_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/config/json/deploy_test.go b/config/json/deploy_test.go index 41b0c880..7af5bad2 100644 --- a/config/json/deploy_test.go +++ b/config/json/deploy_test.go @@ -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) { From 3b3411e895576f6d373bd0e7cb0cd7fde810af84 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 2 May 2024 22:40:35 -0700 Subject: [PATCH 4/4] fix schema --- schema.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/schema.json b/schema.json index 7a0281ef..478fee70 100644 --- a/schema.json +++ b/schema.json @@ -120,9 +120,7 @@ "type": "string" }, "args": { - "items": { - "type": "object" - }, + "items": true, "type": "array" } },