Skip to content

Commit

Permalink
e2e checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBigBoss committed Jul 30, 2023
1 parent 539cc04 commit 89f151c
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 71 deletions.
62 changes: 62 additions & 0 deletions e2e/tests/steps_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type rootSuite struct {
// TECHDEBT: Rename `validator` to something more appropriate
validator *validatorPod
// validatorA maps to suffix ID 001 of the kube pod that we use as our control agent
// Pending transaction hashes are stored here.
pendingTxs []string
}

func (s *rootSuite) Before() {
Expand Down Expand Up @@ -87,6 +89,66 @@ func (s *rootSuite) TheUserRunsTheCommand(cmd string) {
s.validator.result = res
}

// TheNetworkCommitsTheTransactions is a step that triggers the next view and verifies that all pending transactions are committed
func (s *rootSuite) TheNetworkCommitsTheTransactions() {
if len(s.pendingTxs) == 0 {
e2eLogger.Info().Msg("no pending transactions to commit")
require.FailNow(s, "no pending transactions to commit")
}

// trigger the next view
_, err := s.validator.RunCommand("dui", "TriggerNextView")
require.NoError(s, err)

// Make a copy of the pendingTxs slice to keep track of the transactions still pending
remainingTxs := make([]string, len(s.pendingTxs))
copy(remainingTxs, s.pendingTxs)

// wait up to 10 iterations for all txs to be committed
for i := 0; i < 10; i++ {
// List to hold the transactions that are still pending after this iteration
stillPendingTxs := []string{}

// Iterate over each remaining transaction
for _, tx := range remainingTxs {

// check if the tx has been committed
res, err := s.validator.RunCommand("query", "tx", tx)
if err != nil {
e2eLogger.Info().Msgf("failed to query tx %s: %s", tx, err.Error())
stillPendingTxs = append(stillPendingTxs, tx)
continue
}
if strings.Contains(res.Stdout, "Key not found") {
e2eLogger.Info().Msgf("tx %s not found", tx)
stillPendingTxs = append(stillPendingTxs, tx)
continue
}
if strings.Contains(res.Stdout, "tx failed") {
e2eLogger.Info().Msgf("tx %s failed", tx)
stillPendingTxs = append(stillPendingTxs, tx)
continue
}
if strings.Contains(res.Stdout, "tx succeeded") {
e2eLogger.Info().Msgf("tx %s succeeded", tx)
// No need to add the transaction to stillPendingTxs
}
}

// Update the remainingTxs slice
remainingTxs = stillPendingTxs

if len(remainingTxs) == 0 {
break
}
}

if len(remainingTxs) > 0 {
e2eLogger.Info().Msg("Not all pending transactions committed after 10 attempts")
require.FailNow(s, "Not all pending transactions committed after 10 attempts")
}
}

func (s *rootSuite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) {
require.Contains(s, s.validator.result.Stdout, arg1)
}
Expand Down
110 changes: 60 additions & 50 deletions e2e/tests/steps_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,70 @@

package e2e

import "github.com/stretchr/testify/require"

func (s *rootSuite) UserHasAValidCancelUpgradeCommandWithSignerAndVersion() {
require.Fail(s, "implement me")
}

func (s *rootSuite) UserHasACancelUpgradeCommandForAPastVersion() {
require.Fail(s, "implement me")
import (
"fmt"
"strings"

"github.com/blang/semver/v4"
"github.com/pokt-network/pocket/rpc"
"github.com/pokt-network/pocket/runtime/test_artifacts"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/json"
)

func (s *rootSuite) TheUserSubmitsAMajorProtocolUpgrade() {
res, err := s.validator.RunCommand("query", "upgrade")
require.NoError(s, err)

var qur rpc.QueryUpgradeResponse
// TECHDEBT: cli outputs debug logs so scan for our answer
for _, line := range strings.Split(res.Stdout, "\n") {
// parse into QueryUpgradeResponse
err = json.Unmarshal([]byte(line), &qur)
if err == nil && qur.Version != "" {
break
}
}
require.NoError(s, err)

// submit a major protocol upgrade
newVersion, err := semver.Parse(qur.Version)
require.NoError(s, err)
newVersion.Major++
res, err = s.validator.RunCommand("gov", "upgrade", test_artifacts.DefaultParams().AclOwner, newVersion.String(), fmt.Sprint(qur.Height+1))
require.NoError(s, err)

// TECHBDEBT: cli outputs debug logs last non-blank line is our answer
var lines = strings.Split(res.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)
s.validator.result = res
}

func (s *rootSuite) TheSystemShouldCancelTheScheduledUpgrade() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSpecifiedUpgradeIsScheduledAndNotYetActivated() {
require.Fail(s, "implement me")
}
func (s *rootSuite) TheSystemReachesTheUpgradeHeight() {
for {
res, err := s.validator.RunCommand("query", "upgrade")
require.NoError(s, err)

func (s *rootSuite) TheSystemShouldRejectTheCommandAsItCannotCancelAPastUpgrade() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldValidateTheCommand() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldSuccessfullyAcceptTheCommand() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldReturnTheUpdatedProtocolVersion() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldRejectTheCommandDueToInvalidInput() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldRejectTheCommandDueToTooManyVersionsAhead() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldReturnTheSuccessfulCancellationStatus() {
require.Fail(s, "implement me")
}

func (s *rootSuite) TheSystemShouldApplyTheProtocolUpgradeAtTheSpecifiedActivationHeight() {
require.Fail(s, "implement me")
}
// parse into QueryUpgradeResponse
var qur rpc.QueryUpgradeResponse
err = json.Unmarshal([]byte(res.Stdout), &qur)
require.NoError(s, err)

func (s *rootSuite) TheUserHasAnInvalidUpgradeProtocolCommand() {
require.Fail(s, "implement me")
if qur.Height > 0 {
break
}
}
}

func (s *rootSuite) TheUserHasAUpgradeProtocolCommandWithTooManyVersionsJump() {
require.Fail(s, "implement me")
func (s *rootSuite) TheUserShouldBeAbleToSeeTheNewVersion() {
panic("PENDING")
}
18 changes: 11 additions & 7 deletions e2e/tests/upgrade.feature
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
Feature: Upgrade Protocol

Scenario: ACL Owner Successfully Submits a Protocol Upgrade Using CLI
Given the user is an ACL Owner
When the user runs the command "gov upgrade <owner> <version> <height>"
Then the user should be able to see standard output containing "<stdout>"
When the user runs the command "gov query upgrade"
Scenario: User can query the current protocol version using CLI
Given the user runs the command "query upgrade"
Then the user should be able to see standard output containing "<version>"

Examples:
| owner | version | height | stdout |
| da034209758b78eaea06dd99c07909ab54c99b45 | 2.0.0 | 100 | 2.0.0 |
| version |
| 1.0.0 |

Scenario: ACL Owner Successfully Submits a Protocol Upgrade Using CLI
Given 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

Scenario: ACL Owner Submits an Invalid Protocol Upgrade Using CLI
Given the user is an ACL Owner
Expand Down
28 changes: 14 additions & 14 deletions e2e/tests/upgrade_cancel.feature
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Feature: Upgrade Protocol Cancel
# Feature: Upgrade Protocol Cancel

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"
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 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"
# 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"
Then the system should validate the command
And the system should reject the command as it cannot cancel a past upgrade
# 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"
# Then the system should validate the command
# And the system should reject the command as it cannot cancel a past upgrade

0 comments on commit 89f151c

Please sign in to comment.