Skip to content

Commit 9e655a2

Browse files
committed
test: verify that BlockInfo is backwards compatible
1 parent fdc9bc6 commit 9e655a2

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,4 +2196,77 @@ mod tests {
21962196
.unwrap()
21972197
.is_none());
21982198
}
2199+
2200+
/// BlockInfo without the `reject_reason` field for backwards compatibility testing
2201+
#[derive(Serialize, Deserialize, Debug, PartialEq)]
2202+
pub struct BlockInfoPrev {
2203+
/// The block we are considering
2204+
pub block: NakamotoBlock,
2205+
/// The burn block height at which the block was proposed
2206+
pub burn_block_height: u64,
2207+
/// The reward cycle the block belongs to
2208+
pub reward_cycle: u64,
2209+
/// Our vote on the block if we have one yet
2210+
pub vote: Option<NakamotoBlockVote>,
2211+
/// Whether the block contents are valid
2212+
pub valid: Option<bool>,
2213+
/// Whether this block is already being signed over
2214+
pub signed_over: bool,
2215+
/// Time at which the proposal was received by this signer (epoch time in seconds)
2216+
pub proposed_time: u64,
2217+
/// Time at which the proposal was signed by this signer (epoch time in seconds)
2218+
pub signed_self: Option<u64>,
2219+
/// Time at which the proposal was signed by a threshold in the signer set (epoch time in seconds)
2220+
pub signed_group: Option<u64>,
2221+
/// The block state relative to the signer's view of the stacks blockchain
2222+
pub state: BlockState,
2223+
/// Consumed processing time in milliseconds to validate this block
2224+
pub validation_time_ms: Option<u64>,
2225+
/// Extra data specific to v0, v1, etc.
2226+
pub ext: ExtraBlockInfo,
2227+
}
2228+
2229+
/// Verify that we can deserialize the old BlockInfo struct into the new version
2230+
#[test]
2231+
fn deserialize_old_block_info() {
2232+
let block_info_prev = BlockInfoPrev {
2233+
block: NakamotoBlock {
2234+
header: NakamotoBlockHeader::genesis(),
2235+
txs: vec![],
2236+
},
2237+
burn_block_height: 2,
2238+
reward_cycle: 3,
2239+
vote: None,
2240+
valid: None,
2241+
signed_over: true,
2242+
proposed_time: 4,
2243+
signed_self: None,
2244+
signed_group: None,
2245+
state: BlockState::Unprocessed,
2246+
validation_time_ms: Some(5),
2247+
ext: ExtraBlockInfo::default(),
2248+
};
2249+
2250+
let block_info: BlockInfo =
2251+
serde_json::from_value(serde_json::to_value(&block_info_prev).unwrap()).unwrap();
2252+
assert_eq!(block_info.block, block_info_prev.block);
2253+
assert_eq!(
2254+
block_info.burn_block_height,
2255+
block_info_prev.burn_block_height
2256+
);
2257+
assert_eq!(block_info.reward_cycle, block_info_prev.reward_cycle);
2258+
assert_eq!(block_info.vote, block_info_prev.vote);
2259+
assert_eq!(block_info.valid, block_info_prev.valid);
2260+
assert_eq!(block_info.signed_over, block_info_prev.signed_over);
2261+
assert_eq!(block_info.proposed_time, block_info_prev.proposed_time);
2262+
assert_eq!(block_info.signed_self, block_info_prev.signed_self);
2263+
assert_eq!(block_info.signed_group, block_info_prev.signed_group);
2264+
assert_eq!(block_info.state, block_info_prev.state);
2265+
assert_eq!(
2266+
block_info.validation_time_ms,
2267+
block_info_prev.validation_time_ms
2268+
);
2269+
assert_eq!(block_info.ext, block_info_prev.ext);
2270+
assert!(block_info.reject_reason.is_none());
2271+
}
21992272
}

0 commit comments

Comments
 (0)