Skip to content

Commit c4308ba

Browse files
committed
primitives - channel_fixtures
1 parent 926ef44 commit c4308ba

File tree

1 file changed

+90
-90
lines changed

1 file changed

+90
-90
lines changed

primitives/src/channel_fixtures.rs

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
//use chrono::{DateTime, Utc};
2-
//use fake::faker::*;
3-
//use time::Duration;
4-
//
5-
//use crate::asset::fixtures::get_asset;
6-
//use crate::fixtures::{get_targeting_tags, get_validator};
7-
//use crate::test_util;
8-
//use crate::BigNum;
9-
//
10-
//use super::{Channel, ChannelId, ChannelSpec, SpecValidators, ValidatorDesc};
11-
//
1+
use chrono::{DateTime, Utc};
2+
use fake::faker::*;
3+
use time::Duration;
4+
5+
use crate::targeting_tag::fixtures::get_targeting_tags;
6+
use crate::validator::fixtures::get_validator;
7+
use crate::BigNum;
8+
9+
use super::{Channel, ChannelSpec, SpecValidators, ValidatorDesc};
10+
use crate::util::tests::take_one;
11+
12+
const ASSETS_LIST: [&str; 8] = ["DAI", "BGN", "EUR", "USD", "ADX", "BTC", "LIT", "ETH"];
13+
1214
///// It will get the length of channel_id bytes and will fill enough bytes in front
1315
///// If > 32 bytes &str is passed it will `panic!`
1416
//pub fn get_channel_id(channel_id: &str) -> ChannelId {
@@ -24,35 +26,34 @@
2426
//
2527
// ChannelId { bytes: id }
2628
//}
27-
//
28-
//pub fn get_channel(
29-
// id: &str,
30-
// valid_until: &Option<DateTime<Utc>>,
31-
// spec: Option<ChannelSpec>,
32-
//) -> Channel {
33-
// let channel_id = get_channel_id(id);
34-
// let deposit_amount = BigNum::from(<Faker as Number>::between(100, 5000));
35-
// let valid_until: DateTime<Utc> = valid_until.unwrap_or_else(|| {
36-
// let future_from = Utc::now() + Duration::days(7);
37-
// test_util::time::datetime_between(&future_from, None)
38-
// });
39-
// let creator = <Faker as Name>::name();
40-
// let deposit_asset = get_asset();
41-
// let spec = spec.unwrap_or_else(|| {
42-
// get_channel_spec(ValidatorsOption::Generate {
43-
// validators_prefix: id,
44-
// })
45-
// });
46-
//
47-
// Channel {
48-
// id: channel_id,
49-
// creator,
50-
// deposit_asset,
51-
// deposit_amount,
52-
// valid_until,
53-
// spec,
54-
// }
55-
//}
29+
30+
pub fn get_channel(
31+
id: &str,
32+
valid_until: &Option<DateTime<Utc>>,
33+
spec: Option<ChannelSpec>,
34+
) -> Channel {
35+
let deposit_amount = BigNum::from(<Faker as Number>::between(100, 5000));
36+
let valid_until: DateTime<Utc> = valid_until.unwrap_or_else(|| {
37+
let future_from = Utc::now() + Duration::days(7);
38+
crate::util::tests::time::datetime_between(&future_from, None)
39+
});
40+
let creator = <Faker as Name>::name();
41+
let deposit_asset = take_one(&ASSETS_LIST).into();
42+
let spec = spec.unwrap_or_else(|| {
43+
get_channel_spec(ValidatorsOption::Generate {
44+
validators_prefix: id,
45+
})
46+
});
47+
48+
Channel {
49+
id: id.into(),
50+
creator,
51+
deposit_asset,
52+
deposit_amount,
53+
valid_until,
54+
spec,
55+
}
56+
}
5657
//
5758
//pub fn get_channels(count: usize, valid_until_ge: Option<DateTime<Utc>>) -> Vec<Channel> {
5859
// (1..=count)
@@ -67,53 +68,52 @@
6768
// .collect()
6869
//}
6970
//
70-
//pub enum ValidatorsOption<'a> {
71-
// Pair {
72-
// leader: ValidatorDesc,
73-
// follower: ValidatorDesc,
74-
// },
75-
// SpecValidators(SpecValidators),
76-
// Generate {
77-
// validators_prefix: &'a str,
78-
// },
79-
//}
80-
//
81-
//pub fn get_channel_spec(validators_option: ValidatorsOption<'_>) -> ChannelSpec {
82-
// use crate::EventSubmission;
83-
// use test_util::take_one;
84-
//
85-
// let validators = match validators_option {
86-
// ValidatorsOption::Pair { leader, follower } => [leader, follower].into(),
87-
// ValidatorsOption::SpecValidators(spec_validators) => spec_validators,
88-
// ValidatorsOption::Generate { validators_prefix } => [
89-
// get_validator(&format!("{} leader", validators_prefix), None),
90-
// get_validator(&format!("{} follower", validators_prefix), None),
91-
// ]
92-
// .into(),
93-
// };
94-
//
95-
// let title_string = Some(<Faker as Lorem>::sentence(3, 4));
96-
//
97-
// let title = take_one(&[&title_string, &None]).to_owned();
98-
// let max_per_impression = BigNum::from(<Faker as Number>::between(250, 500));
99-
// let min_per_impression = BigNum::from(<Faker as Number>::between(1, 250));
100-
// let nonce = BigNum::from(<Faker as Number>::between(100_000_000, 999_999_999));
101-
// let min_targeting_score =
102-
// take_one(&[&None, &Some(<Faker as Number>::between(1, 500))]).to_owned();
103-
//
104-
// ChannelSpec {
105-
// validators,
106-
// title,
107-
// max_per_impression,
108-
// min_per_impression,
109-
// targeting: get_targeting_tags(<Faker as Number>::between(0, 5)),
110-
// min_targeting_score,
111-
// // @TODO: `EventSubmission` fixture issue #27
112-
// event_submission: EventSubmission { allow: vec![] },
113-
// created: Utc::now(),
114-
// active_from: Some(Utc::now()),
115-
// nonce,
116-
// withdraw_period_start: Utc::now(),
117-
// ad_units: Vec::new(),
118-
// }
119-
//}
71+
pub enum ValidatorsOption<'a> {
72+
Pair {
73+
leader: ValidatorDesc,
74+
follower: ValidatorDesc,
75+
},
76+
SpecValidators(SpecValidators),
77+
Generate {
78+
validators_prefix: &'a str,
79+
},
80+
}
81+
82+
pub fn get_channel_spec(validators_option: ValidatorsOption<'_>) -> ChannelSpec {
83+
use crate::EventSubmission;
84+
85+
let validators = match validators_option {
86+
ValidatorsOption::Pair { leader, follower } => [leader, follower].into(),
87+
ValidatorsOption::SpecValidators(spec_validators) => spec_validators,
88+
ValidatorsOption::Generate { validators_prefix } => [
89+
get_validator(&format!("{} leader", validators_prefix), None),
90+
get_validator(&format!("{} follower", validators_prefix), None),
91+
]
92+
.into(),
93+
};
94+
95+
let title_string = Some(<Faker as Lorem>::sentence(3, 4));
96+
97+
let title = take_one(&[&title_string, &None]).to_owned();
98+
let max_per_impression = BigNum::from(<Faker as Number>::between(250, 500));
99+
let min_per_impression = BigNum::from(<Faker as Number>::between(1, 250));
100+
let nonce = BigNum::from(<Faker as Number>::between(100_000_000, 999_999_999));
101+
let min_targeting_score =
102+
take_one(&[&None, &Some(<Faker as Number>::between(1_f64, 500_f64))]).to_owned();
103+
104+
ChannelSpec {
105+
validators,
106+
title,
107+
max_per_impression,
108+
min_per_impression,
109+
targeting: get_targeting_tags(<Faker as Number>::between(0, 5)),
110+
min_targeting_score,
111+
// @TODO: `EventSubmission` fixture issue #27
112+
event_submission: EventSubmission { allow: vec![] },
113+
created: Utc::now(),
114+
active_from: Some(Utc::now()),
115+
nonce,
116+
withdraw_period_start: Utc::now(),
117+
ad_units: Vec::new(),
118+
}
119+
}

0 commit comments

Comments
 (0)