52 Env env(*
this, features);
54 auto const lowerFee = [&] {
60 auto const baseFee = env.
current()->fees().base;
65 auto const lenderPass =
"lender";
68 env.
fund(
XRP(1'000'000), alice, lender, borrower);
80 txJson[sfTransactionType] =
"AccountSet";
81 txJson[sfAccount] = borrower.
human();
83 auto const signParams = [&] {
85 signParams[jss::passphrase] = borrowerPass;
86 signParams[jss::key_type] =
"ed25519";
87 signParams[jss::tx_json] = txJson;
90 auto const jSign = env.
rpc(
"json",
"sign",
to_string(signParams));
91 BEAST_EXPECT(jSign.isMember(jss::result) && jSign[jss::result].isMember(jss::tx_json));
92 auto txSignResult = jSign[jss::result][jss::tx_json];
93 auto const txSignBlob = jSign[jss::result][jss::tx_blob].asString();
94 txSignResult.removeMember(jss::hash);
96 auto const jtx = env.
jt(txJson,
Sig(borrower));
97 BEAST_EXPECT(txSignResult ==
jtx.jv);
100 auto const jSubmit = env.
rpc(
"submit", txSignBlob);
102 jSubmit.isMember(jss::result) &&
103 jSubmit[jss::result].isMember(jss::engine_result) &&
104 jSubmit[jss::result][jss::engine_result].asString() ==
"tesSUCCESS");
111 testcase(
"RPC LoanSet - illegal signature_target");
114 txJson[sfTransactionType] =
"AccountSet";
115 txJson[sfAccount] = borrower.
human();
119 for (
char const* target : {
"Destination",
"Book",
"Signer"})
121 auto const borrowerSignParams = [&] {
123 params[jss::passphrase] = borrowerPass;
124 params[jss::key_type] =
"ed25519";
125 params[jss::signature_target] = target;
126 params[jss::tx_json] = txJson;
129 auto const jSignBorrower = env.
rpc(
"json",
"sign",
to_string(borrowerSignParams));
130 BEAST_EXPECT(jSignBorrower[jss::result][jss::error] ==
"invalidParams");
131 BEAST_EXPECT(jSignBorrower[jss::result][jss::error_code] ==
RpcInvalidParams);
132 BEAST_EXPECT(jSignBorrower[jss::result][jss::error_message] == target);
136 testcase(
"RPC LoanSet - sign and submit borrower initiated");
139 txJson[sfTransactionType] =
"LoanSet";
140 txJson[sfAccount] = borrower.
human();
141 txJson[sfCounterparty] = lender.
human();
142 txJson[sfLoanBrokerID] =
143 "FF924CD18A236C2B49CF8E80A351CEAC6A10171DC9F110025646894FEC"
146 txJson[sfPrincipalRequested] =
"100000000";
147 txJson[sfPaymentTotal] = 10000;
148 txJson[sfPaymentInterval] = 3600;
149 txJson[sfGracePeriod] = 300;
150 txJson[sfFlags] = 65536;
151 txJson[sfFee] =
to_string(24 * baseFee / 10);
154 auto const borrowerSignParams = [&] {
156 params[jss::passphrase] = borrowerPass;
157 params[jss::key_type] =
"ed25519";
158 params[jss::tx_json] = txJson;
161 auto const jSignBorrower = env.
rpc(
"json",
"sign",
to_string(borrowerSignParams));
163 jSignBorrower.isMember(jss::result) &&
164 jSignBorrower[jss::result].isMember(jss::tx_json),
166 auto const txBorrowerSignResult = jSignBorrower[jss::result][jss::tx_json];
167 auto const txBorrowerSignBlob = jSignBorrower[jss::result][jss::tx_blob].asString();
173 auto const jSubmitBlob = env.
rpc(
"submit", txBorrowerSignBlob);
174 BEAST_EXPECT(jSubmitBlob.isMember(jss::result));
175 auto const jSubmitBlobResult = jSubmitBlob[jss::result];
176 BEAST_EXPECT(jSubmitBlobResult.isMember(jss::tx_json));
180 jSubmitBlobResult.isMember(jss::engine_result) &&
181 jSubmitBlobResult[jss::engine_result].asString() ==
"temBAD_SIGNER");
186 auto const lenderSignParams = [&] {
188 params[jss::passphrase] = lenderPass;
189 params[jss::key_type] =
"ed25519";
190 params[jss::signature_target] =
"CounterpartySignature";
191 params[jss::tx_json] = txBorrowerSignResult;
194 auto const jSignLender = env.
rpc(
"json",
"sign",
to_string(lenderSignParams));
196 jSignLender.isMember(jss::result) &&
197 jSignLender[jss::result].isMember(jss::tx_json));
198 auto const txLenderSignResult = jSignLender[jss::result][jss::tx_json];
199 auto const txLenderSignBlob = jSignLender[jss::result][jss::tx_blob].asString();
203 auto const jSubmitBlob = env.
rpc(
"submit", txLenderSignBlob);
204 BEAST_EXPECT(jSubmitBlob.isMember(jss::result));
205 auto const jSubmitBlobResult = jSubmitBlob[jss::result];
206 BEAST_EXPECT(jSubmitBlobResult.isMember(jss::tx_json));
207 auto const jSubmitBlobTx = jSubmitBlobResult[jss::tx_json];
212 jSubmitBlobResult.isMember(jss::engine_result) &&
213 jSubmitBlobResult[jss::engine_result].asString() ==
"tecNO_ENTRY",
217 !jSubmitBlob.isMember(jss::error) && !jSubmitBlobResult.isMember(jss::error));
224 auto const jSubmitJson = env.
rpc(
"json",
"submit",
to_string(lenderSignParams));
225 BEAST_EXPECT(jSubmitJson.isMember(jss::result));
226 auto const jSubmitJsonResult = jSubmitJson[jss::result];
227 BEAST_EXPECT(jSubmitJsonResult.isMember(jss::tx_json));
228 auto const jSubmitJsonTx = jSubmitJsonResult[jss::tx_json];
232 jSubmitJsonResult.isMember(jss::engine_result) &&
233 jSubmitJsonResult[jss::engine_result].asString() ==
"tefPAST_SEQ",
237 !jSubmitJson.isMember(jss::error) && !jSubmitJsonResult.isMember(jss::error));
239 BEAST_EXPECT(jSubmitBlobTx == jSubmitJsonTx);
243 testcase(
"RPC LoanSet - sign and submit lender initiated");
246 txJson[sfTransactionType] =
"LoanSet";
247 txJson[sfAccount] = lender.
human();
248 txJson[sfCounterparty] = borrower.
human();
249 txJson[sfLoanBrokerID] =
250 "FF924CD18A236C2B49CF8E80A351CEAC6A10171DC9F110025646894FEC"
253 txJson[sfPrincipalRequested] =
"100000000";
254 txJson[sfPaymentTotal] = 10000;
255 txJson[sfPaymentInterval] = 3600;
256 txJson[sfGracePeriod] = 300;
257 txJson[sfFlags] = 65536;
258 txJson[sfFee] =
to_string(24 * baseFee / 10);
261 auto const lenderSignParams = [&] {
263 params[jss::passphrase] = lenderPass;
264 params[jss::key_type] =
"ed25519";
265 params[jss::tx_json] = txJson;
268 auto const jSignLender = env.
rpc(
"json",
"sign",
to_string(lenderSignParams));
270 jSignLender.isMember(jss::result) &&
271 jSignLender[jss::result].isMember(jss::tx_json));
272 auto const txLenderSignResult = jSignLender[jss::result][jss::tx_json];
273 auto const txLenderSignBlob = jSignLender[jss::result][jss::tx_blob].asString();
279 auto const jSubmitBlob = env.
rpc(
"submit", txLenderSignBlob);
280 BEAST_EXPECT(jSubmitBlob.isMember(jss::result));
281 auto const jSubmitBlobResult = jSubmitBlob[jss::result];
282 BEAST_EXPECT(jSubmitBlobResult.isMember(jss::tx_json));
286 jSubmitBlobResult.isMember(jss::engine_result) &&
287 jSubmitBlobResult[jss::engine_result].asString() ==
"temBAD_SIGNER");
292 auto const borrowerSignParams = [&] {
294 params[jss::passphrase] = borrowerPass;
295 params[jss::key_type] =
"ed25519";
296 params[jss::signature_target] =
"CounterpartySignature";
297 params[jss::tx_json] = txLenderSignResult;
300 auto const jSignBorrower = env.
rpc(
"json",
"sign",
to_string(borrowerSignParams));
302 jSignBorrower.isMember(jss::result) &&
303 jSignBorrower[jss::result].isMember(jss::tx_json));
304 auto const txBorrowerSignResult = jSignBorrower[jss::result][jss::tx_json];
305 auto const txBorrowerSignBlob = jSignBorrower[jss::result][jss::tx_blob].asString();
309 auto const jSubmitBlob = env.
rpc(
"submit", txBorrowerSignBlob);
310 BEAST_EXPECT(jSubmitBlob.isMember(jss::result));
311 auto const jSubmitBlobResult = jSubmitBlob[jss::result];
312 BEAST_EXPECT(jSubmitBlobResult.isMember(jss::tx_json));
313 auto const jSubmitBlobTx = jSubmitBlobResult[jss::tx_json];
318 jSubmitBlobResult.isMember(jss::engine_result) &&
319 jSubmitBlobResult[jss::engine_result].asString() ==
"tecNO_ENTRY",
323 !jSubmitBlob.isMember(jss::error) && !jSubmitBlobResult.isMember(jss::error));
330 auto const jSubmitJson = env.
rpc(
"json",
"submit",
to_string(borrowerSignParams));
331 BEAST_EXPECT(jSubmitJson.isMember(jss::result));
332 auto const jSubmitJsonResult = jSubmitJson[jss::result];
333 BEAST_EXPECT(jSubmitJsonResult.isMember(jss::tx_json));
334 auto const jSubmitJsonTx = jSubmitJsonResult[jss::tx_json];
338 jSubmitJsonResult.isMember(jss::engine_result) &&
339 jSubmitJsonResult[jss::engine_result].asString() ==
"tefPAST_SEQ",
343 !jSubmitJson.isMember(jss::error) && !jSubmitJsonResult.isMember(jss::error));
345 BEAST_EXPECT(jSubmitBlobTx == jSubmitJsonTx);