forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add simapp setup helpers (cosmos#10020)
- Loading branch information
Showing
8 changed files
with
182 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package mock | ||
|
||
import ( | ||
"github.com/tendermint/tendermint/crypto" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
|
||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
) | ||
|
||
var _ tmtypes.PrivValidator = PV{} | ||
|
||
// MockPV implements PrivValidator without any safety or persistence. | ||
// Only use it for testing. | ||
type PV struct { | ||
PrivKey cryptotypes.PrivKey | ||
} | ||
|
||
func NewPV() PV { | ||
return PV{ed25519.GenPrivKey()} | ||
} | ||
|
||
// GetPubKey implements PrivValidator interface | ||
func (pv PV) GetPubKey() (crypto.PubKey, error) { | ||
return cryptocodec.ToTmPubKeyInterface(pv.PrivKey.PubKey()) | ||
} | ||
|
||
// SignVote implements PrivValidator interface | ||
func (pv PV) SignVote(chainID string, vote *tmproto.Vote) error { | ||
signBytes := tmtypes.VoteSignBytes(chainID, vote) | ||
sig, err := pv.PrivKey.Sign(signBytes) | ||
if err != nil { | ||
return err | ||
} | ||
vote.Signature = sig | ||
return nil | ||
} | ||
|
||
// SignProposal implements PrivValidator interface | ||
func (pv PV) SignProposal(chainID string, proposal *tmproto.Proposal) error { | ||
signBytes := tmtypes.ProposalSignBytes(chainID, proposal) | ||
sig, err := pv.PrivKey.Sign(signBytes) | ||
if err != nil { | ||
return err | ||
} | ||
proposal.Signature = sig | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.