From 09a6ad7b1e1112e6b49053323130d27d161d6d9e Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Fri, 30 Apr 2021 03:27:51 -1000 Subject: [PATCH] types: Refactor EventAttribute (#6408) --- CHANGELOG_PENDING.md | 1 + abci/example/kvstore/kvstore.go | 17 ++-- abci/types/messages_test.go | 4 +- abci/types/types.pb.go | 118 +++++++++++++-------------- proto/tendermint/abci/types.proto | 38 +++------ state/indexer/block/kv/kv.go | 4 +- state/indexer/block/kv/kv_test.go | 16 ++-- state/indexer/tx/kv/kv.go | 6 +- state/indexer/tx/kv/kv_bench_test.go | 4 +- state/indexer/tx/kv/kv_test.go | 26 +++--- state/state_test.go | 8 +- test/e2e/app/app.go | 8 +- types/event_bus.go | 4 +- types/event_bus_test.go | 28 +++---- 14 files changed, 134 insertions(+), 148 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 718a7592c..c35b4339e 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -21,6 +21,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi startup (@cmwaters) - Apps + - [ABCI] \#6408 Change the `key` and `value` fields from `[]byte` to `string` in the `EventAttribute` type. (@alexanderbez) - [ABCI] \#5447 Remove `SetOption` method from `ABCI.Client` interface - [ABCI] \#5447 Reset `Oneof` indexes for `Request` and `Response`. - [ABCI] \#5818 Use protoio for msg length delimitation. Migrates from int64 to uint64 length delimiters. diff --git a/abci/example/kvstore/kvstore.go b/abci/example/kvstore/kvstore.go index 8b851ca9a..97256c8ac 100644 --- a/abci/example/kvstore/kvstore.go +++ b/abci/example/kvstore/kvstore.go @@ -87,15 +87,16 @@ func (app *Application) Info(req types.RequestInfo) (resInfo types.ResponseInfo) // tx is either "key=value" or just arbitrary bytes func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverTx { - var key, value []byte + var key, value string + parts := bytes.Split(req.Tx, []byte("=")) if len(parts) == 2 { - key, value = parts[0], parts[1] + key, value = string(parts[0]), string(parts[1]) } else { - key, value = req.Tx, req.Tx + key, value = string(req.Tx), string(req.Tx) } - err := app.state.db.Set(prefixKey(key), value) + err := app.state.db.Set(prefixKey([]byte(key)), []byte(value)) if err != nil { panic(err) } @@ -105,10 +106,10 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli { Type: "app", Attributes: []types.EventAttribute{ - {Key: []byte("creator"), Value: []byte("Cosmoshi Netowoko"), Index: true}, - {Key: []byte("key"), Value: key, Index: true}, - {Key: []byte("index_key"), Value: []byte("index is working"), Index: true}, - {Key: []byte("noindex_key"), Value: []byte("index is working"), Index: false}, + {Key: "creator", Value: "Cosmoshi Netowoko", Index: true}, + {Key: "key", Value: key, Index: true}, + {Key: "index_key", Value: "index is working", Index: true}, + {Key: "noindex_key", Value: "index is working", Index: false}, }, }, } diff --git a/abci/types/messages_test.go b/abci/types/messages_test.go index 8da12cfff..491d10c7f 100644 --- a/abci/types/messages_test.go +++ b/abci/types/messages_test.go @@ -25,7 +25,7 @@ func TestMarshalJSON(t *testing.T) { { Type: "testEvent", Attributes: []EventAttribute{ - {Key: []byte("pho"), Value: []byte("bo")}, + {Key: "pho", Value: "bo"}, }, }, }, @@ -92,7 +92,7 @@ func TestWriteReadMessage2(t *testing.T) { { Type: "testEvent", Attributes: []EventAttribute{ - {Key: []byte("abc"), Value: []byte("def")}, + {Key: "abc", Value: "def"}, }, }, }, diff --git a/abci/types/types.pb.go b/abci/types/types.pb.go index 92e26de6b..fd4bb3369 100644 --- a/abci/types/types.pb.go +++ b/abci/types/types.pb.go @@ -2440,8 +2440,8 @@ func (m *Event) GetAttributes() []EventAttribute { // EventAttribute is a single key-value pair, associated with an event. type EventAttribute struct { - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` Index bool `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"` } @@ -2478,18 +2478,18 @@ func (m *EventAttribute) XXX_DiscardUnknown() { var xxx_messageInfo_EventAttribute proto.InternalMessageInfo -func (m *EventAttribute) GetKey() []byte { +func (m *EventAttribute) GetKey() string { if m != nil { return m.Key } - return nil + return "" } -func (m *EventAttribute) GetValue() []byte { +func (m *EventAttribute) GetValue() string { if m != nil { return m.Value } - return nil + return "" } func (m *EventAttribute) GetIndex() bool { @@ -2938,7 +2938,7 @@ func init() { func init() { proto.RegisterFile("tendermint/abci/types.proto", fileDescriptor_252557cfdd89a31a) } var fileDescriptor_252557cfdd89a31a = []byte{ - // 2583 bytes of a gzipped FileDescriptorProto + // 2585 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x5a, 0x4b, 0x73, 0x1b, 0xc7, 0x11, 0xc6, 0x1b, 0xd8, 0x26, 0x01, 0x82, 0x23, 0x5a, 0x86, 0x60, 0x89, 0x94, 0x57, 0x25, 0xc7, 0x92, 0x6d, 0x32, 0xa6, 0x4a, 0x8a, 0x5c, 0xce, 0xc3, 0x04, 0x04, 0x05, 0xb4, 0x18, 0x92, 0x19, @@ -3063,44 +3063,44 @@ var fileDescriptor_252557cfdd89a31a = []byte{ 0xb2, 0x29, 0x09, 0x95, 0xf8, 0x82, 0x5b, 0xfd, 0x02, 0xb2, 0xdc, 0x6b, 0x98, 0x07, 0xf0, 0x62, 0x5b, 0x62, 0x1f, 0x36, 0x46, 0x9f, 0x00, 0xe8, 0x94, 0x0e, 0xcd, 0xf6, 0x28, 0x50, 0xbc, 0x31, 0xdd, 0xeb, 0x76, 0x3c, 0xbe, 0xda, 0x65, 0xe9, 0x7e, 0x6b, 0x81, 0x68, 0xc8, 0x05, 0x43, 0x0a, - 0xd5, 0x7d, 0x28, 0x45, 0x65,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2, 0x98, 0xfe, 0x28, 0xb2, 0x5c, 0xec, 0x45, 0xb0, 0xba, 0x60, 0x5f, 0x0a, 0x7d, 0x06, + 0xab, 0x93, 0xc8, 0x6f, 0xf1, 0x07, 0xc2, 0xea, 0x39, 0x3a, 0x55, 0x68, 0x00, 0x68, 0x0a, 0x62, + 0x3c, 0xc7, 0x7b, 0x61, 0xf5, 0x3c, 0x8d, 0xab, 0x5a, 0xe3, 0xab, 0x17, 0xeb, 0xc9, 0xaf, 0x5f, + 0xac, 0x27, 0xff, 0xf1, 0x62, 0x3d, 0xf9, 0xfc, 0xe5, 0x7a, 0xe2, 0xeb, 0x97, 0xeb, 0x89, 0xbf, + 0xbd, 0x5c, 0x4f, 0xfc, 0xec, 0xad, 0xae, 0x49, 0x7b, 0xa3, 0xf6, 0x66, 0xc7, 0x1e, 0x6c, 0x85, + 0xff, 0x88, 0x30, 0xed, 0xcf, 0x11, 0xed, 0x1c, 0x4f, 0x2a, 0xb7, 0xfe, 0x13, 0x00, 0x00, 0xff, + 0xff, 0x34, 0x1a, 0x9a, 0xa7, 0x3c, 0x21, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -12235,7 +12235,7 @@ func (m *EventAttribute) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -12245,31 +12245,29 @@ func (m *EventAttribute) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } + m.Key = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -12279,25 +12277,23 @@ func (m *EventAttribute) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } + m.Value = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 0 { diff --git a/proto/tendermint/abci/types.proto b/proto/tendermint/abci/types.proto index 31275c5ee..b34b3d192 100644 --- a/proto/tendermint/abci/types.proto +++ b/proto/tendermint/abci/types.proto @@ -52,8 +52,7 @@ message RequestInfo { } message RequestInitChain { - google.protobuf.Timestamp time = 1 - [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + google.protobuf.Timestamp time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; string chain_id = 2; tendermint.types.ConsensusParams consensus_params = 3; repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false]; @@ -96,8 +95,7 @@ message RequestEndBlock { message RequestCommit {} // lists available snapshots -message RequestListSnapshots { -} +message RequestListSnapshots {} // offers a snapshot to the application message RequestOfferSnapshot { @@ -184,8 +182,7 @@ message ResponseQuery { } message ResponseBeginBlock { - repeated Event events = 1 - [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; + repeated Event events = 1 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; } message ResponseCheckTx { @@ -195,9 +192,8 @@ message ResponseCheckTx { string info = 4; // nondeterministic int64 gas_wanted = 5 [json_name = "gas_wanted"]; int64 gas_used = 6 [json_name = "gas_used"]; - repeated Event events = 7 - [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; - string codespace = 8; + repeated Event events = 7 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; + string codespace = 8; } message ResponseDeliverTx { @@ -208,16 +204,14 @@ message ResponseDeliverTx { int64 gas_wanted = 5 [json_name = "gas_wanted"]; int64 gas_used = 6 [json_name = "gas_used"]; repeated Event events = 7 - [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; // nondeterministic + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; // nondeterministic string codespace = 8; } message ResponseEndBlock { - repeated ValidatorUpdate validator_updates = 1 - [(gogoproto.nullable) = false]; + repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable) = false]; tendermint.types.ConsensusParams consensus_param_updates = 2; - repeated Event events = 3 - [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; + repeated Event events = 3 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; } message ResponseCommit { @@ -275,17 +269,14 @@ message LastCommitInfo { // Later, transactions may be queried using these events. message Event { string type = 1; - repeated EventAttribute attributes = 2 [ - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "attributes,omitempty" - ]; + repeated EventAttribute attributes = 2 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "attributes,omitempty"]; } // EventAttribute is a single key-value pair, associated with an event. message EventAttribute { - bytes key = 1; - bytes value = 2; - bool index = 3; // nondeterministic + string key = 1; + string value = 2; + bool index = 3; // nondeterministic } // TxResult contains results of executing the transaction. @@ -333,10 +324,7 @@ message Evidence { // The height when the offense occurred int64 height = 3; // The corresponding time where the offense occurred - google.protobuf.Timestamp time = 4 [ - (gogoproto.nullable) = false, - (gogoproto.stdtime) = true - ]; + google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; // Total voting power of the validator set in case the ABCI application does // not store historical validators. // https://github.com/tendermint/tendermint/issues/4581 diff --git a/state/indexer/block/kv/kv.go b/state/indexer/block/kv/kv.go index 901f0e1d2..1787be9ef 100644 --- a/state/indexer/block/kv/kv.go +++ b/state/indexer/block/kv/kv.go @@ -468,13 +468,13 @@ func (idx *BlockerIndexer) indexEvents(batch dbm.Batch, events []abci.Event, typ } // index iff the event specified index:true and it's not a reserved event - compositeKey := fmt.Sprintf("%s.%s", event.Type, string(attr.Key)) + compositeKey := fmt.Sprintf("%s.%s", event.Type, attr.Key) if compositeKey == types.BlockHeightKey { return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeKey) } if attr.GetIndex() { - key, err := eventKey(compositeKey, typ, string(attr.Value), height) + key, err := eventKey(compositeKey, typ, attr.Value, height) if err != nil { return fmt.Errorf("failed to create block index key: %w", err) } diff --git a/state/indexer/block/kv/kv_test.go b/state/indexer/block/kv/kv_test.go index eacf51c42..2a342f870 100644 --- a/state/indexer/block/kv/kv_test.go +++ b/state/indexer/block/kv/kv_test.go @@ -25,8 +25,8 @@ func TestBlockIndexer(t *testing.T) { Type: "begin_event", Attributes: []abci.EventAttribute{ { - Key: []byte("proposer"), - Value: []byte("FCAA001"), + Key: "proposer", + Value: "FCAA001", Index: true, }, }, @@ -39,8 +39,8 @@ func TestBlockIndexer(t *testing.T) { Type: "end_event", Attributes: []abci.EventAttribute{ { - Key: []byte("foo"), - Value: []byte("100"), + Key: "foo", + Value: "100", Index: true, }, }, @@ -63,8 +63,8 @@ func TestBlockIndexer(t *testing.T) { Type: "begin_event", Attributes: []abci.EventAttribute{ { - Key: []byte("proposer"), - Value: []byte("FCAA001"), + Key: "proposer", + Value: "FCAA001", Index: true, }, }, @@ -77,8 +77,8 @@ func TestBlockIndexer(t *testing.T) { Type: "end_event", Attributes: []abci.EventAttribute{ { - Key: []byte("foo"), - Value: []byte(fmt.Sprintf("%d", i)), + Key: "foo", + Value: fmt.Sprintf("%d", i), Index: index, }, }, diff --git a/state/indexer/tx/kv/kv.go b/state/indexer/tx/kv/kv.go index 47b7e444e..e07393656 100644 --- a/state/indexer/tx/kv/kv.go +++ b/state/indexer/tx/kv/kv.go @@ -143,7 +143,7 @@ func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store dbm.Ba } // index if `index: true` is set - compositeTag := fmt.Sprintf("%s.%s", event.Type, string(attr.Key)) + compositeTag := fmt.Sprintf("%s.%s", event.Type, attr.Key) // ensure event does not conflict with a reserved prefix key if compositeTag == types.TxHashKey || compositeTag == types.TxHeightKey { return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeTag) @@ -580,8 +580,8 @@ func parseValueFromKey(key []byte) (string, error) { return value, nil } -func keyFromEvent(compositeKey string, value []byte, result *abci.TxResult) []byte { - return secondaryKey(compositeKey, string(value), result.Height, result.Index) +func keyFromEvent(compositeKey string, value string, result *abci.TxResult) []byte { + return secondaryKey(compositeKey, value, result.Height, result.Index) } func keyFromHeight(result *abci.TxResult) []byte { diff --git a/state/indexer/tx/kv/kv_bench_test.go b/state/indexer/tx/kv/kv_bench_test.go index fdfe550f3..9ad4922a0 100644 --- a/state/indexer/tx/kv/kv_bench_test.go +++ b/state/indexer/tx/kv/kv_bench_test.go @@ -32,8 +32,8 @@ func BenchmarkTxSearch(b *testing.B) { { Type: "transfer", Attributes: []abci.EventAttribute{ - {Key: []byte("address"), Value: []byte(fmt.Sprintf("address_%d", i%100)), Index: true}, - {Key: []byte("amount"), Value: []byte("50"), Index: true}, + {Key: "address", Value: fmt.Sprintf("address_%d", i%100), Index: true}, + {Key: "amount", Value: "50", Index: true}, }, }, } diff --git a/state/indexer/tx/kv/kv_test.go b/state/indexer/tx/kv/kv_test.go index d57f89c4e..16ca079d3 100644 --- a/state/indexer/tx/kv/kv_test.go +++ b/state/indexer/tx/kv/kv_test.go @@ -70,9 +70,9 @@ func TestTxSearch(t *testing.T) { indexer := NewTxIndex(db.NewMemDB()) txResult := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}}, - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("owner"), Value: []byte("Ivan"), Index: true}}}, - {Type: "", Attributes: []abci.EventAttribute{{Key: []byte("not_allowed"), Value: []byte("Vlad"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "owner", Value: "Ivan", Index: true}}}, + {Type: "", Attributes: []abci.EventAttribute{{Key: "not_allowed", Value: "Vlad", Index: true}}}, }) hash := types.Tx(txResult.Tx).Hash() @@ -150,9 +150,9 @@ func TestTxSearchWithCancelation(t *testing.T) { indexer := NewTxIndex(db.NewMemDB()) txResult := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}}, - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("owner"), Value: []byte("Ivan"), Index: true}}}, - {Type: "", Attributes: []abci.EventAttribute{{Key: []byte("not_allowed"), Value: []byte("Vlad"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "owner", Value: "Ivan", Index: true}}}, + {Type: "", Attributes: []abci.EventAttribute{{Key: "not_allowed", Value: "Vlad", Index: true}}}, }) err := indexer.Index(txResult) require.NoError(t, err) @@ -169,7 +169,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) { // index tx using events indexing (composite key) txResult1 := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}}, }) hash1 := types.Tx(txResult1.Tx).Hash() @@ -247,8 +247,8 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) { indexer := NewTxIndex(db.NewMemDB()) txResult := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}}, - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("2"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "2", Index: true}}}, }) err := indexer.Index(txResult) @@ -270,7 +270,7 @@ func TestTxSearchMultipleTxs(t *testing.T) { // indexed first, but bigger height (to test the order of transactions) txResult := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}}, }) txResult.Tx = types.Tx("Bob's account") @@ -281,7 +281,7 @@ func TestTxSearchMultipleTxs(t *testing.T) { // indexed second, but smaller height (to test the order of transactions) txResult2 := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("2"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "2", Index: true}}}, }) txResult2.Tx = types.Tx("Alice's account") txResult2.Height = 1 @@ -292,7 +292,7 @@ func TestTxSearchMultipleTxs(t *testing.T) { // indexed third (to test the order of transactions) txResult3 := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("3"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "3", Index: true}}}, }) txResult3.Tx = types.Tx("Jack's account") txResult3.Height = 1 @@ -303,7 +303,7 @@ func TestTxSearchMultipleTxs(t *testing.T) { // indexed fourth (to test we don't include txs with similar events) // https://github.com/tendermint/tendermint/issues/2908 txResult4 := txResultWithEvents([]abci.Event{ - {Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number.id"), Value: []byte("1"), Index: true}}}, + {Type: "account", Attributes: []abci.EventAttribute{{Key: "number.id", Value: "1", Index: true}}}, }) txResult4.Tx = types.Tx("Mike's account") txResult4.Height = 2 diff --git a/state/state_test.go b/state/state_test.go index 7806e281d..7c48c58d5 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -153,16 +153,16 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { { Data: []byte("Gotcha!"), Events: []abci.Event{ - {Type: "type1", Attributes: []abci.EventAttribute{{Key: []byte("a"), Value: []byte("1")}}}, - {Type: "type2", Attributes: []abci.EventAttribute{{Key: []byte("build"), Value: []byte("stuff")}}}, + {Type: "type1", Attributes: []abci.EventAttribute{{Key: "a", Value: "1"}}}, + {Type: "type2", Attributes: []abci.EventAttribute{{Key: "build", Value: "stuff"}}}, }, }, }, []*abci.ResponseDeliverTx{ {Code: 383, Data: nil}, {Code: 0, Data: []byte("Gotcha!"), Events: []abci.Event{ - {Type: "type1", Attributes: []abci.EventAttribute{{Key: []byte("a"), Value: []byte("1")}}}, - {Type: "type2", Attributes: []abci.EventAttribute{{Key: []byte("build"), Value: []byte("stuff")}}}, + {Type: "type1", Attributes: []abci.EventAttribute{{Key: "a", Value: "1"}}}, + {Type: "type2", Attributes: []abci.EventAttribute{{Key: "build", Value: "stuff"}}}, }}, }}, 3: { diff --git a/test/e2e/app/app.go b/test/e2e/app/app.go index 09a11a49a..89e0ce296 100644 --- a/test/e2e/app/app.go +++ b/test/e2e/app/app.go @@ -111,12 +111,12 @@ func (app *Application) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock Type: "val_updates", Attributes: []abci.EventAttribute{ { - Key: []byte("size"), - Value: []byte(strconv.Itoa(valUpdates.Len())), + Key: "size", + Value: strconv.Itoa(valUpdates.Len()), }, { - Key: []byte("height"), - Value: []byte(strconv.Itoa(int(req.Height))), + Key: "height", + Value: strconv.Itoa(int(req.Height)), }, }, }, diff --git a/types/event_bus.go b/types/event_bus.go index 34f511d14..9aefdceee 100644 --- a/types/event_bus.go +++ b/types/event_bus.go @@ -123,8 +123,8 @@ func (b *EventBus) validateAndStringifyEvents(events []types.Event, logger log.L continue } - compositeTag := fmt.Sprintf("%s.%s", event.Type, string(attr.Key)) - result[compositeTag] = append(result[compositeTag], string(attr.Value)) + compositeTag := fmt.Sprintf("%s.%s", event.Type, attr.Key) + result[compositeTag] = append(result[compositeTag], attr.Value) } } diff --git a/types/event_bus_test.go b/types/event_bus_test.go index 0578396e2..aff9d20f5 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -29,7 +29,7 @@ func TestEventBusPublishEventTx(t *testing.T) { result := abci.ResponseDeliverTx{ Data: []byte("bar"), Events: []abci.Event{ - {Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("baz"), Value: []byte("1")}}}, + {Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}}, }, } @@ -77,12 +77,12 @@ func TestEventBusPublishEventNewBlock(t *testing.T) { block := MakeBlock(0, []Tx{}, nil, []Evidence{}) resultBeginBlock := abci.ResponseBeginBlock{ Events: []abci.Event{ - {Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("baz"), Value: []byte("1")}}}, + {Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}}, }, } resultEndBlock := abci.ResponseEndBlock{ Events: []abci.Event{ - {Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("foz"), Value: []byte("2")}}}, + {Type: "testType", Attributes: []abci.EventAttribute{{Key: "foz", Value: "2"}}}, }, } @@ -132,25 +132,25 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) { { Type: "transfer", Attributes: []abci.EventAttribute{ - {Key: []byte("sender"), Value: []byte("foo")}, - {Key: []byte("recipient"), Value: []byte("bar")}, - {Key: []byte("amount"), Value: []byte("5")}, + {Key: "sender", Value: "foo"}, + {Key: "recipient", Value: "bar"}, + {Key: "amount", Value: "5"}, }, }, { Type: "transfer", Attributes: []abci.EventAttribute{ - {Key: []byte("sender"), Value: []byte("baz")}, - {Key: []byte("recipient"), Value: []byte("cat")}, - {Key: []byte("amount"), Value: []byte("13")}, + {Key: "sender", Value: "baz"}, + {Key: "recipient", Value: "cat"}, + {Key: "amount", Value: "13"}, }, }, { Type: "withdraw.rewards", Attributes: []abci.EventAttribute{ - {Key: []byte("address"), Value: []byte("bar")}, - {Key: []byte("source"), Value: []byte("iceman")}, - {Key: []byte("amount"), Value: []byte("33")}, + {Key: "address", Value: "bar"}, + {Key: "source", Value: "iceman"}, + {Key: "amount", Value: "33"}, }, }, }, @@ -236,12 +236,12 @@ func TestEventBusPublishEventNewBlockHeader(t *testing.T) { block := MakeBlock(0, []Tx{}, nil, []Evidence{}) resultBeginBlock := abci.ResponseBeginBlock{ Events: []abci.Event{ - {Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("baz"), Value: []byte("1")}}}, + {Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}}, }, } resultEndBlock := abci.ResponseEndBlock{ Events: []abci.Event{ - {Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("foz"), Value: []byte("2")}}}, + {Type: "testType", Attributes: []abci.EventAttribute{{Key: "foz", Value: "2"}}}, }, }