From 741c1d7baad48658e9f3653e9bbad3e36ec5b415 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Fri, 5 Jan 2024 17:30:18 -0600 Subject: [PATCH 1/7] add prefix to user address when processing flow.json --- internal/super/flix.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 64550da36..3b4a94e66 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -24,6 +24,7 @@ import ( "net/url" "os" "path/filepath" + "strings" "github.com/onflow/flixkit-go/flixkit" @@ -290,7 +291,7 @@ func GetDeployedContracts(state *flowkit.State) flixkit.ContractInfos { if _, ok := allContracts[c.Name]; !ok { allContracts[c.Name] = make(flixkit.NetworkAddressMap) } - allContracts[c.Name][network] = c.AccountAddress.String() + allContracts[c.Name][network] = add0xPrefix(c.AccountAddress.String()) } locAliases := state.AliasesForNetwork(config.Network{Name: network}) for name, addr := range locAliases { @@ -300,12 +301,19 @@ func GetDeployedContracts(state *flowkit.State) flixkit.ContractInfos { if _, ok := allContracts[name]; !ok { allContracts[name] = make(flixkit.NetworkAddressMap) } - allContracts[name][network] = addr + allContracts[name][network] = add0xPrefix(addr) } } return allContracts } +func add0xPrefix(s string) string { + prefix := "0x" + if !strings.HasPrefix(s, prefix) { + return prefix + s + } + return s +} func isUrl(str string) bool { u, err := url.Parse(str) return err == nil && u.Scheme != "" && u.Host != "" From 3e15d878488cd1924dfbc7195098c48731727a93 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 8 Jan 2024 13:02:07 -0600 Subject: [PATCH 2/7] use .Hex() to format address --- internal/super/flix.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 3b4a94e66..5320c2b93 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -24,7 +24,6 @@ import ( "net/url" "os" "path/filepath" - "strings" "github.com/onflow/flixkit-go/flixkit" @@ -34,7 +33,7 @@ import ( "github.com/onflow/flow-cli/internal/command" "github.com/onflow/flow-cli/internal/scripts" "github.com/onflow/flow-cli/internal/transactions" - + "github.com/onflow/flow-go-sdk" "github.com/spf13/cobra" ) @@ -291,29 +290,23 @@ func GetDeployedContracts(state *flowkit.State) flixkit.ContractInfos { if _, ok := allContracts[c.Name]; !ok { allContracts[c.Name] = make(flixkit.NetworkAddressMap) } - allContracts[c.Name][network] = add0xPrefix(c.AccountAddress.String()) + allContracts[c.Name][network] = c.AccountAddress.Hex() } locAliases := state.AliasesForNetwork(config.Network{Name: network}) for name, addr := range locAliases { + address := flow.BytesToAddress([]byte(addr)) if isPath(name) { continue } if _, ok := allContracts[name]; !ok { allContracts[name] = make(flixkit.NetworkAddressMap) } - allContracts[name][network] = add0xPrefix(addr) + allContracts[name][network] = address.Hex() } } return allContracts } -func add0xPrefix(s string) string { - prefix := "0x" - if !strings.HasPrefix(s, prefix) { - return prefix + s - } - return s -} func isUrl(str string) bool { u, err := url.Parse(str) return err == nil && u.Scheme != "" && u.Host != "" From da50b06ece76f59a36c12ec15419ae030ec0f76e Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 8 Jan 2024 14:38:34 -0600 Subject: [PATCH 3/7] update to use newest version of flixkit-go --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d73c8cf14..6d2bcce87 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onflow/cadence-tools/languageserver v0.33.3 github.com/onflow/cadence-tools/test v0.14.5 github.com/onflow/fcl-dev-wallet v0.7.4 - github.com/onflow/flixkit-go v1.0.0 + github.com/onflow/flixkit-go v1.0.1 github.com/onflow/flow-cli/flowkit v1.6.1-0.20231110211255-b41f57a8b8c7 github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f github.com/onflow/flow-emulator v0.59.0 From ce5b320be8176c38b86039065532ac3284075548 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 8 Jan 2024 14:41:22 -0600 Subject: [PATCH 4/7] update dependencies --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index a84212ff6..0710702d4 100644 --- a/go.sum +++ b/go.sum @@ -875,8 +875,8 @@ github.com/onflow/cadence-tools/test v0.14.5 h1:u1kYkotKdwKEf9c3h65mI3VMevBkHY+7 github.com/onflow/cadence-tools/test v0.14.5/go.mod h1:ix09Bb3GQ/fZMNpSR8E+vSFItGF54fzP9gFxU7AsOIw= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= github.com/onflow/fcl-dev-wallet v0.7.4/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw= -github.com/onflow/flixkit-go v1.0.0 h1:SY2H4iB3kW8CEOxnofJZYm3sEZXnz3x0qiWkIe4l1LI= -github.com/onflow/flixkit-go v1.0.0/go.mod h1:KGL7oMu4uzt7s0qsNkaqGBYIt+Z38Qbf0JG56qK/Sg0= +github.com/onflow/flixkit-go v1.0.1 h1:/YZTxDfLAyxL0PdxnINUuJCTTLDsmLqNTXlCJDg87k8= +github.com/onflow/flixkit-go v1.0.1/go.mod h1:KGL7oMu4uzt7s0qsNkaqGBYIt+Z38Qbf0JG56qK/Sg0= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f h1:S8yIZw9LFXfYD1V5H9BiixihHw3GrXVPrmfplSzYaww= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI= github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f h1:Ep+Mpo2miWMe4pjPGIaEvEzshRep30dvNgxqk+//FrQ= From 9dbe65dc30edb897f3bb6440ced4e8b559c8e07c Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 8 Jan 2024 14:47:47 -0600 Subject: [PATCH 5/7] fix linting issues --- internal/super/flix.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 5320c2b93..72e1c78da 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -27,14 +27,15 @@ import ( "github.com/onflow/flixkit-go/flixkit" + "github.com/onflow/flow-go-sdk" + "github.com/spf13/cobra" + "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/config" "github.com/onflow/flow-cli/flowkit/output" "github.com/onflow/flow-cli/internal/command" "github.com/onflow/flow-cli/internal/scripts" "github.com/onflow/flow-cli/internal/transactions" - "github.com/onflow/flow-go-sdk" - "github.com/spf13/cobra" ) type flixFlags struct { From 9438977a2e597b24513003c3e6928873e7cf8a81 Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Tue, 9 Jan 2024 23:02:29 -0600 Subject: [PATCH 6/7] add unit test file for flix, upgrade to v1.0.2 --- go.mod | 2 +- go.sum | 4 +-- internal/super/flix.go | 1 + internal/super/flix_test.go | 60 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 internal/super/flix_test.go diff --git a/go.mod b/go.mod index d73c8cf14..d59388e3f 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onflow/cadence-tools/languageserver v0.33.3 github.com/onflow/cadence-tools/test v0.14.5 github.com/onflow/fcl-dev-wallet v0.7.4 - github.com/onflow/flixkit-go v1.0.0 + github.com/onflow/flixkit-go v1.0.2 github.com/onflow/flow-cli/flowkit v1.6.1-0.20231110211255-b41f57a8b8c7 github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f github.com/onflow/flow-emulator v0.59.0 diff --git a/go.sum b/go.sum index a84212ff6..65f0c2b12 100644 --- a/go.sum +++ b/go.sum @@ -875,8 +875,8 @@ github.com/onflow/cadence-tools/test v0.14.5 h1:u1kYkotKdwKEf9c3h65mI3VMevBkHY+7 github.com/onflow/cadence-tools/test v0.14.5/go.mod h1:ix09Bb3GQ/fZMNpSR8E+vSFItGF54fzP9gFxU7AsOIw= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= github.com/onflow/fcl-dev-wallet v0.7.4/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw= -github.com/onflow/flixkit-go v1.0.0 h1:SY2H4iB3kW8CEOxnofJZYm3sEZXnz3x0qiWkIe4l1LI= -github.com/onflow/flixkit-go v1.0.0/go.mod h1:KGL7oMu4uzt7s0qsNkaqGBYIt+Z38Qbf0JG56qK/Sg0= +github.com/onflow/flixkit-go v1.0.2 h1:6PVLLb8qQj9L6cs57HUO3wszzbgPD46pc9MAGWHnb1s= +github.com/onflow/flixkit-go v1.0.2/go.mod h1:KGL7oMu4uzt7s0qsNkaqGBYIt+Z38Qbf0JG56qK/Sg0= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f h1:S8yIZw9LFXfYD1V5H9BiixihHw3GrXVPrmfplSzYaww= github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI= github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f h1:Ep+Mpo2miWMe4pjPGIaEvEzshRep30dvNgxqk+//FrQ= diff --git a/internal/super/flix.go b/internal/super/flix.go index 64550da36..3dfad09f8 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -283,6 +283,7 @@ func GetDeployedContracts(state *flowkit.State) flixkit.ContractInfos { // get all deployed and alias contracts for configured networks for _, network := range depNetworks { contracts, err := state.DeploymentContractsByNetwork(config.Network{Name: network}) + fmt.Println("contracts len", network, len(contracts)) if err != nil { continue } diff --git a/internal/super/flix_test.go b/internal/super/flix_test.go new file mode 100644 index 000000000..72336b925 --- /dev/null +++ b/internal/super/flix_test.go @@ -0,0 +1,60 @@ +package super + +import ( + "testing" + + "github.com/onflow/flow-cli/flowkit" + "github.com/onflow/flow-cli/flowkit/config" + "github.com/onflow/flow-cli/flowkit/tests" + "github.com/spf13/afero" + "github.com/stretchr/testify/assert" +) + +func Test_flix_generate(t *testing.T) { + configJson := []byte(`{ + "contracts": {}, + "accounts": { + "emulator-account": { + "address": "f8d6e0586b0a20c7", + "key": "dd72967fd2bd75234ae9037dd4694c1f00baad63a10c35172bf65fbb8ad74b47" + } + }, + "networks": { + "emulator": "127.0.0.1.3569" + }, + "deployments": { + } + }`) + + af := afero.Afero{Fs: afero.NewMemMapFs()} + err := afero.WriteFile(af.Fs, "flow.json", configJson, 0644) + assert.NoError(t, err) + err = afero.WriteFile(af.Fs, tests.ContractHelloString.Filename, []byte(tests.ContractHelloString.Source), 0644) + assert.NoError(t, err) + paths := []string{"flow.json"} + state, err := flowkit.Load(paths, af) + assert.NotNil(t, state) + assert.NoError(t, err) + d := config.Deployment{ + Network: "emulator", + Account: "emulator-account", + Contracts: []config.ContractDeployment{{ + Name: tests.ContractHelloString.Name, + Args: nil, + }}, + } + state.Deployments().AddOrUpdate(d) + c := config.Contract{ + Name: tests.ContractHelloString.Name, + Location: tests.ContractHelloString.Filename, + } + state.Contracts().AddOrUpdate(c) + + contracts, err := state.DeploymentContractsByNetwork(config.Network{Name: "emulator"}) + assert.NoError(t, err) + assert.Equal(t, 1, len(contracts)) + + cs := GetDeployedContracts(state) + assert.Equal(t, 1, len(cs)) + +} From 63dc7aa80be6521ffb2bd907cd9ade248ad379da Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Wed, 10 Jan 2024 10:36:12 -0600 Subject: [PATCH 7/7] add to test, fix linting --- internal/super/flix_test.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/super/flix_test.go b/internal/super/flix_test.go index 72336b925..c1b2c117b 100644 --- a/internal/super/flix_test.go +++ b/internal/super/flix_test.go @@ -1,13 +1,32 @@ +/* + * Flow CLI + * + * Copyright 2024 Flow Foundation, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package super import ( "testing" + "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/config" "github.com/onflow/flow-cli/flowkit/tests" - "github.com/spf13/afero" - "github.com/stretchr/testify/assert" ) func Test_flix_generate(t *testing.T) { @@ -56,5 +75,11 @@ func Test_flix_generate(t *testing.T) { cs := GetDeployedContracts(state) assert.Equal(t, 1, len(cs)) + networkContract := cs[tests.ContractHelloString.Name] + assert.NotNil(t, networkContract) + addr := networkContract["emulator"] + acct, err := state.Accounts().ByName("emulator-account") + assert.NoError(t, err) + assert.Equal(t, acct.Address.String(), addr) }