mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 07:12:16 +00:00
update for new abci int types
This commit is contained in:
parent
c9be2b89f9
commit
9af8da7aad
@ -59,7 +59,7 @@ type validatorStub struct {
|
|||||||
types.PrivValidator
|
types.PrivValidator
|
||||||
}
|
}
|
||||||
|
|
||||||
var testMinPower = 10
|
var testMinPower int64 = 10
|
||||||
|
|
||||||
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
|
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
|
||||||
return &validatorStub{
|
return &validatorStub{
|
||||||
@ -372,7 +372,7 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
|
|||||||
|
|
||||||
// nPeers = nValidators + nNotValidator
|
// nPeers = nValidators + nNotValidator
|
||||||
func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
|
func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
|
||||||
genDoc, privVals := randGenesisDoc(nValidators, false, int64(testMinPower))
|
genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower)
|
||||||
css := make([]*ConsensusState, nPeers)
|
css := make([]*ConsensusState, nPeers)
|
||||||
logger := consensusLogger()
|
logger := consensusLogger()
|
||||||
for i := 0; i < nPeers; i++ {
|
for i := 0; i < nPeers; i++ {
|
||||||
|
@ -8,9 +8,11 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/tendermint/abci/example/code"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -135,7 +137,7 @@ func TestRmBadTx(t *testing.T) {
|
|||||||
// CheckTx should not err, but the app should return a bad abci code
|
// CheckTx should not err, but the app should return a bad abci code
|
||||||
// and the tx should get removed from the pool
|
// and the tx should get removed from the pool
|
||||||
err := cs.mempool.CheckTx(txBytes, func(r *abci.Response) {
|
err := cs.mempool.CheckTx(txBytes, func(r *abci.Response) {
|
||||||
if r.GetCheckTx().Code != abci.CodeType_BadNonce {
|
if r.GetCheckTx().Code != code.CodeTypeBadNonce {
|
||||||
t.Fatalf("expected checktx to return bad nonce, got %v", r)
|
t.Fatalf("expected checktx to return bad nonce, got %v", r)
|
||||||
}
|
}
|
||||||
checkTxRespCh <- struct{}{}
|
checkTxRespCh <- struct{}{}
|
||||||
@ -193,22 +195,22 @@ func (app *CounterApplication) DeliverTx(tx []byte) abci.ResponseDeliverTx {
|
|||||||
txValue := txAsUint64(tx)
|
txValue := txAsUint64(tx)
|
||||||
if txValue != uint64(app.txCount) {
|
if txValue != uint64(app.txCount) {
|
||||||
return abci.ResponseDeliverTx{
|
return abci.ResponseDeliverTx{
|
||||||
Code: abci.CodeType_BadNonce,
|
Code: code.CodeTypeBadNonce,
|
||||||
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
|
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
|
||||||
}
|
}
|
||||||
app.txCount += 1
|
app.txCount += 1
|
||||||
return abci.ResponseDeliverTx{Code: abci.CodeType_OK}
|
return abci.ResponseDeliverTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) CheckTx(tx []byte) abci.ResponseCheckTx {
|
func (app *CounterApplication) CheckTx(tx []byte) abci.ResponseCheckTx {
|
||||||
txValue := txAsUint64(tx)
|
txValue := txAsUint64(tx)
|
||||||
if txValue != uint64(app.mempoolTxCount) {
|
if txValue != uint64(app.mempoolTxCount) {
|
||||||
return abci.ResponseCheckTx{
|
return abci.ResponseCheckTx{
|
||||||
Code: abci.CodeType_BadNonce,
|
Code: code.CodeTypeBadNonce,
|
||||||
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.mempoolTxCount, txValue)}
|
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.mempoolTxCount, txValue)}
|
||||||
}
|
}
|
||||||
app.mempoolTxCount += 1
|
app.mempoolTxCount += 1
|
||||||
return abci.ResponseCheckTx{Code: abci.CodeType_OK}
|
return abci.ResponseCheckTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func txAsUint64(tx []byte) uint64 {
|
func txAsUint64(tx []byte) uint64 {
|
||||||
@ -220,10 +222,10 @@ func txAsUint64(tx []byte) uint64 {
|
|||||||
func (app *CounterApplication) Commit() abci.ResponseCommit {
|
func (app *CounterApplication) Commit() abci.ResponseCommit {
|
||||||
app.mempoolTxCount = app.txCount
|
app.mempoolTxCount = app.txCount
|
||||||
if app.txCount == 0 {
|
if app.txCount == 0 {
|
||||||
return abci.ResponseCommit{Code: abci.CodeType_OK}
|
return abci.ResponseCommit{Code: code.CodeTypeOK}
|
||||||
} else {
|
} else {
|
||||||
hash := make([]byte, 8)
|
hash := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
||||||
return abci.ResponseCommit{Code: abci.CodeType_OK, Data: hash}
|
return abci.ResponseCommit{Code: code.CodeTypeOK, Data: hash}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ func TestValidatorSetChanges(t *testing.T) {
|
|||||||
t.Log("---------------------------- Testing adding one validator")
|
t.Log("---------------------------- Testing adding one validator")
|
||||||
|
|
||||||
newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
|
newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
|
||||||
newValidatorTx1 := dummy.MakeValSetChangeTx(newValidatorPubKey1.Bytes(), uint64(testMinPower))
|
newValidatorTx1 := dummy.MakeValSetChangeTx(newValidatorPubKey1.Bytes(), testMinPower)
|
||||||
|
|
||||||
// wait till everyone makes block 2
|
// wait till everyone makes block 2
|
||||||
// ensure the commit includes all validators
|
// ensure the commit includes all validators
|
||||||
@ -251,10 +251,10 @@ func TestValidatorSetChanges(t *testing.T) {
|
|||||||
t.Log("---------------------------- Testing adding two validators at once")
|
t.Log("---------------------------- Testing adding two validators at once")
|
||||||
|
|
||||||
newValidatorPubKey2 := css[nVals+1].privValidator.GetPubKey()
|
newValidatorPubKey2 := css[nVals+1].privValidator.GetPubKey()
|
||||||
newValidatorTx2 := dummy.MakeValSetChangeTx(newValidatorPubKey2.Bytes(), uint64(testMinPower))
|
newValidatorTx2 := dummy.MakeValSetChangeTx(newValidatorPubKey2.Bytes(), testMinPower)
|
||||||
|
|
||||||
newValidatorPubKey3 := css[nVals+2].privValidator.GetPubKey()
|
newValidatorPubKey3 := css[nVals+2].privValidator.GetPubKey()
|
||||||
newValidatorTx3 := dummy.MakeValSetChangeTx(newValidatorPubKey3.Bytes(), uint64(testMinPower))
|
newValidatorTx3 := dummy.MakeValSetChangeTx(newValidatorPubKey3.Bytes(), testMinPower)
|
||||||
|
|
||||||
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css, newValidatorTx2, newValidatorTx3)
|
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css, newValidatorTx2, newValidatorTx3)
|
||||||
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css)
|
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css)
|
||||||
|
@ -401,5 +401,5 @@ func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mock *mockProxyApp) Commit() abci.ResponseCommit {
|
func (mock *mockProxyApp) Commit() abci.ResponseCommit {
|
||||||
return abci.ResponseCommit{Code: abci.CodeType_OK, Data: mock.appHash}
|
return abci.ResponseCommit{Code: abci.CodeTypeOK, Data: mock.appHash}
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,14 @@ import (
|
|||||||
"github.com/tendermint/abci/example/counter"
|
"github.com/tendermint/abci/example/counter"
|
||||||
"github.com/tendermint/abci/example/dummy"
|
"github.com/tendermint/abci/example/dummy"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -122,10 +124,10 @@ func TestSerialReap(t *testing.T) {
|
|||||||
mempool := newMempoolWithApp(cc)
|
mempool := newMempoolWithApp(cc)
|
||||||
appConnCon, _ := cc.NewABCIClient()
|
appConnCon, _ := cc.NewABCIClient()
|
||||||
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
|
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
|
||||||
if err := appConnCon.Start(); err != nil {
|
err := appConnCon.Start()
|
||||||
t.Fatalf("Error starting ABCI client: %v", err.Error())
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
|
cacheMap := make(map[string]struct{})
|
||||||
deliverTxsRange := func(start, end int) {
|
deliverTxsRange := func(start, end int) {
|
||||||
// Deliver some txs.
|
// Deliver some txs.
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
@ -134,26 +136,23 @@ func TestSerialReap(t *testing.T) {
|
|||||||
txBytes := make([]byte, 8)
|
txBytes := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
||||||
err := mempool.CheckTx(txBytes, nil)
|
err := mempool.CheckTx(txBytes, nil)
|
||||||
if err != nil {
|
_, cached := cacheMap[string(txBytes)]
|
||||||
t.Fatalf("Error after CheckTx: %v", err)
|
if cached {
|
||||||
|
assert.NotNil(t, err, "expected error for cached tx")
|
||||||
|
} else {
|
||||||
|
assert.Nil(t, err, "expected no err for uncached tx")
|
||||||
}
|
}
|
||||||
|
cacheMap[string(txBytes)] = struct{}{}
|
||||||
|
|
||||||
// This will fail because not serial (incrementing)
|
// Duplicates are cached and should return error
|
||||||
// However, error should still be nil.
|
|
||||||
// It just won't show up on Reap().
|
|
||||||
err = mempool.CheckTx(txBytes, nil)
|
err = mempool.CheckTx(txBytes, nil)
|
||||||
if err != nil {
|
assert.NotNil(t, err, "Expected error after CheckTx on duplicated tx")
|
||||||
t.Fatalf("Error after CheckTx: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reapCheck := func(exp int) {
|
reapCheck := func(exp int) {
|
||||||
txs := mempool.Reap(-1)
|
txs := mempool.Reap(-1)
|
||||||
if len(txs) != exp {
|
assert.Equal(t, len(txs), exp, cmn.Fmt("Expected to reap %v txs but got %v", exp, len(txs)))
|
||||||
t.Fatalf("Expected to reap %v txs but got %v", exp, len(txs))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRange := func(start, end int) {
|
updateRange := func(start, end int) {
|
||||||
|
12
node/node.go
12
node/node.go
@ -256,20 +256,20 @@ func NewNode(config *cfg.Config,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resQuery.Code.IsOK() {
|
if resQuery.IsErr() {
|
||||||
return nil
|
return resQuery
|
||||||
}
|
}
|
||||||
return errors.New(resQuery.Code.String())
|
return nil
|
||||||
})
|
})
|
||||||
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
|
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
|
||||||
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
|
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resQuery.Code.IsOK() {
|
if resQuery.IsErr() {
|
||||||
return nil
|
return resQuery
|
||||||
}
|
}
|
||||||
return errors.New(resQuery.Code.String())
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/rpc/client"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
@ -90,7 +91,7 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
|
|||||||
// send async
|
// send async
|
||||||
txres, err := c.BroadcastTxAsync(tx)
|
txres, err := c.BroadcastTxAsync(tx)
|
||||||
require.Nil(err, "%+v", err)
|
require.Nil(err, "%+v", err)
|
||||||
require.True(txres.Code.IsOK())
|
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
|
||||||
|
|
||||||
// and wait for confirmation
|
// and wait for confirmation
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
@ -100,7 +101,7 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
|
|||||||
require.True(ok, "%d: %#v", i, evt)
|
require.True(ok, "%d: %#v", i, evt)
|
||||||
// make sure this is the proper tx
|
// make sure this is the proper tx
|
||||||
require.EqualValues(tx, txe.Tx)
|
require.EqualValues(tx, txe.Tx)
|
||||||
require.True(txe.Result.Code.IsOK())
|
require.True(txe.Result.IsOK())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
|
|||||||
// send sync
|
// send sync
|
||||||
txres, err := c.BroadcastTxSync(tx)
|
txres, err := c.BroadcastTxSync(tx)
|
||||||
require.Nil(err, "%+v", err)
|
require.Nil(err, "%+v", err)
|
||||||
require.True(txres.Code.IsOK())
|
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
|
||||||
|
|
||||||
// and wait for confirmation
|
// and wait for confirmation
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
@ -132,6 +133,6 @@ func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
|
|||||||
require.True(ok, "%d: %#v", i, evt)
|
require.True(ok, "%d: %#v", i, evt)
|
||||||
// make sure this is the proper tx
|
// make sure this is the proper tx
|
||||||
require.EqualValues(tx, txe.Tx)
|
require.EqualValues(tx, txe.Tx)
|
||||||
require.True(txe.Result.Code.IsOK())
|
require.True(txe.Result.IsOK())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func (a ABCIApp) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuer
|
|||||||
|
|
||||||
func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||||
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Trusted})
|
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Trusted})
|
||||||
return &ctypes.ResultABCIQuery{q.Result()}, nil
|
return &ctypes.ResultABCIQuery{&q}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||||
@ -91,7 +91,7 @@ func (m ABCIMock) ABCIQueryWithOptions(path string, data data.Bytes, opts client
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resQuery := res.(abci.ResponseQuery)
|
resQuery := res.(abci.ResponseQuery)
|
||||||
return &ctypes.ResultABCIQuery{resQuery.Result()}, nil
|
return &ctypes.ResultABCIQuery{&resQuery}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m ABCIMock) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
func (m ABCIMock) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||||
@ -135,7 +135,7 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder {
|
|||||||
type QueryArgs struct {
|
type QueryArgs struct {
|
||||||
Path string
|
Path string
|
||||||
Data data.Bytes
|
Data data.Bytes
|
||||||
Height uint64
|
Height int64
|
||||||
Trusted bool
|
Trusted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func TestABCIMock(t *testing.T) {
|
|||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
key, value := []byte("foo"), []byte("bar")
|
key, value := []byte("foo"), []byte("bar")
|
||||||
height := uint64(10)
|
height := int64(10)
|
||||||
goodTx := types.Tx{0x01, 0xff}
|
goodTx := types.Tx{0x01, 0xff}
|
||||||
badTx := types.Tx{0x12, 0x21}
|
badTx := types.Tx{0x12, 0x21}
|
||||||
|
|
||||||
@ -168,9 +168,9 @@ func TestABCIApp(t *testing.T) {
|
|||||||
tx := fmt.Sprintf("%s=%s", key, value)
|
tx := fmt.Sprintf("%s=%s", key, value)
|
||||||
res, err := m.BroadcastTxCommit(types.Tx(tx))
|
res, err := m.BroadcastTxCommit(types.Tx(tx))
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
assert.True(res.CheckTx.Code.IsOK())
|
assert.True(res.CheckTx.IsOK())
|
||||||
require.NotNil(res.DeliverTx)
|
require.NotNil(res.DeliverTx)
|
||||||
assert.True(res.DeliverTx.Code.IsOK())
|
assert.True(res.DeliverTx.IsOK())
|
||||||
|
|
||||||
// check the key
|
// check the key
|
||||||
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})
|
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})
|
||||||
|
@ -8,7 +8,9 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/iavl"
|
"github.com/tendermint/iavl"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/rpc/client"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
@ -110,7 +112,7 @@ func TestABCIQuery(t *testing.T) {
|
|||||||
// wait before querying
|
// wait before querying
|
||||||
client.WaitForHeight(c, apph, nil)
|
client.WaitForHeight(c, apph, nil)
|
||||||
qres, err := c.ABCIQuery("/key", k)
|
qres, err := c.ABCIQuery("/key", k)
|
||||||
if assert.Nil(t, err) && assert.True(t, qres.Code.IsOK()) {
|
if assert.Nil(t, err) && assert.True(t, qres.IsOK()) {
|
||||||
assert.EqualValues(t, v, qres.Value)
|
assert.EqualValues(t, v, qres.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +138,7 @@ func TestAppCalls(t *testing.T) {
|
|||||||
k, v, tx := MakeTxKV()
|
k, v, tx := MakeTxKV()
|
||||||
bres, err := c.BroadcastTxCommit(tx)
|
bres, err := c.BroadcastTxCommit(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(err, "%d: %+v", i, err)
|
||||||
require.True(bres.DeliverTx.Code.IsOK())
|
require.True(bres.DeliverTx.IsOK())
|
||||||
txh := bres.Height
|
txh := bres.Height
|
||||||
apph := txh + 1 // this is where the tx will be applied to the state
|
apph := txh + 1 // this is where the tx will be applied to the state
|
||||||
|
|
||||||
@ -145,7 +147,7 @@ func TestAppCalls(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
qres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: true})
|
qres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: true})
|
||||||
if assert.Nil(err) && assert.True(qres.Code.IsOK()) {
|
if assert.Nil(err) && assert.True(qres.IsOK()) {
|
||||||
// assert.Equal(k, data.GetKey()) // only returned for proofs
|
// assert.Equal(k, data.GetKey()) // only returned for proofs
|
||||||
assert.EqualValues(v, qres.Value)
|
assert.EqualValues(v, qres.Value)
|
||||||
}
|
}
|
||||||
@ -193,7 +195,7 @@ func TestAppCalls(t *testing.T) {
|
|||||||
|
|
||||||
// and we got a proof that works!
|
// and we got a proof that works!
|
||||||
pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: false})
|
pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: false})
|
||||||
if assert.Nil(err) && assert.True(pres.Code.IsOK()) {
|
if assert.Nil(err) && assert.True(pres.IsOK()) {
|
||||||
proof, err := iavl.ReadKeyExistsProof(pres.Proof)
|
proof, err := iavl.ReadKeyExistsProof(pres.Proof)
|
||||||
if assert.Nil(err) {
|
if assert.Nil(err) {
|
||||||
key := pres.Key
|
key := pres.Key
|
||||||
@ -216,7 +218,7 @@ func TestBroadcastTxSync(t *testing.T) {
|
|||||||
_, _, tx := MakeTxKV()
|
_, _, tx := MakeTxKV()
|
||||||
bres, err := c.BroadcastTxSync(tx)
|
bres, err := c.BroadcastTxSync(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(err, "%d: %+v", i, err)
|
||||||
require.True(bres.Code.IsOK())
|
require.Equal(bres.Code, abci.CodeTypeOK) // FIXME
|
||||||
|
|
||||||
require.Equal(initMempoolSize+1, mempool.Size())
|
require.Equal(initMempoolSize+1, mempool.Size())
|
||||||
|
|
||||||
@ -234,8 +236,8 @@ func TestBroadcastTxCommit(t *testing.T) {
|
|||||||
_, _, tx := MakeTxKV()
|
_, _, tx := MakeTxKV()
|
||||||
bres, err := c.BroadcastTxCommit(tx)
|
bres, err := c.BroadcastTxCommit(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(err, "%d: %+v", i, err)
|
||||||
require.True(bres.CheckTx.Code.IsOK())
|
require.True(bres.CheckTx.IsOK())
|
||||||
require.True(bres.DeliverTx.Code.IsOK())
|
require.True(bres.DeliverTx.IsOK())
|
||||||
|
|
||||||
require.Equal(0, mempool.Size())
|
require.Equal(0, mempool.Size())
|
||||||
}
|
}
|
||||||
@ -284,7 +286,7 @@ func TestTx(t *testing.T) {
|
|||||||
assert.EqualValues(txHeight, ptx.Height)
|
assert.EqualValues(txHeight, ptx.Height)
|
||||||
assert.EqualValues(tx, ptx.Tx)
|
assert.EqualValues(tx, ptx.Tx)
|
||||||
assert.Zero(ptx.Index)
|
assert.Zero(ptx.Index)
|
||||||
assert.True(ptx.TxResult.Code.IsOK())
|
assert.True(ptx.TxResult.IsOK())
|
||||||
|
|
||||||
// time to verify the proof
|
// time to verify the proof
|
||||||
proof := ptx.Proof
|
proof := ptx.Proof
|
||||||
@ -321,7 +323,7 @@ func TestTxSearch(t *testing.T) {
|
|||||||
assert.EqualValues(t, txHeight, ptx.Height)
|
assert.EqualValues(t, txHeight, ptx.Height)
|
||||||
assert.EqualValues(t, tx, ptx.Tx)
|
assert.EqualValues(t, tx, ptx.Tx)
|
||||||
assert.Zero(t, ptx.Index)
|
assert.Zero(t, ptx.Index)
|
||||||
assert.True(t, ptx.TxResult.Code.IsOK())
|
assert.True(t, ptx.TxResult.IsOK())
|
||||||
|
|
||||||
// time to verify the proof
|
// time to verify the proof
|
||||||
proof := ptx.Proof
|
proof := ptx.Proof
|
||||||
|
@ -3,7 +3,7 @@ package client
|
|||||||
// ABCIQueryOptions can be used to provide options for ABCIQuery call other
|
// ABCIQueryOptions can be used to provide options for ABCIQuery call other
|
||||||
// than the DefaultABCIQueryOptions.
|
// than the DefaultABCIQueryOptions.
|
||||||
type ABCIQueryOptions struct {
|
type ABCIQueryOptions struct {
|
||||||
Height uint64
|
Height int64
|
||||||
Trusted bool
|
Trusted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ import (
|
|||||||
// |-----------+--------+---------+----------+------------------------------------------------|
|
// |-----------+--------+---------+----------+------------------------------------------------|
|
||||||
// | path | string | false | false | Path to the data ("/a/b/c") |
|
// | path | string | false | false | Path to the data ("/a/b/c") |
|
||||||
// | data | []byte | false | true | Data |
|
// | data | []byte | false | true | Data |
|
||||||
// | height | uint64 | 0 | false | Height (0 means latest) |
|
// | height | int64 | 0 | false | Height (0 means latest) |
|
||||||
// | trusted | bool | false | false | Does not include a proof of the data inclusion |
|
// | trusted | bool | false | false | Does not include a proof of the data inclusion |
|
||||||
func ABCIQuery(path string, data data.Bytes, height uint64, trusted bool) (*ctypes.ResultABCIQuery, error) {
|
func ABCIQuery(path string, data data.Bytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error) {
|
||||||
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
|
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
|
||||||
Path: path,
|
Path: path,
|
||||||
Data: data,
|
Data: data,
|
||||||
@ -59,7 +59,7 @@ func ABCIQuery(path string, data data.Bytes, height uint64, trusted bool) (*ctyp
|
|||||||
}
|
}
|
||||||
logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
|
logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
|
||||||
return &ctypes.ResultABCIQuery{
|
return &ctypes.ResultABCIQuery{
|
||||||
resQuery.Result(),
|
resQuery,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
|||||||
}
|
}
|
||||||
checkTxRes := <-checkTxResCh
|
checkTxRes := <-checkTxResCh
|
||||||
checkTxR := checkTxRes.GetCheckTx()
|
checkTxR := checkTxRes.GetCheckTx()
|
||||||
if checkTxR.Code != abci.CodeType_OK {
|
if checkTxR.Code != abci.CodeTypeOK {
|
||||||
// CheckTx failed!
|
// CheckTx failed!
|
||||||
return &ctypes.ResultBroadcastTxCommit{
|
return &ctypes.ResultBroadcastTxCommit{
|
||||||
CheckTx: *checkTxR,
|
CheckTx: *checkTxR,
|
||||||
|
@ -96,7 +96,7 @@ type ResultDumpConsensusState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResultBroadcastTx struct {
|
type ResultBroadcastTx struct {
|
||||||
Code abci.CodeType `json:"code"`
|
Code uint32 `json:"code"`
|
||||||
Data data.Bytes `json:"data"`
|
Data data.Bytes `json:"data"`
|
||||||
Log string `json:"log"`
|
Log string `json:"log"`
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ type ResultABCIInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResultABCIQuery struct {
|
type ResultABCIQuery struct {
|
||||||
*abci.ResultQuery `json:"response"`
|
*abci.ResponseQuery `json:"response"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultUnsafeFlushMempool struct{}
|
type ResultUnsafeFlushMempool struct{}
|
||||||
|
@ -54,7 +54,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
|
|||||||
// Blocks may include invalid txs.
|
// Blocks may include invalid txs.
|
||||||
// reqDeliverTx := req.(abci.RequestDeliverTx)
|
// reqDeliverTx := req.(abci.RequestDeliverTx)
|
||||||
txResult := r.DeliverTx
|
txResult := r.DeliverTx
|
||||||
if txResult.Code == abci.CodeType_OK {
|
if txResult.Code == abci.CodeTypeOK {
|
||||||
validTxs++
|
validTxs++
|
||||||
} else {
|
} else {
|
||||||
logger.Debug("Invalid tx", "code", txResult.Code, "log", txResult.Log)
|
logger.Debug("Invalid tx", "code", txResult.Code, "log", txResult.Log)
|
||||||
@ -80,6 +80,8 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
|
|||||||
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
||||||
block.Hash(),
|
block.Hash(),
|
||||||
types.TM2PB.Header(block.Header),
|
types.TM2PB.Header(block.Header),
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
|
logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
|
||||||
@ -95,7 +97,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End block
|
// End block
|
||||||
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{uint64(block.Height)})
|
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{block.Height})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error in proxyAppConn.EndBlock", "err", err)
|
logger.Error("Error in proxyAppConn.EndBlock", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -211,10 +211,10 @@ func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookForHeight(conditions []query.Condition) (height uint64, index int) {
|
func lookForHeight(conditions []query.Condition) (height int64, index int) {
|
||||||
for i, c := range conditions {
|
for i, c := range conditions {
|
||||||
if c.Tag == types.TxHeightKey {
|
if c.Tag == types.TxHeightKey {
|
||||||
return uint64(c.Operand.(int64)), i
|
return c.Operand.(int64), i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, -1
|
return 0, -1
|
||||||
@ -330,7 +330,7 @@ LOOP:
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Keys
|
// Keys
|
||||||
|
|
||||||
func startKey(c query.Condition, height uint64) []byte {
|
func startKey(c query.Condition, height int64) []byte {
|
||||||
var key string
|
var key string
|
||||||
if height > 0 {
|
if height > 0 {
|
||||||
key = fmt.Sprintf("%s/%v/%d", c.Tag, c.Operand, height)
|
key = fmt.Sprintf("%s/%v/%d", c.Tag, c.Operand, height)
|
||||||
@ -340,7 +340,7 @@ func startKey(c query.Condition, height uint64) []byte {
|
|||||||
return []byte(key)
|
return []byte(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startKeyForRange(r queryRange, height uint64) []byte {
|
func startKeyForRange(r queryRange, height int64) []byte {
|
||||||
if r.lowerBound == nil {
|
if r.lowerBound == nil {
|
||||||
return []byte(fmt.Sprintf("%s", r.key))
|
return []byte(fmt.Sprintf("%s", r.key))
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func TestTxIndex(t *testing.T) {
|
|||||||
indexer := NewTxIndex(db.NewMemDB())
|
indexer := NewTxIndex(db.NewMemDB())
|
||||||
|
|
||||||
tx := types.Tx("HELLO WORLD")
|
tx := types.Tx("HELLO WORLD")
|
||||||
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: "", Tags: []*abci.KVPair{}}}
|
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
|
|
||||||
batch := txindex.NewBatch(1)
|
batch := txindex.NewBatch(1)
|
||||||
@ -34,7 +34,7 @@ func TestTxIndex(t *testing.T) {
|
|||||||
assert.Equal(t, txResult, loadedTxResult)
|
assert.Equal(t, txResult, loadedTxResult)
|
||||||
|
|
||||||
tx2 := types.Tx("BYE BYE WORLD")
|
tx2 := types.Tx("BYE BYE WORLD")
|
||||||
txResult2 := &types.TxResult{1, 0, tx2, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: "", Tags: []*abci.KVPair{}}}
|
txResult2 := &types.TxResult{1, 0, tx2, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
|
||||||
hash2 := tx2.Hash()
|
hash2 := tx2.Hash()
|
||||||
|
|
||||||
err = indexer.Index(txResult2)
|
err = indexer.Index(txResult2)
|
||||||
@ -145,12 +145,12 @@ func TestIndexAllTags(t *testing.T) {
|
|||||||
|
|
||||||
func txResultWithTags(tags []*abci.KVPair) *types.TxResult {
|
func txResultWithTags(tags []*abci.KVPair) *types.TxResult {
|
||||||
tx := types.Tx("HELLO WORLD")
|
tx := types.Tx("HELLO WORLD")
|
||||||
return &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: "", Tags: tags}}
|
return &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: tags}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkTxIndex(txsCount int, b *testing.B) {
|
func benchmarkTxIndex(txsCount int, b *testing.B) {
|
||||||
tx := types.Tx("HELLO WORLD")
|
tx := types.Tx("HELLO WORLD")
|
||||||
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: "", Tags: []*abci.KVPair{}}}
|
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "tx_index_db")
|
dir, err := ioutil.TempDir("", "tx_index_db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user