From a3362ccf356126416bbf80b7a5479173e4890379 Mon Sep 17 00:00:00 2001 From: zramsay Date: Mon, 19 Feb 2018 20:34:51 +0000 Subject: [PATCH 1/3] s/Dummy/KVStore/g --- README.md | 15 ++-- cmd/abci-cli/abci-cli.go | 40 +++++++--- example/example_test.go | 8 +- example/{dummy => kvstore}/README.md | 12 +-- example/{dummy => kvstore}/dummy.go | 20 ++--- example/{dummy => kvstore}/dummy_test.go | 78 +++++++++---------- example/{dummy => kvstore}/helpers.go | 6 +- .../{dummy => kvstore}/persistent_dummy.go | 42 +++++----- tests/client_server_test.go | 4 +- 9 files changed, 123 insertions(+), 102 deletions(-) rename example/{dummy => kvstore}/README.md (75%) rename example/{dummy => kvstore}/dummy.go (79%) rename example/{dummy => kvstore}/dummy_test.go (76%) rename example/{dummy => kvstore}/helpers.go (87%) rename example/{dummy => kvstore}/persistent_dummy.go (73%) diff --git a/README.md b/README.md index 79e2edda4..e733dea71 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ See [the documentation](http://tendermint.readthedocs.io/en/master/) for more de ### Examples Check out the variety of example applications in the [example directory](example/). -It also contains the code refered to by the `counter` and `dummy` apps; these apps come +It also contains the code refered to by the `counter` and `kvstore` apps; these apps come built into the `abci-cli` binary. #### Counter @@ -122,21 +122,21 @@ func cmdCounter(cmd *cobra.Command, args []string) error { and can be found in [this file](cmd/abci-cli/abci-cli.go). -#### Dummy +#### kvstore -The `abci-cli dummy` application, which illustrates a simple key-value Merkle tree +The `abci-cli kvstore` application, which illustrates a simple key-value Merkle tree ```golang -func cmdDummy(cmd *cobra.Command, args []string) error { +func cmdKVStore(cmd *cobra.Command, args []string) error { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) // Create the application - in memory or persisted to disk var app types.Application if flagPersist == "" { - app = dummy.NewDummyApplication() + app = dummy.NewKVStoreApplication() } else { - app = dummy.NewPersistentDummyApplication(flagPersist) - app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy")) + app = dummy.NewPersistentKVStoreApplication(flagPersist) + app.(*dummy.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore")) } // Start the listener @@ -157,4 +157,3 @@ func cmdDummy(cmd *cobra.Command, args []string) error { return nil } ``` - diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index faaea5020..5204137ce 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -17,7 +17,7 @@ import ( abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/example/code" "github.com/tendermint/abci/example/counter" - "github.com/tendermint/abci/example/dummy" + "github.com/tendermint/abci/example/kvstore" "github.com/tendermint/abci/server" servertest "github.com/tendermint/abci/tests/server" "github.com/tendermint/abci/types" @@ -47,7 +47,7 @@ var ( flagAddrC string flagSerial bool - // dummy + // kvstore flagAddrD string flagPersist string ) @@ -59,7 +59,7 @@ var RootCmd = &cobra.Command{ PersistentPreRunE: func(cmd *cobra.Command, args []string) error { switch cmd.Use { - case "counter", "dummy": // for the examples apps, don't pre-run + case "counter", "kvstore", "dummy": // for the examples apps, don't pre-run return nil case "version": // skip running for version command return nil @@ -133,6 +133,12 @@ func addDummyFlags() { dummyCmd.PersistentFlags().StringVarP(&flagAddrD, "addr", "", "tcp://0.0.0.0:46658", "listen address") dummyCmd.PersistentFlags().StringVarP(&flagPersist, "persist", "", "", "directory to use for a database") } + +func addKVStoreFlags() { + kvstoreCmd.PersistentFlags().StringVarP(&flagAddrD, "addr", "", "tcp://0.0.0.0:46658", "listen address") + kvstoreCmd.PersistentFlags().StringVarP(&flagPersist, "persist", "", "", "directory to use for a database") +} + func addCommands() { RootCmd.AddCommand(batchCmd) RootCmd.AddCommand(consoleCmd) @@ -150,8 +156,12 @@ func addCommands() { // examples addCounterFlags() RootCmd.AddCommand(counterCmd) + // deprecated, left for backwards compatibility addDummyFlags() RootCmd.AddCommand(dummyCmd) + // replaces dummy, see issue #196 + addKVStoreFlags() + RootCmd.AddCommand(kvstoreCmd) } var batchCmd = &cobra.Command{ @@ -285,13 +295,25 @@ var counterCmd = &cobra.Command{ }, } +// deprecated, left for backwards compatibility var dummyCmd = &cobra.Command{ - Use: "dummy", + Use: "dummy", + Deprecated: "use: [abci-cli kvstore] instead", + Short: "ABCI demo example", + Long: "ABCI demo example", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + return cmdKVStore(cmd, args) + }, +} + +var kvstoreCmd = &cobra.Command{ + Use: "kvstore", Short: "ABCI demo example", Long: "ABCI demo example", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - return cmdDummy(cmd, args) + return cmdKVStore(cmd, args) }, } @@ -654,16 +676,16 @@ func cmdCounter(cmd *cobra.Command, args []string) error { return nil } -func cmdDummy(cmd *cobra.Command, args []string) error { +func cmdKVStore(cmd *cobra.Command, args []string) error { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) // Create the application - in memory or persisted to disk var app types.Application if flagPersist == "" { - app = dummy.NewDummyApplication() + app = kvstore.NewDummyApplication() } else { - app = dummy.NewPersistentDummyApplication(flagPersist) - app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy")) + app = kvstore.NewPersistentDummyApplication(flagPersist) + app.(*kvstore.PersistentDummyApplication).SetLogger(logger.With("module", "kvstore")) } // Start the listener diff --git a/example/example_test.go b/example/example_test.go index dfa38a398..513c28799 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -16,14 +16,14 @@ import ( abcicli "github.com/tendermint/abci/client" "github.com/tendermint/abci/example/code" - "github.com/tendermint/abci/example/dummy" + "github.com/tendermint/abci/example/kvstore" abciserver "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" ) -func TestDummy(t *testing.T) { - fmt.Println("### Testing Dummy") - testStream(t, dummy.NewDummyApplication()) +func TestKVStore(t *testing.T) { + fmt.Println("### Testing KVStore") + testStream(t, dummy.NewKVStoreApplication()) } func TestBaseApp(t *testing.T) { diff --git a/example/dummy/README.md b/example/kvstore/README.md similarity index 75% rename from example/dummy/README.md rename to example/kvstore/README.md index 8c1f0f042..e988eadb0 100644 --- a/example/dummy/README.md +++ b/example/kvstore/README.md @@ -1,17 +1,17 @@ -# Dummy +# KVStore -There are two app's here: the DummyApplication and the PersistentDummyApplication. +There are two app's here: the KVStoreApplication and the PersistentKVStoreApplication. -## DummyApplication +## KVStoreApplication -The DummyApplication is a simple merkle key-value store. +The KVStoreApplication is a simple merkle key-value store. Transactions of the form `key=value` are stored as key-value pairs in the tree. Transactions without an `=` sign set the value to the key. The app has no replay protection (other than what the mempool provides). -## PersistentDummyApplication +## PersistentKVStoreApplication -The PersistentDummyApplication wraps the DummyApplication +The PersistentKVStoreApplication wraps the KVStoreApplication and provides two additional features: 1) persistence of state across app restarts (using Tendermint's ABCI-Handshake mechanism) diff --git a/example/dummy/dummy.go b/example/kvstore/dummy.go similarity index 79% rename from example/dummy/dummy.go rename to example/kvstore/dummy.go index 79aa43978..4ccbc56b0 100644 --- a/example/dummy/dummy.go +++ b/example/kvstore/dummy.go @@ -1,4 +1,4 @@ -package dummy +package kvstore import ( "bytes" @@ -51,25 +51,25 @@ func prefixKey(key []byte) []byte { //--------------------------------------------------- -var _ types.Application = (*DummyApplication)(nil) +var _ types.Application = (*KVStoreApplication)(nil) -type DummyApplication struct { +type KVStoreApplication struct { types.BaseApplication state State } -func NewDummyApplication() *DummyApplication { +func NewKVStoreApplication() *KVStoreApplication { state := loadState(dbm.NewMemDB()) - return &DummyApplication{state: state} + return &KVStoreApplication{state: state} } -func (app *DummyApplication) Info(req types.RequestInfo) (resInfo types.ResponseInfo) { +func (app *KVStoreApplication) Info(req types.RequestInfo) (resInfo types.ResponseInfo) { return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size)} } // tx is either "key=value" or just arbitrary bytes -func (app *DummyApplication) DeliverTx(tx []byte) types.ResponseDeliverTx { +func (app *KVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx { var key, value []byte parts := bytes.Split(tx, []byte("=")) if len(parts) == 2 { @@ -87,11 +87,11 @@ func (app *DummyApplication) DeliverTx(tx []byte) types.ResponseDeliverTx { return types.ResponseDeliverTx{Code: code.CodeTypeOK, Tags: tags} } -func (app *DummyApplication) CheckTx(tx []byte) types.ResponseCheckTx { +func (app *KVStoreApplication) CheckTx(tx []byte) types.ResponseCheckTx { return types.ResponseCheckTx{Code: code.CodeTypeOK} } -func (app *DummyApplication) Commit() types.ResponseCommit { +func (app *KVStoreApplication) Commit() types.ResponseCommit { // Using a memdb - just return the big endian size of the db appHash := make([]byte, 8) binary.PutVarint(appHash, app.state.Size) @@ -101,7 +101,7 @@ func (app *DummyApplication) Commit() types.ResponseCommit { return types.ResponseCommit{Data: appHash} } -func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) { +func (app *KVStoreApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) { if reqQuery.Prove { value := app.state.db.Get(prefixKey(reqQuery.Data)) resQuery.Index = -1 // TODO make Proof return index diff --git a/example/dummy/dummy_test.go b/example/kvstore/dummy_test.go similarity index 76% rename from example/dummy/dummy_test.go rename to example/kvstore/dummy_test.go index 548fe7422..b3d29ffb0 100644 --- a/example/dummy/dummy_test.go +++ b/example/kvstore/dummy_test.go @@ -1,4 +1,4 @@ -package dummy +package kvstore import ( "bytes" @@ -17,7 +17,7 @@ import ( "github.com/tendermint/abci/types" ) -func testDummy(t *testing.T, app types.Application, tx []byte, key, value string) { +func testKVStore(t *testing.T, app types.Application, tx []byte, key, value string) { ar := app.DeliverTx(tx) require.False(t, ar.IsErr(), ar) // repeating tx doesn't raise error @@ -42,44 +42,44 @@ func testDummy(t *testing.T, app types.Application, tx []byte, key, value string require.Equal(t, value, string(resQuery.Value)) } -func TestDummyKV(t *testing.T) { - dummy := NewDummyApplication() +func TestKVStoreKV(t *testing.T) { + kvstore := NewKVStoreApplication() key := "abc" value := key tx := []byte(key) - testDummy(t, dummy, tx, key, value) + testKVStore(t, kvstore, tx, key, value) value = "def" tx = []byte(key + "=" + value) - testDummy(t, dummy, tx, key, value) + testKVStore(t, kvstore, tx, key, value) } -func TestPersistentDummyKV(t *testing.T) { - dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO +func TestPersistentKVStoreKV(t *testing.T) { + dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO if err != nil { t.Fatal(err) } - dummy := NewPersistentDummyApplication(dir) + kvstore := NewPersistentKVStoreApplication(dir) key := "abc" value := key tx := []byte(key) - testDummy(t, dummy, tx, key, value) + testKVStore(t, kvstore, tx, key, value) value = "def" tx = []byte(key + "=" + value) - testDummy(t, dummy, tx, key, value) + testKVStore(t, kvstore, tx, key, value) } -func TestPersistentDummyInfo(t *testing.T) { - dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO +func TestPersistentKVStoreInfo(t *testing.T) { + dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO if err != nil { t.Fatal(err) } - dummy := NewPersistentDummyApplication(dir) - InitDummy(dummy) + kvstore := NewPersistentKVStoreApplication(dir) + InitKVStore(kvstore) height := int64(0) - resInfo := dummy.Info(types.RequestInfo{}) + resInfo := kvstore.Info(types.RequestInfo{}) if resInfo.LastBlockHeight != height { t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight) } @@ -90,11 +90,11 @@ func TestPersistentDummyInfo(t *testing.T) { header := types.Header{ Height: int64(height), } - dummy.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil}) - dummy.EndBlock(types.RequestEndBlock{header.Height}) - dummy.Commit() + kvstore.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil}) + kvstore.EndBlock(types.RequestEndBlock{header.Height}) + kvstore.Commit() - resInfo = dummy.Info(types.RequestInfo{}) + resInfo = kvstore.Info(types.RequestInfo{}) if resInfo.LastBlockHeight != height { t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight) } @@ -103,22 +103,22 @@ func TestPersistentDummyInfo(t *testing.T) { // add a validator, remove a validator, update a validator func TestValUpdates(t *testing.T) { - dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO + dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO if err != nil { t.Fatal(err) } - dummy := NewPersistentDummyApplication(dir) + kvstore := NewPersistentKVStoreApplication(dir) // init with some validators total := 10 nInit := 5 vals := RandVals(total) // iniitalize with the first nInit - dummy.InitChain(types.RequestInitChain{ + kvstore.InitChain(types.RequestInitChain{ Validators: vals[:nInit], }) - vals1, vals2 := vals[:nInit], dummy.Validators() + vals1, vals2 := vals[:nInit], kvstore.Validators() valsEqual(t, vals1, vals2) var v1, v2, v3 types.Validator @@ -129,9 +129,9 @@ func TestValUpdates(t *testing.T) { tx1 := MakeValSetChangeTx(v1.PubKey, v1.Power) tx2 := MakeValSetChangeTx(v2.PubKey, v2.Power) - makeApplyBlock(t, dummy, 1, diff, tx1, tx2) + makeApplyBlock(t, kvstore, 1, diff, tx1, tx2) - vals1, vals2 = vals[:nInit+2], dummy.Validators() + vals1, vals2 = vals[:nInit+2], kvstore.Validators() valsEqual(t, vals1, vals2) // remove some validators @@ -144,10 +144,10 @@ func TestValUpdates(t *testing.T) { tx2 = MakeValSetChangeTx(v2.PubKey, v2.Power) tx3 := MakeValSetChangeTx(v3.PubKey, v3.Power) - makeApplyBlock(t, dummy, 2, diff, tx1, tx2, tx3) + makeApplyBlock(t, kvstore, 2, diff, tx1, tx2, tx3) vals1 = append(vals[:nInit-2], vals[nInit+1]) - vals2 = dummy.Validators() + vals2 = kvstore.Validators() valsEqual(t, vals1, vals2) // update some validators @@ -160,15 +160,15 @@ func TestValUpdates(t *testing.T) { diff = []types.Validator{v1} tx1 = MakeValSetChangeTx(v1.PubKey, v1.Power) - makeApplyBlock(t, dummy, 3, diff, tx1) + makeApplyBlock(t, kvstore, 3, diff, tx1) vals1 = append([]types.Validator{v1}, vals1[1:]...) - vals2 = dummy.Validators() + vals2 = kvstore.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, kvstore types.Application, heightInt int, diff []types.Validator, txs ...[]byte) { // make and apply block height := int64(heightInt) hash := []byte("foo") @@ -176,14 +176,14 @@ func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff [ Height: height, } - dummy.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil}) + kvstore.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil}) for _, tx := range txs { - if r := dummy.DeliverTx(tx); r.IsErr() { + if r := kvstore.DeliverTx(tx); r.IsErr() { t.Fatal(r) } } - resEndBlock := dummy.EndBlock(types.RequestEndBlock{header.Height}) - dummy.Commit() + resEndBlock := kvstore.EndBlock(types.RequestEndBlock{header.Height}) + kvstore.Commit() valsEqual(t, diff, resEndBlock.ValidatorUpdates) @@ -250,8 +250,8 @@ func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, c func TestClientServer(t *testing.T) { // set up socket app - dummy := NewDummyApplication() - client, server, err := makeSocketClientServer(dummy, "dummy-socket") + kvstore := NewKVStoreApplication() + client, server, err := makeSocketClientServer(kvstore, "kvstore-socket") require.Nil(t, err) defer server.Stop() defer client.Stop() @@ -259,8 +259,8 @@ func TestClientServer(t *testing.T) { runClientTests(t, client) // set up grpc app - dummy = NewDummyApplication() - gclient, gserver, err := makeGRPCClientServer(dummy, "dummy-grpc") + kvstore = NewKVStoreApplication() + gclient, gserver, err := makeGRPCClientServer(kvstore, "kvstore-grpc") require.Nil(t, err) defer gserver.Stop() defer gclient.Stop() diff --git a/example/dummy/helpers.go b/example/kvstore/helpers.go similarity index 87% rename from example/dummy/helpers.go rename to example/kvstore/helpers.go index 927319867..154d33ebc 100644 --- a/example/dummy/helpers.go +++ b/example/kvstore/helpers.go @@ -1,4 +1,4 @@ -package dummy +package kvstore import ( "github.com/tendermint/abci/types" @@ -25,10 +25,10 @@ func RandVals(cnt int) []types.Validator { return res } -// InitDummy initializes the dummy app with some data, +// InitKVStore initializes the dummy app with some data, // which allows tests to pass and is fine as long as you // don't make any tx that modify the validator state -func InitDummy(app *PersistentDummyApplication) { +func InitKVStore(app *PersistentKVStoreApplication) { app.InitChain(types.RequestInitChain{ Validators: RandVals(1), AppStateBytes: []byte("[]"), diff --git a/example/dummy/persistent_dummy.go b/example/kvstore/persistent_dummy.go similarity index 73% rename from example/dummy/persistent_dummy.go rename to example/kvstore/persistent_dummy.go index 30885bc1e..888258ff5 100644 --- a/example/dummy/persistent_dummy.go +++ b/example/kvstore/persistent_dummy.go @@ -1,4 +1,4 @@ -package dummy +package kvstore import ( "bytes" @@ -20,10 +20,10 @@ const ( //----------------------------------------- -var _ types.Application = (*PersistentDummyApplication)(nil) +var _ types.Application = (*PersistentKVStoreApplication)(nil) -type PersistentDummyApplication struct { - app *DummyApplication +type PersistentKVStoreApplication struct { + app *KVStoreApplication // validator set ValUpdates []types.Validator @@ -31,8 +31,8 @@ type PersistentDummyApplication struct { logger log.Logger } -func NewPersistentDummyApplication(dbDir string) *PersistentDummyApplication { - name := "dummy" +func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication { + name := "kvstore" db, err := dbm.NewGoLevelDB(name, dbDir) if err != nil { panic(err) @@ -40,29 +40,29 @@ func NewPersistentDummyApplication(dbDir string) *PersistentDummyApplication { state := loadState(db) - return &PersistentDummyApplication{ - app: &DummyApplication{state: state}, + return &PersistentKVStoreApplication{ + app: &KVStoreApplication{state: state}, logger: log.NewNopLogger(), } } -func (app *PersistentDummyApplication) SetLogger(l log.Logger) { +func (app *PersistentKVStoreApplication) SetLogger(l log.Logger) { app.logger = l } -func (app *PersistentDummyApplication) Info(req types.RequestInfo) types.ResponseInfo { +func (app *PersistentKVStoreApplication) Info(req types.RequestInfo) types.ResponseInfo { res := app.app.Info(req) res.LastBlockHeight = app.app.state.Height res.LastBlockAppHash = app.app.state.AppHash return res } -func (app *PersistentDummyApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption { +func (app *PersistentKVStoreApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption { return app.app.SetOption(req) } // tx is either "val:pubkey/power" or "key=value" or just arbitrary bytes -func (app *PersistentDummyApplication) DeliverTx(tx []byte) types.ResponseDeliverTx { +func (app *PersistentKVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx { // if it starts with "val:", update the validator set // format is "val:pubkey/power" if isValidatorTx(tx) { @@ -75,21 +75,21 @@ func (app *PersistentDummyApplication) DeliverTx(tx []byte) types.ResponseDelive return app.app.DeliverTx(tx) } -func (app *PersistentDummyApplication) CheckTx(tx []byte) types.ResponseCheckTx { +func (app *PersistentKVStoreApplication) CheckTx(tx []byte) types.ResponseCheckTx { return app.app.CheckTx(tx) } // Commit will panic if InitChain was not called -func (app *PersistentDummyApplication) Commit() types.ResponseCommit { +func (app *PersistentKVStoreApplication) Commit() types.ResponseCommit { return app.app.Commit() } -func (app *PersistentDummyApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery { +func (app *PersistentKVStoreApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery { return app.app.Query(reqQuery) } // Save the validators in the merkle tree -func (app *PersistentDummyApplication) InitChain(req types.RequestInitChain) types.ResponseInitChain { +func (app *PersistentKVStoreApplication) InitChain(req types.RequestInitChain) types.ResponseInitChain { for _, v := range req.Validators { r := app.updateValidator(v) if r.IsErr() { @@ -100,21 +100,21 @@ func (app *PersistentDummyApplication) InitChain(req types.RequestInitChain) typ } // Track the block hash and header information -func (app *PersistentDummyApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock { +func (app *PersistentKVStoreApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock { // reset valset changes app.ValUpdates = make([]types.Validator, 0) return types.ResponseBeginBlock{} } // Update the validator set -func (app *PersistentDummyApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock { +func (app *PersistentKVStoreApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock { return types.ResponseEndBlock{ValidatorUpdates: app.ValUpdates} } //--------------------------------------------- // update validators -func (app *PersistentDummyApplication) Validators() (validators []types.Validator) { +func (app *PersistentKVStoreApplication) Validators() (validators []types.Validator) { itr := app.app.state.db.Iterator(nil, nil) for ; itr.Valid(); itr.Next() { if isValidatorTx(itr.Key()) { @@ -138,7 +138,7 @@ func isValidatorTx(tx []byte) bool { } // format is "val:pubkey1/power1,addr2/power2,addr3/power3"tx -func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.ResponseDeliverTx { +func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.ResponseDeliverTx { tx = tx[len(ValidatorSetChangePrefix):] //get the pubkey and power @@ -177,7 +177,7 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Response } // add, update, or remove a validator -func (app *PersistentDummyApplication) updateValidator(v types.Validator) types.ResponseDeliverTx { +func (app *PersistentKVStoreApplication) updateValidator(v types.Validator) types.ResponseDeliverTx { key := []byte("val:" + string(v.PubKey)) if v.Power == 0 { // remove validator diff --git a/tests/client_server_test.go b/tests/client_server_test.go index 3d74478bc..3e1e3e1cd 100644 --- a/tests/client_server_test.go +++ b/tests/client_server_test.go @@ -6,14 +6,14 @@ import ( "github.com/stretchr/testify/assert" abciclient "github.com/tendermint/abci/client" - "github.com/tendermint/abci/example/dummy" + "github.com/tendermint/abci/example/kvstore" abciserver "github.com/tendermint/abci/server" ) func TestClientServerNoAddrPrefix(t *testing.T) { addr := "localhost:46658" transport := "socket" - app := dummy.NewDummyApplication() + app := kvstore.NewKVStoreApplication() server, err := abciserver.NewServer(addr, transport, app) assert.NoError(t, err, "expected no error on NewServer") From 594db8606947a6ee3e97a45001f060d555640955 Mon Sep 17 00:00:00 2001 From: zramsay Date: Mon, 19 Feb 2018 20:39:36 +0000 Subject: [PATCH 2/3] rename dummy*.go files to kvstore*.go --- cmd/abci-cli/abci-cli.go | 6 +++--- example/kvstore/{dummy.go => kvstore.go} | 0 example/kvstore/{dummy_test.go => kvstore_test.go} | 0 .../kvstore/{persistent_dummy.go => persistent_kvstore.go} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename example/kvstore/{dummy.go => kvstore.go} (100%) rename example/kvstore/{dummy_test.go => kvstore_test.go} (100%) rename example/kvstore/{persistent_dummy.go => persistent_kvstore.go} (100%) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index 5204137ce..4dc5e96e3 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -682,10 +682,10 @@ func cmdKVStore(cmd *cobra.Command, args []string) error { // Create the application - in memory or persisted to disk var app types.Application if flagPersist == "" { - app = kvstore.NewDummyApplication() + app = kvstore.NewKVStoreApplication() } else { - app = kvstore.NewPersistentDummyApplication(flagPersist) - app.(*kvstore.PersistentDummyApplication).SetLogger(logger.With("module", "kvstore")) + app = kvstore.NewPersistentKVStoreApplication(flagPersist) + app.(*kvstore.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore")) } // Start the listener diff --git a/example/kvstore/dummy.go b/example/kvstore/kvstore.go similarity index 100% rename from example/kvstore/dummy.go rename to example/kvstore/kvstore.go diff --git a/example/kvstore/dummy_test.go b/example/kvstore/kvstore_test.go similarity index 100% rename from example/kvstore/dummy_test.go rename to example/kvstore/kvstore_test.go diff --git a/example/kvstore/persistent_dummy.go b/example/kvstore/persistent_kvstore.go similarity index 100% rename from example/kvstore/persistent_dummy.go rename to example/kvstore/persistent_kvstore.go From 831e10f15d36462b8524e4f520f97fc9c4bf6ddf Mon Sep 17 00:00:00 2001 From: zramsay Date: Mon, 19 Feb 2018 20:43:36 +0000 Subject: [PATCH 3/3] finish the job, dummy --- README.md | 6 +++--- example/example_test.go | 2 +- example/kvstore/helpers.go | 2 +- tests/test_cli/test.sh | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e733dea71..ed382930b 100644 --- a/README.md +++ b/README.md @@ -133,10 +133,10 @@ func cmdKVStore(cmd *cobra.Command, args []string) error { // Create the application - in memory or persisted to disk var app types.Application if flagPersist == "" { - app = dummy.NewKVStoreApplication() + app = kvstore.NewKVStoreApplication() } else { - app = dummy.NewPersistentKVStoreApplication(flagPersist) - app.(*dummy.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore")) + app = kvstore.NewPersistentKVStoreApplication(flagPersist) + app.(*kvstore.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore")) } // Start the listener diff --git a/example/example_test.go b/example/example_test.go index 513c28799..3fc38f492 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -23,7 +23,7 @@ import ( func TestKVStore(t *testing.T) { fmt.Println("### Testing KVStore") - testStream(t, dummy.NewKVStoreApplication()) + testStream(t, kvstore.NewKVStoreApplication()) } func TestBaseApp(t *testing.T) { diff --git a/example/kvstore/helpers.go b/example/kvstore/helpers.go index 154d33ebc..c71e371a9 100644 --- a/example/kvstore/helpers.go +++ b/example/kvstore/helpers.go @@ -25,7 +25,7 @@ func RandVals(cnt int) []types.Validator { return res } -// InitKVStore initializes the dummy app with some data, +// InitKVStore initializes the kvstore app with some data, // which allows tests to pass and is fine as long as you // don't make any tx that modify the validator state func InitKVStore(app *PersistentKVStoreApplication) { diff --git a/tests/test_cli/test.sh b/tests/test_cli/test.sh index ccbb313c5..ce074f513 100755 --- a/tests/test_cli/test.sh +++ b/tests/test_cli/test.sh @@ -35,7 +35,7 @@ function testExample() { rm "${INPUT}".out.new } -testExample 1 tests/test_cli/ex1.abci abci-cli dummy +testExample 1 tests/test_cli/ex1.abci abci-cli kvstore testExample 2 tests/test_cli/ex2.abci abci-cli counter echo ""