diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e4544373..1642d6324 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ "C_Cpp.clang_format_path": ".clang-format", "C_Cpp.clang_format_fallbackStyle": "{ ColumnLimit: 0 }", "[cpp]":{ - "editor.wordBasedSuggestions": false, + "editor.wordBasedSuggestions": "off", "editor.suggest.insertMode": "replace", "editor.semanticHighlighting.enabled": true, "editor.tabSize": 4, diff --git a/Builds/CMake/deps/WasmEdge.cmake b/Builds/CMake/deps/WasmEdge.cmake index 75347354c..780cad1c6 100644 --- a/Builds/CMake/deps/WasmEdge.cmake +++ b/Builds/CMake/deps/WasmEdge.cmake @@ -1,9 +1,84 @@ -find_package(LLVM REQUIRED CONFIG) -message(STATUS "Found LLVM ") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") -add_library (wasmedge STATIC IMPORTED GLOBAL) -set_target_properties(wasmedge PROPERTIES IMPORTED_LOCATION ${WasmEdge_LIB}) -target_link_libraries (ripple_libs INTERFACE wasmedge) -add_library (NIH::WasmEdge ALIAS wasmedge) -message("WasmEdge DONE") +#[===================================================================[ + NIH dep: wasmedge: web assembly runtime for hooks. +#]===================================================================] +find_package(Curses) +if(CURSES_FOUND) + include_directories(${CURSES_INCLUDE_DIR}) + target_link_libraries(ripple_libs INTERFACE ${CURSES_LIBRARY}) +else() + message(WARNING "CURSES library not found... (only important for mac builds)") +endif() + + +find_package(LLVM REQUIRED CONFIG) +message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") +ExternalProject_Add (wasmedge_src + PREFIX ${nih_cache_path} + GIT_REPOSITORY https://github.com/WasmEdge/WasmEdge.git + GIT_TAG 0.11.2 + CMAKE_ARGS + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + $<$:-DCMAKE_VERBOSE_MAKEFILE=ON> + -DCMAKE_DEBUG_POSTFIX=_d + -DWASMEDGE_BUILD_SHARED_LIB=OFF + -DWASMEDGE_BUILD_STATIC_LIB=ON + -DWASMEDGE_BUILD_AOT_RUNTIME=ON + -DWASMEDGE_FORCE_DISABLE_LTO=ON + -DWASMEDGE_LINK_LLVM_STATIC=ON + -DWASMEDGE_LINK_TOOLS_STATIC=ON + -DWASMEDGE_BUILD_PLUGINS=OFF + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DLLVM_DIR=${LLVM_DIR} + -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR} + -DLLVM_ENABLE_TERMINFO=OFF + $<$>:-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}> + $<$: + "-DCMAKE_C_FLAGS=-GR -Gd -fp:precise -FS -MP -march=native" + "-DCMAKE_C_FLAGS_DEBUG=-MTd" + "-DCMAKE_C_FLAGS_RELEASE=-MT" + > + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_CONFIGURE ON + COMMAND + pwd + BUILD_COMMAND + ${CMAKE_COMMAND} + --build . + --config $ + $<$:--parallel ${ep_procs}> + TEST_COMMAND "" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS + /lib/api/libwasmedge.a +) +add_library (wasmedge STATIC IMPORTED GLOBAL) +ExternalProject_Get_Property (wasmedge_src BINARY_DIR) +ExternalProject_Get_Property (wasmedge_src SOURCE_DIR) +set (wasmedge_src_BINARY_DIR "${BINARY_DIR}") +add_dependencies (wasmedge wasmedge_src) +execute_process( + COMMAND + mkdir -p "${wasmedge_src_BINARY_DIR}/include/api" +) +set_target_properties (wasmedge PROPERTIES + IMPORTED_LOCATION_DEBUG + "${wasmedge_src_BINARY_DIR}/lib/api/libwasmedge.a" + IMPORTED_LOCATION_RELEASE + "${wasmedge_src_BINARY_DIR}/lib/api/libwasmedge.a" + INTERFACE_INCLUDE_DIRECTORIES + "${wasmedge_src_BINARY_DIR}/include/api/" +) +target_link_libraries (ripple_libs INTERFACE wasmedge) +#RH NOTE: some compilers / versions of some libraries need these, most don't + +find_library(XAR_LIBRARY NAMES xar) +if(XAR_LIBRARY) + target_link_libraries(ripple_libs INTERFACE ${XAR_LIBRARY}) +else() + message(WARNING "xar library not found... (only important for mac builds)") +endif() +add_library (NIH::WasmEdge ALIAS wasmedge) \ No newline at end of file diff --git a/src/ripple/beast/container/detail/aged_ordered_container.h b/src/ripple/beast/container/detail/aged_ordered_container.h index 23534a26b..10dca962b 100644 --- a/src/ripple/beast/container/detail/aged_ordered_container.h +++ b/src/ripple/beast/container/detail/aged_ordered_container.h @@ -145,111 +145,78 @@ private: }; // VFALCO TODO This should only be enabled for maps. - class pair_value_compare - : public beast::detail::empty_base_optimization -#ifdef _LIBCPP_VERSION - , - public std::binary_function -#endif + class pair_value_compare : public Compare { public: -#ifndef _LIBCPP_VERSION using first_argument = value_type; using second_argument = value_type; using result_type = bool; -#endif bool operator()(value_type const& lhs, value_type const& rhs) const { - return this->member()(lhs.first, rhs.first); + return Compare::operator()(lhs.first, rhs.first); } pair_value_compare() { } - pair_value_compare(pair_value_compare const& other) - : beast::detail::empty_base_optimization(other) + pair_value_compare(pair_value_compare const& other) : Compare(other) { } private: friend aged_ordered_container; - pair_value_compare(Compare const& compare) - : beast::detail::empty_base_optimization(compare) + pair_value_compare(Compare const& compare) : Compare(compare) { } }; // Compares value_type against element, used in insert_check // VFALCO TODO hoist to remove template argument dependencies - class KeyValueCompare - : public beast::detail::empty_base_optimization -#ifdef _LIBCPP_VERSION - , - public std::binary_function -#endif + class KeyValueCompare : public Compare { public: -#ifndef _LIBCPP_VERSION using first_argument = Key; using second_argument = element; using result_type = bool; -#endif KeyValueCompare() = default; - KeyValueCompare(Compare const& compare) - : beast::detail::empty_base_optimization(compare) + KeyValueCompare(Compare const& compare) : Compare(compare) { } - // VFALCO NOTE WE might want only to enable these overloads - // if Compare has is_transparent -#if 0 - template - bool operator() (K const& k, element const& e) const - { - return this->member() (k, extract (e.value)); - } - - template - bool operator() (element const& e, K const& k) const - { - return this->member() (extract (e.value), k); - } -#endif - bool operator()(Key const& k, element const& e) const { - return this->member()(k, extract(e.value)); + return Compare::operator()(k, extract(e.value)); } bool operator()(element const& e, Key const& k) const { - return this->member()(extract(e.value), k); + return Compare::operator()(extract(e.value), k); } bool operator()(element const& x, element const& y) const { - return this->member()(extract(x.value), extract(y.value)); + return Compare::operator()(extract(x.value), extract(y.value)); } Compare& compare() { - return beast::detail::empty_base_optimization::member(); + return *this; } Compare const& compare() const { - return beast::detail::empty_base_optimization::member(); + return *this; } }; diff --git a/src/ripple/beast/container/detail/aged_unordered_container.h b/src/ripple/beast/container/detail/aged_unordered_container.h index 920e6196b..fcdccd2a6 100644 --- a/src/ripple/beast/container/detail/aged_unordered_container.h +++ b/src/ripple/beast/container/detail/aged_unordered_container.h @@ -148,115 +148,84 @@ private: }; // VFALCO TODO hoist to remove template argument dependencies - class ValueHash : private beast::detail::empty_base_optimization -#ifdef _LIBCPP_VERSION - , - public std::unary_function -#endif + class ValueHash : public Hash { public: -#ifndef _LIBCPP_VERSION using argument_type = element; using result_type = size_t; -#endif ValueHash() { } - ValueHash(Hash const& h) - : beast::detail::empty_base_optimization(h) + ValueHash(Hash const& h) : Hash(h) { } std::size_t operator()(element const& e) const { - return this->member()(extract(e.value)); + return Hash::operator()(extract(e.value)); } Hash& hash_function() { - return this->member(); + return *this; } Hash const& hash_function() const { - return this->member(); + return *this; } }; // Compares value_type against element, used in find/insert_check // VFALCO TODO hoist to remove template argument dependencies - class KeyValueEqual - : private beast::detail::empty_base_optimization -#ifdef _LIBCPP_VERSION - , - public std::binary_function -#endif + class KeyValueEqual : public KeyEqual { public: -#ifndef _LIBCPP_VERSION using first_argument_type = Key; using second_argument_type = element; using result_type = bool; -#endif KeyValueEqual() { } - KeyValueEqual(KeyEqual const& keyEqual) - : beast::detail::empty_base_optimization(keyEqual) + KeyValueEqual(KeyEqual const& keyEqual) : KeyEqual(keyEqual) { } - // VFALCO NOTE WE might want only to enable these overloads - // if KeyEqual has is_transparent -#if 0 - template - bool operator() (K const& k, element const& e) const - { - return this->member() (k, extract (e.value)); - } - - template - bool operator() (element const& e, K const& k) const - { - return this->member() (extract (e.value), k); - } -#endif - bool operator()(Key const& k, element const& e) const { - return this->member()(k, extract(e.value)); + return KeyEqual::operator()(k, extract(e.value)); } bool operator()(element const& e, Key const& k) const { - return this->member()(extract(e.value), k); + return KeyEqual::operator()(extract(e.value), k); } bool operator()(element const& lhs, element const& rhs) const { - return this->member()(extract(lhs.value), extract(rhs.value)); + return KeyEqual::operator()(extract(lhs.value), extract(rhs.value)); } KeyEqual& key_eq() { - return this->member(); + return *this; } KeyEqual const& key_eq() const { - return this->member(); + return *this; } }; diff --git a/src/ripple/peerfinder/impl/Bootcache.h b/src/ripple/peerfinder/impl/Bootcache.h index eb6455879..b48f248ae 100644 --- a/src/ripple/peerfinder/impl/Bootcache.h +++ b/src/ripple/peerfinder/impl/Bootcache.h @@ -91,17 +91,10 @@ private: using value_type = map_type::value_type; struct Transform -#ifdef _LIBCPP_VERSION - : std::unary_function< - map_type::right_map::const_iterator::value_type const&, - beast::IP::Endpoint const&> -#endif { -#ifndef _LIBCPP_VERSION using first_argument_type = map_type::right_map::const_iterator::value_type const&; using result_type = beast::IP::Endpoint const&; -#endif explicit Transform() = default; diff --git a/src/ripple/peerfinder/impl/Livecache.h b/src/ripple/peerfinder/impl/Livecache.h index 12e2373fa..8ecd68e84 100644 --- a/src/ripple/peerfinder/impl/Livecache.h +++ b/src/ripple/peerfinder/impl/Livecache.h @@ -69,14 +69,9 @@ public: public: // Iterator transformation to extract the endpoint from Element struct Transform -#ifdef _LIBCPP_VERSION - : public std::unary_function -#endif { -#ifndef _LIBCPP_VERSION using first_argument = Element; using result_type = Endpoint; -#endif explicit Transform() = default; @@ -239,15 +234,9 @@ public: template struct Transform -#ifdef _LIBCPP_VERSION - : public std:: - unary_function> -#endif { -#ifndef _LIBCPP_VERSION using first_argument = typename lists_type::value_type; using result_type = Hop; -#endif explicit Transform() = default; diff --git a/src/ripple/protocol/SField.h b/src/ripple/protocol/SField.h index 1f9d15368..9acf72b59 100644 --- a/src/ripple/protocol/SField.h +++ b/src/ripple/protocol/SField.h @@ -594,6 +594,7 @@ extern SField const sfImportVLKey; extern SField const sfHookEmission; extern SField const sfMintURIToken; extern SField const sfAmountEntry; +extern SField const sfGenesisMint; // array of objects (common) // ARRAY/1 is reserved for end of array @@ -607,7 +608,6 @@ extern SField const sfAffectedNodes; extern SField const sfMemos; extern SField const sfNFTokens; extern SField const sfHooks; -extern SField const sfGenesisMint; // array of objects (uncommon) extern SField const sfMajorities; diff --git a/src/ripple/resource/impl/Tuning.h b/src/ripple/resource/impl/Tuning.h index b57d57348..b3862ec16 100644 --- a/src/ripple/resource/impl/Tuning.h +++ b/src/ripple/resource/impl/Tuning.h @@ -28,20 +28,17 @@ namespace Resource { /** Tunable constants. */ enum { // Balance at which a warning is issued - warningThreshold = 5000 + warningThreshold = 5000, // Balance at which the consumer is disconnected - , - dropThreshold = 15000 + dropThreshold = 15000, // The number of seconds in the exponential decay window // (This should be a power of two) - , - decayWindowSeconds = 32 + decayWindowSeconds = 32, // The minimum balance required in order to include a load source in gossip - , - minimumGossipBalance = 1000 + minimumGossipBalance = 1000, }; // The number of seconds until an inactive table item is removed diff --git a/src/ripple/shamap/impl/SHAMapInnerNode.cpp b/src/ripple/shamap/impl/SHAMapInnerNode.cpp index 6ea6f47eb..1cac616b0 100644 --- a/src/ripple/shamap/impl/SHAMapInnerNode.cpp +++ b/src/ripple/shamap/impl/SHAMapInnerNode.cpp @@ -398,7 +398,7 @@ SHAMapInnerNode::canonicalizeChild( void SHAMapInnerNode::invariants(bool is_root) const { - unsigned count = 0; + [[maybe_unused]] unsigned count = 0; auto [numAllocated, hashes, children] = hashesAndChildren_.getHashesAndChildren(); diff --git a/src/test/app/SetJSHook_test.cpp b/src/test/app/SetJSHook_test.cpp index d2e6ccf53..965fd5908 100644 --- a/src/test/app/SetJSHook_test.cpp +++ b/src/test/app/SetJSHook_test.cpp @@ -1503,532 +1503,240 @@ public: env.close(); } - void - test_emit(FeatureBitset features) - { - testcase("Test float_emit"); - using namespace jtx; - Env env{ - *this, envconfig(), features, nullptr, beast::severities::kWarning - // beast::severities::kTrace - }; + // void + // test_emit(FeatureBitset features) - auto const alice = Account{"alice"}; - auto const bob = Account{"bob"}; + void + test_otxn_field(FeatureBitset features) + { + testcase("Test otxn_field"); + using namespace jtx; + Env env{*this, features}; + + Account const alice{"alice"}; + Account const bob{"bob"}; env.fund(XRP(10000), alice); env.fund(XRP(10000), bob); - TestHook hook = wasm[R"[test.hook]( - #include - extern int32_t _g(uint32_t, uint32_t); - 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 emit (uint32_t, uint32_t, uint32_t, uint32_t); - extern int64_t etxn_reserve(uint32_t); - extern int64_t otxn_param(uint32_t, uint32_t, uint32_t, uint32_t); - extern int64_t hook_account(uint32_t, uint32_t); - extern int64_t otxn_field ( - uint32_t write_ptr, - uint32_t write_len, - uint32_t field_id - ); - #define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1) - #define OUT_OF_BOUNDS (-1) - #define ttPAYMENT 0 - #define tfCANONICAL 0x80000000UL - #define amAMOUNT 1U - #define amFEE 8U - #define atACCOUNT 1U - #define DOESNT_EXIST (-5) - #define atDESTINATION 3U - #define SBUF(x) (uint32_t)x,sizeof(x) + TestHook hook = jswasm[R"[test.hook]( + const INVALID_ARGUMENT = -7 + const sfAccount = 0x80001 - #define PREREQUISITE_NOT_MET -9 - #define ENCODE_DROPS_SIZE 9 - #define ENCODE_DROPS(buf_out, drops, amount_type ) \ - {\ - uint8_t uat = amount_type; \ - uint64_t udrops = drops; \ - buf_out[0] = 0x60U +(uat & 0x0FU ); \ - buf_out[1] = 0b01000000 + (( udrops >> 56 ) & 0b00111111 ); \ - buf_out[2] = (udrops >> 48) & 0xFFU; \ - buf_out[3] = (udrops >> 40) & 0xFFU; \ - buf_out[4] = (udrops >> 32) & 0xFFU; \ - buf_out[5] = (udrops >> 24) & 0xFFU; \ - buf_out[6] = (udrops >> 16) & 0xFFU; \ - buf_out[7] = (udrops >> 8) & 0xFFU; \ - buf_out[8] = (udrops >> 0) & 0xFFU; \ - buf_out += ENCODE_DROPS_SIZE; \ - } - - #define _06_XX_ENCODE_DROPS(buf_out, drops, amount_type )\ - ENCODE_DROPS(buf_out, drops, amount_type ); - - #define ENCODE_DROPS_AMOUNT(buf_out, drops )\ - ENCODE_DROPS(buf_out, drops, amAMOUNT ); - #define _06_01_ENCODE_DROPS_AMOUNT(buf_out, drops )\ - ENCODE_DROPS_AMOUNT(buf_out, drops ); - - #define ENCODE_DROPS_FEE(buf_out, drops )\ - ENCODE_DROPS(buf_out, drops, amFEE ); - #define _06_08_ENCODE_DROPS_FEE(buf_out, drops )\ - ENCODE_DROPS_FEE(buf_out, drops ); - - #define ENCODE_TT_SIZE 3 - #define ENCODE_TT(buf_out, tt )\ - {\ - uint8_t utt = tt;\ - buf_out[0] = 0x12U;\ - buf_out[1] =(utt >> 8 ) & 0xFFU;\ - buf_out[2] =(utt >> 0 ) & 0xFFU;\ - buf_out += ENCODE_TT_SIZE; \ - } - #define _01_02_ENCODE_TT(buf_out, tt)\ - ENCODE_TT(buf_out, tt); - - - #define ENCODE_ACCOUNT_SIZE 22 - #define ENCODE_ACCOUNT(buf_out, account_id, account_type)\ - {\ - uint8_t uat = account_type;\ - buf_out[0] = 0x80U + uat;\ - buf_out[1] = 0x14U;\ - *(uint64_t*)(buf_out + 2) = *(uint64_t*)(account_id + 0);\ - *(uint64_t*)(buf_out + 10) = *(uint64_t*)(account_id + 8);\ - *(uint32_t*)(buf_out + 18) = *(uint32_t*)(account_id + 16);\ - buf_out += ENCODE_ACCOUNT_SIZE;\ - } - #define _08_XX_ENCODE_ACCOUNT(buf_out, account_id, account_type)\ - ENCODE_ACCOUNT(buf_out, account_id, account_type); - - #define ENCODE_ACCOUNT_SRC_SIZE 22 - #define ENCODE_ACCOUNT_SRC(buf_out, account_id)\ - ENCODE_ACCOUNT(buf_out, account_id, atACCOUNT); - #define _08_01_ENCODE_ACCOUNT_SRC(buf_out, account_id)\ - ENCODE_ACCOUNT_SRC(buf_out, account_id); - - #define ENCODE_ACCOUNT_DST_SIZE 22 - #define ENCODE_ACCOUNT_DST(buf_out, account_id)\ - ENCODE_ACCOUNT(buf_out, account_id, atDESTINATION); - #define _08_03_ENCODE_ACCOUNT_DST(buf_out, account_id)\ - ENCODE_ACCOUNT_DST(buf_out, account_id); - - #define ENCODE_ACCOUNT_OWNER_SIZE 22 - #define ENCODE_ACCOUNT_OWNER(buf_out, account_id) \ - ENCODE_ACCOUNT(buf_out, account_id, atOWNER); - #define _08_02_ENCODE_ACCOUNT_OWNER(buf_out, account_id) \ - ENCODE_ACCOUNT_OWNER(buf_out, account_id); - - #define ENCODE_UINT32_COMMON_SIZE 5U - #define ENCODE_UINT32_COMMON(buf_out, i, field)\ - {\ - uint32_t ui = i; \ - uint8_t uf = field; \ - buf_out[0] = 0x20U +(uf & 0x0FU); \ - buf_out[1] =(ui >> 24 ) & 0xFFU; \ - buf_out[2] =(ui >> 16 ) & 0xFFU; \ - buf_out[3] =(ui >> 8 ) & 0xFFU; \ - buf_out[4] =(ui >> 0 ) & 0xFFU; \ - buf_out += ENCODE_UINT32_COMMON_SIZE; \ - } - #define _02_XX_ENCODE_UINT32_COMMON(buf_out, i, field)\ - ENCODE_UINT32_COMMON(buf_out, i, field)\ - - #define ENCODE_UINT32_UNCOMMON_SIZE 6U - #define ENCODE_UINT32_UNCOMMON(buf_out, i, field)\ - {\ - uint32_t ui = i; \ - uint8_t uf = field; \ - buf_out[0] = 0x20U; \ - buf_out[1] = uf; \ - buf_out[2] =(ui >> 24 ) & 0xFFU; \ - buf_out[3] =(ui >> 16 ) & 0xFFU; \ - buf_out[4] =(ui >> 8 ) & 0xFFU; \ - buf_out[5] =(ui >> 0 ) & 0xFFU; \ - buf_out += ENCODE_UINT32_UNCOMMON_SIZE; \ - } - #define _02_XX_ENCODE_UINT32_UNCOMMON(buf_out, i, field)\ - ENCODE_UINT32_UNCOMMON(buf_out, i, field)\ - - #define ENCODE_LLS_SIZE 6U - #define ENCODE_LLS(buf_out, lls )\ - ENCODE_UINT32_UNCOMMON(buf_out, lls, 0x1B ); - #define _02_27_ENCODE_LLS(buf_out, lls )\ - ENCODE_LLS(buf_out, lls ); - - #define ENCODE_FLS_SIZE 6U - #define ENCODE_FLS(buf_out, fls )\ - ENCODE_UINT32_UNCOMMON(buf_out, fls, 0x1A ); - #define _02_26_ENCODE_FLS(buf_out, fls )\ - ENCODE_FLS(buf_out, fls ); - - #define ENCODE_TAG_SRC_SIZE 5 - #define ENCODE_TAG_SRC(buf_out, tag )\ - ENCODE_UINT32_COMMON(buf_out, tag, 0x3U ); - #define _02_03_ENCODE_TAG_SRC(buf_out, tag )\ - ENCODE_TAG_SRC(buf_out, tag ); - - #define ENCODE_TAG_DST_SIZE 5 - #define ENCODE_TAG_DST(buf_out, tag )\ - ENCODE_UINT32_COMMON(buf_out, tag, 0xEU ); - #define _02_14_ENCODE_TAG_DST(buf_out, tag )\ - ENCODE_TAG_DST(buf_out, tag ); - - #define ENCODE_SEQUENCE_SIZE 5 - #define ENCODE_SEQUENCE(buf_out, sequence )\ - ENCODE_UINT32_COMMON(buf_out, sequence, 0x4U ); - #define _02_04_ENCODE_SEQUENCE(buf_out, sequence )\ - ENCODE_SEQUENCE(buf_out, sequence ); - - #define ENCODE_FLAGS_SIZE 5 - #define ENCODE_FLAGS(buf_out, tag )\ - ENCODE_UINT32_COMMON(buf_out, tag, 0x2U ); - #define _02_02_ENCODE_FLAGS(buf_out, tag )\ - ENCODE_FLAGS(buf_out, tag ); - - #define ENCODE_SIGNING_PUBKEY_SIZE 35 - #define ENCODE_SIGNING_PUBKEY(buf_out, pkey )\ - {\ - buf_out[0] = 0x73U;\ - buf_out[1] = 0x21U;\ - *(uint64_t*)(buf_out + 2) = *(uint64_t*)(pkey + 0);\ - *(uint64_t*)(buf_out + 10) = *(uint64_t*)(pkey + 8);\ - *(uint64_t*)(buf_out + 18) = *(uint64_t*)(pkey + 16);\ - *(uint64_t*)(buf_out + 26) = *(uint64_t*)(pkey + 24);\ - buf[34] = pkey[32];\ - buf_out += ENCODE_SIGNING_PUBKEY_SIZE;\ - } - - #define _07_03_ENCODE_SIGNING_PUBKEY(buf_out, pkey )\ - ENCODE_SIGNING_PUBKEY(buf_out, pkey ); - - #define ENCODE_SIGNING_PUBKEY_NULL_SIZE 35 - #define ENCODE_SIGNING_PUBKEY_NULL(buf_out )\ - {\ - buf_out[0] = 0x73U;\ - buf_out[1] = 0x21U;\ - *(uint64_t*)(buf_out+2) = 0;\ - *(uint64_t*)(buf_out+10) = 0;\ - *(uint64_t*)(buf_out+18) = 0;\ - *(uint64_t*)(buf_out+25) = 0;\ - buf_out += ENCODE_SIGNING_PUBKEY_NULL_SIZE;\ - } - - #define _07_03_ENCODE_SIGNING_PUBKEY_NULL(buf_out )\ - ENCODE_SIGNING_PUBKEY_NULL(buf_out ); - - extern int64_t etxn_fee_base ( - uint32_t read_ptr, - uint32_t read_len - ); - extern int64_t etxn_details ( - uint32_t write_ptr, - uint32_t write_len - ); - extern int64_t ledger_seq (void); - - #define PREPARE_PAYMENT_SIMPLE_SIZE 270U - #define PREPARE_PAYMENT_SIMPLE(buf_out_master, drops_amount_raw, to_address, dest_tag_raw, src_tag_raw)\ - {\ - uint8_t* buf_out = buf_out_master;\ - uint8_t acc[20];\ - uint64_t drops_amount = (drops_amount_raw);\ - uint32_t dest_tag = (dest_tag_raw);\ - uint32_t src_tag = (src_tag_raw);\ - uint32_t cls = (uint32_t)ledger_seq();\ - hook_account(SBUF(acc));\ - _01_02_ENCODE_TT (buf_out, ttPAYMENT ); /* uint16 | size 3 */ \ - _02_02_ENCODE_FLAGS (buf_out, tfCANONICAL ); /* uint32 | size 5 */ \ - _02_03_ENCODE_TAG_SRC (buf_out, src_tag ); /* uint32 | size 5 */ \ - _02_04_ENCODE_SEQUENCE (buf_out, 0 ); /* uint32 | size 5 */ \ - _02_14_ENCODE_TAG_DST (buf_out, dest_tag ); /* uint32 | size 5 */ \ - _02_26_ENCODE_FLS (buf_out, cls + 1 ); /* uint32 | size 6 */ \ - _02_27_ENCODE_LLS (buf_out, cls + 5 ); /* uint32 | size 6 */ \ - _06_01_ENCODE_DROPS_AMOUNT (buf_out, drops_amount ); /* amount | size 9 */ \ - uint8_t* fee_ptr = buf_out;\ - _06_08_ENCODE_DROPS_FEE (buf_out, 0 ); /* amount | size 9 */ \ - _07_03_ENCODE_SIGNING_PUBKEY_NULL (buf_out ); /* pk | size 35 */ \ - _08_01_ENCODE_ACCOUNT_SRC (buf_out, acc ); /* account | size 22 */ \ - _08_03_ENCODE_ACCOUNT_DST (buf_out, to_address ); /* account | size 22 */ \ - int64_t edlen = etxn_details((uint32_t)buf_out, PREPARE_PAYMENT_SIMPLE_SIZE); /* emitdet | size 1?? */ \ - int64_t fee = etxn_fee_base(buf_out_master, PREPARE_PAYMENT_SIMPLE_SIZE); \ - _06_08_ENCODE_DROPS_FEE (fee_ptr, fee ); \ - } - - #define UINT16_FROM_BUF(buf)\ - (((uint64_t)((buf)[0]) << 8U) +\ - ((uint64_t)((buf)[1]) << 0U)) - - #define BUFFER_EQUAL_32(buf1, buf2)\ - (\ - *(((uint64_t*)(buf1)) + 0) == *(((uint64_t*)(buf2)) + 0) &&\ - *(((uint64_t*)(buf1)) + 1) == *(((uint64_t*)(buf2)) + 1) &&\ - *(((uint64_t*)(buf1)) + 2) == *(((uint64_t*)(buf2)) + 2) &&\ - *(((uint64_t*)(buf1)) + 3) == *(((uint64_t*)(buf2)) + 3) &&\ - *(((uint64_t*)(buf1)) + 4) == *(((uint64_t*)(buf2)) + 4) &&\ - *(((uint64_t*)(buf1)) + 5) == *(((uint64_t*)(buf2)) + 5) &&\ - *(((uint64_t*)(buf1)) + 6) == *(((uint64_t*)(buf2)) + 6) &&\ - *(((uint64_t*)(buf1)) + 7) == *(((uint64_t*)(buf2)) + 7)) - - #define ASSERT(x)\ - if (!(x))\ - rollback((uint32_t)#x,sizeof(#x),__LINE__) - - #define sfDestination ((8U << 16U) + 3U) - - extern int64_t etxn_generation(void); - extern int64_t otxn_generation(void); - extern int64_t otxn_burden(void); - extern int64_t etxn_burden(void); - - int64_t cbak(uint32_t r) - { - // on callback we emit 2 more txns - uint8_t bob[20]; - ASSERT(otxn_field(SBUF(bob), sfDestination) == 20); - - ASSERT(otxn_generation() + 1 == etxn_generation()); - - ASSERT(etxn_burden() == PREREQUISITE_NOT_MET); - - ASSERT(etxn_reserve(2) == 2); - - ASSERT(otxn_burden() > 0); - ASSERT(etxn_burden() == otxn_burden() * 2); - - uint8_t tx[PREPARE_PAYMENT_SIMPLE_SIZE]; - PREPARE_PAYMENT_SIMPLE(tx, 1000, bob, 0, 0); - - uint8_t hash1[32]; - ASSERT(emit(SBUF(hash1), SBUF(tx)) == 32); - - ASSERT(etxn_details(tx + 132, 138) == 138); - uint8_t hash2[32]; - ASSERT(emit(SBUF(hash2), SBUF(tx)) == 32); - - ASSERT(!BUFFER_EQUAL_32(hash1, hash2)); - - return accept(0,0,0); - } - - int64_t hook(uint32_t r) - { - _g(1,1); - - etxn_reserve(1); - - // bounds checks - ASSERT(emit(1000000, 32, 0, 32) == OUT_OF_BOUNDS); - ASSERT(emit(0,1000000, 0, 32) == OUT_OF_BOUNDS); - ASSERT(emit(0,32, 1000000, 32) == OUT_OF_BOUNDS); - ASSERT(emit(0,32, 0, 1000000) == OUT_OF_BOUNDS); - - ASSERT(otxn_generation() == 0); - ASSERT(otxn_burden == 1); - - uint8_t bob[20]; - ASSERT(otxn_param(SBUF(bob), "bob", 3) == 20); - - uint8_t tx[PREPARE_PAYMENT_SIMPLE_SIZE]; - PREPARE_PAYMENT_SIMPLE(tx, 1000, bob, 0, 0); - - uint8_t hash[32]; - ASSERT(emit(SBUF(hash), SBUF(tx)) == 32); - - return accept(0,0,0); - } - )[test.hook]"]; - - env(ripple::test::jtx::hook(alice, {{hsov1(hook, 1, overrideFlag)}}, 0), - M("set emit"), - HSFEE); - env.close(); - - Json::Value invoke; - invoke[jss::TransactionType] = "Invoke"; - invoke[jss::Account] = alice.human(); - - Json::Value params{Json::arrayValue}; - params[0U][jss::HookParameter][jss::HookParameterName] = - strHex(std::string("bob")); - params[0U][jss::HookParameter][jss::HookParameterValue] = - strHex(bob.id()); - - invoke[jss::HookParameters] = params; - - env(invoke, M("test emit"), fee(XRP(1))); - - bool const fixV2 = env.current()->rules().enabled(fixXahauV2); - - std::optional emithash; - { - auto meta = env.meta(); // meta can close - - // ensure hook execution occured - BEAST_REQUIRE(meta); - BEAST_REQUIRE(meta->isFieldPresent(sfHookExecutions)); - - auto const hookEmissions = meta->getFieldArray(sfHookEmissions); - BEAST_EXPECT( - hookEmissions[0u].isFieldPresent(sfEmitNonce) == fixV2 ? true - : false); - BEAST_EXPECT( - hookEmissions[0u].getAccountID(sfHookAccount) == alice.id()); - - auto const hookExecutions = meta->getFieldArray(sfHookExecutions); - BEAST_REQUIRE(hookExecutions.size() == 1); - - // ensure there was one emitted txn - BEAST_EXPECT(hookExecutions[0].getFieldU16(sfHookEmitCount) == 1); - - BEAST_REQUIRE(meta->isFieldPresent(sfAffectedNodes)); - - BEAST_REQUIRE(meta->getFieldArray(sfAffectedNodes).size() == 3); - - for (auto const& node : meta->getFieldArray(sfAffectedNodes)) - { - SField const& metaType = node.getFName(); - uint16_t nodeType = node.getFieldU16(sfLedgerEntryType); - if (metaType == sfCreatedNode && nodeType == ltEMITTED_TXN) - { - BEAST_REQUIRE(node.isFieldPresent(sfNewFields)); - - auto const& nf = const_cast(node) - .getField(sfNewFields) - .downcast(); - - auto const& et = const_cast(nf) - .getField(sfEmittedTxn) - .downcast(); - - auto const& em = const_cast(et) - .getField(sfEmitDetails) - .downcast(); - - BEAST_EXPECT(em.getFieldU32(sfEmitGeneration) == 1); - BEAST_EXPECT(em.getFieldU64(sfEmitBurden) == 1); - - Blob txBlob = et.getSerializer().getData(); - auto const tx = std::make_unique( - Slice{txBlob.data(), txBlob.size()}); - emithash = tx->getTransactionID(); - - break; + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); } } - BEAST_REQUIRE(emithash); - BEAST_EXPECT( - emithash == hookEmissions[0u].getFieldH256(sfEmittedTxnID)); - } + const Hook = (arg) => { + ASSERT(otxn_field(sfAccount) == 20); + ASSERT(otxn_field(1) == INVALID_ARGUMENT); + + let acc2 = hook_account(); + ASSERT(acc2 == 20); - { - auto balbefore = env.balance(bob).value().xrp().drops(); + for (var i = 0; i < 20; ++i) + ASSERT(acc[i] == acc2[i]); - env.close(); - - auto const ledger = env.closed(); - - int txcount = 0; - for (auto& i : ledger->txs) - { - auto const& hash = i.first->getTransactionID(); - txcount++; - BEAST_EXPECT(hash == *emithash); + return accept("0", 0); } + )[test.hook]"]; - BEAST_EXPECT(txcount == 1); - - auto balafter = env.balance(bob).value().xrp().drops(); - - BEAST_EXPECT(balafter - balbefore == 1000); - - env.close(); - } - - uint64_t burden_expected = 2; - for (int j = 0; j < 7; ++j) - { - auto const ledger = env.closed(); - for (auto& i : ledger->txs) - { - auto const& em = const_cast(*(i.first)) - .getField(sfEmitDetails) - .downcast(); - BEAST_EXPECT(em.getFieldU64(sfEmitBurden) == burden_expected); - BEAST_EXPECT(em.getFieldU32(sfEmitGeneration) == j + 2); - BEAST_REQUIRE(i.second->isFieldPresent(sfHookExecutions)); - auto const hookExecutions = - i.second->getFieldArray(sfHookExecutions); - BEAST_EXPECT(hookExecutions.size() == 1); - BEAST_EXPECT( - hookExecutions[0].getFieldU64(sfHookReturnCode) == 0); - BEAST_EXPECT(hookExecutions[0].getFieldU8(sfHookResult) == 3); - BEAST_EXPECT( - hookExecutions[0].getFieldU16(sfHookEmitCount) == 2); - if (fixV2) - BEAST_EXPECT(hookExecutions[0].getFieldU32(sfFlags) == 2); - } - env.close(); - burden_expected *= 2U; - } - - { - auto const ledger = env.closed(); - int txcount = 0; - for (auto& i : ledger->txs) - { - txcount++; - auto const& em = const_cast(*(i.first)) - .getField(sfEmitDetails) - .downcast(); - BEAST_EXPECT(em.getFieldU64(sfEmitBurden) == 256); - BEAST_EXPECT(em.getFieldU32(sfEmitGeneration) == 9); - BEAST_REQUIRE(i.second->isFieldPresent(sfHookExecutions)); - auto const hookExecutions = - i.second->getFieldArray(sfHookExecutions); - BEAST_EXPECT(hookExecutions.size() == 1); - BEAST_EXPECT( - hookExecutions[0].getFieldU64(sfHookReturnCode) == - 283); // emission failure on first emit - if (fixV2) - BEAST_EXPECT(hookExecutions[0].getFieldU32(sfFlags) == 2); - } - BEAST_EXPECT(txcount == 256); - } - - // next close will lead to zero transactions + // install the hook on alice + env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0), + M("set otxn_field"), + HSFEE); env.close(); - { - auto const ledger = env.closed(); - int txcount = 0; - for ([[maybe_unused]] auto& i : ledger->txs) - txcount++; - BEAST_EXPECT(txcount == 0); - } + + // invoke the hook + env(pay(alice, bob, XRP(1)), M("test otxn_field"), fee(XRP(1))); + } + + void + test_hook_account(FeatureBitset features) + { + testcase("Test hook_account"); + using namespace jtx; + + auto const test = [&](Account alice) -> void { + Env env{*this, features}; + + // Env env{*this, envconfig(), features, nullptr, + // beast::severities::kTrace + // }; + + auto const bob = Account{"bob"}; + env.fund(XRP(10000), alice); + env.fund(XRP(10000), bob); + + TestHook hook = {0x43U, 0x0bU, 0x0cU, 0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U, + 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, + 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x31U, 0x2dU, 0x67U, + 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU, + 0x64U, 0x65U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, + 0x6bU, 0x06U, 0x61U, 0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U, + 0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU, + 0x75U, 0x6eU, 0x74U, 0x0aU, 0x74U, 0x72U, 0x61U, 0x63U, 0x65U, 0x0cU, + 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, + 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x32U, 0x01U, + 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, + 0x80U, 0x3fU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0xc2U, + 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, 0x00U, + 0x00U, 0xc2U, 0x01U, 0x4dU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe4U, + 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xcaU, 0x03U, 0x01U, 0x07U, 0x3dU, + 0x00U, 0x0cU, 0x0cU, 0x00U, 0x0cU, 0x0eU, 0x0cU, 0x02U, 0x06U, 0x00U, + 0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U, 0xccU, + 0x03U, 0x00U, 0x01U, 0x00U, 0xceU, 0x03U, 0x00U, 0x01U, 0x00U, 0xd3U, + 0x97U, 0xecU, 0x12U, 0x38U, 0xe8U, 0x00U, 0x00U, 0x00U, 0xd3U, 0x42U, + 0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U, 0x0eU, + 0x29U, 0xcaU, 0x03U, 0x02U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU, 0x02U, + 0x06U, 0x00U, 0x00U, 0x01U, 0x01U, 0x01U, 0x04U, 0x00U, 0x00U, 0x34U, + 0x02U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd4U, 0x03U, 0x01U, 0x00U, + 0x20U, 0x61U, 0x00U, 0x00U, 0x38U, 0xebU, 0x00U, 0x00U, 0x00U, 0xf0U, + 0xcbU, 0x38U, 0xecU, 0x00U, 0x00U, 0x00U, 0x04U, 0xeaU, 0x00U, 0x00U, + 0x00U, 0x62U, 0x00U, 0x00U, 0x09U, 0xf3U, 0x0eU, 0x38U, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xebU, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xedU, 0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xb7U, + 0x23U, 0x02U, 0x00U, 0xcaU, 0x03U, 0x08U, 0x04U, 0x12U, 0x26U, 0x53U, + 0x49U}; + + // TestHook hook = jswasm[ + // R"[test.hook]( + // const ASSERT = (x, code) => { + // if (!x) { + // rollback(x.toString(), code); + // } + // } + + // const Hook = (arg) => { + // let acc2 = hook_account(); + // trace("acc2", acc2, false); + // ASSERT(acc2.length == 20); + // return accept(acc2, 0); + // } + // )[test.hook]"]; + + std::cout << "TEST: 1" << "\n"; + + // install the hook on alice + env(ripple::test::jtx::hook(alice, {{hsov1(hook, 1, overrideFlag)}}, 0), + M("set hook_account"), + HSFEE); + env.close(); + + std::cout << "TEST: 2" << "\n"; + + // invoke the hook + env(pay(bob, alice, XRP(1)), M("test hook_account"), fee(XRP(1))); + + std::cout << "TEST: 3" << "\n"; + { + auto meta = env.meta(); + + // ensure hook execution occured + BEAST_REQUIRE(meta); + BEAST_REQUIRE(meta->isFieldPresent(sfHookExecutions)); + + std::cout << "TEST: 3.1" << "\n"; + + // ensure there was only one hook execution + auto const hookExecutions = + meta->getFieldArray(sfHookExecutions); + BEAST_REQUIRE(hookExecutions.size() == 1); + + std::cout << "TEST: 3.2" << "\n"; + + // get the data in the return string of the extention + auto const retStr = + hookExecutions[0].getFieldVL(sfHookReturnString); + + std::cout << "TEST: 3.3" << "\n"; + + // check that it matches the account id + BEAST_EXPECT(retStr.size() == 20); + auto const a = alice.id(); + BEAST_EXPECT(memcmp(retStr.data(), a.data(), 20) == 0); + } + + std::cout << "TEST: 4" << "\n"; + + // install the same hook bob + env(ripple::test::jtx::hook(bob, {{hsov1(hook, 1, overrideFlag)}}, 0), + M("set hook_account 2"), + HSFEE); + env.close(); + + std::cout << "TEST: 5" << "\n"; + + // invoke the hook + env(pay(bob, alice, XRP(1)), M("test hook_account 2"), fee(XRP(1))); + + // there should be two hook executions, the first should be bob's + // address the second should be alice's + { + auto meta = env.meta(); + + // ensure hook execution occured + BEAST_REQUIRE(meta); + BEAST_REQUIRE(meta->isFieldPresent(sfHookExecutions)); + + // ensure there were two hook executions + auto const hookExecutions = + meta->getFieldArray(sfHookExecutions); + BEAST_REQUIRE(hookExecutions.size() == 2); + + { + // get the data in the return string of the extention + auto const retStr = + hookExecutions[0].getFieldVL(sfHookReturnString); + + // check that it matches the account id + BEAST_EXPECT(retStr.size() == 20); + auto const b = bob.id(); + BEAST_EXPECT(memcmp(retStr.data(), b.data(), 20) == 0); + } + + { + // get the data in the return string of the extention + auto const retStr = + hookExecutions[1].getFieldVL(sfHookReturnString); + + // check that it matches the account id + BEAST_EXPECT(retStr.size() == 20); + auto const a = alice.id(); + BEAST_EXPECT(memcmp(retStr.data(), a.data(), 20) == 0); + } + } + }; + + test(Account{"alice"}); + test(Account{"cho"}); } void testWithFeatures(FeatureBitset features) { - testHooksOwnerDir(features); - testHooksDisabled(features); - testTxStructure(features); - // testInferHookSetOperation(); // Not Version Specific - // testParams(features); // Not Version Specific - // testGrants(features); // Not Version Specific + // testHooksOwnerDir(features); + // testHooksDisabled(features); + // testTxStructure(features); + // // testInferHookSetOperation(); // Not Version Specific + // // testParams(features); // Not Version Specific + // // testGrants(features); // Not Version Specific - testInstall(features); - testDelete(features); - testNSDelete(features); - testCreate(features); - testUpdate(features); - testWithTickets(features); + // testInstall(features); + // testDelete(features); + // testNSDelete(features); + // testCreate(features); + // testUpdate(features); + // testWithTickets(features); - // DA TODO: illegalfunc_wasm - // testWasm(features); - test_accept(features); - test_rollback(features); + // // DA TODO: illegalfunc_wasm + // // testWasm(features); + // test_accept(features); + // test_rollback(features); + + // DA HERE // testGuards(features); // Not Used in JSHooks @@ -2064,7 +1772,7 @@ public: // test_float_sto_set(features); // // test_float_sum(features); // - // test_hook_account(features); // + test_hook_account(features); // // test_hook_again(features); // // test_hook_hash(features); // // test_hook_param(features); // @@ -2149,6 +1857,7 @@ private: TestHook illegalfunc_wasm = // WASM: 3 jswasm[ R"[test.hook]( + const Hook = (arg) => { console.log("HERE"); return accept(ret, 0); } diff --git a/src/test/app/SetJSHook_tmp_wasm.h b/src/test/app/SetJSHook_tmp_wasm.h new file mode 100644 index 000000000..868aefab4 --- /dev/null +++ b/src/test/app/SetJSHook_tmp_wasm.h @@ -0,0 +1,311 @@ + +// This file is generated by build_test_hooks.h +#ifndef SETHOOK_JSWASM_INCLUDED +#define SETHOOK_JSWASM_INCLUDED +#include +#include +#include +#include +namespace ripple { +namespace test { +std::map> jswasm = { + /* ==== WASM: 0 ==== */ + {R"[test.hook]( + const INVALID_ARGUMENT = -7 + const sfAccount = 0x80001 + + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); + } + } + + const Hook = (arg) => { + ASSERT(otxn_field(sfAccount) == 20); + ASSERT(otxn_field(1) == INVALID_ARGUMENT); + + let acc2 = hook_account(); + ASSERT(acc2 == 20); + + for (var i = 0; i < 20; ++i) + ASSERT(acc[i] == acc2[i]); + + return accept("0", 0); + } + )[test.hook]", + {0x43U, 0x0fU, 0x20U, 0x49U, 0x4eU, 0x56U, 0x41U, 0x4cU, 0x49U, 0x44U, + 0x5fU, 0x41U, 0x52U, 0x47U, 0x55U, 0x4dU, 0x45U, 0x4eU, 0x54U, 0x12U, + 0x73U, 0x66U, 0x41U, 0x63U, 0x63U, 0x6fU, 0x75U, 0x6eU, 0x74U, 0x0cU, + 0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U, 0x48U, 0x6fU, 0x6fU, + 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, + 0x65U, 0x73U, 0x74U, 0x2dU, 0x30U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, + 0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU, 0x64U, 0x65U, 0x10U, + 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, 0x6bU, 0x06U, 0x61U, + 0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U, 0x02U, 0x69U, 0x14U, + 0x6fU, 0x74U, 0x78U, 0x6eU, 0x5fU, 0x66U, 0x69U, 0x65U, 0x6cU, 0x64U, + 0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU, + 0x75U, 0x6eU, 0x74U, 0x06U, 0x61U, 0x63U, 0x63U, 0x0cU, 0x61U, 0x63U, + 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, + 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x5bU, 0x01U, 0xa4U, 0x01U, + 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, + 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, 0xe5U, 0x00U, 0x00U, 0x00U, + 0x80U, 0x3fU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, + 0xe5U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe6U, 0x00U, 0x00U, 0x00U, + 0x80U, 0xbfU, 0xf9U, 0x3aU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x01U, 0x01U, + 0x00U, 0x08U, 0x00U, 0x3aU, 0xe4U, 0x00U, 0x00U, 0x00U, 0xc2U, 0x00U, + 0x4dU, 0xe5U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe5U, 0x00U, 0x00U, 0x00U, + 0xc2U, 0x01U, 0x4dU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe6U, 0x00U, + 0x00U, 0x00U, 0xc7U, 0x28U, 0xceU, 0x03U, 0x01U, 0x09U, 0x79U, 0x7cU, + 0x26U, 0x00U, 0x0aU, 0x0cU, 0x00U, 0x0cU, 0x1aU, 0x0cU, 0x02U, 0x06U, + 0x00U, 0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U, + 0xd0U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U, + 0xd3U, 0x97U, 0xecU, 0x12U, 0x38U, 0xeaU, 0x00U, 0x00U, 0x00U, 0xd3U, + 0x42U, 0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U, + 0x0eU, 0x29U, 0xceU, 0x03U, 0x05U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU, + 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x02U, 0x01U, 0x04U, 0x00U, 0x01U, + 0x6bU, 0x03U, 0xd6U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd8U, 0x03U, 0x01U, + 0x00U, 0x20U, 0xdaU, 0x03U, 0x00U, 0x00U, 0x00U, 0x61U, 0x00U, 0x00U, + 0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeeU, 0x00U, 0x00U, 0x00U, + 0x38U, 0xe4U, 0x00U, 0x00U, 0x00U, 0xf1U, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeeU, 0x00U, 0x00U, + 0x00U, 0xb8U, 0xf1U, 0x38U, 0xe3U, 0x00U, 0x00U, 0x00U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xefU, 0x00U, 0x00U, 0x00U, 0xf0U, 0xcbU, 0x38U, 0xe5U, + 0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0xb7U, 0xccU, 0xc8U, 0xbfU, 0x14U, 0xa4U, 0xecU, 0x19U, 0x38U, + 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xf0U, 0x00U, 0x00U, 0x00U, 0xc8U, + 0x47U, 0x62U, 0x00U, 0x00U, 0xc8U, 0x47U, 0xaaU, 0xf1U, 0x0eU, 0x94U, + 0x01U, 0xeeU, 0xe3U, 0x38U, 0xf1U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, + 0xb7U, 0x23U, 0x02U, 0x00U, 0xceU, 0x03U, 0x0bU, 0x07U, 0x12U, 0x6cU, + 0x68U, 0x26U, 0x45U, 0x2bU, 0x7cU, 0x07U, 0x02U, 0x30U}}, + + /* ==== WASM: 1 ==== */ + {R"[test.hook]( + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); + } + } + + const Hook = (arg) => { + let acc2 = hook_account(); + trace("acc2", acc2, false); + ASSERT(acc2.length == 20); + return accept(acc2, 0); + } + )[test.hook]", + {0x43U, 0x0bU, 0x0cU, 0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U, + 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, + 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x31U, 0x2dU, 0x67U, + 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU, + 0x64U, 0x65U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, + 0x6bU, 0x06U, 0x61U, 0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U, + 0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU, + 0x75U, 0x6eU, 0x74U, 0x0aU, 0x74U, 0x72U, 0x61U, 0x63U, 0x65U, 0x0cU, + 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, + 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x32U, 0x01U, + 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, + 0x80U, 0x3fU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0xc2U, + 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, 0x00U, + 0x00U, 0xc2U, 0x01U, 0x4dU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe4U, + 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xcaU, 0x03U, 0x01U, 0x07U, 0x3dU, + 0x00U, 0x0cU, 0x0cU, 0x00U, 0x0cU, 0x0eU, 0x0cU, 0x02U, 0x06U, 0x00U, + 0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U, 0xccU, + 0x03U, 0x00U, 0x01U, 0x00U, 0xceU, 0x03U, 0x00U, 0x01U, 0x00U, 0xd3U, + 0x97U, 0xecU, 0x12U, 0x38U, 0xe8U, 0x00U, 0x00U, 0x00U, 0xd3U, 0x42U, + 0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U, 0x0eU, + 0x29U, 0xcaU, 0x03U, 0x02U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU, 0x02U, + 0x06U, 0x00U, 0x00U, 0x01U, 0x01U, 0x01U, 0x04U, 0x00U, 0x00U, 0x34U, + 0x02U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd4U, 0x03U, 0x01U, 0x00U, + 0x20U, 0x61U, 0x00U, 0x00U, 0x38U, 0xebU, 0x00U, 0x00U, 0x00U, 0xf0U, + 0xcbU, 0x38U, 0xecU, 0x00U, 0x00U, 0x00U, 0x04U, 0xeaU, 0x00U, 0x00U, + 0x00U, 0x62U, 0x00U, 0x00U, 0x09U, 0xf3U, 0x0eU, 0x38U, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xebU, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xedU, 0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xb7U, + 0x23U, 0x02U, 0x00U, 0xcaU, 0x03U, 0x08U, 0x04U, 0x12U, 0x26U, 0x53U, + 0x49U}}, + + /* ==== WASM: 2 ==== */ + {R"[test.hook]( + const Hook = (arg) => { + return accept("0", 0); + } + )[test.hook]", + {0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, + 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, + 0x32U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x72U, 0x67U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, + 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, + 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, + 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, 0x1fU, 0x00U, + 0x06U, 0x08U, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U, 0x01U, + 0x03U, 0x00U, 0x01U, 0x0bU, 0x01U, 0xcaU, 0x03U, 0x00U, 0x01U, 0x00U, + 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, 0xb7U, 0x23U, 0x02U, + 0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U, 0x30U}}, + + /* ==== WASM: 3 ==== */ + {R"[test.hook]( + const Hook = (arg) => { + return rollback("0", 0); + } + )[test.hook]", + {0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, + 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, + 0x33U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x72U, 0x67U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, + 0x6bU, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, + 0x01U, 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, + 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, + 0x00U, 0x80U, 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, + 0xe3U, 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, + 0x1fU, 0x00U, 0x06U, 0x08U, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, + 0x00U, 0x01U, 0x03U, 0x00U, 0x01U, 0x0bU, 0x01U, 0xcaU, 0x03U, 0x00U, + 0x01U, 0x00U, 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, 0xb7U, + 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U, + 0x30U}}, + + /* ==== WASM: 4 ==== */ + {R"[test.hook]( + const Hook = (arg) => { + console.log("HERE"); + return accept(ret, 0); + } + )[test.hook]", + {0x43U, 0x08U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, + 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, + 0x34U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x72U, 0x67U, 0x0eU, 0x63U, 0x6fU, 0x6eU, 0x73U, 0x6fU, 0x6cU, 0x65U, + 0x06U, 0x6cU, 0x6fU, 0x67U, 0x08U, 0x48U, 0x45U, 0x52U, 0x45U, 0x0cU, + 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x06U, 0x72U, 0x65U, 0x74U, + 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, + 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, + 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U, + 0x80U, 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, 0x1fU, + 0x00U, 0x06U, 0x0aU, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U, + 0x01U, 0x03U, 0x00U, 0x00U, 0x21U, 0x01U, 0xcaU, 0x03U, 0x00U, 0x01U, + 0x00U, 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0x42U, 0xe7U, 0x00U, 0x00U, + 0x00U, 0x04U, 0xe8U, 0x00U, 0x00U, 0x00U, 0x24U, 0x01U, 0x00U, 0x0eU, + 0x38U, 0xe9U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeaU, 0x00U, 0x00U, 0x00U, + 0xb7U, 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x02U, 0x03U, 0x62U}}, + + /* ==== WASM: 5 ==== */ + {R"[test.hook]( + const M_REPEAT_10 = (X) => X.repeat(10); + const M_REPEAT_100 = (X) => M_REPEAT_10(X).repeat(10); + const M_REPEAT_1000 = (X) => M_REPEAT_100(X).repeat(10); + const Hook = (arg) => { + const ret = M_REPEAT_1000("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz01234567890123"); + return accept(ret, 0); + } + )[test.hook]", + {0x43U, 0x0bU, 0x16U, 0x4dU, 0x5fU, 0x52U, 0x45U, 0x50U, 0x45U, 0x41U, + 0x54U, 0x5fU, 0x31U, 0x30U, 0x18U, 0x4dU, 0x5fU, 0x52U, 0x45U, 0x50U, + 0x45U, 0x41U, 0x54U, 0x5fU, 0x31U, 0x30U, 0x30U, 0x1aU, 0x4dU, 0x5fU, + 0x52U, 0x45U, 0x50U, 0x45U, 0x41U, 0x54U, 0x5fU, 0x31U, 0x30U, 0x30U, + 0x30U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, + 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x35U, + 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x58U, 0x0cU, + 0x72U, 0x65U, 0x70U, 0x65U, 0x61U, 0x74U, 0x06U, 0x61U, 0x72U, 0x67U, + 0x06U, 0x72U, 0x65U, 0x74U, 0x84U, 0x01U, 0x61U, 0x62U, 0x63U, 0x64U, + 0x65U, 0x66U, 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, + 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, 0x77U, 0x78U, + 0x79U, 0x7aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, 0x67U, 0x68U, + 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, 0x70U, 0x71U, 0x72U, + 0x73U, 0x74U, 0x75U, 0x76U, 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, + 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x30U, 0x31U, + 0x32U, 0x33U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, + 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, + 0x04U, 0x62U, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, + 0x3fU, 0xe5U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, 0xe6U, 0x00U, 0x00U, + 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, + 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe5U, 0x00U, 0x00U, 0x00U, 0x80U, + 0x3eU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x80U, 0xc2U, 0x00U, 0x4dU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, 0x00U, 0x00U, 0xc2U, 0x01U, + 0x4dU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe4U, 0x00U, 0x00U, 0x00U, + 0xc2U, 0x02U, 0x4dU, 0xe5U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe5U, 0x00U, + 0x00U, 0x00U, 0xc2U, 0x03U, 0x4dU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x3aU, + 0xe6U, 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xceU, 0x03U, 0x01U, 0x07U, + 0x79U, 0x7cU, 0x3fU, 0x3fU, 0x00U, 0x0cU, 0x08U, 0x0cU, 0x02U, 0x06U, + 0x00U, 0x00U, 0x01U, 0x00U, 0x01U, 0x03U, 0x00U, 0x00U, 0x0bU, 0x01U, + 0xd0U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd3U, 0x42U, 0xe9U, 0x00U, 0x00U, + 0x00U, 0xbfU, 0x0aU, 0x25U, 0x01U, 0x00U, 0xceU, 0x03U, 0x02U, 0x00U, + 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U, 0x01U, 0x03U, 0x00U, + 0x00U, 0x11U, 0x01U, 0xd0U, 0x03U, 0x00U, 0x01U, 0x00U, 0x38U, 0xe3U, + 0x00U, 0x00U, 0x00U, 0xd3U, 0xf1U, 0x42U, 0xe9U, 0x00U, 0x00U, 0x00U, + 0xbfU, 0x0aU, 0x25U, 0x01U, 0x00U, 0xceU, 0x03U, 0x03U, 0x00U, 0x0cU, + 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U, 0x01U, 0x03U, 0x00U, 0x00U, + 0x11U, 0x01U, 0xd0U, 0x03U, 0x00U, 0x01U, 0x00U, 0x38U, 0xe4U, 0x00U, + 0x00U, 0x00U, 0xd3U, 0xf1U, 0x42U, 0xe9U, 0x00U, 0x00U, 0x00U, 0xbfU, + 0x0aU, 0x25U, 0x01U, 0x00U, 0xceU, 0x03U, 0x04U, 0x00U, 0x0cU, 0x02U, + 0x06U, 0x00U, 0x00U, 0x01U, 0x01U, 0x01U, 0x03U, 0x00U, 0x00U, 0x1bU, + 0x02U, 0xd4U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd6U, 0x03U, 0x01U, 0x00U, + 0x30U, 0x61U, 0x00U, 0x00U, 0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x04U, + 0xecU, 0x00U, 0x00U, 0x00U, 0xf1U, 0xcbU, 0x38U, 0xedU, 0x00U, 0x00U, + 0x00U, 0x62U, 0x00U, 0x00U, 0xb7U, 0x23U, 0x02U, 0x00U, 0xceU, 0x03U, + 0x05U, 0x02U, 0x12U, 0x3fU}}, + + /* ==== WASM: 6 ==== */ + {R"[test.hook]( + const Hook = (arg) => { + const test_key = "0000000000000000000000000000000000000000000000006b657900"; + const test_value = "76616C756500"; + return accept("0", state_set(test_value, test_key)); + } + )[test.hook]", + {0x43U, 0x09U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, + 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, + 0x36U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x72U, 0x67U, 0x10U, 0x74U, 0x65U, 0x73U, 0x74U, 0x5fU, 0x6bU, 0x65U, + 0x79U, 0x14U, 0x74U, 0x65U, 0x73U, 0x74U, 0x5fU, 0x76U, 0x61U, 0x6cU, + 0x75U, 0x65U, 0x70U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x36U, 0x62U, 0x36U, 0x35U, 0x37U, 0x39U, 0x30U, 0x30U, 0x18U, + 0x37U, 0x36U, 0x36U, 0x31U, 0x36U, 0x43U, 0x37U, 0x35U, 0x36U, 0x35U, + 0x30U, 0x30U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x12U, + 0x73U, 0x74U, 0x61U, 0x74U, 0x65U, 0x5fU, 0x73U, 0x65U, 0x74U, 0x0cU, + 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, + 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, + 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, 0x1fU, 0x00U, + 0x06U, 0x0cU, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x02U, 0x01U, + 0x05U, 0x00U, 0x01U, 0x28U, 0x03U, 0xcaU, 0x03U, 0x00U, 0x01U, 0x00U, + 0xccU, 0x03U, 0x01U, 0x00U, 0x30U, 0xceU, 0x03U, 0x01U, 0x01U, 0x30U, + 0x61U, 0x01U, 0x00U, 0x61U, 0x00U, 0x00U, 0x04U, 0xe8U, 0x00U, 0x00U, + 0x00U, 0xcbU, 0x04U, 0xe9U, 0x00U, 0x00U, 0x00U, 0xccU, 0x38U, 0xeaU, + 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, 0x38U, 0xebU, 0x00U, 0x00U, 0x00U, + 0x62U, 0x01U, 0x00U, 0x62U, 0x00U, 0x00U, 0xf2U, 0x23U, 0x02U, 0x00U, + 0xc8U, 0x03U, 0x02U, 0x03U, 0x21U, 0x21U, 0x21U, 0x07U, 0x02U, 0x30U}}, + + /* ==== WASM: 7 ==== */ + {R"[test.hook]( + const Hook = (arg) => { + return accept("0", 2); + } + )[test.hook]", + {0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, + 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, + 0x37U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x72U, 0x67U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, + 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, + 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, + 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, 0x1fU, 0x00U, + 0x06U, 0x08U, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U, 0x01U, + 0x03U, 0x00U, 0x01U, 0x0bU, 0x01U, 0xcaU, 0x03U, 0x00U, 0x01U, 0x00U, + 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, 0xb9U, 0x23U, 0x02U, + 0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U, 0x30U}}, + +}; +} +} // namespace ripple +#endif diff --git a/src/test/app/SetJSHook_wasm.h b/src/test/app/SetJSHook_wasm.h index 5cd05f781..43df087db 100644 --- a/src/test/app/SetJSHook_wasm.h +++ b/src/test/app/SetJSHook_wasm.h @@ -10,6 +10,123 @@ namespace ripple { namespace test { std::map> jswasm = { /* ==== WASM: 0 ==== */ + {R"[test.hook]( + const INVALID_ARGUMENT = -7 + const sfAccount = 0x80001 + + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); + } + } + + const Hook = (arg) => { + ASSERT(otxn_field(sfAccount) == 20); + ASSERT(otxn_field(1) == INVALID_ARGUMENT); + + let acc2 = hook_account(); + ASSERT(acc2 == 20); + + for (var i = 0; i < 20; ++i) + ASSERT(acc[i] == acc2[i]); + + return accept("0", 0); + } + )[test.hook]", + {0x43U, 0x0fU, 0x20U, 0x49U, 0x4eU, 0x56U, 0x41U, 0x4cU, 0x49U, 0x44U, + 0x5fU, 0x41U, 0x52U, 0x47U, 0x55U, 0x4dU, 0x45U, 0x4eU, 0x54U, 0x12U, + 0x73U, 0x66U, 0x41U, 0x63U, 0x63U, 0x6fU, 0x75U, 0x6eU, 0x74U, 0x0cU, + 0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U, 0x48U, 0x6fU, 0x6fU, + 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, + 0x65U, 0x73U, 0x74U, 0x2dU, 0x30U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, + 0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU, 0x64U, 0x65U, 0x10U, + 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, 0x6bU, 0x06U, 0x61U, + 0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U, 0x02U, 0x69U, 0x14U, + 0x6fU, 0x74U, 0x78U, 0x6eU, 0x5fU, 0x66U, 0x69U, 0x65U, 0x6cU, 0x64U, + 0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU, + 0x75U, 0x6eU, 0x74U, 0x06U, 0x61U, 0x63U, 0x63U, 0x0cU, 0x61U, 0x63U, + 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, + 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x5bU, 0x01U, 0xa4U, 0x01U, + 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, + 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, 0xe5U, 0x00U, 0x00U, 0x00U, + 0x80U, 0x3fU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, + 0xe5U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe6U, 0x00U, 0x00U, 0x00U, + 0x80U, 0xbfU, 0xf9U, 0x3aU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x01U, 0x01U, + 0x00U, 0x08U, 0x00U, 0x3aU, 0xe4U, 0x00U, 0x00U, 0x00U, 0xc2U, 0x00U, + 0x4dU, 0xe5U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe5U, 0x00U, 0x00U, 0x00U, + 0xc2U, 0x01U, 0x4dU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe6U, 0x00U, + 0x00U, 0x00U, 0xc7U, 0x28U, 0xceU, 0x03U, 0x01U, 0x09U, 0x79U, 0x7cU, + 0x26U, 0x00U, 0x0aU, 0x0cU, 0x00U, 0x0cU, 0x1aU, 0x0cU, 0x02U, 0x06U, + 0x00U, 0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U, + 0xd0U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U, + 0xd3U, 0x97U, 0xecU, 0x12U, 0x38U, 0xeaU, 0x00U, 0x00U, 0x00U, 0xd3U, + 0x42U, 0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U, + 0x0eU, 0x29U, 0xceU, 0x03U, 0x05U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU, + 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x02U, 0x01U, 0x04U, 0x00U, 0x01U, + 0x6bU, 0x03U, 0xd6U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd8U, 0x03U, 0x01U, + 0x00U, 0x20U, 0xdaU, 0x03U, 0x00U, 0x00U, 0x00U, 0x61U, 0x00U, 0x00U, + 0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeeU, 0x00U, 0x00U, 0x00U, + 0x38U, 0xe4U, 0x00U, 0x00U, 0x00U, 0xf1U, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeeU, 0x00U, 0x00U, + 0x00U, 0xb8U, 0xf1U, 0x38U, 0xe3U, 0x00U, 0x00U, 0x00U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xefU, 0x00U, 0x00U, 0x00U, 0xf0U, 0xcbU, 0x38U, 0xe5U, + 0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0xb7U, 0xccU, 0xc8U, 0xbfU, 0x14U, 0xa4U, 0xecU, 0x19U, 0x38U, + 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xf0U, 0x00U, 0x00U, 0x00U, 0xc8U, + 0x47U, 0x62U, 0x00U, 0x00U, 0xc8U, 0x47U, 0xaaU, 0xf1U, 0x0eU, 0x94U, + 0x01U, 0xeeU, 0xe3U, 0x38U, 0xf1U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, + 0xb7U, 0x23U, 0x02U, 0x00U, 0xceU, 0x03U, 0x0bU, 0x07U, 0x12U, 0x6cU, + 0x68U, 0x26U, 0x45U, 0x2bU, 0x7cU, 0x07U, 0x02U, 0x30U}}, + + /* ==== WASM: 1 ==== */ + {R"[test.hook]( + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); + } + } + + const Hook = (arg) => { + let acc2 = hook_account(); + trace("acc2", acc2, false); + ASSERT(acc2.length == 20); + return accept(acc2, 0); + } + )[test.hook]", + {0x43U, 0x0bU, 0x0cU, 0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U, + 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, + 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x31U, 0x2dU, 0x67U, + 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU, + 0x64U, 0x65U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, + 0x6bU, 0x06U, 0x61U, 0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U, + 0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU, + 0x75U, 0x6eU, 0x74U, 0x0aU, 0x74U, 0x72U, 0x61U, 0x63U, 0x65U, 0x0cU, + 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, + 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x32U, 0x01U, + 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, + 0x80U, 0x3fU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0xc2U, + 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, 0x00U, + 0x00U, 0xc2U, 0x01U, 0x4dU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe4U, + 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xcaU, 0x03U, 0x01U, 0x07U, 0x3dU, + 0x00U, 0x0cU, 0x0cU, 0x00U, 0x0cU, 0x0eU, 0x0cU, 0x02U, 0x06U, 0x00U, + 0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U, 0xccU, + 0x03U, 0x00U, 0x01U, 0x00U, 0xceU, 0x03U, 0x00U, 0x01U, 0x00U, 0xd3U, + 0x97U, 0xecU, 0x12U, 0x38U, 0xe8U, 0x00U, 0x00U, 0x00U, 0xd3U, 0x42U, + 0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U, 0x0eU, + 0x29U, 0xcaU, 0x03U, 0x02U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU, 0x02U, + 0x06U, 0x00U, 0x00U, 0x01U, 0x01U, 0x01U, 0x04U, 0x00U, 0x00U, 0x34U, + 0x02U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd4U, 0x03U, 0x01U, 0x00U, + 0x20U, 0x61U, 0x00U, 0x00U, 0x38U, 0xebU, 0x00U, 0x00U, 0x00U, 0xf0U, + 0xcbU, 0x38U, 0xecU, 0x00U, 0x00U, 0x00U, 0x04U, 0xeaU, 0x00U, 0x00U, + 0x00U, 0x62U, 0x00U, 0x00U, 0x09U, 0xf3U, 0x0eU, 0x38U, 0xe3U, 0x00U, + 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xebU, 0xbfU, 0x14U, 0xaaU, 0xf1U, + 0x0eU, 0x38U, 0xedU, 0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xb7U, + 0x23U, 0x02U, 0x00U, 0xcaU, 0x03U, 0x08U, 0x04U, 0x12U, 0x26U, 0x53U, + 0x49U}}, + + /* ==== WASM: 1 ==== */ {R"[test.hook]( const Hook = (arg) => { return accept("0", 0); @@ -17,7 +134,7 @@ std::map> jswasm = { )[test.hook]", {0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, - 0x30U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x31U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, 0x72U, 0x67U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, @@ -29,7 +146,7 @@ std::map> jswasm = { 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, 0xb7U, 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U, 0x30U}}, - /* ==== WASM: 1 ==== */ + /* ==== WASM: 2 ==== */ {R"[test.hook]( const Hook = (arg) => { return rollback("0", 0); @@ -37,7 +154,7 @@ std::map> jswasm = { )[test.hook]", {0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, - 0x31U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x32U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, 0x72U, 0x67U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, 0x6bU, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, @@ -50,7 +167,32 @@ std::map> jswasm = { 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U, 0x30U}}, - /* ==== WASM: 2 ==== */ + /* ==== WASM: 3 ==== */ + {R"[test.hook]( + const Hook = (arg) => { + console.log("HERE"); + return accept(ret, 0); + } + )[test.hook]", + {0x43U, 0x08U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, + 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, + 0x33U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x72U, 0x67U, 0x0eU, 0x63U, 0x6fU, 0x6eU, 0x73U, 0x6fU, 0x6cU, 0x65U, + 0x06U, 0x6cU, 0x6fU, 0x67U, 0x08U, 0x48U, 0x45U, 0x52U, 0x45U, 0x0cU, + 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x06U, 0x72U, 0x65U, 0x74U, + 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, + 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, + 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U, + 0x80U, 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, + 0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, 0x1fU, + 0x00U, 0x06U, 0x0aU, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U, + 0x01U, 0x03U, 0x00U, 0x00U, 0x21U, 0x01U, 0xcaU, 0x03U, 0x00U, 0x01U, + 0x00U, 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0x42U, 0xe7U, 0x00U, 0x00U, + 0x00U, 0x04U, 0xe8U, 0x00U, 0x00U, 0x00U, 0x24U, 0x01U, 0x00U, 0x0eU, + 0x38U, 0xe9U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeaU, 0x00U, 0x00U, 0x00U, + 0xb7U, 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x02U, 0x03U, 0x62U}}, + + /* ==== WASM: 4 ==== */ {R"[test.hook]( const M_REPEAT_10 = (X) => X.repeat(10); const M_REPEAT_100 = (X) => M_REPEAT_10(X).repeat(10); @@ -65,7 +207,7 @@ std::map> jswasm = { 0x45U, 0x41U, 0x54U, 0x5fU, 0x31U, 0x30U, 0x30U, 0x1aU, 0x4dU, 0x5fU, 0x52U, 0x45U, 0x50U, 0x45U, 0x41U, 0x54U, 0x5fU, 0x31U, 0x30U, 0x30U, 0x30U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, - 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x32U, + 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x34U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x58U, 0x0cU, 0x72U, 0x65U, 0x70U, 0x65U, 0x61U, 0x74U, 0x06U, 0x61U, 0x72U, 0x67U, 0x06U, 0x72U, 0x65U, 0x74U, 0x84U, 0x01U, 0x61U, 0x62U, 0x63U, 0x64U, @@ -107,7 +249,7 @@ std::map> jswasm = { 0x00U, 0x62U, 0x00U, 0x00U, 0xb7U, 0x23U, 0x02U, 0x00U, 0xceU, 0x03U, 0x05U, 0x02U, 0x12U, 0x3fU}}, - /* ==== WASM: 3 ==== */ + /* ==== WASM: 5 ==== */ {R"[test.hook]( const Hook = (arg) => { const test_key = "0000000000000000000000000000000000000000000000006b657900"; @@ -117,7 +259,7 @@ std::map> jswasm = { )[test.hook]", {0x43U, 0x09U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, - 0x33U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x35U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, 0x72U, 0x67U, 0x10U, 0x74U, 0x65U, 0x73U, 0x74U, 0x5fU, 0x6bU, 0x65U, 0x79U, 0x14U, 0x74U, 0x65U, 0x73U, 0x74U, 0x5fU, 0x76U, 0x61U, 0x6cU, 0x75U, 0x65U, 0x70U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, @@ -143,7 +285,7 @@ std::map> jswasm = { 0x62U, 0x01U, 0x00U, 0x62U, 0x00U, 0x00U, 0xf2U, 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x03U, 0x21U, 0x21U, 0x21U, 0x07U, 0x02U, 0x30U}}, - /* ==== WASM: 4 ==== */ + /* ==== WASM: 6 ==== */ {R"[test.hook]( const Hook = (arg) => { return accept("0", 2); @@ -151,7 +293,7 @@ std::map> jswasm = { )[test.hook]", {0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, - 0x34U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, + 0x36U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U, 0x72U, 0x67U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, diff --git a/src/test/app/build-js-carray.sh b/src/test/app/build-js-carray.sh new file mode 100755 index 000000000..474329d92 --- /dev/null +++ b/src/test/app/build-js-carray.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Get the input file name from the command line argument +input_file="$1" +# Generate the hex output +hex_output=$(./qjsc -c -o /dev/stdout "$input_file" | tr -d '\n' | grep -Eo '\{[^}]+\}' | grep -Eo '0x[a-fA-F0-9]+' | sed -e 's/0x//g' | tr -d '\n') +# Convert the hex to a C array format +c_array="" +for ((i=0; i<${#hex_output}; i+=2)); do + c_array+="0x${hex_output:$i:2}U, " +done +c_array="${c_array%, }" +c_array+="" +# Output the C array to the console +echo "$c_array" \ No newline at end of file diff --git a/src/test/app/build_test_jshooks.sh b/src/test/app/build_test_jshooks.sh new file mode 100755 index 000000000..2045318be --- /dev/null +++ b/src/test/app/build_test_jshooks.sh @@ -0,0 +1,47 @@ +#!/bin/bash +rm -r wasmjs && mkdir wasmjs +echo ' +//This file is generated by build_test_hooks.h +#ifndef SETHOOK_JSWASM_INCLUDED +#define SETHOOK_JSWASM_INCLUDED +#include +#include +#include +#include +namespace ripple { +namespace test { +std::map> jswasm = {' > SetJSHook_tmp_wasm.h +COUNTER="0" +cat SetJSHook_test.cpp | tr '\n' '\f' | + ggrep -Po 'R"\[test\.hook\](.*?)\[test\.hook\]"' | + gsed -E 's/R"\[test\.hook\]\(//g' | + gsed -E 's/\)\[test\.hook\]"[\f \t]*/\/*end*\//g' | + while read -r line + do + echo "/* ==== WASM: $COUNTER ==== */" >> SetJSHook_tmp_wasm.h + echo -n '{ R"[test.hook](' >> SetJSHook_tmp_wasm.h + cat <<< $line | gsed -E 's/.{7}$//g' | tr -d '\n' | tr '\f' '\n' >> SetJSHook_tmp_wasm.h + echo ')[test.hook]",' >> SetJSHook_tmp_wasm.h + echo "{" >> SetJSHook_tmp_wasm.h + WAT=`ggrep -Eo '\(module' <<< $line | wc -l` + if [ "$WAT" -eq "0" ] + then + tr '\f' '\n' <<< $line >> wasmjs/test-$COUNTER-gen.js + ./build-js-carray.sh wasmjs/test-$COUNTER-gen.js >> SetJSHook_tmp_wasm.h + else + echo "Compilation error ^" + exit 1 + fi + if [ "$?" -gt "0" ] + then + echo "Compilation error ^" + exit 1 + fi + echo '}},' >> SetJSHook_tmp_wasm.h + echo >> SetJSHook_tmp_wasm.h + COUNTER=`echo $COUNTER + 1 | bc` + done +echo '}; +} +} +#endif' >> SetJSHook_tmp_wasm.h diff --git a/src/test/app/qjsc b/src/test/app/qjsc new file mode 100755 index 000000000..9790473a4 Binary files /dev/null and b/src/test/app/qjsc differ diff --git a/src/test/app/wasmjs/test-0-gen.js b/src/test/app/wasmjs/test-0-gen.js new file mode 100644 index 000000000..93a221c54 --- /dev/null +++ b/src/test/app/wasmjs/test-0-gen.js @@ -0,0 +1,23 @@ + + const INVALID_ARGUMENT = -7 + const sfAccount = 0x80001 + + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); + } + } + + const Hook = (arg) => { + ASSERT(otxn_field(sfAccount) == 20); + ASSERT(otxn_field(1) == INVALID_ARGUMENT); + + let acc2 = hook_account(); + ASSERT(acc2 == 20); + + for (var i = 0; i < 20; ++i) + ASSERT(acc[i] == acc2[i]); + + return accept("0", 0); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-1-gen.js b/src/test/app/wasmjs/test-1-gen.js new file mode 100644 index 000000000..b071c8298 --- /dev/null +++ b/src/test/app/wasmjs/test-1-gen.js @@ -0,0 +1,14 @@ + + const ASSERT = (x, code) => { + if (!x) { + rollback(x.toString(), code); + } + } + + const Hook = (arg) => { + let acc2 = hook_account(); + trace("acc2", acc2, false); + ASSERT(acc2.length == 20); + return accept(acc2, 0); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-2-gen.js b/src/test/app/wasmjs/test-2-gen.js new file mode 100644 index 000000000..83275ce5c --- /dev/null +++ b/src/test/app/wasmjs/test-2-gen.js @@ -0,0 +1,5 @@ + + const Hook = (arg) => { + return accept("0", 0); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-3-gen.js b/src/test/app/wasmjs/test-3-gen.js new file mode 100644 index 000000000..724eae33c --- /dev/null +++ b/src/test/app/wasmjs/test-3-gen.js @@ -0,0 +1,5 @@ + + const Hook = (arg) => { + return rollback("0", 0); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-4-gen.js b/src/test/app/wasmjs/test-4-gen.js new file mode 100644 index 000000000..97fb1bfb5 --- /dev/null +++ b/src/test/app/wasmjs/test-4-gen.js @@ -0,0 +1,6 @@ + + const Hook = (arg) => { + console.log("HERE"); + return accept(ret, 0); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-5-gen.js b/src/test/app/wasmjs/test-5-gen.js new file mode 100644 index 000000000..7bfec8647 --- /dev/null +++ b/src/test/app/wasmjs/test-5-gen.js @@ -0,0 +1,9 @@ + + const M_REPEAT_10 = (X) => X.repeat(10); + const M_REPEAT_100 = (X) => M_REPEAT_10(X).repeat(10); + const M_REPEAT_1000 = (X) => M_REPEAT_100(X).repeat(10); + const Hook = (arg) => { + const ret = M_REPEAT_1000("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz01234567890123"); + return accept(ret, 0); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-6-gen.js b/src/test/app/wasmjs/test-6-gen.js new file mode 100644 index 000000000..915f87ad9 --- /dev/null +++ b/src/test/app/wasmjs/test-6-gen.js @@ -0,0 +1,7 @@ + + const Hook = (arg) => { + const test_key = "0000000000000000000000000000000000000000000000006b657900"; + const test_value = "76616C756500"; + return accept("0", state_set(test_value, test_key)); + } + /*end*/ diff --git a/src/test/app/wasmjs/test-7-gen.js b/src/test/app/wasmjs/test-7-gen.js new file mode 100644 index 000000000..b77312c12 --- /dev/null +++ b/src/test/app/wasmjs/test-7-gen.js @@ -0,0 +1,5 @@ + + const Hook = (arg) => { + return accept("0", 2); + } + /*end*/