@@ -1255,7 +1255,6 @@ mod test {
1255
1255
} ;
1256
1256
use adapter:: primitives:: Deposit ;
1257
1257
use chrono:: { TimeZone , Utc } ;
1258
- use hyper:: StatusCode ;
1259
1258
use primitives:: {
1260
1259
campaign:: validators:: Validators ,
1261
1260
config:: GANACHE_CONFIG ,
@@ -1268,12 +1267,13 @@ mod test {
1268
1267
ValidatorDesc , ValidatorId ,
1269
1268
} ;
1270
1269
1271
- #[ tokio:: test]
1272
1270
/// Test single campaign creation and modification
1273
1271
// &
1274
1272
/// Test with multiple campaigns (because of Budget) and modifications
1273
+ #[ tokio:: test]
1275
1274
async fn create_and_modify_with_multiple_campaigns ( ) {
1276
- let app = setup_dummy_app ( ) . await ;
1275
+ let app_guard = setup_dummy_app ( ) . await ;
1276
+ let app = Extension ( Arc :: new ( app_guard. app . clone ( ) ) ) ;
1277
1277
1278
1278
// Create a new Campaign with different CampaignId
1279
1279
let dummy_channel = DUMMY_CAMPAIGN . channel ;
@@ -1296,45 +1296,29 @@ mod test {
1296
1296
} ,
1297
1297
) ;
1298
1298
1299
- let build_request = |create_campaign : CreateCampaign | -> Request < Body > {
1300
- let auth = Auth {
1301
- era : 0 ,
1302
- uid : ValidatorId :: from ( create_campaign. creator ) ,
1303
- chain : channel_context. chain . clone ( ) ,
1304
- } ;
1305
-
1306
- let body =
1307
- Body :: from ( serde_json:: to_string ( & create_campaign) . expect ( "Should serialize" ) ) ;
1308
-
1309
- Request :: builder ( )
1310
- . extension ( auth)
1311
- . body ( body)
1312
- . expect ( "Should build Request" )
1313
- } ;
1299
+ let auth = Extension ( Auth {
1300
+ era : 0 ,
1301
+ uid : IDS [ & CREATOR ] ,
1302
+ chain : channel_context. chain . clone ( ) ,
1303
+ } ) ;
1314
1304
1315
1305
let campaign_context: ChainOf < Campaign > = {
1316
1306
// erases the CampaignId for the CreateCampaign request
1317
1307
let mut create = CreateCampaign :: from_campaign_erased ( DUMMY_CAMPAIGN . clone ( ) , None ) ;
1318
1308
create. budget = UnifiedNum :: from_whole ( 500 ) ;
1319
1309
1320
- let create_response = create_campaign ( build_request ( create) , & app)
1321
- . await
1322
- . expect ( "Should create campaign" ) ;
1323
-
1324
- assert_eq ! ( StatusCode :: OK , create_response. status( ) ) ;
1325
- let json = hyper:: body:: to_bytes ( create_response. into_body ( ) )
1310
+ let create_response = create_campaign_axum ( Json ( create) , auth. clone ( ) , app. clone ( ) )
1326
1311
. await
1327
- . expect ( "Should get json" ) ;
1312
+ . expect ( "Should create campaign" )
1313
+ . 0 ;
1328
1314
1329
- let campaign: Campaign =
1330
- serde_json:: from_slice ( & json) . expect ( "Should get new Campaign" ) ;
1331
1315
1332
- assert_ne ! ( DUMMY_CAMPAIGN . id, campaign . id) ;
1316
+ assert_ne ! ( DUMMY_CAMPAIGN . id, create_response . id) ;
1333
1317
1334
1318
let campaign_remaining = CampaignRemaining :: new ( app. redis . clone ( ) ) ;
1335
1319
1336
1320
let remaining = campaign_remaining
1337
- . get_remaining_opt ( campaign . id )
1321
+ . get_remaining_opt ( create_response . id )
1338
1322
. await
1339
1323
. expect ( "Should get remaining from redis" )
1340
1324
. expect ( "There should be value for the Campaign" ) ;
@@ -1344,7 +1328,7 @@ mod test {
1344
1328
UnifiedNum :: from( remaining. unsigned_abs( ) )
1345
1329
) ;
1346
1330
1347
- channel_context. clone ( ) . with ( campaign )
1331
+ channel_context. clone ( ) . with ( create_response )
1348
1332
} ;
1349
1333
1350
1334
// modify campaign
@@ -1391,19 +1375,9 @@ mod test {
1391
1375
CreateCampaign :: from_campaign_erased ( DUMMY_CAMPAIGN . clone ( ) , None ) ;
1392
1376
create_second. budget = UnifiedNum :: from_whole ( 500 ) ;
1393
1377
1394
- let create_response = create_campaign ( build_request ( create_second) , & app)
1395
- . await
1396
- . expect ( "Should create campaign" ) ;
1397
-
1398
- assert_eq ! ( StatusCode :: OK , create_response. status( ) ) ;
1399
- let json = hyper:: body:: to_bytes ( create_response. into_body ( ) )
1378
+ create_campaign_axum ( Json ( create_second) , auth. clone ( ) , app. clone ( ) )
1400
1379
. await
1401
- . expect ( "Should get json" ) ;
1402
-
1403
- let second_campaign: Campaign =
1404
- serde_json:: from_slice ( & json) . expect ( "Should get new Campaign" ) ;
1405
-
1406
- second_campaign
1380
+ . expect ( "Should create campaign" ) . 0
1407
1381
} ;
1408
1382
1409
1383
// No budget left for new campaigns
@@ -1414,7 +1388,7 @@ mod test {
1414
1388
let mut create = CreateCampaign :: from_campaign_erased ( DUMMY_CAMPAIGN . clone ( ) , None ) ;
1415
1389
create. budget = UnifiedNum :: from_whole ( 600 ) ;
1416
1390
1417
- let create_err = create_campaign ( build_request ( create) , & app)
1391
+ let create_err = create_campaign_axum ( Json ( create) , auth . clone ( ) , app. clone ( ) )
1418
1392
. await
1419
1393
. expect_err ( "Should return Error response" ) ;
1420
1394
@@ -1463,16 +1437,9 @@ mod test {
1463
1437
let mut create = CreateCampaign :: from_campaign_erased ( DUMMY_CAMPAIGN . clone ( ) , None ) ;
1464
1438
create. budget = UnifiedNum :: from_whole ( 600 ) ;
1465
1439
1466
- let create_response = create_campaign ( build_request ( create) , & app)
1440
+ let _create_response = create_campaign_axum ( Json ( create) , auth . clone ( ) , app. clone ( ) )
1467
1441
. await
1468
1442
. expect ( "Should return create campaign" ) ;
1469
-
1470
- let json = hyper:: body:: to_bytes ( create_response. into_body ( ) )
1471
- . await
1472
- . expect ( "Should get json" ) ;
1473
-
1474
- let _campaign: Campaign =
1475
- serde_json:: from_slice ( & json) . expect ( "Should get new Campaign" ) ;
1476
1443
}
1477
1444
1478
1445
// Modify a campaign without enough budget
0 commit comments