@@ -9,7 +9,7 @@ use axum::{
9
9
http:: { Method , StatusCode } ,
10
10
middleware,
11
11
routing:: get,
12
- Extension , Router ,
12
+ Extension , Json , Router ,
13
13
} ;
14
14
use axum_server:: { tls_rustls:: RustlsConfig , Handle } ;
15
15
use once_cell:: sync:: Lazy ;
@@ -19,14 +19,19 @@ use slog::{error, info, Logger};
19
19
use tower:: ServiceBuilder ;
20
20
use tower_http:: cors:: CorsLayer ;
21
21
22
- use adapter:: { client:: Locked , Adapter } ;
23
- use primitives:: { config:: Environment , ValidatorId } ;
22
+ use adapter:: { client:: Locked , Adapter , Dummy , Ethereum } ;
23
+ use primitives:: {
24
+ config:: Environment , sentry:: campaign_create:: CreateCampaign , test_util:: CAMPAIGNS ,
25
+ unified_num:: FromWhole , Campaign , ChainOf , Deposit , UnifiedNum , ValidatorId ,
26
+ } ;
24
27
25
28
use crate :: {
26
29
db:: { CampaignRemaining , DbPool } ,
27
30
middleware:: auth:: authenticate,
28
31
platform:: PlatformApi ,
29
32
routes:: {
33
+ campaign:: create_campaign,
34
+ channel:: { channel_dummy_deposit, ChannelDummyDeposit } ,
30
35
get_cfg,
31
36
routers:: { analytics_router, campaigns_router, channels_router, units_for_slot_router} ,
32
37
} ,
@@ -307,6 +312,136 @@ async fn shutdown_signal(logger: Logger, handle: Handle) {
307
312
info ! ( & logger, "Received Ctrl+C signal. Shutting down.." )
308
313
}
309
314
315
+ pub async fn seed_dummy ( app : Application < Dummy > ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
316
+ // create campaign
317
+ // Chain 1337
318
+ let campaign_1 = CAMPAIGNS [ 0 ] . clone ( ) ;
319
+ // Chain 1337
320
+ let campaign_2 = CAMPAIGNS [ 1 ] . clone ( ) ;
321
+ // Chain 1
322
+ let campaign_3 = CAMPAIGNS [ 2 ] . clone ( ) ;
323
+
324
+ async fn create_seed_campaign (
325
+ app : Application < Dummy > ,
326
+ campaign : & ChainOf < Campaign > ,
327
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
328
+ let campaign_to_create = CreateCampaign :: from_campaign ( campaign. context . clone ( ) ) ;
329
+ let auth = Auth {
330
+ era : 0 ,
331
+ uid : ValidatorId :: from ( campaign_to_create. creator ) ,
332
+ chain : campaign. chain . clone ( ) ,
333
+ } ;
334
+ let _result = create_campaign (
335
+ Json ( campaign_to_create) ,
336
+ Extension ( auth) ,
337
+ Extension ( Arc :: new ( app) ) ,
338
+ )
339
+ . await
340
+ . expect ( "Should create seed campaigns" ) ;
341
+
342
+ Ok ( ( ) )
343
+ }
344
+
345
+ async fn dummy_deposit (
346
+ app : Application < Dummy > ,
347
+ campaign : & ChainOf < Campaign > ,
348
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
349
+ let channel = campaign. context . channel ;
350
+ let auth = Auth {
351
+ era : 0 ,
352
+ uid : ValidatorId :: from ( campaign. context . creator ) ,
353
+ chain : campaign. chain . clone ( ) ,
354
+ } ;
355
+
356
+ let request = ChannelDummyDeposit {
357
+ channel,
358
+ deposit : Deposit {
359
+ total : UnifiedNum :: from_whole ( 1_000_000 ) ,
360
+ } ,
361
+ } ;
362
+
363
+ let result =
364
+ channel_dummy_deposit ( Extension ( Arc :: new ( app) ) , Extension ( auth) , Json ( request) ) . await ;
365
+
366
+ assert ! ( result. is_ok( ) ) ;
367
+
368
+ Ok ( ( ) )
369
+ }
370
+ // chain 1337
371
+ dummy_deposit ( app. clone ( ) , & campaign_1) . await ?;
372
+ // chain 1337
373
+ dummy_deposit ( app. clone ( ) , & campaign_2) . await ?;
374
+ // chain 1
375
+ dummy_deposit ( app. clone ( ) , & campaign_3) . await ?;
376
+
377
+ create_seed_campaign ( app. clone ( ) , & campaign_1) . await ?;
378
+ create_seed_campaign ( app. clone ( ) , & campaign_2) . await ?;
379
+ create_seed_campaign ( app. clone ( ) , & campaign_3) . await ?;
380
+ Ok ( ( ) )
381
+ }
382
+
383
+ pub async fn seed_ethereum ( app : Application < Ethereum > ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
384
+ // create campaign
385
+ // Chain 1337
386
+ let campaign_1 = CAMPAIGNS [ 0 ] . clone ( ) ;
387
+ // Chain 1337
388
+ let campaign_2 = CAMPAIGNS [ 1 ] . clone ( ) ;
389
+ // Chain 1
390
+ let campaign_3 = CAMPAIGNS [ 2 ] . clone ( ) ;
391
+
392
+ async fn create_seed_campaign (
393
+ app : Application < Ethereum > ,
394
+ campaign : & ChainOf < Campaign > ,
395
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
396
+ let campaign_to_create = CreateCampaign :: from_campaign ( campaign. context . clone ( ) ) ;
397
+ let auth = Auth {
398
+ era : 0 ,
399
+ uid : ValidatorId :: from ( campaign_to_create. creator ) ,
400
+ chain : campaign. chain . clone ( ) ,
401
+ } ;
402
+ let _result = create_campaign (
403
+ Json ( campaign_to_create) ,
404
+ Extension ( auth) ,
405
+ Extension ( Arc :: new ( app) ) ,
406
+ )
407
+ . await
408
+ . expect ( "Should create seed campaigns" ) ;
409
+ Ok ( ( ) )
410
+ }
411
+ async fn deposit (
412
+ app : Application < Ethereum > ,
413
+ campaign : & ChainOf < Campaign > ,
414
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
415
+ let channel = campaign. context . channel ;
416
+ let auth = Auth {
417
+ era : 0 ,
418
+ uid : ValidatorId :: from ( campaign. context . creator ) ,
419
+ chain : campaign. chain . clone ( ) ,
420
+ } ;
421
+ let request = ChannelDummyDeposit {
422
+ channel,
423
+ deposit : Deposit {
424
+ total : UnifiedNum :: from_whole ( 1_000_000 ) ,
425
+ } ,
426
+ } ;
427
+ let result =
428
+ channel_dummy_deposit ( Extension ( Arc :: new ( app) ) , Extension ( auth) , Json ( request) ) . await ;
429
+ assert ! ( result. is_ok( ) ) ;
430
+ Ok ( ( ) )
431
+ }
432
+ // chain 1337
433
+ deposit ( app. clone ( ) , & campaign_1) . await ?;
434
+ // chain 1337
435
+ deposit ( app. clone ( ) , & campaign_2) . await ?;
436
+ // chain 1
437
+ deposit ( app. clone ( ) , & campaign_3) . await ?;
438
+
439
+ create_seed_campaign ( app. clone ( ) , & campaign_1) . await ?;
440
+ create_seed_campaign ( app. clone ( ) , & campaign_2) . await ?;
441
+ create_seed_campaign ( app. clone ( ) , & campaign_3) . await ?;
442
+ Ok ( ( ) )
443
+ }
444
+
310
445
#[ cfg( test) ]
311
446
mod test {
312
447
use serde_json:: json;
0 commit comments