Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(qa): add large values QA #710

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions QA_LARGE_VALUES.md
Original file line number Diff line number Diff line change
@@ -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 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`.
2. Make sure it outputs `Checks executed successfully.`

## Tear down

1. Run `npm run_qa_network_down`.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions qa/large-values-network/checks.py
Original file line number Diff line number Diff line change
@@ -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)
62 changes: 62 additions & 0 deletions qa/large-values-network/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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}
tuliomir marked this conversation as resolved.
Show resolved Hide resolved
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:
31 changes: 31 additions & 0 deletions qa/large-values-network/privnet.yml
Original file line number Diff line number Diff line change
@@ -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: []
Loading