Use gogoproto's nullable=false (#166)

* Use gogoproto's nullable=false where appropriate.
This commit is contained in:
Jae Kwon
2017-12-22 19:41:19 -08:00
committed by GitHub
parent e4b9f1abe7
commit aaaacba1cd
8 changed files with 174 additions and 173 deletions

View File

@ -39,7 +39,7 @@ func (app *DummyApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
}
app.state.Set(key, value)
tags := []*types.KVPair{
tags := []types.KVPair{
{Key: "app.creator", ValueType: types.KVPair_STRING, ValueString: "jae"},
{Key: "app.key", ValueType: types.KVPair_STRING, ValueString: string(key)},
}

View File

@ -92,7 +92,7 @@ func TestPersistentDummyInfo(t *testing.T) {
// make and apply block
height = int64(1)
hash := []byte("foo")
header := &types.Header{
header := types.Header{
Height: int64(height),
}
dummy.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil})
@ -124,11 +124,11 @@ func TestValUpdates(t *testing.T) {
vals1, vals2 := vals[:nInit], dummy.Validators()
valsEqual(t, vals1, vals2)
var v1, v2, v3 *types.Validator
var v1, v2, v3 types.Validator
// add some validators
v1, v2 = vals[nInit], vals[nInit+1]
diff := []*types.Validator{v1, v2}
diff := []types.Validator{v1, v2}
tx1 := MakeValSetChangeTx(v1.PubKey, v1.Power)
tx2 := MakeValSetChangeTx(v2.PubKey, v2.Power)
@ -142,7 +142,7 @@ func TestValUpdates(t *testing.T) {
v1.Power = 0
v2.Power = 0
v3.Power = 0
diff = []*types.Validator{v1, v2, v3}
diff = []types.Validator{v1, v2, v3}
tx1 = MakeValSetChangeTx(v1.PubKey, v1.Power)
tx2 = MakeValSetChangeTx(v2.PubKey, v2.Power)
tx3 := MakeValSetChangeTx(v3.PubKey, v3.Power)
@ -160,22 +160,22 @@ func TestValUpdates(t *testing.T) {
} else {
v1.Power = 5
}
diff = []*types.Validator{v1}
diff = []types.Validator{v1}
tx1 = MakeValSetChangeTx(v1.PubKey, v1.Power)
makeApplyBlock(t, dummy, 3, diff, tx1)
vals1 = append([]*types.Validator{v1}, vals1[1:]...)
vals1 = append([]types.Validator{v1}, vals1[1:]...)
vals2 = dummy.Validators()
valsEqual(t, vals1, vals2)
}
func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff []*types.Validator, txs ...[]byte) {
func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff []types.Validator, txs ...[]byte) {
// make and apply block
height := int64(heightInt)
hash := []byte("foo")
header := &types.Header{
header := types.Header{
Height: height,
}
@ -193,7 +193,7 @@ func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff [
}
// order doesn't matter
func valsEqual(t *testing.T, vals1, vals2 []*types.Validator) {
func valsEqual(t *testing.T, vals1, vals2 []types.Validator) {
if len(vals1) != len(vals2) {
t.Fatalf("vals dont match in len. got %d, expected %d", len(vals2), len(vals1))
}

View File

@ -8,18 +8,18 @@ import (
// RandVal creates one random validator, with a key derived
// from the input value
func RandVal(i int) *types.Validator {
func RandVal(i int) types.Validator {
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes()
power := cmn.RandUint16() + 1
return &types.Validator{pubkey, int64(power)}
return types.Validator{pubkey, int64(power)}
}
// RandVals returns a list of cnt validators for initializing
// the application. Note that the keys are deterministically
// derived from the index in the array, while the power is
// random (Change this if not desired)
func RandVals(cnt int) []*types.Validator {
res := make([]*types.Validator, cnt)
func RandVals(cnt int) []types.Validator {
res := make([]types.Validator, cnt)
for i := 0; i < cnt; i++ {
res[i] = RandVal(i)
}

View File

@ -28,7 +28,7 @@ type PersistentDummyApplication struct {
app *DummyApplication
// validator set
ValUpdates []*types.Validator
ValUpdates []types.Validator
logger log.Logger
}
@ -119,7 +119,7 @@ func (app *PersistentDummyApplication) InitChain(req types.RequestInitChain) typ
// Track the block hash and header information
func (app *PersistentDummyApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
// reset valset changes
app.ValUpdates = make([]*types.Validator, 0)
app.ValUpdates = make([]types.Validator, 0)
return types.ResponseBeginBlock{}
}
@ -131,7 +131,7 @@ func (app *PersistentDummyApplication) EndBlock(req types.RequestEndBlock) types
//---------------------------------------------
// update validators
func (app *PersistentDummyApplication) Validators() (validators []*types.Validator) {
func (app *PersistentDummyApplication) Validators() (validators []types.Validator) {
app.app.state.Iterate(func(key, value []byte) bool {
if isValidatorTx(key) {
validator := new(types.Validator)
@ -139,7 +139,7 @@ func (app *PersistentDummyApplication) Validators() (validators []*types.Validat
if err != nil {
panic(err)
}
validators = append(validators, validator)
validators = append(validators, *validator)
}
return false
})
@ -190,11 +190,11 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Response
}
// update
return app.updateValidator(&types.Validator{pubkey, power})
return app.updateValidator(types.Validator{pubkey, power})
}
// add, update, or remove a validator
func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types.ResponseDeliverTx {
func (app *PersistentDummyApplication) updateValidator(v types.Validator) types.ResponseDeliverTx {
key := []byte("val:" + string(v.PubKey))
if v.Power == 0 {
// remove validator
@ -207,7 +207,7 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
} else {
// add or update validator
value := bytes.NewBuffer(make([]byte, 0))
if err := types.WriteMessage(v, value); err != nil {
if err := types.WriteMessage(&v, value); err != nil {
return types.ResponseDeliverTx{
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Error encoding validator: %v", err)}