Browse Source

example/kvstore: return ABCI query height (#4509)

* example/kvstore: return ABCI query height

* CHANGELOG: added PR link

* Updated tests
pull/4511/head
Erik Grinaker 5 years ago
committed by GitHub
parent
commit
c33576e72a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 6 deletions
  1. +3
    -2
      CHANGELOG_PENDING.md
  2. +2
    -0
      abci/example/kvstore/kvstore.go
  3. +20
    -0
      abci/example/kvstore/kvstore_test.go
  4. +2
    -2
      abci/tests/test_cli/ex1.abci.out
  5. +2
    -2
      docs/app-dev/abci-cli.md

+ 3
- 2
CHANGELOG_PENDING.md View File

@ -4,8 +4,7 @@
Special thanks to external contributors on this release: Special thanks to external contributors on this release:
Friendly reminder, we have a [bug bounty
program](https://hackerone.com/tendermint).
Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermint).
### BREAKING CHANGES: ### BREAKING CHANGES:
@ -21,6 +20,8 @@ program](https://hackerone.com/tendermint).
- [types] [\#4417](https://github.com/tendermint/tendermint/issues/4417) VerifyCommitX() functions should return as soon as +2/3 threashold is reached. - [types] [\#4417](https://github.com/tendermint/tendermint/issues/4417) VerifyCommitX() functions should return as soon as +2/3 threashold is reached.
- [examples/kvstore] [\#4509](https://github.com/tendermint/tendermint/pull/4509) ABCI query now returns the proper height (@erikgrinaker)
### BUG FIXES: ### BUG FIXES:
- [rpc] [\#4493](https://github.com/tendermint/tendermint/pull/4493) Keep the original subscription "id" field when new RPCs come in (@michaelfig) - [rpc] [\#4493](https://github.com/tendermint/tendermint/pull/4493) Keep the original subscription "id" field when new RPCs come in (@michaelfig)


+ 2
- 0
abci/example/kvstore/kvstore.go View File

@ -136,6 +136,7 @@ func (app *Application) Query(reqQuery types.RequestQuery) (resQuery types.Respo
resQuery.Index = -1 // TODO make Proof return index resQuery.Index = -1 // TODO make Proof return index
resQuery.Key = reqQuery.Data resQuery.Key = reqQuery.Data
resQuery.Value = value resQuery.Value = value
resQuery.Height = app.state.Height
return return
} }
@ -151,6 +152,7 @@ func (app *Application) Query(reqQuery types.RequestQuery) (resQuery types.Respo
resQuery.Log = "exists" resQuery.Log = "exists"
} }
resQuery.Value = value resQuery.Value = value
resQuery.Height = app.state.Height
return resQuery return resQuery
} }

+ 20
- 0
abci/example/kvstore/kvstore_test.go View File

@ -30,6 +30,11 @@ func testKVStore(t *testing.T, app types.Application, tx []byte, key, value stri
// repeating tx doesn't raise error // repeating tx doesn't raise error
ar = app.DeliverTx(req) ar = app.DeliverTx(req)
require.False(t, ar.IsErr(), ar) require.False(t, ar.IsErr(), ar)
// commit
app.Commit()
info := app.Info(types.RequestInfo{})
require.NotZero(t, info.LastBlockHeight)
// make sure query is fine // make sure query is fine
resQuery := app.Query(types.RequestQuery{ resQuery := app.Query(types.RequestQuery{
@ -37,7 +42,9 @@ func testKVStore(t *testing.T, app types.Application, tx []byte, key, value stri
Data: []byte(key), Data: []byte(key),
}) })
require.Equal(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, code.CodeTypeOK, resQuery.Code)
require.Equal(t, key, string(resQuery.Key))
require.Equal(t, value, string(resQuery.Value)) require.Equal(t, value, string(resQuery.Value))
require.EqualValues(t, info.LastBlockHeight, resQuery.Height)
// make sure proof is fine // make sure proof is fine
resQuery = app.Query(types.RequestQuery{ resQuery = app.Query(types.RequestQuery{
@ -46,7 +53,9 @@ func testKVStore(t *testing.T, app types.Application, tx []byte, key, value stri
Prove: true, Prove: true,
}) })
require.EqualValues(t, code.CodeTypeOK, resQuery.Code) require.EqualValues(t, code.CodeTypeOK, resQuery.Code)
require.Equal(t, key, string(resQuery.Key))
require.Equal(t, value, string(resQuery.Value)) require.Equal(t, value, string(resQuery.Value))
require.EqualValues(t, info.LastBlockHeight, resQuery.Height)
} }
func TestKVStoreKV(t *testing.T) { func TestKVStoreKV(t *testing.T) {
@ -300,6 +309,13 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
ar, err = app.DeliverTxSync(types.RequestDeliverTx{Tx: tx}) ar, err = app.DeliverTxSync(types.RequestDeliverTx{Tx: tx})
require.NoError(t, err) require.NoError(t, err)
require.False(t, ar.IsErr(), ar) require.False(t, ar.IsErr(), ar)
// commit
_, err = app.CommitSync()
require.NoError(t, err)
info, err := app.InfoSync(types.RequestInfo{})
require.NoError(t, err)
require.NotZero(t, info.LastBlockHeight)
// make sure query is fine // make sure query is fine
resQuery, err := app.QuerySync(types.RequestQuery{ resQuery, err := app.QuerySync(types.RequestQuery{
@ -308,7 +324,9 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
}) })
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, code.CodeTypeOK, resQuery.Code)
require.Equal(t, key, string(resQuery.Key))
require.Equal(t, value, string(resQuery.Value)) require.Equal(t, value, string(resQuery.Value))
require.EqualValues(t, info.LastBlockHeight, resQuery.Height)
// make sure proof is fine // make sure proof is fine
resQuery, err = app.QuerySync(types.RequestQuery{ resQuery, err = app.QuerySync(types.RequestQuery{
@ -318,5 +336,7 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
}) })
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, code.CodeTypeOK, resQuery.Code) require.Equal(t, code.CodeTypeOK, resQuery.Code)
require.Equal(t, key, string(resQuery.Key))
require.Equal(t, value, string(resQuery.Value)) require.Equal(t, value, string(resQuery.Value))
require.EqualValues(t, info.LastBlockHeight, resQuery.Height)
} }

+ 2
- 2
abci/tests/test_cli/ex1.abci.out View File

@ -27,7 +27,7 @@
> query "abc" > query "abc"
-> code: OK -> code: OK
-> log: exists -> log: exists
-> height: 0
-> height: 2
-> key: abc -> key: abc
-> key.hex: 616263 -> key.hex: 616263
-> value: abc -> value: abc
@ -43,7 +43,7 @@
> query "def" > query "def"
-> code: OK -> code: OK
-> log: exists -> log: exists
-> height: 0
-> height: 3
-> key: def -> key: def
-> key.hex: 646566 -> key.hex: 646566
-> value: xyz -> value: xyz


+ 2
- 2
docs/app-dev/abci-cli.md View File

@ -192,7 +192,7 @@ Try running these commands:
> query "abc" > query "abc"
-> code: OK -> code: OK
-> log: exists -> log: exists
-> height: 0
-> height: 2
-> value: abc -> value: abc
-> value.hex: 616263 -> value.hex: 616263
@ -206,7 +206,7 @@ Try running these commands:
> query "def" > query "def"
-> code: OK -> code: OK
-> log: exists -> log: exists
-> height: 0
-> height: 3
-> value: xyz -> value: xyz
-> value.hex: 78797A -> value.hex: 78797A
``` ```


Loading…
Cancel
Save