diff --git a/e2e/tests/help.feature b/e2e/tests/help.feature index 156ec5194..7d0867f99 100644 --- a/e2e/tests/help.feature +++ b/e2e/tests/help.feature @@ -1,7 +1,7 @@ Feature: Root Namespace - Scenario: User Needs Help - Given the user has the pocketd binary installed - When the user runs the command "help" - Then the user should be able to see standard output containing "Available Commands" - And the pocketd binary should exit without error \ No newline at end of file + Scenario: User Needs Help + Given the user has the pocketd binary installed + When the user runs the command "help" + Then the user should be able to see standard output containing "Available Commands" + And the pocketd binary should exit without error diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index fe831a507..e1284417a 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -22,8 +22,8 @@ var ( ) func init() { - addrRe = regexp.MustCompile(`address: (\S+)\s+name: (\S+)`) - amountRe = regexp.MustCompile(`amount: "(.+?)"\s+denom: upokt`) + addrRe = regexp.MustCompile(`address:\s+(\S+)\s+name:\s+(\S+)`) + amountRe = regexp.MustCompile(`amount:\s+"(.+?)"\s+denom:\s+upokt`) } type suite struct { @@ -123,6 +123,85 @@ func (s *suite) TheUserShouldWaitForSeconds(dur int64) { time.Sleep(time.Duration(dur) * time.Second) } +func (s *suite) TheUserStakesAWithUpoktFromTheAccount(actorType string, amount int64, accName string) { + args := []string{ + "tx", + actorType, + fmt.Sprintf("stake-%s", actorType), + fmt.Sprintf("%dupokt", amount), + "--from", + accName, + keyRingFlag, + "-y", + } + res, err := s.pocketd.RunCommandOnHost("", args...) + if err != nil { + s.Fatalf("error staking %s: %s", actorType, err) + } + s.pocketd.result = res +} + +func (s *suite) TheUserUnstakesAFromTheAccount(actorType string, accName string) { + args := []string{ + "tx", + actorType, + fmt.Sprintf("unstake-%s", actorType), + "--from", + accName, + keyRingFlag, + "-y", + } + res, err := s.pocketd.RunCommandOnHost("", args...) + if err != nil { + s.Fatalf("error unstaking %s: %s", actorType, err) + } + s.pocketd.result = res +} + +func (s *suite) TheForAccountIsNotStaked(actorType, accName string) { + found, _ := s.getStakedAmount(actorType, accName) + if found { + s.Fatalf("account %s should not be staked", accName) + } +} + +func (s *suite) TheForAccountIsStakedWithUpokt(actorType, accName string, amount int64) { + found, stakeAmount := s.getStakedAmount(actorType, accName) + if !found { + s.Fatalf("account %s should be staked", accName) + } + if int64(stakeAmount) != amount { + s.Fatalf("account %s stake amount is not %d", accName, amount) + } +} + +func (s *suite) getStakedAmount(actorType, accName string) (bool, int) { + s.Helper() + args := []string{ + "query", + actorType, + fmt.Sprintf("list-%s", actorType), + } + res, err := s.pocketd.RunCommandOnHost("", args...) + if err != nil { + s.Fatalf("error getting %s: %s", actorType, err) + } + s.pocketd.result = res + found := strings.Contains(res.Stdout, accNameToAddrMap[accName]) + amount := 0 + if found { + escapedAddress := regexp.QuoteMeta(accNameToAddrMap[accName]) + stakedAmountRe := regexp.MustCompile(`address: ` + escapedAddress + `\s+stake:\s+amount: "(\d+)"`) + matches := stakedAmountRe.FindStringSubmatch(res.Stdout) + if len(matches) < 2 { + s.Fatalf("no stake amount found for %s", accName) + } + amount, err = strconv.Atoi(matches[1]) + require.NoError(s, err) + } + return found, amount +} + func (s *suite) buildAddrMap() { s.Helper() res, err := s.pocketd.RunCommand( @@ -131,6 +210,7 @@ func (s *suite) buildAddrMap() { if err != nil { s.Fatalf("error getting keys: %s", err) } + s.pocketd.result = res matches := addrRe.FindAllStringSubmatch(res.Stdout, -1) for _, match := range matches { name := match[2] diff --git a/e2e/tests/send.feature b/e2e/tests/send.feature index dc5fc4504..4df818bf2 100644 --- a/e2e/tests/send.feature +++ b/e2e/tests/send.feature @@ -1,13 +1,13 @@ Feature: Tx Namespace - Scenario: User can send uPOKT - Given the user has the pocketd binary installed - And the account "app1" has a balance greater than "1000" uPOKT - And an account exists for "app2" - When the user sends "1000" uPOKT from account "app1" to account "app2" - Then the user should be able to see standard output containing "txhash:" - And the user should be able to see standard output containing "code: 0" - And the pocketd binary should exit without error - And the user should wait for "5" seconds - And the account balance of "app1" should be "1000" uPOKT "less" than before - And the account balance of "app2" should be "1000" uPOKT "more" than before + Scenario: User can send uPOKT + Given the user has the pocketd binary installed + And the account "app1" has a balance greater than "1000" uPOKT + And an account exists for "app2" + When the user sends "1000" uPOKT from account "app1" to account "app2" + Then the user should be able to see standard output containing "txhash:" + And the user should be able to see standard output containing "code: 0" + And the pocketd binary should exit without error + And the user should wait for "5" seconds + And the account balance of "app1" should be "1000" uPOKT "less" than before + And the account balance of "app2" should be "1000" uPOKT "more" than before diff --git a/e2e/tests/stake.feature b/e2e/tests/stake.feature new file mode 100644 index 000000000..1171ef3d6 --- /dev/null +++ b/e2e/tests/stake.feature @@ -0,0 +1,25 @@ +Feature: Stake Namespaces + + Scenario: User can stake a Gateway + Given the user has the pocketd binary installed + And the "gateway" for account "gateway1" is not staked + And the account "gateway1" has a balance greater than "1000" uPOKT + When the user stakes a "gateway" with "1000" uPOKT from the account "gateway1" + Then the user should be able to see standard output containing "txhash:" + And the user should be able to see standard output containing "code: 0" + And the pocketd binary should exit without error + And the user should wait for "5" seconds + And the "gateway" for account "gateway1" is staked with "1000" uPOKT + And the account balance of "gateway1" should be "1000" uPOKT "less" than before + + Scenario: User can unstake a Gateway + Given the user has the pocketd binary installed + And the "gateway" for account "gateway1" is staked with "1000" uPOKT + And an account exists for "gateway1" + When the user unstakes a "gateway" from the account "gateway1" + Then the user should be able to see standard output containing "txhash:" + And the user should be able to see standard output containing "code: 0" + And the pocketd binary should exit without error + And the user should wait for "5" seconds + And the "gateway" for account "gateway1" is not staked + And the account balance of "gateway1" should be "1000" uPOKT "more" than before