cosmos-sdk/server/mock/tx.go
Marko 90e2a2ae89
style: linting (#15704)
## Description

closing in on completion of linting

---

### 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/main/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/main/docs/docs/building-modules)
* [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)
2023-04-06 23:25:23 +00:00

137 lines
3.3 KiB
Go

package mock
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
errorsmod "cosmossdk.io/errors"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing"
)
// An sdk.Tx which is its own sdk.Msg.
type KVStoreTx struct {
key []byte
value []byte
bytes []byte
address sdk.AccAddress
}
// testPubKey is a dummy implementation of PubKey used for testing.
type testPubKey struct {
address sdk.AccAddress
}
func (t testPubKey) Reset() { panic("not implemented") }
func (t testPubKey) String() string { panic("not implemented") }
func (t testPubKey) ProtoMessage() { panic("not implemented") }
func (t testPubKey) Address() cryptotypes.Address { return t.address.Bytes() }
func (t testPubKey) Bytes() []byte { panic("not implemented") }
func (t testPubKey) VerifySignature(msg, sig []byte) bool { panic("not implemented") }
func (t testPubKey) Equals(key cryptotypes.PubKey) bool { panic("not implemented") }
func (t testPubKey) Type() string { panic("not implemented") }
func (msg *KVStoreTx) GetSignaturesV2() (res []txsigning.SignatureV2, err error) {
res = append(res, txsigning.SignatureV2{
PubKey: testPubKey{address: msg.address},
Data: nil,
Sequence: 1,
})
return res, nil
}
func (msg *KVStoreTx) VerifySignature(msgByte, sig []byte) bool {
panic("implement me")
}
func (msg *KVStoreTx) Address() cryptotypes.Address {
panic("implement me")
}
func (msg *KVStoreTx) Bytes() []byte {
panic("implement me")
}
func (msg *KVStoreTx) Equals(key cryptotypes.PubKey) bool {
panic("implement me")
}
// dummy implementation of proto.Message
func (msg *KVStoreTx) Reset() {}
func (msg *KVStoreTx) String() string { return "TODO" }
func (msg *KVStoreTx) ProtoMessage() {}
var (
_ sdk.Tx = &KVStoreTx{}
_ sdk.Msg = &KVStoreTx{}
_ signing.SigVerifiableTx = &KVStoreTx{}
_ cryptotypes.PubKey = &KVStoreTx{}
_ cryptotypes.PubKey = &testPubKey{}
)
func NewTx(key, value string, accAddress sdk.AccAddress) *KVStoreTx {
bytes := fmt.Sprintf("%s=%s", key, value)
return &KVStoreTx{
key: []byte(key),
value: []byte(value),
bytes: []byte(bytes),
address: accAddress,
}
}
func (msg *KVStoreTx) Type() string {
return "kvstore_tx"
}
func (msg *KVStoreTx) GetMsgs() []sdk.Msg {
return []sdk.Msg{msg}
}
func (msg *KVStoreTx) GetSignBytes() []byte {
return msg.bytes
}
// Should the app be calling this? Or only handlers?
func (msg *KVStoreTx) ValidateBasic() error {
return nil
}
func (msg *KVStoreTx) GetSigners() []sdk.AccAddress {
return nil
}
func (msg *KVStoreTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") }
// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has
// all the signatures and can be used to authenticate.
func decodeTx(txBytes []byte) (sdk.Tx, error) {
var tx sdk.Tx
split := bytes.Split(txBytes, []byte("="))
switch len(split) {
case 1:
k := split[0]
tx = &KVStoreTx{k, k, txBytes, nil}
case 2:
k, v := split[0], split[1]
tx = &KVStoreTx{k, v, txBytes, nil}
default:
return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "too many '='")
}
return tx, nil
}