Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
abdb4a4
[WIP] Cadence 1.0 Multi-Staging
jribbink May 7, 2024
b57aa40
cleanup
jribbink May 7, 2024
3c43bc7
fixup
jribbink May 7, 2024
91cecfc
report missing dependencies error
jribbink May 7, 2024
68f473d
cleanup small issues
jribbink May 7, 2024
dbae112
stash
jribbink May 8, 2024
3bcfdb0
fix tests
jribbink May 8, 2024
c48c080
fix header
jribbink May 8, 2024
fef9bcd
better filtering
jribbink May 8, 2024
2f015e8
cleanup tests
jribbink May 8, 2024
6d66ea9
enhance validator tests
jribbink May 8, 2024
cc86157
testing overhaul & bug fixes
jribbink May 8, 2024
1eb11fd
enhance tests
jribbink May 8, 2024
bad8568
update tests
jribbink May 9, 2024
2bcad5f
Refactor & improve result printing
jribbink May 9, 2024
0c76d38
UI improvements
jribbink May 9, 2024
31d1f16
fix nil deref bug
jribbink May 9, 2024
aea7cdc
cleanup checker cache
jribbink May 9, 2024
e5975cf
add txid
jribbink May 9, 2024
38171a4
fix test regressions
jribbink May 10, 2024
8ed698b
stash
jribbink May 10, 2024
6052d40
refactor stagedContractUpdate
jribbink May 10, 2024
46eb618
Fix goimports
jribbink May 10, 2024
6a07a84
fix import
jribbink May 10, 2024
6ea9a59
fix goimport-ed
jribbink May 10, 2024
4e794c4
fix windows tests
jribbink May 10, 2024
5b7d8d7
fix tests
jribbink May 10, 2024
fd9bd6c
update formatting
jribbink May 10, 2024
c5e77ff
fix test
jribbink May 10, 2024
a6871a7
wip
jribbink May 10, 2024
62a0140
refactor deps & add upstream errors
jribbink May 10, 2024
4ddaecf
Fix flakey tests
jribbink May 10, 2024
6b92528
fix windows
jribbink May 10, 2024
b80f3f7
make pluralize helper
jribbink May 10, 2024
4b5cba8
use GenericBoolPrompt
jribbink May 10, 2024
99fd85c
Add cyclic import checking
jribbink May 11, 2024
5812e1b
fix account access
jribbink May 13, 2024
f9f03ea
Fix crypto checker import
jribbink May 14, 2024
30c96d2
cleanup missing dependencies messaging
jribbink May 14, 2024
922530b
export fields for json
jribbink May 14, 2024
0acecef
skip staging unchanged contracts
jribbink May 14, 2024
9f21a3e
add more assertions to tests
jribbink May 14, 2024
734f8cc
fix deps
jribbink May 14, 2024
12ee3b4
fix getstagedcode test
jribbink May 14, 2024
114c4b7
address feedback
jribbink May 14, 2024
3929d24
rename to checkAllStaged
jribbink May 14, 2024
e11a9d1
rename test file & add limit
jribbink May 14, 2024
7c0c2ae
change wording
jribbink May 15, 2024
f2d3513
Merge branch 'feature/stable-cadence' into jribbink/stage-all
jribbink May 15, 2024
718d898
fix flowkit args
jribbink May 15, 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
20 changes: 11 additions & 9 deletions internal/cadence/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/onflow/flowkit/v2/output"

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

type lintFlagsCollection struct{}
Expand Down Expand Up @@ -202,7 +203,15 @@ func (r *lintResult) String() string {

total := numErrors + numWarnings
if total > 0 {
sb.WriteString(aurora.Colorize(fmt.Sprintf("%d %s (%d %s, %d %s)", total, pluralize("problem", total), numErrors, pluralize("error", numErrors), numWarnings, pluralize("warning", numWarnings)), color).String())
sb.WriteString(aurora.Colorize(fmt.Sprintf(
"%d %s (%d %s, %d %s)",
total,
util.Pluralize("problem", total),
numErrors,
util.Pluralize("error", numErrors),
numWarnings,
util.Pluralize("warning", numWarnings),
), color).String())
} else {
sb.WriteString(aurora.Green("Lint passed").String())
}
Expand All @@ -219,18 +228,11 @@ func (r *lintResult) Oneliner() string {
total := numErrors + numWarnings

if total > 0 {
return fmt.Sprintf("%d %s (%d %s, %d %s)", total, pluralize("problem", total), numErrors, pluralize("error", numErrors), numWarnings, pluralize("warning", numWarnings))
return fmt.Sprintf("%d %s (%d %s, %d %s)", total, util.Pluralize("problem", total), numErrors, util.Pluralize("error", numErrors), numWarnings, util.Pluralize("warning", numWarnings))
}
return "Lint passed"
}

func (r *lintResult) ExitCode() int {
return r.exitCode
}

func pluralize(word string, count int) string {
if count == 1 {
return word
}
return word + "s"
}
45 changes: 39 additions & 6 deletions internal/migrate/get_staged_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"

"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/flowkit/v2"
"github.com/onflow/flowkit/v2/output"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -64,24 +65,56 @@ func getStagedCode(
return nil, fmt.Errorf("error getting address by contract name: %w", err)
}

cName, err := cadence.NewString(contractName)
location := common.NewAddressLocation(nil, common.Address(addr), contractName)
code, err := getStagedContractCode(context.Background(), flow, location)
if err != nil {
return nil, fmt.Errorf("error creating cadence string: %w", err)
return nil, err
}

// If the contract is not staged, return nil
if code == nil {
return scripts.NewScriptResult(cadence.NewOptional(nil)), nil
}

caddr := cadence.NewAddress(addr)
return scripts.NewScriptResult(cadence.NewOptional(cadence.String(code))), nil
Comment thread
jribbink marked this conversation as resolved.
}

