<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #10243 Charge the per-byte fee for the key length as for the values in gas meter --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
package testdata
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
)
|
|
|
|
// KeyTestPubAddr generates a new secp256k1 keypair.
|
|
func KeyTestPubAddr() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
|
|
key := secp256k1.GenPrivKey()
|
|
pub := key.PubKey()
|
|
addr := sdk.AccAddress(pub.Address())
|
|
return key, pub, addr
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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 200000
|
|
}
|
|
|
|
// NewTestMsg creates a message for testing with the given signers.
|
|
func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg {
|
|
var accAddresses []string
|
|
|
|
for _, addr := range addrs {
|
|
accAddresses = append(accAddresses, addr.String())
|
|
}
|
|
|
|
return &TestMsg{
|
|
Signers: accAddresses,
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
func (msg *TestMsg) GetSigners() []sdk.AccAddress {
|
|
signers := make([]sdk.AccAddress, 0, len(msg.Signers))
|
|
for _, addr := range msg.Signers {
|
|
a, _ := sdk.AccAddressFromBech32(addr)
|
|
signers = append(signers, a)
|
|
}
|
|
return signers
|
|
}
|
|
func (msg *TestMsg) ValidateBasic() error {
|
|
for _, addr := range msg.Signers {
|
|
if _, err := sdk.AccAddressFromBech32(addr); err != nil {
|
|
return sdkerrors.ErrInvalidAddress.Wrapf("invalid signer address: %s", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgCreateDog{}
|
|
|
|
func (msg *MsgCreateDog) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} }
|
|
func (msg *MsgCreateDog) ValidateBasic() error { return nil }
|