From 550d6a6081dbdc0c4acee7f101f1828852ddca8f Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 30 Nov 2017 15:37:31 -0500 Subject: [PATCH] shame: forgot to add new code pkg --- example/code/code.go | 9 +++++++++ example/counter/counter.go | 8 ++++---- example/dummy/dummy.go | 7 ++++--- example/dummy/dummy_test.go | 17 ++++++++++------- example/dummy/persistent_dummy.go | 4 ++-- example/example_test.go | 10 ++++++---- 6 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 example/code/code.go diff --git a/example/code/code.go b/example/code/code.go new file mode 100644 index 000000000..94e9d015e --- /dev/null +++ b/example/code/code.go @@ -0,0 +1,9 @@ +package code + +// Return codes for the examples +const ( + CodeTypeOK uint32 = 0 + CodeTypeEncodingError uint32 = 1 + CodeTypeBadNonce uint32 = 2 + CodeTypeUnauthorized uint32 = 3 +) diff --git a/example/counter/counter.go b/example/counter/counter.go index 67fa06e31..0978799e8 100644 --- a/example/counter/counter.go +++ b/example/counter/counter.go @@ -50,7 +50,7 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx { } } app.txCount++ - return types.ResponseDeliverTx{Code: types.CodeTypeOK} + return types.ResponseDeliverTx{Code: code.CodeTypeOK} } func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx { @@ -69,17 +69,17 @@ func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx { Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)} } } - return types.ResponseCheckTx{Code: types.CodeTypeOK} + return types.ResponseCheckTx{Code: code.CodeTypeOK} } func (app *CounterApplication) Commit() (resp types.ResponseCommit) { app.hashCount++ if app.txCount == 0 { - return types.ResponseCommit{Code: types.CodeTypeOK} + return types.ResponseCommit{Code: code.CodeTypeOK} } hash := make([]byte, 8) binary.BigEndian.PutUint64(hash, uint64(app.txCount)) - return types.ResponseCommit{Code: types.CodeTypeOK, Data: hash} + return types.ResponseCommit{Code: code.CodeTypeOK, Data: hash} } func (app *CounterApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery { diff --git a/example/dummy/dummy.go b/example/dummy/dummy.go index 8329ef039..fdb4851cf 100644 --- a/example/dummy/dummy.go +++ b/example/dummy/dummy.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + "github.com/tendermint/abci/example/code" "github.com/tendermint/abci/types" wire "github.com/tendermint/go-wire" "github.com/tendermint/iavl" @@ -42,11 +43,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.CodeTypeOK, Tags: tags} + return types.ResponseDeliverTx{Code: code.CodeTypeOK, Tags: tags} } func (app *DummyApplication) CheckTx(tx []byte) types.ResponseCheckTx { - return types.ResponseCheckTx{Code: types.CodeTypeOK} + return types.ResponseCheckTx{Code: code.CodeTypeOK} } func (app *DummyApplication) Commit() types.ResponseCommit { @@ -64,7 +65,7 @@ func (app *DummyApplication) Commit() types.ResponseCommit { } } - return types.ResponseCommit{Code: types.CodeTypeOK, Data: hash} + return types.ResponseCommit{Code: code.CodeTypeOK, Data: hash} } func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) { diff --git a/example/dummy/dummy_test.go b/example/dummy/dummy_test.go index 65970ecd7..738da6e85 100644 --- a/example/dummy/dummy_test.go +++ b/example/dummy/dummy_test.go @@ -7,12 +7,15 @@ import ( "testing" "github.com/stretchr/testify/require" - abcicli "github.com/tendermint/abci/client" - abciserver "github.com/tendermint/abci/server" - "github.com/tendermint/abci/types" + "github.com/tendermint/iavl" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" + + abcicli "github.com/tendermint/abci/client" + "github.com/tendermint/abci/example/code" + abciserver "github.com/tendermint/abci/server" + "github.com/tendermint/abci/types" ) func testDummy(t *testing.T, app types.Application, tx []byte, key, value string) { @@ -27,7 +30,7 @@ func testDummy(t *testing.T, app types.Application, tx []byte, key, value string Path: "/store", Data: []byte(key), }) - require.Equal(t, types.CodeTypeOK, resQuery.Code) + require.Equal(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, value, string(resQuery.Value)) // make sure proof is fine @@ -36,7 +39,7 @@ func testDummy(t *testing.T, app types.Application, tx []byte, key, value string Data: []byte(key), Prove: true, }) - require.EqualValues(t, types.CodeTypeOK, resQuery.Code) + require.EqualValues(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, value, string(resQuery.Value)) proof, err := iavl.ReadKeyExistsProof(resQuery.Proof) require.Nil(t, err) @@ -295,7 +298,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.CodeTypeOK, resQuery.Code) + require.Equal(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, value, string(resQuery.Value)) // make sure proof is fine @@ -305,7 +308,7 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string) Prove: true, }) require.Nil(t, err) - require.Equal(t, types.CodeTypeOK, resQuery.Code) + require.Equal(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, value, string(resQuery.Value)) proof, err := iavl.ReadKeyExistsProof(resQuery.Proof) require.Nil(t, err) diff --git a/example/dummy/persistent_dummy.go b/example/dummy/persistent_dummy.go index 51da8b30f..1d72bea14 100644 --- a/example/dummy/persistent_dummy.go +++ b/example/dummy/persistent_dummy.go @@ -97,7 +97,7 @@ func (app *PersistentDummyApplication) Commit() types.ResponseCommit { } app.logger.Info("Commit block", "height", height, "root", appHash) - return types.ResponseCommit{Code: types.CodeTypeOK, Data: appHash} + return types.ResponseCommit{Code: code.CodeTypeOK, Data: appHash} } func (app *PersistentDummyApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery { @@ -217,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.CodeTypeOK} + return types.ResponseDeliverTx{Code: code.CodeTypeOK} } diff --git a/example/example_test.go b/example/example_test.go index 7fd3bb520..dfa38a398 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -11,12 +11,14 @@ import ( "golang.org/x/net/context" + cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/tmlibs/log" + abcicli "github.com/tendermint/abci/client" + "github.com/tendermint/abci/example/code" "github.com/tendermint/abci/example/dummy" abciserver "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/log" ) func TestDummy(t *testing.T) { @@ -60,7 +62,7 @@ func testStream(t *testing.T, app types.Application) { switch r := res.Value.(type) { case *types.Response_DeliverTx: counter++ - if r.DeliverTx.Code != types.CodeTypeOK { + if r.DeliverTx.Code != code.CodeTypeOK { t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code) } if counter > numDeliverTxs { @@ -135,7 +137,7 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) { t.Fatalf("Error in GRPC DeliverTx: %v", err.Error()) } counter++ - if response.Code != types.CodeTypeOK { + if response.Code != code.CodeTypeOK { t.Error("DeliverTx failed with ret_code", response.Code) } if counter > numDeliverTxs {