@@ -689,6 +689,109 @@ class Freeze_test : public beast::unit_test::suite
689
689
return ;
690
690
}
691
691
692
+ void
693
+ testOffersWhenDeepFrozen (FeatureBitset features)
694
+ {
695
+ testcase (" Offers on frozen trust lines" );
696
+
697
+ using namespace test ::jtx;
698
+ Env env (*this , features);
699
+
700
+ Account G1{" G1" };
701
+ Account A1{" A1" };
702
+ Account A2{" A2" };
703
+ Account A3{" A3" };
704
+
705
+ env.fund (XRP (10000 ), G1, A1, A2, A3);
706
+ env.close ();
707
+
708
+ env.trust (G1[" USD" ](1000 ), A1, A2, A3);
709
+ env.close ();
710
+
711
+ env (pay (G1, A1, G1[" USD" ](1000 )));
712
+ env (pay (G1, A2, G1[" USD" ](1000 )));
713
+ env.close ();
714
+
715
+ // Making large passive sell offer
716
+ // Wants to sell 90 USD for 100 XRP
717
+ env (offer (A2, XRP (100 ), G1[" USD" ](90 )), txflags (tfPassive));
718
+ env.close ();
719
+ // Making large passive buy offer
720
+ // Wants to buy 100 USD for 100 XRP
721
+ env (offer (A3, G1[" USD" ](100 ), XRP (100 )), txflags (tfPassive));
722
+ env.close ();
723
+ env.require (offers (A2, 1 ), offers (A3, 1 ));
724
+
725
+ // Checking A1 can buy from A2 by crossing it's offer
726
+ env (offer (A1, G1[" USD" ](1 ), XRP (2 )));
727
+ env.close ();
728
+ env.require (balance (A1, G1[" USD" ](1001 )), balance (A2, G1[" USD" ](999 )));
729
+
730
+ // Checking A1 can sell to A3 by crossing it's offer
731
+ env (offer (A1, XRP (1 ), G1[" USD" ](1 )));
732
+ env.close ();
733
+ env.require (balance (A1, G1[" USD" ](1000 )), balance (A3, G1[" USD" ](1 )));
734
+
735
+ // Testing aggressive and passive offer placing A1 frozen by issuer
736
+ {
737
+ env (trust (G1, A1[" USD" ](0 ), tfSetFreeze));
738
+ env.close ();
739
+
740
+ // test: can still make passive buy offer
741
+ env (offer (A1, G1[" USD" ](1 ), XRP (0.5 )), txflags (tfPassive));
742
+ env.close ();
743
+ env.require (balance (A1, G1[" USD" ](1000 )), offers (A1, 1 ));
744
+ // Cleanup
745
+ env (offer_cancel (A1, env.seq (A1) - 1 ));
746
+ env.close ();
747
+
748
+ // test: can still buy from A2
749
+ env (offer (A1, G1[" USD" ](1 ), XRP (2 )));
750
+ env.close ();
751
+ env.require (
752
+ balance (A1, G1[" USD" ](1001 )),
753
+ balance (A2, G1[" USD" ](998 )),
754
+ offers (A1, 0 ));
755
+
756
+ // test: cannot create passive sell offer
757
+ env (offer (A1, XRP (2 ), G1[" USD" ](1 )), ter (tecUNFUNDED_OFFER));
758
+ env.require (balance (A1, G1[" USD" ](1001 )), offers (A1, 0 ));
759
+
760
+ // test: cannot sell to A3
761
+ env (offer (A1, XRP (1 ), G1[" USD" ](1 )), ter (tecUNFUNDED_OFFER));
762
+ env.require (balance (A1, G1[" USD" ](1001 )), offers (A1, 0 ));
763
+
764
+ env.require (
765
+ balance (A1, G1[" USD" ](1001 )), balance (A3, G1[" USD" ](1 )));
766
+ env (trust (G1, A1[" USD" ](0 ), tfClearFreeze));
767
+ env.close ();
768
+ env.require (
769
+ balance (A1, G1[" USD" ](1000 )), balance (A3, G1[" USD" ](2 )));
770
+ }
771
+
772
+ // Testing aggressive and passive offer placing A1 deep frozen by issuer
773
+ if (features[featureDeepFreeze])
774
+ {
775
+ env (trust (G1, A1[" USD" ](1000 ), tfSetFreeze | tfSetDeepFreeze));
776
+ env.close ();
777
+
778
+ // test: cannot create passive buy offer
779
+ env (offer (A1, G1[" USD" ](1 ), XRP (0.5 )), ter (tecFROZEN));
780
+
781
+ // test: cannot buy from A2
782
+ env (offer (A1, G1[" USD" ](1 ), XRP (2 )), ter (tecFROZEN));
783
+
784
+ // test: cannot create passive sell offer
785
+ env (offer (A1, XRP (2 ), G1[" USD" ](1 )), ter (tecUNFUNDED_OFFER));
786
+
787
+ // test: cannot sell to A3
788
+ env (offer (A1, XRP (1 ), G1[" USD" ](1 )), ter (tecUNFUNDED_OFFER));
789
+
790
+ env (trust (G1, A1[" USD" ](0 ), tfClearFreeze | tfClearDeepFreeze));
791
+ env.close ();
792
+ }
793
+ }
794
+
692
795
void
693
796
testPaymentsWhenDeepFrozen (FeatureBitset features)
694
797
{
@@ -701,13 +804,10 @@ class Freeze_test : public beast::unit_test::suite
701
804
Account A1{" A1" };
702
805
Account A2{" A2" };
703
806
704
- env.fund (XRP (10000 ), G1);
705
- env.fund (XRP (10000 ), A1);
706
- env.fund (XRP (10000 ), A2);
807
+ env.fund (XRP (10000 ), G1, A1, A2);
707
808
env.close ();
708
809
709
- env.trust (G1[" USD" ](1000 ), A1);
710
- env.trust (G1[" USD" ](1000 ), A2);
810
+ env.trust (G1[" USD" ](1000 ), A1, A2);
711
811
env.close ();
712
812
713
813
env (pay (G1, A1, G1[" USD" ](1000 )));
@@ -836,6 +936,7 @@ class Freeze_test : public beast::unit_test::suite
836
936
testGlobalFreeze (features);
837
937
testNoFreeze (features);
838
938
testOffersWhenFrozen (features);
939
+ testOffersWhenDeepFrozen (features);
839
940
testPaymentsWhenDeepFrozen (features);
840
941
};
841
942
using namespace test ::jtx;
0 commit comments