-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[E2E] Add basics of the E2E suite (#62)
- Loading branch information
Showing
7 changed files
with
216 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/regen-network/gocuke" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var addrRe *regexp.Regexp | ||
|
||
func init() { | ||
addrRe = regexp.MustCompile(`address:\s+(pokt1\w+)`) | ||
} | ||
|
||
type suite struct { | ||
gocuke.TestingT | ||
pocketd *pocketdBin | ||
} | ||
|
||
func (s *suite) Before() { | ||
s.pocketd = new(pocketdBin) | ||
} | ||
|
||
// TestFeatures runs the e2e tests specified in any .features files in this directory | ||
// * This test suite assumes that a LocalNet is running | ||
func TestFeatures(t *testing.T) { | ||
gocuke.NewRunner(t, &suite{}).Path("*.feature").Run() | ||
} | ||
|
||
func (s *suite) TheUserHasThePocketdBinaryInstalled() { | ||
s.TheUserRunsTheCommand("help") | ||
} | ||
|
||
func (s *suite) ThePocketdBinaryShouldExitWithoutError() { | ||
require.NoError(s, s.pocketd.result.Err) | ||
} | ||
|
||
func (s *suite) TheUserRunsTheCommand(cmd string) { | ||
cmds := strings.Split(cmd, " ") | ||
res, err := s.pocketd.RunCommand(cmds...) | ||
s.pocketd.result = res | ||
if err != nil { | ||
s.Fatalf("error running command %s: %s", cmd, err) | ||
} | ||
} | ||
|
||
func (s *suite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) { | ||
if !strings.Contains(s.pocketd.result.Stdout, arg1) { | ||
s.Fatalf("stdout must contain %s", arg1) | ||
} | ||
} | ||
|
||
func (s *suite) TheUserSendsUpoktToAnotherAddress(amount int64) { | ||
addrs := s.getAddresses() | ||
args := []string{ | ||
"tx", | ||
"bank", | ||
"send", | ||
addrs[0], | ||
addrs[1], | ||
fmt.Sprintf("%dupokt", amount), | ||
"--keyring-backend", | ||
"test", | ||
"-y", | ||
} | ||
res, err := s.pocketd.RunCommandOnHost("", args...) | ||
if err != nil { | ||
s.Fatalf("error sending upokt: %s", err) | ||
} | ||
s.pocketd.result = res | ||
} | ||
|
||
func (s *suite) getAddresses() [2]string { | ||
var strs [2]string | ||
res, err := s.pocketd.RunCommand( | ||
"keys", "list", "--keyring-backend", "test", | ||
) | ||
if err != nil { | ||
s.Fatalf("error getting keys: %s", err) | ||
} | ||
matches := addrRe.FindAllStringSubmatch(res.Stdout, -1) | ||
if len(matches) >= 2 { | ||
strs[0] = matches[0][1] | ||
strs[1] = matches[len(matches)-1][1] | ||
} else { | ||
s.Fatalf("could not find two addresses in output: %s", res.Stdout) | ||
} | ||
return strs | ||
} |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
var ( | ||
// defaultRPCURL used by pocketdBin to run remote commands | ||
defaultRPCURL = os.Getenv("POCKET_NODE") | ||
// defaultRPCPort is the default RPC port that pocketd listens on | ||
defaultRPCPort = 36657 | ||
// defaultRPCHost is the default RPC host that pocketd listens on | ||
defaultRPCHost = "127.0.0.1" | ||
// defaultHome is the default home directory for pocketd | ||
defaultHome = os.Getenv("POCKETD_HOME") | ||
) | ||
|
||
func init() { | ||
if defaultRPCURL == "" { | ||
defaultRPCURL = fmt.Sprintf("tcp://%s:%d", defaultRPCHost, defaultRPCPort) | ||
} | ||
if defaultHome == "" { | ||
defaultHome = "./localnet/pocketd" | ||
} | ||
} | ||
|
||
// commandResult combines the stdout, stderr, and err of an operation | ||
type commandResult struct { | ||
Stdout string | ||
Stderr string | ||
Err error | ||
} | ||
|
||
// PocketClient is a single function interface for interacting with a node | ||
type PocketClient interface { | ||
RunCommand(...string) (*commandResult, error) | ||
RunCommandOnHost(string, ...string) (*commandResult, error) | ||
} | ||
|
||
// Ensure that pocketdBin struct fulfills PocketClient | ||
var _ PocketClient = &pocketdBin{} | ||
|
||
// pocketdBin holds the reults of the last command that was run | ||
type pocketdBin struct { | ||
result *commandResult // stores the result of the last command that was run | ||
} | ||
|
||
// RunCommand runs a command on the local machine using the pocketd binary | ||
func (p *pocketdBin) RunCommand(args ...string) (*commandResult, error) { | ||
return p.runCmd(args...) | ||
} | ||
|
||
// RunCommandOnHost runs a command on specified host with the given args | ||
func (p *pocketdBin) RunCommandOnHost(rpcUrl string, args ...string) (*commandResult, error) { | ||
if rpcUrl == "" { | ||
rpcUrl = defaultRPCURL | ||
} | ||
args = append(args, "--node", rpcUrl) | ||
return p.runCmd(args...) | ||
} | ||
|
||
// runCmd is a helper to run a command using the local pocketd binary with the flags provided | ||
func (p *pocketdBin) runCmd(args ...string) (*commandResult, error) { | ||
base := []string{"--home", defaultHome} | ||
args = append(base, args...) | ||
cmd := exec.Command("pocketd", args...) | ||
r := &commandResult{} | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return nil, err | ||
} | ||
r.Stdout = string(out) | ||
p.result = r | ||
return r, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: Tx Namespace | ||
|
||
Scenario: User can send uPOKT | ||
Given the user has the pocketd binary installed | ||
When the user sends 10000 uPOKT to another address | ||
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 |
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