From 0ef9db4d9aa619ccf45e46c271f0b367ab09a7a4 Mon Sep 17 00:00:00 2001 From: Pratik Mankawde Date: Thu, 30 Oct 2025 16:05:32 +0000 Subject: [PATCH] formatting changes Signed-off-by: Pratik Mankawde --- include/xrpl/protocol/IOUAmount.h | 6 +- src/test/app/AMM_test.cpp | 228 +++++++++++++----------------- 2 files changed, 102 insertions(+), 132 deletions(-) diff --git a/include/xrpl/protocol/IOUAmount.h b/include/xrpl/protocol/IOUAmount.h index 11175ba498..56403e941c 100644 --- a/include/xrpl/protocol/IOUAmount.h +++ b/include/xrpl/protocol/IOUAmount.h @@ -127,8 +127,7 @@ IOUAmount::operator=(beast::Zero) return *this; } -inline IOUAmount:: -operator Number() const +inline IOUAmount::operator Number() const { return Number{mantissa_, exponent_}; } @@ -158,8 +157,7 @@ IOUAmount::operator<(IOUAmount const& other) const return Number{*this} < Number{other}; } -inline IOUAmount:: -operator bool() const noexcept +inline IOUAmount::operator bool() const noexcept { return mantissa_ != 0; } diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index 4283aad201..8986733c87 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -1333,55 +1333,49 @@ private: // Equal deposit, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { - amm.deposit( - DepositArg{ - .tokens = IOUAmount{1, -12}, - .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{ + .tokens = IOUAmount{1, -12}, + .err = ter(tecAMM_INVALID_TOKENS)}); }); // Equal deposit limit, tokens rounded to 0 testAMM( [&](AMM& amm, Env& env) { - amm.deposit( - DepositArg{ - .asset1In = STAmount{USD, 1, -15}, - .asset2In = XRPAmount{1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{ + .asset1In = STAmount{USD, 1, -15}, + .asset2In = XRPAmount{1}, + .err = ter(tecAMM_INVALID_TOKENS)}); }, {.pool = {{USD(1'000'000), XRP(1'000'000)}}, .features = {features - fixAMMv1_3}}); testAMM([&](AMM& amm, Env& env) { - amm.deposit( - DepositArg{ - .asset1In = STAmount{USD, 1, -15}, - .asset2In = XRPAmount{1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{ + .asset1In = STAmount{USD, 1, -15}, + .asset2In = XRPAmount{1}, + .err = ter(tecAMM_INVALID_TOKENS)}); }); // Single deposit by asset, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { - amm.deposit( - DepositArg{ - .asset1In = STAmount{USD, 1, -15}, - .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{ + .asset1In = STAmount{USD, 1, -15}, + .err = ter(tecAMM_INVALID_TOKENS)}); }); // Single deposit by tokens, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { - amm.deposit( - DepositArg{ - .tokens = IOUAmount{1, -10}, - .asset1In = STAmount{USD, 1, -15}, - .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{ + .tokens = IOUAmount{1, -10}, + .asset1In = STAmount{USD, 1, -15}, + .err = ter(tecAMM_INVALID_TOKENS)}); }); // Single deposit with eprice, tokens rounded to 0 testAMM([&](AMM& amm, Env& env) { - amm.deposit( - DepositArg{ - .asset1In = STAmount{USD, 1, -15}, - .maxEP = STAmount{USD, 1, -1}, - .err = ter(tecAMM_INVALID_TOKENS)}); + amm.deposit(DepositArg{ + .asset1In = STAmount{USD, 1, -15}, + .maxEP = STAmount{USD, 1, -1}, + .err = ter(tecAMM_INVALID_TOKENS)}); }); } @@ -2254,20 +2248,17 @@ private: XRPAmount{1}, std::nullopt, ter(tecAMM_INVALID_TOKENS)); - ammAlice.withdraw( - WithdrawArg{ - .tokens = IOUAmount{1, -10}, - .err = ter(tecAMM_INVALID_TOKENS)}); - ammAlice.withdraw( - WithdrawArg{ - .asset1Out = STAmount{USD, 1, -15}, - .asset2Out = XRPAmount{1}, - .err = ter(tecAMM_INVALID_TOKENS)}); - ammAlice.withdraw( - WithdrawArg{ - .tokens = IOUAmount{1, -10}, - .asset1Out = STAmount{USD, 1, -15}, - .err = ter(tecAMM_INVALID_TOKENS)}); + ammAlice.withdraw(WithdrawArg{ + .tokens = IOUAmount{1, -10}, + .err = ter(tecAMM_INVALID_TOKENS)}); + ammAlice.withdraw(WithdrawArg{ + .asset1Out = STAmount{USD, 1, -15}, + .asset2Out = XRPAmount{1}, + .err = ter(tecAMM_INVALID_TOKENS)}); + ammAlice.withdraw(WithdrawArg{ + .tokens = IOUAmount{1, -10}, + .asset1Out = STAmount{USD, 1, -15}, + .err = ter(tecAMM_INVALID_TOKENS)}); }); } @@ -5887,10 +5878,9 @@ private: USD(1'000), ETH(1'000), amm->tokens())); } BEAST_EXPECT(expectHolding(env, bob, USD(2'100))); - q[i] = Quality( - Amounts{ - ETH(2'000) - env.balance(carol, ETH), - env.balance(bob, USD) - USD(2'000)}); + q[i] = Quality(Amounts{ + ETH(2'000) - env.balance(carol, ETH), + env.balance(bob, USD) - USD(2'000)}); } // CLOB is better quality than AMM BEAST_EXPECT(q[0] > q[1]); @@ -6061,10 +6051,9 @@ private: } } BEAST_EXPECT(expectHolding(env, bob, USD(2'100))); - q[i] = Quality( - Amounts{ - ETH(2'000) - env.balance(carol, ETH), - env.balance(bob, USD) - USD(2'000)}); + q[i] = Quality(Amounts{ + ETH(2'000) - env.balance(carol, ETH), + env.balance(bob, USD) - USD(2'000)}); } // AMM is better quality BEAST_EXPECT(q[1] > q[0]); @@ -6296,10 +6285,9 @@ private: }}})); } } - q[i] = Quality( - Amounts{ - ETH(2'000) - env.balance(carol, ETH), - env.balance(bob, USD) - USD(2'000)}); + q[i] = Quality(Amounts{ + ETH(2'000) - env.balance(carol, ETH), + env.balance(bob, USD) - USD(2'000)}); } BEAST_EXPECT(q[1] > q[0]); BEAST_EXPECT(q[2] > q[0] && q[2] < q[1]); @@ -6332,18 +6320,16 @@ private: {.tfee = tfee, .close = closeLedger}); amm.deposit(alice, USD(10), XRP(10)); amm.vote(VoteArg{.account = alice, .tfee = tfee, .err = ter(err1)}); - amm.withdraw( - WithdrawArg{ - .account = gw, .asset1Out = USD(1), .err = ter(err2)}); + amm.withdraw(WithdrawArg{ + .account = gw, .asset1Out = USD(1), .err = ter(err2)}); // with the amendment disabled and ledger not closed, // second vote succeeds if the first vote sets the trading fee // to non-zero; if the first vote sets the trading fee to >0 && // <9 then the second withdraw succeeds if the second vote sets // the trading fee so that the discounted fee is non-zero amm.vote(VoteArg{.account = alice, .tfee = 20, .err = ter(err3)}); - amm.withdraw( - WithdrawArg{ - .account = gw, .asset1Out = USD(2), .err = ter(err4)}); + amm.withdraw(WithdrawArg{ + .account = gw, .asset1Out = USD(2), .err = ter(err4)}); }; // ledger is closed after each transaction, vote/withdraw don't fail @@ -7466,25 +7452,22 @@ private: // Equal withdraw with a limit test([&](AMM& amm) { - amm.withdraw( - WithdrawArg{ - .account = alice, - .asset1Out = EUR(0.1), - .asset2Out = USD(0.1), - .err = err}); - amm.withdraw( - WithdrawArg{ - .account = alice, - .asset1Out = USD(0.1), - .asset2Out = EUR(0.1), - .err = err}); + amm.withdraw(WithdrawArg{ + .account = alice, + .asset1Out = EUR(0.1), + .asset2Out = USD(0.1), + .err = err}); + amm.withdraw(WithdrawArg{ + .account = alice, + .asset1Out = USD(0.1), + .asset2Out = EUR(0.1), + .err = err}); }); // Single withdraw test([&](AMM& amm) { - amm.withdraw( - WithdrawArg{ - .account = alice, .asset1Out = EUR(0.1), .err = err}); + amm.withdraw(WithdrawArg{ + .account = alice, .asset1Out = EUR(0.1), .err = err}); amm.withdraw(WithdrawArg{.account = alice, .asset1Out = USD(0.1)}); }); } @@ -7567,9 +7550,8 @@ private: [&](AMM& amm, Env& env) { auto const err = env.enabled(fixAMMv1_3) ? ter(tesSUCCESS) : ter(tecUNFUNDED_AMM); - amm.deposit( - DepositArg{ - .account = alice, .asset1In = amount, .err = err}); + amm.deposit(DepositArg{ + .account = alice, .asset1In = amount, .err = err}); }, tfee); test( @@ -7664,11 +7646,10 @@ private: STAmount const depositGBP{ GBP, UINT64_C(10'1234567890123456), -16}; - ammAlice.deposit( - DepositArg{ - .account = bob, - .asset1In = depositEuro, - .asset2In = depositGBP}); + ammAlice.deposit(DepositArg{ + .account = bob, + .asset1In = depositEuro, + .asset2In = depositGBP}); invariant(ammAlice, env, "dep2", false); }, {{GBP(30'000), EUR(30'000)}}, @@ -7693,11 +7674,10 @@ private: STAmount const depositEuro{EUR, 1, exponent}; STAmount const depositGBP{GBP, 1, exponent}; - ammAlice.deposit( - DepositArg{ - .account = bob, - .asset1In = depositEuro, - .asset2In = depositGBP}); + ammAlice.deposit(DepositArg{ + .account = bob, + .asset1In = depositEuro, + .asset2In = depositGBP}); invariant( ammAlice, env, @@ -7722,10 +7702,9 @@ private: Fund::Acct); env.close(); - ammAlice.deposit( - DepositArg{ - .account = bob, - .tokens = IOUAmount{10'1234567890123456, -16}}); + ammAlice.deposit(DepositArg{ + .account = bob, + .tokens = IOUAmount{10'1234567890123456, -16}}); invariant(ammAlice, env, "dep4", false); }, {{GBP(7'000), EUR(30'000)}}, @@ -7755,11 +7734,10 @@ private: Fund::Acct); env.close(); - ammAlice.deposit( - DepositArg{ - .account = bob, - .tokens = tokens, - .asset1In = STAmount{EUR, 1, 6}}); + ammAlice.deposit(DepositArg{ + .account = bob, + .tokens = tokens, + .asset1In = STAmount{EUR, 1, 6}}); invariant(ammAlice, env, "dep5", false); }, {{GBP(7'000), EUR(30'000)}}, @@ -7824,12 +7802,11 @@ private: // tfTwoAsset withdraw mode testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw( - WithdrawArg{ - .account = alice, - .asset1Out = STAmount{GBP, 3'500}, - .asset2Out = STAmount{EUR, 15'000}, - .flags = tfTwoAsset}); + ammAlice.withdraw(WithdrawArg{ + .account = alice, + .asset1Out = STAmount{GBP, 3'500}, + .asset2Out = STAmount{EUR, 15'000}, + .flags = tfTwoAsset}); invariant(ammAlice, env, "with3", false); }, {{GBP(7'000), EUR(30'000)}}, @@ -7844,11 +7821,10 @@ private: // errors testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw( - WithdrawArg{ - .account = alice, - .asset1Out = STAmount{GBP, 1'234}, - .flags = tfSingleAsset}); + ammAlice.withdraw(WithdrawArg{ + .account = alice, + .asset1Out = STAmount{GBP, 1'234}, + .flags = tfSingleAsset}); invariant(ammAlice, env, "with4", false); }, {{GBP(7'000), EUR(30'000)}}, @@ -7868,15 +7844,13 @@ private: Fund::Acct); env.close(); - ammAlice.deposit( - DepositArg{ - .account = bob, .asset1In = STAmount{GBP, 3'456}}); + ammAlice.deposit(DepositArg{ + .account = bob, .asset1In = STAmount{GBP, 3'456}}); - ammAlice.withdraw( - WithdrawArg{ - .account = bob, - .asset1Out = STAmount{GBP, 1'000}, - .flags = tfOneAssetWithdrawAll}); + ammAlice.withdraw(WithdrawArg{ + .account = bob, + .asset1Out = STAmount{GBP, 1'000}, + .flags = tfOneAssetWithdrawAll}); invariant(ammAlice, env, "with5", false); }, {{GBP(7'000), EUR(30'000)}}, @@ -7887,12 +7861,11 @@ private: // tfOneAssetLPToken mode testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw( - WithdrawArg{ - .account = alice, - .tokens = 1'000, - .asset1Out = STAmount{GBP, 100}, - .flags = tfOneAssetLPToken}); + ammAlice.withdraw(WithdrawArg{ + .account = alice, + .tokens = 1'000, + .asset1Out = STAmount{GBP, 100}, + .flags = tfOneAssetLPToken}); invariant(ammAlice, env, "with6", false); }, {{GBP(7'000), EUR(30'000)}}, @@ -7903,12 +7876,11 @@ private: // tfLimitLPToken mode testAMM( [&](AMM& ammAlice, Env& env) { - ammAlice.withdraw( - WithdrawArg{ - .account = alice, - .asset1Out = STAmount{GBP, 100}, - .maxEP = IOUAmount{2}, - .flags = tfLimitLPToken}); + ammAlice.withdraw(WithdrawArg{ + .account = alice, + .asset1Out = STAmount{GBP, 100}, + .maxEP = IOUAmount{2}, + .flags = tfLimitLPToken}); invariant(ammAlice, env, "with7", true); }, {{GBP(7'000), EUR(30'000)}},