Skip to content

Commit 2bbdc1e

Browse files
committed
primitives - test_util - add 3 Campaigns for testing
1 parent 6029cc3 commit 2bbdc1e

File tree

1 file changed

+201
-10
lines changed

1 file changed

+201
-10
lines changed

primitives/src/test_util.rs

Lines changed: 201 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
sentry::{CLICK, IMPRESSION},
1111
targeting::Rules,
1212
unified_num::FromWhole,
13-
AdUnit, Address, Campaign, Channel, EventSubmission, UnifiedNum, ValidatorDesc, ValidatorId,
14-
IPFS,
13+
AdUnit, Address, Campaign, ChainOf, Channel, EventSubmission, UnifiedNum, ValidatorDesc,
14+
ValidatorId, IPFS,
1515
};
1616

1717
pub use logger::discard_logger;
@@ -300,12 +300,203 @@ pub static DUMMY_IPFS: Lazy<[IPFS; 5]> = Lazy::new(|| {
300300
]
301301
});
302302

303-
#[cfg(test)]
304-
mod test {
305-
use super::*;
303+
/// List of test campaigns with keys `Campaign {Chain id} #{Number campaign}`
304+
pub static CAMPAIGNS: Lazy<[ChainOf<Campaign>; 3]> = Lazy::new(|| {
305+
let campaign_1337_1 = {
306+
let ganache_chain_info = GANACHE_CONFIG.chains["Ganache #1337"].clone();
307+
let token_info = ganache_chain_info.tokens["Mocked TOKEN 1337"].clone();
306308

307-
#[test]
308-
fn test_ids() {
309-
println!("{:?}", IDS[&LEADER]);
310-
}
311-
}
309+
let channel = Channel {
310+
leader: IDS[&LEADER],
311+
follower: IDS[&FOLLOWER],
312+
guardian: *GUARDIAN,
313+
token: token_info.address,
314+
nonce: 0_u64.into(),
315+
};
316+
317+
let leader_desc = ValidatorDesc {
318+
fee: UnifiedNum::from_whole(0.5),
319+
..DUMMY_VALIDATOR_LEADER.clone()
320+
};
321+
322+
let follower_desc = ValidatorDesc {
323+
fee: UnifiedNum::from_whole(0.4),
324+
..DUMMY_VALIDATOR_FOLLOWER.clone()
325+
};
326+
327+
let validators = Validators::new((leader_desc, follower_desc));
328+
329+
ChainOf::new(ganache_chain_info.chain, token_info).with_campaign(Campaign {
330+
id: "0x936da01f9abd4d9d80c702af85c822a8"
331+
.parse()
332+
.expect("Should parse"),
333+
channel,
334+
creator: *ADVERTISER,
335+
// 100 000
336+
budget: UnifiedNum::from_whole(100_000),
337+
validators,
338+
title: Some("Dummy Campaign".to_string()),
339+
pricing_bounds: vec![
340+
(
341+
IMPRESSION,
342+
Pricing {
343+
min: UnifiedNum::from_whole(0.0004),
344+
max: UnifiedNum::from_whole(0.0005),
345+
},
346+
),
347+
(
348+
CLICK,
349+
Pricing {
350+
min: UnifiedNum::from_whole(0.0006),
351+
max: UnifiedNum::from_whole(0.001),
352+
},
353+
),
354+
]
355+
.into_iter()
356+
.collect(),
357+
event_submission: Some(EventSubmission { allow: vec![] }),
358+
ad_units: vec![DUMMY_AD_UNITS[0].clone(), DUMMY_AD_UNITS[1].clone()],
359+
targeting_rules: Rules::new(),
360+
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
361+
active: Active {
362+
from: Some(Utc.ymd(2022, 6, 27).and_hms(0, 0, 0)),
363+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
364+
},
365+
})
366+
};
367+
368+
let campaign_1337_2 = {
369+
let ganache_chain_info = GANACHE_CONFIG.chains["Ganache #1337"].clone();
370+
let token_info = ganache_chain_info.tokens["Mocked TOKEN 1337"].clone();
371+
372+
let channel = Channel {
373+
leader: IDS[&FOLLOWER],
374+
follower: IDS[&LEADER],
375+
guardian: *GUARDIAN_2,
376+
token: token_info.address,
377+
nonce: 0_u64.into(),
378+
};
379+
380+
let leader_desc = ValidatorDesc {
381+
fee: UnifiedNum::from_whole(0.1),
382+
..DUMMY_VALIDATOR_FOLLOWER.clone()
383+
};
384+
385+
let follower_desc = ValidatorDesc {
386+
fee: UnifiedNum::from_whole(0.05),
387+
..DUMMY_VALIDATOR_LEADER.clone()
388+
};
389+
let validators = Validators::new((leader_desc, follower_desc));
390+
391+
ChainOf::new(ganache_chain_info.chain, token_info).with_campaign(Campaign {
392+
id: "0x127b98248f4e4b73af409d10f62daeaa"
393+
.parse()
394+
.expect("Should parse"),
395+
channel,
396+
creator: *ADVERTISER,
397+
// 200 000
398+
budget: UnifiedNum::from_whole(200_000.0),
399+
validators,
400+
title: Some("Dummy Campaign 2 in Chain #1337".to_string()),
401+
pricing_bounds: vec![
402+
(
403+
IMPRESSION,
404+
Pricing {
405+
min: UnifiedNum::from_whole(0.0004),
406+
max: UnifiedNum::from_whole(0.0005),
407+
},
408+
),
409+
(
410+
CLICK,
411+
Pricing {
412+
min: UnifiedNum::from_whole(0.0006),
413+
max: UnifiedNum::from_whole(0.001),
414+
},
415+
),
416+
]
417+
.into_iter()
418+
.collect(),
419+
event_submission: Some(EventSubmission { allow: vec![] }),
420+
ad_units: vec![DUMMY_AD_UNITS[0].clone(), DUMMY_AD_UNITS[1].clone()],
421+
targeting_rules: Rules::new(),
422+
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
423+
active: Active {
424+
from: None,
425+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
426+
},
427+
})
428+
};
429+
430+
let campaign_1_1 = {
431+
let ganache_chain_info = GANACHE_CONFIG.chains["Ganache #1"].clone();
432+
let token_info = ganache_chain_info.tokens["Mocked TOKEN 1"].clone();
433+
434+
let channel = Channel {
435+
leader: IDS[&LEADER],
436+
follower: IDS[&FOLLOWER],
437+
guardian: *GUARDIAN_2,
438+
token: token_info.address,
439+
nonce: 1_u64.into(),
440+
};
441+
442+
let leader_desc = ValidatorDesc {
443+
fee: UnifiedNum::from_whole(0.02),
444+
..DUMMY_VALIDATOR_LEADER.clone()
445+
};
446+
447+
let follower_desc = ValidatorDesc {
448+
fee: UnifiedNum::from_whole(0.0175),
449+
..DUMMY_VALIDATOR_FOLLOWER.clone()
450+
};
451+
452+
let validators = Validators::new((leader_desc, follower_desc));
453+
454+
ChainOf::new(ganache_chain_info.chain, token_info).with_campaign(Campaign {
455+
id: "0xa78f3492481b41a688488a7aa1ff17df"
456+
.parse()
457+
.expect("Should parse"),
458+
channel,
459+
creator: *ADVERTISER_2,
460+
// 20 000
461+
budget: UnifiedNum::from_whole(20_000),
462+
validators,
463+
title: Some("Dummy Campaign 3 in Chain #1".to_string()),
464+
pricing_bounds: vec![
465+
(
466+
IMPRESSION,
467+
Pricing {
468+
// 0.01500000
469+
// Per 1000 = 15.00000000
470+
min: UnifiedNum::from_whole(0.015),
471+
// 0.0250000
472+
// Per 1000 = 25.00000000
473+
max: UnifiedNum::from_whole(0.025),
474+
},
475+
),
476+
(
477+
CLICK,
478+
Pricing {
479+
// 0.03500000
480+
// Per 1000 = 35.00000000
481+
min: UnifiedNum::from_whole(0.035),
482+
// 0.06500000
483+
// Per 1000 = 65.00000000
484+
max: UnifiedNum::from_whole(0.065),
485+
},
486+
),
487+
]
488+
.into_iter()
489+
.collect(),
490+
event_submission: Some(EventSubmission { allow: vec![] }),
491+
ad_units: vec![DUMMY_AD_UNITS[2].clone(), DUMMY_AD_UNITS[3].clone()],
492+
targeting_rules: Rules::new(),
493+
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
494+
active: Active {
495+
from: None,
496+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
497+
},
498+
})
499+
};
500+
501+
[campaign_1337_1, campaign_1337_2, campaign_1_1]
502+
});

0 commit comments

Comments
 (0)