mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
state test runs
This commit is contained in:
parent
7606b7595f
commit
e4147b6f1a
@ -80,7 +80,7 @@ func TestBeginBlockAbsentValidators(t *testing.T) {
|
|||||||
require.Nil(t, err, tc.desc)
|
require.Nil(t, err, tc.desc)
|
||||||
|
|
||||||
// -> app must receive an index of the absent validator
|
// -> app must receive an index of the absent validator
|
||||||
assert.Equal(t, tc.expectedAbsentValidators, app.AbsentValidators, tc.desc)
|
assert.Equal(t, tc.expectedAbsentValidators, app.Validators, tc.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,10 +110,10 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
|
|||||||
expectedByzantineValidators []abci.Evidence
|
expectedByzantineValidators []abci.Evidence
|
||||||
}{
|
}{
|
||||||
{"none byzantine", []types.Evidence{}, []abci.Evidence{}},
|
{"none byzantine", []types.Evidence{}, []abci.Evidence{}},
|
||||||
{"one byzantine", []types.Evidence{ev1}, []abci.Evidence{{ev1.Address(), ev1.Height()}}},
|
{"one byzantine", []types.Evidence{ev1}, []abci.Evidence{types.TM2PB.Evidence(ev1)}},
|
||||||
{"multiple byzantine", []types.Evidence{ev1, ev2}, []abci.Evidence{
|
{"multiple byzantine", []types.Evidence{ev1, ev2}, []abci.Evidence{
|
||||||
{ev1.Address(), ev1.Height()},
|
types.TM2PB.Evidence(ev1),
|
||||||
{ev2.Address(), ev2.Height()}}},
|
types.TM2PB.Evidence(ev1)}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@ -162,7 +162,7 @@ var _ abci.Application = (*testApp)(nil)
|
|||||||
type testApp struct {
|
type testApp struct {
|
||||||
abci.BaseApplication
|
abci.BaseApplication
|
||||||
|
|
||||||
AbsentValidators []int32
|
Validators []abci.SigningValidator
|
||||||
ByzantineValidators []abci.Evidence
|
ByzantineValidators []abci.Evidence
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func (app *testApp) Info(req abci.RequestInfo) (resInfo abci.ResponseInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
||||||
app.AbsentValidators = req.AbsentValidators
|
app.Validators = req.Validators
|
||||||
app.ByzantineValidators = req.ByzantineValidators
|
app.ByzantineValidators = req.ByzantineValidators
|
||||||
return abci.ResponseBeginBlock{}
|
return abci.ResponseBeginBlock{}
|
||||||
}
|
}
|
||||||
|
@ -78,10 +78,7 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
|
|||||||
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: nil}
|
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: nil}
|
||||||
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: nil}
|
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: nil}
|
||||||
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{
|
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{
|
||||||
{
|
types.TM2PB.ValidatorFromPubKeyAndPower(crypto.GenPrivKeyEd25519().PubKey(), 10),
|
||||||
PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(),
|
|
||||||
Power: 10,
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
saveABCIResponses(stateDB, block.Height, abciResponses)
|
saveABCIResponses(stateDB, block.Height, abciResponses)
|
||||||
@ -435,8 +432,8 @@ func makeHeaderPartsResponsesValPubKeyChange(state State, height int64,
|
|||||||
if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) {
|
if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) {
|
||||||
abciResponses.EndBlock = &abci.ResponseEndBlock{
|
abciResponses.EndBlock = &abci.ResponseEndBlock{
|
||||||
ValidatorUpdates: []abci.Validator{
|
ValidatorUpdates: []abci.Validator{
|
||||||
{val.PubKey.Bytes(), 0},
|
types.TM2PB.ValidatorFromPubKeyAndPower(val.PubKey, 0),
|
||||||
{pubkey.Bytes(), 10},
|
types.TM2PB.ValidatorFromPubKeyAndPower(pubkey, 10),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,7 +454,7 @@ func makeHeaderPartsResponsesValPowerChange(state State, height int64,
|
|||||||
if val.VotingPower != power {
|
if val.VotingPower != power {
|
||||||
abciResponses.EndBlock = &abci.ResponseEndBlock{
|
abciResponses.EndBlock = &abci.ResponseEndBlock{
|
||||||
ValidatorUpdates: []abci.Validator{
|
ValidatorUpdates: []abci.Validator{
|
||||||
{val.PubKey.Bytes(), power},
|
types.TM2PB.ValidatorFromPubKeyAndPower(val.PubKey, power),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TM2PB is used for converting Tendermint types to protobuf types.
|
// TM2PB is used for converting Tendermint abci to protobuf abci.
|
||||||
// UNSTABLE
|
// UNSTABLE
|
||||||
var TM2PB = tm2pb{}
|
var TM2PB = tm2pb{}
|
||||||
|
|
||||||
type tm2pb struct{}
|
type tm2pb struct{}
|
||||||
|
|
||||||
func (tm2pb) Header(header *Header) types.Header {
|
func (tm2pb) Header(header *Header) abci.Header {
|
||||||
return types.Header{
|
return abci.Header{
|
||||||
ChainID: header.ChainID,
|
ChainID: header.ChainID,
|
||||||
Height: header.Height,
|
Height: header.Height,
|
||||||
Time: header.Time.Unix(),
|
Time: header.Time.Unix(),
|
||||||
@ -25,22 +25,22 @@ func (tm2pb) Header(header *Header) types.Header {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tm2pb) Validator(val *Validator) types.Validator {
|
func (tm2pb) Validator(val *Validator) abci.Validator {
|
||||||
return types.Validator{
|
return abci.Validator{
|
||||||
PubKey: TM2PB.PubKey(val.PubKey),
|
PubKey: TM2PB.PubKey(val.PubKey),
|
||||||
Power: val.VotingPower,
|
Power: val.VotingPower,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tm2pb) PubKey(pubKey crypto.PubKey) types.PubKey {
|
func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
|
||||||
switch pk := pubKey.(type) {
|
switch pk := pubKey.(type) {
|
||||||
case crypto.PubKeyEd25519:
|
case crypto.PubKeyEd25519:
|
||||||
return types.PubKey{
|
return abci.PubKey{
|
||||||
Type: "ed25519",
|
Type: "ed25519",
|
||||||
Data: pk[:],
|
Data: pk[:],
|
||||||
}
|
}
|
||||||
case crypto.PubKeySecp256k1:
|
case crypto.PubKeySecp256k1:
|
||||||
return types.PubKey{
|
return abci.PubKey{
|
||||||
Type: "secp256k1",
|
Type: "secp256k1",
|
||||||
Data: pk[:],
|
Data: pk[:],
|
||||||
}
|
}
|
||||||
@ -49,42 +49,70 @@ func (tm2pb) PubKey(pubKey crypto.PubKey) types.PubKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tm2pb) Validators(vals *ValidatorSet) []types.Validator {
|
func (tm2pb) Validators(vals *ValidatorSet) []abci.Validator {
|
||||||
validators := make([]types.Validator, len(vals.Validators))
|
validators := make([]abci.Validator, len(vals.Validators))
|
||||||
for i, val := range vals.Validators {
|
for i, val := range vals.Validators {
|
||||||
validators[i] = TM2PB.Validator(val)
|
validators[i] = TM2PB.Validator(val)
|
||||||
}
|
}
|
||||||
return validators
|
return validators
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tm2pb) ConsensusParams(params *ConsensusParams) *types.ConsensusParams {
|
func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams {
|
||||||
return &types.ConsensusParams{
|
return &abci.ConsensusParams{
|
||||||
BlockSize: &types.BlockSize{
|
BlockSize: &abci.BlockSize{
|
||||||
|
|
||||||
MaxBytes: int32(params.BlockSize.MaxBytes),
|
MaxBytes: int32(params.BlockSize.MaxBytes),
|
||||||
MaxTxs: int32(params.BlockSize.MaxTxs),
|
MaxTxs: int32(params.BlockSize.MaxTxs),
|
||||||
MaxGas: params.BlockSize.MaxGas,
|
MaxGas: params.BlockSize.MaxGas,
|
||||||
},
|
},
|
||||||
TxSize: &types.TxSize{
|
TxSize: &abci.TxSize{
|
||||||
MaxBytes: int32(params.TxSize.MaxBytes),
|
MaxBytes: int32(params.TxSize.MaxBytes),
|
||||||
MaxGas: params.TxSize.MaxGas,
|
MaxGas: params.TxSize.MaxGas,
|
||||||
},
|
},
|
||||||
BlockGossip: &types.BlockGossip{
|
BlockGossip: &abci.BlockGossip{
|
||||||
BlockPartSizeBytes: int32(params.BlockGossip.BlockPartSizeBytes),
|
BlockPartSizeBytes: int32(params.BlockGossip.BlockPartSizeBytes),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tm2pb) Evidence(ev_ Evidence) abci.Evidence {
|
||||||
|
switch ev := ev_.(type) {
|
||||||
|
case *DuplicateVoteEvidence:
|
||||||
|
return abci.Evidence{
|
||||||
|
Type: "duplicate/vote",
|
||||||
|
Validator: abci.Validator{
|
||||||
|
Address: ev.Address(),
|
||||||
|
// TODO
|
||||||
|
},
|
||||||
|
Height: ev.Height(),
|
||||||
|
// Time: ev.Time(),
|
||||||
|
// TotalVotingPower: 10,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("Unknown evidence type: %v %v", ev_, reflect.TypeOf(ev_)))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tm2pb) ValidatorFromPubKeyAndPower(pubkey crypto.PubKey, power int64) abci.Validator {
|
||||||
|
pubkeyABCI := TM2PB.PubKey(pubkey)
|
||||||
|
return abci.Validator{
|
||||||
|
Address: pubkey.Address(),
|
||||||
|
PubKey: pubkeyABCI,
|
||||||
|
Power: power,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// PB2TM is used for converting protobuf types to Tendermint types.
|
// PB2TM is used for converting protobuf abci to Tendermint abci.
|
||||||
// UNSTABLE
|
// UNSTABLE
|
||||||
var PB2TM = pb2tm{}
|
var PB2TM = pb2tm{}
|
||||||
|
|
||||||
type pb2tm struct{}
|
type pb2tm struct{}
|
||||||
|
|
||||||
// TODO: validate key lengths ...
|
// TODO: validate key lengths ...
|
||||||
func (pb2tm) PubKey(pubKey types.PubKey) (crypto.PubKey, error) {
|
func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
|
||||||
switch pubKey.Type {
|
switch pubKey.Type {
|
||||||
case "ed25519":
|
case "ed25519":
|
||||||
var pk crypto.PubKeyEd25519
|
var pk crypto.PubKeyEd25519
|
||||||
|
Loading…
x
Reference in New Issue
Block a user