Skip to content

Commit 9deaf37

Browse files
committed
primitives - sentry - Event::Impression.publisher - use ValidatorId
1 parent 2af6403 commit 9deaf37

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

primitives/src/sentry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct ApproveStateValidatorMessage {
3232
pub enum Event {
3333
#[serde(rename_all = "camelCase")]
3434
Impression {
35-
publisher: String,
35+
publisher: ValidatorId,
3636
ad_unit: Option<String>,
3737
},
3838
Click {

sentry/src/access.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ mod test {
188188

189189
channel
190190
}
191+
191192
fn get_impression_events(count: i8) -> Vec<Event> {
192193
(0..count)
193194
.map(|_| Event::Impression {
194-
publisher: "working".to_string(),
195+
publisher: IDS["publisher2"].clone(),
195196
ad_unit: None,
196197
})
197198
.collect()

sentry/src/event_reducer.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use primitives::sentry::{AggregateEvents, Event, EventAggregate};
2-
use primitives::Channel;
2+
use primitives::{Channel, ValidatorId};
33

44
// @TODO: Remove attribute once we use this function!
55
#[allow(dead_code)]
@@ -13,7 +13,7 @@ pub(crate) fn reduce(channel: &Channel, initial_aggr: &mut EventAggregate, ev: &
1313
initial_aggr.events.insert("IMPRESSION".to_owned(), merge);
1414
}
1515
Event::Close => {
16-
let creator = channel.creator.to_string();
16+
let creator = channel.creator.clone();
1717
let close_event = AggregateEvents {
1818
event_counts: Some(vec![(creator.clone(), 1.into())].into_iter().collect()),
1919
event_payouts: vec![(creator, channel.deposit_amount.clone())]
@@ -28,22 +28,22 @@ pub(crate) fn reduce(channel: &Channel, initial_aggr: &mut EventAggregate, ev: &
2828

2929
fn merge_impression_ev(
3030
impression: Option<&AggregateEvents>,
31-
earner: &str,
31+
earner: &ValidatorId,
3232
channel: &Channel,
3333
) -> AggregateEvents {
3434
let mut impression = impression.map(Clone::clone).unwrap_or_default();
3535

3636
let event_count = impression
3737
.event_counts
3838
.get_or_insert_with(Default::default)
39-
.entry(earner.to_string())
39+
.entry(earner.clone())
4040
.or_insert_with(|| 0.into());
4141

4242
*event_count += &1.into();
4343

4444
let event_payouts = impression
4545
.event_payouts
46-
.entry(earner.to_string())
46+
.entry(earner.clone())
4747
.or_insert_with(|| 0.into());
4848
*event_payouts += &channel.spec.min_per_impression;
4949

@@ -54,7 +54,7 @@ fn merge_impression_ev(
5454
mod test {
5555
use super::*;
5656
use chrono::Utc;
57-
use primitives::util::tests::prep_db::DUMMY_CHANNEL;
57+
use primitives::util::tests::prep_db::{DUMMY_CHANNEL, IDS};
5858
use primitives::BigNum;
5959

6060
#[test]
@@ -71,7 +71,7 @@ mod test {
7171
};
7272

7373
let event = Event::Impression {
74-
publisher: "myAwesomePublisher".to_string(),
74+
publisher: IDS["publisher"].clone(),
7575
ad_unit: None,
7676
};
7777

@@ -90,15 +90,15 @@ mod test {
9090
.event_counts
9191
.as_ref()
9292
.expect("there should be event_counts set")
93-
.get("myAwesomePublisher")
93+
.get(&IDS["publisher"])
9494
.expect("There should be myAwesomePublisher event_counts key");
9595
assert_eq!(event_counts, &BigNum::from(101));
9696

9797
let event_payouts = impression_event
9898
.event_counts
9999
.as_ref()
100100
.expect("there should be event_counts set")
101-
.get("myAwesomePublisher")
101+
.get(&IDS["publisher"])
102102
.expect("There should be myAwesomePublisher event_payouts key");
103103
assert_eq!(event_payouts, &BigNum::from(101));
104104
}

0 commit comments

Comments
 (0)