abci: interface should take pointers to arguments (#8404)

This commit is contained in:
Sam Kleinman
2022-04-24 18:37:07 +00:00
committed by GitHub
parent 674908b130
commit 2e5d53ea9a
39 changed files with 333 additions and 392 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ func testBulk(ctx context.Context, t *testing.T, logger log.Logger, app types.Ap
require.NoError(t, err)
// Construct request
rfb := types.RequestFinalizeBlock{Txs: make([][]byte, numDeliverTxs)}
rfb := &types.RequestFinalizeBlock{Txs: make([][]byte, numDeliverTxs)}
for counter := 0; counter < numDeliverTxs; counter++ {
rfb.Txs[counter] = []byte("test")
}
+1 -1
View File
@@ -34,7 +34,7 @@ func RandVals(cnt int) []types.ValidatorUpdate {
// which allows tests to pass and is fine as long as you
// don't make any tx that modify the validator state
func InitKVStore(ctx context.Context, app *PersistentKVStoreApplication) error {
_, err := app.InitChain(ctx, types.RequestInitChain{
_, err := app.InitChain(ctx, &types.RequestInitChain{
Validators: RandVals(1),
})
return err
+7 -7
View File
@@ -91,7 +91,7 @@ func NewApplication() *Application {
}
}
func (app *Application) InitChain(_ context.Context, req types.RequestInitChain) (*types.ResponseInitChain, error) {
func (app *Application) InitChain(_ context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
app.mu.Lock()
defer app.mu.Unlock()
@@ -105,7 +105,7 @@ func (app *Application) InitChain(_ context.Context, req types.RequestInitChain)
return &types.ResponseInitChain{}, nil
}
func (app *Application) Info(_ context.Context, req types.RequestInfo) (*types.ResponseInfo, error) {
func (app *Application) Info(_ context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
app.mu.Lock()
defer app.mu.Unlock()
return &types.ResponseInfo{
@@ -167,7 +167,7 @@ func (app *Application) Close() error {
return app.state.db.Close()
}
func (app *Application) FinalizeBlock(_ context.Context, req types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
func (app *Application) FinalizeBlock(_ context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
app.mu.Lock()
defer app.mu.Unlock()
@@ -199,7 +199,7 @@ func (app *Application) FinalizeBlock(_ context.Context, req types.RequestFinali
return &types.ResponseFinalizeBlock{TxResults: respTxs, ValidatorUpdates: app.ValUpdates}, nil
}
func (*Application) CheckTx(_ context.Context, req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
func (*Application) CheckTx(_ context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
return &types.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}, nil
}
@@ -222,7 +222,7 @@ func (app *Application) Commit(_ context.Context) (*types.ResponseCommit, error)
}
// Returns an associated value or nil if missing.
func (app *Application) Query(_ context.Context, reqQuery types.RequestQuery) (*types.ResponseQuery, error) {
func (app *Application) Query(_ context.Context, reqQuery *types.RequestQuery) (*types.ResponseQuery, error) {
app.mu.Lock()
defer app.mu.Unlock()
@@ -281,7 +281,7 @@ func (app *Application) Query(_ context.Context, reqQuery types.RequestQuery) (*
return &resQuery, nil
}
func (app *Application) PrepareProposal(_ context.Context, req types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
func (app *Application) PrepareProposal(_ context.Context, req *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
app.mu.Lock()
defer app.mu.Unlock()
@@ -290,7 +290,7 @@ func (app *Application) PrepareProposal(_ context.Context, req types.RequestPrep
}, nil
}
func (*Application) ProcessProposal(_ context.Context, req types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
func (*Application) ProcessProposal(_ context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
for _, tx := range req.Txs {
if len(tx) == 0 {
return &types.ResponseProcessProposal{Status: types.ResponseProcessProposal_REJECT}, nil
+14 -14
View File
@@ -24,7 +24,7 @@ const (
)
func testKVStore(ctx context.Context, t *testing.T, app types.Application, tx []byte, key, value string) {
req := types.RequestFinalizeBlock{Txs: [][]byte{tx}}
req := &types.RequestFinalizeBlock{Txs: [][]byte{tx}}
ar, err := app.FinalizeBlock(ctx, req)
require.NoError(t, err)
require.Equal(t, 1, len(ar.TxResults))
@@ -38,12 +38,12 @@ func testKVStore(ctx context.Context, t *testing.T, app types.Application, tx []
_, err = app.Commit(ctx)
require.NoError(t, err)
info, err := app.Info(ctx, types.RequestInfo{})
info, err := app.Info(ctx, &types.RequestInfo{})
require.NoError(t, err)
require.NotZero(t, info.LastBlockHeight)
// make sure query is fine
resQuery, err := app.Query(ctx, types.RequestQuery{
resQuery, err := app.Query(ctx, &types.RequestQuery{
Path: "/store",
Data: []byte(key),
})
@@ -54,7 +54,7 @@ func testKVStore(ctx context.Context, t *testing.T, app types.Application, tx []
require.EqualValues(t, info.LastBlockHeight, resQuery.Height)
// make sure proof is fine
resQuery, err = app.Query(ctx, types.RequestQuery{
resQuery, err = app.Query(ctx, &types.RequestQuery{
Path: "/store",
Data: []byte(key),
Prove: true,
@@ -111,7 +111,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
}
height := int64(0)
resInfo, err := kvstore.Info(ctx, types.RequestInfo{})
resInfo, err := kvstore.Info(ctx, &types.RequestInfo{})
if err != nil {
t.Fatal(err)
}
@@ -123,7 +123,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
// make and apply block
height = int64(1)
hash := []byte("foo")
if _, err := kvstore.FinalizeBlock(ctx, types.RequestFinalizeBlock{Hash: hash, Height: height}); err != nil {
if _, err := kvstore.FinalizeBlock(ctx, &types.RequestFinalizeBlock{Hash: hash, Height: height}); err != nil {
t.Fatal(err)
}
@@ -132,7 +132,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
}
resInfo, err = kvstore.Info(ctx, types.RequestInfo{})
resInfo, err = kvstore.Info(ctx, &types.RequestInfo{})
if err != nil {
t.Fatal(err)
}
@@ -154,7 +154,7 @@ func TestValUpdates(t *testing.T) {
nInit := 5
vals := RandVals(total)
// initialize with the first nInit
_, err := kvstore.InitChain(ctx, types.RequestInitChain{
_, err := kvstore.InitChain(ctx, &types.RequestInitChain{
Validators: vals[:nInit],
})
if err != nil {
@@ -215,7 +215,7 @@ func makeApplyBlock(ctx context.Context, t *testing.T, kvstore types.Application
// make and apply block
height := int64(heightInt)
hash := []byte("foo")
resFinalizeBlock, err := kvstore.FinalizeBlock(ctx, types.RequestFinalizeBlock{
resFinalizeBlock, err := kvstore.FinalizeBlock(ctx, &types.RequestFinalizeBlock{
Hash: hash,
Height: height,
Txs: txs,
@@ -350,12 +350,12 @@ func runClientTests(ctx context.Context, t *testing.T, client abciclient.Client)
}
func testClient(ctx context.Context, t *testing.T, app abciclient.Client, tx []byte, key, value string) {
ar, err := app.FinalizeBlock(ctx, types.RequestFinalizeBlock{Txs: [][]byte{tx}})
ar, err := app.FinalizeBlock(ctx, &types.RequestFinalizeBlock{Txs: [][]byte{tx}})
require.NoError(t, err)
require.Equal(t, 1, len(ar.TxResults))
require.False(t, ar.TxResults[0].IsErr())
// repeating FinalizeBlock doesn't raise error
ar, err = app.FinalizeBlock(ctx, types.RequestFinalizeBlock{Txs: [][]byte{tx}})
ar, err = app.FinalizeBlock(ctx, &types.RequestFinalizeBlock{Txs: [][]byte{tx}})
require.NoError(t, err)
require.Equal(t, 1, len(ar.TxResults))
require.False(t, ar.TxResults[0].IsErr())
@@ -363,12 +363,12 @@ func testClient(ctx context.Context, t *testing.T, app abciclient.Client, tx []b
_, err = app.Commit(ctx)
require.NoError(t, err)
info, err := app.Info(ctx, types.RequestInfo{})
info, err := app.Info(ctx, &types.RequestInfo{})
require.NoError(t, err)
require.NotZero(t, info.LastBlockHeight)
// make sure query is fine
resQuery, err := app.Query(ctx, types.RequestQuery{
resQuery, err := app.Query(ctx, &types.RequestQuery{
Path: "/store",
Data: []byte(key),
})
@@ -379,7 +379,7 @@ func testClient(ctx context.Context, t *testing.T, app abciclient.Client, tx []b
require.EqualValues(t, info.LastBlockHeight, resQuery.Height)
// make sure proof is fine
resQuery, err = app.Query(ctx, types.RequestQuery{
resQuery, err = app.Query(ctx, &types.RequestQuery{
Path: "/store",
Data: []byte(key),
Prove: true,
+2 -2
View File
@@ -37,10 +37,10 @@ func NewPersistentKVStoreApplication(logger log.Logger, dbDir string) *Persisten
}
}
func (app *PersistentKVStoreApplication) OfferSnapshot(_ context.Context, req types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
func (app *PersistentKVStoreApplication) OfferSnapshot(_ context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
return &types.ResponseOfferSnapshot{Result: types.ResponseOfferSnapshot_ABORT}, nil
}
func (app *PersistentKVStoreApplication) ApplySnapshotChunk(_ context.Context, req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
func (app *PersistentKVStoreApplication) ApplySnapshotChunk(_ context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
return &types.ResponseApplySnapshotChunk{Result: types.ResponseApplySnapshotChunk_ABORT}, nil
}