|
@ -77,9 +77,9 @@ func TestABCIResponsesSaveLoad1(t *testing.T) { |
|
|
// build mock responses
|
|
|
// build mock responses
|
|
|
block := makeBlock(state, 2) |
|
|
block := makeBlock(state, 2) |
|
|
abciResponses := NewABCIResponses(block) |
|
|
abciResponses := NewABCIResponses(block) |
|
|
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: []*abci.KVPair{}} |
|
|
|
|
|
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: []*abci.KVPair{}} |
|
|
|
|
|
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{ |
|
|
|
|
|
|
|
|
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: []cmn.KVPair{}} |
|
|
|
|
|
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: []cmn.KVPair{}} |
|
|
|
|
|
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{ |
|
|
{ |
|
|
{ |
|
|
PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(), |
|
|
PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(), |
|
|
Power: 10, |
|
|
Power: 10, |
|
@ -122,9 +122,9 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { |
|
|
[]*abci.ResponseDeliverTx{ |
|
|
[]*abci.ResponseDeliverTx{ |
|
|
{Code: 383}, |
|
|
{Code: 383}, |
|
|
{Data: []byte("Gotcha!"), |
|
|
{Data: []byte("Gotcha!"), |
|
|
Tags: []*abci.KVPair{ |
|
|
|
|
|
abci.KVPairInt("a", 1), |
|
|
|
|
|
abci.KVPairString("build", "stuff"), |
|
|
|
|
|
|
|
|
Tags: []cmn.KVPair{ |
|
|
|
|
|
cmn.KVPair{[]byte("a"), []byte{1}}, |
|
|
|
|
|
cmn.KVPair{[]byte("build"), []byte("stuff")}, |
|
|
}}, |
|
|
}}, |
|
|
}, |
|
|
}, |
|
|
types.ABCIResults{ |
|
|
types.ABCIResults{ |
|
@ -378,44 +378,44 @@ func TestLessThanOneThirdOfVotingPowerPerBlockEnforced(t *testing.T) { |
|
|
testCases := []struct { |
|
|
testCases := []struct { |
|
|
initialValSetSize int |
|
|
initialValSetSize int |
|
|
shouldErr bool |
|
|
shouldErr bool |
|
|
valUpdatesFn func(vals *types.ValidatorSet) []*abci.Validator |
|
|
|
|
|
|
|
|
valUpdatesFn func(vals *types.ValidatorSet) []abci.Validator |
|
|
}{ |
|
|
}{ |
|
|
///////////// 1 val (vp: 10) => less than 3 is ok ////////////////////////
|
|
|
///////////// 1 val (vp: 10) => less than 3 is ok ////////////////////////
|
|
|
// adding 1 validator => 10
|
|
|
// adding 1 validator => 10
|
|
|
0: {1, false, func(vals *types.ValidatorSet) []*abci.Validator { |
|
|
|
|
|
return []*abci.Validator{ |
|
|
|
|
|
|
|
|
0: {1, false, func(vals *types.ValidatorSet) []abci.Validator { |
|
|
|
|
|
return []abci.Validator{ |
|
|
{PubKey: pk(), Power: 2}, |
|
|
{PubKey: pk(), Power: 2}, |
|
|
} |
|
|
} |
|
|
}}, |
|
|
}}, |
|
|
1: {1, true, func(vals *types.ValidatorSet) []*abci.Validator { |
|
|
|
|
|
return []*abci.Validator{ |
|
|
|
|
|
|
|
|
1: {1, true, func(vals *types.ValidatorSet) []abci.Validator { |
|
|
|
|
|
return []abci.Validator{ |
|
|
{PubKey: pk(), Power: 3}, |
|
|
{PubKey: pk(), Power: 3}, |
|
|
} |
|
|
} |
|
|
}}, |
|
|
}}, |
|
|
2: {1, true, func(vals *types.ValidatorSet) []*abci.Validator { |
|
|
|
|
|
return []*abci.Validator{ |
|
|
|
|
|
|
|
|
2: {1, true, func(vals *types.ValidatorSet) []abci.Validator { |
|
|
|
|
|
return []abci.Validator{ |
|
|
{PubKey: pk(), Power: 100}, |
|
|
{PubKey: pk(), Power: 100}, |
|
|
} |
|
|
} |
|
|
}}, |
|
|
}}, |
|
|
|
|
|
|
|
|
///////////// 3 val (vp: 30) => less than 10 is ok ////////////////////////
|
|
|
///////////// 3 val (vp: 30) => less than 10 is ok ////////////////////////
|
|
|
// adding and removing validator => 20
|
|
|
// adding and removing validator => 20
|
|
|
3: {3, true, func(vals *types.ValidatorSet) []*abci.Validator { |
|
|
|
|
|
|
|
|
3: {3, true, func(vals *types.ValidatorSet) []abci.Validator { |
|
|
_, firstVal := vals.GetByIndex(0) |
|
|
_, firstVal := vals.GetByIndex(0) |
|
|
return []*abci.Validator{ |
|
|
|
|
|
|
|
|
return []abci.Validator{ |
|
|
{PubKey: firstVal.PubKey.Bytes(), Power: 0}, |
|
|
{PubKey: firstVal.PubKey.Bytes(), Power: 0}, |
|
|
{PubKey: pk(), Power: 10}, |
|
|
{PubKey: pk(), Power: 10}, |
|
|
} |
|
|
} |
|
|
}}, |
|
|
}}, |
|
|
// adding 1 validator => 10
|
|
|
// adding 1 validator => 10
|
|
|
4: {3, true, func(vals *types.ValidatorSet) []*abci.Validator { |
|
|
|
|
|
return []*abci.Validator{ |
|
|
|
|
|
|
|
|
4: {3, true, func(vals *types.ValidatorSet) []abci.Validator { |
|
|
|
|
|
return []abci.Validator{ |
|
|
{PubKey: pk(), Power: 10}, |
|
|
{PubKey: pk(), Power: 10}, |
|
|
} |
|
|
} |
|
|
}}, |
|
|
}}, |
|
|
// adding 2 validators => 8
|
|
|
// adding 2 validators => 8
|
|
|
5: {3, false, func(vals *types.ValidatorSet) []*abci.Validator { |
|
|
|
|
|
return []*abci.Validator{ |
|
|
|
|
|
|
|
|
5: {3, false, func(vals *types.ValidatorSet) []abci.Validator { |
|
|
|
|
|
return []abci.Validator{ |
|
|
{PubKey: pk(), Power: 4}, |
|
|
{PubKey: pk(), Power: 4}, |
|
|
{PubKey: pk(), Power: 4}, |
|
|
{PubKey: pk(), Power: 4}, |
|
|
} |
|
|
} |
|
@ -450,20 +450,20 @@ func TestApplyUpdates(t *testing.T) { |
|
|
|
|
|
|
|
|
cases := [...]struct { |
|
|
cases := [...]struct { |
|
|
init types.ConsensusParams |
|
|
init types.ConsensusParams |
|
|
updates *abci.ConsensusParams |
|
|
|
|
|
|
|
|
updates abci.ConsensusParams |
|
|
expected types.ConsensusParams |
|
|
expected types.ConsensusParams |
|
|
}{ |
|
|
}{ |
|
|
0: {initParams, nil, initParams}, |
|
|
|
|
|
1: {initParams, &abci.ConsensusParams{}, initParams}, |
|
|
|
|
|
|
|
|
0: {initParams, abci.ConsensusParams{}, initParams}, |
|
|
|
|
|
1: {initParams, abci.ConsensusParams{}, initParams}, |
|
|
2: {initParams, |
|
|
2: {initParams, |
|
|
&abci.ConsensusParams{ |
|
|
|
|
|
|
|
|
abci.ConsensusParams{ |
|
|
TxSize: &abci.TxSize{ |
|
|
TxSize: &abci.TxSize{ |
|
|
MaxBytes: 123, |
|
|
MaxBytes: 123, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
makeParams(1, 2, 3, 123, 5, 6)}, |
|
|
makeParams(1, 2, 3, 123, 5, 6)}, |
|
|
3: {initParams, |
|
|
3: {initParams, |
|
|
&abci.ConsensusParams{ |
|
|
|
|
|
|
|
|
abci.ConsensusParams{ |
|
|
BlockSize: &abci.BlockSize{ |
|
|
BlockSize: &abci.BlockSize{ |
|
|
MaxTxs: 44, |
|
|
MaxTxs: 44, |
|
|
MaxGas: 55, |
|
|
MaxGas: 55, |
|
@ -471,7 +471,7 @@ func TestApplyUpdates(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
makeParams(1, 44, 55, 4, 5, 6)}, |
|
|
makeParams(1, 44, 55, 4, 5, 6)}, |
|
|
4: {initParams, |
|
|
4: {initParams, |
|
|
&abci.ConsensusParams{ |
|
|
|
|
|
|
|
|
abci.ConsensusParams{ |
|
|
BlockSize: &abci.BlockSize{ |
|
|
BlockSize: &abci.BlockSize{ |
|
|
MaxTxs: 789, |
|
|
MaxTxs: 789, |
|
|
}, |
|
|
}, |
|
@ -486,7 +486,7 @@ func TestApplyUpdates(t *testing.T) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for i, tc := range cases { |
|
|
for i, tc := range cases { |
|
|
res := tc.init.Update(tc.updates) |
|
|
|
|
|
|
|
|
res := tc.init.Update(&(tc.updates)) |
|
|
assert.Equal(t, tc.expected, res, "case %d", i) |
|
|
assert.Equal(t, tc.expected, res, "case %d", i) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -496,14 +496,14 @@ func makeHeaderPartsResponsesValPubKeyChange(state State, height int64, |
|
|
|
|
|
|
|
|
block := makeBlock(state, height) |
|
|
block := makeBlock(state, height) |
|
|
abciResponses := &ABCIResponses{ |
|
|
abciResponses := &ABCIResponses{ |
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{}}, |
|
|
|
|
|
|
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{}}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|
_, val := state.Validators.GetByIndex(0) |
|
|
_, val := state.Validators.GetByIndex(0) |
|
|
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}, |
|
|
{val.PubKey.Bytes(), 0}, |
|
|
{pubkey.Bytes(), 10}, |
|
|
{pubkey.Bytes(), 10}, |
|
|
}, |
|
|
}, |
|
@ -518,14 +518,14 @@ func makeHeaderPartsResponsesValPowerChange(state State, height int64, |
|
|
|
|
|
|
|
|
block := makeBlock(state, height) |
|
|
block := makeBlock(state, height) |
|
|
abciResponses := &ABCIResponses{ |
|
|
abciResponses := &ABCIResponses{ |
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{}}, |
|
|
|
|
|
|
|
|
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{}}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|
// if the pubkey is new, remove the old and add the new
|
|
|
_, val := state.Validators.GetByIndex(0) |
|
|
_, val := state.Validators.GetByIndex(0) |
|
|
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}, |
|
|
{val.PubKey.Bytes(), power}, |
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|