Skip to content

Commit

Permalink
fix: add back icmd and print stderr regardless if cmd fails
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Sep 11, 2023
1 parent 284ba59 commit 1720e4e
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package test
import (
"crypto/sha256"
"fmt"
"log"
"os"
"os/exec"
"strings"
"testing"

Expand All @@ -15,6 +15,7 @@ import (
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/require"
"gotest.tools/v3/icmd"
)

func TestCLIContractInstall(t *testing.T) {
Expand Down Expand Up @@ -67,35 +68,32 @@ func TestCLIContractDeploy(t *testing.T) {

func TestCLIContractDeployAndInvoke(t *testing.T) {
NewCLITest(t)
output := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath, true)
output := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath)
contractID := strings.TrimSpace(output)
output = runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- hello --world=world", contractID))
require.Contains(t, output, `["Hello","world"]`)
}

func runSuccessfulCLICmd(t *testing.T, cmd string, rest ...bool) string {
output, err := runCLICmd(t, cmd, len(rest) > 0 && rest[0])
require.NoError(t, err, output)
return output
func runSuccessfulCLICmd(t *testing.T, cmd string) string {
res := runCLICommand(t, cmd)
stderr := res.Stderr()
require.NoError(t, res.Error, stderr)
l := log.New(os.Stderr, "", 1)
l.Println(stderr)
return res.Stdout()
}

func runCLICmd(t *testing.T, cmd string, stdoutOnly bool) (string, error) {
func runCLICommand(t *testing.T, cmd string) *icmd.Result {
args := []string{"run", "-q", "--", "--vv"}
parsedArgs, err := shlex.Split(cmd)
require.NoError(t, err)
require.NoError(t, err, cmd)
args = append(args, parsedArgs...)
c := exec.Command("cargo", args...)
c := icmd.Command("cargo", args...)
c.Env = append(os.Environ(),
fmt.Sprintf("SOROBAN_RPC_URL=http://localhost:%d/", sorobanRPCPort),
fmt.Sprintf("SOROBAN_NETWORK_PASSPHRASE=%s", StandaloneNetworkPassphrase),
)
if stdoutOnly {
output, err := c.Output()
return string(output), err
} else {
output, err := c.CombinedOutput()
return string(output), err
}
return icmd.RunCmd(c)
}

func NewCLITest(t *testing.T) *Test {
Expand Down

0 comments on commit 1720e4e

Please sign in to comment.