Skip to content

Commit ca1fcb7

Browse files
authored
Merge branch 'dev' into add-exhausted-property
2 parents f626f28 + bc4308b commit ca1fcb7

File tree

13 files changed

+1293
-131
lines changed

13 files changed

+1293
-131
lines changed

Cargo.lock

Lines changed: 706 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ We need two services to be able to run `Sentry`: `Postgres` and `Redis`.
3939

4040
### Running Redis
4141

42-
`docker run --rm --name adex-validator-redis -d redis`
42+
`docker run --rm -p 6379:6379 --name adex-validator-redis -d redis`
4343

4444
### Running Sentry Rest API
4545

adapter/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ serde = { version = "^1.0", features = ['derive'] }
1414
serde_json = "1.0"
1515
serde-hex = "0.1.0"
1616
# Ethereum
17-
web3 = { git = "https://github.com/tomusdrw/rust-web3" }
17+
web3 = { git = "https://github.com/elpiel/rust-web3" }
1818
eth_checksum = "0.1.1"
1919
tiny-keccak = "1.5"
2020
ethstore = { git = "https://github.com/elpiel/openethereum", branch = "remove-dir-depenedency-for-ethstore" }
@@ -31,3 +31,4 @@ async-trait = "0.1.40"
3131
[dev-dependencies]
3232
byteorder = "1.3"
3333
tokio = { version = "0.2", features = ["macros", "rt-threaded"] }
34+
wiremock = "0.3"

