Skip to content

Commit

Permalink
fix no account
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Sep 22, 2024
1 parent 597e7fe commit 639f8b7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
60 changes: 59 additions & 1 deletion src/test/app/Batch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,64 @@ class Batch_test : public beast::unit_test::suite
}
}

void
testNoAccount(FeatureBitset features)
{
testcase("no account");

using namespace test::jtx;
using namespace std::literals;

test::jtx::Env env{*this, envconfig()};

auto const feeDrops = env.current()->fees().base;
auto const alice = Account("alice");
auto const bob = Account("bob");
env.fund(XRP(10000), alice);
env.close();
env.memoize(bob);

auto const preAlice = env.balance(alice);

// Tx 1
Json::Value tx1 = noop(bob);
tx1[sfSetFlag.fieldName] = asfAllowTrustLineClawback;

auto const ledSeq = env.current()->seq();
auto const seq = env.seq(alice);
auto const batchFee = ((1 + 2) * feeDrops) + feeDrops * 2;
env(batch::batch(alice, seq, batchFee, tfAllOrNothing),
batch::add(pay(alice, bob, XRP(1000)), alice, 1, seq),
batch::add(tx1, alice, 0, ledSeq),
batch::sig(bob));
env.close();

std::vector<TestBatchData> testCases = {{
{"tesSUCCESS",
"Payment",
"A2639F4AC0E57B007A8EEFAEDD00DBD608588A34ECB29A2A55139F0147AA7C9"
"9"},
{"tesSUCCESS",
"AccountSet",
"16515DD535232F8D9B5993539CBFB6DC49C0274B8DD18E0C7199BFE30511F0C"
"1"},
}};

Json::Value params;
params[jss::ledger_index] = env.current()->seq() - 1;
params[jss::transactions] = true;
params[jss::expand] = true;
auto const jrr = env.rpc("json", "ledger", to_string(params));
auto const txn = getTxByIndex(jrr, 3);
validateBatchTxns(txn[jss::metaData], 3, testCases);
validateBatchMeta(txn[jss::metaData], preAlice, seq);

BEAST_EXPECT(env.seq(alice) == 6);
BEAST_EXPECT(env.seq(bob) == 5);
BEAST_EXPECT(env.balance(alice) == preAlice - XRP(1000) - batchFee);
BEAST_EXPECT(env.balance(bob) == XRP(1000));
}

void
testAccountSet(FeatureBitset features)
{
Expand Down Expand Up @@ -1541,7 +1599,6 @@ class Batch_test : public beast::unit_test::suite
params[jss::transactions] = true;
params[jss::expand] = true;
auto const jrr = env.rpc("json", "ledger", to_string(params));
std::cout << jrr << std::endl;
auto const txn = getTxByIndex(jrr, 2);
validateBatchTxns(txn[jss::metaData], 3, testCases);
validateBatchMeta(txn[jss::metaData], preAlice, seq, 10, 10);
Expand Down Expand Up @@ -1572,6 +1629,7 @@ class Batch_test : public beast::unit_test::suite
testMultisign(features);
testMultisignMultiParty(features);
testSubmit(features);
testNoAccount(features);
testAccountSet(features);
testObjectCreateSequence(features);
testObjectCreateTicket(features);
Expand Down
18 changes: 7 additions & 11 deletions src/xrpld/app/tx/detail/Batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Batch::preflight(PreflightContext const& ctx)
return temINVALID;
}

auto const innerAccount = stx.getAccountID(sfAccount);
if (!stx.isFieldPresent(sfTransactionType))
{
JLOG(ctx.j.warn())
Expand All @@ -96,6 +95,7 @@ Batch::preflight(PreflightContext const& ctx)
return temINVALID_BATCH;
}

auto const innerAccount = stx.getAccountID(sfAccount);
if (stx.getFieldU16(sfTransactionType) == ttACCOUNT_DELETE &&
innerAccount == outerAccount)
{
Expand All @@ -107,6 +107,12 @@ Batch::preflight(PreflightContext const& ctx)

if (innerAccount != outerAccount)
{
if (!tx.isFieldPresent(sfBatchSigners))
{
JLOG(ctx.j.warn()) << "Batch: missing batch signers.";
return temBAD_SIGNER;
}

if (tx.getFieldArray(sfBatchSigners).end() ==
std::find_if(
tx.getFieldArray(sfBatchSigners).begin(),
Expand Down Expand Up @@ -146,16 +152,6 @@ Batch::preclaim(PreclaimContext const& ctx)
if (!ctx.view.rules().enabled(featureBatch))
return temDISABLED;

for (STObject txn : ctx.tx.getFieldArray(sfRawTransactions))
{
auto const innerAccount = txn.getAccountID(sfAccount);
auto const sle = ctx.view.read(keylet::account(innerAccount));
if (!sle)
{
JLOG(ctx.j.warn()) << "Batch: delay: inner account does not exist.";
return terNO_ACCOUNT;
}
}
return tesSUCCESS;
}

Expand Down
5 changes: 4 additions & 1 deletion src/xrpld/app/tx/detail/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,11 @@ Transactor::checkBatchSign(PreclaimContext const& ctx)

auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner)));
auto const sleAccount = ctx.view.read(keylet::account(idAccount));

// We dont need to check the regular key or multisign here
// because the account does not exist.
if (!sleAccount)
ret = terNO_ACCOUNT;
return tesSUCCESS;

ret = checkSingleSign(
idSigner, idAccount, sleAccount, ctx.view.rules(), ctx.j);
Expand Down

0 comments on commit 639f8b7

Please sign in to comment.