Skip to content

Commit

Permalink
add upgrade validations, update e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBigBoss committed Aug 6, 2023
1 parent 5c07b9d commit 7b337ed
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 123 deletions.
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Feature: Example Namespace
Scenario: User Needs Example
Given the user has a node
When the user runs the command "example"
When the user runs the command with no error "example"
Then the user should be able to see standard output containing "Example Output"
And the pocket client should have exited without error
```
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/account.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Node Namespace

Scenario: User Wants Help Using The Node Command
Given the user has a node
When the user runs the command "Validator help"
When the user runs the command with no error "Validator help"
Then the user should be able to see standard output containing "Available Commands"
And the node should have exited without error

Expand Down
18 changes: 12 additions & 6 deletions e2e/tests/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,24 @@ func (n *nodePod) RunCommandOnHost(rpcUrl string, args ...string) (*commandResul
"--remote_cli_url=" + rpcUrl,
}
args = append(base, args...)

e2eLogger.Debug().Msgf("Running command: kubectl %s", strings.Join(args, " "))
cmdStr := strings.Join(args, " ")
e2eLogger.Debug().Msgf("Running command: kubectl %s", cmdStr)

cmd := exec.Command("kubectl", args...)
r := &commandResult{}
out, err := cmd.Output()
if err != nil {
return nil, err
}
r.Stdout = string(out)
n.result = r
// IMPROVE: make targetPodName configurable
n.targetPodName = targetDevClientPod
return r, nil

if err != nil {
// unpack ExitError to get stderr
if exitErr, ok := err.(*exec.ExitError); ok {
r.Stderr = string(exitErr.Stderr)
}
return r, err
}
e2eLogger.Debug().Str("stderr", r.Stderr).Err(err).Msgf("command result: %s", string(out))
return r, err
}
8 changes: 4 additions & 4 deletions e2e/tests/query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Feature: Query Namespace

Scenario: User Wants Help Using The Query Command
Given the user has a node
When the user runs the command "Query help"
When the user runs the command with no error "Query help"
Then the user should be able to see standard output containing "Available Commands"
And the node should have exited without error

Scenario: User Wants To See The Block At Current Height
Scenario: User Wants To See The Block At Current Height
Given the user has a node
When the user runs the command "Query Block"
When the user runs the command with no error "Query Block"
Then the user should be able to see standard output containing "state_hash"
And the node should have exited without error
And the node should have exited without error
4 changes: 2 additions & 2 deletions e2e/tests/root.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Feature: Root Namespace

Scenario: User Needs Help
Given the user has a node
When the user runs the command "help"
When the user runs the command with no error "help"
Then the user should be able to see standard output containing "Available Commands"
And the node should have exited without error
And the node should have exited without error
44 changes: 39 additions & 5 deletions e2e/tests/steps_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,52 @@ func TestFeatures(t *testing.T) {

func (s *rootSuite) TheUserHasANode() {
res, err := s.node.RunCommand("help")
require.NoErrorf(s, err, res.Stderr)
require.NoErrorf(s, err, res.Stderr, "failed to run command: 'help' due to error: %s", err)
s.node.result = res
}

func (s *rootSuite) TheNodeShouldHaveExitedWithoutError() {
require.NoError(s, s.node.result.Err)
}

func (s *rootSuite) TheUserRunsTheCommand(cmd string) {
func (s *rootSuite) TheUserRunsTheCommandWithNoError(cmd string) {
cmds := strings.Split(cmd, " ")
res, err := s.node.RunCommand(cmds...)
require.NoError(s, err)
require.NoError(s, err, fmt.Sprintf("failed to run command: '%s' due to error: %s", cmd, err))
s.node.result = res
}

func (s *rootSuite) TheUserRunsTheCommandWithError(cmd string) {
cmds := strings.Split(cmd, " ")
res, err := s.node.RunCommand(cmds...)
require.Error(s, err, fmt.Sprintf("expected error running command: '%s'", cmd))
s.node.result = res
}

func (s *rootSuite) TheUserSubmitsTheTransaction(cmd string) {
s.TheUserRunsTheCommandWithNoError(cmd)
// TECHBDEBT: cli outputs debug logs last non-blank line is our answer
var lines = strings.Split(s.node.result.Stdout, "\n")
var answer string
for i := len(lines) - 1; i >= 0; i-- {
if lines[i] != "" {
answer = lines[i]
break
}
}
// ensure it is a valid sha256 hash
require.Regexp(s, "^([a-f0-9]{64})$", answer, "invalid tx hash")
s.pendingTxs = append(s.pendingTxs, answer)
}

func (s *rootSuite) TheUserQueriesTheTransaction(cmd string) {
if len(s.pendingTxs) == 0 {
e2eLogger.Info().Msg("no pending transactions to query")
require.FailNow(s, "no pending transactions to query")
}
s.TheUserRunsTheCommandWithNoError("query tx " + s.pendingTxs[len(s.pendingTxs)-1])
}

// TheDeveloperRunsTheCommand is similar to TheUserRunsTheCommand but exclusive to `Debug` commands
func (s *rootSuite) TheDeveloperRunsTheCommand(cmd string) {
cmds := strings.Split(cmd, " ")
Expand Down Expand Up @@ -199,8 +230,7 @@ func (s *rootSuite) ShouldBeAtHeight(pod string, height int64) {

res := getResponseFromStdout[expectedResponse](s, resRaw.Stdout, validate)
require.NotNil(s, res)

require.Equal(s, height, *res.Height)
require.Equal(s, height, *res.Height, "height mismatch")
}

// TheNetworkCommitsTheTransactions is a step that triggers the next view and verifies that all pending transactions are committed
Expand Down Expand Up @@ -263,6 +293,10 @@ func (s *rootSuite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string
require.Contains(s, s.node.result.Stdout, arg1)
}

func (s *rootSuite) TheUserShouldBeAbleToSeeStandardErrorContaining(arg1 string) {
require.Contains(s, s.node.result.Stderr, arg1)
}

func (s *rootSuite) TheUserStakesTheirValidatorWithAmountUpokt(amount int64) {
privKey := s.getPrivateKey(validatorA)
s.stakeValidator(privKey, fmt.Sprintf("%d", amount))
Expand Down
71 changes: 0 additions & 71 deletions e2e/tests/steps_upgrade_test.go

This file was deleted.

54 changes: 35 additions & 19 deletions e2e/tests/upgrade.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Upgrade Protocol
Given the network is at genesis
And the network has "4" actors of type "Validator"
And "validator-001" should be at height "0"
And the user runs the command "query upgrade"
And the user runs the command with no error "query upgrade"
Then the user should be able to see standard output containing "<version>"

Examples:
Expand All @@ -16,33 +16,49 @@ Feature: Upgrade Protocol
And the network has "4" actors of type "Validator"
And "validator-001" should be at height "0"
And the user is an ACL Owner
When the user submits a major protocol upgrade
And the network commits the transactions
When the user runs the command "query upgrade"
Then the user should be able to see the new version
When the user runs the command with no error "gov upgrade da034209758b78eaea06dd99c07909ab54c99b45 2.0.0 1"
And the developer runs the command "TriggerView"
And the developer waits for "1000" milliseconds
And "validator-001" should be at height "1"
And the user runs the command with no error "query upgrade"
Then the user should be able to see standard output containing "2.0.0"

Scenario: ACL Owner Submits an Invalid Protocol Upgrade Using CLI
Scenario: ACL Owner Fails Basic Validation Submitting a Protocol Upgrade Using CLI
Given the network is at genesis
And the network has "4" actors of type "Validator"
And "validator-001" should be at height "0"
And the user is an ACL Owner
And the user has an invalid upgrade protocol command
When the user runs the command "gov upgrade"
Then the system should validate the command
And the system should reject the command due to invalid input
When the user runs the command with error "<cmd>"
Then the user should be able to see standard error containing "<error>"

Scenario: ACL Owner Submits a Protocol Upgrade with Too Many Versions Ahead Using CLI
Examples:
| cmd | error |
| gov upgrade da034209758b78eaea06dd99c07909ab54c99b45 2.0.zxcv 1 | CODE: 149, ERROR: the protocol version is invalid |
| gov upgrade da034209758b78eaea06dd99c07909ab54c99b45 new 1 | CODE: 149, ERROR: the protocol version is invalid |

Scenario: ACL Owner Fails Consensus Validation Submitting a Protocol Upgrade Using CLI
Given the network is at genesis
And the network has "4" actors of type "Validator"
And "validator-001" should be at height "0"
And the user is an ACL Owner
And the user has a upgrade protocol command with too many versions jump
When the user runs the command "gov upgrade"
Then the system should validate the command
And the system should reject the command due to too many versions ahead
When the user runs the command with no error "<cmd>"
And the developer runs the command "TriggerView"
And the developer waits for "1000" milliseconds
And "validator-001" should be at height "1"
And the user queries the transaction
Then the user should be able to see standard output containing "<error>"

Examples:
| cmd | error |
| gov upgrade da034209758b78eaea06dd99c07909ab54c99b45 3.0.0 1 | CODE: 149, ERROR: the protocol version is invalid |
| gov upgrade da034209758b78eaea06dd99c07909ab54c99b45 2.0.0 0 | CODE: 149, ERROR: the protocol version is invalid |

Scenario: Regular User Submits an Upgrade Using CLI
Scenario: Regular User Fails Consensus Validation Submits an Upgrade Using CLI
Given the network is at genesis
And the network has "4" actors of type "Validator"
When the user submits a major protocol upgrade
When the user runs the command "gov upgrade 100.0.0 100000"
Then the user should be able to see standard output containing "invalid upgrade proposal: sender is not authorized to submit upgrade proposals"
When the user submits the transaction "gov upgrade 00101f2ff54811e84df2d767c661f57a06349b7e 2.0.0 1"
And the developer runs the command "TriggerView"
And the developer waits for "1000" milliseconds
And "validator-001" should be at height "1"
And the user queries the transaction
Then the user should be able to see standard output containing "CODE: 3, ERROR: the signer of the message is not a proper candidate: da034209758b78eaea06dd99c07909ab54c99b45"
4 changes: 2 additions & 2 deletions e2e/tests/upgrade_cancel.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# Scenario: User Successfully Cancels a Scheduled Upgrade using CLI
# Given the user is an ACL Owner
# And the specified upgrade is scheduled and not yet activated
# When the user runs the command "gov cancel_upgrade"
# When the user runs the command with no error "gov cancel_upgrade"
# Then the system should cancel the scheduled upgrade
# When user runs the command "gov query upgrade"
# Then the system should return the successful cancellation status

# Scenario: User Attempts to Cancel a Past Upgrade using CLI
# Given the user is an ACL Owner
# And the user has a cancel upgrade command for a past version
# When the user runs the command "gov cancel_upgrade"
# When the user runs the command with no error "gov cancel_upgrade"
# Then the system should validate the command
# And the system should reject the command as it cannot cancel a past upgrade
2 changes: 1 addition & 1 deletion e2e/tests/validator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Validator Namespace

Scenario: User Wants Help Using The Validator Command
Given the user has a node
When the user runs the command "Validator help"
When the user runs the command with no error "Validator help"
Then the user should be able to see standard output containing "Available Commands"
And the node should have exited without error

Expand Down
8 changes: 8 additions & 0 deletions utility/unit_of_work/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,11 @@ func (u *baseUtilityUnitOfWork) getStringParam(paramName string) (string, coreTy
}
return value, nil
}

func (u *baseUtilityUnitOfWork) getMessageUpgradeSignerCandidates(msg *typesUtil.MessageUpgrade) ([][]byte, coreTypes.Error) {

Check failure on line 274 in utility/unit_of_work/gov.go

View workflow job for this annotation

GitHub Actions / lint

`(*baseUtilityUnitOfWork).getMessageUpgradeSignerCandidates` - `msg` is unused (unparam)
owner, err := u.getStringParam(typesUtil.AclOwner)
if err != nil {
return nil, coreTypes.ErrGetParam(typesUtil.AclOwner, err)
}
return [][]byte{[]byte(owner)}, nil
}
4 changes: 4 additions & 0 deletions utility/unit_of_work/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (u *baseUtilityUnitOfWork) validateTxMessage(tx *coreTypes.Transaction) (ty
if !ok {
return nil, coreTypes.ErrDecodeMessage(fmt.Errorf("not a supported message type"))
}
// Validate the message the same as the client is expected to
if err := msg.ValidateBasic(); err != nil {
return nil, err
}
return msg, nil
}

Expand Down
Loading

0 comments on commit 7b337ed

Please sign in to comment.