@@ -9,7 +9,7 @@ use aiken/transaction.{
9
9
ScriptContext , Spend , Transaction , TransactionId ,
10
10
}
11
11
use aiken/ transaction/ credential.{
12
- Address , VerificationKeyCredential ,
12
+ Address , VerificationKeyCredential , from_verification_key, from_script, with_delegation_key
13
13
}
14
14
use aiken/ transaction/ value.{Value }
15
15
use shared.{
@@ -35,6 +35,8 @@ type ScoopTestOptions {
35
35
edit_escrow_destination: Option < Address > ,
36
36
edit_fee: Option < Value > ,
37
37
edit_swap_fees: Option < (Int ,Int )> ,
38
+ edit_pool_input_address: Option < Address > ,
39
+ edit_pool_output_address: Option < Address > ,
38
40
edit_pool_output_value: Option < Value > ,
39
41
edit_settings_datum: Option < Datum > ,
40
42
}
@@ -46,6 +48,8 @@ fn default_scoop_test_options() -> ScoopTestOptions {
46
48
edit_escrow_destination: None ,
47
49
edit_fee: None ,
48
50
edit_swap_fees: None ,
51
+ edit_pool_input_address: None ,
52
+ edit_pool_output_address: None ,
49
53
edit_pool_output_value: None ,
50
54
edit_settings_datum: None ,
51
55
}
@@ -101,8 +105,6 @@ test pool_validator_ignores_fee() {
101
105
}
102
106
103
107
test scoop_high_swap_fees () {
104
- let hash_of_pool_script =
105
- #"00000000000000000000000000000000000000000000000000000000"
106
108
let pool_id = #"00000000000000000000000000000000000000000000000000000000"
107
109
let pool_nft_name = shared.pool_nft_name (pool_id)
108
110
let dummy_policy_id =
@@ -128,7 +130,7 @@ test scoop_high_swap_fees() {
128
130
dummy_asset_name,
129
131
1_000_000_000 - ( 9_802_950 + 9_611_678 ),
130
132
)
131
- |> value.add (hash_of_pool_script , pool_nft_name, 1 ),
133
+ |> value.add (pool_script_hash , pool_nft_name, 1 ),
132
134
),
133
135
}
134
136
scoop (options)
@@ -153,6 +155,35 @@ test output_missing_nft() fail {
153
155
scoop (options)
154
156
}
155
157
158
+ const pool_script_hash = #"00000000000000000000000000000000000000000000000000000000"
159
+ const random_hash = #"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513"
160
+ const other_hash = #"01010101010101010101010101010101010101010101010101010101"
161
+ test scoop_pool_output_wallet_address () fail {
162
+ let options =
163
+ ScoopTestOptions {
164
+ .. default_scoop_test_options (),
165
+ edit_pool_output_address: Some (from_verification_key (random_hash)),
166
+ }
167
+ scoop (options)
168
+ }
169
+ test scoop_pool_output_wrong_script () fail {
170
+ let options =
171
+ ScoopTestOptions {
172
+ .. default_scoop_test_options (),
173
+ edit_pool_output_address: Some (from_script (random_hash)),
174
+ }
175
+ scoop (options)
176
+ }
177
+ test scoop_pool_output_change_staking_credential () fail {
178
+ let options =
179
+ ScoopTestOptions {
180
+ .. default_scoop_test_options (),
181
+ edit_pool_input_address: Some (from_script (pool_script_hash) |> with_delegation_key (random_hash)),
182
+ edit_pool_output_address: Some (from_script (pool_script_hash) |> with_delegation_key (other_hash)),
183
+ }
184
+ scoop (options)
185
+ }
186
+
156
187
test scooper_not_in_settings () fail {
157
188
let somebody = #"11111111111111111111111111111111111111111111111111111111"
158
189
let options =
@@ -197,8 +228,6 @@ fn scoop(options: ScoopTestOptions) {
197
228
#"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77"
198
229
let dummy_asset_name = #"53554e444145"
199
230
let scooper = #"00000000000000000000000000000000000000000000000000000000"
200
- let hash_of_pool_script =
201
- #"00000000000000000000000000000000000000000000000000000000"
202
231
let hash_of_escrow_script =
203
232
#"00000000000000000000000000000000000000000000000000000000"
204
233
let user_addr =
@@ -229,15 +258,15 @@ fn scoop(options: ScoopTestOptions) {
229
258
protocol_fees: 7_000_000 ,
230
259
}
231
260
let pool_nft_name = shared.pool_nft_name (pool_id)
232
- let pool_address = script_address (hash_of_pool_script )
261
+ let pool_address = script_address (pool_script_hash )
233
262
let pool_input =
234
263
Input {
235
264
output_reference: mk_output_reference (0 ),
236
265
output: Output {
237
- address: pool_address,
266
+ address: option. or_else (options.edit_pool_input_address, pool_address) ,
238
267
value: value.from_lovelace (1_000_000_000 + 2_000_000 )
239
268
|> value.add (dummy_policy_id, dummy_asset_name, 1_000_000_000 )
240
- |> value.add (hash_of_pool_script , pool_nft_name, 1 ),
269
+ |> value.add (pool_script_hash , pool_nft_name, 1 ),
241
270
datum: InlineDatum (pool_datum),
242
271
reference_script: None ,
243
272
},
@@ -309,7 +338,7 @@ fn scoop(options: ScoopTestOptions) {
309
338
}
310
339
let pool_output =
311
340
Output {
312
- address: pool_address,
341
+ address: option. or_else (options.edit_pool_output_address, pool_address) ,
313
342
value: option.or_else (
314
343
options.edit_pool_output_value,
315
344
value.from_lovelace (1_000_000_000 + 20_000_000 + 5_000_000 + 2_000_000 )
@@ -318,7 +347,7 @@ fn scoop(options: ScoopTestOptions) {
318
347
dummy_asset_name,
319
348
1_000_000_000 - ( 9_896_088 + 9_702_095 ),
320
349
)
321
- |> value.add (hash_of_pool_script , pool_nft_name, 1 ),
350
+ |> value.add (pool_script_hash , pool_nft_name, 1 ),
322
351
),
323
352
datum: InlineDatum (pool_out_datum),
324
353
reference_script: None ,
@@ -358,7 +387,6 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
358
387
let dummy_policy_id = #"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77"
359
388
let dummy_asset_name = #"53554e444145"
360
389
let scooper = #"00000000000000000000000000000000000000000000000000000000"
361
- let hash_of_pool_script = #"00000000000000000000000000000000000000000000000000000000"
362
390
let hash_of_escrow_script = #"00000000000000000000000000000000000000000000000000000000"
363
391
let user_addr = wallet_address (
364
392
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513"
@@ -392,14 +420,14 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
392
420
protocol_fees: 7_000_000 ,
393
421
}
394
422
let pool_nft_name = shared.pool_nft_name (pool_id)
395
- let pool_address = script_address (hash_of_pool_script )
423
+ let pool_address = script_address (pool_script_hash )
396
424
let pool_input = Input {
397
425
output_reference: mk_output_reference (0 ),
398
426
output: Output {
399
427
address: pool_address,
400
428
value: value.from_lovelace (1_000_000_000 + 2_000_000 )
401
429
|> value.add (dummy_policy_id, dummy_asset_name, 1_000_000_000 )
402
- |> value.add (hash_of_pool_script , pool_nft_name, 1 ),
430
+ |> value.add (pool_script_hash , pool_nft_name, 1 ),
403
431
datum: InlineDatum (pool_datum),
404
432
reference_script: None ,
405
433
},
@@ -473,7 +501,7 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
473
501
let escrow2_out = Output {
474
502
address: option.or_else (options.edit_escrow_destination, user_addr),
475
503
value: value.from_lovelace (2_000_000 )
476
- |> value.add (hash_of_pool_script , pool_lp_name (pool_id), 9_900_990 )
504
+ |> value.add (pool_script_hash , pool_lp_name (pool_id), 9_900_990 )
477
505
|> value.add (dummy_policy_id, dummy_asset_name, 196_990 ),
478
506
datum: NoDatum ,
479
507
reference_script: None ,
@@ -483,7 +511,7 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
483
511
value: option.or_else (options.edit_pool_output_value,
484
512
value.from_lovelace (1_000_000_000 + 20_000_000 + 5_000_000 + 2_000_000 )
485
513
|> value.add (dummy_policy_id, dummy_asset_name, 1_000_000_000 - 9_896_088 + 10_000_000 - 196_990 )
486
- |> value.add (hash_of_pool_script , pool_nft_name, 1 )),
514
+ |> value.add (pool_script_hash , pool_nft_name, 1 )),
487
515
datum: InlineDatum (pool_out_datum),
488
516
reference_script: None ,
489
517
}
@@ -496,7 +524,7 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
496
524
fee: option.or_else (options.edit_fee, value.from_lovelace (1_000_000 )),
497
525
mint: value.to_minted_value (
498
526
value.from_lovelace (0 )
499
- |> value.add (hash_of_pool_script , pool_lp_name (pool_id), 9_900_990 )
527
+ |> value.add (pool_script_hash , pool_lp_name (pool_id), 9_900_990 )
500
528
),
501
529
certificates: [],
502
530
withdrawals: dict.new (),
@@ -520,7 +548,6 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
520
548
result
521
549
}
522
550
523
- const hash_of_pool_script = #"00000000000000000000000000000000000000000000000000000000"
524
551
fn pool_test_tx_input () -> Input {
525
552
let funds_input =
526
553
new_tx_input (
@@ -532,12 +559,12 @@ fn pool_test_tx_input() -> Input {
532
559
funds_input
533
560
}
534
561
535
- test mint_test_two_nfts () {
562
+ test mint_test_two_nfts () fail {
536
563
let pool_id = pool_ident_from_input (pool_test_tx_input ())
537
564
let (_, new_pool_nft_token, _) = shared.pool_token_names (pool_id)
538
565
// if we add on another pool NFT token to the pool output, it should fail
539
- ! mint_test_modify (
540
- fn (output) { Output { .. output, value: value.add (output.value, hash_of_pool_script , new_pool_nft_token, 1 ) } },
566
+ mint_test_modify (
567
+ fn (output) { Output { .. output, value: value.add (output.value, pool_script_hash , new_pool_nft_token, 1 ) } },
541
568
identity,
542
569
identity,
543
570
identity
@@ -559,8 +586,7 @@ fn mint_test_modify(
559
586
modify_ref_output: fn (Output ) -> Output ,
560
587
modify_datum: fn (Datum ) -> Datum ) -> Bool {
561
588
let settings_policy_id = #"00000000000000000000000000000000000000000000000000000000"
562
- let hash_of_pool_script = #"00000000000000000000000000000000000000000000000000000000"
563
- let pool_address = script_address (hash_of_pool_script)
589
+ let pool_address = script_address (pool_script_hash) |> with_delegation_key (#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad" )
564
590
let rberry_policy_id = #"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77"
565
591
let rberry_token_name = #"524245525259"
566
592
let user_address =
@@ -583,41 +609,41 @@ fn mint_test_modify(
583
609
))
584
610
let pool_output_val =
585
611
value.from_asset (rberry_policy_id, rberry_token_name, 1_000_000_000 )
586
- |> value.add (hash_of_pool_script , new_pool_nft_token, 1 )
612
+ |> value.add (pool_script_hash , new_pool_nft_token, 1 )
587
613
|> value.merge (value.from_lovelace (1_002_000_000 ))
588
614
let pool_output = new_tx_output (pool_address, 0 , inline_pool_datum) // 1_002_000_000 = 1_000_000_000 ADA for pool + 2_000_000 ADA for protocol_fees
589
615
|> add_asset_to_tx_output (pool_output_val)
590
616
|> modify_pool_output
591
617
592
618
let lp_output_val =
593
- value.from_asset (hash_of_pool_script , pool_lp_name (pool_id), 1_000_000_000 )
619
+ value.from_asset (pool_script_hash , pool_lp_name (pool_id), 1_000_000_000 )
594
620
|> value.merge (value.from_lovelace (2_000_000 ))
595
621
let lp_output =
596
622
new_tx_output (user_address, 0 , NoDatum ) // we can probably get rid of the rider, it gets auto added
597
623
|> add_asset_to_tx_output (lp_output_val)
598
624
|> modify_lp_output
599
625
600
626
let ref_output_val =
601
- value.from_asset (hash_of_pool_script , new_pool_ref_token, 1 )
627
+ value.from_asset (pool_script_hash , new_pool_ref_token, 1 )
602
628
|> value.merge (value.from_lovelace (2_000_000 ))
603
629
let ref_output =
604
630
new_tx_output (user_address, 0 , NoDatum ) // we can probably get rid of the rider, it gets auto added
605
631
|> add_asset_to_tx_output (ref_output_val)
606
632
|> modify_ref_output
607
633
608
- let pool MintRedeemer = CreatePool {
634
+ let pool_mint_redeemer = CreatePool {
609
635
assets: ((#"" , #"" ), (rberry_policy_id, rberry_token_name)),
610
636
pool_output: 0 ,
611
637
metadata_output: 2 ,
612
638
}
613
639
614
640
let ctx = interval.between (1 ,2 )
615
641
|> build_txn_context ()
616
- |> mint_assets (hash_of_pool_script , value.to_minted_value (
642
+ |> mint_assets (pool_script_hash , value.to_minted_value (
617
643
value.from_lovelace (0 )
618
- |> value.add (hash_of_pool_script , new_pool_lp_token, 1_000_000_000 )
619
- |> value.add (hash_of_pool_script , new_pool_nft_token, 1 )
620
- |> value.add (hash_of_pool_script , new_pool_ref_token, 1 )
644
+ |> value.add (pool_script_hash , new_pool_lp_token, 1_000_000_000 )
645
+ |> value.add (pool_script_hash , new_pool_nft_token, 1 )
646
+ |> value.add (pool_script_hash , new_pool_ref_token, 1 )
621
647
))
622
648
|> add_tx_input (funds_input)
623
649
|> add_tx_ref_input (settings_input)
@@ -627,11 +653,28 @@ fn mint_test_modify(
627
653
|> add_tx_output (lp_output)
628
654
|> add_tx_output (pool_output)
629
655
630
- let result = pool_validator.mint (settings_policy_id, pool MintRedeemer , ctx)
656
+ let result = pool_validator.mint (settings_policy_id, pool_mint_redeemer , ctx)
631
657
result
632
658
}
633
659
634
660
test mint_test () {
635
661
mint_test_modify (identity, identity, identity, identity)
636
662
}
637
663
664
+ // make sure pool_output.address is checked to be the pool address
665
+ test mint_test_wrong_address () fail {
666
+ let minted = mint_test_modify (
667
+ // change pool nft output address to destination that shouldn't be possible
668
+ fn (output) {
669
+ Output {
670
+ .. output,
671
+ // TODO: move some of this stuff to constants?
672
+ address: from_verification_key (random_hash) |> with_delegation_key (#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad" )
673
+ }
674
+ },
675
+ identity,
676
+ identity,
677
+ identity
678
+ )
679
+ minted
680
+ }
0 commit comments