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

add contract migration check on all calls #1547

Merged
merged 47 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1d60627
remove version check in 1.0
ianthpun Apr 26, 2024
7d3d289
add is_validated
ianthpun May 6, 2024
a2d3035
udpate
ianthpun May 6, 2024
63d7a04
update
ianthpun May 6, 2024
8c088cf
update
ianthpun May 6, 2024
4b97f0f
add missing contracts
ianthpun May 7, 2024
bce8af0
update
ianthpun May 7, 2024
6d8a8d3
resolve comments
ianthpun May 7, 2024
fe3475d
some cleanup
ianthpun May 7, 2024
13d1582
fix slices
ianthpun May 7, 2024
71b47a9
linter
ianthpun May 7, 2024
1d5fd8e
update test
ianthpun May 7, 2024
aaa6383
update
ianthpun May 8, 2024
63af7e6
update
ianthpun May 8, 2024
8a16b1b
update
ianthpun May 8, 2024
1ce938b
move to util
ianthpun May 9, 2024
682c562
update
ianthpun May 9, 2024
427d845
update
ianthpun May 9, 2024
7a740d4
update
ianthpun May 9, 2024
0e92418
udpate
ianthpun May 9, 2024
339fb21
udpate
ianthpun May 9, 2024
49fd909
Merge branch 'feature/stable-cadence' into ianthpun/validation-check
ianthpun May 9, 2024
0ee2665
regenerate
ianthpun May 9, 2024
87af46c
renegrate mocks
ianthpun May 9, 2024
6e0170d
impoirt error
ianthpun May 9, 2024
e394a79
udpate
ianthpun May 9, 2024
805e3a0
update
ianthpun May 9, 2024
bedd97b
formatter
ianthpun May 9, 2024
f607271
test fix
ianthpun May 9, 2024
7796bac
fix test
ianthpun May 9, 2024
93e569f
update
ianthpun May 10, 2024
44d166d
update
ianthpun May 10, 2024
b518842
update
ianthpun May 10, 2024
87cb8d0
update
ianthpun May 10, 2024
37b40f1
update
ianthpun May 13, 2024
a49a609
fix skip
ianthpun May 13, 2024
751ebbc
update
ianthpun May 13, 2024
3a34a57
update
ianthpun May 14, 2024
a10057f
udpated with link check
ianthpun May 14, 2024
026e718
update with better wording
ianthpun May 14, 2024
21c87fb
update wording
ianthpun May 14, 2024
25e164b
format
ianthpun May 15, 2024
f923a07
update state check
ianthpun May 15, 2024
765164b
update
ianthpun May 16, 2024
a5f50ca
Update
ianthpun May 16, 2024
98d0884
Merge branch 'feature/stable-cadence' into ianthpun/validation-check
ianthpun May 16, 2024
67810c3
update copy
ianthpun May 16, 2024
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
32 changes: 0 additions & 32 deletions cmd/flow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
package main

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"

"github.com/onflow/flow-cli/internal/accounts"
Expand Down Expand Up @@ -57,34 +53,6 @@ func main() {
var cmd = &cobra.Command{
Use: "flow",
TraverseChildren: true,
// Messaging for Cadence 1.0 upgrade
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleting this since this feature branch is literally 1.0

PersistentPreRun: func(cmd *cobra.Command, args []string) {
outputFlag, _ := cmd.Flags().GetString("output")
// If output is set to json, do not append any message
if outputFlag != "json" {

width := 80
url := "https://cadence-lang.org/docs/cadence_migration_guide"

// Function to center text within a given width
centerText := func(text string, width int) string {
space := (width - len(text)) / 2
if space < 0 {
space = 0
}
return fmt.Sprintf("%s%s%s", strings.Repeat(" ", space), text, strings.Repeat(" ", space))
}

fmt.Fprintln(os.Stderr, strings.Repeat("+", width))
fmt.Fprintln(os.Stderr, centerText("⚠ Upgrade to Cadence 1.0", width))
fmt.Fprintln(os.Stderr, centerText("The Crescendo network upgrade, including Cadence 1.0, is coming soon.", width))
fmt.Fprintln(os.Stderr, centerText("You may need to update your existing contracts to support this change.", width))
fmt.Fprintln(os.Stderr, centerText("Please visit our migration guide here:", width))
fmt.Fprintln(os.Stderr, centerText(url, width))
fmt.Fprintln(os.Stderr, strings.Repeat("+", width))

}
},
}

// quick commands
Expand Down
61 changes: 51 additions & 10 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

"github.com/dukex/mixpanel"
"github.com/getsentry/sentry-go"
"github.com/google/go-github/github"
"github.com/spf13/afero"
"github.com/spf13/cobra"

Expand All @@ -45,6 +46,7 @@
"github.com/onflow/flowkit/v2/output"

"github.com/onflow/flow-cli/build"
"github.com/onflow/flow-cli/internal/migrate/validator"
"github.com/onflow/flow-cli/internal/settings"
"github.com/onflow/flow-cli/internal/util"
)
Expand Down Expand Up @@ -126,6 +128,11 @@
checkVersion(logger)
}

