Support new STIs for sto_* HookAPI (#657)

This commit is contained in:
tequ
2026-02-20 06:03:26 +09:00
parent 8e1ae86ce2
commit 57c4e3c9cc
7 changed files with 502 additions and 49 deletions

View File

@@ -11722,6 +11722,186 @@ public:
// invoke the hook
env(pay(bob, alice, XRP(1)), M("test sto_validate"), fee(XRP(1)));
{
// test STIs
TestHook hook = wasm[R"[test.hook](
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
#define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t rollback (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t sto_validate(uint32_t, uint32_t);
extern int64_t otxn_param(uint32_t, uint32_t, uint32_t, uint32_t);
#define ASSERT(x)\
if (!(x))\
rollback((uint32_t)#x, sizeof(#x), __LINE__);
#define SBUF(x) (uint32_t)(x), sizeof(x)
uint8_t buf[1000];
int64_t hook(uint32_t reserved)
{
_g(1,1);
int64_t size = otxn_param(SBUF(buf), "V", 1);
int64_t result = sto_validate(buf, size);
accept(0,0,result);
}
)[test.hook]"];
for (auto feature : {
features - featureHookAPISerializedType240,
features | featureHookAPISerializedType240,
})
{
Env env{*this, feature};
env.fund(XRP(10000), alice, bob);
env.close();
auto hasEnabled = env.current()->rules().enabled(
featureHookAPISerializedType240);
// install the hook on alice
env(ripple::test::jtx::hook(
alice, {{hso(hook, overrideFlag)}}, 0),
M("set sto_validate"),
HSFEE);
env.close();
// invoke the hook
auto buildTx = [&](std::string value) {
auto payJv = pay(bob, alice, XRP(1));
Json::Value params{Json::arrayValue};
auto& param = params[0U][jss::HookParameter];
param[jss::HookParameterName] = strHex(std::string("V"));
param[jss::HookParameterValue] = value;
payJv[jss::HookParameters] = params;
return payJv;
};
auto testSTI = [&](std::string value, bool expectedResult) {
auto tx = buildTx(value);
env(tx, M("test STI"), fee(XRP(1)));
env.close();
auto const result = env.meta()
->getFieldArray(sfHookExecutions)[0]
.getFieldU64(sfHookReturnCode);
if (expectedResult)
BEAST_EXPECTS(result == 1, value);
else
BEAST_EXPECTS(result == 0, value);
};
// STI_UINT32
testSTI("2200000001", true);
// STI_UINT64
testSTI("301100000000000003E8", true);
// STI_UINT128
testSTI("4100000000000000000000000000000000", true);
// STI_UINT256
testSTI(
"5060000000000000000000000000000000000000000000000000000000"
"0000000000",
true);
// STI_AMOUNT
testSTI("614000000000000064", true);
testSTI(
"61D5038D7EA4C680000000000000000000000000005553440000000000"
"AE123A8556F3CF91154711376AFB0F894F832B3D",
true);
// STI_VL
testSTI("7504DEADBEEF", true);
// STI_ACCOUNT
testSTI("8114AE123A8556F3CF91154711376AFB0F894F832B3D", true);
// STI_NUMBER
// testSTI("000400000000000000000000000000000001", true);
// STI_OBJECT
testSTI("E05C22000000017504DEADBEEFE1", true);
// STI_ARRAY
testSTI(
"F05CE05B614000000000000064E1E05B61D5038D7EA4C6800000000000"
"00000000000000005553440000000000AE123A8556F3CF91154711376A"
"FB0F894F832B3DE1F1",
true);
// STI_UINT8
testSTI("00101003", true);
// STI_UINT160
testSTI("01110000000000000000000000000000000000000000", true);
// STI_PATHSET
testSTI(
"0112300000000000000000000000005553440000000000AE123A8556F3"
"CF91154711376AFB0F894F832B3D00",
hasEnabled);
testSTI(
"0112310A20B3C85F482532A9578DBB3950B85CA06594D1000000000000"
"00000000000042544300000000000A20B3C85F482532A9578DBB3950B8"
"5CA06594D13000000000000000000000000055534400000000000A20B3"
"C85F482532A9578DBB3950B85CA06594D1FF3157180C769B66D942EE69"
"E6DCC940CA48D82337AD00000000000000000000000042544300000000"
"0057180C769B66D942EE69E6DCC940CA48D82337AD1000000000000000"
"0000000000000000000000000030000000000000000000000000555344"
"00000000000A20B3C85F482532A9578DBB3950B85CA06594D100",
hasEnabled);
// STI_VECTOR256
testSTI(
"0013634000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000"
"00000000000000000000",
true);
// STI_UINT96
// testSTI("000400000000000000000000000000000001", true);
// STI_UINT192
// testSTI("000400000000000000000000000000000001", true);
// STI_UINT384
// testSTI("000400000000000000000000000000000001", true);
// STI_UINT512
// testSTI("000400000000000000000000000000000001", true);
// STI_ISSUE
testSTI(
"03180000000000000000000000005553440000000000AE123A8556F3CF"
"91154711376AFB0F894F832B3D",
hasEnabled);
testSTI(
"03180000000000000000000000000000000000000000", hasEnabled);
// STI_XCHAIN_BRIDGE
/// Native-Native
testSTI(
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
"000000000000000000000000000014AE123A8556F3CF91154711376AFB"
"0F894F832B3D0000000000000000000000000000000000000000",
hasEnabled);
/// IOU-Native
testSTI(
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
"0000000000005553440000000000AE123A8556F3CF91154711376AFB0F"
"894F832B3D14AE123A8556F3CF91154711376AFB0F894F832B3D000000"
"0000"
"000000000000000000000000000000",
hasEnabled);
/// Native-IOU
testSTI(
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
"0000000000005553440000000000AE123A8556F3CF91154711376AFB0F"
"894F832B3D14AE123A8556F3CF91154711376AFB0F894F832B3D000000"
"0000000000000000000000000000000000",
hasEnabled);
/// IOU-IOU
testSTI(
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
"0000000000005553440000000000AE123A8556F3CF91154711376AFB0F"
"894F832B3D14AE123A8556F3CF91154711376AFB0F894F832B3D000000"
"0000000000000000005553440000000000AE123A8556F3CF9115471137"
"6AFB0F894F832B3D",
hasEnabled);
// STI_CURRENCY
testSTI(
"011A0000000000000000000000005553440000000000", hasEnabled);
}
}
}
void