mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-11 14:21:18 +00:00
Compare commits
1 Commits
wb/fix-tim
...
wb/remove-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3276f86587 |
@@ -1,15 +1,11 @@
|
|||||||
package blocksync_test
|
package blocksync_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
math "math"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
bcproto "github.com/tendermint/tendermint/proto/tendermint/blocksync"
|
bcproto "github.com/tendermint/tendermint/proto/tendermint/blocksync"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBlockRequest_Validate(t *testing.T) {
|
func TestBlockRequest_Validate(t *testing.T) {
|
||||||
@@ -83,48 +79,3 @@ func TestStatusResponse_Validate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockchainMessageVectors(t *testing.T) {
|
|
||||||
block := types.MakeBlock(int64(3), []types.Tx{types.Tx("Hello World")}, nil, nil)
|
|
||||||
block.Version.Block = 11 // overwrite updated protocol version
|
|
||||||
|
|
||||||
bpb, err := block.ToProto()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
testCases := []struct {
|
|
||||||
testName string
|
|
||||||
bmsg proto.Message
|
|
||||||
expBytes string
|
|
||||||
}{
|
|
||||||
{"BlockRequestMessage", &bcproto.Message{Sum: &bcproto.Message_BlockRequest{
|
|
||||||
BlockRequest: &bcproto.BlockRequest{Height: 1}}}, "0a020801"},
|
|
||||||
{"BlockRequestMessage", &bcproto.Message{Sum: &bcproto.Message_BlockRequest{
|
|
||||||
BlockRequest: &bcproto.BlockRequest{Height: math.MaxInt64}}},
|
|
||||||
"0a0a08ffffffffffffffff7f"},
|
|
||||||
{"BlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_BlockResponse{
|
|
||||||
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1a700a6e0a5b0a02080b1803220b088092b8c398feffffff012a0212003a20c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf96a20e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855120d0a0b48656c6c6f20576f726c641a00"},
|
|
||||||
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
|
|
||||||
NoBlockResponse: &bcproto.NoBlockResponse{Height: 1}}}, "12020801"},
|
|
||||||
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
|
|
||||||
NoBlockResponse: &bcproto.NoBlockResponse{Height: math.MaxInt64}}},
|
|
||||||
"120a08ffffffffffffffff7f"},
|
|
||||||
{"StatusRequestMessage", &bcproto.Message{Sum: &bcproto.Message_StatusRequest{
|
|
||||||
StatusRequest: &bcproto.StatusRequest{}}},
|
|
||||||
"2200"},
|
|
||||||
{"StatusResponseMessage", &bcproto.Message{Sum: &bcproto.Message_StatusResponse{
|
|
||||||
StatusResponse: &bcproto.StatusResponse{Height: 1, Base: 2}}},
|
|
||||||
"2a0408011002"},
|
|
||||||
{"StatusResponseMessage", &bcproto.Message{Sum: &bcproto.Message_StatusResponse{
|
|
||||||
StatusResponse: &bcproto.StatusResponse{Height: math.MaxInt64, Base: math.MaxInt64}}},
|
|
||||||
"2a1408ffffffffffffffff7f10ffffffffffffffff7f"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range testCases {
|
|
||||||
tc := tc
|
|
||||||
t.Run(tc.testName, func(t *testing.T) {
|
|
||||||
bz, err := proto.Marshal(tc.bmsg)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, tc.expBytes, hex.EncodeToString(bz))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package consensus_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/hex"
|
|
||||||
"math"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus"
|
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHasVoteVector(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
msg tmcons.HasVote
|
|
||||||
expBytes string
|
|
||||||
}{
|
|
||||||
{tmcons.HasVote{1, 3, tmproto.PrevoteType, 1}, "3a080801100318012001"},
|
|
||||||
{tmcons.HasVote{2, 2, tmproto.PrecommitType, 2}, "3a080802100218022002"},
|
|
||||||
{tmcons.HasVote{math.MaxInt64, math.MaxInt32, tmproto.ProposalType, math.MaxInt32},
|
|
||||||
"3a1808ffffffffffffffff7f10ffffffff07182020ffffffff07"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tc := range testCases {
|
|
||||||
msg := tmcons.Message{&tmcons.Message_HasVote{HasVote: &tc.msg}}
|
|
||||||
bz, err := proto.Marshal(&msg)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), "test vector failed", i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package statesync_test
|
package statesync_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
@@ -9,7 +8,6 @@ import (
|
|||||||
|
|
||||||
ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync"
|
ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync"
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateMsg(t *testing.T) {
|
func TestValidateMsg(t *testing.T) {
|
||||||
@@ -120,87 +118,3 @@ func TestValidateMsg(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStateSyncVectors(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
testName string
|
|
||||||
msg proto.Message
|
|
||||||
expBytes string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
"SnapshotsRequest",
|
|
||||||
&ssproto.SnapshotsRequest{},
|
|
||||||
"0a00",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"SnapshotsResponse",
|
|
||||||
&ssproto.SnapshotsResponse{
|
|
||||||
Height: 1,
|
|
||||||
Format: 2,
|
|
||||||
Chunks: 3,
|
|
||||||
Hash: []byte("chuck hash"),
|
|
||||||
Metadata: []byte("snapshot metadata"),
|
|
||||||
},
|
|
||||||
"1225080110021803220a636875636b20686173682a11736e617073686f74206d65746164617461",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ChunkRequest",
|
|
||||||
&ssproto.ChunkRequest{
|
|
||||||
Height: 1,
|
|
||||||
Format: 2,
|
|
||||||
Index: 3,
|
|
||||||
},
|
|
||||||
"1a06080110021803",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ChunkResponse",
|
|
||||||
&ssproto.ChunkResponse{
|
|
||||||
Height: 1,
|
|
||||||
Format: 2,
|
|
||||||
Index: 3,
|
|
||||||
Chunk: []byte("it's a chunk"),
|
|
||||||
},
|
|
||||||
"2214080110021803220c697427732061206368756e6b",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LightBlockRequest",
|
|
||||||
&ssproto.LightBlockRequest{
|
|
||||||
Height: 100,
|
|
||||||
},
|
|
||||||
"2a020864",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"LightBlockResponse",
|
|
||||||
&ssproto.LightBlockResponse{
|
|
||||||
LightBlock: nil,
|
|
||||||
},
|
|
||||||
"3200",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ParamsRequest",
|
|
||||||
&ssproto.ParamsRequest{
|
|
||||||
Height: 9001,
|
|
||||||
},
|
|
||||||
"3a0308a946",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ParamsResponse",
|
|
||||||
&ssproto.ParamsResponse{
|
|
||||||
Height: 9001,
|
|
||||||
ConsensusParams: types.DefaultConsensusParams().ToProto(),
|
|
||||||
},
|
|
||||||
"423408a946122f0a10088080c00a10ffffffffffffffffff01120e08a08d0612040880c60a188080401a090a07656432353531392200",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range testCases {
|
|
||||||
tc := tc
|
|
||||||
|
|
||||||
msg := new(ssproto.Message)
|
|
||||||
require.NoError(t, msg.Wrap(tc.msg))
|
|
||||||
|
|
||||||
bz, err := msg.Marshal()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user