Skip to content

Commit cbf1a70

Browse files
committed
did requested changes
1 parent e6ca5ed commit cbf1a70

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

adview-manager/src/helpers.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn get_unit_html_with_events(
163163
.iter()
164164
.map(|validator| {
165165
let fetch_url = format!(
166-
"{}/campaign/{}/events?pubAddr={}",
166+
"{}/v5/campaign/{}/events?pubAddr={}",
167167
validator.url, campaign_id, options.publisher_addr
168168
);
169169

@@ -201,12 +201,13 @@ pub fn get_unit_html_with_events(
201201
#[cfg(test)]
202202
mod test {
203203
use super::*;
204-
use crate::manager::DEFAULT_TOKENS;
205204
use adex_primitives::{
205+
config::GANACHE_CONFIG,
206206
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS, PUBLISHER},
207207
util::ApiUrl,
208208
};
209209
use scraper::{Html, Selector};
210+
use std::collections::HashSet;
210211

211212
fn get_ad_unit(media_mime: &str) -> AdUnit {
212213
AdUnit {
@@ -354,7 +355,11 @@ mod test {
354355

355356
#[test]
356357
fn getting_unit_html_with_events() {
357-
let whitelisted_tokens = DEFAULT_TOKENS.clone();
358+
let whitelisted_tokens = GANACHE_CONFIG
359+
.chains
360+
.values()
361+
.flat_map(|chain| chain.tokens.values().map(|token| token.address))
362+
.collect::<HashSet<_>>();
358363

359364
let market_url = ApiUrl::parse("https://market.adex.network").expect("should parse");
360365
let validator_1_url = ApiUrl::parse("https://tom.adex.network").expect("should parse");
@@ -403,11 +408,10 @@ mod test {
403408
.next()
404409
.expect("There should be a video");
405410

406-
// TODO: If campaign.validators doesn't guarantee order this might fail and become untestable
407-
let expected_onclick: &str = &format!("var fetchOpts = {{ method: 'POST', headers: {{ 'content-type': 'application/json' }}, body: {{'events':[{{'type':'CLICK','publisher':'{}','adUnit':'{}','adSlot':'{}','referrer':'document.referrer'}}]}} }}; fetch('{}/campaign/{}/events?pubAddr={}', fetchOpts); fetch('{}/campaign/{}/events?pubAddr={}', fetchOpts)", options.publisher_addr, ad_unit.ipfs, options.market_slot, validators.iter().nth(0).unwrap().url, campaign_id, options.publisher_addr, validators.iter().nth(1).unwrap().url, campaign_id, options.publisher_addr);
411+
let expected_onclick: &str = &format!("var fetchOpts = {{ method: 'POST', headers: {{ 'content-type': 'application/json' }}, body: {{'events':[{{'type':'CLICK','publisher':'{}','adUnit':'{}','adSlot':'{}','referrer':'document.referrer'}}]}} }}; fetch('{}/v5/campaign/{}/events?pubAddr={}', fetchOpts); fetch('{}/v5/campaign/{}/events?pubAddr={}', fetchOpts)", options.publisher_addr, ad_unit.ipfs, options.market_slot, validators[0].url, campaign_id, options.publisher_addr, validators[1].url, campaign_id, options.publisher_addr);
408412
assert_eq!(Some(expected_onclick), anchor.value().attr("onclick"));
409413

410-
let expected_onloadeddata: &str = &format!("setTimeout(function() {{ var fetchOpts = {{ method: 'POST', headers: {{ 'content-type': 'application/json' }}, body: {{'events':[{{'type':'IMPRESSION','publisher':'{}','adUnit':'{}','adSlot':'{}','referrer':'document.referrer'}}]}} }}; fetch('{}/campaign/{}/events?pubAddr={}', fetchOpts); fetch('{}/campaign/{}/events?pubAddr={}', fetchOpts) }}, 8000)", options.publisher_addr, ad_unit.ipfs, options.market_slot, validators.iter().nth(0).unwrap().url, campaign_id, options.publisher_addr, validators.iter().nth(1).unwrap().url, campaign_id, options.publisher_addr);
414+
let expected_onloadeddata: &str = &format!("setTimeout(function() {{ var fetchOpts = {{ method: 'POST', headers: {{ 'content-type': 'application/json' }}, body: {{'events':[{{'type':'IMPRESSION','publisher':'{}','adUnit':'{}','adSlot':'{}','referrer':'document.referrer'}}]}} }}; fetch('{}/v5/campaign/{}/events?pubAddr={}', fetchOpts); fetch('{}/v5/campaign/{}/events?pubAddr={}', fetchOpts) }}, 8000)", options.publisher_addr, ad_unit.ipfs, options.market_slot, validators[0].url, campaign_id, options.publisher_addr, validators[1].url, campaign_id, options.publisher_addr);
411415
assert_eq!(
412416
Some(expected_onloadeddata),
413417
video.value().attr("onloadeddata")

adview-manager/src/manager.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ impl Manager {
206206
} else {
207207
None
208208
}
209-
})
210-
.expect("Something went terribly wrong. Data is corrupted! There should be an AdUnit");
209+
})?;
211210

212211
let html = get_unit_html_with_events(
213212
&self.options,
@@ -437,11 +436,13 @@ mod test {
437436
use super::*;
438437
use crate::manager::input::Input;
439438
use adex_primitives::{
439+
config::GANACHE_CONFIG,
440440
sentry::{
441441
units_for_slot::response::{AdUnit, UnitsWithPrice},
442442
CLICK,
443443
},
444444
test_util::{CAMPAIGNS, DUMMY_AD_UNITS, DUMMY_CAMPAIGN, DUMMY_IPFS, PUBLISHER},
445+
unified_num::FromWhole,
445446
};
446447
use wiremock::{
447448
matchers::{method, path},
@@ -450,7 +451,11 @@ mod test {
450451

451452
fn setup_manager(uri: String) -> Manager {
452453
let market_url = uri.parse().unwrap();
453-
let whitelisted_tokens = DEFAULT_TOKENS.clone();
454+
let whitelisted_tokens = GANACHE_CONFIG
455+
.chains
456+
.values()
457+
.flat_map(|chain| chain.tokens.values().map(|token| token.address))
458+
.collect::<HashSet<_>>();
454459

455460
let validator_1_url = ApiUrl::parse(&format!("{}/validator-1", uri)).expect("should parse");
456461
let validator_2_url = ApiUrl::parse(&format!("{}/validator-2", uri)).expect("should parse");
@@ -646,8 +651,7 @@ mod test {
646651
}
647652

648653
#[tokio::test]
649-
#[should_panic]
650-
async fn get_sticky_ad_unit_panic_on_unit_deletion() {
654+
async fn check_sticky_ad_unit() {
651655
let server = MockServer::start().await;
652656
let mut manager = setup_manager(server.uri());
653657
let history = vec![HistoryEntry {
@@ -663,7 +667,7 @@ mod test {
663667
campaign: DUMMY_CAMPAIGN.clone(),
664668
units_with_price: vec![UnitsWithPrice {
665669
unit: AdUnit::from(&DUMMY_AD_UNITS[0]),
666-
price: UnifiedNum::from_u64(10_000),
670+
price: UnifiedNum::from_whole(0.0001),
667671
}],
668672
};
669673
let res = manager
@@ -677,13 +681,14 @@ mod test {
677681
campaign: DUMMY_CAMPAIGN.clone(),
678682
units_with_price: vec![UnitsWithPrice {
679683
unit: AdUnit::from(&DUMMY_AD_UNITS[1]),
680-
price: UnifiedNum::from_u64(10_000),
684+
price: UnifiedNum::from_whole(0.0001),
681685
}],
682686
};
683687

684-
// TODO: This panics, verify that this is the correct behaviour
685-
manager
688+
let res = manager
686689
.get_sticky_ad_unit(&[campaign], "http://localhost:1337")
687690
.await;
691+
692+
assert!(res.is_none());
688693
}
689694
}

primitives/src/targeting/input.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ impl GetField for AdView {
127127

128128
fn get(&self, field: &Self::Field) -> Self::Output {
129129
match field {
130+
// We could use `Option`, however, `try_get` will return `UnknownVariable`
131+
// this is why we use `u64::MAX` when returning the value of the field.
130132
field::AdView::SecondsSinceCampaignImpression => Value::Number(
131133
self.seconds_since_campaign_impression
132134
.unwrap_or(u64::MAX)

0 commit comments

Comments
 (0)