Skip to content

Commit cb21b5b

Browse files
committed
test fixes
1 parent a2eb3eb commit cb21b5b

2 files changed

Lines changed: 29 additions & 42 deletions

File tree

sentry/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ async fn channels_router<A: Adapter + 'static>(
379379
CHANNEL_SPENDER_LEAF_AND_TOTAL_DEPOSITED.captures(&path),
380380
method,
381381
) {
382-
req = AuthRequired.call(req, app).await?;
383382
req = Chain::new()
384383
.chain(AuthRequired)
385384
.chain(ChannelLoad)

sentry/src/routes/channel.rs

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use crate::db::{
55
},
66
get_channel_by_id, insert_channel, insert_validator_messages, list_channels,
77
spendable::{fetch_spendable, update_spendable},
8-
DbPool, PoolError
8+
DbPool, PoolError,
99
};
1010
use crate::{success_response, Application, Auth, ResponseError, RouteParams};
1111
use futures::future::try_join_all;
1212
use hex::FromHex;
1313
use hyper::{Body, Request, Response};
1414
use primitives::{
1515
adapter::Adapter,
16+
balances::UncheckedState,
1617
channel_v5::Channel as ChannelV5,
1718
config::TokenInfo,
18-
balances::UncheckedState,
1919
sentry::{
2020
channel_list::{ChannelListQuery, LastApprovedQuery},
2121
LastApproved, LastApprovedResponse, SpenderResponse, SuccessResponse,
@@ -225,7 +225,7 @@ pub async fn create_validator_messages<A: Adapter + 'static>(
225225
}
226226
}
227227

228-
async fn create_spendable_document(
228+
async fn create_or_update_spendable_document(
229229
adapter: &impl Adapter,
230230
token_info: &TokenInfo,
231231
pool: DbPool,
@@ -300,7 +300,7 @@ pub async fn get_spender_limits<A: Adapter + 'static>(
300300
let latest_spendable = match latest_spendable {
301301
Some(spendable) => spendable,
302302
None => {
303-
create_spendable_document(
303+
create_or_update_spendable_document(
304304
&app.adapter,
305305
token_info,
306306
app.pool.clone(),
@@ -345,54 +345,42 @@ pub async fn get_spender_limits<A: Adapter + 'static>(
345345
#[cfg(test)]
346346
mod test {
347347
use super::*;
348-
use crate::db::tests_postgres::{setup_test_migrations, DATABASE_POOL};
349-
use adapter::DummyAdapter;
348+
use crate::test_util::setup_dummy_app;
350349
use primitives::{
351-
adapter::{Deposit, DummyAdapterOptions},
352-
config::configuration,
353-
util::tests::prep_db::{ADDRESSES, DUMMY_CAMPAIGN, IDS},
350+
adapter::Deposit,
351+
util::tests::prep_db::{ADDRESSES, DUMMY_CAMPAIGN},
354352
BigNum,
355353
};
356354

357355
#[tokio::test]
358356
async fn create_and_fetch_spendable() {
359-
let config = configuration("development", None).expect("Should get Config");
360-
let adapter = DummyAdapter::init(
361-
DummyAdapterOptions {
362-
dummy_identity: IDS["leader"],
363-
dummy_auth: Default::default(),
364-
dummy_auth_tokens: Default::default(),
365-
},
366-
&config,
367-
);
368-
let database = DATABASE_POOL.get().await.expect("Should get a DB pool");
369-
setup_test_migrations(database.pool.clone())
370-
.await
371-
.expect("Migrations should succeed");
357+
let app = setup_dummy_app().await;
372358

373359
let channel = DUMMY_CAMPAIGN.channel.clone();
374360

375-
let token_info = config
361+
let token_info = app
362+
.config
376363
.token_address_whitelist
377364
.get(&channel.token)
378365
.expect("should retrieve address");
379366
let precision: u8 = token_info.precision.into();
380367
let deposit = Deposit {
381-
total: BigNum::from(1000000000), // 100 USDT
382-
still_on_create2: BigNum::from(1000000), // 1 USDT
368+
total: BigNum::from_str("100000000000000000000").expect("should convert"), // 100 DAI
369+
still_on_create2: BigNum::from_str("1000000000000000000").expect("should convert"), // 1 DAI
383370
};
384-
adapter.add_deposit_call(channel.id(), ADDRESSES["creator"], deposit.clone());
371+
app.adapter
372+
.add_deposit_call(channel.id(), ADDRESSES["creator"], deposit.clone());
385373
// Making sure spendable does not yet exist
386-
let spendable = fetch_spendable(database.clone(), &ADDRESSES["creator"], &channel.id())
374+
let spendable = fetch_spendable(app.pool.clone(), &ADDRESSES["creator"], &channel.id())
387375
.await
388376
.expect("should return None");
389377
assert!(spendable.is_none());
390378

391-
// Call create_spendable
392-
let new_spendable = create_spendable_document(
393-
&adapter,
394-
&token_info,
395-
database.clone(),
379+
// Call create_or_update_spendable
380+
let new_spendable = create_or_update_spendable_document(
381+
&app.adapter,
382+
token_info,
383+
app.pool.clone(),
396384
&channel,
397385
ADDRESSES["creator"],
398386
)
@@ -413,23 +401,23 @@ mod test {
413401
assert_eq!(new_spendable.spender, ADDRESSES["creator"]);
414402

415403
// Make sure spendable NOW exists
416-
let spendable = fetch_spendable(database.clone(), &ADDRESSES["creator"], &channel.id())
404+
let spendable = fetch_spendable(app.pool.clone(), &ADDRESSES["creator"], &channel.id())
417405
.await
418406
.expect("should return a spendable");
419407
assert!(spendable.is_some());
420408

421-
// Updating our deposit by doubling it
422409
let updated_deposit = Deposit {
423-
total: BigNum::from(110000000), // 101 USDT
424-
still_on_create2: BigNum::from(1100000), // 1.1 USDT
410+
total: BigNum::from_str("110000000000000000000").expect("should convert"), // 110 DAI
411+
still_on_create2: BigNum::from_str("1100000000000000000").expect("should convert"), // 1.1 DAI
425412
};
426413

427-
adapter.add_deposit_call(channel.id(), ADDRESSES["creator"], updated_deposit.clone());
414+
app.adapter
415+
.add_deposit_call(channel.id(), ADDRESSES["creator"], updated_deposit.clone());
428416

429-
let updated_spendable = create_spendable_document(
430-
&adapter,
431-
&token_info,
432-
database.clone(),
417+
let updated_spendable = create_or_update_spendable_document(
418+
&app.adapter,
419+
token_info,
420+
app.pool.clone(),
433421
&channel,
434422
ADDRESSES["creator"],
435423
)

0 commit comments

Comments
 (0)