Browse Source

cleanup remaining struct problems

pull/7983/head
William Banfield 3 years ago
parent
commit
afbaa86a63
15 changed files with 56 additions and 48 deletions
  1. +1
    -2
      abci/example/kvstore/kvstore_test.go
  2. +1
    -1
      abci/types/messages_test.go
  3. +10
    -0
      abci/types/result.go
  4. +1
    -1
      internal/eventbus/event_bus.go
  5. +4
    -4
      internal/eventbus/event_bus_test.go
  6. +0
    -1
      internal/state/execution.go
  7. +2
    -2
      internal/state/indexer/indexer_service_test.go
  8. +5
    -5
      internal/state/indexer/sink/kv/kv_test.go
  9. +1
    -1
      internal/state/indexer/sink/psql/psql.go
  10. +5
    -5
      internal/state/indexer/sink/psql/psql_test.go
  11. +1
    -1
      internal/state/indexer/tx/kv/kv.go
  12. +5
    -5
      internal/state/indexer/tx/kv/kv_bench_test.go
  13. +14
    -14
      internal/state/indexer/tx/kv/kv_test.go
  14. +4
    -4
      internal/state/state_test.go
  15. +2
    -2
      test/e2e/app/app.go

+ 1
- 2
abci/example/kvstore/kvstore_test.go View File

