shame: forgot to add new code pkg
This commit is contained in:
parent
81e4effbdb
commit
550d6a6081
|
@ -0,0 +1,9 @@
|
||||||
|
package code
|
||||||
|
|
||||||
|
// Return codes for the examples
|
||||||
|
const (
|
||||||
|
CodeTypeOK uint32 = 0
|
||||||
|
CodeTypeEncodingError uint32 = 1
|
||||||
|
CodeTypeBadNonce uint32 = 2
|
||||||
|
CodeTypeUnauthorized uint32 = 3
|
||||||
|
)
|
|
@ -50,7 +50,7 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.txCount++
|
app.txCount++
|
||||||
return types.ResponseDeliverTx{Code: types.CodeTypeOK}
|
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx {
|
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)}
|
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) {
|
func (app *CounterApplication) Commit() (resp types.ResponseCommit) {
|
||||||
app.hashCount++
|
app.hashCount++
|
||||||
if app.txCount == 0 {
|
if app.txCount == 0 {
|
||||||
return types.ResponseCommit{Code: types.CodeTypeOK}
|
return types.ResponseCommit{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
hash := make([]byte, 8)
|
hash := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
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 {
|
func (app *CounterApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/tendermint/abci/example/code"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
wire "github.com/tendermint/go-wire"
|
wire "github.com/tendermint/go-wire"
|
||||||
"github.com/tendermint/iavl"
|
"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.creator", ValueType: types.KVPair_STRING, ValueString: "jae"},
|
||||||
{Key: "app.key", ValueType: types.KVPair_STRING, ValueString: string(key)},
|
{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 {
|
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 {
|
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) {
|
func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
|
||||||
|
|
|
@ -7,12 +7,15 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"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"
|
"github.com/tendermint/iavl"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"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) {
|
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",
|
Path: "/store",
|
||||||
Data: []byte(key),
|
Data: []byte(key),
|
||||||
})
|
})
|
||||||
require.Equal(t, types.CodeTypeOK, resQuery.Code)
|
require.Equal(t, code.CodeTypeOK, resQuery.Code)
|
||||||
require.Equal(t, value, string(resQuery.Value))
|
require.Equal(t, value, string(resQuery.Value))
|
||||||
|
|
||||||
// make sure proof is fine
|
// 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),
|
Data: []byte(key),
|
||||||
Prove: true,
|
Prove: true,
|
||||||
})
|
})
|
||||||
require.EqualValues(t, types.CodeTypeOK, resQuery.Code)
|
require.EqualValues(t, code.CodeTypeOK, resQuery.Code)
|
||||||
require.Equal(t, value, string(resQuery.Value))
|
require.Equal(t, value, string(resQuery.Value))
|
||||||
proof, err := iavl.ReadKeyExistsProof(resQuery.Proof)
|
proof, err := iavl.ReadKeyExistsProof(resQuery.Proof)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
@ -295,7 +298,7 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
|
||||||
Data: []byte(key),
|
Data: []byte(key),
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
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))
|
require.Equal(t, value, string(resQuery.Value))
|
||||||
|
|
||||||
// make sure proof is fine
|
// make sure proof is fine
|
||||||
|
@ -305,7 +308,7 @@ func testClient(t *testing.T, app abcicli.Client, tx []byte, key, value string)
|
||||||
Prove: true,
|
Prove: true,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
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))
|
require.Equal(t, value, string(resQuery.Value))
|
||||||
proof, err := iavl.ReadKeyExistsProof(resQuery.Proof)
|
proof, err := iavl.ReadKeyExistsProof(resQuery.Proof)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
|
@ -97,7 +97,7 @@ func (app *PersistentDummyApplication) Commit() types.ResponseCommit {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.logger.Info("Commit block", "height", height, "root", appHash)
|
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 {
|
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
|
// we only update the changes array if we successfully updated the tree
|
||||||
app.changes = append(app.changes, v)
|
app.changes = append(app.changes, v)
|
||||||
|
|
||||||
return types.ResponseDeliverTx{Code: types.CodeTypeOK}
|
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,14 @@ import (
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
abcicli "github.com/tendermint/abci/client"
|
abcicli "github.com/tendermint/abci/client"
|
||||||
|
"github.com/tendermint/abci/example/code"
|
||||||
"github.com/tendermint/abci/example/dummy"
|
"github.com/tendermint/abci/example/dummy"
|
||||||
abciserver "github.com/tendermint/abci/server"
|
abciserver "github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
|
||||||
"github.com/tendermint/tmlibs/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDummy(t *testing.T) {
|
func TestDummy(t *testing.T) {
|
||||||
|
@ -60,7 +62,7 @@ func testStream(t *testing.T, app types.Application) {
|
||||||
switch r := res.Value.(type) {
|
switch r := res.Value.(type) {
|
||||||
case *types.Response_DeliverTx:
|
case *types.Response_DeliverTx:
|
||||||
counter++
|
counter++
|
||||||
if r.DeliverTx.Code != types.CodeTypeOK {
|
if r.DeliverTx.Code != code.CodeTypeOK {
|
||||||
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
|
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
|
||||||
}
|
}
|
||||||
if counter > numDeliverTxs {
|
if counter > numDeliverTxs {
|
||||||
|
@ -135,7 +137,7 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
|
||||||
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
|
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
|
||||||
}
|
}
|
||||||
counter++
|
counter++
|
||||||
if response.Code != types.CodeTypeOK {
|
if response.Code != code.CodeTypeOK {
|
||||||
t.Error("DeliverTx failed with ret_code", response.Code)
|
t.Error("DeliverTx failed with ret_code", response.Code)
|
||||||
}
|
}
|
||||||
if counter > numDeliverTxs {
|
if counter > numDeliverTxs {
|
||||||
|
|
Loading…
Reference in New Issue