Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tendermint: Change EventAttribute's key and value fields to Vec<u8> for Tendermint v0.34 #1405

Merged
merged 17 commits into from
Apr 22, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[tendermint]` Change `EventAttribute`'s `key` and `value` fields from `String` to `Vec<u8>` for Tendermint v0.34, as enforced by the Protobuf schema for Tendermint v0.34.
`tendermint::abci::EventAttribute` is now an enum, to account for version 0.34 and 0.37+, therefore the `key`, `value` and `index` fields now have to be retrieved through the `key_str()`/`key_bytes`, `value_str()`/`value_bytes()` and `index()` methods.
([\#1400](https://github.com/informalsystems/tendermint-rs/issues/1400)).
20 changes: 11 additions & 9 deletions rpc/src/dialect/v0_34.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ pub struct EventAttribute {
/// The event key.
#[serde(
serialize_with = "base64string::serialize",
deserialize_with = "base64string::deserialize_to_string"
deserialize_with = "base64string::deserialize"
)]
pub key: String,
pub key: Vec<u8>,
penso marked this conversation as resolved.
Show resolved Hide resolved

/// The event value.
#[serde(
serialize_with = "base64string::serialize",
deserialize_with = "base64string::deserialize_to_string"
deserialize_with = "base64string::deserialize"
)]
pub value: String,
pub value: Vec<u8>,

/// Whether Tendermint's indexer should index this event.
///
/// **This field is nondeterministic**.
Expand All @@ -61,20 +63,20 @@ pub struct EventAttribute {

impl From<EventAttribute> for abci::EventAttribute {
fn from(msg: EventAttribute) -> Self {
Self {
Self::V034(abci::v0_34::EventAttribute {
key: msg.key,
value: msg.value,
index: msg.index,
}
})
}
}

impl From<abci::EventAttribute> for EventAttribute {
fn from(msg: abci::EventAttribute) -> Self {
Self {
key: msg.key,
value: msg.value,
index: msg.index,
key: msg.key_bytes().to_vec(),
value: msg.value_bytes().to_vec(),
index: msg.index(),
}
}
}
Expand Down
112 changes: 66 additions & 46 deletions rpc/tests/kvstore_fixtures/v0_34.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,41 @@ fn incoming_fixtures() {
assert!(result.tx_result.data.is_empty());
assert_eq!(result.tx_result.events.len(), 1);
assert_eq!(result.tx_result.events[0].attributes.len(), 4);
assert_eq!(result.tx_result.events[0].attributes[0].key, "creator");
assert_eq!(
result.tx_result.events[0].attributes[0].value,
result.tx_result.events[0].attributes[0].key_bytes(),
b"creator"
);
assert_eq!(
result.tx_result.events[0].attributes[0]
.value_str()
.unwrap(),
"Cosmoshi Netowoko"
);
assert_eq!(result.tx_result.events[0].attributes[1].key, "key");
assert_eq!(result.tx_result.events[0].attributes[1].value, "commit-key");
assert_eq!(result.tx_result.events[0].attributes[2].key, "index_key");
assert_eq!(result.tx_result.events[0].attributes[1].key_bytes(), b"key");
assert_eq!(
result.tx_result.events[0].attributes[1]
.value_str()
.unwrap(),
"commit-key"
);
assert_eq!(
result.tx_result.events[0].attributes[2].value,
result.tx_result.events[0].attributes[2].key_bytes(),
b"index_key"
);
assert_eq!(
result.tx_result.events[0].attributes[2]
.value_str()
.unwrap(),
"index is working"
);
assert_eq!(result.tx_result.events[0].attributes[3].key, "noindex_key");
assert_eq!(
result.tx_result.events[0].attributes[3].value,
result.tx_result.events[0].attributes[3].key_bytes(),
b"noindex_key"
);
assert_eq!(
result.tx_result.events[0].attributes[3]
.value_str()
.unwrap(),
"index is working"
);
assert_eq!(result.tx_result.events[0].kind, "app");
Expand Down Expand Up @@ -908,23 +928,23 @@ fn incoming_fixtures() {
assert_eq!(rbb.events.len(), 2);
assert_eq!(rbb.events[0].kind, "transfer");
assert_eq!(rbb.events[0].attributes.len(), 2);
assert_eq!(rbb.events[0].attributes[0].key, "recipient");
assert_eq!(rbb.events[0].attributes[0].key_bytes(), b"recipient");
assert_eq!(
rbb.events[0].attributes[0].value,
rbb.events[0].attributes[0].value_str().unwrap(),
"cosmos17xpfvakm2amg962yls6f84z3kell8c5lserqta"
);
assert!(rbb.events[0].attributes[0].index);
assert_eq!(rbb.events[0].attributes[1].key, "sender");
assert!(rbb.events[0].attributes[0].index());
assert_eq!(rbb.events[0].attributes[1].key_bytes(), b"sender");
assert_eq!(
rbb.events[0].attributes[1].value,
rbb.events[0].attributes[1].value_str().unwrap(),
"cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q"
);
assert!(!rbb.events[0].attributes[1].index);
assert!(!rbb.events[0].attributes[1].index());
assert_eq!(rbb.events[1].kind, "message");
assert_eq!(rbb.events[1].attributes.len(), 1);
assert_eq!(rbb.events[1].attributes[0].key, "sender");
assert_eq!(rbb.events[1].attributes[0].key_bytes(), b"sender");
assert_eq!(
rbb.events[1].attributes[0].value,
rbb.events[1].attributes[0].value_str().unwrap(),
"cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q"
);
let reb = result_end_block.unwrap();
Expand Down Expand Up @@ -1115,18 +1135,18 @@ fn incoming_fixtures() {
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].kind, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
match attr.key_str().unwrap() {
"creator" => {
assert_eq!(attr.value, "Cosmoshi Netowoko")
assert_eq!(attr.value_str().unwrap(), "Cosmoshi Netowoko")
},
"key" => assert_eq!(attr.value, "tx0"),
"key" => assert_eq!(attr.value_str().unwrap(), "tx0"),
"index_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
"noindex_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
_ => panic!("unknown attribute found {}", attr.key),
other => panic!("unknown attribute found {other}"),
}
}
assert_eq!(tx_result.tx, base64::decode("dHgwPXZhbHVl").unwrap());
Expand All @@ -1147,18 +1167,18 @@ fn incoming_fixtures() {
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].kind, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
match attr.key_str().unwrap() {
"creator" => {
assert_eq!(attr.value, "Cosmoshi Netowoko")
assert_eq!(attr.value_str().unwrap(), "Cosmoshi Netowoko")
},
"key" => assert_eq!(attr.value, "tx1"),
"key" => assert_eq!(attr.value_str().unwrap(), "tx1"),
"index_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
"noindex_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
_ => panic!("unknown attribute found {}", attr.key),
other => panic!("unknown attribute found {other}"),
}
}
assert_eq!(tx_result.tx, base64::decode("dHgxPXZhbHVl").unwrap());
Expand All @@ -1180,18 +1200,18 @@ fn incoming_fixtures() {
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].kind, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
match attr.key_str().unwrap() {
"creator" => {
assert_eq!(attr.value, "Cosmoshi Netowoko")
assert_eq!(attr.value_str().unwrap(), "Cosmoshi Netowoko")
},
"key" => assert_eq!(attr.value, "tx2"),
"key" => assert_eq!(attr.value_str().unwrap(), "tx2"),
"index_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
"noindex_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
_ => panic!("unknown attribute found {}", attr.key),
other => panic!("unknown attribute found {other}"),
}
}
assert_eq!(tx_result.tx, base64::decode("dHgyPXZhbHVl").unwrap());
Expand All @@ -1212,18 +1232,18 @@ fn incoming_fixtures() {
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].kind, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
match attr.key_str().unwrap() {
"creator" => {
assert_eq!(attr.value, "Cosmoshi Netowoko")
assert_eq!(attr.value_str().unwrap(), "Cosmoshi Netowoko")
},
"key" => assert_eq!(attr.value, "tx3"),
"key" => assert_eq!(attr.value_str().unwrap(), "tx3"),
"index_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
"noindex_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
_ => panic!("unknown attribute found {}", attr.key),
other => panic!("unknown attribute found {other}"),
}
}
assert_eq!(tx_result.tx, base64::decode("dHgzPXZhbHVl").unwrap());
Expand All @@ -1244,18 +1264,18 @@ fn incoming_fixtures() {
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].kind, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
match attr.key_str().unwrap() {
"creator" => {
assert_eq!(attr.value, "Cosmoshi Netowoko")
assert_eq!(attr.value_str().unwrap(), "Cosmoshi Netowoko")
},
"key" => assert_eq!(attr.value, "tx4"),
"key" => assert_eq!(attr.value_str().unwrap(), "tx4"),
"index_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
"noindex_key" => {
assert_eq!(attr.value, "index is working")
assert_eq!(attr.value_str().unwrap(), "index is working")
},
_ => panic!("unknown attribute found {}", attr.key),
other => panic!("unknown attribute found {other}"),
}
}
assert_eq!(tx_result.tx, base64::decode("dHg0PXZhbHVl").unwrap());
Expand Down
Loading
Loading