2020-07-20 05:30:12 -07:00
|
|
|
package testdata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2020-08-28 09:02:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
2021-03-04 13:31:42 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
|
2020-11-09 08:01:43 -08:00
|
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
2020-07-20 09:05:01 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-03-04 13:31:42 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-20 05:30:12 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// KeyTestPubAddr generates a new secp256k1 keypair.
|
2020-11-09 08:01:43 -08:00
|
|
|
func KeyTestPubAddr() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
|
2020-07-20 05:30:12 -07:00
|
|
|
key := secp256k1.GenPrivKey()
|
|
|
|
pub := key.PubKey()
|
|
|
|
addr := sdk.AccAddress(pub.Address())
|
|
|
|
return key, pub, addr
|
|
|
|
}
|
|
|
|
|
2021-03-04 13:31:42 -08:00
|
|
|
// KeyTestPubAddr generates a new secp256r1 keypair.
|
|
|
|
func KeyTestPubAddrSecp256R1(require *require.Assertions) (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
|
|
|
|
key, err := secp256r1.GenPrivKey()
|
|
|
|
require.NoError(err)
|
|
|
|
pub := key.PubKey()
|
|
|
|
addr := sdk.AccAddress(pub.Address())
|
|
|
|
return key, pub, addr
|
|
|
|
}
|
|
|
|
|
2020-07-20 05:30:12 -07:00
|
|
|
// 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 }
|
2020-10-15 06:07:59 -07:00
|
|
|
|
|
|
|
var _ sdk.MsgRequest = &MsgCreateDog{}
|
|
|
|
|
|
|
|
func (msg *MsgCreateDog) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} }
|
|
|
|
func (msg *MsgCreateDog) ValidateBasic() error { return nil }
|
|
|
|
|
|
|
|
func NewServiceMsgCreateDog(msg *MsgCreateDog) sdk.Msg {
|
|
|
|
return sdk.ServiceMsg{
|
|
|
|
MethodName: "/testdata.Msg/CreateDog",
|
|
|
|
Request: msg,
|
|
|
|
}
|
|
|
|
}
|