mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
commit
a766379c39
14
tests/e2e/machine/cli_test.go
Normal file
14
tests/e2e/machine/cli_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"planetmint-go/testutil/network"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
cfg := network.DefaultConfig()
|
||||
cfg.NumValidators = 1
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
81
tests/e2e/machine/suite.go
Normal file
81
tests/e2e/machine/suite.go
Normal file
@ -0,0 +1,81 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
clitestutil "planetmint-go/testutil/cli"
|
||||
"planetmint-go/testutil/network"
|
||||
machinecli "planetmint-go/x/machine/client/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
|
||||
s.network = network.New(s.T())
|
||||
val := s.network.Validators[0]
|
||||
|
||||
kb := val.ClientCtx.Keyring
|
||||
account, _, err := kb.NewMnemonic("machine", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
s.Require().NoError(err)
|
||||
|
||||
addr, _ := account.GetAddress()
|
||||
|
||||
// sending funds to machine to initialize account on chain
|
||||
args := []string{
|
||||
"node0",
|
||||
addr.String(),
|
||||
"1000stake",
|
||||
"-y",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
|
||||
}
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestAttestMachine() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID),
|
||||
"{\"name\": \"machine\", \"ticker\": \"machine_ticker\", \"issued\": 1, \"amount\": 1000, \"precision\": 8, \"issuerPlanetmint\": \"A/ZrbETECRq5DNGJZ0aH0DjlV4Y1opMlRfGoEJH454eB\", \"issuerLiquid\": \"A/ZrbETECRq5DNGJZ0aH0DjlV4Y1opMlRfGoEJH454eB\", \"machineId\": \"A/ZrbETECRq5DNGJZ0aH0DjlV4Y1opMlRfGoEJH454eB\", \"metadata\": {\"additionalDataCID\": \"CID\", \"gps\": \"{'Latitude':'-48.876667','Longitude':'-123.393333'}\"}}",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, "machine"),
|
||||
"-y",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
|
||||
}
|
||||
|
||||
_, err := clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdAttestMachine(), args)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
args = []string{
|
||||
"A/ZrbETECRq5DNGJZ0aH0DjlV4Y1opMlRfGoEJH454eB",
|
||||
}
|
||||
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)
|
||||
s.Require().NoError(err)
|
||||
}
|
26
testutil/cli/cmd.go
Normal file
26
testutil/cli/cmd.go
Normal file
@ -0,0 +1,26 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"planetmint-go/testutil"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// ExecTestCLICmd builds the client context, mocks the output and executes the command.
|
||||
func ExecTestCLICmd(clientCtx client.Context, cmd *cobra.Command, extraArgs []string) (testutil.BufferWriter, error) {
|
||||
cmd.SetArgs(extraArgs)
|
||||
|
||||
_, out := testutil.ApplyMockIO(cmd)
|
||||
clientCtx = clientCtx.WithOutput(out)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
|
||||
if err := cmd.ExecuteContext(ctx); err != nil {
|
||||
return out, err
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
32
testutil/ioutil.go
Normal file
32
testutil/ioutil.go
Normal file
@ -0,0 +1,32 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type BufferReader interface {
|
||||
io.Reader
|
||||
Reset(string)
|
||||
}
|
||||
|
||||
type BufferWriter interface {
|
||||
io.Writer
|
||||
Reset()
|
||||
Bytes() []byte
|
||||
String() string
|
||||
}
|
||||
|
||||
func ApplyMockIO(c *cobra.Command) (BufferReader, BufferWriter) {
|
||||
mockIn := strings.NewReader("")
|
||||
mockOut := bytes.NewBufferString("")
|
||||
|
||||
c.SetIn(mockIn)
|
||||
c.SetOut(mockOut)
|
||||
c.SetErr(mockOut)
|
||||
|
||||
return mockIn, mockOut
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user