67 Account const dpIssuer(
"dpIssuer");
68 char const credType[] =
"KYC_VERIFIED";
72 env(credentials::create(subject, dpIssuer, credType));
74 env(credentials::accept(subject, dpIssuer, credType));
76 auto const jv = credentials::ledgerEntry(env, subject, dpIssuer, credType);
77 return jv[jss::result][jss::index].asString();
82 Env env(*
this, features);
87 {.account = bob, .payAmount = 100, .convertAmount = 50},
88 {.account = carol, .payAmount = 100, .convertAmount = 50},
90 auto& mpt = confEnv.
mpt;
91 env(fset(bob, asfDepositAuth));
103 env(deposit::auth(bob, carol));
117 env(deposit::unauth(bob, carol));
131 Env env(*
this, features);
132 env.fund(XRP(50000), dpIssuer);
139 {.account = bob, .payAmount = 100, .convertAmount = 50},
140 {.account = carol, .payAmount = 100, .convertAmount = 50},
142 auto& mpt = confEnv.
mpt;
143 env(fset(bob, asfDepositAuth));
146 auto const credIdx = createCredential(env, carol);
153 .credentials = {{credIdx}},
158 env(deposit::authCredentials(bob, {{.issuer = dpIssuer, .credType = credType}}));
170 mpt.send({.account = carol, .dest = bob, .amt = 10, .credentials = {{credIdx}}});
178 Env env(*
this, features);
179 env.fund(XRP(50000), dpIssuer);
186 {.account = bob, .payAmount = 100, .convertAmount = 50},
187 {.account = carol, .payAmount = 100, .convertAmount = 50},
189 auto& mpt = confEnv.
mpt;
190 env(fset(bob, asfDepositAuth));
193 auto const credIdx = createCredential(env, carol);
196 env(deposit::auth(bob, carol));
210 mpt.send({.account = carol, .dest = bob, .amt = 10, .credentials = {{credIdx}}});
216 env(deposit::unauth(bob, carol));
232 .credentials = {{credIdx}},
237 env(deposit::authCredentials(bob, {{.issuer = dpIssuer, .credType = credType}}));
241 mpt.send({.account = carol, .dest = bob, .amt = 10, .credentials = {{credIdx}}});
244 auto const expireTime = 30;
248 auto const createExpiringCredential = [&](Env& env,
Account const& subject) ->
std::string {
249 auto jv = credentials::create(subject, dpIssuer, credType);
251 env.current()->header().parentCloseTime.time_since_epoch().count() + expireTime;
252 jv[sfExpiration.jsonName] = expiry;
255 env(credentials::accept(subject, dpIssuer, credType));
257 auto const credentials = credentials::ledgerEntry(env, subject, dpIssuer, credType);
258 return credentials[jss::result][jss::index].asString();
261 auto const credentialDeleted = [&](Env& env,
Account const& subject) ->
bool {
262 auto const credentials = credentials::ledgerEntry(env, subject, dpIssuer, credType);
263 return credentials[jss::result][jss::error] ==
"entryNotFound" &&
265 credentials[jss::result][jss::error_message] ==
"Entry not found.";
274 Env env(*
this, features);
275 env.fund(XRP(50000), dpIssuer);
282 {.account = bob, .payAmount = 100, .convertAmount = 50},
283 {.account = carol, .payAmount = 100, .convertAmount = 50},
285 auto& mpt = confEnv.
mpt;
286 env(fset(bob, asfDepositAuth));
289 auto const credIdx = createExpiringCredential(env, carol);
292 env(deposit::authCredentials(bob, {{.issuer = dpIssuer, .credType = credType}}));
303 .credentials = {{credIdx}},
308 BEAST_EXPECT(credentialDeleted(env, carol));
317 Env env(*
this, features);
318 env.fund(XRP(50000), dpIssuer);
325 {.account = bob, .payAmount = 100, .convertAmount = 50},
326 {.account = carol, .payAmount = 100, .convertAmount = 50},
328 auto& mpt = confEnv.
mpt;
330 auto const credIdx = createExpiringCredential(env, carol);
340 .credentials = {{credIdx}},
345 BEAST_EXPECT(credentialDeleted(env, carol));
360 Env env(*
this, features);
361 env.fund(XRP(50000), dpIssuer);
368 {.account = bob, .payAmount = 100, .convertAmount = 50},
369 {.account = carol, .payAmount = 100, .convertAmount = 50},
371 auto& mpt = confEnv.
mpt;
372 env(fset(bob, asfDepositAuth));
375 auto const credIdx = createExpiringCredential(env, carol);
385 .credentials = {{credIdx}},
391 BEAST_EXPECT(!credentialDeleted(env, carol));
398 testcase(
"Send credential validation");
417 Account const dpIssuer(
"dpIssuer");
418 char const credType[] =
"KYC";
422 Env env(*
this, features);
427 {.account = bob, .payAmount = 100, .convertAmount = 50},
428 {.account = carol, .payAmount = 100, .convertAmount = 50},
430 auto& mpt = confEnv.
mpt;
443 Env env(*
this, features);
448 {.account = bob, .payAmount = 100, .convertAmount = 50},
449 {.account = carol, .payAmount = 100, .convertAmount = 50},
451 auto& mpt = confEnv.
mpt;
455 for (
int i = 0; i < 9; ++i)
462 .credentials = tooManyCredentials,
469 Env env(*
this, features);
470 env.fund(XRP(50000), dpIssuer);
476 {.account = bob, .payAmount = 100, .convertAmount = 50},
477 {.account = carol, .payAmount = 100, .convertAmount = 50},
479 auto& mpt = confEnv.
mpt;
481 env(credentials::create(carol, dpIssuer, credType));
483 env(credentials::accept(carol, dpIssuer, credType));
486 auto const jv = credentials::ledgerEntry(env, carol, dpIssuer, credType);
487 std::string const credIdx = jv[jss::result][jss::index].asString();
493 .credentials = {{credIdx, credIdx}},
500 Env env(*
this, features);
505 {.account = bob, .payAmount = 100, .convertAmount = 50},
506 {.account = carol, .payAmount = 100, .convertAmount = 50},
508 auto& mpt = confEnv.
mpt;
515 .credentials = {{fakeCredIdx}},
522 Env env(*
this, features);
523 env.fund(XRP(50000), dpIssuer);
529 {.account = bob, .payAmount = 100, .convertAmount = 50},
530 {.account = carol, .payAmount = 100, .convertAmount = 50},
532 auto& mpt = confEnv.
mpt;
535 env(credentials::create(bob, dpIssuer, credType));
537 env(credentials::accept(bob, dpIssuer, credType));
540 auto const jv = credentials::ledgerEntry(env, bob, dpIssuer, credType);
541 std::string const credIdx = jv[jss::result][jss::index].asString();
547 .credentials = {{credIdx}},
554 Env env(*
this, features);
555 env.fund(XRP(50000), dpIssuer);
561 {.account = bob, .payAmount = 100, .convertAmount = 50},
562 {.account = carol, .payAmount = 100, .convertAmount = 50},
564 auto& mpt = confEnv.
mpt;
567 env(credentials::create(carol, dpIssuer, credType));
570 auto const jv = credentials::ledgerEntry(env, carol, dpIssuer, credType);
571 std::string const credIdx = jv[jss::result][jss::index].asString();
577 .credentials = {{credIdx}},
587 Env env(*
this, features - featureCredentials);
592 {.account = bob, .payAmount = 100, .convertAmount = 50},
593 {.account = carol, .payAmount = 100, .convertAmount = 50},
595 auto& mpt = confEnv.
mpt;
597 auto constexpr kCredIdx =
598 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288BE4";
604 .credentials = {{kCredIdx}},
620 testcase(
"AMM holder cannot have confidential state");
626 for (
bool const enablePseudoAccount : {
false,
true})
630 enablePseudoAccount ? features | featureSingleAssetVault
631 : features - featureSingleAssetVault};
633 MPTTester mptAlice(env, alice, {.holders = {bob}});
636 .flags = kMptDexFlags | tfMPTCanClawback | tfMPTCanHoldConfidentialBalance,
638 mptAlice.authorize({.account = bob});
639 mptAlice.pay(alice, bob, 1'000);
641 mptAlice.generateKeyPair(alice);
642 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
644 AMM
const amm(env, bob, XRP(100), mptAlice(100));
645 Account const ammHolder(
"amm", amm.ammAccount());
648 BEAST_EXPECT(ammSle && ammSle->isFieldPresent(sfAMMID));
649 BEAST_EXPECT(mptAlice.getBalance(ammHolder) == 100);
651 BEAST_EXPECT(!mptAlice.getEncryptedBalance(ammHolder, MPTTester::holderEncryptedInbox));
653 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::holderEncryptedSpending));
655 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::issuerEncryptedBalance));
657 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::auditorEncryptedBalance));
659 mptAlice.confidentialClaw({
676 testcase(
"Full AMMWithdraw with an unrelated holder's COA");
683 for (
bool const withFix : {
true,
false})
685 for (
bool const carolConverts : {
false,
true})
687 Env env{*
this, withFix ? features | fixCleanup3_5_0 : features - fixCleanup3_5_0};
689 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
690 mptAlice.create({.flags = kMptDexFlags | tfMPTCanHoldConfidentialBalance});
691 mptAlice.authorize({.account = bob});
692 mptAlice.authorize({.account = carol});
693 mptAlice.pay(alice, bob, 1'000);
694 mptAlice.pay(alice, carol, 100);
696 mptAlice.generateKeyPair(alice);
697 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
701 AMM amm(env, bob, XRP(100), mptAlice(100));
702 Account const ammHolder(
"amm", amm.ammAccount());
703 BEAST_EXPECT(amm.ammExists());
704 BEAST_EXPECT(mptAlice.getBalance(ammHolder) == 100);
710 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::holderEncryptedInbox));
712 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::holderEncryptedSpending));
714 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::issuerEncryptedBalance));
716 !mptAlice.getEncryptedBalance(ammHolder, MPTTester::auditorEncryptedBalance));
720 mptAlice.generateKeyPair(carol);
722 {.account = carol, .amt = 1, .holderPubKey = mptAlice.getPubKey(carol)});
725 BEAST_EXPECT(mptAlice.getIssuanceConfidentialBalance() == (carolConverts ? 1 : 0));
727 if (carolConverts && !withFix)
734 BEAST_EXPECT(amm.ammExists());
735 BEAST_EXPECT(mptAlice.getBalance(ammHolder) == 100);
743 auto const bobLPTokens = amm.getLPTokensBalance(bob.id());
745 bob,
IOUAmount{bobLPTokens.mantissa() / 2, bobLPTokens.exponent()});
747 BEAST_EXPECT(amm.ammExists());
748 BEAST_EXPECT(mptAlice.getBalance(ammHolder) > 0);
755 amm.withdrawAll(bob);
758 BEAST_EXPECT(!amm.ammExists());
773 testcase(
"Confidential transfer with tickets");
776 Env env{*
this, features};
780 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
784 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
786 mptAlice.authorize({.account = bob});
787 mptAlice.authorize({.account = carol});
788 mptAlice.pay(alice, bob, 100);
789 mptAlice.pay(alice, carol, 100);
791 mptAlice.generateKeyPair(alice);
792 mptAlice.generateKeyPair(bob);
793 mptAlice.generateKeyPair(carol);
798 env(ticket::create(alice, 1));
799 mptAlice.set({.issuerPubKey = mptAlice.getPubKey(alice), .ticketSeq = ticketSeq});
805 env(ticket::create(bob, 1));
809 .holderPubKey = mptAlice.getPubKey(bob),
810 .ticketSeq = ticketSeq,
812 env.require(MptBalance(mptAlice, bob, 50));
818 env(ticket::create(bob, 1));
819 mptAlice.convert({.account = bob, .amt = 20, .ticketSeq = ticketSeq});
820 env.require(MptBalance(mptAlice, bob, 30));
826 env(ticket::create(bob, 1));
827 mptAlice.mergeInbox({.account = bob, .ticketSeq = ticketSeq});
830 mptAlice.convert({.account = carol, .amt = 50, .holderPubKey = mptAlice.getPubKey(carol)});
831 mptAlice.mergeInbox({.account = carol});
836 env(ticket::create(bob, 1));
837 mptAlice.send({.account = bob, .dest = carol, .amt = 10, .ticketSeq = ticketSeq});
841 mptAlice.mergeInbox({.account = carol});
847 env(ticket::create(carol, 1));
848 mptAlice.convertBack({.account = carol, .amt = 10, .ticketSeq = ticketSeq});
850 env.require(MptBalance(mptAlice, carol, 60));
860 testcase(
"Convert proof binds to ticket sequence");
863 Env env{*
this, features};
866 MPTTester mptAlice(env, alice, {.holders = {bob}});
871 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanHoldConfidentialBalance,
873 mptAlice.authorize({.account = bob});
874 mptAlice.pay(alice, bob, 100);
876 mptAlice.generateKeyPair(alice);
877 mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)});
878 mptAlice.generateKeyPair(bob);
880 uint64_t
const amt = 30;
882 Buffer const holderCt = mptAlice.encryptAmount(bob, amt, bf);
883 Buffer const issuerCt = mptAlice.encryptAmount(alice, amt, bf);
886 env(ticket::create(bob, 1));
891 BEAST_EXPECT(env.seq(bob) != ticketSeq1);
895 mptAlice.getSchnorrProof(bob, badCtxHash),
"Missing Schnorr Proof.");
900 .proof =
strHex(badProof),
901 .holderPubKey = mptAlice.getPubKey(bob),
902 .holderEncryptedAmt = holderCt,
903 .issuerEncryptedAmt = issuerCt,
904 .blindingFactor = bf,
905 .ticketSeq = ticketSeq1,
911 env(ticket::create(bob, 1));
917 .holderPubKey = mptAlice.getPubKey(bob),
918 .holderEncryptedAmt = holderCt,
919 .issuerEncryptedAmt = issuerCt,
920 .blindingFactor = bf,
921 .ticketSeq = ticketSeq2,
923 env.require(MptBalance(mptAlice, bob, 70));
1036 testcase(
"Batch confidential send - merge inbox dependency");
1040 Env env{*
this, features};
1046 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1054 auto const bobSeq = env.seq(bob);
1055 auto const carolSeq = env.seq(carol);
1057 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 3);
1059 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 100}, bobSeq + 1);
1060 auto const jv2 = mpt.mergeInboxJV({.account = carol});
1061 auto const jv3 = mpt.sendJV({.account = carol, .dest = dave, .amt = 50}, carolSeq + 1);
1063 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1064 batch::Inner(jv1, bobSeq + 1),
1065 batch::Inner(jv2, carolSeq),
1066 batch::Inner(jv3, carolSeq + 1),
1073 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1074 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
1082 Env env{*
this, features};
1088 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1093 auto const bobSeq = env.seq(bob);
1094 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1096 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 50}, bobSeq + 1);
1097 auto const jv2 = mpt.sendJV({.account = bob, .dest = dave, .amt = 60}, bobSeq + 2);
1099 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1100 batch::Inner(jv1, bobSeq + 1),
1101 batch::Inner(jv2, bobSeq + 2),
1107 mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 150);
1108 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
1109 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
1114 auto const bobSeq = env.seq(bob);
1115 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1117 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 50}, bobSeq + 1);
1118 auto const jv2 = mpt.sendJV({.account = bob, .dest = dave, .amt = 60}, bobSeq + 2);
1120 env(batch::outer(bob, bobSeq, batchFee, tfIndependent),
1121 batch::Inner(jv1, bobSeq + 1),
1122 batch::Inner(jv2, bobSeq + 2),
1128 mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1129 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 50);
1131 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
1140 Env env{*
this, features};
1146 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1150 auto const bobSeq = env.seq(bob);
1151 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1155 mpt.sendJV({.account = bob, .dest = carol, .amt = 100}, bobSeq + 1);
1158 auto const chain1 = mpt.chainAfterSend(bob, 100, jv1);
1162 mpt.sendJV({.account = bob, .dest = dave, .amt = 100}, bobSeq + 2, chain1);
1164 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1165 batch::Inner(jv1, bobSeq + 1),
1166 batch::Inner(jv2, bobSeq + 2),
1171 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 0);
1173 mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 100);
1174 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 100);
1180 Env env2{*
this, features};
1181 Account const alice2(
"alice");
1183 Account const carol2(
"carol");
1186 MPTTester mpt2(env2, alice2, {.holders = {bob2, carol2, dave2}});
1189 auto const bobSeq = env2.seq(bob2);
1190 auto const batchFee = batch::calcConfidentialBatchFee(env2, 0, 2);
1193 mpt2.sendJV({.account = bob2, .dest = carol2, .amt = 100}, bobSeq + 1);
1194 auto const chain1 = mpt2.chainAfterSend(bob2, 100, jv1);
1197 mpt2.sendJV({.account = bob2, .dest = dave2, .amt = 100}, bobSeq + 2, chain1);
1200 batch::outer(bob2, bobSeq, batchFee, tfAllOrNothing),
1201 batch::Inner(jv1, bobSeq + 1),
1202 batch::Inner(jv2, bobSeq + 2),
1208 mpt2.getDecryptedBalance(bob2, MPTTester::holderEncryptedSpending) == 150);
1210 mpt2.getDecryptedBalance(carol2, MPTTester::holderEncryptedInbox) == 0);
1211 BEAST_EXPECT(mpt2.getDecryptedBalance(dave2, MPTTester::holderEncryptedInbox) == 0);
1218 testcase(
"Batch confidential convert and convertBack");
1230 Env env{*
this, features};
1236 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1240 mpt.pay(alice, bob, 50);
1242 auto const bobSeq = env.seq(bob);
1243 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1246 auto const jv1 = mpt.convertJV({.account = bob, .amt = 50}, bobSeq + 1);
1248 auto const jv2 = mpt.convertBackJV({.account = bob, .amt = 30}, bobSeq + 2);
1250 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1251 batch::Inner(jv1, bobSeq + 1),
1252 batch::Inner(jv2, bobSeq + 2),
1259 env.require(MptBalance(mpt, bob, 30));
1260 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 70);
1261 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedInbox) == 50);
1273 Env env{*
this, features};
1279 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1281 mpt.pay(alice, bob, 50);
1283 auto const bobSeq = env.seq(bob);
1284 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 3);
1286 auto const jv1 = mpt.convertJV({.account = bob, .amt = 50}, bobSeq + 1);
1287 auto const jv2 = mpt.mergeInboxJV({.account = bob});
1289 auto const jv3 = mpt.convertBackJV({.account = bob, .amt = 30}, bobSeq + 3);
1291 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1292 batch::Inner(jv1, bobSeq + 1),
1293 batch::Inner(jv2, bobSeq + 2),
1294 batch::Inner(jv3, bobSeq + 3),
1299 env.require(MptBalance(mpt, bob, 50));
1300 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1301 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedInbox) == 0);
1310 testcase(
"Batch confidential mixed operations");
1326 Env env{*
this, features};
1332 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1337 mpt.pay(alice, carol, 50);
1339 mpt.pay(alice, dave, 50);
1340 mpt.convert({.account = dave, .amt = 50});
1341 mpt.mergeInbox({.account = dave});
1343 auto const bobSeq = env.seq(bob);
1344 auto const carolSeq = env.seq(carol);
1345 auto const daveSeq = env.seq(dave);
1347 auto const batchFee = batch::calcConfidentialBatchFee(env, 2, 4);
1350 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 30}, bobSeq + 1);
1352 auto const jv2 = mpt.convertJV({.account = carol, .amt = 50}, carolSeq);
1354 auto const jv3 = mpt.convertBackJV({.account = dave, .amt = 20}, daveSeq);
1357 auto const jv4 = mpt.mergeInboxJV({.account = carol});
1359 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1360 batch::Inner(jv1, bobSeq + 1),
1361 batch::Inner(jv2, carolSeq),
1362 batch::Inner(jv3, daveSeq),
1363 batch::Inner(jv4, carolSeq + 1),
1364 batch::Sig(carol, dave),
1369 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 70);
1371 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 80);
1372 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
1374 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedSpending) == 30);
1375 env.require(MptBalance(mpt, dave, 20));
1384 Env env{*
this, features};
1390 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1393 auto const bobSeq = env.seq(bob);
1394 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1397 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 30}, bobSeq + 1);
1399 auto const jv2 = mpt.convertBackJV({.account = bob, .amt = 40}, bobSeq + 2);
1401 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1402 batch::Inner(jv1, bobSeq + 1),
1403 batch::Inner(jv2, bobSeq + 2),
1408 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1409 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
1418 testcase(
"Batch confidential MPT - all or nothing");
1421 Env env{*
this, features};
1427 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1433 auto const bobSeq = env.seq(bob);
1434 auto const carolSeq = env.seq(carol);
1435 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
1437 auto const jv1 = mpt.sendJV({.account = bob, .dest = dave, .amt = 10}, bobSeq + 1);
1438 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 5}, carolSeq);
1440 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1441 batch::Inner(jv1, bobSeq + 1),
1442 batch::Inner(jv2, carolSeq),
1448 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 90);
1449 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 55);
1450 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 15);
1457 testcase(
"Batch confidential MPT - only one");
1460 Env env{*
this, features};
1466 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1472 auto const bobSeq = env.seq(bob);
1473 auto const carolSeq = env.seq(carol);
1474 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
1477 auto const jv1 = mpt.sendJV({.account = bob, .dest = dave, .amt = 200}, bobSeq + 1);
1478 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 300}, carolSeq);
1480 env(batch::outer(bob, bobSeq, batchFee, tfOnlyOne),
1481 batch::Inner(jv1, bobSeq + 1),
1482 batch::Inner(jv2, carolSeq),
1488 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1489 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 60);
1490 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
1495 auto const bobSeq = env.seq(bob);
1496 auto const carolSeq = env.seq(carol);
1497 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
1499 auto const jv1 = mpt.sendJV({.account = bob, .dest = dave, .amt = 200}, bobSeq + 1);
1500 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 5}, carolSeq);
1502 env(batch::outer(bob, bobSeq, batchFee, tfOnlyOne),
1503 batch::Inner(jv1, bobSeq + 1),
1504 batch::Inner(jv2, carolSeq),
1510 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1511 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 55);
1512 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 5);
1519 testcase(
"Batch confidential MPT - until failure");
1522 Env env{*
this, features};
1528 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1535 auto const bobSeq = env.seq(bob);
1536 auto const carolSeq = env.seq(carol);
1537 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
1539 auto const jv1 = mpt.sendJV({.account = bob, .dest = dave, .amt = 200}, bobSeq + 1);
1540 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 5}, carolSeq);
1542 env(batch::outer(bob, bobSeq, batchFee, tfUntilFailure),
1543 batch::Inner(jv1, bobSeq + 1),
1544 batch::Inner(jv2, carolSeq),
1549 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1550 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 60);
1555 auto const bobSeq = env.seq(bob);
1556 auto const carolSeq = env.seq(carol);
1557 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
1559 auto const jv1 = mpt.sendJV({.account = bob, .dest = dave, .amt = 10}, bobSeq + 1);
1560 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 5}, carolSeq);
1562 env(batch::outer(bob, bobSeq, batchFee, tfUntilFailure),
1563 batch::Inner(jv1, bobSeq + 1),
1564 batch::Inner(jv2, carolSeq),
1570 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 90);
1571 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 55);
1572 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 15);
1579 testcase(
"Batch confidential MPT - independent");
1582 Env env{*
this, features};
1588 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1596 auto const bobSeq = env.seq(bob);
1597 auto const carolSeq = env.seq(carol);
1598 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 3);
1600 auto const jv1 = mpt.sendJV({.account = bob, .dest = dave, .amt = 10}, bobSeq + 1);
1603 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 300}, carolSeq);
1604 auto const jv3 = mpt.sendJV({.account = carol, .dest = dave, .amt = 5}, carolSeq + 1);
1606 env(batch::outer(bob, bobSeq, batchFee, tfIndependent),
1607 batch::Inner(jv1, bobSeq + 1),
1608 batch::Inner(jv2, carolSeq),
1609 batch::Inner(jv3, carolSeq + 1),
1615 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 90);
1617 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 55);
1619 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 15);
1631 testcase(
"Batch confidential MPT with tickets");
1637 Env env{*
this, features};
1643 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1648 env(ticket::create(bob, 1));
1651 auto const bobSeq = env.seq(bob);
1653 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1657 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 40}, bobSeq);
1658 auto const chain1 = mpt.chainAfterSend(bob, 40, jv1);
1660 mpt.sendJV({.account = bob, .dest = dave, .amt = 20}, bobSeq + 1, chain1);
1662 env(batch::outer(bob, 0, batchFee, tfAllOrNothing),
1663 batch::Inner(jv1, bobSeq),
1664 batch::Inner(jv2, bobSeq + 1),
1665 ticket::Use(outerTicketSeq),
1670 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 40);
1671 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 40);
1672 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 20);
1679 Env env{*
this, features};
1685 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1691 env(ticket::create(bob, 2));
1694 auto const bobSeq = env.seq(bob);
1695 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1698 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 40}, ticketSeq1);
1700 auto const chain1 = mpt.chainAfterSend(bob, 40, jv1);
1702 mpt.sendJV({.account = bob, .dest = dave, .amt = 30}, ticketSeq2, chain1);
1704 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1705 batch::Inner(jv1, 0, ticketSeq1),
1706 batch::Inner(jv2, 0, ticketSeq2),
1711 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 30);
1712 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 40);
1713 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 30);
1718 Env env{*
this, features};
1724 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
1728 env(ticket::create(bob, 1));
1731 auto const bobSeq = env.seq(bob);
1732 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
1735 auto const badJV = mpt.sendJV({.account = bob, .dest = carol, .amt = 40}, bobSeq + 1);
1736 auto const jv2 = mpt.mergeInboxJV({.account = bob});
1738 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
1739 batch::Inner(badJV, 0, ticketSeq),
1740 batch::Inner(jv2, bobSeq + 1),
1744 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
1745 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
1755 testcase(
"Confidential transfers through delegation");
1758 Env env{*
this, features};
1764 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
1765 env.fund(XRP(10000), dave);
1770 .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback |
1771 tfMPTCanHoldConfidentialBalance,
1773 mptAlice.authorize({.account = bob});
1774 mptAlice.authorize({.account = carol});
1775 mptAlice.pay(alice, bob, 200);
1776 mptAlice.pay(alice, carol, 100);
1778 mptAlice.generateKeyPair(alice);
1779 mptAlice.generateKeyPair(bob);
1780 mptAlice.generateKeyPair(carol);
1781 mptAlice.set({.issuerPubKey = mptAlice.getPubKey(alice)});
1785 env(delegate::set(bob, dave, {
"ConfidentialMPTConvert"}), Ter(
temMALFORMED));
1789 env(delegate::set(bob, dave, {
"ConfidentialMPTMergeInbox"}));
1797 .holderPubKey = mptAlice.getPubKey(bob),
1806 .holderPubKey = mptAlice.getPubKey(bob),
1808 env.require(MptBalance(mptAlice, bob, 100));
1811 mptAlice.convert({.account = bob, .amt = 50});
1814 mptAlice.mergeInbox({.account = bob, .delegate = dave});
1820 .holderPubKey = mptAlice.getPubKey(carol),
1822 mptAlice.mergeInbox({.account = carol});
1834 env(delegate::set(bob, dave, {
"ConfidentialMPTMergeInbox",
"ConfidentialMPTSend"}));
1838 mptAlice.send({.account = bob, .dest = carol, .amt = 10, .delegate = dave});
1839 mptAlice.mergeInbox({.account = carol});
1842 mptAlice.convertBack(
1849 {
"ConfidentialMPTMergeInbox",
"ConfidentialMPTSend",
"ConfidentialMPTConvertBack"}));
1853 mptAlice.convertBack({.account = bob, .amt = 10, .delegate = dave});
1856 mptAlice.confidentialClaw(
1860 env(delegate::set(alice, dave, {
"ConfidentialMPTClawback"}));
1864 mptAlice.confidentialClaw({.holder = bob, .amt = 130, .delegate = dave});
1871 testcase(
"Confidential delegation revocation");
1874 Env env{*
this, features};
1879 MPTTester mptAlice(env, alice, {.holders = {bob}});
1880 env.fund(XRP(10000), carol);
1885 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
1887 mptAlice.authorize({.account = bob});
1888 mptAlice.pay(alice, bob, 100);
1890 mptAlice.generateKeyPair(alice);
1891 mptAlice.generateKeyPair(bob);
1892 mptAlice.set({.issuerPubKey = mptAlice.getPubKey(alice)});
1895 auto const bobOwnersBefore =
ownerCount(env, bob);
1896 env(delegate::set(bob, carol, {
"ConfidentialMPTMergeInbox"}));
1898 env.require(Owners(bob, bobOwnersBefore + 1));
1904 .holderPubKey = mptAlice.getPubKey(bob),
1906 mptAlice.mergeInbox({.account = bob, .delegate = carol});
1911 env.require(Owners(bob, bobOwnersBefore));
1914 mptAlice.convert({.account = bob, .amt = 30});
1917 mptAlice.mergeInbox({
1924 mptAlice.mergeInbox({.account = bob});
1932 testcase(
"Confidential delegation with auditor");
1935 Env env{*
this, features};
1940 Account const auditor{
"auditor"};
1942 MPTTester mptAlice(env, alice, {.holders = {bob, carol}, .auditor = auditor});
1943 env.fund(XRP(10000), dave);
1948 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance,
1950 mptAlice.authorize({.account = bob});
1951 mptAlice.authorize({.account = carol});
1952 mptAlice.pay(alice, bob, 100);
1953 mptAlice.pay(alice, carol, 100);
1955 mptAlice.generateKeyPair(alice);
1956 mptAlice.generateKeyPair(bob);
1957 mptAlice.generateKeyPair(carol);
1958 mptAlice.generateKeyPair(auditor);
1960 .issuerPubKey = mptAlice.getPubKey(alice),
1961 .auditorPubKey = mptAlice.getPubKey(auditor),
1965 env(delegate::set(bob, dave, {
"ConfidentialMPTSend"}));
1972 .holderPubKey = mptAlice.getPubKey(bob),
1974 mptAlice.mergeInbox({.account = bob});
1979 .holderPubKey = mptAlice.getPubKey(carol),
1981 mptAlice.mergeInbox({.account = carol});
1984 mptAlice.send({.account = bob, .dest = carol, .amt = 20, .delegate = dave});
1985 mptAlice.send({.account = bob, .dest = carol, .amt = 10, .delegate = dave});
1988 env(delegate::set(bob, auditor, {
"ConfidentialMPTSend",
"ConfidentialMPTConvertBack"}));
1992 mptAlice.send({.account = bob, .dest = carol, .amt = 10, .delegate = auditor});
1993 mptAlice.convertBack({.account = bob, .amt = 10, .delegate = auditor});
2058 testcase(
"Batch ConfidentialMPTSend with delegation");
2064 Env env{*
this, features};
2070 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2073 env(delegate::set(bob, dave, {
"ConfidentialMPTSend"}));
2076 auto const bobSeq = env.seq(bob);
2077 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
2080 auto jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 60}, bobSeq + 1);
2081 jv1[jss::Delegate] = dave.human();
2083 auto jv2 = mpt.sendJV({.account = bob, .dest = dave, .amt = 60}, bobSeq + 2);
2084 jv2[jss::Delegate] = dave.human();
2086 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
2087 batch::Inner(jv1, bobSeq + 1),
2088 batch::Inner(jv2, bobSeq + 2),
2094 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
2095 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
2096 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
2101 Env env{*
this, features};
2107 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2110 env(delegate::set(bob, dave, {
"ConfidentialMPTSend"}));
2113 auto const bobSeq = env.seq(bob);
2114 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
2117 auto jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 40}, bobSeq + 1);
2118 jv1[jss::Delegate] = dave.human();
2119 auto const chain1 = mpt.chainAfterSend(bob, 40, jv1);
2121 auto jv2 = mpt.sendJV({.account = bob, .dest = dave, .amt = 40}, bobSeq + 2, chain1);
2122 jv2[jss::Delegate] = dave.human();
2124 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
2125 batch::Inner(jv1, bobSeq + 1),
2126 batch::Inner(jv2, bobSeq + 2),
2132 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 20);
2133 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 40);
2134 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 40);
2142 testcase(
"Batch delegation missing permission");
2148 Env env{*
this, features};
2154 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2158 env(delegate::set(bob, dave, {
"ConfidentialMPTMergeInbox"}));
2161 auto const bobSeq = env.seq(bob);
2162 auto const carolSeq = env.seq(carol);
2163 auto const batchFee = batch::calcConfidentialBatchFee(env, 2, 2);
2166 auto const jv1 = mpt.sendJV({.account = carol, .dest = dave, .amt = 30}, carolSeq);
2168 auto jv2 = mpt.sendJV({.account = bob, .dest = carol, .amt = 50}, bobSeq + 1);
2169 jv2[jss::Delegate] = dave.human();
2171 env(batch::outer(bob, bobSeq, batchFee, tfAllOrNothing),
2172 batch::Inner(jv1, carolSeq),
2173 batch::Inner(jv2, bobSeq + 1),
2174 batch::Sig(carol, dave),
2180 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
2181 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 60);
2182 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
2188 Env env{*
this, features};
2194 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2198 auto const bobSeq = env.seq(bob);
2199 auto const carolSeq = env.seq(carol);
2200 auto const batchFee = batch::calcConfidentialBatchFee(env, 2, 2);
2202 auto jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 50}, bobSeq + 1);
2203 jv1[jss::Delegate] = dave.human();
2204 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 30}, carolSeq);
2206 env(batch::outer(bob, bobSeq, batchFee, tfIndependent),
2207 batch::Inner(jv1, bobSeq + 1),
2208 batch::Inner(jv2, carolSeq),
2209 batch::Sig(carol, dave),
2214 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
2215 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 30);
2216 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 30);
2224 testcase(
"Test batch delegated send with delegate as outer account");
2231 Env env{*
this, features};
2237 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2240 env(delegate::set(bob, dave, {
"ConfidentialMPTSend"}));
2243 auto const daveSeq = env.seq(dave);
2244 auto const bobSeq = env.seq(bob);
2245 auto const batchFee = batch::calcConfidentialBatchFee(env, 0, 2);
2247 auto jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 40}, bobSeq);
2248 jv1[jss::Delegate] = dave.human();
2249 auto const jv2 = mpt.mergeInboxJV({.account = dave});
2251 env(batch::outer(dave, daveSeq, batchFee, tfAllOrNothing),
2252 batch::Inner(jv1, bobSeq),
2253 batch::Inner(jv2, daveSeq + 1),
2257 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 60);
2258 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 40);
2264 Env env{*
this, features};
2270 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2273 env(delegate::set(bob, dave, {
"ConfidentialMPTSend"}));
2276 auto const daveSeq = env.seq(dave);
2277 auto const bobSeq = env.seq(bob);
2278 auto const batchFee = batch::calcConfidentialBatchFee(env, 1, 2);
2280 auto const jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 40}, bobSeq);
2281 auto const chain1 = mpt.chainAfterSend(bob, 40, jv1);
2282 auto jv2 = mpt.sendJV({.account = bob, .dest = carol, .amt = 30}, bobSeq + 1, chain1);
2283 jv2[jss::Delegate] = dave.human();
2286 env(batch::outer(dave, daveSeq, batchFee, tfAllOrNothing),
2287 batch::Inner(jv1, bobSeq),
2288 batch::Inner(jv2, bobSeq + 1),
2294 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 30);
2295 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 70);
2303 Env env{*
this, features};
2309 MPTTester mpt(env, alice, {.holders = {bob, carol, dave}});
2313 auto const daveSeq = env.seq(dave);
2314 auto const bobSeq = env.seq(bob);
2315 auto const carolSeq = env.seq(carol);
2316 auto const batchFee = batch::calcConfidentialBatchFee(env, 2, 2);
2318 auto jv1 = mpt.sendJV({.account = bob, .dest = carol, .amt = 50}, bobSeq);
2319 jv1[jss::Delegate] = dave.human();
2320 auto const jv2 = mpt.sendJV({.account = carol, .dest = dave, .amt = 30}, carolSeq);
2322 env(batch::outer(dave, daveSeq, batchFee, tfAllOrNothing),
2323 batch::Inner(jv1, bobSeq),
2324 batch::Inner(jv2, carolSeq),
2325 batch::Sig(bob, carol),
2330 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 100);
2331 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 60);
2332 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
2340 testcase(
"Batch delegated confidential multiple operations");
2343 Env env{*
this, features};
2351 MPTTester mpt(env, alice, {.holders = {bob, carol, dave, frank}});
2353 mpt.pay(alice, bob, 50);
2354 env.fund(XRP(10000), erin);
2357 mpt.authorize({.account = frank});
2358 mpt.pay(alice, frank, 40);
2359 mpt.generateKeyPair(frank);
2361 env(delegate::set(bob, dave, {
"ConfidentialMPTConvertBack"}));
2362 env(delegate::set(carol, erin, {
"ConfidentialMPTSend"}));
2363 env(delegate::set(bob, erin, {
"ConfidentialMPTMergeInbox"}));
2366 auto const daveSeq = env.seq(dave);
2367 auto const bobSeq = env.seq(bob);
2368 auto const carolSeq = env.seq(carol);
2369 auto const frankSeq = env.seq(frank);
2370 auto const batchFee = batch::calcConfidentialBatchFee(env, 4, 6);
2376 auto jv1 = mpt.convertBackJV({.account = bob, .amt = 30}, bobSeq);
2377 jv1[jss::Delegate] = dave.human();
2378 auto const jv2 = mpt.convertJV({.account = bob, .amt = 20}, bobSeq + 1);
2379 auto jv3 = mpt.sendJV({.account = carol, .dest = bob, .amt = 15}, carolSeq);
2380 jv3[jss::Delegate] = erin.human();
2381 auto const jv4 = mpt.convertJV(
2382 {.account = frank, .amt = 25, .holderPubKey = mpt.getPubKey(frank)}, frankSeq);
2383 auto const jv5 = mpt.mergeInboxJV({.account = frank});
2384 auto jv6 = mpt.mergeInboxJV({.account = bob});
2385 jv6[jss::Delegate] = erin.human();
2387 env(batch::outer(dave, daveSeq, batchFee, tfAllOrNothing),
2388 batch::Inner(jv1, bobSeq),
2389 batch::Inner(jv2, bobSeq + 1),
2390 batch::Inner(jv3, carolSeq),
2391 batch::Inner(jv4, frankSeq),
2392 batch::Inner(jv5, frankSeq + 1),
2393 batch::Inner(jv6, bobSeq + 2),
2394 batch::Sig(erin, frank, bob),
2398 env.require(MptBalance(mpt, bob, 60));
2399 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending) == 105);
2400 BEAST_EXPECT(mpt.getDecryptedBalance(bob, MPTTester::holderEncryptedInbox) == 0);
2401 env.require(MptBalance(mpt, carol, 0));
2402 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedSpending) == 45);
2403 BEAST_EXPECT(mpt.getDecryptedBalance(carol, MPTTester::holderEncryptedInbox) == 0);
2404 env.require(MptBalance(mpt, frank, 15));
2405 BEAST_EXPECT(mpt.getDecryptedBalance(frank, MPTTester::holderEncryptedSpending) == 25);
2406 BEAST_EXPECT(mpt.getDecryptedBalance(frank, MPTTester::holderEncryptedInbox) == 0);
2407 env.require(MptBalance(mpt, dave, 0));
2408 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedSpending) == 0);
2409 BEAST_EXPECT(mpt.getDecryptedBalance(dave, MPTTester::holderEncryptedInbox) == 0);
2410 auto const outstandingBalance = mpt.getIssuanceOutstandingBalance();
2411 BEAST_EXPECT(outstandingBalance && *outstandingBalance == 250);
2412 BEAST_EXPECT(mpt.getIssuanceConfidentialBalance() == 175);
2422 testcase(
"Invalid cases for delegation with tickets");
2425 Env env{*
this, features};
2429 MPTTester mptAlice(env, alice, {.holders = {bob}});
2430 env.fund(XRP(10000), carol);
2435 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance | tfMPTCanClawback,
2437 mptAlice.authorize({.account = bob});
2438 mptAlice.pay(alice, bob, 200);
2440 mptAlice.generateKeyPair(alice);
2441 mptAlice.generateKeyPair(bob);
2442 mptAlice.set({.issuerPubKey = mptAlice.getPubKey(alice)});
2445 mptAlice.convert({.account = bob, .amt = 100, .holderPubKey = mptAlice.getPubKey(bob)});
2446 mptAlice.mergeInbox({.account = bob});
2449 env(delegate::set(bob, carol, {
"ConfidentialMPTConvertBack"}));
2452 uint64_t
const amt = 10;
2457 mptAlice.getDecryptedBalance(bob, MPTTester::holderEncryptedSpending),
2458 "Missing spending balance.");
2460 mptAlice.getEncryptedBalance(bob, MPTTester::holderEncryptedSpending),
2461 "Missing encrypted spending balance.");
2462 auto const version = mptAlice.getMPTokenVersion(bob);
2464 auto const pc = mptAlice.getPedersenCommitment(spendingBalance, pcBf);
2468 return mptAlice.getConvertBackProof(
2473 .pedersenCommitment = pc,
2474 .amt = spendingBalance,
2475 .encryptedAmt = encSpending,
2476 .blindingFactor = pcBf,
2482 auto const ticketSeq = env.seq(bob) + 1;
2483 env(ticket::create(bob, 1));
2485 mptAlice.convertBack({
2488 .proof = proofForSeq(ticketSeq + 1),
2489 .pedersenCommitment = pc,
2491 .ticketSeq = ticketSeq,
2498 auto const ticketSeq = env.seq(bob) + 1;
2499 env(ticket::create(bob, 1));
2501 mptAlice.convertBack({
2504 .proof = proofForSeq(env.seq(bob)),
2505 .pedersenCommitment = pc,
2507 .ticketSeq = ticketSeq,
2514 mptAlice.convertBack({
2518 .ticketSeq = env.seq(bob) + 100,
2525 mptAlice.convertBack({
2537 auto const carolTicketSeq = env.seq(carol) + 1;
2538 env(ticket::create(carol, 1));
2540 mptAlice.convertBack({
2544 .ticketSeq = carolTicketSeq,
2552 auto const ticketSeq = env.seq(bob) + 1;
2553 env(ticket::create(bob, 1));
2556 mptAlice.convertBack({
2559 .proof = proofForSeq(ticketSeq),
2560 .pedersenCommitment = pc,
2570 auto const ticketSeq = env.seq(bob) + 1;
2571 env(ticket::create(bob, 1));
2573 mptAlice.convertBack({
2577 .ticketSeq = ticketSeq,
2588 testcase(
"Confidential delegation with tickets");
2591 Env env{*
this, features};
2596 MPTTester mptAlice(env, alice, {.holders = {bob, carol}});
2597 env.fund(XRP(10000), dave);
2602 .flags = tfMPTCanTransfer | tfMPTCanHoldConfidentialBalance | tfMPTCanClawback,
2604 mptAlice.authorize({.account = bob});
2605 mptAlice.authorize({.account = carol});
2606 mptAlice.pay(alice, bob, 200);
2607 mptAlice.pay(alice, carol, 100);
2609 mptAlice.generateKeyPair(alice);
2610 mptAlice.generateKeyPair(bob);
2611 mptAlice.generateKeyPair(carol);
2612 mptAlice.set({.issuerPubKey = mptAlice.getPubKey(alice)});
2618 {
"ConfidentialMPTMergeInbox",
"ConfidentialMPTSend",
"ConfidentialMPTConvertBack"}));
2620 env(delegate::set(alice, dave, {
"ConfidentialMPTClawback"}));
2624 auto ticketSeq = env.seq(bob) + 1;
2625 env(ticket::create(bob, 1));
2626 BEAST_EXPECT(env.seq(bob) != ticketSeq);
2630 .holderPubKey = mptAlice.getPubKey(bob),
2631 .ticketSeq = ticketSeq,
2633 env.require(MptBalance(mptAlice, bob, 100));
2636 ticketSeq = env.seq(bob) + 1;
2637 env(ticket::create(bob, 1));
2638 BEAST_EXPECT(env.seq(bob) != ticketSeq);
2639 mptAlice.mergeInbox({.account = bob, .delegate = dave, .ticketSeq = ticketSeq});
2645 .holderPubKey = mptAlice.getPubKey(carol),
2647 mptAlice.mergeInbox({.account = carol});
2650 ticketSeq = env.seq(bob) + 1;
2651 env(ticket::create(bob, 1));
2652 BEAST_EXPECT(env.seq(bob) != ticketSeq);
2658 .ticketSeq = ticketSeq,
2662 ticketSeq = env.seq(bob) + 1;
2663 env(ticket::create(bob, 1));
2664 BEAST_EXPECT(env.seq(bob) != ticketSeq);
2665 mptAlice.convertBack({
2669 .ticketSeq = ticketSeq,
2673 ticketSeq = env.seq(alice) + 1;
2674 env(ticket::create(alice, 1));
2675 BEAST_EXPECT(env.seq(alice) != ticketSeq);
2676 mptAlice.confidentialClaw({
2680 .ticketSeq = ticketSeq,