From 9ae8a83e29782de7c6684fbb54fd4e3c7b3c71d7 Mon Sep 17 00:00:00 2001 From: tequ Date: Thu, 1 Aug 2024 13:30:52 +0900 Subject: [PATCH 1/5] use `jshooks-api` in contractjs/tests --- contractsjs/@types/global.d.ts | 498 -------------------------- contractsjs/tests/base copy.ts | 5 +- contractsjs/tests/base.ts | 2 - contractsjs/tests/floatCompare.ts | 5 +- contractsjs/tests/floatDivide.ts | 12 +- contractsjs/tests/floatInt.ts | 12 +- contractsjs/tests/floatInvert.ts | 6 +- contractsjs/tests/floatLog.ts | 5 +- contractsjs/tests/floatMantissa.ts | 5 +- contractsjs/tests/floatMulratio.ts | 6 +- contractsjs/tests/floatMultiply.ts | 12 +- contractsjs/tests/floatNegate.ts | 5 +- contractsjs/tests/floatRoot.ts | 5 +- contractsjs/tests/floatSet.ts | 5 +- contractsjs/tests/hookAgain.ts | 3 +- contractsjs/tests/hookParam.ts | 5 +- contractsjs/tests/hookParamSet1.ts | 4 +- contractsjs/tests/hookSkip.ts | 6 +- contractsjs/tests/otxnParam.ts | 5 +- contractsjs/tests/otxnSlot.ts | 5 +- contractsjs/tests/otxnType.ts | 4 +- contractsjs/tests/slot.ts | 14 +- contractsjs/tests/slotClear.ts | 4 +- contractsjs/tests/slotCount.ts | 6 +- contractsjs/tests/slotFloat.ts | 6 +- contractsjs/tests/slotJson.ts | 12 +- contractsjs/tests/slotSet.ts | 5 +- contractsjs/tests/slotSize.ts | 4 +- contractsjs/tests/slotSubArray.ts | 14 +- contractsjs/tests/slotSubField.ts | 23 +- contractsjs/tests/slotType.ts | 21 +- contractsjs/tests/stateForeignSet0.ts | 4 +- contractsjs/tests/stateSet0.ts | 4 +- contractsjs/tests/stateSet3.ts | 4 +- contractsjs/tests/stateSet5.ts | 4 +- contractsjs/tests/utilKeylet.ts | 51 ++- package.json | 2 +- tsconfig.json | 3 +- yarn.lock | 31 +- 39 files changed, 164 insertions(+), 663 deletions(-) delete mode 100644 contractsjs/@types/global.d.ts diff --git a/contractsjs/@types/global.d.ts b/contractsjs/@types/global.d.ts deleted file mode 100644 index bd3fd06..0000000 --- a/contractsjs/@types/global.d.ts +++ /dev/null @@ -1,498 +0,0 @@ -import type { Transaction } from '@transia/xahau-models' -import { - SUCCESS, - OUT_OF_BOUNDS, - INTERNAL_ERROR, - TOO_BIG, - TOO_SMALL, - DOESNT_EXIST, - NO_FREE_SLOTS, - INVALID_ARGUMENT, - ALREADY_SET, - PREREQUISITE_NOT_MET, - FEE_TOO_LARGE, - EMISSION_FAILURE, - TOO_MANY_NONCES, - TOO_MANY_EMITTED_TXN, - NOT_IMPLEMENTED, - INVALID_ACCOUNT, - GUARD_VIOLATION, - INVALID_FIELD, - PARSE_ERROR, - RC_ROLLBACK, - RC_ACCEPT, - NO_SUCH_KEYLET, - NOT_AN_ARRAY, - NOT_AN_OBJECT, - INVALID_FLOAT, - DIVISION_BY_ZERO, - MANTISSA_OVERSIZED, - MANTISSA_UNDERSIZED, - EXPONENT_OVERSIZED, - EXPONENT_UNDERSIZED, - // XFL_OVERFLOW, - NOT_IOU_AMOUNT, - NOT_AN_AMOUNT, - CANT_RETURN_NEGATIVE, - NOT_AUTHORIZED, - PREVIOUS_FAILURE_PREVENTS_RETRY, - TOO_MANY_PARAMS, - INVALID_TXN, - RESERVE_INSUFFICIENT, - COMPLEX_NOT_SUPPORTED, - DOES_NOT_MATCH, - // INVALID_KEY, - // NOT_A_STRING, - // MEM_OVERLAP, - // TOO_MANY_STATE_MODIFICATIONS, - // TOO_MANY_NAMESPACES, -} from 'jshooks-api/dist/npm/src/error' - -export type ErrorCode = - | typeof SUCCESS - | typeof OUT_OF_BOUNDS - | typeof INTERNAL_ERROR - | typeof TOO_BIG - | typeof TOO_SMALL - | typeof DOESNT_EXIST - | typeof NO_FREE_SLOTS - | typeof INVALID_ARGUMENT - | typeof ALREADY_SET - | typeof PREREQUISITE_NOT_MET - | typeof FEE_TOO_LARGE - | typeof EMISSION_FAILURE - | typeof TOO_MANY_NONCES - | typeof TOO_MANY_EMITTED_TXN - | typeof NOT_IMPLEMENTED - | typeof INVALID_ACCOUNT - | typeof GUARD_VIOLATION - | typeof INVALID_FIELD - | typeof PARSE_ERROR - | typeof RC_ROLLBACK - | typeof RC_ACCEPT - | typeof NO_SUCH_KEYLET - | typeof NOT_AN_ARRAY - | typeof NOT_AN_OBJECT - | typeof INVALID_FLOAT - | typeof DIVISION_BY_ZERO - | typeof MANTISSA_OVERSIZED - | typeof MANTISSA_UNDERSIZED - | typeof EXPONENT_OVERSIZED - | typeof EXPONENT_UNDERSIZED - // | typeof XFL_OVERFLOW - | typeof NOT_IOU_AMOUNT - | typeof NOT_AN_AMOUNT - | typeof CANT_RETURN_NEGATIVE - | typeof NOT_AUTHORIZED - | typeof PREVIOUS_FAILURE_PREVENTS_RETRY - | typeof TOO_MANY_PARAMS - | typeof INVALID_TXN - | typeof RESERVE_INSUFFICIENT - | typeof COMPLEX_NOT_SUPPORTED - | typeof DOES_NOT_MATCH -// | typeof INVALID_KEY -// | typeof NOT_A_STRING -// | typeof MEM_OVERLAP -// | typeof TOO_MANY_STATE_MODIFICATIONS -// | typeof TOO_MANY_NAMESPACES - -declare global { - /********************************************************************************************************************* */ - - /** - * Write logging information to the trace log of nodes. Used for debugging purposes. - * - * @param message The 'logging key', message to output before the buffer (can be null) - * @param data The data to log - * @param hex (Optional) Should it log formatted in HEX? (default: false) - * @returns int64_t, value is 0 if successful, If negative, an error: OUT_OF_BOUNDS - */ - const trace: (message: string | null, data: any, hex?: boolean) => ErrorCode - - /********************************************************************************************************************* */ - - /** - * Definition of a Hook (smart contract) written in TS/JS. - * - * @param reserved uint32_t, Reserved for future use. - * @returns int64_t, An arbitrary return code you wish to return from your hook. This will - * be present in the metadata of the originating transaction. - */ - type Hook = (reserved?: number) => ErrorCode - - /** - * Definition of a Hook Callback - user defined function called in order to inform your hook about the - * status of a previously emitted transaction. State changes and further emit calls can be made from - * cbak but it cannot rollback a transaction. When Callback is executed the emitted transaction to - * which the callback relates is now the originating transaction. - * - * @param reserved uint32_t, If 0: the emittted transaction to which this callback - * relates was successfully accepted into a ledger. - * If 1: the emitted transaction to which the callback relates was NOT - * successfully accepted into a ledger before it expired. - * @returns int64_t, An arbitrary return code you wish to return from your hook. - * This will be present in the metadata of the originating transaction. - */ - type Callback = (reserved?: number) => ErrorCode - - /********************************************************************************************************************* */ - - /** - * Accept the originating transaction and commit any changes the hook made. End the execution of the hook - * with status: success. Record a return string and return code in transaction metadata. Commit all state - * changes. Submit all emit() transactions, allow originating transaction to continue. - * - * @param msg String to be stored in execution metadata. This is any string the - * hook-developer wishes to return with the acceptance. - * @param code A return code specific to this hook to be stored in execution metadata. - * Similar to the return code of an application on a *nix system. - * By convention success is zero. - * @returns int64_t, accept ends the hook, therefore no value is returned to the - * caller. By convention all Hook APIs return int64_t, but in this - * case nothing is returned. - */ - const accept: (msg: string, code: number) => ErrorCode - - /********************************************************************************************************************* */ - - /** - * Reject the originating transaction and discard any changes the hook made. End the execution of the - * hook with status: reject. Record a return string and return code in transaction metadata. Discard all - * state changes. Discard all emit() transactions. Disallow originating transaction to continue. - * - * The originating transaction will fail with tecHOOK_REJECTED and a fee will be charged - * - * @param error_msg String to be stored in execution metadata. This is any string the - * hook-developer wishes to return with the rollback. - * @param error_code A return code specific to this hook to be stored in execution metadata. - * Similar to the return code of an application on a *nix system. - * By convention success is zero. - * @returns int64_t, rollback ends the hook, therefore no value is returned to - * the caller. By convention all Hook APIs return int64_t, but in this - * case nothing is returned. - */ - const rollback: (error_msg: string, error_code: number) => ErrorCode - - /********************************************************************************************************************* */ - // UTIL APIS - - /** - * Format an r-address as Account ID - * - * @param raddress The r-address to format as HEX accountid - * @returns HEX Account ID - */ - const util_accid: (raddress: string) => ErrorCode | number[] - - /** - * Format an Acocunt ID as r-address - * - * @param accountid The HEX accountid to return as r-address - * @returns r-address - */ - const util_raddr: (accountid: number[] | string) => ErrorCode | string - - /** - * Verify a cryptographic signature. If the public key is prefixed with 0xED then use ED25519, otherwise assume SECP256k1 - * - * @param signedData The signed data to verify - * @param signature The signature (secp256k1 / ed25519) - * @param pubkey The public key responsible for the signature - * @returns Number 1: validation succeeded, the signature is valid, Number 0 if the signature is invalid - */ - const util_verify: ( - signedData: number[] | string, - signature: number[] | string, - pubkey: number[] | string - ) => 0 | 1 - - /** - * Compute an sha512-half over some data - * - * @param data The data to compute the hash over - * @returns Sha512half hash - */ - const util_sha512h: (data: number[] | string) => ErrorCode | number[] - - const util_keylet: ( - keylet_type: number, - keylet_data_a?: number[] | string | number, - keylet_data_b?: number[] | string | number, - keylet_data_c?: number[] | string | number - ) => ErrorCode | number[] - - /********************************************************************************************************************* */ - // HOOK APIS - - /** - * Retreive the 20 byte Account ID the Hook is executing on - * - * @returns Account ID the Hook is executing on - */ - const hook_account: () => ErrorCode | number[] - - /** - * Look up the hash of the hook installed on hook account at position hookno - * - * @param hookno The position in the hook chain the hook is located at, or -1 for the currently executing hook - * @returns Namespace biased SHA512H of the currently executing Hook, - */ - const hook_hash: (hookno: number) => ErrorCode | number[] - - const hook_param_set: ( - val: number[] | string, - key: number[] | string, - hash: number[] | string - ) => number - const hook_param: (key: number[] | string) => ErrorCode | number[] - const hook_skip: (hash: number[] | string, flag: number) => ErrorCode | number - const hook_pos: () => ErrorCode | number - const hook_again: () => ErrorCode | number - - /********************************************************************************************************************* */ - // OTXN APIS - - /** - * Look up the value for a named parameter specified on the originating transaction (ttINVOKE only) - * - * @param name Parameter's name - * @returns Param's value - */ - const otxn_param: (name: number[] | string) => ErrorCode | number[] - - /** - * Return the Transaction Type of the originating transaction - * - * @returns number as Transaction Type - */ - const otxn_type: () => ErrorCode | number - - /** - * Output the canonical hash of the originating transaction - * - * @param flag 0 = hash of the originating transaction, flag 1 & emit_failure = hash of emitting tx (default: 0) - * @returns TX Hash - */ - const otxn_id: (flag?: number) => ErrorCode | number[] - - const otxn_slot: (slotno: number) => ErrorCode | number[] - const otxn_field: (field_id: number) => ErrorCode | number[] - const otxn_json: () => ErrorCode | Record | Transaction // Triggering transaction - - /********************************************************************************************************************* */ - // FLOAT APIS - - const float_one: () => ErrorCode | bigint - const float_set: (exponent: number, mantissa: number) => ErrorCode | bigint - const float_multiply: (f1: bigint, f2: bigint) => ErrorCode | bigint - const float_mulratio: ( - f1: bigint, - round_up: number, - numerator: number, - denominator: number - ) => ErrorCode | bigint - const float_negate: (f1: bigint) => ErrorCode | bigint - const float_compare: ( - f1: bigint, - f2: bigint, - mode: number - ) => ErrorCode | number - const float_sum: (f1: bigint, f2: bigint) => ErrorCode | bigint - const float_sto: ( - cur: number[] | string | undefined, - isu: number[] | string | undefined, - f1: bigint, - field_code: number - ) => ErrorCode | number[] - const float_sto_set: (buf: number[] | string) => ErrorCode | number - const float_invert: (f1: bigint) => ErrorCode | bigint - const float_divide: (f1: bigint, f2: bigint) => ErrorCode | bigint - const float_mantissa: (f1: bigint) => ErrorCode | bigint - const float_sign: (f1: bigint) => ErrorCode | bigint - const float_int: ( - f1: bigint, - decimal_places: number, - abs: number - ) => ErrorCode | number - const float_log: (f1: bigint) => ErrorCode | bigint - const float_root: (f1: bigintt, n: number) => ErrorCode | bigint - - /********************************************************************************************************************* */ - // STO APIS - - /** - * Format an STO object (binary encoded ledger data) as JSON format - * - * @param blob The blob (e.g. serialized transaction) - * @returns Decoded JSON - */ - const sto_to_json: ( - blob: number[] | string - ) => ErrorCode | Record | Transaction - - /** - * Validate an STO object (binary encoded ledger data) - * - * @param blob The blob (e.g. serialized transaction) - * @returns Returns number 1 if the STObject pointed to by read_ptr is a valid STObject, 0 if it isn't. - */ - const sto_validate: (blob: number[] | string) => ErrorCode | number - - /** - * Format JSON as an STO object (binary encoded ledger data) - * - * @param jsonobj JSON object - * @returns STO Object (binary encoded ledger data) - */ - const sto_from_json: ( - jsonobj: Record | Transaction - ) => ErrorCode | number[] - - const sto_subfield: ( - sto: number[] | string, - field_id: number - ) => ErrorCode | number - const sto_subarray: ( - sto: number[] | string, - array_id: number - ) => ErrorCode | number - const sto_emplace: ( - sto: number[] | string, - field_bytes: number[] | string, - field_id: number - ) => ErrorCode | number[] - const sto_erase: ( - sto: number[] | string, - field_id: number - ) => ErrorCode | number[] - - /********************************************************************************************************************* */ - // LEDGER APIS - - /** - * Search for a keylet within a specified range on the current ledger - * Search the ledger for the first (lowest) Keylet of this type in this range - * - * @param low Pointer to the 34 byte serialised Keylet that represents the lower boundary of the Keylet range to search - * @param high Pointer to the 34 byte serialised Keylet that represents the upper boundary of the Keylet range to search - * @returns The number of bytes written (34 bytes) on success - */ - const ledger_keylet: ( - low: number[] | string, - high: number[] | string - ) => ErrorCode | number[] - - const ledger_last_hash: () => ErrorCode | number[] - const ledger_last_time: () => ErrorCode | number - const ledger_nonce: () => ErrorCode | number[] - const ledger_seq: () => ErrorCode | number - - /********************************************************************************************************************* */ - // SLOT APIS - - const slot_json: (slotno: number) => ErrorCode | number[] - const slot: (slotno: number) => ErrorCode | number[] - const slot_clear: (slotno: number) => ErrorCode | number - const slot_count: (slotno: number) => ErrorCode | number - const slot_set: (kl: number[] | string, slotno: number) => ErrorCode | number - const slot_size: (slotno: number) => ErrorCode | number - const slot_subarray: ( - parent_slotno: number, - array_id: number, - new_slotno: number - ) => ErrorCode | number - const slot_subfield: ( - parent_slotno: number, - field_id: number, - new_slotno: number - ) => ErrorCode | number - const slot_type: (slotno: number, flags: number) => ErrorCode | number - const slot_float: (slotno: number) => ErrorCode | number - const meta_slot: (slotno: number) => ErrorCode | number - const xpop_slot: ( - slotno_tx: number, - slotno_meta: number - ) => ErrorCode | number - - /********************************************************************************************************************* */ - // STATE APIS - /** - * Get Hook State - * - * @param key Key of the Hook State - * @returns Hook State value for key - */ - const state: (key: number[] | string) => ErrorCode | number[] - - /** - * Set Hook State - * - * @param value The value of data to persist - * @param key Key of the Hook State - * @returns The number of bytes written to Hook State (the length of the data), negative on error. - */ - const state_set: ( - value: number[] | string | undefined | null, - key: number[] | string - ) => ErrorCode | number - - /** - * Get Foreign Hook State (belonging to another account) - * - * @param key Key of the Hook State - * @param namespace The Hook namespace to look in - * @param accountid The owner of the state - * @returns Hook State value for key - */ - const state_foreign: ( - key: number[] | string, - namespace: number[] | string | undefined | null, - accountid: number[] | string | undefined | null - ) => ErrorCode | number[] - - /** - * Set Foreign Hook State - Authorized, needs a Grant to allows this - * - * @param value The value of data to persist - * @param key Key of the Hook State - * @param namespace The Hook namespace to look in - * @param accountid The owner of the state - * @returns The number of bytes written to Hook State (the length of the data), negative on error. - */ - const state_foreign_set: ( - value: number[] | string | undefined | null, - key: number[] | string, - namespace: number[] | string | undefined | null, - accountid: number[] | string | undefined | null - ) => ErrorCode | number - - /********************************************************************************************************************* */ - // EMIT APIS - - /** - * Prepare a JSON transaction for being Emitted - * - * @param txJson The transaction JSON, must be a complete transaction except for Account (always the Hook account) - */ - const prepare: ( - txJson: Record | Transaction - ) => ErrorCode | Record | Transaction - - /** - * Emit a transaction, returns number on error, number of emitted TX Hash in case of emit success - * - * @param txJson The TX JSON to emit - */ - const emit: (txJson: Record | Transaction) => ErrorCode | number - - /** - * Configure the amount of transactions this Hook is allowed to emit. - * - * @param txCount The max amount of transactions this Hook is allowed to emit in its lifecycle - */ - const etxn_reserve: (txCount: number) => ErrorCode | number - - const etxn_fee_base: (txblob: number[] | string) => ErrorCode | number -} - -export {} diff --git a/contractsjs/tests/base copy.ts b/contractsjs/tests/base copy.ts index 92ce8c9..b1e464a 100644 --- a/contractsjs/tests/base copy.ts +++ b/contractsjs/tests/base copy.ts @@ -1,12 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback('ASSERT.error', 0) } } -const INVALID_ARGUMENT = -7 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { ASSERT(float_sign(undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/base.ts b/contractsjs/tests/base.ts index cdbb8c1..a904b7d 100644 --- a/contractsjs/tests/base.ts +++ b/contractsjs/tests/base.ts @@ -4,8 +4,6 @@ const ASSERT = (x, code) => { } } -const DOESNT_EXIST = -5 - const names = [ '706172616d30', // 'param0' '706172616d31', // 'param1' diff --git a/contractsjs/tests/floatCompare.ts b/contractsjs/tests/floatCompare.ts index a53ed0e..68a1deb 100644 --- a/contractsjs/tests/floatCompare.ts +++ b/contractsjs/tests/floatCompare.ts @@ -1,12 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const INVALID_FLOAT = -10024 - const EQ = 0b001 const LT = 0b010 const GT = 0b100 diff --git a/contractsjs/tests/floatDivide.ts b/contractsjs/tests/floatDivide.ts index 6d88bdc..391f252 100644 --- a/contractsjs/tests/floatDivide.ts +++ b/contractsjs/tests/floatDivide.ts @@ -1,3 +1,10 @@ +import { + DIVISION_BY_ZERO, + INVALID_ARGUMENT, + INVALID_FLOAT, + XFL_OVERFLOW, +} from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) @@ -51,11 +58,6 @@ function ASSERT_EQUAL(x: bigint, y: bigint): void { } } -const INVALID_ARGUMENT = -7 -const DIVISION_BY_ZERO = -25 -const XFL_OVERFLOW = -30 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { ASSERT(float_divide(undefined, float_one()) === INVALID_ARGUMENT) ASSERT(float_divide(float_one(), undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatInt.ts b/contractsjs/tests/floatInt.ts index 6ea7279..3d476c0 100644 --- a/contractsjs/tests/floatInt.ts +++ b/contractsjs/tests/floatInt.ts @@ -1,14 +1,16 @@ +import { + CANT_RETURN_NEGATIVE, + INVALID_ARGUMENT, + INVALID_FLOAT, + TOO_BIG, +} from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const TOO_BIG = -3 -const INVALID_ARGUMENT = -7 -const CANT_RETURN_NEGATIVE = -33 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { ASSERT(float_int(undefined, 1, 1) === INVALID_ARGUMENT) ASSERT(float_int(1, undefined, 1) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatInvert.ts b/contractsjs/tests/floatInvert.ts index 2b4302f..b808183 100644 --- a/contractsjs/tests/floatInvert.ts +++ b/contractsjs/tests/floatInvert.ts @@ -1,13 +1,11 @@ +import { DIVISION_BY_ZERO, INVALID_ARGUMENT, INVALID_FLOAT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const DIVISION_BY_ZERO = -25 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { // invalid argument ASSERT(float_invert(undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatLog.ts b/contractsjs/tests/floatLog.ts index 65621f2..e2ac5d1 100644 --- a/contractsjs/tests/floatLog.ts +++ b/contractsjs/tests/floatLog.ts @@ -1,12 +1,11 @@ +import { COMPLEX_NOT_SUPPORTED, INVALID_ARGUMENT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const COMPLEX_NOT_SUPPORTED = -39 - const Hook = (arg) => { // invalid argument ASSERT(float_log(undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatMantissa.ts b/contractsjs/tests/floatMantissa.ts index f41bf6e..7c17532 100644 --- a/contractsjs/tests/floatMantissa.ts +++ b/contractsjs/tests/floatMantissa.ts @@ -1,12 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { // invalid argument ASSERT(float_mantissa(undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatMulratio.ts b/contractsjs/tests/floatMulratio.ts index 5d902ae..441dbd9 100644 --- a/contractsjs/tests/floatMulratio.ts +++ b/contractsjs/tests/floatMulratio.ts @@ -1,13 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT, XFL_OVERFLOW } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const XFL_OVERFLOW = -30 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { // invalid argument ASSERT(float_mulratio(undefined, 1, 1, 1) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatMultiply.ts b/contractsjs/tests/floatMultiply.ts index e7f049c..c8992db 100644 --- a/contractsjs/tests/floatMultiply.ts +++ b/contractsjs/tests/floatMultiply.ts @@ -1,13 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT, XFL_OVERFLOW } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const XFL_OVERFLOW = -30 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { ASSERT(float_multiply(undefined, float_one()) === INVALID_ARGUMENT) ASSERT(float_multiply(float_one(), undefined) === INVALID_ARGUMENT) @@ -53,12 +51,10 @@ const Hook = (arg) => { // identity ASSERT( - float_multiply(3189548536178311168n, float_one()), - 3189548536178311168n + float_multiply(3189548536178311168n, float_one()) === 3189548536178311168n ) ASSERT( - float_multiply(float_one(), 3189548536178311168n), - 3189548536178311168n + float_multiply(float_one(), 3189548536178311168n) === 3189548536178311168n ) // random multiplications diff --git a/contractsjs/tests/floatNegate.ts b/contractsjs/tests/floatNegate.ts index c8b9b67..5628b48 100644 --- a/contractsjs/tests/floatNegate.ts +++ b/contractsjs/tests/floatNegate.ts @@ -1,12 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const INVALID_ARGUMENT = -7 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { ASSERT(float_negate(undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatRoot.ts b/contractsjs/tests/floatRoot.ts index 1b2d479..cbf5589 100644 --- a/contractsjs/tests/floatRoot.ts +++ b/contractsjs/tests/floatRoot.ts @@ -1,12 +1,11 @@ +import { COMPLEX_NOT_SUPPORTED, INVALID_ARGUMENT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback('ASSERT.error', 0) } } -const INVALID_ARGUMENT = -7 -const COMPLEX_NOT_SUPPORTED = -39 - const Hook = (arg) => { ASSERT(float_root(undefined, 0) === INVALID_ARGUMENT) ASSERT(float_root(0, undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/floatSet.ts b/contractsjs/tests/floatSet.ts index 37d98d9..8c4678c 100644 --- a/contractsjs/tests/floatSet.ts +++ b/contractsjs/tests/floatSet.ts @@ -1,12 +1,11 @@ +import { INVALID_ARGUMENT, INVALID_FLOAT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback('ASSERT.error', 0) } } -const INVALID_ARGUMENT = -7 -const INVALID_FLOAT = -10024 - const Hook = (arg) => { ASSERT(float_set(undefined, 0) === INVALID_ARGUMENT) ASSERT(float_set(0, undefined) === INVALID_ARGUMENT) diff --git a/contractsjs/tests/hookAgain.ts b/contractsjs/tests/hookAgain.ts index 02a7326..9888880 100644 --- a/contractsjs/tests/hookAgain.ts +++ b/contractsjs/tests/hookAgain.ts @@ -1,5 +1,4 @@ -const PREREQUISITE_NOT_MET = -9 -const ALREADY_SET = -8 +import { ALREADY_SET, PREREQUISITE_NOT_MET } from 'jshooks-api' const Hook = (r) => { if (r > 0) { diff --git a/contractsjs/tests/hookParam.ts b/contractsjs/tests/hookParam.ts index 89ccd2f..9e96804 100644 --- a/contractsjs/tests/hookParam.ts +++ b/contractsjs/tests/hookParam.ts @@ -1,12 +1,11 @@ +import { DOESNT_EXIST, INVALID_ARGUMENT } from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const DOESNT_EXIST = -5 -const INVALID_ARGUMENT = -7 - const names = [ '706172616d30', // 'param0' '706172616d31', // 'param1' diff --git a/contractsjs/tests/hookParamSet1.ts b/contractsjs/tests/hookParamSet1.ts index 917dd95..3fcaf64 100644 --- a/contractsjs/tests/hookParamSet1.ts +++ b/contractsjs/tests/hookParamSet1.ts @@ -1,11 +1,11 @@ +import { DOESNT_EXIST } from 'jshooks-api' + const ASSERT = (x, code) => { if (!x) { rollback(x.toString(), code) } } -const DOESNT_EXIST = -5 - const names = ['param0', 'param1', 'param2', 'param3'] function toHex(str) { diff --git a/contractsjs/tests/hookSkip.ts b/contractsjs/tests/hookSkip.ts index 1b7aba6..446f694 100644 --- a/contractsjs/tests/hookSkip.ts +++ b/contractsjs/tests/hookSkip.ts @@ -1,13 +1,11 @@ +import { DOESNT_EXIST, INVALID_ARGUMENT, sfInvoiceID } from 'jshooks-api' + const ASSERT = (x, code) => { if (!x) { rollback(x.toString(), code) } } -const DOESNT_EXIST = -5 -const INVALID_ARGUMENT = -7 -const sfInvoiceID = 0x50011 - const Hook = (arg) => { // garbage check ASSERT(hook_skip([], 0) === DOESNT_EXIST) diff --git a/contractsjs/tests/otxnParam.ts b/contractsjs/tests/otxnParam.ts index bea71e5..65314d2 100644 --- a/contractsjs/tests/otxnParam.ts +++ b/contractsjs/tests/otxnParam.ts @@ -1,3 +1,5 @@ +import { DOESNT_EXIST, INVALID_ARGUMENT } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,9 +7,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 -const INVALID_ARGUMENT = -7 - const names = [ '706172616d30', // 'param0' '706172616d31', // 'param1' diff --git a/contractsjs/tests/otxnSlot.ts b/contractsjs/tests/otxnSlot.ts index 05d2018..ebd220b 100644 --- a/contractsjs/tests/otxnSlot.ts +++ b/contractsjs/tests/otxnSlot.ts @@ -1,3 +1,5 @@ +import { INVALID_ARGUMENT, NO_FREE_SLOTS } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,9 +7,6 @@ const ASSERT = (x, line) => { } } -const INVALID_ARGUMENT = -7 -const NO_FREE_SLOTS = -6 - const Hook = (arg) => { ASSERT(otxn_slot(256) === INVALID_ARGUMENT, 1) diff --git a/contractsjs/tests/otxnType.ts b/contractsjs/tests/otxnType.ts index fdb13d8..238b0ca 100644 --- a/contractsjs/tests/otxnType.ts +++ b/contractsjs/tests/otxnType.ts @@ -1,3 +1,5 @@ +import { sfTransactionType } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,8 +7,6 @@ const ASSERT = (x, line) => { } } -const sfTransactionType = 0x10002 - const Hook = (arg) => { ASSERT(otxn_slot(1) === 1, 1) diff --git a/contractsjs/tests/slot.ts b/contractsjs/tests/slot.ts index 890ead8..cfe49ef 100644 --- a/contractsjs/tests/slot.ts +++ b/contractsjs/tests/slot.ts @@ -1,3 +1,11 @@ +import { + DOESNT_EXIST, + INVALID_ARGUMENT, + KEYLET_ACCOUNT, + TOO_BIG, + sfBalance, +} from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,12 +13,6 @@ const ASSERT = (x, line) => { } } -const INVALID_ARGUMENT = -7 -const DOESNT_EXIST = -5 -const TOO_BIG = -3 -const KEYLET_ACCOUNT = 3 -const sfBalance = 0x60002 - const Hook = (arg) => { // slot type check ASSERT(slot(null) === INVALID_ARGUMENT, 1) diff --git a/contractsjs/tests/slotClear.ts b/contractsjs/tests/slotClear.ts index 9fadc60..ab34f9c 100644 --- a/contractsjs/tests/slotClear.ts +++ b/contractsjs/tests/slotClear.ts @@ -1,3 +1,5 @@ +import { DOESNT_EXIST } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,8 +7,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 - const Hook = (arg) => { ASSERT(otxn_slot(1) === 1, 1) diff --git a/contractsjs/tests/slotCount.ts b/contractsjs/tests/slotCount.ts index ca72a17..61ec258 100644 --- a/contractsjs/tests/slotCount.ts +++ b/contractsjs/tests/slotCount.ts @@ -1,3 +1,5 @@ +import { DOESNT_EXIST, NOT_AN_ARRAY, sfMemos } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,10 +7,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 -const NOT_AN_ARRAY = -22 -const sfMemos = 0xf0009 - const Hook = (arg) => { ASSERT(otxn_slot(1) === 1, 1) diff --git a/contractsjs/tests/slotFloat.ts b/contractsjs/tests/slotFloat.ts index 75b338d..5aae485 100644 --- a/contractsjs/tests/slotFloat.ts +++ b/contractsjs/tests/slotFloat.ts @@ -1,3 +1,5 @@ +import { DOESNT_EXIST, NOT_AN_AMOUNT, sfFee } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,10 +7,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 -const NOT_AN_AMOUNT = -32 -const sfFee = 0x60008 - const Hook = (arg) => { ASSERT(otxn_slot(1) === 1, 1) diff --git a/contractsjs/tests/slotJson.ts b/contractsjs/tests/slotJson.ts index 9b7b5a5..94fd43f 100644 --- a/contractsjs/tests/slotJson.ts +++ b/contractsjs/tests/slotJson.ts @@ -1,6 +1,12 @@ import { Payment } from '@transia/xrpl' import { IssuedCurrencyAmount } from '@transia/xrpl/dist/npm/models/common' import { LedgerEntry, RippleState } from '@transia/xrpl/dist/npm/models/ledger' +import { + DOESNT_EXIST, + INVALID_ARGUMENT, + KEYLET_LINE, + sfAccount, +} from 'jshooks-api' const ASSERT = (x) => { if (!x) { @@ -8,12 +14,6 @@ const ASSERT = (x) => { } } -const DOESNT_EXIST = -5 -const INVALID_ARGUMENT = -7 -const KEYLET_LINE = 9 - -const sfAccount = 0x80001 - const kl_sk = [ 0x00, 0x68, 0xb4, 0x97, 0x9a, 0x36, 0xcd, 0xc7, 0xf3, 0xd3, 0xd5, 0xc3, 0x1a, 0x4e, 0xae, 0x2a, 0xc7, 0xd7, 0x20, 0x9d, 0xda, 0x87, 0x75, 0x88, 0xb9, 0xaf, diff --git a/contractsjs/tests/slotSet.ts b/contractsjs/tests/slotSet.ts index b2a57ea..1656ceb 100644 --- a/contractsjs/tests/slotSet.ts +++ b/contractsjs/tests/slotSet.ts @@ -1,3 +1,5 @@ +import { DOESNT_EXIST, INVALID_ARGUMENT } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,9 +7,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 -const INVALID_ARGUMENT = -7 - const kl_sk = [ 0x00, 0x68, 0xb4, 0x97, 0x9a, 0x36, 0xcd, 0xc7, 0xf3, 0xd3, 0xd5, 0xc3, 0x1a, 0x4e, 0xae, 0x2a, 0xc7, 0xd7, 0x20, 0x9d, 0xda, 0x87, 0x75, 0x88, 0xb9, 0xaf, diff --git a/contractsjs/tests/slotSize.ts b/contractsjs/tests/slotSize.ts index c96f91c..1ff122b 100644 --- a/contractsjs/tests/slotSize.ts +++ b/contractsjs/tests/slotSize.ts @@ -1,3 +1,5 @@ +import { DOESNT_EXIST } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,8 +7,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 - const kl_sk = [ 0x00, 0x68, 0xb4, 0x97, 0x9a, 0x36, 0xcd, 0xc7, 0xf3, 0xd3, 0xd5, 0xc3, 0x1a, 0x4e, 0xae, 0x2a, 0xc7, 0xd7, 0x20, 0x9d, 0xda, 0x87, 0x75, 0x88, 0xb9, 0xaf, diff --git a/contractsjs/tests/slotSubArray.ts b/contractsjs/tests/slotSubArray.ts index bea9b4a..0471434 100644 --- a/contractsjs/tests/slotSubArray.ts +++ b/contractsjs/tests/slotSubArray.ts @@ -1,3 +1,11 @@ +import { + DOESNT_EXIST, + NOT_AN_ARRAY, + NO_FREE_SLOTS, + sfMemoData, + sfMemos, +} from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,12 +13,6 @@ const ASSERT = (x, line) => { } } -const DOESNT_EXIST = -5 -const NO_FREE_SLOTS = -6 -const NOT_AN_ARRAY = -22 -const sfMemos = 0xf0009 -const sfMemoData = 0x7000d - const kl_sk = [ 0x00, 0x68, 0xb4, 0x97, 0x9a, 0x36, 0xcd, 0xc7, 0xf3, 0xd3, 0xd5, 0xc3, 0x1a, 0x4e, 0xae, 0x2a, 0xc7, 0xd7, 0x20, 0x9d, 0xda, 0x87, 0x75, 0x88, 0xb9, 0xaf, diff --git a/contractsjs/tests/slotSubField.ts b/contractsjs/tests/slotSubField.ts index cb9828b..884fb16 100644 --- a/contractsjs/tests/slotSubField.ts +++ b/contractsjs/tests/slotSubField.ts @@ -1,20 +1,21 @@ +import { + DOESNT_EXIST, + INVALID_ARGUMENT, + INVALID_FIELD, + NOT_AN_OBJECT, + NO_FREE_SLOTS, + sfHashes, + sfLastLedgerSequence, + sfMemoData, + sfMemos, +} from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const DOESNT_EXIST = -5 -const NO_FREE_SLOTS = -6 -const INVALID_ARGUMENT = -7 -const INVALID_FIELD = -17 -const NOT_AN_OBJECT = -23 - -const sfMemos = 0xf0009 -const sfMemoData = 0x7000d -const sfLastLedgerSequence = 0x2001b -const sfHashes = 0x130002 - const kl_sk = [ 0x00, 0x68, 0xb4, 0x97, 0x9a, 0x36, 0xcd, 0xc7, 0xf3, 0xd3, 0xd5, 0xc3, 0x1a, 0x4e, 0xae, 0x2a, 0xc7, 0xd7, 0x20, 0x9d, 0xda, 0x87, 0x75, 0x88, 0xb9, 0xaf, diff --git a/contractsjs/tests/slotType.ts b/contractsjs/tests/slotType.ts index c576062..17275f9 100644 --- a/contractsjs/tests/slotType.ts +++ b/contractsjs/tests/slotType.ts @@ -1,20 +1,19 @@ +import { + DOESNT_EXIST, + sfLastLedgerSequence, + sfAmount, + NOT_AN_AMOUNT, + sfAccount, + KEYLET_LINE, + sfHighLimit, +} from 'jshooks-api' + const ASSERT = (x) => { if (!x) { rollback(x.toString(), 0) } } -const DOESNT_EXIST = -5 -const NOT_AN_AMOUNT = -32 -const KEYLET_LINE = 9 - -const sfLedgerEntry = 0x27120101 -const sfTransaction = 0x27110101 -const sfAccount = 0x80001 -const sfAmount = 0x60001 -const sfHighLimit = 0x60007 -const sfLastLedgerSequence = 0x2001b - const kl_sk = [ 0x00, 0x68, 0xb4, 0x97, 0x9a, 0x36, 0xcd, 0xc7, 0xf3, 0xd3, 0xd5, 0xc3, 0x1a, 0x4e, 0xae, 0x2a, 0xc7, 0xd7, 0x20, 0x9d, 0xda, 0x87, 0x75, 0x88, 0xb9, 0xaf, diff --git a/contractsjs/tests/stateForeignSet0.ts b/contractsjs/tests/stateForeignSet0.ts index 44148d8..bd74750 100644 --- a/contractsjs/tests/stateForeignSet0.ts +++ b/contractsjs/tests/stateForeignSet0.ts @@ -1,11 +1,11 @@ +import { INVALID_ARGUMENT, sfInvoiceID } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) rollback(x.toString(), line) } } -const sfInvoiceID = 327697 -const INVALID_ARGUMENT = -7 const a = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, diff --git a/contractsjs/tests/stateSet0.ts b/contractsjs/tests/stateSet0.ts index f94c1ab..98c0f12 100644 --- a/contractsjs/tests/stateSet0.ts +++ b/contractsjs/tests/stateSet0.ts @@ -1,3 +1,5 @@ +import { INVALID_ARGUMENT } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,8 +7,6 @@ const ASSERT = (x, line) => { } } -const INVALID_ARGUMENT = -7 - const a = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, diff --git a/contractsjs/tests/stateSet3.ts b/contractsjs/tests/stateSet3.ts index e86bb7d..1f00292 100644 --- a/contractsjs/tests/stateSet3.ts +++ b/contractsjs/tests/stateSet3.ts @@ -1,3 +1,5 @@ +import { sfAccount } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,8 +7,6 @@ const ASSERT = (x, line) => { } } -const sfAccount = 0x80001 - const Hook = (arg) => { hook_again() // we're going to check in weak execution too diff --git a/contractsjs/tests/stateSet5.ts b/contractsjs/tests/stateSet5.ts index d9ed01e..6011c12 100644 --- a/contractsjs/tests/stateSet5.ts +++ b/contractsjs/tests/stateSet5.ts @@ -1,3 +1,5 @@ +import { sfInvoiceID } from 'jshooks-api' + const ASSERT = (x, line) => { if (!x) { trace('line', line, false) @@ -5,8 +7,6 @@ const ASSERT = (x, line) => { } } -const sfInvoiceID = 0x50011 - const Hook = (arg) => { // get this transaction id const txn = otxn_id(0) diff --git a/contractsjs/tests/utilKeylet.ts b/contractsjs/tests/utilKeylet.ts index 34d0be4..030acf8 100644 --- a/contractsjs/tests/utilKeylet.ts +++ b/contractsjs/tests/utilKeylet.ts @@ -1,3 +1,27 @@ +import { + KEYLET_HOOK, + KEYLET_HOOK_STATE, + KEYLET_ACCOUNT, + KEYLET_AMENDMENTS, + KEYLET_CHILD, + KEYLET_SKIP, + KEYLET_FEES, + KEYLET_NEGATIVE_UNL, + KEYLET_LINE, + KEYLET_OFFER, + KEYLET_QUALITY, + KEYLET_EMITTED_DIR, + KEYLET_SIGNERS, + KEYLET_CHECK, + KEYLET_DEPOSIT_PREAUTH, + KEYLET_UNCHECKED, + KEYLET_OWNER_DIR, + KEYLET_PAGE, + KEYLET_ESCROW, + KEYLET_PAYCHAN, + KEYLET_NFT_OFFER, +} from 'jshooks-api' + const ASSERT = (x, code) => { if (!x) { trace('error', 0, false) @@ -45,33 +69,6 @@ const b = [ 0x3e, 0x6d, 0x6e, 0x76, 0x29, 0xfb, 0xba, ] -const KEYLET_HOOK = 1 -const KEYLET_HOOK_STATE = 2 -const KEYLET_ACCOUNT = 3 -const KEYLET_AMENDMENTS = 4 -const KEYLET_CHILD = 5 -const KEYLET_SKIP = 6 -const KEYLET_FEES = 7 -const KEYLET_NEGATIVE_UNL = 8 -const KEYLET_LINE = 9 -const KEYLET_OFFER = 10 -const KEYLET_QUALITY = 11 -const KEYLET_EMITTED_DIR = 12 -const KEYLET_TICKET = 13 -const KEYLET_SIGNERS = 14 -const KEYLET_CHECK = 15 -const KEYLET_DEPOSIT_PREAUTH = 16 -const KEYLET_UNCHECKED = 17 -const KEYLET_OWNER_DIR = 18 -const KEYLET_PAGE = 19 -const KEYLET_ESCROW = 20 -const KEYLET_PAYCHAN = 21 -const KEYLET_EMITTED = 22 -const KEYLET_NFT_OFFER = 23 -const KEYLET_HOOK_DEFINITION = 24 -const KEYLET_HOOK_STATE_DIR = 25 -const KEYLET_URITOKEN = 26 - const INVALID_ARGUMENT = -7 const Hook = (arg) => { diff --git a/package.json b/package.json index 2c35f92..56f2aea 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "@transia/xrpl": "^2.7.3-alpha.27", "crypto-js": "^4.1.1", "dotenv": "^16.4.5", - "jshooks-api": "^1.0.2", "winston": "^3.10.0" }, "devDependencies": { @@ -36,6 +35,7 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", + "jshooks-api": "^1.0.5", "prettier": "^3.0.2", "ts-jest": "^29.0.5", "ts-node": "^10.9.1", diff --git a/tsconfig.json b/tsconfig.json index b5cb597..3768e5f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,6 @@ "extends": "@tsconfig/node16/tsconfig.json", "compilerOptions": { "composite": true, - "module": "commonjs", - "moduleResolution": "node", "sourceMap": true, "strict": true, "pretty": true, @@ -20,6 +18,7 @@ "skipLibCheck": true, "resolveJsonModule": true, "preserveSymlinks": true, + "types": ["jshooks-api/globals"] }, "include": [ "src/**/*.ts", diff --git a/yarn.lock b/yarn.lock index e9c4995..0dec805 100644 --- a/yarn.lock +++ b/yarn.lock @@ -710,6 +710,15 @@ elliptic "^6.5.4" hash.js "^1.0.3" +"@transia/xahau-models@^2.7.3-alpha.29": + version "2.7.3-alpha.29" + resolved "https://registry.yarnpkg.com/@transia/xahau-models/-/xahau-models-2.7.3-alpha.29.tgz#17f28e5ed37d6ae4b9bbc9215b0843afb6fab677" + integrity sha512-MmIS55eTOHcS3skCzS23043QW0m9tLLmuPqq0L5lDI5mOuTcl5Euk5WjD2WcETivxNvlOExqLmp21jmhseXMww== + dependencies: + "@types/node" "^20.4.2" + ts-node "^10.9.1" + typescript "^5.1.6" + "@transia/xrpl@^2.7.3-alpha.27": version "2.7.3-alpha.27" resolved "https://registry.npmjs.org/@transia/xrpl/-/xrpl-2.7.3-alpha.27.tgz" @@ -842,6 +851,13 @@ resolved "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz" integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ== +"@types/node@^20.4.2": + version "20.14.13" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.13.tgz#bf4fe8959ae1c43bc284de78bd6c01730933736b" + integrity sha512-+bHoGiZb8UiQ0+WEtmph2IWQCjIqg8MDZMAV+ppRRhUZnquF5mQkP/9vpSwJClEiSM/C7fZZExPzfU0vJTyp8w== + dependencies: + undici-types "~5.26.4" + "@types/semver@^7.3.12": version "7.5.0" resolved "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz" @@ -2708,10 +2724,12 @@ jsesc@^2.5.1: resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz" integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== -jshooks-api@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/jshooks-api/-/jshooks-api-1.0.2.tgz#6673f1a9dc5cdc35e9236ba7437e079caa0246a6" - integrity sha512-gEJQtjxKd85o+ldYucdARChBByv32Ihx0/Lh9jSzdjKDz2TCIcNXIqIAc0livravExORoHoPu+E6ELhm9XZluA== +jshooks-api@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/jshooks-api/-/jshooks-api-1.0.5.tgz#60fe1c33db524c259eb50a142365f8c35942370f" + integrity sha512-iyPYrWOcTAQUrC+dH6diw8zosDT+CWRfL6ZbUApPB41WBjGKfIsimlJnvE4/NinxnCLTViUTr/SQFoCDKSOIxQ== + dependencies: + "@transia/xahau-models" "^2.7.3-alpha.29" json-parse-even-better-errors@^2.3.0: version "2.3.1" @@ -3559,6 +3577,11 @@ typescript@^5.1.6: resolved "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz" integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w== +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + untildify@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz" From 38602a878afb08cc24feca1e39c48a2a50feba7a Mon Sep 17 00:00:00 2001 From: tequ Date: Thu, 1 Aug 2024 13:40:59 +0900 Subject: [PATCH 2/5] fix jest types --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 3768e5f..95dbf39 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,7 @@ "skipLibCheck": true, "resolveJsonModule": true, "preserveSymlinks": true, - "types": ["jshooks-api/globals"] + "types": ["jest", "jshooks-api/globals"] }, "include": [ "src/**/*.ts", From 99516696c959d2f516d1fe7504a287886ec88f99 Mon Sep 17 00:00:00 2001 From: tequ Date: Thu, 1 Aug 2024 14:09:15 +0900 Subject: [PATCH 3/5] fix tests --- contractsjs/tests/base.ts | 1 + contractsjs/toolbox/base.ts | 2 +- test/integration/hooks/toolbox/hookOnTT.js.test.ts | 2 ++ test/integration/setup/setHook.js.test.ts | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/contractsjs/tests/base.ts b/contractsjs/tests/base.ts index a904b7d..6c32aaa 100644 --- a/contractsjs/tests/base.ts +++ b/contractsjs/tests/base.ts @@ -1,3 +1,4 @@ +import { DOESNT_EXIST } from 'jshooks-api' const ASSERT = (x, code) => { if (!x) { rollback(x.toString(), code) diff --git a/contractsjs/toolbox/base.ts b/contractsjs/toolbox/base.ts index cf40836..1498e38 100644 --- a/contractsjs/toolbox/base.ts +++ b/contractsjs/toolbox/base.ts @@ -1,5 +1,5 @@ const Hook = (arg) => { - return accept('', 0) + return accept('base: Finished.', 0) } export { Hook } diff --git a/test/integration/hooks/toolbox/hookOnTT.js.test.ts b/test/integration/hooks/toolbox/hookOnTT.js.test.ts index 7cc4e2c..5ec9990 100644 --- a/test/integration/hooks/toolbox/hookOnTT.js.test.ts +++ b/test/integration/hooks/toolbox/hookOnTT.js.test.ts @@ -40,6 +40,7 @@ describe('hookOnTT', () => { namespace: 'hookOnTT', flags: SetHookFlags.hsfOverride, hookOnArray: ['Invoke'], + fee: '100000', }) await setHooksV3({ client: testContext.client, @@ -68,6 +69,7 @@ describe('hookOnTT', () => { namespace: 'hookOnTT', flags: SetHookFlags.hsfOverride, hookOnArray: ['Invoke', 'Payment'], + fee: '100000', }) await setHooksV3({ client: testContext.client, diff --git a/test/integration/setup/setHook.js.test.ts b/test/integration/setup/setHook.js.test.ts index 72eb147..b33c5b6 100644 --- a/test/integration/setup/setHook.js.test.ts +++ b/test/integration/setup/setHook.js.test.ts @@ -153,7 +153,7 @@ describe('SetHook - (noop|create|install', () => { const leHook = hookRes.result.node as LeHook expect(leHook.Hooks.length).toBe(1) expect(leHook.Hooks[0].Hook.HookHash).toEqual( - '567E69AD2AEB8DEDE3206263BEC83EE0166EE745E6EA0028CCADF9759D82DF07' + '8F621E7F154E74B699A2E00D2C354C416C3409B709DED57F4A677DF2AEC7D054' ) const hookDefRequest: LedgerEntryRequest = { command: 'ledger_entry', @@ -161,7 +161,7 @@ describe('SetHook - (noop|create|install', () => { } const hookDefRes = await testContext.client.request(hookDefRequest) expect((hookDefRes.result.node as LeHookDefinition).HookNamespace).toEqual( - '326178559E63837BA3B83BC05E5DC323A7B52C782AC4D5B3B182B2E050565581' + 'CAE662172FD450BB0CD710A769079C05BFC5D8E35EFA6576EDC7D0377AFDD4A2' ) await clearAllHooksV3({ From eb2feb2a5a5a3dd3916fdea0587a1e53c365f56a Mon Sep 17 00:00:00 2001 From: tequ Date: Sun, 4 Aug 2024 22:48:57 +0900 Subject: [PATCH 4/5] fix test hookhash --- test/integration/setup/setHook.js.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/setup/setHook.js.test.ts b/test/integration/setup/setHook.js.test.ts index def38d3..b33c5b6 100644 --- a/test/integration/setup/setHook.js.test.ts +++ b/test/integration/setup/setHook.js.test.ts @@ -153,7 +153,7 @@ describe('SetHook - (noop|create|install', () => { const leHook = hookRes.result.node as LeHook expect(leHook.Hooks.length).toBe(1) expect(leHook.Hooks[0].Hook.HookHash).toEqual( - 'C5785FD06D7133640AADDA3DF244AD96F09C65FFF629B5D7A9BDD70BD8D8C7F6' + '8F621E7F154E74B699A2E00D2C354C416C3409B709DED57F4A677DF2AEC7D054' ) const hookDefRequest: LedgerEntryRequest = { command: 'ledger_entry', From 6c552cf71fd45a75b8201c509e771e72496a4557 Mon Sep 17 00:00:00 2001 From: tequ Date: Sun, 4 Aug 2024 22:55:43 +0900 Subject: [PATCH 5/5] fix --- test/integration/setup/setHook.js.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/setup/setHook.js.test.ts b/test/integration/setup/setHook.js.test.ts index b33c5b6..5de3efb 100644 --- a/test/integration/setup/setHook.js.test.ts +++ b/test/integration/setup/setHook.js.test.ts @@ -153,7 +153,7 @@ describe('SetHook - (noop|create|install', () => { const leHook = hookRes.result.node as LeHook expect(leHook.Hooks.length).toBe(1) expect(leHook.Hooks[0].Hook.HookHash).toEqual( - '8F621E7F154E74B699A2E00D2C354C416C3409B709DED57F4A677DF2AEC7D054' + '42376A3F22FAA8C32414DD8731D327EA94269BC7573CDE7DB1CBA7707F672BDC' ) const hookDefRequest: LedgerEntryRequest = { command: 'ledger_entry',