-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathtests.rs
88 lines (76 loc) · 2.41 KB
/
tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use cid::Cid;
use crate::{
blockchain::mock::{MockBlockchain, MockDataSource},
ipfs::ContentPath,
prelude::Link,
};
use super::{
offchain::{Mapping, Source},
*,
};
#[test]
fn offchain_duplicate() {
let a = new_datasource();
let mut b = a.clone();
// Equal data sources are duplicates.
assert!(a.is_duplicate_of(&b));
// The causality region, the creation block and the done status are ignored in the duplicate check.
b.causality_region = a.causality_region.next();
b.creation_block = Some(1);
b.set_done_at(Some(1));
assert!(a.is_duplicate_of(&b));
// The manifest idx, the source and the context are relevant for duplicate detection.
let mut c = a.clone();
c.manifest_idx = 1;
assert!(!a.is_duplicate_of(&c));
let mut c = a.clone();
c.source = Source::Ipfs(ContentPath::new(format!("{}/foo", Cid::default())).unwrap());
assert!(!a.is_duplicate_of(&c));
let mut c = a.clone();
c.context = Arc::new(Some(DataSourceContext::new()));
assert!(!a.is_duplicate_of(&c));
}
#[test]
#[should_panic]
fn offchain_mark_processed_error() {
let x = new_datasource();
x.mark_processed_at(-1)
}
#[test]
fn data_source_helpers() {
let offchain = new_datasource();
let offchain_ds = DataSource::<MockBlockchain>::Offchain(offchain.clone());
assert!(offchain_ds.causality_region() == offchain.causality_region);
assert!(offchain_ds
.as_offchain()
.unwrap()
.is_duplicate_of(&offchain));
let onchain = DataSource::<MockBlockchain>::Onchain(MockDataSource {
api_version: Version::new(1, 0, 0),
kind: "mock/kind".into(),
network: Some("mock_network".into()),
});
assert!(onchain.causality_region() == CausalityRegion::ONCHAIN);
assert!(onchain.as_offchain().is_none());
}
fn new_datasource() -> offchain::DataSource {
offchain::DataSource::new(
offchain::OffchainDataSourceKind::Ipfs,
"theName".into(),
0,
Source::Ipfs(ContentPath::new(Cid::default().to_string()).unwrap()),
Mapping {
language: String::new(),
api_version: Version::new(0, 0, 0),
entities: vec![],
handler: String::new(),
runtime: Arc::new(vec![]),
link: Link {
link: String::new(),
},
},
Arc::new(None),
Some(0),
CausalityRegion::ONCHAIN.next(),
)
}