|
19 | 19 | #include <ripple/app/hook/Enum.h>
|
20 | 20 | #include <ripple/app/ledger/LedgerMaster.h>
|
21 | 21 | #include <ripple/app/tx/impl/SetHook.h>
|
| 22 | +#include <ripple/json/json_reader.h> |
| 23 | +#include <ripple/json/json_writer.h> |
22 | 24 | #include <ripple/protocol/TxFlags.h>
|
23 | 25 | #include <ripple/protocol/jss.h>
|
24 | 26 | #include <test/app/SetHook_wasm.h>
|
@@ -87,6 +89,147 @@ class SetHook_test : public beast::unit_test::suite
|
87 | 89 | // fee unit tests, the rest of the time we want to ignore it.
|
88 | 90 | #define HSFEE fee(100'000'000)
|
89 | 91 | #define M(m) memo(m, "", "")
|
| 92 | + |
| 93 | + std::unique_ptr<Config> |
| 94 | + makePageCapConfig( |
| 95 | + FeatureBitset features, |
| 96 | + uint32_t networkID, |
| 97 | + std::string fee, |
| 98 | + std::string a_res, |
| 99 | + std::string o_res, |
| 100 | + uint32_t ledgerID) |
| 101 | + { |
| 102 | + using namespace jtx; |
| 103 | + |
| 104 | + Json::Value jsonValue; |
| 105 | + Json::Reader reader; |
| 106 | + std::string base_genesis = R"json({ |
| 107 | + "ledger": { |
| 108 | + "accepted": true, |
| 109 | + "accountState": [ |
| 110 | + { |
| 111 | + "Account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", |
| 112 | + "Balance": "100000000000000000", |
| 113 | + "Flags": 0, |
| 114 | + "LedgerEntryType": "AccountRoot", |
| 115 | + "OwnerCount": 0, |
| 116 | + "PreviousTxnID": "A92EF82C3C68F771927E3892A2F708F12CBD492EF68A860F042E4053C8EC6C8D", |
| 117 | + "PreviousTxnLgrSeq": 0, |
| 118 | + "Sequence": 1, |
| 119 | + "index": "2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8" |
| 120 | + }, |
| 121 | + { |
| 122 | + "Amendments": [], |
| 123 | + "Flags": 0, |
| 124 | + "LedgerEntryType": "Amendments", |
| 125 | + "index": "7DB0788C020F02780A673DC74757F23823FA3014C1866E72CC4CD8B226CD6EF4" |
| 126 | + }, |
| 127 | + { |
| 128 | + "BaseFee": "A", |
| 129 | + "Flags": 0, |
| 130 | + "LedgerEntryType": "FeeSettings", |
| 131 | + "ReferenceFeeUnits": 10, |
| 132 | + "ReserveBase": 1000000, |
| 133 | + "ReserveIncrement": 200000, |
| 134 | + "XahauActivationLgrSeq": 0, |
| 135 | + "index": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A651" |
| 136 | + }, |
| 137 | + { |
| 138 | + "Flags": 0, |
| 139 | + "IndexNext": "40000", |
| 140 | + "IndexPrevious": "3fffe", |
| 141 | + "Indexes": [], |
| 142 | + "LedgerEntryType": "DirectoryNode", |
| 143 | + "Owner": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", |
| 144 | + "RootIndex": "EC1A88838E9ADA27E8ED583917C1530D2F48C3A3C93F50EDAD662D662E9BCC76", |
| 145 | + "index": "EC1A88838E9ADA27E8ED583917C1530D2F48C3A3C93F50EDAD662D662E9BCC76" |
| 146 | + }, |
| 147 | + { |
| 148 | + "Flags": 0, |
| 149 | + "IndexNext": "3fffe", |
| 150 | + "IndexPrevious": "3fffd", |
| 151 | + "Indexes": [], |
| 152 | + "LedgerEntryType": "DirectoryNode", |
| 153 | + "Owner": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", |
| 154 | + "RootIndex": "EC1A88838E9ADA27E8ED583917C1530D2F48C3A3C93F50EDAD662D662E9BCC76", |
| 155 | + "index": "4A5F3F9E6762A4F89FFCD385FF2309E1F7D1309321BFEEA61D5C9ACB768DB61B" |
| 156 | + }, |
| 157 | + { |
| 158 | + "Flags": 0, |
| 159 | + "Indexes": [], |
| 160 | + "LedgerEntryType": "DirectoryNode", |
| 161 | + "Owner": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", |
| 162 | + "RootIndex": "A33EC6BB85FB5674074C4A3A43373BB17645308F3EAE1933E3E35252162B217D", |
| 163 | + "index": "A33EC6BB85FB5674074C4A3A43373BB17645308F3EAE1933E3E35252162B217D" |
| 164 | + }, |
| 165 | + { |
| 166 | + "Account": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", |
| 167 | + "Balance": "99999899000000", |
| 168 | + "Flags": 8388608, |
| 169 | + "LedgerEntryType": "AccountRoot", |
| 170 | + "HookNamespaces": [ "0000000000000000000000000000000000000000000000000000000000000000" ], |
| 171 | + "HookStateCount": 8388576, |
| 172 | + "OwnerCount": 8388577, |
| 173 | + "PreviousTxnID": "A92EF82C3C68F771927E3892A2F708F12CBD492EF68A860F042E4053C8EC6C8D", |
| 174 | + "PreviousTxnLgrSeq": 0, |
| 175 | + "Sequence": 3, |
| 176 | + "index": "92FA6A9FC8EA6018D5D16532D7795C91BFB0831355BDFDA177E86C8BF997985F" |
| 177 | + } |
| 178 | + ], |
| 179 | + "account_hash": "5DF3A98772FB73E782B8740E87885C6BAD9BA486422E3626DEF968AD2CB2C514", |
| 180 | + "close_flags": 0, |
| 181 | + "close_time": 0, |
| 182 | + "close_time_human": "2000-Jan-01 00:00:00.000000", |
| 183 | + "close_time_resolution": 10, |
| 184 | + "closed": true, |
| 185 | + "hash": "56DA0940767AC2F17F0E384F04816002403D0756432B9D503DDA20128A2AAF11", |
| 186 | + "ledger_hash": "56DA0940767AC2F17F0E384F04816002403D0756432B9D503DDA20128A2AAF11", |
| 187 | + "ledger_index": "0", |
| 188 | + "parent_close_time": 0, |
| 189 | + "parent_hash": "56DA0940767AC2F17F0E384F04816002403D0756432B9D503DDA20128A2AAF11", |
| 190 | + "seqNum": "5", |
| 191 | + "totalCoins": "100000000000000000", |
| 192 | + "total_coins": "100000000000000000", |
| 193 | + "transaction_hash": "9A77D1D1A4B36DA77B9C4DC63FDEB8F821741D157802F9C42A6ED86003D8B4A0", |
| 194 | + "transactions": [] |
| 195 | + }, |
| 196 | + "ledger_current_index": 0, |
| 197 | + "status": "success", |
| 198 | + "validated": true |
| 199 | + })json"; |
| 200 | + reader.parse(base_genesis, jsonValue); |
| 201 | + |
| 202 | + foreachFeature(features, [&](uint256 const& feature) { |
| 203 | + std::string featureName = featureToName(feature); |
| 204 | + std::optional<uint256> featureHash = |
| 205 | + getRegisteredFeature(featureName); |
| 206 | + if (featureHash.has_value()) |
| 207 | + { |
| 208 | + std::string hashString = to_string(featureHash.value()); |
| 209 | + jsonValue["ledger"]["accountState"][1]["Amendments"].append( |
| 210 | + hashString); |
| 211 | + } |
| 212 | + }); |
| 213 | + |
| 214 | + jsonValue["ledger_current_index"] = ledgerID; |
| 215 | + jsonValue["ledger"]["ledger_index"] = to_string(ledgerID); |
| 216 | + jsonValue["ledger"]["seqNum"] = to_string(ledgerID); |
| 217 | + |
| 218 | + return envconfig([&](std::unique_ptr<Config> cfg) { |
| 219 | + cfg->NETWORK_ID = networkID; |
| 220 | + cfg->START_LEDGER = jsonValue.toStyledString(); |
| 221 | + cfg->START_UP = Config::LOAD_JSON; |
| 222 | + Section config; |
| 223 | + config.append( |
| 224 | + {"reference_fee = " + fee, |
| 225 | + "account_reserve = " + a_res, |
| 226 | + "owner_reserve = " + o_res}); |
| 227 | + auto setup = setup_FeeVote(config); |
| 228 | + cfg->FEES = setup; |
| 229 | + return cfg; |
| 230 | + }); |
| 231 | + } |
| 232 | + |
90 | 233 | void
|
91 | 234 | testHooksOwnerDir(FeatureBitset features)
|
92 | 235 | {
|
@@ -928,6 +1071,73 @@ class SetHook_test : public beast::unit_test::suite
|
928 | 1071 | }
|
929 | 1072 | }
|
930 | 1073 |
|
| 1074 | + void |
| 1075 | + testPageCap(FeatureBitset features) |
| 1076 | + { |
| 1077 | + testcase("Test page cap"); |
| 1078 | + |
| 1079 | + using namespace jtx; |
| 1080 | + |
| 1081 | + test::jtx::Env env{ |
| 1082 | + *this, |
| 1083 | + makePageCapConfig(features, 21337, "10", "1000000", "200000", 0), |
| 1084 | + features}; |
| 1085 | + |
| 1086 | + bool const hasFix = env.current()->rules().enabled(fixPageCap); |
| 1087 | + |
| 1088 | + auto const alice = Account{"alice"}; |
| 1089 | + env.memoize(alice); |
| 1090 | + |
| 1091 | + auto const bob = Account{"bob"}; |
| 1092 | + env.fund(XRP(10000000), bob); |
| 1093 | + |
| 1094 | + auto const preHookCount = (*env.le(alice))[sfHookStateCount]; |
| 1095 | + auto const preOwnerCount = (*env.le(alice))[sfOwnerCount]; |
| 1096 | + |
| 1097 | + std::string hook = |
| 1098 | + "0061736D01000000012A0660057F7F7F7F7F017E60027F7F017E60027F7F017F60" |
| 1099 | + "047F7F7F7F017E60037F7F7E017E60017F017E02520603656E7605747261636500" |
| 1100 | + "0003656E760C686F6F6B5F6163636F756E74000103656E76025F67000203656E76" |
| 1101 | + "057374617465000303656E760973746174655F736574000303656E760661636365" |
| 1102 | + "70740004030201050503010002062B077F0141B088040B7F004180080B7F0041A2" |
| 1103 | + "080B7F004180080B7F0041B088040B7F0041000B7F0041010B07080104686F6F6B" |
| 1104 | + "00060ABF830001BB830002017F017E230041D0006B220124002001200036024C41" |
| 1105 | + "900841114180084110410010001A200141306A2200411410011A4101410110021A" |
| 1106 | + "200141286A41082000411410031A2001200131002F200131002842388620013100" |
| 1107 | + "294230867C200131002A4228867C200131002B4220867C200131002C4218867C20" |
| 1108 | + "0131002D4210867C200131002E4208867C7C3703202001410036021C0340419280" |
| 1109 | + "80807841C90110021A200128021C41C8014E4504402001200134021C2001290320" |
| 1110 | + "42C8017E7C370310200141106A220041082000410810041A2001200128021C4101" |
| 1111 | + "6A36021C0C010B0B2001200129032042017C3703202001200141286A220036020C" |
| 1112 | + "200128020C200129032042388842FF01833C0000200128020C2001290320423088" |
| 1113 | + "42FF01833C0001200128020C200129032042288842FF01833C0002200128020C20" |
| 1114 | + "0129032042208842FF01833C0003200128020C200129032042188842FF01833C00" |
| 1115 | + "04200128020C200129032042108842FF01833C0005200128020C20012903204208" |
| 1116 | + "8842FF01833C0006200128020C200129032042FF01833C00072000410820014130" |
| 1117 | + "6A411410041A4180084110421C1005200141D0006A24000B0B2801004180080B21" |
| 1118 | + "426173652E633A2043616C6C65642E0022426173652E633A2043616C6C65642E2" |
| 1119 | + "2"; |
| 1120 | + |
| 1121 | + // install the hook on alice |
| 1122 | + env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0), |
| 1123 | + M("set fix_page_cap"), |
| 1124 | + HSFEE); |
| 1125 | + env.close(); |
| 1126 | + |
| 1127 | + env(invoke::invoke(alice), |
| 1128 | + M("test simple"), |
| 1129 | + fee(XRP(1)), |
| 1130 | + ter(tesSUCCESS)); |
| 1131 | + env.close(); |
| 1132 | + |
| 1133 | + BEAST_EXPECT( |
| 1134 | + (*env.le(alice))[sfHookStateCount] == hasFix ? preHookCount + 200 |
| 1135 | + : preHookCount + 64); |
| 1136 | + BEAST_EXPECT( |
| 1137 | + (*env.le(alice))[sfOwnerCount] == hasFix ? preHookCount + 202 |
| 1138 | + : preHookCount + 66); |
| 1139 | + } |
| 1140 | + |
931 | 1141 | void
|
932 | 1142 | testCreate(FeatureBitset features)
|
933 | 1143 | {
|
@@ -11761,6 +11971,7 @@ class SetHook_test : public beast::unit_test::suite
|
11761 | 11971 |
|
11762 | 11972 | testNSDelete(features);
|
11763 | 11973 | testNSDeletePartial(features);
|
| 11974 | + testPageCap(features); |
11764 | 11975 |
|
11765 | 11976 | testWasm(features);
|
11766 | 11977 | test_accept(features);
|
@@ -11862,6 +12073,8 @@ class SetHook_test : public beast::unit_test::suite
|
11862 | 12073 | testWithFeatures(sa - fixXahauV2);
|
11863 | 12074 | testWithFeatures(sa - fixXahauV1 - fixXahauV2);
|
11864 | 12075 | testWithFeatures(sa - fixXahauV1 - fixXahauV2 - fixNSDelete);
|
| 12076 | + testWithFeatures( |
| 12077 | + sa - fixXahauV1 - fixXahauV2 - fixNSDelete - fixPageCap); |
11865 | 12078 | }
|
11866 | 12079 |
|
11867 | 12080 | private:
|
|
0 commit comments