From 89f151cb075e957b5ef4ffe7f763bea307adb922 Mon Sep 17 00:00:00 2001 From: BigBoss Date: Sun, 30 Jul 2023 14:27:57 -0400 Subject: [PATCH] e2e checkpoint --- e2e/tests/steps_init_test.go | 62 +++++++++++++++++ e2e/tests/steps_upgrade_test.go | 110 +++++++++++++++++-------------- e2e/tests/upgrade.feature | 18 +++-- e2e/tests/upgrade_cancel.feature | 28 ++++---- 4 files changed, 147 insertions(+), 71 deletions(-) diff --git a/e2e/tests/steps_init_test.go b/e2e/tests/steps_init_test.go index ee680cd82..01bc652b2 100644 --- a/e2e/tests/steps_init_test.go +++ b/e2e/tests/steps_init_test.go @@ -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() { @@ -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) } diff --git a/e2e/tests/steps_upgrade_test.go b/e2e/tests/steps_upgrade_test.go index 665a01b60..303189957 100644 --- a/e2e/tests/steps_upgrade_test.go +++ b/e2e/tests/steps_upgrade_test.go @@ -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") } diff --git a/e2e/tests/upgrade.feature b/e2e/tests/upgrade.feature index fcb5c4d4a..06adeba40 100644 --- a/e2e/tests/upgrade.feature +++ b/e2e/tests/upgrade.feature @@ -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 " - Then the user should be able to see standard output containing "" - 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 "" 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 diff --git a/e2e/tests/upgrade_cancel.feature b/e2e/tests/upgrade_cancel.feature index c27bb5faf..5fbb80a38 100644 --- a/e2e/tests/upgrade_cancel.feature +++ b/e2e/tests/upgrade_cancel.feature @@ -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