remove CodeType

This commit is contained in:
Ethan Buchman
2017-11-30 14:29:12 -05:00
parent 22b491bb19
commit 42a8e3240c
19 changed files with 190 additions and 410 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/binary"
"fmt"
"github.com/tendermint/abci/example/code"
"github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
)
@ -36,7 +37,7 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
if app.serial {
if len(tx) > 8 {
return types.ResponseDeliverTx{
Code: types.CodeType_EncodingError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx))}
}
tx8 := make([]byte, 8)
@ -44,19 +45,19 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
txValue := binary.BigEndian.Uint64(tx8)
if txValue != uint64(app.txCount) {
return types.ResponseDeliverTx{
Code: types.CodeType_BadNonce,
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
}
}
app.txCount++
return types.ResponseDeliverTx{Code: types.CodeType_OK}
return types.ResponseDeliverTx{Code: types.CodeTypeOK}
}
func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx {
if app.serial {
if len(tx) > 8 {
return types.ResponseCheckTx{
Code: types.CodeType_EncodingError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx))}
}
tx8 := make([]byte, 8)
@ -64,21 +65,21 @@ func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx {
txValue := binary.BigEndian.Uint64(tx8)
if txValue < uint64(app.txCount) {
return types.ResponseCheckTx{
Code: types.CodeType_BadNonce,
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)}
}
}
return types.ResponseCheckTx{Code: types.CodeType_OK}
return types.ResponseCheckTx{Code: types.CodeTypeOK}
}
func (app *CounterApplication) Commit() (resp types.ResponseCommit) {
app.hashCount++
if app.txCount == 0 {
return types.ResponseCommit{Code: types.CodeType_OK}
return types.ResponseCommit{Code: types.CodeTypeOK}
}
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return types.ResponseCommit{Code: types.CodeType_OK, Data: hash}
return types.ResponseCommit{Code: types.CodeTypeOK, Data: hash}
}
func (app *CounterApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery {

View File

@ -42,11 +42,11 @@ func (app *DummyApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
{Key: "app.creator", ValueType: types.KVPair_STRING, ValueString: "jae"},
{Key: "app.key", ValueType: types.KVPair_STRING, ValueString: string(key)},
}
return types.ResponseDeliverTx{Code: types.CodeType_OK, Tags: tags}
return types.ResponseDeliverTx{Code: types.CodeTypeOK, Tags: tags}
}
func (app *DummyApplication) CheckTx(tx []byte) types.ResponseCheckTx {
return types.ResponseCheckTx{Code: types.CodeType_OK}
return types.ResponseCheckTx{Code: types.CodeTypeOK}
}
func (app *DummyApplication) Commit() types.ResponseCommit {
@ -64,7 +64,7 @@ func (app *DummyApplication) Commit() types.ResponseCommit {
}
}
return types.ResponseCommit{Code: types.CodeType_OK, Data: hash}
return types.ResponseCommit{Code: types.CodeTypeOK, Data: hash}
}
func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {

View File

@ -27,7 +27,7 @@ func testDummy(t *testing.T, app types.Application, tx []byte, key, value string
Path: "/store",
Data: []byte(key),
})
require.Equal(t, types.CodeType_OK, resQuery.Code)
require.Equal(t, types.CodeTypeOK, resQuery.Code)
require.Equal(t, value, string(resQuery.Value))
// make sure proof is fine
@ -36,7 +36,7 @@ func testDummy(t *testing.T, app types.Application, tx []byte, key, value string
Data: []byte(key),
Prove: true,
})
require.Equal(t, types.CodeType_OK, resQuery.Code)
require.EqualValues(t, types.CodeTypeOK, resQuery.Code)
require.Equal(t, value, string(resQuery.Value))
proof, err := iavl.ReadKeyExistsProof(resQuery.Proof)
require.Nil(t, err)
@ -295,7 +295,7 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
Data: []byte(key),
})
require.Nil(t, err)
require.Equal(t, types.CodeType_OK, resQuery.Code)
require.Equal(t, types.CodeTypeOK, resQuery.Code)
require.Equal(t, value, string(resQuery.Value))
// make sure proof is fine
@ -305,7 +305,7 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
Prove: true,
})
require.Nil(t, err)
require.Equal(t, types.CodeType_OK, resQuery.Code)
require.Equal(t, types.CodeTypeOK, resQuery.Code)
require.Equal(t, value, string(resQuery.Value))
proof, err := iavl.ReadKeyExistsProof(resQuery.Proof)
require.Nil(t, err)

View File

@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"github.com/tendermint/abci/example/code"
"github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/iavl"
@ -96,7 +97,7 @@ func (app *PersistentDummyApplication) Commit() types.ResponseCommit {
}
app.logger.Info("Commit block", "height", height, "root", appHash)
return types.ResponseCommit{Code: types.CodeType_OK, Data: appHash}
return types.ResponseCommit{Code: types.CodeTypeOK, Data: appHash}
}
func (app *PersistentDummyApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery {
@ -160,7 +161,7 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Response
pubKeyAndPower := strings.Split(string(tx), "/")
if len(pubKeyAndPower) != 2 {
return types.ResponseDeliverTx{
Code: types.CodeType_EncodingError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower)}
}
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1]
@ -169,13 +170,13 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Response
pubkey, err := hex.DecodeString(pubkeyS)
if err != nil {
return types.ResponseDeliverTx{
Code: types.CodeType_EncodingError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS)}
}
_, err = crypto.PubKeyFromBytes(pubkey)
if err != nil {
return types.ResponseDeliverTx{
Code: types.CodeType_EncodingError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Pubkey (%X) is invalid go-crypto encoded", pubkey)}
}
@ -183,7 +184,7 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Response
power, err := strconv.Atoi(powerS)
if err != nil {
return types.ResponseDeliverTx{
Code: types.CodeType_EncodingError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Power (%s) is not an int", powerS)}
}
@ -198,7 +199,7 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
// remove validator
if !app.app.state.Has(key) {
return types.ResponseDeliverTx{
Code: types.CodeType_Unauthorized,
Code: code.CodeTypeUnauthorized,
Log: fmt.Sprintf("Cannot remove non-existent validator %X", key)}
}
app.app.state.Remove(key)
@ -207,7 +208,7 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
value := bytes.NewBuffer(make([]byte, 0))
if err := types.WriteMessage(v, value); err != nil {
return types.ResponseDeliverTx{
Code: types.CodeType_InternalError,
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Error encoding validator: %v", err)}
}
app.app.state.Set(key, value.Bytes())
@ -216,5 +217,5 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
// we only update the changes array if we successfully updated the tree
app.changes = append(app.changes, v)
return types.ResponseDeliverTx{Code: types.CodeType_OK}
return types.ResponseDeliverTx{Code: types.CodeTypeOK}
}

View File

@ -1,3 +1,3 @@
package example
// so the go tool doesn't return errors about no buildable go files ...
// so go get doesnt complain

View File

@ -60,7 +60,7 @@ func testStream(t *testing.T, app types.Application) {
switch r := res.Value.(type) {
case *types.Response_DeliverTx:
counter++
if r.DeliverTx.Code != types.CodeType_OK {
if r.DeliverTx.Code != types.CodeTypeOK {
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
}
if counter > numDeliverTxs {
@ -135,7 +135,7 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
}
counter++
if response.Code != types.CodeType_OK {
if response.Code != types.CodeTypeOK {
t.Error("DeliverTx failed with ret_code", response.Code)
}
if counter > numDeliverTxs {