[tests] DRY

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-07-19 08:06:57 +02:00
parent 18ce58f139
commit a97d1126f9
No known key found for this signature in database
GPG Key ID: E0A8F9AD733499A7
4 changed files with 31 additions and 23 deletions

View File

@ -25,9 +25,6 @@ import (
"sigs.k8s.io/yaml"
)
// Queryable pubkey for TestNotarizeAsset
const mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
// E2ETestSuite struct definition of asset suite
type E2ETestSuite struct {
suite.Suite
@ -49,7 +46,7 @@ func (s *E2ETestSuite) SetupSuite() {
val := s.network.Validators[0]
kb := val.ClientCtx.Keyring
account, err := kb.NewAccount("machine", mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
s.Require().NoError(err)
pk, err := account.GetPubKey()
pkHex := hex.EncodeToString(pk.Bytes())
@ -59,11 +56,11 @@ func (s *E2ETestSuite) SetupSuite() {
// sending funds to machine to initialize account on chain
args := []string{
"node0",
val.Moniker,
addr.String(),
"1000stake",
sample.Amount,
"--yes",
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
}
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
s.Require().NoError(err)

View File

@ -14,20 +14,20 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
baseURL := val.APIAddress
// Query Sequence Number
k, err := val.ClientCtx.Keyring.Key("machine")
k, err := val.ClientCtx.Keyring.Key(sample.Name)
s.Require().NoError(err)
addr, err := k.GetAddress()
s.Require().NoError(err)
// Create Attest Machine TX
machine := sample.Machine("machine", pubKey)
machine := sample.Machine(sample.Name, sample.PubKey)
msg := machinetypes.MsgAttestMachine{
Creator: addr.String(),
Machine: &machine,
}
txBytes, err := testutil.PrepareTx(val, &msg, "machine")
txBytes, err := testutil.PrepareTx(val, &msg, sample.Name)
s.Require().NoError(err)
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
@ -42,7 +42,7 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
s.Require().NoError(err)
s.Require().Equal(uint32(0), txRes.TxResponse.Code)
queryMachineUrl := fmt.Sprintf("%s/planetmint-go/machine/get_machine_by_public_key/%s", baseURL, pubKey)
queryMachineUrl := fmt.Sprintf("%s/planetmint-go/machine/get_machine_by_public_key/%s", baseURL, sample.PubKey)
queryMachineRes, err := testutil.GetRequest(queryMachineUrl)
s.Require().NoError(err)

View File

@ -17,10 +17,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Queryable pubkey for TestAttestMachine
const pubKey = "AjKN6HiWucu1EBwzX0ACnkvomJiLRwq79oPxoLMY1zRw"
const mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
// E2ETestSuite struct definition of machine suite
type E2ETestSuite struct {
suite.Suite
@ -42,18 +38,18 @@ func (s *E2ETestSuite) SetupSuite() {
val := s.network.Validators[0]
kb := val.ClientCtx.Keyring
account, err := kb.NewAccount("machine", mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
s.Require().NoError(err)
addr, _ := account.GetAddress()
// sending funds to machine to initialize account on chain
args := []string{
"node0",
val.Moniker,
addr.String(),
"1000stake",
sample.Amount,
"--yes",
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
}
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
s.Require().NoError(err)
@ -70,14 +66,14 @@ func (s *E2ETestSuite) TearDownSuite() {
func (s *E2ETestSuite) TestAttestMachine() {
val := s.network.Validators[0]
machine := sample.Machine("machine", pubKey)
machine := sample.Machine(sample.Name, sample.PubKey)
machineJSON, err := json.Marshal(&machine)
s.Require().NoError(err)
args := []string{
fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID),
fmt.Sprintf("--%s=%s", flags.FlagFrom, "machine"),
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
fmt.Sprintf("--%s=%s", flags.FlagFrom, sample.Name),
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
"--yes",
string(machineJSON),
}
@ -88,7 +84,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
s.Require().NoError(s.network.WaitForNextBlock())
args = []string{
pubKey,
sample.PubKey,
}
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)

View File

@ -11,6 +11,21 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Mnemonic sample mnemonic to use in tests
const Mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
// PubKey corresponding public key to sample mnemonic
const PubKey = "AjKN6HiWucu1EBwzX0ACnkvomJiLRwq79oPxoLMY1zRw"
// Name is the name of the sample machine to use in tests
const Name = "machine"
// Amount is the amount to transfer to the machine account
const Amount = "1000stake"
// Fees is the amount of fees to use in tests
const Fees = "2stake"
// KeyPair returns a sample private / public keypair
func KeyPair() (string, string) {
secret := "Don't tell anybody"