// check contract migrations if flag is set
if !Flags.SkipContractMigrationCheck {
checkContractMigrations(state, logger, flow)
ianthpun marked this conversation as resolved.
Show resolved Hide resolved
}

// record command usage
wg := sync.WaitGroup{}
go UsageMetrics(c.Cmd, &wg)
Expand Down Expand Up @@ -424,14 +431,48 @@

// GlobalFlags contains all global flags definitions.
type GlobalFlags struct {
Filter string
Format string
Save string
Host string
HostNetworkKey string
Log string
Network string
Yes bool
ConfigPaths []string
SkipVersionCheck bool
Filter string
Format string
Save string
Host string
HostNetworkKey string
Log string
Network string
Yes bool
ConfigPaths []string
SkipVersionCheck bool
SkipContractMigrationCheck bool
}


Check failure on line 447 in internal/command/command.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/onflow/flow-cli (goimports)
const migrationDataURL = "https://github.com/onflow/cadence/tree/master/migrations_data"

func checkContractMigrations(state *flowkit.State, logger output.Logger, flow flowkit.Services) {
contractStatuses, err := validator.NewValidator(github.NewClient(nil).Repositories, flow.Network(), state, logger).GetContractStatuses()
if err != nil {
logger.Error(fmt.Sprintf("failed to validate contracts: %s", err))
ianthpun marked this conversation as resolved.
Show resolved Hide resolved
return
}

var failedContracts []validator.ContractUpdateStatus

for _, contract := range contractStatuses {
if contract.IsFailure() {
failedContracts = append(failedContracts, contract)
}
}

if len(failedContracts) > 0 {
fmt.Fprintf(
os.Stderr, "\n%s Contract Migration Check: %d contract(s) failed to migrate\n", output.ErrorEmoji(), len(failedContracts),
)
for _, contract := range failedContracts {
fmt.Fprintf(os.Stderr, " - Account: %s\n - Contract: %s\n\n", contract.AccountAddress, contract.ContractName)
}

fmt.Fprintf(
os.Stderr, "\n Please visit %s for more information about the failure. \n", migrationDataURL,
)
}
return
}
5 changes: 3 additions & 2 deletions internal/migrate/get_staged_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/onflow/flow-cli/internal/command"
"github.com/onflow/flow-cli/internal/scripts"
"github.com/onflow/flow-cli/internal/util"
)

var getStagedCodeflags struct{}
Expand All @@ -53,13 +54,13 @@ func getStagedCode(
flow flowkit.Services,
state *flowkit.State,
) (command.Result, error) {
err := checkNetwork(flow.Network())
err := util.CheckNetwork(flow.Network())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved CheckNetwork and GetAddressByContractName to util package

if err != nil {
return nil, err
}

contractName := args[0]
addr, err := getAddressByContractName(state, contractName, flow.Network())
addr, err := util.GetAddressByContractName(state, contractName, flow.Network())
if err != nil {
return nil, fmt.Errorf("error getting address by contract name: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/migrate/is_staged.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/onflow/flow-cli/internal/command"
"github.com/onflow/flow-cli/internal/scripts"
"github.com/onflow/flow-cli/internal/util"
)

var isStagedflags struct{}
Expand All @@ -52,13 +53,13 @@ func isStaged(
flow flowkit.Services,
state *flowkit.State,
) (command.Result, error) {
err := checkNetwork(flow.Network())
err := util.CheckNetwork(flow.Network())
if err != nil {
return nil, err
}

contractName := args[0]
addr, err := getAddressByContractName(state, contractName, flow.Network())
addr, err := util.GetAddressByContractName(state, contractName, flow.Network())
if err != nil {
return nil, fmt.Errorf("error getting address by contract name: %w", err)
}
Expand Down
Loading
Loading