From e1633be4e434347f41f648f82f0a02c142035b8f Mon Sep 17 00:00:00 2001 From: Gabriel Levcovitz Date: Fri, 20 Dec 2024 18:39:25 -0300 Subject: [PATCH 1/2] docs(qa): add large values QA --- QA_LARGE_VALUES.md | 36 +++++++++++++ README.md | 2 +- package.json | 4 +- qa/large-values-network/checks.py | 63 ++++++++++++++++++++++ qa/large-values-network/docker-compose.yml | 62 +++++++++++++++++++++ qa/large-values-network/privnet.yml | 31 +++++++++++ 6 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 QA_LARGE_VALUES.md create mode 100644 qa/large-values-network/checks.py create mode 100644 qa/large-values-network/docker-compose.yml create mode 100644 qa/large-values-network/privnet.yml diff --git a/QA_LARGE_VALUES.md b/QA_LARGE_VALUES.md new file mode 100644 index 00000000..671e53fb --- /dev/null +++ b/QA_LARGE_VALUES.md @@ -0,0 +1,36 @@ +# QA with large output values + +## Setup + +1. Run `npm run qa_network_up`. This will run a docker compose with a full node in a custom network, a tx-mining-service, and a CPU miner. +2. Start the wallet with this seed: `avocado spot town typical traffic vault danger century property shallow divorce festival spend attack anchor afford rotate green audit adjust fade wagon depart level` (same as in `qa/large-values-network/privnet.yml`) +3. Go to settings, "Change network", select "Custom network" and configure: + 1. Full node URL: `http://localhost:8083/v1a/` + 2. Transaction Mining Service URL: `http://localhost:8035/` + 3. Explorer URL: `https://explorer.testnet.hathor.network` (same as testnet — we don't use it in this QA) + 4. Explorer Service URL: `https://explorer-service.testnet.hathor.network/` (same as testnet — we don't use it in this QA) + +## Checks + +1. Check that the total available is exactly `92,233,720,368,547,758.00 HTR`. +2. Check that a simple transaction can be sent + 1. Copy an address from this wallet. + 2. Go to the "Send Tokens" tab and create a transaction to that address. + 3. Copy the "Balance available" value, paste it in the value input, and send the transaction. + 4. The transaction should be successfully created. Return to the main screen. + 5. The balance should remain `92,233,720,368,547,758.00 HTR`, and a new transaction with value `0.00` should appear in the history. +3. Check that a custom token can be created with the maximum output value + 1. Go to the "Custom tokens" tab. + 2. Type any "Short name" and "Symbol". + 3. Put exactly `9223372036854775808` as the "Amount". This is `2^63`, which is the maximum value an output can hold. It should appear as `92,233,720,368,547,758.08` in the input. + 4. The deposit should appear as exactly `922,337,203,685,477.60 HTR`. It's not precisely 1% of the requested amount, this is expected. For more information, see [this](https://github.com/HathorNetwork/hathor-wallet-lib/blob/c06d3ce7132efb6e28fe507e94bbc585b65c3d94/src/utils/tokens.ts#L274-L277). + 5. Create the token, and the transaction should be successfully created. Return to the main screen. + 6. Go to you newly created token's tab, and check that the total available is exactly `92,233,720,368,547,758.08`. It should contain one transaction in the history with `92,233,720,368,547,758.08` as the value. + 7. Go to the HTR tab, the total available should be exactly `91,311,383,164,862,280.40`, and a new transaction with value `-922,337,203,685,477.60` should appear in the history. +4. Run automated checking script. This is like an integration test, the goal is to check that transactions were created with the correct values in the full node, and that we're not being tricked by display values that may accidentally look the same as the correct value in the wallet. + 1. Run `python ./qa/large-values-network/checks.py`. + 2. Make sure it outputs `Checks executed successfully.` + +## Tear down + +1. Run `npm run_qa_network_down`. \ No newline at end of file diff --git a/README.md b/README.md index 43ca6383..0f396acf 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ If you get some error like this `error while loading shared libraries: libxshmfe To use the Chrome Dev Tools associated with Electron for debugging purposes, the unsafe mode may be enabled through CLI arguments: ```sh -npm run electron-dev -- --unsafe-mode --hathor-debug +npm run electron-debug ``` ### Debug mode on installed app diff --git a/package.json b/package.json index 5e3a5954..905ab8b3 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,9 @@ "electron-dev-concurrently": "npx concurrently 'npx cross-env BROWSER=none npm run start' 'npx wait-on http://localhost:3000/ && npx cross-env ELECTRON_START_URL=http://localhost:3000 NODE_ENV=dev electron --inspect=5858 .'", "locale-update-pot": "ttag extract -o ./locale/texts.pot ./src/", "postinstall": "npx cross-env ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=true npm run electron-deps && patch-package", - "generate-doc": "npx jsdoc -c jsdoc.json -r src/. README.md || exit 0" + "generate-doc": "npx jsdoc -c jsdoc.json -r src/. README.md || exit 0", + "qa_network_up": "docker compose -f ./qa/large-values-network/docker-compose.yml up", + "qa_network_down": "docker compose -f ./qa/large-values-network/docker-compose.yml down" }, "devDependencies": { "@sentry/browser": "7.99.0", diff --git a/qa/large-values-network/checks.py b/qa/large-values-network/checks.py new file mode 100644 index 00000000..120ea1d7 --- /dev/null +++ b/qa/large-values-network/checks.py @@ -0,0 +1,63 @@ +import json +import urllib.request +import traceback +import math + +FULL_NODE_PORT = 8083 +FULL_NODE_URL = f'http://localhost:{FULL_NODE_PORT}/v1a' +TX_COUNT = 2 +TX_API_URL = f'{FULL_NODE_URL}/transaction?type=tx&count={TX_COUNT}' + +GREEN_COLOR = '\033[92m' +RED_COLOR = '\033[91m' +NO_COLOR = '\033[0m' + +DECIMAL_PLACES = 2 +MAX_OUTPUT_VALUE = 2 ** 63 +ALL_TOKENS = (MAX_OUTPUT_VALUE // (10 ** DECIMAL_PLACES)) * (10 ** DECIMAL_PLACES) +TOKEN_DEPOSIT_PERCENTAGE = 0.01 +DEPOSIT_AMOUNT = math.ceil(ALL_TOKENS * TOKEN_DEPOSIT_PERCENTAGE) +CHANGE_AMOUNT = ALL_TOKENS - DEPOSIT_AMOUNT + + +def print_with_color(text: str, color: str) -> None: + print(f'{color}{text}{NO_COLOR}') + +def run_checks() -> None: + with urllib.request.urlopen(TX_API_URL) as response: + data = response.read().decode('utf-8') + json_dict = json.loads(data) + + print('Checking transaction list...', end=' ') + txs = json_dict['transactions'] + assert len(txs) == 2, 'expected 2 transactions' + print_with_color('success', GREEN_COLOR) + tx0, tx1 = txs + + print('Checking first transaction...', end=' ') + tx1_inputs = tx1['inputs'] + tx1_outputs = tx1['outputs'] + assert len(tx1_inputs) == 1 and len(tx1_outputs), 'expected 1 input and 1 output' + assert tx1_inputs[0]['value'] == ALL_TOKENS and tx1_outputs[0]['value'] == ALL_TOKENS, f'expected value to be {ALL_TOKENS}' + print_with_color('success', GREEN_COLOR) + + print('Checking second transaction...', end=' ') + tx0_id = tx0['tx_id'] + tx0_inputs = tx0['inputs'] + tx0_outputs = tx0['outputs'] + assert len(tx0_inputs) == 1, 'expected 1 input' + assert len(tx0_outputs) == 4, 'expected 4 outputs' + assert tx0_inputs[0]['value'] == ALL_TOKENS, f'expected single input to contain {ALL_TOKENS} HTR' + assert tx0_outputs[0]['token'] == '00', f'expected first output to be HTR' + assert tx0_outputs[0]['value'] == CHANGE_AMOUNT, f'expected first output to contain {CHANGE_AMOUNT} HTR (the change)' + assert tx0_outputs[1]['token'] == tx0_id, f'expected second output to be the custom token' + assert tx0_outputs[1]['value'] == MAX_OUTPUT_VALUE, f'expected second output to contain {MAX_OUTPUT_VALUE} custom tokens' + print_with_color('success', GREEN_COLOR) + +try: + run_checks() + print_with_color('Checks executed successfully.', GREEN_COLOR) +except: + print('\n') + traceback.print_exc() + print_with_color('\nSome checks failed.', RED_COLOR) diff --git a/qa/large-values-network/docker-compose.yml b/qa/large-values-network/docker-compose.yml new file mode 100644 index 00000000..0e689792 --- /dev/null +++ b/qa/large-values-network/docker-compose.yml @@ -0,0 +1,62 @@ +version: "3.9" +services: + + # For more information on these configs, refer to: + # https://github.com/HathorNetwork/rfcs/blob/master/text/0033-private-network-guide.md + + fullnode: + image: + ${HATHOR_LIB_INTEGRATION_TESTS_FULLNODE_IMAGE:-hathornetwork/hathor-core} + command: [ + "run_node", + "--listen", "tcp:40404", + "--status", "8080", + "--test-mode-tx-weight", + "--wallet-index", + "--allow-mining-without-peers", + "--unsafe-mode", "testnet-golf", + "--memory-storage", + "--config-yaml", "privnet/conf/privnet.yml" + ] + ports: + - "8083:8080" + - "40404:40404" + volumes: + - type: bind + source: ./ + target: /privnet/conf + networks: + - hathor-privnet + + tx-mining-service: + image: + ${HATHOR_LIB_INTEGRATION_TESTS_TXMINING_IMAGE:-hathornetwork/tx-mining-service} + depends_on: + - fullnode + ports: + - "8034:8034" # Not mandatory to keep this port open, but helpful for developer machine debugging + - "8035:8035" + command: [ + "http://fullnode:8080", + "--stratum-port=8034", + "--api-port=8035" + ] + networks: + - hathor-privnet + + cpuminer: + image: hathornetwork/cpuminer + depends_on: + - tx-mining-service + command: [ + "-a", "sha256d", + "--coinbase-addr", "WTjhJXzQJETVx7BVXdyZmvk396DRRsubdw", # Refer to test-utils-integration.js, WALLET_CONSTANTS + "-o", "stratum+tcp://tx-mining-service:8034", + "--retry-pause", "5", # 5 seconds between retries + "-t", "1" # Number of threads used to mine + ] + networks: + - hathor-privnet + +networks: + hathor-privnet: diff --git a/qa/large-values-network/privnet.yml b/qa/large-values-network/privnet.yml new file mode 100644 index 00000000..b461027d --- /dev/null +++ b/qa/large-values-network/privnet.yml @@ -0,0 +1,31 @@ +# This file is the Private Network Configuration for the Fullnode +# It is consumed by the docker-compose.yml file on the qa folder. +# For more information, refer to: +# https://github.com/HathorNetwork/rfcs/blob/master/text/0033-private-network-guide.md + +# This genesis adds the funds to the following wallet seed: +# avocado spot town typical traffic vault danger century property shallow divorce festival spend attack anchor afford rotate green audit adjust fade wagon depart level + +extends: testnet.yml + +BOOTSTRAP_DNS: [] + +# Genesis stuff +GENESIS_OUTPUT_SCRIPT: 76a91466665b27f7dbc4c8c089d2f686c170c74d66f0b588ac +GENESIS_BLOCK_TIMESTAMP: 1643902665 +GENESIS_BLOCK_NONCE: 2518838 +GENESIS_BLOCK_HASH: 0000076d916e83de99f9623db91bffe6649606427b848fa0b8e0cbb72c9e87cc +GENESIS_TX1_NONCE: 0 +GENESIS_TX1_HASH: 54165cef1fd4cf2240d702b8383c307c822c16ca407f78014bdefa189a7571c2 +GENESIS_TX2_NONCE: 0 +GENESIS_TX2_HASH: 039906854ce6309b3180945f2a23deb9edff369753f7082e19053f5ac11bfbae + +GENESIS_TOKEN_UNITS: 92233720368547758 +GENESIS_TOKENS: 9223372036854775800 + +MIN_TX_WEIGHT_K: 0 +MIN_TX_WEIGHT_COEFFICIENT: 0 +MIN_TX_WEIGHT: 1 +REWARD_SPEND_MIN_BLOCKS: 1 + +CHECKPOINTS: [] From ed61bf0ae4602c05bd18b5fd8b5574b394e2ea0c Mon Sep 17 00:00:00 2001 From: Tulio Miranda Date: Tue, 7 Jan 2025 19:46:25 -0300 Subject: [PATCH 2/2] Update QA_LARGE_VALUES.md Co-authored-by: Pedro Ferreira --- QA_LARGE_VALUES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QA_LARGE_VALUES.md b/QA_LARGE_VALUES.md index 671e53fb..d94e4af8 100644 --- a/QA_LARGE_VALUES.md +++ b/QA_LARGE_VALUES.md @@ -25,7 +25,7 @@ 3. Put exactly `9223372036854775808` as the "Amount". This is `2^63`, which is the maximum value an output can hold. It should appear as `92,233,720,368,547,758.08` in the input. 4. The deposit should appear as exactly `922,337,203,685,477.60 HTR`. It's not precisely 1% of the requested amount, this is expected. For more information, see [this](https://github.com/HathorNetwork/hathor-wallet-lib/blob/c06d3ce7132efb6e28fe507e94bbc585b65c3d94/src/utils/tokens.ts#L274-L277). 5. Create the token, and the transaction should be successfully created. Return to the main screen. - 6. Go to you newly created token's tab, and check that the total available is exactly `92,233,720,368,547,758.08`. It should contain one transaction in the history with `92,233,720,368,547,758.08` as the value. + 6. Go to your newly created token's tab, and check that the total available is exactly `92,233,720,368,547,758.08`. It should contain one transaction in the history with `92,233,720,368,547,758.08` as the value. 7. Go to the HTR tab, the total available should be exactly `91,311,383,164,862,280.40`, and a new transaction with value `-922,337,203,685,477.60` should appear in the history. 4. Run automated checking script. This is like an integration test, the goal is to check that transactions were created with the correct values in the full node, and that we're not being tricked by display values that may accidentally look the same as the correct value in the wallet. 1. Run `python ./qa/large-values-network/checks.py`.