mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-28 00:42:30 +00:00
Split up e2e test suites to run separately (#256)
* refactor: Split up machine e2e test suites * refactor: move CreateAccount and FundAccount to testutil/e2e * refactor: add AttestMachine to testutil/e2e * refactor: split up asset e2e test suites * refactor: make use of testutil in e2e dao suite Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
99031fb857
commit
6bff8e835d
@ -14,3 +14,8 @@ func TestE2ETestSuite(t *testing.T) {
|
|||||||
cfg.NumValidators = 1
|
cfg.NumValidators = 1
|
||||||
suite.Run(t, NewE2ETestSuite(cfg))
|
suite.Run(t, NewE2ETestSuite(cfg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRESTMachineAttestationSuite(t *testing.T) {
|
||||||
|
cfg := network.DefaultConfig()
|
||||||
|
suite.Run(t, NewRestE2ETestSuite(cfg))
|
||||||
|
}
|
||||||
|
@ -3,16 +3,61 @@ package asset
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/planetmint/planetmint-go/config"
|
||||||
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
"github.com/planetmint/planetmint-go/testutil"
|
"github.com/planetmint/planetmint-go/testutil"
|
||||||
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
assettypes "github.com/planetmint/planetmint-go/x/asset/types"
|
assettypes "github.com/planetmint/planetmint-go/x/asset/types"
|
||||||
|
|
||||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RestE2ETestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
|
||||||
|
cfg network.Config
|
||||||
|
network *network.Network
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRestE2ETestSuite(cfg network.Config) *RestE2ETestSuite {
|
||||||
|
return &RestE2ETestSuite{cfg: cfg}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupSuite initializes asset E2ETestSuite
|
||||||
|
func (s *RestE2ETestSuite) SetupSuite() {
|
||||||
|
conf := config.GetConfig()
|
||||||
|
conf.FeeDenom = "stake"
|
||||||
|
|
||||||
|
s.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
|
s.network = network.New(s.T())
|
||||||
|
err := e2etestutil.AttestMachine(s.network, sample.Name, sample.Mnemonic, 0)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
val := s.network.Validators[0]
|
||||||
|
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
addr, _ := k.GetAddress()
|
||||||
|
|
||||||
|
clientCtx := val.ClientCtx.
|
||||||
|
WithFromAddress(addr).
|
||||||
|
WithFromName(sample.Name)
|
||||||
|
libConfig := lib.GetConfig()
|
||||||
|
libConfig.SetClientCtx(clientCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TearDownSuite clean up after testing
|
||||||
|
func (s *RestE2ETestSuite) TearDownSuite() {
|
||||||
|
s.T().Log("tearing down e2e test suite")
|
||||||
|
}
|
||||||
|
|
||||||
// TestNotarizeAssetREST notarizes asset over REST endpoint
|
// TestNotarizeAssetREST notarizes asset over REST endpoint
|
||||||
func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
func (s *RestE2ETestSuite) TestNotarizeAssetREST() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
// Create Msg
|
// Create Msg
|
||||||
|
@ -7,22 +7,13 @@ import (
|
|||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
|
|
||||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
assettypes "github.com/planetmint/planetmint-go/x/asset/types"
|
assettypes "github.com/planetmint/planetmint-go/x/asset/types"
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
pubKey string
|
|
||||||
prvKey string
|
|
||||||
)
|
|
||||||
|
|
||||||
// E2ETestSuite struct definition of asset suite
|
// E2ETestSuite struct definition of asset suite
|
||||||
type E2ETestSuite struct {
|
type E2ETestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
@ -44,58 +35,20 @@ func (s *E2ETestSuite) SetupSuite() {
|
|||||||
s.T().Log("setting up e2e test suite")
|
s.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
s.network = network.New(s.T())
|
s.network = network.New(s.T())
|
||||||
|
err := e2etestutil.AttestMachine(s.network, sample.Name, sample.Mnemonic, 0)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||||
kb := val.ClientCtx.Keyring
|
|
||||||
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sample.DefaultDerivationPath, hd.Secp256k1)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
addr, _ := account.GetAddress()
|
addr, _ := k.GetAddress()
|
||||||
|
|
||||||
// sending funds to machine to initialize account on chain
|
|
||||||
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
|
|
||||||
msg1 := banktypes.NewMsgSend(val.Address, addr, coin)
|
|
||||||
out, err := lib.BroadcastTxWithFileLock(val.Address, msg1)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
assert.Contains(s.T(), rawLog, "cosmos.bank.v1beta1.MsgSend")
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
|
|
||||||
prvKey, pubKey = sample.KeyPair()
|
|
||||||
|
|
||||||
ta := sample.TrustAnchor(pubKey)
|
|
||||||
msg2 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
|
||||||
out, err = lib.BroadcastTxWithFileLock(val.Address, msg2)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
_, err = clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
|
|
||||||
// name and address of private key with which to sign
|
|
||||||
clientCtx := val.ClientCtx.
|
clientCtx := val.ClientCtx.
|
||||||
WithFromAddress(addr).
|
WithFromAddress(addr).
|
||||||
WithFromName(sample.Name)
|
WithFromName(sample.Name)
|
||||||
libConfig := lib.GetConfig()
|
libConfig := lib.GetConfig()
|
||||||
libConfig.SetClientCtx(clientCtx)
|
libConfig.SetClientCtx(clientCtx)
|
||||||
|
|
||||||
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
|
||||||
msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
|
||||||
out, err = lib.BroadcastTxWithFileLock(addr, msg3)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
rawLog, err = clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgAttestMachine")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TearDownSuite clean up after testing
|
// TearDownSuite clean up after testing
|
||||||
|
@ -3,17 +3,11 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
||||||
"github.com/planetmint/planetmint-go/config"
|
"github.com/planetmint/planetmint-go/config"
|
||||||
"github.com/planetmint/planetmint-go/lib"
|
|
||||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
"github.com/planetmint/planetmint-go/testutil/network"
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
|
||||||
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -55,7 +49,8 @@ func (s *PopSelectionE2ETestSuite) SetupSuite() {
|
|||||||
|
|
||||||
// create 2 machines accounts
|
// create 2 machines accounts
|
||||||
for i, machine := range machines {
|
for i, machine := range machines {
|
||||||
s.attestMachine(machine.name, machine.mnemonic, i)
|
err := e2etestutil.AttestMachine(s.network, machine.name, machine.mnemonic, i)
|
||||||
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,45 +81,3 @@ func (s *PopSelectionE2ETestSuite) TestPopSelection() {
|
|||||||
assert.Contains(s.T(), out.String(), machines[0].address)
|
assert.Contains(s.T(), out.String(), machines[0].address)
|
||||||
assert.Contains(s.T(), out.String(), machines[1].address)
|
assert.Contains(s.T(), out.String(), machines[1].address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PopSelectionE2ETestSuite) attestMachine(name string, mnemonic string, num int) {
|
|
||||||
val := s.network.Validators[0]
|
|
||||||
|
|
||||||
kb := val.ClientCtx.Keyring
|
|
||||||
account, err := kb.NewAccount(name, mnemonic, keyring.DefaultBIP39Passphrase, sample.DefaultDerivationPath, hd.Secp256k1)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
addr, _ := account.GetAddress()
|
|
||||||
|
|
||||||
// sending funds to machine to initialize account on chain
|
|
||||||
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
|
|
||||||
sendMsg := banktypes.NewMsgSend(val.Address, addr, coin)
|
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, sendMsg)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
|
|
||||||
// register Ta
|
|
||||||
prvKey, pubKey := sample.KeyPair(num)
|
|
||||||
|
|
||||||
ta := sample.TrustAnchor(pubKey)
|
|
||||||
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
|
|
||||||
// name and address of private key with which to sign
|
|
||||||
clientCtx := val.ClientCtx.
|
|
||||||
WithFromAddress(addr).
|
|
||||||
WithFromName(name)
|
|
||||||
libConfig := lib.GetConfig()
|
|
||||||
libConfig.SetClientCtx(clientCtx)
|
|
||||||
|
|
||||||
machine := sample.Machine(name, pubKey, prvKey, addr.String())
|
|
||||||
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
|
||||||
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
|
|
||||||
// reset clientCtx to validator ctx
|
|
||||||
libConfig.SetClientCtx(val.ClientCtx)
|
|
||||||
}
|
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||||
"github.com/planetmint/planetmint-go/config"
|
"github.com/planetmint/planetmint-go/config"
|
||||||
"github.com/planetmint/planetmint-go/lib"
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
"github.com/planetmint/planetmint-go/testutil/network"
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
daocli "github.com/planetmint/planetmint-go/x/dao/client/cli"
|
||||||
@ -184,20 +184,12 @@ func (s *E2ETestSuite) TestMintToken() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// send mint token request from non mint address
|
// send mint token request from non mint address
|
||||||
kb := val.ClientCtx.Keyring
|
account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic)
|
||||||
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sample.DefaultDerivationPath, hd.Secp256k1)
|
s.Require().NoError(err)
|
||||||
|
err = e2etestutil.FundAccount(s.network, account)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
addr, _ := account.GetAddress()
|
addr, _ := account.GetAddress()
|
||||||
|
|
||||||
// sending funds to account to initialize on chain
|
|
||||||
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
|
|
||||||
msg2 := banktypes.NewMsgSend(val.Address, addr, coin)
|
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, msg2)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
|
|
||||||
msg1 = daotypes.NewMsgMintToken(addr.String(), &mintRequest)
|
msg1 = daotypes.NewMsgMintToken(addr.String(), &mintRequest)
|
||||||
out, err = lib.BroadcastTxWithFileLock(addr, msg1)
|
out, err = lib.BroadcastTxWithFileLock(addr, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -14,3 +14,8 @@ func TestE2ETestSuite(t *testing.T) {
|
|||||||
cfg.NumValidators = 1
|
cfg.NumValidators = 1
|
||||||
suite.Run(t, NewE2ETestSuite(cfg))
|
suite.Run(t, NewE2ETestSuite(cfg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRESTMachineAttestationSuite(t *testing.T) {
|
||||||
|
cfg := network.DefaultConfig()
|
||||||
|
suite.Run(t, NewRestE2ETestSuite(cfg))
|
||||||
|
}
|
||||||
|
@ -3,14 +3,49 @@ package machine
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/planetmint/planetmint-go/config"
|
||||||
"github.com/planetmint/planetmint-go/testutil"
|
"github.com/planetmint/planetmint-go/testutil"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
|
|
||||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *E2ETestSuite) TestAttestMachineREST() {
|
type RestE2ETestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
|
||||||
|
cfg network.Config
|
||||||
|
network *network.Network
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRestE2ETestSuite(cfg network.Config) *RestE2ETestSuite {
|
||||||
|
return &RestE2ETestSuite{cfg: cfg}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RestE2ETestSuite) SetupSuite() {
|
||||||
|
cfg := config.GetConfig()
|
||||||
|
cfg.FeeDenom = "stake"
|
||||||
|
|
||||||
|
s.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
|
s.network = network.New(s.T())
|
||||||
|
// create machine account for attestation
|
||||||
|
account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
err = e2etestutil.FundAccount(s.network, account)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TearDownSuite clean up after testing
|
||||||
|
func (s *RestE2ETestSuite) TearDownSuite() {
|
||||||
|
s.T().Log("tearing down e2e test suite")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RestE2ETestSuite) TestAttestMachineREST() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
baseURL := val.APIAddress
|
baseURL := val.APIAddress
|
||||||
|
|
||||||
@ -21,7 +56,7 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
|
|||||||
addr, err := k.GetAddress()
|
addr, err := k.GetAddress()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
prvKey, pubKey := sample.KeyPair(1)
|
prvKey, pubKey := sample.KeyPair()
|
||||||
|
|
||||||
// Register TA
|
// Register TA
|
||||||
ta := sample.TrustAnchor(pubKey)
|
ta := sample.TrustAnchor(pubKey)
|
||||||
|
@ -12,8 +12,8 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
"github.com/cosmos/cosmos-sdk/x/feegrant"
|
||||||
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -39,25 +39,11 @@ func (s *E2ETestSuite) SetupSuite() {
|
|||||||
s.T().Log("setting up e2e test suite")
|
s.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
s.network = network.New(s.T())
|
s.network = network.New(s.T())
|
||||||
val := s.network.Validators[0]
|
// create machine account for attestation
|
||||||
|
account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic)
|
||||||
kb := val.ClientCtx.Keyring
|
|
||||||
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sample.DefaultDerivationPath, hd.Secp256k1)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
err = e2etestutil.FundAccount(s.network, account)
|
||||||
addr, _ := account.GetAddress()
|
|
||||||
|
|
||||||
// sending funds to machine to initialize account on chain
|
|
||||||
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
|
|
||||||
msg := banktypes.NewMsgSend(val.Address, addr, coin)
|
|
||||||
out, err := lib.BroadcastTxWithFileLock(val.Address, msg)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
assert.Contains(s.T(), rawLog, "cosmos.bank.v1beta1.MsgSend")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TearDownSuite clean up after testing
|
// TearDownSuite clean up after testing
|
||||||
@ -116,8 +102,8 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
|||||||
func (s *E2ETestSuite) TestInvalidAttestMachine() {
|
func (s *E2ETestSuite) TestInvalidAttestMachine() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
// already used in REST test case
|
// already used in previous test case
|
||||||
prvKey, pubKey := sample.KeyPair(1)
|
prvKey, pubKey := sample.KeyPair()
|
||||||
|
|
||||||
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
118
testutil/e2e/e2e.go
Normal file
118
testutil/e2e/e2e.go
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
|
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateAccount(network *network.Network, name string, mnemonic string) (account *keyring.Record, err error) {
|
||||||
|
val := network.Validators[0]
|
||||||
|
|
||||||
|
kb := val.ClientCtx.Keyring
|
||||||
|
account, err = kb.NewAccount(name, mnemonic, keyring.DefaultBIP39Passphrase, sample.DefaultDerivationPath, hd.Secp256k1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return account, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func FundAccount(network *network.Network, account *keyring.Record) (err error) {
|
||||||
|
val := network.Validators[0]
|
||||||
|
|
||||||
|
addr, err := account.GetAddress()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// sending funds to account to initialize account on chain
|
||||||
|
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000)) // TODO: make denom dependent on cfg
|
||||||
|
msg := banktypes.NewMsgSend(val.Address, addr, coin)
|
||||||
|
out, err := lib.BroadcastTxWithFileLock(val.Address, msg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = network.WaitForNextBlock()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(rawLog, "cosmos.bank.v1beta1.MsgSend") {
|
||||||
|
err = errors.New("failed to fund account")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func AttestMachine(network *network.Network, name string, mnemonic string, num int) (err error) {
|
||||||
|
val := network.Validators[0]
|
||||||
|
|
||||||
|
account, err := CreateAccount(network, name, mnemonic)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = FundAccount(network, account)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// register Ta
|
||||||
|
prvKey, pubKey := sample.KeyPair(num)
|
||||||
|
|
||||||
|
ta := sample.TrustAnchor(pubKey)
|
||||||
|
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
|
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = network.WaitForNextBlock()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
addr, err := account.GetAddress()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// name and address of private key with which to sign
|
||||||
|
clientCtx := val.ClientCtx.
|
||||||
|
WithFromAddress(addr).
|
||||||
|
WithFromName(name)
|
||||||
|
libConfig := lib.GetConfig()
|
||||||
|
libConfig.SetClientCtx(clientCtx)
|
||||||
|
|
||||||
|
machine := sample.Machine(name, pubKey, prvKey, addr.String())
|
||||||
|
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
|
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = network.WaitForNextBlock()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset clientCtx to validator ctx
|
||||||
|
libConfig.SetClientCtx(val.ClientCtx)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user