Skip to content

Commit

Permalink
test: refactor btc address format stacking with bitcoin rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Jan 22, 2024
1 parent eaffd31 commit 9e61b40
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 891 deletions.
102 changes: 44 additions & 58 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
"type": "node",
"request": "launch",
"name": "Launch: mocknet",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
Expand All @@ -46,15 +44,13 @@
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
"request": "launch",
"name": "Launch: w/ postgres",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
Expand All @@ -66,15 +62,13 @@
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
"request": "launch",
"name": "Launch: krypton 2.1",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
Expand All @@ -86,15 +80,13 @@
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
"request": "launch",
"name": "Launch: krypton 2.1-transition",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
Expand All @@ -106,15 +98,13 @@
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
"request": "launch",
"name": "Launch: mocknet write-only",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
Expand All @@ -127,24 +117,15 @@
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
"request": "launch",
"name": "Launch: mocknet offline-mode",
"skipFiles": [
"<node_internals>/**"
],
"runtimeArgs": [
"-r",
"ts-node/register/transpile-only",
"-r",
"tsconfig-paths/register"
],
"args": [
"${workspaceFolder}/src/index.ts"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "stacks-node:start-mocknet",
Expand All @@ -155,24 +136,15 @@
"STACKS_API_MODE": "offline",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
"request": "launch",
"name": "Launch: read-only",
"skipFiles": [
"<node_internals>/**"
],
"runtimeArgs": [
"-r",
"ts-node/register/transpile-only",
"-r",
"tsconfig-paths/register"
],
"args": [
"${workspaceFolder}/src/index.ts"
],
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"env": {
Expand All @@ -182,7 +154,7 @@
"NODE_ENV": "production",
"TS_NODE_SKIP_IGNORE": "true"
},
"killBehavior": "polite",
"killBehavior": "polite"
},
{
"type": "node",
Expand All @@ -205,7 +177,13 @@
"request": "launch",
"name": "Launch: export-events",
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts", "export-events", "--file", "/tmp/test-events-export.csv", "--overwrite-file"],
"args": [
"${workspaceFolder}/src/index.ts",
"export-events",
"--file",
"/tmp/test-events-export.csv",
"--overwrite-file"
],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"env": {
Expand All @@ -218,7 +196,13 @@
"request": "launch",
"name": "Launch: import-events",
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
"args": ["${workspaceFolder}/src/index.ts", "import-events", "--file", "/tmp/test-events-export.csv", "--wipe-db"],
"args": [
"${workspaceFolder}/src/index.ts",
"import-events",
"--file",
"/tmp/test-events-export.csv",
"--wipe-db"
],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"env": {
Expand Down Expand Up @@ -275,7 +259,7 @@
"outputCapture": "std",
"console": "integratedTerminal",
"preLaunchTask": "deploy:krypton",
"postDebugTask": "stop:krypton",
"postDebugTask": "stop:krypton"
},
{
"type": "node",
Expand All @@ -294,7 +278,7 @@
"preLaunchTask": "deploy:subnets",
"postDebugTask": "stop:subnets",
"smartStep": false,
"sourceMaps": true,
"sourceMaps": true
},
{
"type": "node",
Expand All @@ -311,7 +295,7 @@
"outputCapture": "std",
"console": "integratedTerminal",
"preLaunchTask": "deploy:krypton",
"postDebugTask": "stop:krypton",
"postDebugTask": "stop:krypton"
},
{
"type": "node",
Expand All @@ -324,13 +308,15 @@
"--no-cache",
"--config",
"${workspaceRoot}/tests/jest.config.2.5.js",
"-t",
"PoX-4 - Stack using bitcoin address"
],
"outputCapture": "std",
"console": "integratedTerminal",
"preLaunchTask": "deploy:krypton",
"postDebugTask": "stop:krypton",
"smartStep": false,
"sourceMaps": true,
"sourceMaps": true
},
{
"type": "node",
Expand All @@ -342,12 +328,12 @@
"--runInBand",
"--no-cache",
"--config",
"${workspaceRoot}/tests/jest.config.bns.js",
"${workspaceRoot}/tests/jest.config.bns.js"
],
"outputCapture": "std",
"console": "integratedTerminal",
"preLaunchTask": "deploy:krypton",
"postDebugTask": "stop:krypton",
"postDebugTask": "stop:krypton"
},
{
"type": "node",
Expand All @@ -359,12 +345,12 @@
"--runInBand",
"--no-cache",
"--config",
"${workspaceRoot}/tests/jest.config.bns-e2e.js",
"${workspaceRoot}/tests/jest.config.bns-e2e.js"
],
"outputCapture": "std",
"console": "integratedTerminal",
"preLaunchTask": "deploy:krypton",
"postDebugTask": "stop:krypton",
"postDebugTask": "stop:krypton"
},
{
"type": "node",
Expand All @@ -383,7 +369,7 @@
"preLaunchTask": "deploy:krypton",
"postDebugTask": "stop:krypton",
"smartStep": false,
"sourceMaps": true,
"sourceMaps": true
},
{
"type": "node",
Expand Down Expand Up @@ -475,7 +461,7 @@
"runtimeArgs": ["-r", "ts-node/register/transpile-only"],
"cwd": "${workspaceFolder}/utils",
"args": ["${workspaceFolder}/utils/src/chaintip-cache-control-test.ts"]
},
}
],
"compounds": [
{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"@stacks/network": "6.8.1",
"@stacks/stacking": "6.11.2-pr.64326b1.0",
"@stacks/transactions": "6.9.0",
"@types/express-list-endpoints": "4.0.1",
"@types/express-list-endpoints": "6.0.3",
"@types/lru-cache": "5.1.1",
"@types/ws": "7.4.7",
"ajv": "6.12.6",
Expand Down Expand Up @@ -159,7 +159,7 @@
"@types/cors": "2.8.12",
"@types/dotenv-flow": "3.2.0",
"@types/elliptic": "6.4.14",
"@types/express": "4.17.13",
"@types/express": "4.17.21",
"@types/is-ci": "3.0.0",
"@types/jest": "29.5.6",
"@types/node": "18.13.0",
Expand Down
1 change: 1 addition & 0 deletions src/datastore/pg-write-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import {
isProdEnv,
isTestEnv,
runMigrations,
timeout,
} from '@hirosystems/api-toolkit';
import { PgServer, getConnectionArgs, getConnectionConfig } from './connection';

Expand Down
5 changes: 4 additions & 1 deletion src/ec-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ interface KeyOutput {
ecPair: ECPairInterface;
}

function ecPairFromKeyInputArgs(args: KeyInputArgs, allowXOnlyPubkey = false): ECPairInterface {
export function ecPairFromKeyInputArgs(
args: KeyInputArgs,
allowXOnlyPubkey = false
): ECPairInterface {
const network = BITCOIN_NETWORKS[args.network];
if ('privateKey' in args) {
let keyBuff = coerceToBuffer(args.privateKey);
Expand Down
5 changes: 2 additions & 3 deletions src/test-utils/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ import { coerceToBuffer, hexToBuffer, runMigrations, timeout } from '@hirosystem
import { MIGRATIONS_DIR } from '../datastore/pg-store';
import { getConnectionArgs } from '../datastore/connection';

/** A (buff 33) signer key of all zeroes, to be used for testing */
export const ZERO_SIGNER_KEY_BYTES = hexToBytes('00'.repeat(33));

export async function migrate(direction: 'up' | 'down') {
await runMigrations(MIGRATIONS_DIR, direction, getConnectionArgs());
}
Expand Down Expand Up @@ -137,6 +134,7 @@ export function accountFromKey(
return { secretKey, pubKey, stxAddr, poxAddr, poxAddrClar, btcAddr, btcTestnetAddr, wif };
}

/** Stand by until prepare phase of next pox cycle (still in current cycle) */
export async function standByForNextPoxCycle(): Promise<CoreRpcPoxInfo> {
const firstPoxInfo = await testEnv.client.getPox();
await standByUntilBurnBlock(firstPoxInfo.next_cycle.prepare_phase_start_block_height);
Expand All @@ -151,6 +149,7 @@ export async function standByForNextPoxCycle(): Promise<CoreRpcPoxInfo> {
return lastPoxInfo;
}

/** Stand by until `current_cycle.id` increases */
export async function standByForPoxCycle(
apiArg?: ApiServer,
clientArg?: StacksCoreRpcClient
Expand Down
Loading

0 comments on commit 9e61b40

Please sign in to comment.