update tests

This commit is contained in:
Callum Waters
2022-10-26 14:39:16 +02:00
parent 574fc51efa
commit 2b41970966
16 changed files with 80 additions and 61 deletions
+7 -5
View File
@@ -7,9 +7,10 @@ import (
context "context"
fmt "fmt"
_ "github.com/cosmos/gogoproto/gogoproto"
grpc1 "github.com/cosmos/gogoproto/grpc"
proto "github.com/cosmos/gogoproto/proto"
_ "github.com/cosmos/gogoproto/types"
proto "github.com/gogo/protobuf/proto"
github_com_cosmos_gogoproto_types "github.com/gogo/protobuf/types"
github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types"
crypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
types1 "github.com/tendermint/tendermint/proto/tendermint/types"
grpc "google.golang.org/grpc"
@@ -1523,6 +1524,7 @@ func (m *RequestFinalizeBlock) GetProposerAddress() []byte {
type Response struct {
// Types that are valid to be assigned to Value:
//
// *Response_Exception
// *Response_Echo
// *Response_Flush
@@ -3863,10 +3865,10 @@ type ABCIClient interface {
}
type aBCIClient struct {
cc *grpc.ClientConn
cc grpc1.ClientConn
}
func NewABCIClient(cc *grpc.ClientConn) ABCIClient {
func NewABCIClient(cc grpc1.ClientConn) ABCIClient {
return &aBCIClient{cc}
}
@@ -4087,7 +4089,7 @@ func (*UnimplementedABCIServer) FinalizeBlock(ctx context.Context, req *RequestF
return nil, status.Errorf(codes.Unimplemented, "method FinalizeBlock not implemented")
}
func RegisterABCIServer(s *grpc.Server, srv ABCIServer) {
func RegisterABCIServer(s grpc1.Server, srv ABCIServer) {
s.RegisterService(&_ABCI_serviceDesc, srv)
}
+21 -38
View File
@@ -3,7 +3,6 @@ package blocksync
import (
"fmt"
"os"
"sort"
"testing"
"time"
@@ -15,6 +14,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/internal/test"
"github.com/tendermint/tendermint/libs/log"
mpmocks "github.com/tendermint/tendermint/mempool/mocks"
"github.com/tendermint/tendermint/p2p"
@@ -27,24 +27,10 @@ import (
var config *cfg.Config
func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.GenesisDoc, []types.PrivValidator) {
validators := make([]types.GenesisValidator, numValidators)
privValidators := make([]types.PrivValidator, numValidators)
for i := 0; i < numValidators; i++ {
val, privVal := types.RandValidator(randPower, minPower)
validators[i] = types.GenesisValidator{
PubKey: val.PubKey,
Power: val.VotingPower,
}
privValidators[i] = privVal
}
sort.Sort(types.PrivValidatorsByAddress(privValidators))
return &types.GenesisDoc{
GenesisTime: tmtime.Now(),
ChainID: config.ChainID(),
Validators: validators,
}, privValidators
func randGenesisDoc(t *testing.T) (*types.GenesisDoc, []types.PrivValidator) {
vals, privVals := test.ValidatorSet(t, 1, 30)
genDoc := test.GenesisDoc("", tmtime.Now(), vals.Validators, test.ConsensusParams())
return genDoc, privVals
}
type ReactorPair struct {
@@ -56,11 +42,8 @@ func newReactor(
t *testing.T,
logger log.Logger,
genDoc *types.GenesisDoc,
privVals []types.PrivValidator,
privVal types.PrivValidator,
maxBlockHeight int64) ReactorPair {
if len(privVals) != 1 {
panic("only support one validator")
}
app := abci.NewBaseApplication()
cc := proxy.NewLocalClientCreator(app)
@@ -115,12 +98,12 @@ func newReactor(
require.NoError(t, err)
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
vote, err := types.MakeVote(
vote, err := test.MakePrecommit(
privVal,
0,
thisBlock.Header.Height,
0,
blockID,
state.Validators,
privVals[0],
thisBlock.Header.ChainID,
time.Now(),
)
if err != nil {
@@ -153,14 +136,14 @@ func newReactor(
func TestNoBlockResponse(t *testing.T) {
config = cfg.ResetTestRoot("blockchain_reactor_test")
defer os.RemoveAll(config.RootDir)
genDoc, privVals := randGenesisDoc(1, false, 30)
genDoc, privVals := randGenesisDoc(t)
maxBlockHeight := int64(65)
reactorPairs := make([]ReactorPair, 2)
reactorPairs[0] = newReactor(t, log.TestingLogger(), genDoc, privVals, maxBlockHeight)
reactorPairs[1] = newReactor(t, log.TestingLogger(), genDoc, privVals, 0)
reactorPairs[0] = newReactor(t, log.TestingLogger(), genDoc, privVals[0], maxBlockHeight)
reactorPairs[1] = newReactor(t, log.TestingLogger(), genDoc, privVals[0], 0)
p2p.MakeConnectedSwitches(config.P2P, 2, func(i int, s *p2p.Switch) *p2p.Switch {
s.AddReactor("BLOCKCHAIN", reactorPairs[i].reactor)
@@ -215,13 +198,13 @@ func TestNoBlockResponse(t *testing.T) {
func TestBadBlockStopsPeer(t *testing.T) {
config = cfg.ResetTestRoot("blockchain_reactor_test")
defer os.RemoveAll(config.RootDir)
genDoc, privVals := randGenesisDoc(1, false, 30)
genDoc, privVals := randGenesisDoc(t)
maxBlockHeight := int64(148)
// Other chain needs a different validator set
otherGenDoc, otherPrivVals := randGenesisDoc(1, false, 30)
otherChain := newReactor(t, log.TestingLogger(), otherGenDoc, otherPrivVals, maxBlockHeight)
otherGenDoc, otherPrivVals := randGenesisDoc(t)
otherChain := newReactor(t, log.TestingLogger(), otherGenDoc, otherPrivVals[0], maxBlockHeight)
defer func() {
err := otherChain.reactor.Stop()
@@ -232,10 +215,10 @@ func TestBadBlockStopsPeer(t *testing.T) {
reactorPairs := make([]ReactorPair, 4)
reactorPairs[0] = newReactor(t, log.TestingLogger(), genDoc, privVals, maxBlockHeight)
reactorPairs[1] = newReactor(t, log.TestingLogger(), genDoc, privVals, 0)
reactorPairs[2] = newReactor(t, log.TestingLogger(), genDoc, privVals, 0)
reactorPairs[3] = newReactor(t, log.TestingLogger(), genDoc, privVals, 0)
reactorPairs[0] = newReactor(t, log.TestingLogger(), genDoc, privVals[0], maxBlockHeight)
reactorPairs[1] = newReactor(t, log.TestingLogger(), genDoc, privVals[0], 0)
reactorPairs[2] = newReactor(t, log.TestingLogger(), genDoc, privVals[0], 0)
reactorPairs[3] = newReactor(t, log.TestingLogger(), genDoc, privVals[0], 0)
switches := p2p.MakeConnectedSwitches(config.P2P, 4, func(i int, s *p2p.Switch) *p2p.Switch {
s.AddReactor("BLOCKCHAIN", reactorPairs[i].reactor)
@@ -273,7 +256,7 @@ func TestBadBlockStopsPeer(t *testing.T) {
// race, but can't be easily avoided.
reactorPairs[3].reactor.store = otherChain.reactor.store
lastReactorPair := newReactor(t, log.TestingLogger(), genDoc, privVals, 0)
lastReactorPair := newReactor(t, log.TestingLogger(), genDoc, privVals[0], 0)
reactorPairs = append(reactorPairs, lastReactorPair)
switches = append(switches, p2p.MakeConnectedSwitches(config.P2P, 1, func(i int, s *p2p.Switch) *p2p.Switch {
-8
View File
@@ -526,14 +526,6 @@ func makeLunaticEvidence(
return ev, trusted, common
}
// func makeEquivocationEvidence() *types.LightClientAttackEvidence {
// }
// func makeAmnesiaEvidence() *types.LightClientAttackEvidence {
// }
func makeVote(
t *testing.T, val types.PrivValidator, chainID string, valIndex int32, height int64,
round int32, step int, blockID types.BlockID, time time.Time) *types.Vote {
+3 -1
View File
@@ -32,7 +32,9 @@ func MakeExtendedCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet
return nil, err
}
vote.Signature = v.Signature
vote.ExtensionSignature = v.ExtensionSignature
if voteSet.ExtensionsEnabled() && !blockID.IsNil() {
vote.ExtensionSignature = v.ExtensionSignature
}
if _, err := voteSet.AddVote(vote); err != nil {
return nil, err
}
+9
View File
@@ -14,3 +14,12 @@ func TestMakeHeader(t *testing.T) {
require.NoError(t, header.ValidateBasic())
}
func TestValidatorSet(t *testing.T) {
valSet, privVals := ValidatorSet(t, 5, 10)
for idx, val := range valSet.Validators {
pk, err := privVals[idx].GetPubKey()
require.NoError(t, err)
require.Equal(t, val.PubKey, pk)
}
}
+14
View File
@@ -38,5 +38,19 @@ func MakeVote(
}
v.Signature = vpb.Signature
if tmproto.SignedMsgType(step) == tmproto.PrecommitType {
v.ExtensionSignature = vpb.ExtensionSignature
}
return v, nil
}
func MakePrecommit(
val types.PrivValidator,
valIndex int32,
height int64,
round int32,
blockID types.BlockID,
time time.Time,
) (*types.Vote, error) {
return MakeVote(val, DefaultTestChainID, valIndex, height, round, int(tmproto.PrecommitType), blockID, time)
}
+1
View File
@@ -27,6 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// PublicKey defines the keys available for use with Tendermint Validators
type PublicKey struct {
// Types that are valid to be assigned to Sum:
//
// *PublicKey_Ed25519
// *PublicKey_Secp256K1
Sum isPublicKey_Sum `protobuf_oneof:"sum"`
+1
View File
@@ -68,6 +68,7 @@ func (m *Txs) GetTxs() [][]byte {
type Message struct {
// Types that are valid to be assigned to Sum:
//
// *Message_Txs
Sum isMessage_Sum `protobuf_oneof:"sum"`
}
+1
View File
@@ -158,6 +158,7 @@ func (m *PacketMsg) GetData() []byte {
type Packet struct {
// Types that are valid to be assigned to Sum:
//
// *Packet_PacketPing
// *Packet_PacketPong
// *Packet_PacketMsg
+4 -3
View File
@@ -6,6 +6,7 @@ package coregrpc
import (
context "context"
fmt "fmt"
grpc1 "github.com/cosmos/gogoproto/grpc"
proto "github.com/cosmos/gogoproto/proto"
types "github.com/tendermint/tendermint/abci/types"
grpc "google.golang.org/grpc"
@@ -245,10 +246,10 @@ type BroadcastAPIClient interface {
}
type broadcastAPIClient struct {
cc *grpc.ClientConn
cc grpc1.ClientConn
}
func NewBroadcastAPIClient(cc *grpc.ClientConn) BroadcastAPIClient {
func NewBroadcastAPIClient(cc grpc1.ClientConn) BroadcastAPIClient {
return &broadcastAPIClient{cc}
}
@@ -287,7 +288,7 @@ func (*UnimplementedBroadcastAPIServer) BroadcastTx(ctx context.Context, req *Re
return nil, status.Errorf(codes.Unimplemented, "method BroadcastTx not implemented")
}
func RegisterBroadcastAPIServer(s *grpc.Server, srv BroadcastAPIServer) {
func RegisterBroadcastAPIServer(s grpc1.Server, srv BroadcastAPIServer) {
s.RegisterService(&_BroadcastAPI_serviceDesc, srv)
}
+5 -5
View File
@@ -6,9 +6,9 @@ package state
import (
fmt "fmt"
_ "github.com/cosmos/gogoproto/gogoproto"
proto "github.com/cosmos/gogoproto/proto"
_ "github.com/cosmos/gogoproto/types"
proto "github.com/gogo/protobuf/proto"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types"
types "github.com/tendermint/tendermint/abci/types"
types1 "github.com/tendermint/tendermint/proto/tendermint/types"
version "github.com/tendermint/tendermint/proto/tendermint/version"
@@ -1082,7 +1082,7 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x32
}
n13, err13 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.LastBlockTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.LastBlockTime):])
n13, err13 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.LastBlockTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.LastBlockTime):])
if err13 != nil {
return 0, err13
}
@@ -1281,7 +1281,7 @@ func (m *State) Size() (n int) {
}
l = m.LastBlockID.Size()
n += 1 + l + sovTypes(uint64(l))
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.LastBlockTime)
l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.LastBlockTime)
n += 1 + l + sovTypes(uint64(l))
if m.NextValidators != nil {
l = m.NextValidators.Size()
@@ -2355,7 +2355,7 @@ func (m *State) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.LastBlockTime, dAtA[iNdEx:postIndex]); err != nil {
if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.LastBlockTime, dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
+1
View File
@@ -24,6 +24,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type Message struct {
// Types that are valid to be assigned to Sum:
//
// *Message_SnapshotsRequest
// *Message_SnapshotsResponse
// *Message_ChunkRequest
+1
View File
@@ -606,6 +606,7 @@ func TestExtendedCommitToVoteSet(t *testing.T) {
h := int64(3)
voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
voteSet.extensionsEnabled = testCase.includeExtension
extCommit, err := makeExtCommit(lastID, h-1, 1, voteSet, vals, time.Now())
assert.NoError(t, err)
+3
View File
@@ -44,6 +44,9 @@ func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bo
return false, err
}
vote.Signature = v.Signature
if voteSet.extensionsEnabled {
vote.ExtensionSignature = v.ExtensionSignature
}
return voteSet.AddVote(vote)
}
+4
View File
@@ -233,6 +233,10 @@ func (vote *Vote) VerifyVoteAndExtension(chainID string, pubKey crypto.PubKey) e
}
// We only verify vote extension signatures for non-nil precommits.
if vote.Type == tmproto.PrecommitType && !IsProtoBlockIDNil(&v.BlockID) {
if len(vote.ExtensionSignature) == 0 {
return errors.New("expected vote extension signature")
}
extSignBytes := VoteExtensionSignBytes(chainID, v)
if !pubKey.VerifySignature(extSignBytes, vote.ExtensionSignature) {
return ErrVoteInvalidSignature
+5 -1
View File
@@ -143,6 +143,10 @@ func (voteSet *VoteSet) Size() int {
return voteSet.valSet.Size()
}
func (voteSet *VoteSet) ExtensionsEnabled() bool {
return voteSet.extensionsEnabled
}
// Returns added=true if vote is valid and new.
// Otherwise returns err=ErrVote[
//
@@ -216,7 +220,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
// Check signature.
if voteSet.extensionsEnabled {
if err := vote.VerifyVoteAndExtension(voteSet.chainID, val.PubKey); err != nil {
return false, fmt.Errorf("failed to verify vote with ChainID %s and PubKey %s: %w", voteSet.chainID, val.PubKey, err)
return false, fmt.Errorf("failed to verify extended vote with ChainID %s and PubKey %s: %w", voteSet.chainID, val.PubKey, err)
}
} else {
if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil {