Skip to content

Commit 70376b3

Browse files
committed
Fix merge issues & run rustfmt
1 parent fa39cb1 commit 70376b3

File tree

4 files changed

+75
-56
lines changed

4 files changed

+75
-56
lines changed

sentry/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<A: Adapter + 'static> Application<A> {
105105
logger: Logger,
106106
redis: MultiplexedConnection,
107107
pool: DbPool,
108-
campaign_remaining: CampaignRemaining
108+
campaign_remaining: CampaignRemaining,
109109
) -> Self {
110110
Self {
111111
adapter,
@@ -511,14 +511,18 @@ pub mod test_util {
511511
use primitives::{
512512
adapter::DummyAdapterOptions,
513513
config::configuration,
514-
util::tests::{
515-
discard_logger,
516-
prep_db::{IDS},
514+
util::tests::{discard_logger, prep_db::IDS},
515+
};
516+
517+
use crate::{
518+
db::{
519+
redis_pool::TESTS_POOL,
520+
tests_postgres::{setup_test_migrations, DATABASE_POOL},
521+
CampaignRemaining,
517522
},
523+
Application,
518524
};
519525

520-
use crate::{Application, db::{CampaignRemaining, redis_pool::TESTS_POOL, tests_postgres::{setup_test_migrations, DATABASE_POOL}}};
521-
522526
/// Uses production configuration to setup the correct Contract addresses for tokens.
523527
pub async fn setup_dummy_app() -> Application<DummyAdapter> {
524528
let config = configuration("production", None).expect("Should get Config");
@@ -546,7 +550,7 @@ pub mod test_util {
546550
discard_logger(),
547551
redis.connection.clone(),
548552
database.pool.clone(),
549-
campaign_remaining
553+
campaign_remaining,
550554
);
551555

552556
app

sentry/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use primitives::adapter::{Adapter, DummyAdapterOptions, KeystoreOptions};
1010
use primitives::config::configuration;
1111
use primitives::util::tests::prep_db::{AUTH, IDS};
1212
use primitives::ValidatorId;
13-
use sentry::db::{CampaignRemaining, postgres_connection, redis_connection, setup_migrations};
13+
use sentry::db::{postgres_connection, redis_connection, setup_migrations, CampaignRemaining};
1414
use sentry::Application;
1515
use slog::{error, info, Logger};
1616
use std::{
@@ -120,14 +120,28 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
120120
match adapter {
121121
AdapterTypes::EthereumAdapter(adapter) => {
122122
run(
123-
Application::new(*adapter, config, logger, redis, postgres, campaign_remaining),
123+
Application::new(
124+
*adapter,
125+
config,
126+
logger,
127+
redis,
128+
postgres,
129+
campaign_remaining,
130+
),
124131
socket_addr,
125132
)
126133
.await
127134
}
128135
AdapterTypes::DummyAdapter(adapter) => {
129136
run(
130-
Application::new(*adapter, config, logger, redis, postgres, campaign_remaining),
137+
Application::new(
138+
*adapter,
139+
config,
140+
logger,
141+
redis,
142+
postgres,
143+
campaign_remaining,
144+
),
131145
socket_addr,
132146
)
133147
.await

sentry/src/payout.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ pub fn get_payout(
7777

7878
if output.show {
7979
let price = match output.price.get(&event_type) {
80-
Some(output_price) => {
81-
max(pricing.min, min(pricing.max, *output_price))
82-
}
80+
Some(output_price) => max(pricing.min, min(pricing.max, *output_price)),
8381
None => max(pricing.min, pricing.max),
8482
};
8583

sentry/src/routes/campaign.rs

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
1-
<<<<<<< HEAD
2-
use crate::{success_response, Application, ResponseError};
3-
use hyper::{Body, Request, Response};
4-
use primitives::{
5-
adapter::Adapter,
6-
sentry::{campaign_create::CreateCampaign, SuccessResponse},
7-
=======
81
use crate::{
9-
access::{self, check_access},
102
db::{
11-
accounting::get_accounting_spent,
3+
accounting::{get_accounting, Side},
124
campaign::{get_campaigns_by_channel, insert_campaign, update_campaign},
135
spendable::fetch_spendable,
146
CampaignRemaining, DbPool, RedisError,
157
},
16-
success_response, Application, Auth, ResponseError, Session,
8+
success_response, Application, Auth, ResponseError,
179
};
18-
use chrono::Utc;
1910
use deadpool_postgres::PoolError;
2011
use hyper::{Body, Request, Response};
2112
use primitives::{
2213
adapter::Adapter,
2314
campaign_validator::Validator,
24-
sentry::{
25-
campaign_create::{CreateCampaign, ModifyCampaign},
26-
Event, SuccessResponse,
27-
},
15+
sentry::campaign_create::{CreateCampaign, ModifyCampaign},
2816
Address, Campaign, UnifiedNum,
2917
};
3018
use slog::error;
31-
use std::{
32-
cmp::{max, Ordering},
33-
collections::HashMap,
34-
>>>>>>> issue-382-campaign-routes
35-
};
19+
use std::cmp::{max, Ordering};
3620
use thiserror::Error;
3721
use tokio_postgres::error::SqlState;
3822

@@ -88,9 +72,15 @@ pub async fn create_campaign<A: Adapter>(
8872

8973
let total_remaining =
9074
{
91-
let accounting_spent =
92-
get_accounting_spent(app.pool.clone(), &campaign.creator, &campaign.channel.id())
93-
.await?;
75+
let accounting_spent = get_accounting(
76+
app.pool.clone(),
77+
campaign.channel.id(),
78+
campaign.creator,
79+
Side::Spender,
80+
)
81+
.await?
82+
.map(|accounting| accounting.amount)
83+
.unwrap_or_default();
9484

9585
let latest_spendable =
9686
fetch_spendable(app.pool.clone(), &campaign.creator, &campaign.channel.id())
@@ -168,7 +158,7 @@ pub async fn create_campaign<A: Adapter>(
168158
}
169159

170160
pub mod update_campaign {
171-
use crate::db::CampaignRemaining;
161+
use crate::db::{accounting::Side, CampaignRemaining};
172162

173163
use super::*;
174164

@@ -221,9 +211,15 @@ pub mod update_campaign {
221211
// sum(AllChannelCampaigns.map(getRemaining)) + DeltaBudgetForMutatedCampaign <= totalDeposited - totalSpent
222212
// sum(AllChannelCampaigns.map(getRemaining)) - DeltaBudgetForMutatedCampaign <= totalDeposited - totalSpent
223213
if let Some(delta_budget) = delta_budget {
224-
let accounting_spent =
225-
get_accounting_spent(pool.clone(), &campaign.creator, &campaign.channel.id())
226-
.await?;
214+
let accounting_spent = get_accounting(
215+
pool.clone(),
216+
campaign.channel.id(),
217+
campaign.creator,
218+
Side::Spender,
219+
)
220+
.await?
221+
.map(|accounting| accounting.amount)
222+
.unwrap_or_default();
227223

228224
let latest_spendable =
229225
fetch_spendable(pool.clone(), &campaign.creator, &campaign.channel.id())
@@ -779,12 +775,11 @@ pub mod insert_events {
779775
mod test {
780776
use super::{update_campaign::modify_campaign, *};
781777
use crate::{
782-
db::{accounting::insert_accounting, spendable::insert_spendable},
778+
db::{accounting::update_accounting, spendable::insert_spendable},
783779
test_util::setup_dummy_app,
784780
};
785781
use hyper::StatusCode;
786782
use primitives::{
787-
sentry::accounting::{Balances, CheckedState},
788783
spender::{Deposit, Spendable},
789784
util::tests::prep_db::DUMMY_CAMPAIGN,
790785
ValidatorId,
@@ -831,13 +826,15 @@ mod test {
831826
.await
832827
.expect("Should insert Spendable for Campaign creator"));
833828

834-
let mut balances = Balances::<CheckedState>::default();
835-
balances.add_spender(create.creator);
836-
837-
// TODO: Replace this once https://github.com/AdExNetwork/adex-validator-stack-rust/pull/413 is merged
838-
let _accounting = insert_accounting(app.pool.clone(), create.channel.clone(), balances)
839-
.await
840-
.expect("Should create Accounting");
829+
let _accounting = update_accounting(
830+
app.pool.clone(),
831+
create.channel.id(),
832+
create.creator,
833+
Side::Spender,
834+
UnifiedNum::default(),
835+
)
836+
.await
837+
.expect("Should create Accounting");
841838

842839
let create_response = create_campaign(build_request(create), &app)
843840
.await
@@ -928,7 +925,12 @@ mod test {
928925
.await
929926
.expect_err("Should return Error response");
930927

931-
assert_eq!(ResponseError::BadRequest("Not enough deposit left for the new campaign's budget".to_string()), create_err);
928+
assert_eq!(
929+
ResponseError::BadRequest(
930+
"Not enough deposit left for the new campaign's budget".to_string()
931+
),
932+
create_err
933+
);
932934
}
933935

934936
// modify first campaign, by lowering the budget from 1000 to 900
@@ -967,7 +969,7 @@ mod test {
967969
.await
968970
.expect("Should return create campaign");
969971

970-
let json = hyper::body::to_bytes(create_response.into_body())
972+
let json = hyper::body::to_bytes(create_response.into_body())
971973
.await
972974
.expect("Should get json");
973975

@@ -991,12 +993,13 @@ mod test {
991993
targeting_rules: None,
992994
};
993995

994-
let modify_err =
995-
modify_campaign(&app.pool, &app.campaign_remaining, modified, modify)
996-
.await
997-
.expect_err("Should return Error response");
996+
let modify_err = modify_campaign(&app.pool, &app.campaign_remaining, modified, modify)
997+
.await
998+
.expect_err("Should return Error response");
998999

999-
assert!(matches!(modify_err, Error::NewBudget(string) if string == "Not enough deposit left for the campaign's new budget"));
1000+
assert!(
1001+
matches!(modify_err, Error::NewBudget(string) if string == "Not enough deposit left for the campaign's new budget")
1002+
);
10001003
}
10011004
}
10021005
}

0 commit comments

Comments
 (0)