Miscellaneous refactors and updates (#5590)

- Added a new Invariant: `ValidPseudoAccounts` which checks that all pseudo-accounts behave consistently through creation and updates, and that no "real" accounts look like pseudo-accounts (which means they don't have a 0 sequence). 
- `to_short_string(base_uint)`. Like `to_string`, but only returns the first 8 characters. (Similar to how a git commit ID can be abbreviated.) Used as a wrapped sink to prefix most transaction-related messages. More can be added later.
- `XRPL_ASSERT_PARTS`. Convenience wrapper for `XRPL_ASSERT`, which takes the `function` and `description` as separate parameters.
- `SField::sMD_PseudoAccount`. Metadata option for `SField` definitions to indicate that the field, if set in an `AccountRoot` indicates that account is a pseudo-account. Removes the need for hard-coded field lists all over the place. Added the flag to `AMMID` and `VaultID`.
- Added functionality to `SField` ctor to detect both code and name collisions using asserts. And require all SFields to have a name
- Convenience type aliases `STLedgerEntry::const_pointer` and `STLedgerEntry::const_ref`. (`SLE` is an alias to `STLedgerEntry`.)
- Generalized `feeunit.h` (`TaggedFee`) into `unit.h` (`ValueUnit`) and added new "BIPS"-related tags for future use. Also refactored the type restrictions to use Concepts.
- Restructured `transactions.macro` to do two big things
	1. Include the `#include` directives for transactor header files directly in the macro file. Removes the need to update `applySteps.cpp` and the resulting conflicts.
	2. Added a `privileges` parameter to the `TRANSACTION` macro, which specifies some of the operations a transaction is allowed to do. These `privileges` are enforced by invariant checks. Again, removed the need to update scattered lists of transaction types in various checks.
- Unit tests:
	1.  Moved more helper functions into `TestHelpers.h` and `.cpp`. 
	2. Cleaned up the namespaces to prevent / mitigate random collisions and ambiguous symbols, particularly in unity builds.
	3. Generalized `Env::balance` to add support for `MPTIssue` and `Asset`.
	4. Added a set of helper classes to simplify `Env` transaction parameter classes: `JTxField`, `JTxFieldWrapper`, and a bunch of classes derived or aliased from it. For an example of how awesome it is, check the changes `src/test/jtx/escrow.h` for how much simpler the definitions are for `finish_time`, `cancel_time`, `condition`, and `fulfillment`. 
	5. Generalized several of the amount-related helper classes to understand `Asset`s.
     6. `env.balance` for an MPT issuer will return a negative number (or 0) for consistency with IOUs.
This commit is contained in:
Ed Hennis
2025-09-18 13:55:49 -04:00
committed by GitHub
parent bd834c87e0
commit 3cbdf818a7
65 changed files with 2148 additions and 1210 deletions

View File

@@ -3426,7 +3426,7 @@ struct EscrowToken_test : public beast::unit_test::suite
auto const preAliceMPT = env.balance(alice, MPT);
auto const preOutstanding = env.balance(gw, MPT);
auto const preEscrowed = issuerMPTEscrowed(env, MPT);
BEAST_EXPECT(preOutstanding == MPT(10'000));
BEAST_EXPECT(preOutstanding == MPT(-10'000));
BEAST_EXPECT(preEscrowed == 0);
env(escrow::create(alice, gw, MPT(1'000)),
@@ -3449,7 +3449,7 @@ struct EscrowToken_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(alice, MPT) == preAliceMPT - MPT(1'000));
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == 0);
BEAST_EXPECT(env.balance(gw, MPT) == preOutstanding - MPT(1'000));
BEAST_EXPECT(env.balance(gw, MPT) == preOutstanding + MPT(1'000));
BEAST_EXPECT(issuerMPTEscrowed(env, MPT) == preEscrowed);
}
}
@@ -3503,7 +3503,7 @@ struct EscrowToken_test : public beast::unit_test::suite
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == 125);
BEAST_EXPECT(issuerMPTEscrowed(env, MPT) == 125);
BEAST_EXPECT(env.balance(gw, MPT) == MPT(20'000));
BEAST_EXPECT(env.balance(gw, MPT) == MPT(-20'000));
// bob can finish escrow
env(escrow::finish(bob, alice, seq1),
@@ -3522,7 +3522,7 @@ struct EscrowToken_test : public beast::unit_test::suite
: MPT(20'000);
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == escrowedWithFix);
BEAST_EXPECT(issuerMPTEscrowed(env, MPT) == escrowedWithFix);
BEAST_EXPECT(env.balance(gw, MPT) == outstandingWithFix);
BEAST_EXPECT(env.balance(gw, MPT) == -outstandingWithFix);
}
// test locked rate: cancel
@@ -3567,7 +3567,7 @@ struct EscrowToken_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(alice, MPT) == preAlice);
BEAST_EXPECT(env.balance(bob, MPT) == preBob);
BEAST_EXPECT(env.balance(gw, MPT) == MPT(20'000));
BEAST_EXPECT(env.balance(gw, MPT) == MPT(-20'000));
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == 0);
BEAST_EXPECT(issuerMPTEscrowed(env, MPT) == 0);
}
@@ -3608,7 +3608,7 @@ struct EscrowToken_test : public beast::unit_test::suite
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == 125);
BEAST_EXPECT(issuerMPTEscrowed(env, MPT) == 125);
BEAST_EXPECT(env.balance(gw, MPT) == MPT(20'000));
BEAST_EXPECT(env.balance(gw, MPT) == MPT(-20'000));
// bob can finish escrow
env(escrow::finish(gw, alice, seq1),
@@ -3620,7 +3620,7 @@ struct EscrowToken_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(alice, MPT) == preAlice - delta);
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == 0);
BEAST_EXPECT(issuerMPTEscrowed(env, MPT) == 0);
BEAST_EXPECT(env.balance(gw, MPT) == MPT(19'875));
BEAST_EXPECT(env.balance(gw, MPT) == MPT(-19'875));
}
}
@@ -3826,7 +3826,7 @@ struct EscrowToken_test : public beast::unit_test::suite
BEAST_EXPECT(mptEscrowed(env, alice, MPT) == 10);
BEAST_EXPECT(env.balance(bob, MPT) == MPT(0));
BEAST_EXPECT(mptEscrowed(env, bob, MPT) == 0);
BEAST_EXPECT(env.balance(gw, MPT) == MPT(10));
BEAST_EXPECT(env.balance(gw, MPT) == MPT(-10));
mptGw.authorize({.account = bob, .flags = tfMPTUnauthorize});
mptGw.destroy(
{.id = mptGw.issuanceID(),