2020-07-20 05:30:12 -07:00
|
|
|
package testdata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
2020-07-20 09:05:01 -07:00
|
|
|
|
2020-08-28 09:02:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
2020-07-20 09:05:01 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-07-20 05:30:12 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// KeyTestPubAddr generates a new secp256k1 keypair.
|
|
|
|
func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
|
|
|
|
key := secp256k1.GenPrivKey()
|
|
|
|
pub := key.PubKey()
|
|
|
|
addr := sdk.AccAddress(pub.Address())
|
|
|
|
return key, pub, addr
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTestFeeAmount is a test fee amount.
|
|
|
|
func NewTestFeeAmount() sdk.Coins {
|
|
|
|
return sdk.NewCoins(sdk.NewInt64Coin("atom", 150))
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTestGasLimit is a test fee gas limit.
|
|
|
|
func NewTestGasLimit() uint64 {
|
|
|
|
return 100000
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTestMsg creates a message for testing with the given signers.
|
|
|
|
func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg {
|
2020-09-25 03:25:37 -07:00
|
|
|
var accAddresses []string
|
|
|
|
|
|
|
|
for _, addr := range addrs {
|
|
|
|
accAddresses = append(accAddresses, addr.String())
|
|
|
|
}
|
|
|
|
|
2020-07-20 05:30:12 -07:00
|
|
|
return &TestMsg{
|
2020-09-25 03:25:37 -07:00
|
|
|
Signers: accAddresses,
|
2020-07-20 05:30:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ sdk.Msg = (*TestMsg)(nil)
|
|
|
|
|
|
|
|
func (msg *TestMsg) Route() string { return "TestMsg" }
|
|
|
|
func (msg *TestMsg) Type() string { return "Test message" }
|
|
|
|
func (msg *TestMsg) GetSignBytes() []byte {
|
|
|
|
bz, err := json.Marshal(msg.Signers)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return sdk.MustSortJSON(bz)
|
|
|
|
}
|
2020-09-25 03:25:37 -07:00
|
|
|
func (msg *TestMsg) GetSigners() []sdk.AccAddress {
|
|
|
|
addrs := make([]sdk.AccAddress, len(msg.Signers))
|
|
|
|
for i, in := range msg.Signers {
|
2020-09-29 04:29:10 -07:00
|
|
|
addr, err := sdk.AccAddressFromBech32(in)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:25:37 -07:00
|
|
|
addrs[i] = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
return addrs
|
|
|
|
}
|
2020-07-20 05:30:12 -07:00
|
|
|
func (msg *TestMsg) ValidateBasic() error { return nil }
|