remove a few unnecessary structs

This commit is contained in:
James Wilson
2021-06-16 11:24:00 +01:00
parent 8e25b4fbdf
commit 588f1ea027
2 changed files with 55 additions and 24 deletions
+52 -21
View File
@@ -47,11 +47,11 @@ pub enum Payload {
#[serde(rename = "afg.finalized")]
AfgFinalized(AfgFinalized),
#[serde(rename = "afg.received_precommit")]
AfgReceivedPrecommit(AfgReceivedPrecommit),
AfgReceivedPrecommit(AfgReceived),
#[serde(rename = "afg.received_prevote")]
AfgReceivedPrevote(AfgReceivedPrevote),
AfgReceivedPrevote(AfgReceived),
#[serde(rename = "afg.received_commit")]
AfgReceivedCommit(AfgReceivedCommit),
AfgReceivedCommit(AfgReceived),
#[serde(rename = "afg.authority_set")]
AfgAuthoritySet(AfgAuthoritySet),
#[serde(rename = "afg.finalized_blocks_up_to")]
@@ -109,24 +109,6 @@ pub struct AfgReceived {
pub voter: Option<Box<str>>,
}
#[derive(Deserialize, Debug, Clone)]
pub struct AfgReceivedPrecommit {
#[serde(flatten)]
pub received: AfgReceived,
}
#[derive(Deserialize, Debug, Clone)]
pub struct AfgReceivedPrevote {
#[serde(flatten)]
pub received: AfgReceived,
}
#[derive(Deserialize, Debug, Clone)]
pub struct AfgReceivedCommit {
#[serde(flatten)]
pub received: AfgReceived,
}
#[derive(Deserialize, Debug, Clone, Copy)]
pub struct Block {
#[serde(rename = "best")]
@@ -189,4 +171,53 @@ mod tests {
"message did not match variant V2",
);
}
#[test]
fn message_v2_received_precommit() {
let json = r#"{
"id":1,
"ts":"2021-01-13T12:22:20.053527101+01:00",
"payload":{
"target_hash":"0xcc41708573f2acaded9dd75e07dac2d4163d136ca35b3061c558d7a35a09dd8d",
"target_number":"209",
"voter":"foo",
"msg":"afg.received_precommit"
}
}"#;
assert!(
matches!(
serde_json::from_str::<NodeMessage>(json).unwrap(),
NodeMessage::V2 {
payload: Payload::AfgReceivedPrecommit(..),
..
},
),
"message did not match the expected output",
);
}
#[test]
fn message_v2_tx_pool_import() {
// We should happily ignore any fields we don't care about.
let json = r#"{
"id":1,
"ts":"2021-01-13T12:22:20.053527101+01:00",
"payload":{
"foo":"Something",
"bar":123,
"wibble":"wobble",
"msg":"txpool.import"
}
}"#;
assert!(
matches!(
serde_json::from_str::<NodeMessage>(json).unwrap(),
NodeMessage::V2 {
payload: Payload::TxPoolImport,
..
},
),
"message did not match the expected output",
);
}
}
+3 -3
View File
@@ -86,13 +86,13 @@ impl From<json::Payload> for Payload {
Payload::AfgFinalized(m.into())
},
json::Payload::AfgReceivedPrecommit(m) => {
Payload::AfgReceivedPrecommit(m.received.into())
Payload::AfgReceivedPrecommit(m.into())
},
json::Payload::AfgReceivedPrevote(m) => {
Payload::AfgReceivedPrevote(m.received.into())
Payload::AfgReceivedPrevote(m.into())
},
json::Payload::AfgReceivedCommit(m) => {
Payload::AfgReceivedCommit(m.received.into())
Payload::AfgReceivedCommit(m.into())
},
json::Payload::AfgAuthoritySet(m) => {
Payload::AfgAuthoritySet(m.into())