Skip to content

Commit

Permalink
Merge pull request #1331 from onflow/add-prefix-address
Browse files Browse the repository at this point in the history
add prefix to user address when processing flow.json
  • Loading branch information
bthaile authored Jan 10, 2024
2 parents c47cf7a + 63dc7aa commit fd943af
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 7 additions & 4 deletions internal/super/flix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/spf13/cobra"
)

type flixFlags struct {
Expand Down Expand Up @@ -283,24 +284,26 @@ 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
}
for _, c := range contracts {
if _, ok := allContracts[c.Name]; !ok {
allContracts[c.Name] = make(flixkit.NetworkAddressMap)
}
allContracts[c.Name][network] = 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] = addr
allContracts[name][network] = address.Hex()
}
}
return allContracts
Expand Down
85 changes: 85 additions & 0 deletions internal/super/flix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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"
)

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))
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)

}

0 comments on commit fd943af

Please sign in to comment.