@ -107,7 +107,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
header := tmproto.Header{
Height: height,
}
kvstore.FinalizeBlock(types.RequestFinalizeBlock{Hash: hash, Header: header, Height: height})
kvstore.FinalizeBlock(types.RequestFinalizeBlock{Hash: hash, Header: header})
kvstore.Commit()
resInfo = kvstore.Info(types.RequestInfo{})
@ -196,7 +196,6 @@ func makeApplyBlock(
resFinalizeBlock := kvstore.FinalizeBlock(types.RequestFinalizeBlock{
Hash: hash,
Header: header,
Height: height,
Txs: txs,
})


+ 1
- 1
abci/types/messages_test.go View File

@ -13,7 +13,7 @@ import (
)
func TestMarshalJSON(t *testing.T) {
b, err := json.Marshal(&ResponseDeliverTx{})
b, err := json.Marshal(&ExecTxResult{})
assert.NoError(t, err)
// include empty fields.
assert.True(t, strings.Contains(string(b), "code"))


+ 10
- 0
abci/types/result.go View File

@ -33,6 +33,16 @@ func (r ResponseDeliverTx) IsErr() bool {
return r.Code != CodeTypeOK
}
// IsOK returns true if Code is OK.
func (r ExecTxResult) IsOK() bool {
return r.Code == CodeTypeOK
}
// IsErr returns true if Code is something other than OK.
func (r ExecTxResult) IsErr() bool {
return r.Code != CodeTypeOK
}
// IsOK returns true if Code is OK.
func (r ResponseQuery) IsOK() bool {
return r.Code == CodeTypeOK


+ 1
- 1
internal/eventbus/event_bus.go View File

@ -132,7 +132,7 @@ func (b *EventBus) PublishEventStateSyncStatus(ctx context.Context, data types.E
// predefined keys (EventTypeKey, TxHashKey). Existing events with the same keys
// will be overwritten.
func (b *EventBus) PublishEventTx(ctx context.Context, data types.EventDataTx) error {
events := data.Result.Events
events := data.Result.TxEvents
// add Tendermint-reserved events
events = append(events, types.EventTx)


+ 4
- 4
internal/eventbus/event_bus_test.go View File

@ -27,9 +27,9 @@ func TestEventBusPublishEventTx(t *testing.T) {
require.NoError(t, err)
tx := types.Tx("foo")
result := abci.ResponseDeliverTx{
result := abci.ExecTxResult{
Data: []byte("bar"),
Events: []abci.Event{
TxEvents: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},
},
}
@ -134,9 +134,9 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) {
require.NoError(t, err)
tx := types.Tx("foo")
result := abci.ResponseDeliverTx{
result := abci.ExecTxResult{
Data: []byte("bar"),
Events: []abci.Event{
TxEvents: []abci.Event{
{
Type: "transfer",
Attributes: []abci.EventAttribute{


+ 0
- 1
internal/state/execution.go View File

@ -398,7 +398,6 @@ func execBlockOnProxyApp(
Txs: block.Txs.ToSliceOfBytes(),
Hash: block.Hash(),
Header: *pbh,
Height: block.Height,
LastCommitInfo: buildLastCommitInfo(block, store, initialHeight),
ByzantineValidators: block.Evidence.ToABCI(),
},


+ 2
- 2
internal/state/indexer/indexer_service_test.go View File

@ -80,7 +80,7 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) {
Height: 1,
Index: uint32(0),
Tx: types.Tx("foo"),
Result: abci.ResponseDeliverTx{Code: 0},
Result: abci.ExecTxResult{Code: 0},
}
err = eventBus.PublishEventTx(ctx, types.EventDataTx{TxResult: *txResult1})
require.NoError(t, err)
@ -88,7 +88,7 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) {
Height: 1,
Index: uint32(1),
Tx: types.Tx("bar"),
Result: abci.ResponseDeliverTx{Code: 0},
Result: abci.ExecTxResult{Code: 0},
}
err = eventBus.PublishEventTx(ctx, types.EventDataTx{TxResult: *txResult2})
require.NoError(t, err)


+ 5
- 5
internal/state/indexer/sink/kv/kv_test.go View File

@ -338,11 +338,11 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
Height: 1,
Index: 0,
Tx: tx,
Result: abci.ResponseDeliverTx{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
Events: events,
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
TxEvents: events,
},
}
}

+ 1
- 1
internal/state/indexer/sink/psql/psql.go View File

@ -221,7 +221,7 @@ INSERT INTO `+tableTxResults+` (block_id, index, created_at, tx_hash, tx_result)
return fmt.Errorf("indexing transaction meta-events: %w", err)
}
// Index any events packaged with the transaction.
if err := insertEvents(dbtx, blockID, txID, txr.Result.Events); err != nil {
if err := insertEvents(dbtx, blockID, txID, txr.Result.TxEvents); err != nil {
return fmt.Errorf("indexing transaction events: %w", err)
}
return nil


+ 5
- 5
internal/state/indexer/sink/psql/psql_test.go View File

@ -266,11 +266,11 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
Height: 1,
Index: 0,
Tx: types.Tx("HELLO WORLD"),
Result: abci.ResponseDeliverTx{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
Events: events,
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
TxEvents: events,
},
}
}


+ 1
- 1
internal/state/indexer/tx/kv/kv.go View File

@ -97,7 +97,7 @@ func (txi *TxIndex) Index(results []*abci.TxResult) error {
}
func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store dbm.Batch) error {
for _, event := range result.Result.Events {
for _, event := range result.Result.TxEvents {
// only index events with a non-empty type
if len(event.Type) == 0 {
continue


+ 5
- 5
internal/state/indexer/tx/kv/kv_bench_test.go View File

@ -43,11 +43,11 @@ func BenchmarkTxSearch(b *testing.B) {
Height: int64(i),
Index: 0,
Tx: types.Tx(string(txBz)),
Result: abci.ResponseDeliverTx{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
Events: events,
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
TxEvents: events,
},
}


+ 14
- 14
internal/state/indexer/tx/kv/kv_test.go View File

@ -25,9 +25,9 @@ func TestTxIndex(t *testing.T) {
Height: 1,
Index: 0,
Tx: tx,
Result: abci.ResponseDeliverTx{
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK, Log: "", Events: nil,
Code: abci.CodeTypeOK, Log: "", TxEvents: nil,
},
}
hash := tx.Hash()
@ -48,9 +48,9 @@ func TestTxIndex(t *testing.T) {
Height: 1,
Index: 0,
Tx: tx2,
Result: abci.ResponseDeliverTx{
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK, Log: "", Events: nil,
Code: abci.CodeTypeOK, Log: "", TxEvents: nil,
},
}
hash2 := tx2.Hash()
@ -322,11 +322,11 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
Height: 1,
Index: 0,
Tx: tx,
Result: abci.ResponseDeliverTx{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
Events: events,
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
TxEvents: events,
},
}
}
@ -346,11 +346,11 @@ func benchmarkTxIndex(txsCount int64, b *testing.B) {
Height: 1,
Index: txIndex,
Tx: tx,
Result: abci.ResponseDeliverTx{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
Events: []abci.Event{},
Result: abci.ExecTxResult{
Data: []byte{0},
Code: abci.CodeTypeOK,
Log: "",
TxEvents: []abci.Event{},
},
}
if err := batch.Add(txResult); err != nil {


+ 4
- 4
internal/state/state_test.go View File

@ -111,8 +111,8 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
abciResponses.FinalizeBlock = new(abci.ResponseFinalizeBlock)
abciResponses.FinalizeBlock.TxResults = dtxs
abciResponses.FinalizeBlock.TxResults[0] = &abci.ExecTxResult{Data: []byte("foo"), Events: nil}
abciResponses.FinalizeBlock.TxResults[1] = &abci.ExecTxResult{Data: []byte("bar"), Log: "ok", Events: nil}
abciResponses.FinalizeBlock.TxResults[0] = &abci.ExecTxResult{Data: []byte("foo"), TxEvents: nil}
abciResponses.FinalizeBlock.TxResults[1] = &abci.ExecTxResult{Data: []byte("bar"), Log: "ok", TxEvents: nil}
pbpk, err := encoding.PubKeyToProto(ed25519.GenPrivKey().PubKey())
require.NoError(t, err)
abciResponses.FinalizeBlock.ValidatorUpdates = []abci.ValidatorUpdate{{PubKey: pbpk, Power: 10}}
@ -156,7 +156,7 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
{Code: 383},
{
Data: []byte("Gotcha!"),
Events: []abci.Event{
TxEvents: []abci.Event{
{Type: "type1", Attributes: []abci.EventAttribute{{Key: "a", Value: "1"}}},
{Type: "type2", Attributes: []abci.EventAttribute{{Key: "build", Value: "stuff"}}},
},
@ -164,7 +164,7 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
},
[]*abci.ExecTxResult{
{Code: 383, Data: nil},
{Code: 0, Data: []byte("Gotcha!"), Events: []abci.Event{
{Code: 0, Data: []byte("Gotcha!"), TxEvents: []abci.Event{
{Type: "type1", Attributes: []abci.EventAttribute{{Key: "a", Value: "1"}}},
{Type: "type2", Attributes: []abci.EventAttribute{{Key: "build", Value: "stuff"}}},
}},


+ 2
- 2
test/e2e/app/app.go View File

@ -170,7 +170,7 @@ func (app *Application) FinalizeBlock(req abci.RequestFinalizeBlock) abci.Respon
txs[i] = &abci.ExecTxResult{Code: code.CodeTypeOK}
}
valUpdates, err := app.validatorUpdates(uint64(req.Height))
valUpdates, err := app.validatorUpdates(uint64(req.Header.Height))
if err != nil {
panic(err)
}
@ -188,7 +188,7 @@ func (app *Application) FinalizeBlock(req abci.RequestFinalizeBlock) abci.Respon
},
{
Key: "height",
Value: strconv.Itoa(int(req.Height)),
Value: strconv.Itoa(int(req.Header.Height)),
},
},
},


Loading…
Cancel
Save