Skip to content

Commit 62eb194

Browse files
authored
Merge pull request #551 from AmbireTech/issue-471-tests-for-route-units-for-slot
Sentry REST API route - /units-for-slot
2 parents f748d22 + 0151e15 commit 62eb194

File tree

19 files changed

+1511
-319
lines changed

19 files changed

+1511
-319
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adview-manager/serve/src/routes.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::sync::Arc;
22

33
use adex_primitives::{
4-
sentry::IMPRESSION,
5-
supermarket::units_for_slot,
4+
sentry::{units_for_slot, IMPRESSION},
65
targeting::{input::Global, Input},
76
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS},
87
ToHex,
@@ -110,9 +109,9 @@ pub async fn get_preview_ad(Extension(state): Extension<Arc<State>>) -> Html<Str
110109

111110
debug!("Mocked response: {demand_resp:?}");
112111

113-
let supermarket_ad_unit = adex_primitives::supermarket::units_for_slot::response::AdUnit {
112+
let supermarket_ad_unit = adex_primitives::sentry::units_for_slot::response::AdUnit {
114113
/// Same as `ipfs`
115-
id: DUMMY_IPFS[1],
114+
ipfs: DUMMY_IPFS[1],
116115
media_url: "ipfs://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR".to_string(),
117116
media_mime: "image/jpeg".to_string(),
118117
target_url: "https://www.adex.network/?stremio-test-banner-1".to_string(),
@@ -163,9 +162,9 @@ pub async fn get_preview_video(Extension(state): Extension<Arc<State>>) -> Html<
163162
};
164163

165164
// legacy_728x90
166-
let video_ad_unit = adex_primitives::supermarket::units_for_slot::response::AdUnit {
165+
let video_ad_unit = adex_primitives::sentry::units_for_slot::response::AdUnit {
167166
/// Same as `ipfs`
168-
id: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh"
167+
ipfs: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh"
169168
.parse()
170169
.expect("Valid IPFS"),
171170
media_url: "ipfs://Qmevmms1AZgYXS27A9ghSjHn4DSaHMfgYcD2SoGW14RYGy".to_string(),

adview-manager/src/helpers.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::ops::{Add, Mul};
22

33
use adex_primitives::{
44
campaign::Validators,
5-
sentry::{Event, EventType, InsertEventsRequest, CLICK, IMPRESSION},
6-
supermarket::units_for_slot::response::AdUnit,
5+
sentry::{
6+
units_for_slot::response::AdUnit, Event, EventType, InsertEventsRequest, CLICK, IMPRESSION,
7+
},
78
BigNum, CampaignId,
89
};
910
use num_integer::Integer;
@@ -68,7 +69,7 @@ pub(crate) fn is_video(ad_unit: &AdUnit) -> bool {
6869

6970
/// Does not copy the JS impl, instead it generates the BigNum from the IPFS CID bytes
7071
pub(crate) fn randomized_sort_pos(ad_unit: &AdUnit, seed: BigNum) -> BigNum {
71-
let bytes = ad_unit.id.0.to_bytes();
72+
let bytes = ad_unit.ipfs.0.to_bytes();
7273

7374
let unit_id = BigNum::from_bytes_be(&bytes);
7475

@@ -138,13 +139,13 @@ pub fn get_unit_html_with_events(
138139
let event = match event_type {
139140
EventType::Impression => Event::Impression {
140141
publisher: options.publisher_addr,
141-
ad_unit: ad_unit.id,
142+
ad_unit: ad_unit.ipfs,
142143
ad_slot: options.market_slot,
143144
referrer: Some("document.referrer".to_string()),
144145
},
145146
EventType::Click => Event::Click {
146147
publisher: options.publisher_addr,
147-
ad_unit: ad_unit.id,
148+
ad_unit: ad_unit.ipfs,
148149
ad_slot: options.market_slot,
149150
referrer: Some("document.referrer".to_string()),
150151
},
@@ -204,7 +205,7 @@ mod test {
204205

205206
fn get_ad_unit(media_mime: &str) -> AdUnit {
206207
AdUnit {
207-
id: DUMMY_IPFS[0],
208+
ipfs: DUMMY_IPFS[0],
208209
media_url: "".to_string(),
209210
media_mime: media_mime.to_string(),
210211
target_url: "".to_string(),
@@ -237,7 +238,7 @@ mod test {
237238
#[test]
238239
fn test_randomized_position() {
239240
let ad_unit = AdUnit {
240-
id: DUMMY_IPFS[0],
241+
ipfs: DUMMY_IPFS[0],
241242
media_url: "ipfs://QmWWQSuPMS6aXCbZKpEjPHPUZN2NjB3YrhJTHsV4X3vb2t".to_string(),
242243
media_mime: "image/jpeg".to_string(),
243244
target_url: "https://google.com".to_string(),

adview-manager/src/manager.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! The AdView Manager
22
use adex_primitives::{
3-
sentry::IMPRESSION,
4-
supermarket::units_for_slot,
5-
supermarket::units_for_slot::response::{AdUnit, Campaign},
3+
sentry::{
4+
units_for_slot::response::{AdUnit, Campaign, Response},
5+
IMPRESSION,
6+
},
67
targeting::{self, input},
78
util::ApiUrl,
89
Address, BigNum, CampaignId, ToHex, UnifiedNum, IPFS,
@@ -200,7 +201,7 @@ impl Manager {
200201
.units_with_price
201202
.iter()
202203
.find_map(|u| {
203-
if u.unit.id == sticky_entry.unit_id {
204+
if u.unit.ipfs == sticky_entry.unit_id {
204205
Some(u.unit.clone())
205206
} else {
206207
None
@@ -239,9 +240,7 @@ impl Manager {
239240
}
240241
}
241242

242-
pub async fn get_market_demand_resp(
243-
&self,
244-
) -> Result<units_for_slot::response::Response, Error> {
243+
pub async fn get_market_demand_resp(&self) -> Result<Response, Error> {
245244
let pub_prefix = self.options.publisher_addr.to_hex();
246245

247246
let deposit_asset = self
@@ -320,7 +319,7 @@ impl Manager {
320319
.units_with_price
321320
.iter()
322321
.filter(|unit_with_price| {
323-
unit_input.ad_unit_id = Some(unit_with_price.unit.id);
322+
unit_input.ad_unit_id = Some(unit_with_price.unit.ipfs);
324323

325324
let mut output = targeting::Output {
326325
show: true,
@@ -359,7 +358,7 @@ impl Manager {
359358

360359
let new_entry = HistoryEntry {
361360
time: Utc::now(),
362-
unit_id: unit_with_price.unit.id,
361+
unit_id: unit_with_price.unit.ipfs,
363362
campaign_id: *campaign_id,
364363
slot_id: self.options.market_slot,
365364
};

docs/config/ganache.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ creators_whitelist = [
3131
'0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F',
3232
# ADVERTISER
3333
'0xDd589B43793934EF6Ad266067A0d1D4896b0dff0',
34+
# PUBLISHER
35+
'0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9',
3436
# ADVERTISER_2
3537
'0x541b401362Ea1D489D322579552B099e801F3632',
3638
]
@@ -58,9 +60,10 @@ keep_alive_interval = 1200000
5860
# This will limit the returned Campaigns to the set number
5961
max_campaigns_earning_from = 25
6062

61-
# 0.01 (UnifiedNum) per 1000 impressions
62-
# 1_000 * (per) 1_000 / 10^8 = 0.01
63-
global_min_impression_price = '1000000'
63+
# 0.0001 (UnifiedNum) per 1000 impressions
64+
# 10 * (per) 1_000 / 10^8 = 0.0001
65+
# 0.00010000
66+
global_min_impression_price = '10000'
6467

6568
[chain."Ganache #1"]
6669
chain_id = 1

primitives/examples/get_cfg_response.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn main() {
2525
"creators_whitelist": [
2626
"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F",
2727
"0xDd589B43793934EF6Ad266067A0d1D4896b0dff0",
28+
"0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
2829
"0x541b401362Ea1D489D322579552B099e801F3632"
2930
],
3031
"validators_whitelist": [
@@ -70,7 +71,7 @@ fn main() {
7071
"limits": {
7172
"units_for_slot": {
7273
"max_campaigns_earning_from": 25,
73-
"global_min_impression_price": "1000000"
74+
"global_min_impression_price": "10000"
7475
}
7576
}
7677
});

primitives/src/ad_slot.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{targeting::Rule, Address, UnifiedNum, ValidatorId, IPFS};
1+
use crate::{targeting::Rules, Address, UnifiedNum, ValidatorId, IPFS};
22
use chrono::{
33
serde::{ts_milliseconds, ts_milliseconds_option},
44
DateTime, Utc,
@@ -25,20 +25,24 @@ pub struct AdSlot {
2525
/// see IAB ad unit guidelines and iab_flex_{adUnitName} (see IAB's new ad portfolio and PDF)
2626
#[serde(rename = "type")]
2727
pub ad_type: String,
28-
/// HashMap<DepositAsset, UnifiedNum> for the minimum payment accepted per impression
28+
/// The minimum [`IMPRESSION`] payment accepted for the slot per deposit asset (token address).
29+
///
30+
/// `HashMap<DepositAsset, UnifiedNum>`
31+
///
32+
/// [`IMPRESSION`]: crate::sentry::IMPRESSION
2933
#[serde(default)]
3034
pub min_per_impression: Option<HashMap<Address, UnifiedNum>>,
3135
#[serde(default)]
32-
pub rules: Vec<Rule>,
36+
pub rules: Rules,
3337
/// Valid ipfs hash for Ad Unit object. It will be used as fallback data (optional)
3438
#[serde(default)]
3539
pub fallback_unit: Option<IPFS>,
36-
/// User address from the session
40+
/// The AdSlot owner (Publisher)
3741
pub owner: ValidatorId,
3842
/// UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
3943
#[serde(with = "ts_milliseconds")]
4044
pub created: DateTime<Utc>,
41-
/// the name of the unit used in platform UI
45+
/// The name of the unit used in platform UI
4246
#[serde(default)]
4347
pub title: Option<String>,
4448
/// arbitrary text used in platform UI

primitives/src/campaign.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,13 @@ mod pricing {
255255

256256
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
257257
pub struct Pricing {
258+
/// The minimum payable amount for a single event
258259
pub min: UnifiedNum,
260+
/// The maximum payable amount for a single event
259261
pub max: UnifiedNum,
260262
}
261263

264+
/// The pricing bounds (minimum and maximum payable amount) per event type for 1 event.
262265
#[derive(Default, Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
263266
#[serde(transparent)]
264267
pub struct PricingBounds(HashMap<EventType, Pricing>);

primitives/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub struct Config {
181181
#[serde(rename = "chain")]
182182
pub chains: HashMap<String, ChainInfo>,
183183
pub platform: PlatformConfig,
184+
/// Any limits applied to Sentry or Validator.
184185
pub limits: Limits,
185186
}
186187

primitives/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub mod merkle_tree;
4444
pub mod platform;
4545
pub mod sentry;
4646
pub mod spender;
47-
pub mod supermarket;
4847
pub mod targeting;
4948
// It's not possible to enable this feature for doctest,
5049
// so we always must pass `--feature=test-util` or `--all-features` when running doctests:

0 commit comments

Comments
 (0)