Add terADDRESS_COLLISION to AMMCreate::preclaim

This commit is contained in:
Bronek Kozicki
2025-03-28 21:02:52 +00:00
parent 1807b441ee
commit 124512eba9
2 changed files with 39 additions and 0 deletions

View File

@@ -7143,6 +7143,36 @@ private:
});
}
void
testFailedPseudoAccount()
{
testcase("Failed pseudo-account allocation");
using namespace test::jtx;
Env env{*this};
env.fund(XRP(30'000), gw, alice);
env.close();
env(trust(alice, gw["USD"](30'000), 0));
env(pay(gw, alice, USD(10'000)));
env.close();
STAmount amount = XRP(10'000);
STAmount amount2 = USD(10'000);
auto const keylet = keylet::amm(amount.issue(), amount2.issue());
for (int i = 0; i < 256; ++i)
{
AccountID const accountId =
ripple::pseudoAccountAddress(*env.current(), keylet.key);
env(pay(env.master.id(), accountId, XRP(1000)),
seq(autofill),
fee(autofill),
sig(autofill));
}
AMM ammAlice(env, alice, amount, amount2, ter(terADDRESS_COLLISION));
}
void
run() override
{
@@ -7198,6 +7228,7 @@ private:
testAMMDepositWithFrozenAssets(all - fixAMMv1_1 - featureAMMClawback);
testFixReserveCheckOnWithdrawal(all);
testFixReserveCheckOnWithdrawal(all - fixAMMv1_2);
testFailedPseudoAccount();
}
};

View File

@@ -183,6 +183,14 @@ AMMCreate::preclaim(PreclaimContext const& ctx)
return tecAMM_INVALID_TOKENS;
}
if (ctx.view.rules().enabled(featureSingleAssetVault))
{
if (auto const accountId = pseudoAccountAddress(
ctx.view, keylet::amm(amount.issue(), amount2.issue()).key);
accountId == beast::zero)
return terADDRESS_COLLISION;
}
// If featureAMMClawback is enabled, allow AMMCreate without checking
// if the issuer has clawback enabled
if (ctx.view.rules().enabled(featureAMMClawback))