Skip to content

Commit d57b093

Browse files
committed
XC-238: Add prop_tests with arbitrary events and event types
1 parent 69c8f5d commit d57b093

File tree

2 files changed

+339
-70
lines changed

2 files changed

+339
-70
lines changed
+32-42
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
1-
use crate::state::eventlog::{Event, EventType};
2-
use crate::test_fixtures::{ignored_utxo, ledger_account};
3-
4-
#[test]
5-
fn should_decode_encoded_event() {
6-
let event = Event {
7-
timestamp: Some(123),
8-
payload: event_type(),
9-
};
10-
11-
let encoded = super::encode_event(&event);
12-
let decoded = super::decode_event(&encoded);
13-
14-
assert_eq!(event, decoded);
15-
}
16-
17-
#[test]
18-
fn should_decode_encoded_legacy_event() {
19-
/// Legacy events simply consisted of an event type instance. The
20-
/// encoding logic is the exact same as for new events, only the type
21-
/// being encoded differs.
22-
fn encode_legacy_event(event: &EventType) -> Vec<u8> {
23-
let mut buf = Vec::new();
24-
ciborium::ser::into_writer(event, &mut buf).expect("failed to encode a minter event");
25-
buf
1+
use super::{decode_event, encode_event};
2+
use crate::{
3+
state::eventlog::{Event, EventType},
4+
test_fixtures::arbitrary,
5+
};
6+
use proptest::proptest;
7+
8+
proptest! {
9+
#[test]
10+
fn should_decode_encoded_event(event in arbitrary::event()) {
11+
let encoded = encode_event(&event);
12+
let decoded = decode_event(&encoded);
13+
14+
assert_eq!(event, decoded);
2615
}
2716

28-
let legacy_event = event_type();
29-
30-
let encoded = encode_legacy_event(&legacy_event);
31-
let decoded = super::decode_event(&encoded);
32-
33-
assert_eq!(
34-
decoded,
35-
Event {
36-
timestamp: None,
37-
payload: legacy_event,
17+
#[test]
18+
fn should_decode_encoded_legacy_event(legacy_event in arbitrary::event_type()) {
19+
/// Legacy events just consist of an event type instance. The encoding logic
20+
/// is the exact same as for new events. Only the type being encoded differs.
21+
fn encode_legacy_event(event: &EventType) -> Vec<u8> {
22+
let mut buf = Vec::new();
23+
ciborium::ser::into_writer(event, &mut buf).expect("failed to encode a minter event");
24+
buf
3825
}
39-
);
40-
}
4126

42-
fn event_type() -> EventType {
43-
EventType::ReceivedUtxos {
44-
mint_txid: Some(1),
45-
to_account: ledger_account(),
46-
utxos: vec![ignored_utxo()],
27+
let encoded = encode_legacy_event(&legacy_event);
28+
let decoded = decode_event(&encoded);
29+
30+
assert_eq!(
31+
decoded,
32+
Event {
33+
timestamp: None,
34+
payload: legacy_event,
35+
}
36+
);
4737
}
4838
}

0 commit comments

Comments
 (0)