2222
2323import static org .assertj .core .api .Assertions .assertThat ;
2424
25+ import com .fasterxml .jackson .core .JsonProcessingException ;
2526import com .google .common .primitives .UnsignedInteger ;
2627import com .google .common .primitives .UnsignedLong ;
28+ import org .json .JSONException ;
2729import org .junit .jupiter .api .Test ;
30+ import org .xrpl .xrpl4j .model .AbstractJsonTest ;
2831import org .xrpl .xrpl4j .model .client .common .LedgerIndex ;
2932
3033import java .util .Optional ;
3134
32- public class SetFeeTest {
35+ /**
36+ * Unit tests for {@link SetFee}.
37+ */
38+ public class SetFeeTest extends AbstractJsonTest {
39+
40+ @ Test
41+ public void testConstructWithNoFeeUnits () {
42+ SetFee setFee = SetFee .builder ()
43+ .account (Address .of ("rrrrrrrrrrrrrrrrrrrrrhoLvTp" ))
44+ .fee (XrpCurrencyAmount .ofDrops (12 ))
45+ .sequence (UnsignedInteger .valueOf (2470665 ))
46+ .baseFeeDrops (XrpCurrencyAmount .ofDrops (10 ))
47+ .reserveBaseDrops (XrpCurrencyAmount .ofDrops (20000000 ))
48+ .reserveIncrementDrops (XrpCurrencyAmount .ofDrops (5000000 ))
49+ .ledgerSequence (Optional .of (LedgerIndex .of (UnsignedInteger .valueOf (67850752 ))))
50+ .build ();
51+
52+ assertThat (setFee .transactionType ()).isEqualTo (TransactionType .SET_FEE );
53+ assertThat (setFee .account ()).isEqualTo (Address .of ("rrrrrrrrrrrrrrrrrrrrrhoLvTp" ));
54+ assertThat (setFee .fee ().value ()).isEqualTo (UnsignedLong .valueOf (12 ));
55+ assertThat (setFee .sequence ()).isEqualTo (UnsignedInteger .valueOf (2470665 ));
56+ assertThat (setFee .ledgerSequence ()).isNotEmpty ().get ().isEqualTo (LedgerIndex .of (UnsignedInteger .valueOf (67850752 )));
57+ assertThat (setFee .baseFee ()).isEqualTo ("a" );
58+ assertThat (setFee .baseFeeDrops ()).isEqualTo (XrpCurrencyAmount .ofDrops (10 ));
59+ assertThat (setFee .referenceFeeUnits ()).isEmpty ();
60+ assertThat (setFee .reserveIncrement ()).isEqualTo (UnsignedInteger .valueOf (5000000 ));
61+ assertThat (setFee .reserveIncrementDrops ()).isEqualTo (XrpCurrencyAmount .ofDrops (5000000 ));
62+ assertThat (setFee .reserveBase ()).isEqualTo (UnsignedInteger .valueOf (20000000 ));
63+ assertThat (setFee .reserveBaseDrops ()).isEqualTo (XrpCurrencyAmount .ofDrops (20000000 ));
64+ }
3365
3466 @ Test
35- public void testBuilder () {
67+ public void testConstructWithFeeUnits () {
3668 SetFee setFee = SetFee .builder ()
3769 .account (Address .of ("rrrrrrrrrrrrrrrrrrrrrhoLvTp" ))
3870 .fee (XrpCurrencyAmount .ofDrops (12 ))
3971 .sequence (UnsignedInteger .valueOf (2470665 ))
40- .baseFee ("000000000000000A" )
72+ .baseFeeDrops (XrpCurrencyAmount .ofDrops (10 ))
73+ .reserveBaseDrops (XrpCurrencyAmount .ofDrops (20000000 ))
74+ .reserveIncrementDrops (XrpCurrencyAmount .ofDrops (5000000 ))
4175 .referenceFeeUnits (UnsignedInteger .valueOf (10 ))
42- .reserveBase (UnsignedInteger .valueOf (20000000 ))
43- .reserveIncrement (UnsignedInteger .valueOf (5000000 ))
4476 .ledgerSequence (Optional .of (LedgerIndex .of (UnsignedInteger .valueOf (67850752 ))))
4577 .build ();
4678
@@ -49,8 +81,78 @@ public void testBuilder() {
4981 assertThat (setFee .fee ().value ()).isEqualTo (UnsignedLong .valueOf (12 ));
5082 assertThat (setFee .sequence ()).isEqualTo (UnsignedInteger .valueOf (2470665 ));
5183 assertThat (setFee .ledgerSequence ()).isNotEmpty ().get ().isEqualTo (LedgerIndex .of (UnsignedInteger .valueOf (67850752 )));
52- assertThat (setFee .referenceFeeUnits ()).isEqualTo (UnsignedInteger .valueOf (10 ));
84+ assertThat (setFee .baseFee ()).isEqualTo ("a" );
85+ assertThat (setFee .baseFeeDrops ()).isEqualTo (XrpCurrencyAmount .ofDrops (10 ));
86+ assertThat (setFee .referenceFeeUnits ()).isNotEmpty ().get ().isEqualTo (UnsignedInteger .valueOf (10 ));
5387 assertThat (setFee .reserveIncrement ()).isEqualTo (UnsignedInteger .valueOf (5000000 ));
88+ assertThat (setFee .reserveIncrementDrops ()).isEqualTo (XrpCurrencyAmount .ofDrops (5000000 ));
5489 assertThat (setFee .reserveBase ()).isEqualTo (UnsignedInteger .valueOf (20000000 ));
90+ assertThat (setFee .reserveBaseDrops ()).isEqualTo (XrpCurrencyAmount .ofDrops (20000000 ));
91+ }
92+
93+ @ Test
94+ public void testDeserializePreXrpFeesTransaction () throws JsonProcessingException {
95+ SetFee expected = SetFee .builder ()
96+ .account (Address .of ("rrrrrrrrrrrrrrrrrrrrrhoLvTp" ))
97+ .fee (XrpCurrencyAmount .ofDrops (12 ))
98+ .sequence (UnsignedInteger .valueOf (2470665 ))
99+ .baseFeeDrops (XrpCurrencyAmount .ofDrops (10 ))
100+ .referenceFeeUnits (UnsignedInteger .valueOf (10 ))
101+ .reserveBaseDrops (XrpCurrencyAmount .ofDrops (20000000 ))
102+ .reserveIncrementDrops (XrpCurrencyAmount .ofDrops (5000000 ))
103+ .ledgerSequence (Optional .of (LedgerIndex .of (UnsignedInteger .valueOf (67850752 ))))
104+ .build ();
105+
106+ String json = "{" +
107+ "\" Account\" :\" rrrrrrrrrrrrrrrrrrrrrhoLvTp\" ," +
108+ "\" Fee\" :\" 12\" ," +
109+ "\" LedgerSequence\" :67850752," +
110+ "\" Sequence\" :2470665," +
111+ "\" SigningPubKey\" :\" \" ," +
112+ "\" TransactionType\" :\" SetFee\" ," +
113+ "\" ReserveIncrement\" :5000000," +
114+ "\" ReserveBase\" :20000000," +
115+ "\" ReferenceFeeUnits\" :10," +
116+ "\" BaseFee\" :\" a\" }" ;
117+
118+ Transaction actual = objectMapper .readValue (json , Transaction .class );
119+ assertThat (actual ).isEqualTo (expected );
120+
121+ String reserialized = objectMapper .writeValueAsString (actual );
122+ Transaction redeserialized = objectMapper .readValue (reserialized , Transaction .class );
123+
124+ assertThat (redeserialized ).isEqualTo (expected );
125+ }
126+
127+ @ Test
128+ public void testDeserializePostXrpFeesTransaction () throws JsonProcessingException {
129+ SetFee expected = SetFee .builder ()
130+ .account (Address .of ("rrrrrrrrrrrrrrrrrrrrrhoLvTp" ))
131+ .fee (XrpCurrencyAmount .ofDrops (0 ))
132+ .sequence (UnsignedInteger .valueOf (0 ))
133+ .baseFeeDrops (XrpCurrencyAmount .ofDrops (10 ))
134+ .reserveBaseDrops (XrpCurrencyAmount .ofDrops (10000000 ))
135+ .reserveIncrementDrops (XrpCurrencyAmount .ofDrops (2000000 ))
136+ .ledgerSequence (Optional .of (LedgerIndex .of (UnsignedInteger .valueOf (66462465 ))))
137+ .build ();
138+
139+ String json = "{\n " +
140+ " \" Account\" : \" rrrrrrrrrrrrrrrrrrrrrhoLvTp\" ,\n " +
141+ " \" BaseFeeDrops\" : \" 10\" ,\n " +
142+ " \" Fee\" : \" 0\" ,\n " +
143+ " \" LedgerSequence\" : 66462465,\n " +
144+ " \" ReserveBaseDrops\" : \" 10000000\" ,\n " +
145+ " \" ReserveIncrementDrops\" : \" 2000000\" ,\n " +
146+ " \" Sequence\" : 0,\n " +
147+ " \" SigningPubKey\" : \" \" ,\n " +
148+ " \" TransactionType\" : \" SetFee\" }" ;
149+
150+ Transaction actual = objectMapper .readValue (json , Transaction .class );
151+ assertThat (actual ).isEqualTo (expected );
152+
153+ String reserialized = objectMapper .writeValueAsString (actual );
154+ Transaction redeserialized = objectMapper .readValue (reserialized , Transaction .class );
155+
156+ assertThat (redeserialized ).isEqualTo (expected );
55157 }
56158}
0 commit comments