Browse Source

shame: forgot to add new code pkg

pull/1780/head
Ethan Buchman 7 years ago
parent
commit
550d6a6081
6 changed files with 35 additions and 20 deletions
  1. +9
    -0
      example/code/code.go
  2. +4
    -4
      example/counter/counter.go
  3. +4
    -3
      example/dummy/dummy.go
  4. +10
    -7
      example/dummy/dummy_test.go
  5. +2
    -2
      example/dummy/persistent_dummy.go
  6. +6
    -4
      example/example_test.go

+ 9
- 0
example/code/code.go View File

@ -0,0 +1,9 @@
package code
// Return codes for the examples
const (
CodeTypeOK uint32 = 0
CodeTypeEncodingError uint32 = 1
CodeTypeBadNonce uint32 = 2
CodeTypeUnauthorized uint32 = 3
)

+ 4
- 4
example/counter/counter.go View File

@ -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 {


+ 4
- 3
example/dummy/dummy.go View File

@ -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) {


+ 10
- 7
example/dummy/dummy_test.go View File

@ -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)


+ 2
- 2
example/dummy/persistent_dummy.go View File

@ -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}
}

+ 6
- 4
example/example_test.go View File

@ -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 {


Loading…
Cancel
Save