-
Notifications
You must be signed in to change notification settings - Fork 66
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
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
1d60627
remove version check in 1.0
ianthpun 7d3d289
add is_validated
ianthpun a2d3035
udpate
ianthpun 63d7a04
update
ianthpun 8c088cf
update
ianthpun 4b97f0f
add missing contracts
ianthpun bce8af0
update
ianthpun 6d8a8d3
resolve comments
ianthpun fe3475d
some cleanup
ianthpun 13d1582
fix slices
ianthpun 71b47a9
linter
ianthpun 1d5fd8e
update test
ianthpun aaa6383
update
ianthpun 63af7e6
update
ianthpun 8a16b1b
update
ianthpun 1ce938b
move to util
ianthpun 682c562
update
ianthpun 427d845
update
ianthpun 7a740d4
update
ianthpun 0e92418
udpate
ianthpun 339fb21
udpate
ianthpun 49fd909
Merge branch 'feature/stable-cadence' into ianthpun/validation-check
ianthpun 0ee2665
regenerate
ianthpun 87af46c
renegrate mocks
ianthpun 6e0170d
impoirt error
ianthpun e394a79
udpate
ianthpun 805e3a0
update
ianthpun bedd97b
formatter
ianthpun f607271
test fix
ianthpun 7796bac
fix test
ianthpun 93e569f
update
ianthpun 44d166d
update
ianthpun b518842
update
ianthpun 87cb8d0
update
ianthpun 37b40f1
update
ianthpun a49a609
fix skip
ianthpun 751ebbc
update
ianthpun 3a34a57
update
ianthpun a10057f
udpated with link check
ianthpun 026e718
update with better wording
ianthpun 21c87fb
update wording
ianthpun 25e164b
format
ianthpun f923a07
update state check
ianthpun 765164b
update
ianthpun a5f50ca
Update
ianthpun 98d0884
Merge branch 'feature/stable-cadence' into ianthpun/validation-check
ianthpun 67810c3
update copy
ianthpun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"io" | ||
"path" | ||
"regexp" | ||
"slices" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -111,6 +112,85 @@ func newValidator(repoService GitHubRepositoriesService, network config.Network, | |
} | ||
} | ||
|
||
func (v *validator) getContractUpdateStatuses(contractNames ...string) ([]contractUpdateStatus, *time.Time, error) { | ||
var contractUpdateStatuses []contractUpdateStatus | ||
err := checkNetwork(v.network) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
v.logger.StartProgress("Checking if contracts has been validated") | ||
ianthpun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defer v.logger.StopProgress() | ||
|
||
addressToContractName := make(map[string]string) | ||
for _, contractName := range contractNames { | ||
addr, err := getAddressByContractName(v.state, contractName, v.network) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
addressToContractName[addr.HexWithPrefix()] = contractName | ||
} | ||
|
||
// Get last migration report | ||
report, ts, err := v.getLatestMigrationReport(v.network) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
// Get all the contract statuses from the report | ||
statuses, err := v.fetchAndParseReport(report.GetPath()) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
// Get the validation result related to the contract | ||
var foundAddresses []string | ||
for _, s := range statuses { | ||
if addressToContractName[s.AccountAddress] == s.ContractName { | ||
contractUpdateStatuses = append(contractUpdateStatuses, s) | ||
foundAddresses = append(foundAddresses, s.AccountAddress) | ||
} | ||
} | ||
|
||
for addr, contractName := range addressToContractName { | ||
var missingContractErr error | ||
if !slices.Contains(foundAddresses, addr) { | ||
builder := strings.Builder{} | ||
builder.WriteString("some contracts do not appear to have been a part of any emulated migrations yet, please ensure that it has been staged & wait for the next emulated migration (last migration report was at ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalize "Some" |
||
builder.WriteString(ts.Format(time.RFC3339)) | ||
builder.WriteString(")\n\n") | ||
builder.WriteString(" - Account: ") | ||
builder.WriteString(addr) | ||
builder.WriteString("\n - Contract: ") | ||
builder.WriteString(contractName) | ||
builder.WriteString("\n - Network: ") | ||
builder.WriteString(v.network.Name) | ||
|
||
missingContractErr = fmt.Errorf(builder.String()) | ||
} | ||
|
||
if missingContractErr != nil { | ||
return nil, nil, missingContractErr | ||
} | ||
} | ||
|
||
return contractUpdateStatuses, ts, nil | ||
} | ||
|
||
func (v *validator) getContractValidationStatus(network config.Network, address string, contractName string) (contractUpdateStatus, *time.Time, error) { | ||
status, ts, err := v.getContractUpdateStatuses(contractName) | ||
if err != nil { | ||
return contractUpdateStatus{}, nil, err | ||
} | ||
|
||
if len(status) != 1 { | ||
return contractUpdateStatus{}, nil, fmt.Errorf("failed to find contract in last migration report") | ||
} | ||
|
||
return status[0], ts, nil | ||
|
||
} | ||
|
||
func (v *validator) validate(contractName string) (validationResult, error) { | ||
err := checkNetwork(v.network) | ||
if err != nil { | ||
|
@@ -144,48 +224,6 @@ func (v *validator) validate(contractName string) (validationResult, error) { | |
}, nil | ||
} | ||
|
||
func (v *validator) getContractValidationStatus(network config.Network, address string, contractName string) (contractUpdateStatus, *time.Time, error) { | ||
// Get last migration report | ||
report, timestamp, err := v.getLatestMigrationReport(network) | ||
if err != nil { | ||
return contractUpdateStatus{}, nil, err | ||
} | ||
|
||
// Get all the contract statuses from the report | ||
statuses, err := v.fetchAndParseReport(report.GetPath()) | ||
if err != nil { | ||
return contractUpdateStatus{}, nil, err | ||
} | ||
|
||
// Get the validation result related to the contract | ||
var status *contractUpdateStatus | ||
for _, s := range statuses { | ||
if s.ContractName == contractName && s.AccountAddress == address { | ||
status = &s | ||
break | ||
} | ||
} | ||
|
||
// Throw error if contract was not part of the last migration | ||
if status == nil { | ||
builder := strings.Builder{} | ||
builder.WriteString("the contract does not appear to have been a part of any emulated migrations yet, please ensure that it has been staged & wait for the next emulated migration (last migration report was at ") | ||
builder.WriteString(timestamp.Format(time.RFC3339)) | ||
builder.WriteString(")\n\n") | ||
|
||
builder.WriteString(" - Account: ") | ||
builder.WriteString(address) | ||
builder.WriteString("\n - Contract: ") | ||
builder.WriteString(contractName) | ||
builder.WriteString("\n - Network: ") | ||
builder.WriteString(network.Name) | ||
|
||
return contractUpdateStatus{}, nil, fmt.Errorf(builder.String()) | ||
} | ||
|
||
return *status, timestamp, nil | ||
} | ||
|
||
func (v *validator) getLatestMigrationReport(network config.Network) (*github.RepositoryContent, *time.Time, error) { | ||
// Get the content of the migration reports folder | ||
_, folderContent, _, err := v.repoService.GetContents( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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