func getStagedContractCode(
ctx context.Context,
flow flowkit.Services,
location common.AddressLocation,
) ([]byte, error) {
cAddr := cadence.BytesToAddress(location.Address.Bytes())
cName, err := cadence.NewString(location.Name)
if err != nil {
return nil, fmt.Errorf("failed to get cadence string from contract name: %w", err)
}

value, err := flow.ExecuteScript(
context.Background(),
flowkit.Script{
Code: templates.GenerateGetStagedContractCodeScript(MigrationContractStagingAddress(flow.Network().Name)),
Args: []cadence.Value{caddr, cName},
Args: []cadence.Value{cAddr, cName},
},
flowkit.LatestScriptQuery,
)
if err != nil {
return nil, fmt.Errorf("error executing script: %w", err)
return nil, err
}

optValue, ok := value.(cadence.Optional)
if !ok {
return nil, fmt.Errorf("invalid script return value type: %T", value)
}

if optValue.Value == nil {
return nil, nil
}

strValue, ok := optValue.Value.(cadence.String)
if !ok {
return nil, fmt.Errorf("invalid script return value type: %T", value)
}

return scripts.NewScriptResult(value), nil
return []byte(strValue), nil
}
2 changes: 1 addition & 1 deletion internal/migrate/get_staged_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func Test_GetStagedCode(t *testing.T) {

contractAddr := cadence.NewAddress(account.Address)
assert.Equal(t, contractAddr.String(), actualContractAddressArg.String())
}).Return(cadence.NewString(string(testContract.Source)))
}).Return(cadence.NewOptional(cadence.String(testContract.Source)), nil)

result, err := getStagedCode(
[]string{testContract.Name},
Expand Down
8 changes: 4 additions & 4 deletions internal/migrate/is_validated.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ import (
"github.com/onflow/flow-cli/internal/util"
)

//go:generate mockery --name GitHubRepositoriesService --output ./mocks --case underscore
type GitHubRepositoriesService interface {
//go:generate mockery --name gitHubRepositoriesService --inpackage --testonly --case underscore
type gitHubRepositoriesService interface {
GetContents(ctx context.Context, owner string, repo string, path string, opt *github.RepositoryContentGetOptions) (fileContent *github.RepositoryContent, directoryContent []*github.RepositoryContent, resp *github.Response, err error)
DownloadContents(ctx context.Context, owner string, repo string, filepath string, opt *github.RepositoryContentGetOptions) (io.ReadCloser, error)
}

type validator struct {
repoService GitHubRepositoriesService
repoService gitHubRepositoriesService
state *flowkit.State
logger output.Logger
network config.Network
Expand Down Expand Up @@ -102,7 +102,7 @@ func isValidated(
return v.validate(contractName)
}

func newValidator(repoService GitHubRepositoriesService, network config.Network, state *flowkit.State, logger output.Logger) *validator {
func newValidator(repoService gitHubRepositoriesService, network config.Network, state *flowkit.State, logger output.Logger) *validator {
return &validator{
repoService: repoService,
state: state,
Expand Down
3 changes: 1 addition & 2 deletions internal/migrate/is_validated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/stretchr/testify/require"

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

Expand All @@ -47,7 +46,7 @@ func Test_IsValidated(t *testing.T) {
// Helper function to test the isValidated function
// with all of the necessary mocks
testIsValidatedWithStatuses := func(statuses []contractUpdateStatus) (command.Result, error) {
mockClient := mocks.NewGitHubRepositoriesService(t)
mockClient := newMockGitHubRepositoriesService(t)

// mock github file download
data, _ := json.Marshal(statuses)
Expand Down
2 changes: 1 addition & 1 deletion internal/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func init() {
getStagedCodeCommand.AddToParent(Cmd)
IsStagedCommand.AddToParent(Cmd)
listStagedContractsCommand.AddToParent(Cmd)
stageContractCommand.AddToParent(Cmd)
stageCommand.AddToParent(Cmd)
unstageContractCommand.AddToParent(Cmd)
stateCommand.AddToParent(Cmd)
IsValidatedCommand.AddToParent(Cmd)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions internal/migrate/mock_staging_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions internal/migrate/mock_staging_validator_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading