@@ -17,9 +17,11 @@ use std::collections::BTreeMap;
1717
1818use common:: {
1919 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 ,
2325 } ,
2426 primitives:: { Amount , BlockHeight , CoinOrTokenId , Fee , Id , H256 } ,
2527} ;
@@ -252,11 +254,31 @@ fn create_order_constraints(#[case] seed: Seed) {
252254
253255#[ rstest]
254256#[ 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 ) {
257261 let mut rng = make_seedable_rng ( seed) ;
258262
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 ( ) ;
260282 let block_height = BlockHeight :: one ( ) ;
261283
262284 let pos_store = InMemoryPoSAccounting :: new ( ) ;
@@ -284,19 +306,27 @@ fn fill_order_constraints(#[case] seed: Seed) {
284306
285307 // use in command more than provided in input
286308 {
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 (
293311 AccountNonce :: new ( 0 ) ,
294312 AccountCommand :: FillOrder (
295313 order_id,
296314 ( ask_amount + Amount :: from_atoms ( 1 ) ) . unwrap ( ) ,
297315 Destination :: AnyoneCanSpend ,
298316 ) ,
299317 ) ,
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,
300330 ] ;
301331 let input_utxos = vec ! [
302332 Some ( TxOutput :: Transfer (
@@ -328,15 +358,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
328358
329359 // fill with coins instead of tokens
330360 {
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+ } ;
331372 let inputs = vec ! [
332373 TxInput :: Utxo ( UtxoOutPoint :: new(
333374 OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
334375 0 ,
335376 ) ) ,
336- TxInput :: AccountCommand (
337- AccountNonce :: new( 0 ) ,
338- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
339- ) ,
377+ fill_command,
340378 ] ;
341379 let input_utxos = vec ! [
342380 Some ( TxOutput :: Transfer (
@@ -361,15 +399,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
361399
362400 // try to print coins in output
363401 {
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+ } ;
364413 let inputs = vec ! [
365414 TxInput :: Utxo ( UtxoOutPoint :: new(
366415 OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
367416 0 ,
368417 ) ) ,
369- TxInput :: AccountCommand (
370- AccountNonce :: new( 0 ) ,
371- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
372- ) ,
418+ fill_command,
373419 ] ;
374420 let input_utxos = vec ! [
375421 Some ( TxOutput :: Transfer (
@@ -409,15 +455,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
409455
410456 // try to print tokens in output
411457 {
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+ } ;
412469 let inputs = vec ! [
413470 TxInput :: Utxo ( UtxoOutPoint :: new(
414471 OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
415472 0 ,
416473 ) ) ,
417- TxInput :: AccountCommand (
418- AccountNonce :: new( 0 ) ,
419- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
420- ) ,
474+ fill_command,
421475 ] ;
422476 let input_utxos = vec ! [
423477 Some ( TxOutput :: Transfer (
@@ -462,15 +516,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
462516
463517 {
464518 // 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+ } ;
465530 let inputs = vec ! [
466531 TxInput :: Utxo ( UtxoOutPoint :: new(
467532 OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
468533 0 ,
469534 ) ) ,
470- TxInput :: AccountCommand (
471- AccountNonce :: new( 0 ) ,
472- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
473- ) ,
535+ fill_command,
474536 ] ;
475537 let input_utxos = vec ! [
476538 Some ( TxOutput :: Transfer (
@@ -513,15 +575,23 @@ fn fill_order_constraints(#[case] seed: Seed) {
513575 }
514576
515577 // 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+ } ;
516589 let inputs = vec ! [
517590 TxInput :: Utxo ( UtxoOutPoint :: new(
518591 OutPointSourceId :: BlockReward ( Id :: new( H256 :: random_using( & mut rng) ) ) ,
519592 0 ,
520593 ) ) ,
521- TxInput :: AccountCommand (
522- AccountNonce :: new( 0 ) ,
523- AccountCommand :: FillOrder ( order_id, ask_amount, Destination :: AnyoneCanSpend ) ,
524- ) ,
594+ fill_command,
525595 ] ;
526596 let input_utxos = vec ! [
527597 Some ( TxOutput :: Transfer (
@@ -559,11 +629,31 @@ fn fill_order_constraints(#[case] seed: Seed) {
559629
560630#[ rstest]
561631#[ 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 ) {
564636 let mut rng = make_seedable_rng ( seed) ;
565637
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 ( ) ;
567657 let block_height = BlockHeight :: one ( ) ;
568658
569659 let pos_store = InMemoryPoSAccounting :: new ( ) ;
@@ -591,10 +681,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
591681
592682 // try to print coins in output
593683 {
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] ;
598696 let input_utxos = vec ! [ None ] ;
599697
600698 let outputs = vec ! [ TxOutput :: Transfer (
@@ -627,10 +725,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
627725
628726 // try to print tokens in output
629727 {
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] ;
634740 let input_utxos = vec ! [ None ] ;
635741
636742 let outputs = vec ! [ TxOutput :: Transfer (
@@ -665,10 +771,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
665771
666772 {
667773 // 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] ;
672786 let input_utxos = vec ! [ None ] ;
673787
674788 let outputs = vec ! [ TxOutput :: Transfer (
@@ -701,10 +815,18 @@ fn conclude_order_constraints(#[case] seed: Seed) {
701815 }
702816
703817 // 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] ;
708830 let input_utxos = vec ! [ None ] ;
709831
710832 let outputs =
0 commit comments