@@ -17,9 +17,11 @@ use std::collections::BTreeMap;
17
17
18
18
use common:: {
19
19
chain:: {
20
- config:: create_unit_test_config, output_value:: OutputValue , tokens:: TokenId ,
21
- AccountCommand , AccountNonce , Destination , OrderData , OrderId , OutPointSourceId , TxInput ,
22
- TxOutput , UtxoOutPoint ,
20
+ config:: { create_unit_test_config, create_unit_test_config_builder} ,
21
+ output_value:: OutputValue ,
22
+ tokens:: TokenId ,
23
+ AccountCommand , AccountNonce , Destination , OrderAccountCommand , OrderData , OrderId ,
24
+ OrdersVersion , OutPointSourceId , TxInput , TxOutput , UtxoOutPoint ,
23
25
} ,
24
26
primitives:: { Amount , BlockHeight , CoinOrTokenId , Fee , Id , H256 } ,
25
27
} ;
@@ -252,11 +254,31 @@ fn create_order_constraints(#[case] seed: Seed) {
252
254
253
255
#[ rstest]
254
256
#[ trace]
255
- #[ case( Seed :: from_entropy( ) ) ]
256
- fn fill_order_constraints ( #[ case] seed : Seed ) {
257
+ #[ case( Seed :: from_entropy( ) , OrdersVersion :: V0 ) ]
258
+ #[ trace]
259
+ #[ case( Seed :: from_entropy( ) , OrdersVersion :: V1 ) ]
260
+ fn fill_order_constraints ( #[ case] seed : Seed , #[ case] version : OrdersVersion ) {
257
261
let mut rng = make_seedable_rng ( seed) ;
258
262
259
- let chain_config = create_unit_test_config ( ) ;
263
+ let chain_config = create_unit_test_config_builder ( )
264
+ . chainstate_upgrades (
265
+ common:: chain:: NetUpgrades :: initialize ( vec ! [ (
266
+ BlockHeight :: zero( ) ,
267
+ common:: chain:: ChainstateUpgrade :: new(
268
+ common:: chain:: TokenIssuanceVersion :: V1 ,
269
+ common:: chain:: RewardDistributionVersion :: V1 ,
270
+ common:: chain:: TokensFeeVersion :: V1 ,
271
+ common:: chain:: DataDepositFeeVersion :: V1 ,
272
+ common:: chain:: ChangeTokenMetadataUriActivated :: Yes ,
273
+ common:: chain:: FrozenTokensValidationVersion :: V1 ,
274
+ common:: chain:: HtlcActivated :: Yes ,
275
+ common:: chain:: OrdersActivated :: Yes ,
276
+ version,
277
+ ) ,
278
+ ) ] )
279
+ . expect ( "cannot fail" ) ,
280
+ )
281
+ . build ( ) ;
260
282
let block_height = BlockHeight :: one ( ) ;
261
283
262
284
let pos_store = InMemoryPoSAccounting :: new ( ) ;
@@ -284,19 +306,27 @@ fn fill_order_constraints(#[case] seed: Seed) {
284
306
285
307
// use in command more than provided in input
286
308
{
287
- let inputs = vec ! [
288
- TxInput :: Utxo ( UtxoOutPoint :: new(
289
- OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
290
- 0 ,
291
- ) ) ,
292
- TxInput :: AccountCommand (
309
+ let fill_command = match version {
310
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
293
311
AccountNonce :: new ( 0 ) ,
294
312
AccountCommand :: FillOrder (
295
313
order_id,
296
314
( ask_amount + Amount :: from_atoms ( 1 ) ) . unwrap ( ) ,
297
315
Destination :: AnyoneCanSpend ,
298
316
) ,
299
317
) ,
318
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
319
+ order_id,
320
+ ( ask_amount + Amount :: from_atoms ( 1 ) ) . unwrap ( ) ,
321
+ Destination :: AnyoneCanSpend ,
322
+ ) ) ,
323
+ } ;
324
+ let inputs = vec ! [
325
+ TxInput :: Utxo ( UtxoOutPoint :: new(
326
+ OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
327
+ 0 ,
328
+ ) ) ,
329
+ fill_command,
300
330
] ;
301
331
let input_utxos = vec ! [
302
332
Some ( TxOutput :: Transfer (
@@ -328,15 +358,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
328
358
329
359
// fill with coins instead of tokens
330
360
{
361
+ let fill_command = match version {
362
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
363
+ AccountNonce :: new ( 0 ) ,
364
+ AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
365
+ ) ,
366
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
367
+ order_id,
368
+ ask_amount,
369
+ Destination :: AnyoneCanSpend ,
370
+ ) ) ,
371
+ } ;
331
372
let inputs = vec ! [
332
373
TxInput :: Utxo ( UtxoOutPoint :: new(
333
374
OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
334
375
0 ,
335
376
) ) ,
336
- TxInput :: AccountCommand (
337
- AccountNonce :: new( 0 ) ,
338
- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
339
- ) ,
377
+ fill_command,
340
378
] ;
341
379
let input_utxos = vec ! [
342
380
Some ( TxOutput :: Transfer (
@@ -361,15 +399,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
361
399
362
400
// try to print coins in output
363
401
{
402
+ let fill_command = match version {
403
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
404
+ AccountNonce :: new ( 0 ) ,
405
+ AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
406
+ ) ,
407
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
408
+ order_id,
409
+ ask_amount,
410
+ Destination :: AnyoneCanSpend ,
411
+ ) ) ,
412
+ } ;
364
413
let inputs = vec ! [
365
414
TxInput :: Utxo ( UtxoOutPoint :: new(
366
415
OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
367
416
0 ,
368
417
) ) ,
369
- TxInput :: AccountCommand (
370
- AccountNonce :: new( 0 ) ,
371
- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
372
- ) ,
418
+ fill_command,
373
419
] ;
374
420
let input_utxos = vec ! [
375
421
Some ( TxOutput :: Transfer (
@@ -409,15 +455,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
409
455
410
456
// try to print tokens in output
411
457
{
458
+ let fill_command = match version {
459
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
460
+ AccountNonce :: new ( 0 ) ,
461
+ AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
462
+ ) ,
463
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
464
+ order_id,
465
+ ask_amount,
466
+ Destination :: AnyoneCanSpend ,
467
+ ) ) ,
468
+ } ;
412
469
let inputs = vec ! [
413
470
TxInput :: Utxo ( UtxoOutPoint :: new(
414
471
OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
415
472
0 ,
416
473
) ) ,
417
- TxInput :: AccountCommand (
418
- AccountNonce :: new( 0 ) ,
419
- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
420
- ) ,
474
+ fill_command,
421
475
] ;
422
476
let input_utxos = vec ! [
423
477
Some ( TxOutput :: Transfer (
@@ -462,15 +516,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
462
516
463
517
{
464
518
// partially use input in command
519
+ let fill_command = match version {
520
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
521
+ AccountNonce :: new ( 0 ) ,
522
+ AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
523
+ ) ,
524
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
525
+ order_id,
526
+ ask_amount,
527
+ Destination :: AnyoneCanSpend ,
528
+ ) ) ,
529
+ } ;
465
530
let inputs = vec ! [
466
531
TxInput :: Utxo ( UtxoOutPoint :: new(
467
532
OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
468
533
0 ,
469
534
) ) ,
470
- TxInput :: AccountCommand (
471
- AccountNonce :: new( 0 ) ,
472
- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
473
- ) ,
535
+ fill_command,
474
536
] ;
475
537
let input_utxos = vec ! [
476
538
Some ( TxOutput :: Transfer (
@@ -513,15 +575,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
513
575
}
514
576
515
577
// valid case
578
+ let fill_command = match version {
579
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
580
+ AccountNonce :: new ( 0 ) ,
581
+ AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
582
+ ) ,
583
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
584
+ order_id,
585
+ ask_amount,
586
+ Destination :: AnyoneCanSpend ,
587
+ ) ) ,
588
+ } ;
516
589
let inputs = vec ! [
517
590
TxInput :: Utxo ( UtxoOutPoint :: new(
518
591
OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
519
592
0 ,
520
593
) ) ,
521
- TxInput :: AccountCommand (
522
- AccountNonce :: new( 0 ) ,
523
- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
524
- ) ,
594
+ fill_command,
525
595
] ;
526
596
let input_utxos = vec ! [
527
597
Some ( TxOutput :: Transfer (
@@ -559,11 +629,31 @@ fn fill_order_constraints(#[case] seed: Seed) {
559
629
560
630
#[ rstest]
561
631
#[ trace]
562
- #[ case( Seed :: from_entropy( ) ) ]
563
- fn conclude_order_constraints ( #[ case] seed : Seed ) {
632
+ #[ case( Seed :: from_entropy( ) , OrdersVersion :: V0 ) ]
633
+ #[ trace]
634
+ #[ case( Seed :: from_entropy( ) , OrdersVersion :: V1 ) ]
635
+ fn conclude_order_constraints ( #[ case] seed : Seed , #[ case] version : OrdersVersion ) {
564
636
let mut rng = make_seedable_rng ( seed) ;
565
637
566
- let chain_config = create_unit_test_config ( ) ;
638
+ let chain_config = create_unit_test_config_builder ( )
639
+ . chainstate_upgrades (
640
+ common:: chain:: NetUpgrades :: initialize ( vec ! [ (
641
+ BlockHeight :: zero( ) ,
642
+ common:: chain:: ChainstateUpgrade :: new(
643
+ common:: chain:: TokenIssuanceVersion :: V1 ,
644
+ common:: chain:: RewardDistributionVersion :: V1 ,
645
+ common:: chain:: TokensFeeVersion :: V1 ,
646
+ common:: chain:: DataDepositFeeVersion :: V1 ,
647
+ common:: chain:: ChangeTokenMetadataUriActivated :: Yes ,
648
+ common:: chain:: FrozenTokensValidationVersion :: V1 ,
649
+ common:: chain:: HtlcActivated :: Yes ,
650
+ common:: chain:: OrdersActivated :: Yes ,
651
+ version,
652
+ ) ,
653
+ ) ] )
654
+ . expect ( "cannot fail" ) ,
655
+ )
656
+ . build ( ) ;
567
657
let block_height = BlockHeight :: one ( ) ;
568
658
569
659
let pos_store = InMemoryPoSAccounting :: new ( ) ;
@@ -591,10 +681,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
591
681
592
682
// try to print coins in output
593
683
{
594
- let inputs = vec ! [ TxInput :: AccountCommand (
595
- AccountNonce :: new( 0 ) ,
596
- AccountCommand :: ConcludeOrder ( order_id) ,
597
- ) ] ;
684
+ let conclude_command = match version {
685
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
686
+ AccountNonce :: new ( 0 ) ,
687
+ AccountCommand :: ConcludeOrder ( order_id) ,
688
+ ) ,
689
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: ConcludeOrder {
690
+ order_id,
691
+ filled_amount : Amount :: ZERO ,
692
+ remaining_give_amount : give_amount,
693
+ } ) ,
694
+ } ;
695
+ let inputs = vec ! [ conclude_command] ;
598
696
let input_utxos = vec ! [ None ] ;
599
697
600
698
let outputs = vec ! [ TxOutput :: Transfer (
@@ -627,10 +725,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
627
725
628
726
// try to print tokens in output
629
727
{
630
- let inputs = vec ! [ TxInput :: AccountCommand (
631
- AccountNonce :: new( 0 ) ,
632
- AccountCommand :: ConcludeOrder ( order_id) ,
633
- ) ] ;
728
+ let conclude_command = match version {
729
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
730
+ AccountNonce :: new ( 0 ) ,
731
+ AccountCommand :: ConcludeOrder ( order_id) ,
732
+ ) ,
733
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: ConcludeOrder {
734
+ order_id,
735
+ filled_amount : Amount :: ZERO ,
736
+ remaining_give_amount : give_amount,
737
+ } ) ,
738
+ } ;
739
+ let inputs = vec ! [ conclude_command] ;
634
740
let input_utxos = vec ! [ None ] ;
635
741
636
742
let outputs = vec ! [ TxOutput :: Transfer (
@@ -665,10 +771,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
665
771
666
772
{
667
773
// partially use input in command
668
- let inputs = vec ! [ TxInput :: AccountCommand (
669
- AccountNonce :: new( 0 ) ,
670
- AccountCommand :: ConcludeOrder ( order_id) ,
671
- ) ] ;
774
+ let conclude_command = match version {
775
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
776
+ AccountNonce :: new ( 0 ) ,
777
+ AccountCommand :: ConcludeOrder ( order_id) ,
778
+ ) ,
779
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: ConcludeOrder {
780
+ order_id,
781
+ filled_amount : Amount :: ZERO ,
782
+ remaining_give_amount : give_amount,
783
+ } ) ,
784
+ } ;
785
+ let inputs = vec ! [ conclude_command] ;
672
786
let input_utxos = vec ! [ None ] ;
673
787
674
788
let outputs = vec ! [ TxOutput :: Transfer (
@@ -701,10 +815,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
701
815
}
702
816
703
817
// valid case
704
- let inputs = vec ! [ TxInput :: AccountCommand (
705
- AccountNonce :: new( 0 ) ,
706
- AccountCommand :: ConcludeOrder ( order_id) ,
707
- ) ] ;
818
+ let conclude_command = match version {
819
+ OrdersVersion :: V0 => TxInput :: AccountCommand (
820
+ AccountNonce :: new ( 0 ) ,
821
+ AccountCommand :: ConcludeOrder ( order_id) ,
822
+ ) ,
823
+ OrdersVersion :: V1 => TxInput :: OrderAccountCommand ( OrderAccountCommand :: ConcludeOrder {
824
+ order_id,
825
+ filled_amount : Amount :: ZERO ,
826
+ remaining_give_amount : give_amount,
827
+ } ) ,
828
+ } ;
829
+ let inputs = vec ! [ conclude_command] ;
708
830
let input_utxos = vec ! [ None ] ;
709
831
710
832
let outputs =
0 commit comments