adapter/src/ethereum.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ impl RelayerClient {
295295
) -> Result<bool, AdapterError<Error>> {
296296
use reqwest::Response;
297297
use std::collections::HashMap;
298-
299298
let relay_url = format!(
300299
"{}/identity/by-owner/{}",
301300
self.relayer_url,
@@ -313,7 +312,6 @@ impl RelayerClient {
313312
let has_privileges = identities_owned
314313
.get(identity)
315314
.map_or(false, |privileges| *privileges > 0);
316-
317315
Ok(has_privileges)
318316
}
319317
}
@@ -429,12 +427,16 @@ mod test {
429427
use crate::EthereumChannel;
430428
use chrono::{Duration, Utc};
431429
use hex::FromHex;
432-
use primitives::adapter::KeystoreOptions;
433430
use primitives::config::configuration;
434431
use primitives::ChannelId;
432+
use primitives::{adapter::KeystoreOptions, targeting::Rules};
435433
use primitives::{ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc};
436434
use std::convert::TryFrom;
437435
use web3::types::Address;
436+
use wiremock::{
437+
matchers::{method, path},
438+
Mock, MockServer, ResponseTemplate,
439+
};
438440

439441
fn setup_eth_adapter(contract_address: Option<[u8; 20]>) -> EthereumAdapter {
440442
let mut config = configuration("development", None).expect("failed parse config");
@@ -543,12 +545,23 @@ mod test {
543545
}
544546

545547
#[tokio::test]
546-
#[ignore]
547548
async fn test_session_from_token() {
548549
use primitives::ToETHChecksum;
550+
use std::collections::HashMap;
551+
549552
let identity = ValidatorId::try_from("0x5B04DBc513F90CaAFAa09307Ad5e3C65EB4b26F0").unwrap();
553+
let server = MockServer::start().await;
554+
let mut identities_owned: HashMap<ValidatorId, u8> = HashMap::new();
555+
identities_owned.insert(identity, 2);
550556

551557
let mut eth_adapter = setup_eth_adapter(None);
558+
559+
Mock::given(method("GET"))
560+
.and(path(format!("/identity/by-owner/{}", eth_adapter.whoami())))
561+
.respond_with(ResponseTemplate::new(200).set_body_json(&identities_owned))
562+
.mount(&server)
563+
.await;
564+
552565
eth_adapter.unlock().expect("should unlock eth adapter");
553566
let wallet = eth_adapter.wallet.clone();
554567

@@ -651,13 +664,13 @@ mod test {
651664
deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())),
652665
deposit_amount: 2_000.into(),
653666
valid_until: Utc::now() + Duration::days(2),
654-
targeting_rules: vec![],
667+
targeting_rules: Rules::new(),
655668
spec: ChannelSpec {
656669
title: None,
657670
validators: SpecValidators::new(leader_validator_desc, follower_validator_desc),
658671
max_per_impression: 10.into(),
659672
min_per_impression: 10.into(),
660-
targeting_rules: vec![],
673+
targeting_rules: Rules::new(),
661674
event_submission: Some(EventSubmission { allow: vec![] }),
662675
created: Utc::now(),
663676
active_from: None,

primitives/src/ad_slot.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use crate::{targeting::Rule, BigNum, ValidatorId};
2-
use chrono::{DateTime, Utc};
2+
use chrono::{
3+
serde::{ts_milliseconds, ts_milliseconds_option},
4+
DateTime, Utc,
5+
};
36
use serde::{Deserialize, Serialize};
47
use std::collections::HashMap;
58

69
/// See [AdEx Protocol adSlot.md][protocol] & [adex-models AdSlot.js][adex-models] for more details.
710
/// [protocol]: https://github.com/AdExNetwork/adex-protocol/blob/master/adSlot.md
811
/// [adex-models]: https://github.com/AdExNetwork/adex-models/blob/master/src/models/AdSlot.js
9-
#[derive(Serialize, Deserialize, Debug, Clone)]
12+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
1013
#[serde(rename_all = "camelCase")]
1114
pub struct AdSlot {
1215
/// valid ipfs hash of spec props below
@@ -32,6 +35,7 @@ pub struct AdSlot {
3235
/// User address from the session
3336
pub owner: ValidatorId,
3437
/// UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
38+
#[serde(with = "ts_milliseconds")]
3539
pub created: DateTime<Utc>,
3640
/// the name of the unit used in platform UI
3741
#[serde(default)]
@@ -45,5 +49,6 @@ pub struct AdSlot {
4549
#[serde(default)]
4650
pub archived: bool,
4751
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
52+
#[serde(with = "ts_milliseconds_option")]
4853
pub modified: Option<DateTime<Utc>>,
4954
}

primitives/src/ad_unit.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use chrono::{DateTime, Utc};
1+
use chrono::{
2+
serde::{ts_milliseconds, ts_milliseconds_option},
3+
DateTime, Utc,
4+
};
25
use serde::{Deserialize, Serialize};
36

47
use crate::{ValidatorId, IPFS};
@@ -25,18 +28,27 @@ pub struct AdUnit {
2528
/// Advertised URL
2629
pub target_url: String,
2730
/// Number; minimum targeting score (optional)
31+
#[serde(default, skip_serializing_if = "Option::is_none")]
2832
pub min_targeting_score: Option<f64>,
2933
/// user address from the session
3034
pub owner: ValidatorId,
3135
/// number, UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
36+
#[serde(with = "ts_milliseconds")]
3237
pub created: DateTime<Utc>,
3338
/// the name of the unit used in platform UI
39+
#[serde(default, skip_serializing_if = "Option::is_none")]
3440
pub title: Option<String>,
3541
/// arbitrary text used in platform UI
42+
#[serde(default, skip_serializing_if = "Option::is_none")]
3643
pub description: Option<String>,
3744
/// user can change it - used for filtering in platform UI
3845
#[serde(default)]
3946
pub archived: bool,
4047
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
48+
#[serde(
49+
default,
50+
with = "ts_milliseconds_option",
51+
skip_serializing_if = "Option::is_none"
52+
)]
4153
pub modified: Option<DateTime<Utc>>,
4254
}

primitives/src/channel.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use chrono::{DateTime, Utc};
88
use serde::{Deserialize, Deserializer, Serialize};
99
use serde_hex::{SerHex, StrictPfx};
1010

11-
use crate::{targeting::Rule, AdUnit, BigNum, EventSubmission, ValidatorDesc, ValidatorId};
11+
use crate::{targeting::Rules, AdUnit, BigNum, EventSubmission, ValidatorDesc, ValidatorId};
1212
use hex::{FromHex, FromHexError};
1313

1414
#[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
@@ -96,7 +96,7 @@ pub struct Channel {
9696
#[serde(with = "ts_seconds")]
9797
pub valid_until: DateTime<Utc>,
9898
#[serde(default)]
99-
pub targeting_rules: Vec<Rule>,
99+
pub targeting_rules: Rules,
100100
pub spec: ChannelSpec,
101101
#[serde(default)]
102102
pub exhausted: Vec<bool>
@@ -187,7 +187,7 @@ pub struct ChannelSpec {
187187
#[serde(default, skip_serializing_if = "Vec::is_empty")]
188188
pub ad_units: Vec<AdUnit>,
189189
#[serde(default)]
190-
pub targeting_rules: Vec<Rule>,
190+
pub targeting_rules: Rules,
191191
}
192192

193193
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
@@ -386,7 +386,7 @@ mod test {
386386
pub mod postgres {
387387
use super::ChannelId;
388388
use super::{Channel, ChannelSpec};
389-
use crate::targeting::Rule;
389+
use crate::targeting::Rules;
390390
use bytes::BytesMut;
391391
use hex::FromHex;
392392
use postgres_types::{accepts, to_sql_checked, FromSql, IsNull, Json, ToSql, Type};
@@ -401,7 +401,7 @@ pub mod postgres {
401401
deposit_asset: row.get("deposit_asset"),
402402
deposit_amount: row.get("deposit_amount"),
403403
valid_until: row.get("valid_until"),
404-
targeting_rules: row.get::<_, Json<Vec<Rule>>>("targeting_rules").0,
404+
targeting_rules: row.get::<_, Json<Rules>>("targeting_rules").0,
405405
spec: row.get::<_, Json<ChannelSpec>>("spec").0,
406406
exhausted: row.get("exhausted"),
407407
}

0 commit comments

Comments
 (0)