From c13fb8a9ea5b81712d78c4fa38a77f7b8a59f9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Wed, 25 Sep 2024 08:21:34 -0600 Subject: [PATCH] test: refactor and optimize test suites (#2086) * refactor: move files * fix: bns * fix: event replay * fix: rpc * fix: faucet * fix: 2.5 * fix: rosetta construction * fix: rosetta cli * ci: workflow * fix: some issues * fix: upgrade gh actions * fix: some * fix: rosetta jest * ci: try without var print * fix: api tests * fix: try more timeout for bns e2e --- .eslintignore | 5 - .github/workflows/ci.yml | 582 +-------- .vscode/launch.json | 4 +- docker/docker-compose.dev.postgres.yml | 2 +- package.json | 28 +- src/api/routes/faucets.ts | 24 +- src/helpers.ts | 20 + src/tests-bns/event-server-tests.ts | 1026 ---------------- .../2.5/block-zero-handling.test.ts | 10 +- {src/tests-2.5 => tests/2.5}/env-setup.ts | 10 +- .../2.5/faucet-stx.test.ts | 6 +- {src/tests-2.5 => tests/2.5}/global-setup.ts | 10 +- .../2.5}/global-teardown.ts | 0 .../2.5/pox-4-btc-address-formats.test.ts | 16 +- .../2.5/pox-4-burnchain-delegate-stx.test.ts | 24 +- .../2.5/pox-4-burnchain-stack-stx.test.ts | 22 +- .../2.5/pox-4-delegate-aggregation.test.ts | 10 +- .../pox-4-delegate-revoked-stacking.test.ts | 12 +- .../2.5/pox-4-delegate-stacking.test.ts | 10 +- .../2.5/pox-4-rosetta-btc-addr-types.test.ts | 12 +- .../2.5/pox-4-rosetta-cycle-phases.test.ts | 6 +- .../2.5/pox-4-rosetta-segwit.test.ts | 11 +- .../2.5/pox-4-stack-extend-increase.test.ts | 16 +- .../api/address.test.ts | 16 +- .../block-tests.ts => tests/api/block.test.ts | 14 +- .../api/burnchain.test.ts | 8 +- .../api/cache-control.test.ts | 22 +- .../api/datastore.test.ts | 13 +- .../mainnet-out-of-order-microblock.tsv | 0 .../mainnet-reorg-scenario1.tsv | 0 .../mainnet-reorg-scenario2.tsv | 0 .../api/faucet-stx.test.ts | 2 +- .../api/helpers.test.ts | 9 +- .../api/import-genesis.test.ts | 6 +- .../api/mempool.test.ts | 14 +- .../api/microblock.test.ts | 32 +- .../other-tests.ts => tests/api/other.test.ts | 14 +- .../api/out-of-order-multisig.test.ts | 16 +- .../api/pagination.test.ts | 2 +- .../api/parse-db-tx.test.ts | 0 .../pox-tests.ts => tests/api/pox.test.ts | 16 +- .../api/profiler.test.ts | 4 +- .../api/search.test.ts | 10 +- .../tests-event-replay => tests/api}/setup.ts | 2 +- .../api/smart-contract.test.ts | 12 +- .../api/socket-io.test.ts | 10 +- .../api/synthetic-stx-txs.test.ts | 6 +- ...0e7d900bc66701751037f8b92dd7f8fd2a1b0.json | 0 ...6d5091a96e90fbb156d25427c1a2e7ea1d6fd.json | 0 ...872f672cf10d873852b5218f41594d6b42b11.json | 0 ...904c355a501d6dffa3b5e4799083062469dbc.json | 0 ...a0b7aeb89e2521b2a2218d887477baa1775c9.json | 0 ...28314497f52bd22b8bcbf87a12c764dd9d9be.json | 0 ...c8f15945965a51976ac6697641003533986f6.json | 0 .../api}/teardown.ts | 0 {src/tests => tests/api}/test-helpers.ts | 4 - .../token-tests.ts => tests/api/token.test.ts | 10 +- .../api}/tsv/epoch-3-transition.tsv | 0 ...est-env-pox-4-out-of-order-multisig-tx.tsv | 0 ...env-pox-4-stack-stx-in-reward-phase-S1.tsv | 0 ...env-pox-4-stack-stx-in-reward-phase-S2.tsv | 0 ...env-pox-4-stack-stx-in-reward-phase-S3.tsv | 0 src/tests/tx-tests.ts => tests/api/tx.test.ts | 22 +- .../api/v2-proxy.test.ts | 8 +- .../api/websocket.test.ts | 10 +- .../api/ws-transmitter.test.ts | 8 +- .../bns-e2e/bns-integration.test.ts | 10 +- {src/tests-bns-e2e => tests/bns-e2e}/setup.ts | 2 +- .../bns-e2e}/teardown.ts | 2 +- src/tests-bns/api.ts => tests/bns/api.test.ts | 129 +- .../bns/bns-helpers.test.ts | 2 +- tests/bns/event-server.test.ts | 1073 +++++++++++++++++ .../bns}/import-test-files/chainstate.txt | 0 .../import-test-files/chainstate.txt.sha256 | 0 .../bns}/import-test-files/name_zonefiles.txt | 0 .../name_zonefiles.txt.sha256 | 0 .../import-test-files/subdomain_zonefiles.txt | 0 .../subdomain_zonefiles.txt.sha256 | 0 .../bns}/import-test-files/subdomains.csv | 0 .../import-test-files/subdomains.csv.sha256 | 0 {src/tests-rpc => tests/bns}/setup.ts | 2 +- {src/tests-bns => tests/bns}/teardown.ts | 2 +- .../bns/v1-import.test.ts | 163 ++- .../btc-faucet/faucet-btc.test.ts | 12 +- .../btc-faucet}/setup.ts | 4 +- {src/tests => tests/btc-faucet}/teardown.ts | 0 .../event-replay/helper.test.ts | 4 +- .../event-replay/import-export.test.ts | 55 +- .../event-replay/poison-microblock.test.ts | 6 +- .../event-replay/raw-event-request.test.ts | 16 +- {src/tests => tests/event-replay}/setup.ts | 2 +- .../event-replay}/teardown.ts | 0 .../event-replay}/tsv/mainnet-block0.tsv | 0 .../event-replay}/tsv/mainnet.tsv | 0 .../event-replay}/tsv/mocknet.tsv | 0 .../event-replay}/tsv/poisonmicroblock.tsv | 0 tests/jest.config.2.5.js | 21 +- tests/jest.config.api.js | 10 + tests/jest.config.bns-e2e.js | 16 +- tests/jest.config.bns.js | 20 +- tests/jest.config.btc-faucet.js | 20 +- tests/jest.config.event-replay.js | 17 +- tests/jest.config.js | 12 - tests/jest.config.rosetta-cli-construction.js | 14 +- tests/jest.config.rosetta-cli-data.js | 14 +- tests/jest.config.rosetta-construction.js | 14 +- tests/jest.config.rosetta.js | 14 +- tests/jest.config.rpc.js | 14 +- tests/jest.config.subnets.js | 24 +- .../envs/env.construction | 0 .../rosetta-cli-construction}/setup.ts | 6 +- .../rosetta-cli-construction}/teardown.ts | 0 .../validate-construction.test.ts | 16 +- .../contracts/hello-world.clar | 0 .../rosetta-cli-data}/envs/env.data | 0 .../rosetta-cli-data}/setup.ts | 4 +- .../rosetta-cli-data}/teardown.ts | 0 .../rosetta-cli-data/validate-rosetta.test.ts | 20 +- .../rosetta-construction/construction.test.ts | 20 +- .../rosetta-construction}/setup.ts | 2 +- .../rosetta-construction}/teardown.ts | 2 +- .../rosetta/account.test.ts | 40 +- .../api.ts => tests/rosetta/api.test.ts | 546 +++++---- .../rosetta/block.test.ts | 204 ++-- .../rosetta/disable-api.test.ts | 10 +- .../rosetta/offline-api.test.ts | 39 +- {src/tests-rosetta => tests/rosetta}/setup.ts | 4 +- {src/tests-rpc => tests/rosetta}/teardown.ts | 2 +- .../rpc/core-rpc.test.ts | 2 +- {src/tests-bns => tests/rpc}/setup.ts | 2 +- {src/tests-rosetta => tests/rpc}/teardown.ts | 2 +- .../subnets}/env-setup.ts | 10 +- .../subnets}/global-setup.ts | 12 +- .../subnets}/global-teardown.ts | 0 .../subnets}/l1-contracts/nft-trait.clar | 0 .../subnets}/l1-contracts/simple-ft-l1.clar | 0 .../subnets}/l1-contracts/simple-nft-l1.clar | 0 .../sip-010-trait-ft-standard.clar | 0 .../subnets}/l1-contracts/sip-traits.clar | 0 .../subnets}/l1-contracts/subnet-traits.clar | 0 .../subnets}/l1-contracts/subnet.clar | 0 .../subnets}/l2-contracts/simple-ft-l2.clar | 0 .../subnets}/l2-contracts/simple-nft-l2.clar | 0 .../subnets}/l2-contracts/simple-stx-l2.clar | 0 .../subnets}/set-env.ts | 0 .../subnets/subnet.test.ts | 11 +- .../utils}/shared-setup.ts | 8 +- .../utils}/test-builders.ts | 4 +- .../utils}/test-helpers.ts | 33 +- tsconfig.build.json | 2 +- tsconfig.json | 7 +- 151 files changed, 2237 insertions(+), 2621 deletions(-) delete mode 100644 src/tests-bns/event-server-tests.ts rename src/tests-2.5/block-zero-handling.ts => tests/2.5/block-zero-handling.test.ts (95%) rename {src/tests-2.5 => tests/2.5}/env-setup.ts (83%) rename src/tests-2.5/faucet-stx.ts => tests/2.5/faucet-stx.test.ts (91%) rename {src/tests-2.5 => tests/2.5}/global-setup.ts (82%) rename {src/tests-2.5 => tests/2.5}/global-teardown.ts (100%) rename src/tests-2.5/pox-4-btc-address-formats.ts => tests/2.5/pox-4-btc-address-formats.test.ts (97%) rename src/tests-2.5/pox-4-burnchain-delegate-stx.ts => tests/2.5/pox-4-burnchain-delegate-stx.test.ts (96%) rename src/tests-2.5/pox-4-burnchain-stack-stx.ts => tests/2.5/pox-4-burnchain-stack-stx.test.ts (95%) rename src/tests-2.5/pox-4-delegate-aggregation.ts => tests/2.5/pox-4-delegate-aggregation.test.ts (98%) rename src/tests-2.5/pox-4-delegate-revoked-stacking.ts => tests/2.5/pox-4-delegate-revoked-stacking.test.ts (98%) rename src/tests-2.5/pox-4-delegate-stacking.ts => tests/2.5/pox-4-delegate-stacking.test.ts (98%) rename src/tests-2.5/pox-4-rosetta-btc-addr-types.ts => tests/2.5/pox-4-rosetta-btc-addr-types.test.ts (88%) rename src/tests-2.5/pox-4-rosetta-cycle-phases.ts => tests/2.5/pox-4-rosetta-cycle-phases.test.ts (93%) rename src/tests-2.5/pox-4-rosetta-segwit.ts => tests/2.5/pox-4-rosetta-segwit.test.ts (97%) rename src/tests-2.5/pox-4-stack-extend-increase.ts => tests/2.5/pox-4-stack-extend-increase.test.ts (97%) rename src/tests/address-tests.ts => tests/api/address.test.ts (99%) rename src/tests/block-tests.ts => tests/api/block.test.ts (99%) rename src/tests/burnchain-tests.ts => tests/api/burnchain.test.ts (98%) rename src/tests/cache-control-tests.ts => tests/api/cache-control.test.ts (97%) rename src/tests/datastore-tests.ts => tests/api/datastore.test.ts (99%) rename {src/tests => tests/api}/event-replay-logs/mainnet-out-of-order-microblock.tsv (100%) rename {src/tests => tests/api}/event-replay-logs/mainnet-reorg-scenario1.tsv (100%) rename {src/tests => tests/api}/event-replay-logs/mainnet-reorg-scenario2.tsv (100%) rename src/tests/faucet-stx-tests.ts => tests/api/faucet-stx.test.ts (92%) rename src/tests/helpers-tests.ts => tests/api/helpers.test.ts (98%) rename src/tests/import-genesis-tests.ts => tests/api/import-genesis.test.ts (92%) rename src/tests/mempool-tests.ts => tests/api/mempool.test.ts (99%) rename src/tests/microblock-tests.ts => tests/api/microblock.test.ts (96%) rename src/tests/other-tests.ts => tests/api/other.test.ts (96%) rename src/tests/out-of-order-multisig-tests.ts => tests/api/out-of-order-multisig.test.ts (79%) rename src/tests/pagination-tests.ts => tests/api/pagination.test.ts (96%) rename src/tests/parse-db-tx.ts => tests/api/parse-db-tx.test.ts (100%) rename src/tests/pox-tests.ts => tests/api/pox.test.ts (95%) rename src/tests/profiler-tests.ts => tests/api/profiler.test.ts (93%) rename src/tests/search-tests.ts => tests/api/search.test.ts (99%) rename {src/tests-event-replay => tests/api}/setup.ts (84%) rename src/tests/smart-contract-tests.ts => tests/api/smart-contract.test.ts (99%) rename src/tests/socket-io-tests.ts => tests/api/socket-io.test.ts (98%) rename src/tests/synthetic-stx-txs-tests.ts => tests/api/synthetic-stx-txs.test.ts (98%) rename {src/tests => tests/api}/synthetic-tx-payloads/failed-1352-0x2d825fbeb5368dcaeecdce053860e7d900bc66701751037f8b92dd7f8fd2a1b0.json (100%) rename {src/tests => tests/api}/synthetic-tx-payloads/failed-6910-0x763e485177d772efdb1baede3276d5091a96e90fbb156d25427c1a2e7ea1d6fd.json (100%) rename {src/tests => tests/api}/synthetic-tx-payloads/stx_lock-1379-0xb182e2aacfe2ed4257d66dd2ed4872f672cf10d873852b5218f41594d6b42b11.json (100%) rename {src/tests => tests/api}/synthetic-tx-payloads/stx_lock-1994-0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc.json (100%) rename {src/tests => tests/api}/synthetic-tx-payloads/stx_lock-51451-0xa64ad136e51a3a50eb1fdfd7eefa0b7aeb89e2521b2a2218d887477baa1775c9.json (100%) rename {src/tests => tests/api}/synthetic-tx-payloads/token_transfer-120-0xc0263c14f689ae757290f90765a28314497f52bd22b8bcbf87a12c764dd9d9be.json (100%) rename {src/tests => tests/api}/synthetic-tx-payloads/token_transfer-51655-0x2553c7c5b49eab5a0569e5d0f14c8f15945965a51976ac6697641003533986f6.json (100%) rename {src/tests-btc-faucet => tests/api}/teardown.ts (100%) rename {src/tests => tests/api}/test-helpers.ts (91%) rename src/tests/token-tests.ts => tests/api/token.test.ts (99%) rename {src/tests => tests/api}/tsv/epoch-3-transition.tsv (100%) rename {src/tests => tests/api}/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv (100%) rename {src/tests => tests/api}/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv (100%) rename {src/tests => tests/api}/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv (100%) rename {src/tests => tests/api}/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv (100%) rename src/tests/tx-tests.ts => tests/api/tx.test.ts (99%) rename src/tests/v2-proxy-tests.ts => tests/api/v2-proxy.test.ts (94%) rename src/tests/websocket-tests.ts => tests/api/websocket.test.ts (98%) rename src/tests/ws-transmitter-tests.ts => tests/api/ws-transmitter.test.ts (85%) rename src/tests-bns-e2e/bns-integration-tests.ts => tests/bns-e2e/bns-integration.test.ts (98%) rename {src/tests-bns-e2e => tests/bns-e2e}/setup.ts (72%) rename {src/tests-bns-e2e => tests/bns-e2e}/teardown.ts (72%) rename src/tests-bns/api.ts => tests/bns/api.test.ts (93%) rename src/tests-bns/bns-helpers-tests.ts => tests/bns/bns-helpers.test.ts (99%) create mode 100644 tests/bns/event-server.test.ts rename {src/tests-bns => tests/bns}/import-test-files/chainstate.txt (100%) rename {src/tests-bns => tests/bns}/import-test-files/chainstate.txt.sha256 (100%) rename {src/tests-bns => tests/bns}/import-test-files/name_zonefiles.txt (100%) rename {src/tests-bns => tests/bns}/import-test-files/name_zonefiles.txt.sha256 (100%) rename {src/tests-bns => tests/bns}/import-test-files/subdomain_zonefiles.txt (100%) rename {src/tests-bns => tests/bns}/import-test-files/subdomain_zonefiles.txt.sha256 (100%) rename {src/tests-bns => tests/bns}/import-test-files/subdomains.csv (100%) rename {src/tests-bns => tests/bns}/import-test-files/subdomains.csv.sha256 (100%) rename {src/tests-rpc => tests/bns}/setup.ts (75%) rename {src/tests-bns => tests/bns}/teardown.ts (72%) rename src/tests-bns/v1-import-tests.ts => tests/bns/v1-import.test.ts (51%) rename src/tests-btc-faucet/faucet-btc-tests.ts => tests/btc-faucet/faucet-btc.test.ts (95%) rename {src/tests-btc-faucet => tests/btc-faucet}/setup.ts (87%) rename {src/tests => tests/btc-faucet}/teardown.ts (100%) rename src/tests-event-replay/helper-tests.ts => tests/event-replay/helper.test.ts (96%) rename src/tests-event-replay/import-export-tests.ts => tests/event-replay/import-export.test.ts (80%) rename src/tests-event-replay/poison-microblock-tests.ts => tests/event-replay/poison-microblock.test.ts (87%) rename src/tests-event-replay/raw-event-request-tests.ts => tests/event-replay/raw-event-request.test.ts (91%) rename {src/tests => tests/event-replay}/setup.ts (84%) rename {src/tests-event-replay => tests/event-replay}/teardown.ts (100%) rename {src/tests-event-replay => tests/event-replay}/tsv/mainnet-block0.tsv (100%) rename {src/tests-event-replay => tests/event-replay}/tsv/mainnet.tsv (100%) rename {src/tests-event-replay => tests/event-replay}/tsv/mocknet.tsv (100%) rename {src/tests-event-replay => tests/event-replay}/tsv/poisonmicroblock.tsv (100%) create mode 100644 tests/jest.config.api.js delete mode 100644 tests/jest.config.js rename {src/tests-rosetta-cli-construction => tests/rosetta-cli-construction}/envs/env.construction (100%) rename {src/tests-rosetta-cli-construction => tests/rosetta-cli-construction}/setup.ts (74%) rename {src/tests-rosetta-cli-construction => tests/rosetta-cli-construction}/teardown.ts (100%) rename src/tests-rosetta-cli-construction/validate-construction.ts => tests/rosetta-cli-construction/validate-construction.test.ts (90%) rename {src/tests-rosetta-cli-data => tests/rosetta-cli-data}/contracts/hello-world.clar (100%) rename {src/tests-rosetta-cli-data => tests/rosetta-cli-data}/envs/env.data (100%) rename {src/tests-rosetta-cli-data => tests/rosetta-cli-data}/setup.ts (82%) rename {src/tests-rosetta-cli-data => tests/rosetta-cli-data}/teardown.ts (100%) rename src/tests-rosetta-cli-data/validate-rosetta.ts => tests/rosetta-cli-data/validate-rosetta.test.ts (94%) rename src/tests-rosetta-construction/construction.ts => tests/rosetta-construction/construction.test.ts (99%) rename {src/tests-rosetta-construction => tests/rosetta-construction}/setup.ts (72%) rename {src/tests-rosetta-construction => tests/rosetta-construction}/teardown.ts (74%) rename src/tests-rosetta/account-tests.ts => tests/rosetta/account.test.ts (76%) rename src/tests-rosetta/api.ts => tests/rosetta/api.test.ts (85%) rename src/tests-rosetta/block-tests.ts => tests/rosetta/block.test.ts (80%) rename src/tests-rosetta/disable-api.ts => tests/rosetta/disable-api.test.ts (74%) rename src/tests-rosetta/offline-api-tests.ts => tests/rosetta/offline-api.test.ts (97%) rename {src/tests-rosetta => tests/rosetta}/setup.ts (60%) rename {src/tests-rpc => tests/rosetta}/teardown.ts (74%) rename src/tests-rpc/core-rpc-tests.ts => tests/rpc/core-rpc.test.ts (92%) rename {src/tests-bns => tests/rpc}/setup.ts (75%) rename {src/tests-rosetta => tests/rpc}/teardown.ts (74%) rename {src/tests-subnets => tests/subnets}/env-setup.ts (85%) rename {src/tests-subnets => tests/subnets}/global-setup.ts (82%) rename {src/tests-subnets => tests/subnets}/global-teardown.ts (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/nft-trait.clar (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/simple-ft-l1.clar (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/simple-nft-l1.clar (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/sip-010-trait-ft-standard.clar (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/sip-traits.clar (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/subnet-traits.clar (100%) rename {src/tests-subnets => tests/subnets}/l1-contracts/subnet.clar (100%) rename {src/tests-subnets => tests/subnets}/l2-contracts/simple-ft-l2.clar (100%) rename {src/tests-subnets => tests/subnets}/l2-contracts/simple-nft-l2.clar (100%) rename {src/tests-subnets => tests/subnets}/l2-contracts/simple-stx-l2.clar (100%) rename {src/tests-subnets => tests/subnets}/set-env.ts (100%) rename src/tests-subnets/subnet-tests.ts => tests/subnets/subnet.test.ts (99%) rename {src/test-utils => tests/utils}/shared-setup.ts (90%) rename {src/test-utils => tests/utils}/test-builders.ts (99%) rename {src/test-utils => tests/utils}/test-helpers.ts (95%) diff --git a/.eslintignore b/.eslintignore index ab5411dd7a..3779c12035 100644 --- a/.eslintignore +++ b/.eslintignore @@ -8,11 +8,6 @@ scripts/ stacks-blockchain/ src/schemas/* docs/ -#client/ -#src/tests/ -src/tests-rosetta/ -src/tests-rosetta-cli/ -src/tests-bns/ client/src/ config/ utils/src/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52d2b8048b..83b0024e17 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v4 @@ -27,7 +27,7 @@ jobs: node-version-file: ".nvmrc" - name: Cache node modules - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-node-modules with: @@ -53,9 +53,22 @@ jobs: run: npm run lint:unused-exports test: + strategy: + fail-fast: false + matrix: + suite: + [ + api, + bns, + bns-e2e, + btc-faucet, + event-replay, + rpc, + # subnets, + ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v4 @@ -63,7 +76,7 @@ jobs: node-version-file: ".nvmrc" - name: Cache node modules - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-node-modules with: @@ -86,188 +99,12 @@ jobs: - name: Setup env vars run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy -- -d - npm run devenv:logs -- --no-color &> docker-compose-logs.txt & - - - name: Run tests - run: npm run test - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-event-replay: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup integration environment + - name: Setup replay directories + if: matrix.suite == 'event-replay' run: | - sudo ufw disable - mkdir -p src/tests-event-replay/.tmp/local/ - sudo chown 999:999 src/tests-event-replay/.tmp/local/ - sudo chmod -R 777 src/tests-event-replay/.tmp/local/ - docker compose -f docker/docker-compose.dev.postgres.yml up -d - npm run devenv:logs -- --no-color &> docker-compose-logs.txt & - - - name: Run RPC tests - run: npm run test:event-replay - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-rpc: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV - - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy-krypton -- -d - npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - - - name: Run RPC tests - run: npm run test:rpc - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop-krypton - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-btc-faucet: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV + mkdir -p tests/event-replay/.tmp/local/ + sudo chown 999:999 tests/event-replay/.tmp/local/ + sudo chmod -R 777 tests/event-replay/.tmp/local/ - name: Setup integration environment run: | @@ -275,8 +112,8 @@ jobs: npm run devenv:deploy -- -d npm run devenv:logs -- --no-color &> docker-compose-logs.txt & - - name: Run btc faucet tests - run: npm run test:btc-faucet + - name: Run tests + run: npm run test:${{ matrix.suite }} -- --coverage - name: Print integration environment logs run: cat docker-compose-logs.txt @@ -292,136 +129,6 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} if: always() - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-bns: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV - - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy-krypton -- -d - npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - - - name: Run bns tests - run: npm run test:bns - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop-krypton - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-bns-e2e: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV - - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy-krypton -- -d - npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - - - name: Run bns tests - run: npm run test:bns-e2e - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop-krypton - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - test-2_5: strategy: fail-fast: false @@ -443,7 +150,7 @@ jobs: ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v4 @@ -451,7 +158,7 @@ jobs: node-version-file: ".nvmrc" - name: Cache node modules - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-node-modules with: @@ -477,7 +184,7 @@ jobs: npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - name: Run tests - run: npm run test:2.5 -- --testPathPattern "${{ matrix.suite }}" + run: npm run test:2.5 -- --testPathPattern "${{ matrix.suite }}" --coverage - name: Print integration environment logs run: cat docker-compose-logs.txt @@ -493,79 +200,20 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} if: always() - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - test-rosetta: + strategy: + fail-fast: false + matrix: + suite: + [ + rosetta, + rosetta-construction, + rosetta-cli-data, + rosetta-cli-construction, + ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV - - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy-krypton -- -d - npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - - - name: Run tests - run: npm run test:rosetta - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop-krypton - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-rosetta-construction: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js uses: actions/setup-node@v4 @@ -573,7 +221,7 @@ jobs: node-version-file: ".nvmrc" - name: Cache node modules - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-node-modules with: @@ -592,68 +240,8 @@ jobs: - name: Setup env vars run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy-krypton -- -d - npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - - - name: Run tests - run: npm run test:rosetta-construction - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop-krypton - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-rosetta-cli-data: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0">> $GITHUB_ENV - - - name: Setup cli enviroment variable + - name: Setup CLI env vars + if: contains(matrix.suite, 'cli') run: | echo STACKS_BLOCKCHAIN_API_HOST=0.0.0.0>> .env echo STACKS_CORE_PROXY_HOST=0.0.0.0 >> .env @@ -668,7 +256,7 @@ jobs: npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - name: Run tests - run: sudo npm run test:rosetta-cli:data + run: npm run test:${{ matrix.suite }} -- --coverage - name: Print integration environment logs run: cat docker-compose-logs.txt @@ -684,87 +272,15 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} if: always() - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - - test-rosetta-cli-construction: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - path: | - ~/.npm - **/node_modules - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install deps - run: npm ci --audit=false - - - name: Setup env vars - run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0">> $GITHUB_ENV - - - name: Setup cli enviroment variable - run: | - echo STACKS_BLOCKCHAIN_API_HOST=0.0.0.0>> .env - echo STACKS_CORE_PROXY_HOST=0.0.0.0 >> .env - echo STACKS_CORE_RPC_HOST=0.0.0.0 >> .env - echo STACKS_CORE_EVENT_HOST=0.0.0.0 >> .env - echo BTC_RPC_HOST=http://0.0.0.0 >> .env - - - name: Setup integration environment - run: | - sudo ufw disable - npm run devenv:deploy-krypton -- -d - npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt & - - - name: Run tests - run: sudo npm run test:rosetta-cli:construction - - - name: Print integration environment logs - run: cat docker-compose-logs.txt - if: failure() - - - name: Teardown integration environment - run: npm run devenv:stop-krypton - if: always() - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: always() - - - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - if: ${{ false }} - with: - github-token: ${{ secrets.github_token }} - flag-name: run-${{ github.job }} - parallel: true - build-publish: runs-on: ubuntu-latest + needs: + - lint + - test + - test-2_5 + - test-rosetta steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} fetch-depth: 0 @@ -775,7 +291,7 @@ jobs: node-version-file: ".nvmrc" - name: Semantic Release - uses: cycjimmy/semantic-release-action@v3 + uses: cycjimmy/semantic-release-action@v4 id: semantic # Only run on non-PR events or only PRs that aren't from forks if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository diff --git a/.vscode/launch.json b/.vscode/launch.json index 31cefea2ca..1a90b38bbe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -229,14 +229,14 @@ { "type": "node", "request": "launch", - "name": "Jest", + "name": "Jest: API", "program": "${workspaceFolder}/node_modules/.bin/jest", "args": [ "--testTimeout=3600000", "--runInBand", "--no-cache", "--config", - "${workspaceRoot}/tests/jest.config.js" + "${workspaceRoot}/tests/jest.config.api.js" ], "outputCapture": "std", "console": "integratedTerminal", diff --git a/docker/docker-compose.dev.postgres.yml b/docker/docker-compose.dev.postgres.yml index 316fbab99e..c2d1aacf7c 100644 --- a/docker/docker-compose.dev.postgres.yml +++ b/docker/docker-compose.dev.postgres.yml @@ -9,4 +9,4 @@ services: POSTGRES_DB: stacks_blockchain_api POSTGRES_PORT: 5432 volumes: - - ../src/tests-event-replay/.tmp/local/:/root/ + - ../tests/event-replay/.tmp/local/:/root/ diff --git a/package.json b/package.json index 38e7795f22..308683eb1b 100644 --- a/package.json +++ b/package.json @@ -7,21 +7,19 @@ "dev:watch": "cross-env NODE_ENV=development nodemon -e ts -x 'ts-node-transpile-only src/index.ts'", "dev:integrated": "npm run devenv:build && concurrently npm:dev npm:devenv:deploy", "dev:follower": "npm run devenv:build && concurrently npm:dev npm:devenv:follower", - "test": "cross-env NODE_ENV=test jest --config ./tests/jest.config.js --coverage --runInBand", - "test:subnets": "cross-env NODE_ENV=test jest --config ./tests/jest.config.subnets.js --coverage --runInBand", - "test:2.5": "cross-env NODE_ENV=test jest --config ./tests/jest.config.2.5.js --coverage --runInBand", - "test:rosetta": "cross-env NODE_ENV=test jest --config ./tests/jest.config.rosetta.js --coverage --runInBand", - "test:rosetta-construction": "cross-env NODE_ENV=test jest --config ./tests/jest.config.rosetta-construction.js --coverage --runInBand", - "test:rosetta-cli:data": "cross-env NODE_ENV=test STACKS_CHAIN_ID=0x80000000 jest --config ./tests/jest.config.rosetta-cli-data.js --coverage --runInBand", - "test:rosetta-cli:construction": "cross-env NODE_ENV=test STACKS_CHAIN_ID=0x80000000 jest --config ./tests/jest.config.rosetta-cli-construction.js --coverage --runInBand", - "test:bns": "cross-env NODE_ENV=test jest --config ./tests/jest.config.bns.js --coverage --runInBand", - "test:bns-e2e": "cross-env NODE_ENV=test jest --config ./tests/jest.config.bns-e2e.js --coverage --runInBand", - "test:rpc": "cross-env NODE_ENV=test jest --config ./tests/jest.config.rpc.js --coverage --runInBand", - "test:event-replay": "cross-env NODE_ENV=test jest --config ./tests/jest.config.event-replay.js --coverage --runInBand", - "test:btc-faucet": "cross-env NODE_ENV=test jest --config ./tests/jest.config.btc-faucet.js --coverage --runInBand", - "test:tokens-metadata": "cross-env NODE_ENV=test jest --config ./tests/jest.config.tokens-metadata.js --coverage --runInBand", - "test:tokens-strict": "cross-env NODE_ENV=test jest --config ./tests/jest.config.tokens-strict.js --coverage --runInBand", - "test:watch": "cross-env NODE_ENV=test jest --config ./tests/jest.config.js --watch", + "test": "cross-env NODE_ENV=test jest --runInBand", + "test:api": "npm run test -- --config ./tests/jest.config.api.js", + "test:subnets": "npm run test -- --config ./tests/jest.config.subnets.js", + "test:2.5": "npm run test -- --config ./tests/jest.config.2.5.js", + "test:rosetta": "npm run test -- --config ./tests/jest.config.rosetta.js", + "test:rosetta-construction": "npm run test -- --config ./tests/jest.config.rosetta-construction.js", + "test:rosetta-cli-data": "STACKS_CHAIN_ID=0x80000000 npm run test -- --config ./tests/jest.config.rosetta-cli-data.js", + "test:rosetta-cli-construction": "STACKS_CHAIN_ID=0x80000000 npm run test -- --config ./tests/jest.config.rosetta-cli-construction.js", + "test:bns": "npm run test -- --config ./tests/jest.config.bns.js", + "test:bns-e2e": "npm run test -- --config ./tests/jest.config.bns-e2e.js", + "test:rpc": "npm run test -- --config ./tests/jest.config.rpc.js", + "test:event-replay": "npm run test -- --config ./tests/jest.config.event-replay.js", + "test:btc-faucet": "npm run test -- --config ./tests/jest.config.btc-faucet.js", "test:integration": "concurrently \"docker compose -f docker/docker-compose.dev.postgres.yml up --force-recreate -V\" \"cross-env NODE_ENV=test jest --config ./tests/jest.config.js --no-cache --runInBand; npm run devenv:stop:pg\"", "test:integration:subnets": "concurrently --hide \"devenv:deploy:subnets\" \"npm:devenv:deploy:subnets\" \"cross-env NODE_ENV=test jest --config ./tests/jest.config.subnets.js --no-cache --runInBand; npm run devenv:stop:subnets\"", "test:integration:2.5": "concurrently --hide \"devenv:deploy-krypton\" \"npm:devenv:deploy-krypton\" \"cross-env NODE_ENV=test jest --config ./tests/jest.config.2.5.js --no-cache --runInBand; npm run devenv:stop-krypton\"", diff --git a/src/api/routes/faucets.ts b/src/api/routes/faucets.ts index 4cf68622fd..64d8b93e14 100644 --- a/src/api/routes/faucets.ts +++ b/src/api/routes/faucets.ts @@ -8,7 +8,7 @@ import { SignedTokenTransferOptions, StacksTransaction, } from '@stacks/transactions'; -import { StacksNetwork, StacksTestnet } from '@stacks/network'; +import { StacksNetwork } from '@stacks/network'; import { makeBtcFaucetPayment, getBtcBalance, @@ -16,8 +16,8 @@ import { isValidBtcAddress, } from '../../btc-faucet'; import { DbFaucetRequestCurrency } from '../../datastore/common'; -import { getChainIDNetwork, intMax, stxToMicroStx } from '../../helpers'; -import { testnetKeys, getStacksTestnetNetwork } from './debug'; +import { getChainIDNetwork, getStxFaucetNetworks, intMax, stxToMicroStx } from '../../helpers'; +import { testnetKeys } from './debug'; import { StacksCoreRpcClient } from '../../core-rpc/client'; import { logger } from '../../logger'; import { FastifyPluginAsync, preHandlerHookHandler } from 'fastify'; @@ -27,24 +27,6 @@ import { Server } from 'node:http'; import { OptionalNullable } from '../schemas/util'; import { RunFaucetResponseSchema } from '../schemas/responses/responses'; -export function getStxFaucetNetworks(): StacksNetwork[] { - const networks: StacksNetwork[] = [getStacksTestnetNetwork()]; - const faucetNodeHostOverride: string | undefined = process.env.STACKS_FAUCET_NODE_HOST; - if (faucetNodeHostOverride) { - const faucetNodePortOverride: string | undefined = process.env.STACKS_FAUCET_NODE_PORT; - if (!faucetNodePortOverride) { - const error = 'STACKS_FAUCET_NODE_HOST is specified but STACKS_FAUCET_NODE_PORT is missing'; - logger.error(error); - throw new Error(error); - } - const network = new StacksTestnet({ - url: `http://${faucetNodeHostOverride}:${faucetNodePortOverride}`, - }); - networks.push(network); - } - return networks; -} - enum TxSendResultStatus { Success, ConflictingNonce, diff --git a/src/helpers.ts b/src/helpers.ts index 0e54b057e2..9301aeff59 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -12,6 +12,8 @@ import { StacksCoreRpcClient } from './core-rpc/client'; import { DbEventTypeId } from './datastore/common'; import { logger } from './logger'; import { has0xPrefix, isDevEnv, numberToHex } from '@hirosystems/api-toolkit'; +import { StacksNetwork, StacksTestnet } from '@stacks/network'; +import { getStacksTestnetNetwork } from './api/routes/debug'; export const apiDocumentationUrl = process.env.API_DOCS_URL; @@ -31,6 +33,24 @@ export function getIbdBlockHeight(): number | undefined { } } +export function getStxFaucetNetworks(): StacksNetwork[] { + const networks: StacksNetwork[] = [getStacksTestnetNetwork()]; + const faucetNodeHostOverride: string | undefined = process.env.STACKS_FAUCET_NODE_HOST; + if (faucetNodeHostOverride) { + const faucetNodePortOverride: string | undefined = process.env.STACKS_FAUCET_NODE_PORT; + if (!faucetNodePortOverride) { + const error = 'STACKS_FAUCET_NODE_HOST is specified but STACKS_FAUCET_NODE_PORT is missing'; + logger.error(error); + throw new Error(error); + } + const network = new StacksTestnet({ + url: `http://${faucetNodeHostOverride}:${faucetNodePortOverride}`, + }); + networks.push(network); + } + return networks; +} + function createEnumChecker(enumVariable: { [key in T]: TEnumValue; }): (value: number) => value is TEnumValue { diff --git a/src/tests-bns/event-server-tests.ts b/src/tests-bns/event-server-tests.ts deleted file mode 100644 index b84f3b3569..0000000000 --- a/src/tests-bns/event-server-tests.ts +++ /dev/null @@ -1,1026 +0,0 @@ -import { ChainID } from '@stacks/transactions'; -import { bnsNameCV, httpPostRequest } from '../helpers'; -import { EventStreamServer, startEventServer } from '../event-stream/event-server'; -import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../test-utils/test-builders'; -import { DbAssetEventTypeId, DbBnsZoneFile } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { PgSqlClient } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; - -describe('BNS event server tests', () => { - let db: PgWriteStore; - let client: PgSqlClient; - let eventServer: EventStreamServer; - - beforeEach(async () => { - await migrate('up'); - db = await PgWriteStore.connect({ usageName: 'tests', withNotifier: true }); - client = db.sql; - eventServer = await startEventServer({ - datastore: db, - chainId: ChainID.Mainnet, - serverHost: '127.0.0.1', - serverPort: 0 - }); - }); - - afterEach(async () => { - await eventServer.closeAsync(); - await db?.close(); - await migrate('down'); - }); - - test('namespace-ready called by a contract other than BNS', async () => { - const block = new TestBlockBuilder({ - block_height: 1, - index_block_hash: '0x29fe7ba9674b9196fefa28764a35a4603065dc25c9dcf83c56648066f36a8dce', - burn_block_height: 749661, - burn_block_hash: '0x000000000000000000021e9777470811a937006cf47efceadefca2e8031c4b5f', - burn_block_time: 1660638853, - }) - .addTx() - .build(); - await db.update(block); - const microblock = new TestMicroblockStreamBuilder() - .addMicroblock({ - microblock_hash: '0x8455c986ef89d09968b96fee0ef5b4625aa3860aa68e70123efa129f48e55c6b', - microblock_sequence: 0, - parent_index_block_hash: '0x29fe7ba9674b9196fefa28764a35a4603065dc25c9dcf83c56648066f36a8dce' - }) - .build(); - await db.updateMicroblocks(microblock); - const payload = { - "events": [ - { - "txid": "0x605aa0554fb5ee7995f9780aa54d63b3d32550b0def95e31bdf3beb0fedefdae", - "type": "contract_event", - "committed": true, - "event_index": 50, - "contract_event": { - "topic": "print", - "raw_value": "0x0c00000003096e616d65737061636502000000046672656e0a70726f706572746965730c000000061963616e2d7570646174652d70726963652d66756e6374696f6e030b6c61756e636865642d61740a0100000000000000000000000000011886086c69666574696d65010000000000000000000000000000cd50106e616d6573706163652d696d706f727406161809f2ab9182b6ff1678f82846131c0709e51cf914636f6d6d756e6974792d68616e646c65732d76320e70726963652d66756e6374696f6e0c000000050462617365010000000c9f2c9cd04674edea3fffffff076275636b6574730b00000010010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000105636f6566660100000000000000000000000000000001116e6f2d766f77656c2d646973636f756e740100000000000000000000000000000001116e6f6e616c7068612d646973636f756e7401000000000000000000000000000000010b72657665616c65642d61740100000000000000000000000000011886067374617475730d000000057265616479", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - } - ], - "block_hash": "0x6be6bfbf5e63ee4333c794b0489a791625ad0724722647b748379fe916bbff55", - "miner_txid": "0x1c01668438115f757cfc14210f7f7ba0bee7f9d235c44b8e35c8653ac5879205", - "block_height": 2, - "transactions": [ - { - "txid": "0x605aa0554fb5ee7995f9780aa54d63b3d32550b0def95e31bdf3beb0fedefdae", - "raw_tx": "0x000000000104001809f2ab9182b6ff1678f82846131c0709e51cf900000000000000110000000000000bb80001e2ae2533ed444dcc3dc0118da5c8bbfe5da4c1943b63e3fd9b7389e3f7f384ee417a65d899182ff7791b174a426b947860df5b4006a0cb767aca275af847428d03020000000002161809f2ab9182b6ff1678f82846131c0709e51cf914636f6d6d756e6974792d68616e646c65732d7632106e616d6573706163652d72657665616c0000000402000000046672656e0200000003626f74010000000000000000000000000000cd5009", - "status": "success", - "tx_index": 46, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 201050, - "read_count": 20, - "read_length": 92368, - "write_count": 4, - "write_length": 1386 - }, - "microblock_hash": "0x8455c986ef89d09968b96fee0ef5b4625aa3860aa68e70123efa129f48e55c6b", - "microblock_sequence": 0, - "microblock_parent_hash": "0xea7982ba6a5206b9efc2ab2567eedef3babae4d167619bdc74c7e148717dc208" - } - ], - "anchored_cost": { - "runtime": 19669668, - "read_count": 1420, - "read_length": 8457322, - "write_count": 143, - "write_length": 9331 - }, - "burn_block_hash": "0x00000000000000000004afca18622e18a1f36ff19dc1aece341868c042b7f4ac", - "burn_block_time": 1660639379, - "index_block_hash": "0xd3944c1cf261982ad5d86ad14b1545a2393c0039e378706323927b3a7031a621", - "burn_block_height": 749662, - "parent_block_hash": "0xea7982ba6a5206b9efc2ab2567eedef3babae4d167619bdc74c7e148717dc208", - "parent_microblock": "0x8455c986ef89d09968b96fee0ef5b4625aa3860aa68e70123efa129f48e55c6b", - "matured_miner_rewards": [], - "parent_burn_block_hash": "0x000000000000000000021e9777470811a937006cf47efceadefca2e8031c4b5f", - "parent_index_block_hash": "0x29fe7ba9674b9196fefa28764a35a4603065dc25c9dcf83c56648066f36a8dce", - "parent_burn_block_height": 749661, - "confirmed_microblocks_cost": { - "runtime": 174668984, - "read_count": 12067, - "read_length": 54026355, - "write_count": 1701, - "write_length": 134399 - }, - "parent_microblock_sequence": 0, - "parent_burn_block_timestamp": 1660638853 - }; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/new_block', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - const namespaces = await db.getNamespaceList({ includeUnanchored: true }); - expect(namespaces.results).toStrictEqual(['fren']); - - const namespace = await db.getNamespace({ namespace: 'fren', includeUnanchored: true }); - expect(namespace.found).toBe(true); - expect(namespace.result?.namespace_id).toBe('fren'); - expect(namespace.result?.lifetime).toBe(52560); - expect(namespace.result?.status).toBe('ready'); - expect(namespace.result?.ready_block).toBe(2); - }); - - test('name-transfer called by a contract other than BNS', async () => { - const block = new TestBlockBuilder({ - block_height: 1, - block_hash: '0x09458029b7c0e43e015bd3202c0f9512c2b394e0481bfd2bdd096ae7b5b862f2', - index_block_hash: '0xad9403fc8d8eaef47816555cac51dca9d934384aa9b2581f9b9085509b2af915', - burn_block_height: 743853, - burn_block_hash: '0x00000000000000000008b9d65609c6b39bb89d7da35433e4b287835d7112d6d4', - burn_block_time: 1657123396, - }) - .addTx({ - tx_id: '0x1234', - sender_address: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J' - }) - .addTxBnsNamespace({ - namespace_id: 'btc', - lifetime: 1000 - }) - .addTxBnsName({ - name: 'dayslikewater.btc', - namespace_id: 'btc', - zonefile_hash: 'b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', - address: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J' - }) - .addTxNftEvent({ - asset_event_type_id: DbAssetEventTypeId.Mint, - value: bnsNameCV('dayslikewater.btc'), - asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', - recipient: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J', - }) - .build(); - await db.update(block); - const microblock = new TestMicroblockStreamBuilder() - .addMicroblock({ - microblock_hash: '0xccdd11fef1792979bc54a9b686e9cc4fc3d64f2a9b2d8ee9d34fe27bfab783a4', - microblock_sequence: 0, - parent_index_block_hash: '0xad9403fc8d8eaef47816555cac51dca9d934384aa9b2581f9b9085509b2af915' - }) - .build(); - await db.updateMicroblocks(microblock); - - const name1 = await db.getName({ - name: 'dayslikewater.btc', - includeUnanchored: true, - }); - expect(name1.found).toBe(true); - expect(name1.result?.namespace_id).toBe('btc'); - expect(name1.result?.tx_id).toBe('0x1234'); - expect(name1.result?.status).toBe('name-register'); - expect(name1.result?.expire_block).toBe(1001); - expect(name1.result?.address).toBe('SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J'); - - const payload = { - "events": [ - { - "txid": "0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19", - "type": "contract_event", - "committed": true, - "event_index": 74, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000e52b04686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000d646179736c696b657761746572096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e6465720516016084eead6adbeee180dc0a855609d10eaf4c17", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - }, - { - "txid": "0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19", - "type": "nft_transfer_event", - "committed": true, - "event_index": 73, - "nft_transfer_event": { - "sender": "SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J", - "raw_value": "0x0c00000002046e616d65020000000d646179736c696b657761746572096e616d6573706163650200000003627463", - "recipient": "SP1TY00PDWJVNVEX7H7KJGS2K2YXHTQMY8C0G1NVP", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19", - "type": "stx_transfer_event", - "committed": true, - "event_index": 71, - "stx_transfer_event": { - "amount": "2500", - "sender": "SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C.bns-marketplace-v3", - "recipient": "SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C" - } - } - ], - "block_hash": "0x7d18920cc47f731f186fb9f731d2e8d5029bbab6d73fd012ac3e10637a8e4a37", - "miner_txid": "0xbed35e9e7eb7f98583c87743d3860ab63f2506f7f1efe24740cd37f7708de0b4", - "block_height": 2, - "transactions": [ - { - "txid": "0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19", - "raw_tx": "0x00000000010400016084eead6adbeee180dc0a855609d10eaf4c1700000000000000020000000000000bb80000e452e9d87e94a2a4364e89af3ab44b3ce1117afb6505721ff5b801294e1280f0616ee4d21a6ef9bcca1ea15ac65477e79df3427f7fd6c41c80938f8cca6d2cd0030200000002000316a6a7a70f41adbe8eae708ed7ec2cbf41a272182012626e732d6d61726b6574706c6163652d76330500000000000186a0020216016084eead6adbeee180dc0a855609d10eaf4c1716000000000000000000000000000000000000000003626e73056e616d65730c00000002046e616d65020000000d646179736c696b657761746572096e616d6573706163650200000003627463100216a6a7a70f41adbe8eae708ed7ec2cbf41a272182012626e732d6d61726b6574706c6163652d76330a6163636570742d626964000000030200000003627463020000000d646179736c696b6577617465720a0200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb", - "status": "success", - "tx_index": 25, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 381500, - "read_count": 42, - "read_length": 96314, - "write_count": 9, - "write_length": 359 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - } - ], - "anchored_cost": { - "runtime": 44194708, - "read_count": 4105, - "read_length": 11476905, - "write_count": 546, - "write_length": 47312 - }, - "burn_block_hash": "0x00000000000000000005e28a41cdb7461953b9424b4fd44a9211a145a1c0346d", - "burn_block_time": 1657125225, - "index_block_hash": "0xb70205d38a8666cbd071239b4ec28ae7d12a2c32341118d7c6d4d1e22f56014e", - "burn_block_height": 743854, - "parent_block_hash": "0x09458029b7c0e43e015bd3202c0f9512c2b394e0481bfd2bdd096ae7b5b862f2", - "parent_microblock": "0xccdd11fef1792979bc54a9b686e9cc4fc3d64f2a9b2d8ee9d34fe27bfab783a4", - "matured_miner_rewards": [], - "parent_burn_block_hash": "0x00000000000000000008b9d65609c6b39bb89d7da35433e4b287835d7112d6d4", - "parent_index_block_hash": "0xad9403fc8d8eaef47816555cac51dca9d934384aa9b2581f9b9085509b2af915", - "parent_burn_block_height": 743853, - "confirmed_microblocks_cost": { - "runtime": 48798, - "read_count": 10, - "read_length": 40042, - "write_count": 3, - "write_length": 19 - }, - "parent_microblock_sequence": 0, - "parent_burn_block_timestamp": 1657123396 - }; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/new_block', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - const name2 = await db.getName({ - name: 'dayslikewater.btc', - includeUnanchored: true, - }); - expect(name2.found).toBe(true); - expect(name2.result?.namespace_id).toBe('btc'); - expect(name2.result?.tx_id).toBe('0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19'); - expect(name2.result?.status).toBe('name-transfer'); - expect(name2.result?.expire_block).toBe(1001); // Unchanged as it was not renewed - expect(name2.result?.address).toBe('SP1TY00PDWJVNVEX7H7KJGS2K2YXHTQMY8C0G1NVP'); - }); - - test('name-renewal called with no zonefile_hash', async () => { - const block = new TestBlockBuilder({ - block_height: 1, - block_hash: '0xf81ef7f114213b9034a4378345a931a97c781fab398c3d7a2053f0d0bf48d311', - index_block_hash: '0xaec282925b5096c0bd98588d25a97e134bcc4f19b6600859fa267cf0ee4eaf2d', - burn_block_height: 726955, - burn_block_hash: '0x00000000000000000001523f01cb4304d39527454d2eec79817b50c033a5c5d9', - burn_block_time: 1647068146, - }) - .addTx({ - tx_id: '0x1234', - sender_address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ' - }) - .addTxBnsNamespace({ - namespace_id: 'id', - lifetime: 1000 - }) - .addTxBnsName({ - name: 'friedger.id', - namespace_id: 'id', - zonefile_hash: 'b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', - address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ' - }) - .addTxNftEvent({ - asset_event_type_id: DbAssetEventTypeId.Mint, - value: bnsNameCV('friedger.id'), - asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', - recipient: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ', - }) - .build(); - await db.update(block); - const microblock = new TestMicroblockStreamBuilder() - .addMicroblock({ - microblock_hash: '0x640362ec47c40de3337491993e42efe60d05187431633ab03c3f5d33e70d1f8e', - microblock_sequence: 0, - parent_index_block_hash: '0xaec282925b5096c0bd98588d25a97e134bcc4f19b6600859fa267cf0ee4eaf2d' - }) - .build(); - await db.updateMicroblocks(microblock); - - const name1 = await db.getName({ - name: 'friedger.id', - includeUnanchored: true, - }); - expect(name1.found).toBe(true); - expect(name1.result?.namespace_id).toBe('id'); - expect(name1.result?.tx_id).toBe('0x1234'); - expect(name1.result?.status).toBe('name-register'); - expect(name1.result?.expire_block).toBe(1001); - expect(name1.result?.address).toBe('SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ'); - - const payload = { - "events": [], - "block_hash": "0xaaee893667244adcb8581abac372f1f8c385d402b71e8e8b4ac91e8066024fd5", - "miner_txid": "0x6ff493c6b98b9cff0638c7c5276af8e627b8ed779965a5f1c11bbc0810834b3e", - "block_height": 2, - "transactions": [ - { - "txid": "0xf037c8da8210e2a348bbecd3bc44901de875d3774c5fce49cb75d95f2dc2ca4d", - "raw_tx": "0x00000000010500e1cd6c39a3d316e49bf16b4a20636462231b84f200000000000000000000000000000000000094f2c8529dcb8a55a5cfd4434c68cae9cd54f26f01c656369585db3ba364150a4fead679adf35cf5ba1026656b3873daf3380f48ec6dcc175ada868e531decf5001d04c185cad28a3f5299d3fcbcbcbe66b2e1e227000000000000000000000000000186a0000064cc0eb565e85c0d4110c9a760c8fdad21999409f89320e355f326c144b8ada4268244f80734170cea96f683d2431b59f07f276a10efc80793d4dceef8feb2310302000000000216000000000000000000000000000000000000000003626e730c6e616d652d72656e6577616c000000050200000002696402000000086672696564676572010000000000000000000000000001a72a0909", - "status": "success", - "tx_index": 2, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 184253, - "read_count": 11, - "read_length": 43250, - "write_count": 1, - "write_length": 143 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - } - ], - "anchored_cost": { - "runtime": 28375070, - "read_count": 8888, - "read_length": 1085153, - "write_count": 593, - "write_length": 156284 - }, - "burn_block_hash": "0x0000000000000000000552fb5fd8c08ad8f1ef30c239369a8a3380ec1566047a", - "burn_block_time": 1647068392, - "index_block_hash": "0x9ff46918054b1aa94571a60e14921a56977f26af2adcbf4a7f64138566feba48", - "burn_block_height": 726956, - "parent_block_hash": "0xf81ef7f114213b9034a4378345a931a97c781fab398c3d7a2053f0d0bf48d311", - "parent_microblock": "0x640362ec47c40de3337491993e42efe60d05187431633ab03c3f5d33e70d1f8e", - "matured_miner_rewards": [], - "parent_burn_block_hash": "0x00000000000000000001523f01cb4304d39527454d2eec79817b50c033a5c5d9", - "parent_index_block_hash": "0xaec282925b5096c0bd98588d25a97e134bcc4f19b6600859fa267cf0ee4eaf2d", - "parent_burn_block_height": 726955, - "confirmed_microblocks_cost": { - "runtime": 360206, - "read_count": 38, - "read_length": 95553, - "write_count": 8, - "write_length": 378 - }, - "parent_microblock_sequence": 0, - "parent_burn_block_timestamp": 1647068146 - }; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/new_block', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - const name2 = await db.getName({ - name: 'friedger.id', - includeUnanchored: true, - }); - expect(name2.found).toBe(true); - expect(name2.result?.namespace_id).toBe('id'); - expect(name2.result?.tx_id).toBe('0xf037c8da8210e2a348bbecd3bc44901de875d3774c5fce49cb75d95f2dc2ca4d'); - expect(name2.result?.status).toBe('name-renewal'); - expect(name2.result?.expire_block).toBe(1002); // Updated correctly - expect(name2.result?.address).toBe('SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ'); - }); - - test('/attachments/new with re-orged zonefiles', async () => { - const block1 = new TestBlockBuilder({ - block_height: 1, - index_block_hash: '0x0101', - }) - .addTx() - .addTxBnsNamespace({ namespace_id: 'btc' }) - .addTxBnsName({ name: 'jnj.btc', namespace_id: 'btc' }) - .addTxNftEvent({ - asset_event_type_id: DbAssetEventTypeId.Mint, - value: bnsNameCV('jnj.btc'), - asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', - recipient: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', - }) - .build(); - await db.update(block1); - - const block2 = new TestBlockBuilder({ - block_height: 2, - index_block_hash: '0x0200', - parent_index_block_hash: '0x0101' - }) - .addTx({ tx_id: '0x1212' }) - .addTxBnsName({ - name: 'jnj.btc', - namespace_id: 'btc', - status: 'name-update', // Canonical update - tx_id: '0x1212', - zonefile_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3' - }) - .build(); - await db.update(block2); - - const block2b = new TestBlockBuilder({ - block_height: 2, - index_block_hash: '0x0201', - parent_index_block_hash: '0x0101' - }) - .addTx({ tx_id: '0x121266' }) - .addTxBnsName({ - name: 'jnj.btc', - namespace_id: 'btc', - status: 'name-update', // Non-canonical update - tx_id: '0x121266', - zonefile_hash: '0xffff' - }) - .build(); - await db.update(block2b); - - const block3 = new TestBlockBuilder({ - block_height: 3, - index_block_hash: '0x0300', - parent_index_block_hash: '0x0200' - }) - .addTx({ tx_id: '0x3333' }) - .build(); - await db.update(block3); - - const payload = [ - { - "tx_id": "0x1212", // Canonical - "content": "0x244f524947494e206a6e6a2e6274632e0a2454544c20333630300a5f687474702e5f74637009494e095552490931300931092268747470733a2f2f676169612e626c6f636b737461636b2e6f72672f6875622f317a38417a79684334326e3854766f4661554c326e7363614347487151515755722f70726f66696c652e6a736f6e220a0a", - "metadata": "0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6", - "contract_id": "SP000000000000000000002Q6VF78.bns", - "block_height": 17307, - "content_hash": "0x9198e0b61a029671e53bd59aa229e7ae05af35a3", - "attachment_index": 823, - "index_block_hash": "0x0200" - }, - { - "tx_id": "0x121266", // Non-canonical - "content": "0x", - "metadata": "0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6", - "contract_id": "SP000000000000000000002Q6VF78.bns", - "block_height": 17307, - "content_hash": "0xffff", - "attachment_index": 823, - "index_block_hash": "0x0201" - }, - ]; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/attachments/new', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - const name = await db.getName({ name: 'jnj.btc', includeUnanchored: true }); - expect(name.found).toBe(true); - expect(name.result?.zonefile_hash).toBe('9198e0b61a029671e53bd59aa229e7ae05af35a3'); - expect(name.result?.tx_id).toBe('0x1212'); - expect(name.result?.status).toBe('name-update'); - }); - - test('/attachments/new with duplicate zonefiles for the same tx', async () => { - const block1 = new TestBlockBuilder({ - block_height: 1, - index_block_hash: '0x0101', - }) - .addTx({ tx_id: '0x1234' }) - .addTxBnsNamespace({ namespace_id: 'btc' }) - .addTxBnsName({ - name: 'jnj.btc', - namespace_id: 'btc', - zonefile_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3' - }) - .addTxNftEvent({ - asset_event_type_id: DbAssetEventTypeId.Mint, - value: bnsNameCV('jnj.btc'), - asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', - recipient: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', - }) - .build(); - await db.update(block1); - - const payload = [ - { - "tx_id": "0x1234", - "content": "0x", - "metadata": "0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6", - "contract_id": "SP000000000000000000002Q6VF78.bns", - "block_height": 1, - "content_hash": "0x9198e0b61a029671e53bd59aa229e7ae05af35a3", - "attachment_index": 823, - "index_block_hash": "0x0101" - }, - { - "tx_id": "0x1234", - "content": "0x244f524947494e206a6e6a2e6274632e0a2454544c20333630300a5f687474702e5f74637009494e095552490931300931092268747470733a2f2f676169612e626c6f636b737461636b2e6f72672f6875622f317a38417a79684334326e3854766f4661554c326e7363614347487151515755722f70726f66696c652e6a736f6e220a0a", - "metadata": "0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6", - "contract_id": "SP000000000000000000002Q6VF78.bns", - "block_height": 1, - "content_hash": "0x9198e0b61a029671e53bd59aa229e7ae05af35a3", // Same zonefile_hash but different content, this should overwrite the entry above - "attachment_index": 823, - "index_block_hash": "0x0101" - }, - { - "tx_id": "0x1234", - "content": "0x244f524947494e206a6e6a2e6274632e0a2454544c20333630300a5f687474702e5f74637009494e095552490931300931092268747470733a2f2f676169612e626c6f636b737461636b2e6f72672f6875622f317a38417a79684334326e3854766f4661554c326e7363614347487151515755722f70726f66696c652e6a736f6e220a0a", - "metadata": "0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6", - "contract_id": "SP000000000000000000002Q6VF78.bns", - "block_height": 1, - "content_hash": "0x9198e0b61a029671e53bd59aa229e7ae05af35a3", // Also overwrite - "attachment_index": 823, - "index_block_hash": "0x0101" - }, - ]; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/attachments/new', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - // To validate table data we'll query it directly. There should only be one zonefile. - const result = await client`SELECT * FROM zonefiles`; - expect(result.count).toBe(1); - expect(result[0].zonefile).toBe('$ORIGIN jnj.btc.\n$TTL 3600\n_http._tcp\tIN\tURI\t10\t1\t"https://gaia.blockstack.org/hub/1z8AzyhC42n8TvoFaUL2nscaCGHqQQWUr/profile.json"\n\n'); - }); - - test('name-register and name-transfer for several names in one block', async () => { - const block = new TestBlockBuilder({ - block_height: 1, - block_hash: '0x161bd86201417a55fb0dd851ac0e6b10c67a0b443e593008a4cf46fb6938b369', - index_block_hash: '0x8cc3d58350082f3161ae34deaad77c1c8887947ff0295be59ec5caccf984fe78', - burn_block_height: 756266, - burn_block_hash: '0x00000000000000000002e78c9c19a055ca0e680674e1a2f0f01a48c04a24f627', - burn_block_time: 1664489645, - }) - .addTx({ - tx_id: '0x1234', - sender_address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ' - }) - .addTxBnsNamespace({ - namespace_id: 'btc', - lifetime: 1000 - }) - .build(); - await db.update(block); - const microblock = new TestMicroblockStreamBuilder() - .addMicroblock({ - microblock_hash: '0xc44f4e3ed66bacaaa5cbe5b9c35b4e2ce2467933b57974fa03b539a2b2b88063', - microblock_sequence: 0, - parent_index_block_hash: '0x8cc3d58350082f3161ae34deaad77c1c8887947ff0295be59ec5caccf984fe78' - }) - .build(); - await db.updateMicroblocks(microblock); - - const payload = { - // In the block message, events are not sorted by `event_index`. - "events": [ - { - "txid": "0xd5803813a0befbf7e426ca897a5940c691a18e5959170e12ddb9e71c91ea4f12", - "type": "nft_mint_event", - "committed": true, - "event_index": 405, - "nft_mint_event": { - "raw_value": "0x0c00000002046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463", - "recipient": "SP253DQBW2ZBKE10PBQVBDJ5XSQQ4P06PVP9PR6S8", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0xd5803813a0befbf7e426ca897a5940c691a18e5959170e12ddb9e71c91ea4f12", - "type": "contract_event", - "committed": true, - "event_index": 406, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144ea04686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205168a36dd7c17d73704165df6b6c8bdcdee4b00d6dd", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - }, - { - "txid": "0xa106e30d1df4607a993ff2ec0d68a4acfb3d5ab2ae597179869df8d6da8f1b95", - "type": "nft_transfer_event", - "committed": true, - "event_index": 407, - "nft_transfer_event": { - "sender": "SP253DQBW2ZBKE10PBQVBDJ5XSQQ4P06PVP9PR6S8", - "raw_value": "0x0c00000002046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463", - "recipient": "SP2WPXVTZE2RG4SZGJT5HTZ7JK6CAWTEV0A55HFH7", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0xa106e30d1df4607a993ff2ec0d68a4acfb3d5ab2ae597179869df8d6da8f1b95", - "type": "contract_event", - "committed": true, - "event_index": 408, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144eb04686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e64657205168a36dd7c17d73704165df6b6c8bdcdee4b00d6dd", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - }, - { - "txid": "0x1784633b879ffcf15c18dcf627047a44358f2f0660c14f5188c9f17b28abb8af", - "type": "nft_mint_event", - "committed": true, - "event_index": 381, - "nft_mint_event": { - "raw_value": "0x0c00000002046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463", - "recipient": "SP2MM4ETXDE26HQ64F29VG05Q577DEPTSDJ2DQV8N", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0x1784633b879ffcf15c18dcf627047a44358f2f0660c14f5188c9f17b28abb8af", - "type": "contract_event", - "committed": true, - "event_index": 382, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144e204686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e6465720516a9423b5d6b8468dcc47893b800b729ced75b596c", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - }, - { - "txid": "0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7", - "type": "nft_transfer_event", - "committed": true, - "event_index": 389, - "nft_transfer_event": { - "sender": "SP2MM4ETXDE26HQ64F29VG05Q577DEPTSDJ2DQV8N", - "raw_value": "0x0c00000002046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463", - "recipient": "SP1QFKSVQP3J2PF45KFFCVBR4Q24Y09G0PJDECHS7", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7", - "type": "contract_event", - "committed": true, - "event_index": 390, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144e304686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e6465720516a9423b5d6b8468dcc47893b800b729ced75b596c", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - } - ], - "block_hash": "0x41e158fe192103d2a5f895c6f9093a548ecc35db3a4c3c5de0e616fd3894338e", - "miner_txid": "0x9c48f6c748177cd049db40172e5044e5a98f8fe5b798f33212f876121e764b72", - "block_height": 2, - "transactions": [ - { - "txid": "0x1784633b879ffcf15c18dcf627047a44358f2f0660c14f5188c9f17b28abb8af", - "raw_tx": "0x00000000010400a9423b5d6b8468dcc47893b800b729ced75b596c00000000000000010000000000014ed6010055b3a6e2581eaaf686bc9596a4c9cf62cbdb30ffaad167c094824b5d89598ce1101ff56aeb58e2020c10954da05cd80b733ec79ecd71db1921aa202d377aac740302000000000216000000000000000000000000000000000000000003626e730d6e616d652d7265676973746572000000040200000003627463020000000f637269636b6574776972656c65737302000000149a3db4f009ad960c5a0cad7ad9c19f21fa0fe3680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb", - "status": "success", - "tx_index": 274, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 311527, - "read_count": 17, - "read_length": 43206, - "write_count": 4, - "write_length": 242 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - }, - { - "txid": "0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7", - "raw_tx": "0x00000000010400a9423b5d6b8468dcc47893b800b729ced75b596c00000000000000020000000000014941010173c47aad0c8e5e8e2c655f488e4b8f514a63fd0190ae392f6cc6f22c1ec93aa44facb412a9d6504efd7945eeb52407011069ca1d3a7138e7a889c7c15aa82df2030200000001020216a9423b5d6b8468dcc47893b800b729ced75b596c16000000000000000000000000000000000000000003626e73056e616d65730c00000002046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463100216000000000000000000000000000000000000000003626e730d6e616d652d7472616e73666572000000040200000003627463020000000f637269636b6574776972656c65737305166ef9e777b0e42b3c859bdecdaf04b889e02600b40a0200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb", - "status": "success", - "tx_index": 276, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 183670, - "read_count": 19, - "read_length": 44047, - "write_count": 5, - "write_length": 266 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - }, - { - "txid": "0xd5803813a0befbf7e426ca897a5940c691a18e5959170e12ddb9e71c91ea4f12", - "raw_tx": "0x000000000104008a36dd7c17d73704165df6b6c8bdcdee4b00d6dd0000000000000001000000000001449f0101bd23afc22da4e356847d76d07261a861488389d4864c8d42ce002be439e0e78b3aa1088a8aaac189f7c85e674fd871b787f1fb0cd5a19acd827a011f5e38921c0302000000000216000000000000000000000000000000000000000003626e730d6e616d652d726567697374657200000004020000000362746302000000086b6574656c6f6e6502000000146cd23e487d9068d24e1e1bc90636a6e48c1546a50200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb", - "status": "success", - "tx_index": 285, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 229244, - "read_count": 17, - "read_length": 43199, - "write_count": 4, - "write_length": 228 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - }, - { - "txid": "0xa106e30d1df4607a993ff2ec0d68a4acfb3d5ab2ae597179869df8d6da8f1b95", - "raw_tx": "0x000000000104008a36dd7c17d73704165df6b6c8bdcdee4b00d6dd00000000000000020000000000015cb70101ac9a2e87c627c605ac68f0c40d59ff6bd5543705a5710ee4679d936a664d20f60a0b91e98770cb3597ea25af005e9eb083a827e860b6ba975c0a819205b4792f0302000000010202168a36dd7c17d73704165df6b6c8bdcdee4b00d6dd16000000000000000000000000000000000000000003626e73056e616d65730c00000002046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463100216000000000000000000000000000000000000000003626e730d6e616d652d7472616e7366657200000004020000000362746302000000086b6574656c6f6e650516b96eef5f70b10267f0968b1d7cf29998ae69db020a0200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb", - "status": "success", - "tx_index": 286, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 183264, - "read_count": 19, - "read_length": 44026, - "write_count": 5, - "write_length": 252 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - } - ], - "anchored_cost": { - "runtime": 37717625, - "read_count": 3184, - "read_length": 10513899, - "write_count": 710, - "write_length": 42932 - }, - "burn_block_hash": "0x0000000000000000000213c1512c2bffae7378f2b890bfea3ee6dc8e2e7836a2", - "burn_block_time": 1664490688, - "index_block_hash": "0x2eb444d32bb66a6acc3ba66aedabbb19c3adde8b6a9717765960bdc67ea32070", - "burn_block_height": 756268, - "parent_block_hash": "0x161bd86201417a55fb0dd851ac0e6b10c67a0b443e593008a4cf46fb6938b369", - "parent_microblock": "0xc44f4e3ed66bacaaa5cbe5b9c35b4e2ce2467933b57974fa03b539a2b2b88063", - "matured_miner_rewards": [], - "parent_burn_block_hash": "0x00000000000000000002e78c9c19a055ca0e680674e1a2f0f01a48c04a24f627", - "parent_index_block_hash": "0x8cc3d58350082f3161ae34deaad77c1c8887947ff0295be59ec5caccf984fe78", - "parent_burn_block_height": 756266, - "confirmed_microblocks_cost": { - "runtime": 5707388, - "read_count": 545, - "read_length": 2095326, - "write_count": 127, - "write_length": 8025 - }, - "parent_microblock_sequence": 0, - "parent_burn_block_timestamp": 1664489645 - }; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/new_block', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - const name = await db.getName({ - name: 'cricketwireless.btc', - includeUnanchored: true, - }); - expect(name.found).toBe(true); - expect(name.result?.namespace_id).toBe('btc'); - expect(name.result?.tx_id).toBe('0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7'); - expect(name.result?.status).toBe('name-transfer'); - expect(name.result?.address).toBe('SP1QFKSVQP3J2PF45KFFCVBR4Q24Y09G0PJDECHS7'); - }); - - test('name-register and name-transfer in same tx from non-BNS contract', async () => { - const block = new TestBlockBuilder({ - block_height: 1, - block_hash: '0x08cdd83644176e87cd5fdc584a5193de84c4c54cbe8b3839225e75f396f64468', - index_block_hash: '0x82239cdbd3903ca032d300101990120947132a8a005a92d7a1cdcd5a61b35ba1', - burn_block_height: 749980, - burn_block_hash: '0x000000000000000000089afaf672605818e368521d9ad2d8e4b5763956b75363', - burn_block_time: 1660833970, - }) - .addTx({ - tx_id: '0x1234', - sender_address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ' - }) - .addTxBnsNamespace({ - namespace_id: 'mega', - lifetime: 1000 - }) - .build(); - await db.update(block); - const microblock = new TestMicroblockStreamBuilder() - .addMicroblock({ - microblock_hash: '0x2ad76cc1eadb6e0dd155a7b5ac82ff81a2c664552dacb99a524a410856330529', - microblock_sequence: 0, - parent_index_block_hash: '0x82239cdbd3903ca032d300101990120947132a8a005a92d7a1cdcd5a61b35ba1' - }) - .build(); - await db.updateMicroblocks(microblock); - - const payload = { - "events": [ - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "contract_event", - "committed": true, - "event_index": 85, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000f65804686173680200000000086d657461646174610c00000004046e616d650200000003617065096e616d65737061636502000000046d656761026f700d0000000d6e616d652d7472616e736665720974782d73656e64657206161809f2ab9182b6ff1678f82846131c0709e51cf91b72796465722d68616e646c65732d636f6e74726f6c6c65722d7631", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - }, - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "stx_burn_event", - "committed": true, - "event_index": 81, - "stx_burn_event": { - "amount": "1", - "sender": "SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1" - } - }, - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "nft_transfer_event", - "committed": true, - "event_index": 84, - "nft_transfer_event": { - "sender": "SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1", - "raw_value": "0x0c00000002046e616d650200000003617065096e616d65737061636502000000046d656761", - "recipient": "SPV48Q8E5WP4TCQ63E9TV6KF9R4HP01Z8WS3FBTG", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "nft_mint_event", - "committed": true, - "event_index": 82, - "nft_mint_event": { - "raw_value": "0x0c00000002046e616d650200000003617065096e616d65737061636502000000046d656761", - "recipient": "SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1", - "asset_identifier": "SP000000000000000000002Q6VF78.bns::names" - } - }, - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "stx_transfer_event", - "committed": true, - "event_index": 79, - "stx_transfer_event": { - "amount": "3000000", - "sender": "SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1", - "recipient": "SP2J9XB6CNJX9C36D5SY4J85SA0P1MQX7R5VFKZZX" - } - }, - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "stx_transfer_event", - "committed": true, - "event_index": 80, - "stx_transfer_event": { - "amount": "1", - "sender": "SP3C8QH2R3909YQZ7WVZ71N8RJ6Y0P317T8MG8XSZ", - "recipient": "SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1" - } - }, - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "type": "contract_event", - "committed": true, - "event_index": 83, - "contract_event": { - "topic": "print", - "raw_value": "0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000f65704686173680200000000086d657461646174610c00000004046e616d650200000003617065096e616d65737061636502000000046d656761026f700d0000000d6e616d652d72656769737465720974782d73656e64657206161809f2ab9182b6ff1678f82846131c0709e51cf91b72796465722d68616e646c65732d636f6e74726f6c6c65722d7631", - "contract_identifier": "SP000000000000000000002Q6VF78.bns" - } - } - ], - "block_hash": "0xbcf632eaa887b66a6356bf9410eb61377cced2d3f444a2286fb59b12a63e48e4", - "miner_txid": "0x037d5016d21839a46f136ad846ea99967eda65bf5cdb31feabc60c8eaef5b96d", - "block_height": 2, - "transactions": [ - { - "txid": "0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16", - "raw_tx": "0x00000000010400d88bc4581a409f5fe7e6fe70d51891bc0b0c27d2000000000000001100000000000003e80001fff157398074931aca859d34de1f3070359b8493033cd79fde329ecd66e4bd090235cf61f9916f76cdbaa37ff4d2ee3358322f6a58ec2fb05717115c913fd6e103010000000002161809f2ab9182b6ff1678f82846131c0709e51cf91b72796465722d68616e646c65732d636f6e74726f6c6c65722d76310d6e616d652d72656769737465720000000602000000046d656761020000000361706502000000057337306b35020000004107d00910104bba0ee68b131ceead109ccea598a267a2000140b3277809f1ab535dcef753028c00e7239be1477801ac7d5b8c10e0a7b242261285212da194bdad01051636445d0e2f2c4d32e61b93ad9a6f4e091b003f470200000000", - "status": "success", - "tx_index": 25, - "raw_result": "0x0703", - "contract_abi": null, - "execution_cost": { - "runtime": 643399, - "read_count": 69, - "read_length": 231108, - "write_count": 16, - "write_length": 1948 - }, - "microblock_hash": null, - "microblock_sequence": null, - "microblock_parent_hash": null - } - ], - "anchored_cost": { - "runtime": 39996577, - "read_count": 4234, - "read_length": 13859444, - "write_count": 676, - "write_length": 53049 - }, - "burn_block_hash": "0x0000000000000000000867b5dd6ec7ebb50404acabcdb35193b6b2fcd3ea7a37", - "burn_block_time": 1660834638, - "index_block_hash": "0xe43e505d4c7ca5f64a6d9617fbb658a84344610eb0e6495f8f9b7ab3b2648f61", - "burn_block_height": 749981, - "parent_block_hash": "0x08cdd83644176e87cd5fdc584a5193de84c4c54cbe8b3839225e75f396f64468", - "parent_microblock": "0x2ad76cc1eadb6e0dd155a7b5ac82ff81a2c664552dacb99a524a410856330529", - "matured_miner_rewards": [], - "parent_burn_block_hash": "0x000000000000000000089afaf672605818e368521d9ad2d8e4b5763956b75363", - "parent_index_block_hash": "0x82239cdbd3903ca032d300101990120947132a8a005a92d7a1cdcd5a61b35ba1", - "parent_burn_block_height": 749980, - "confirmed_microblocks_cost": { - "runtime": 0, - "read_count": 0, - "read_length": 0, - "write_count": 0, - "write_length": 0 - }, - "parent_microblock_sequence": 0, - "parent_burn_block_timestamp": 1660833970 - }; - - await httpPostRequest({ - host: '127.0.0.1', - port: eventServer.serverAddress.port, - path: '/new_block', - headers: { 'Content-Type': 'application/json' }, - body: Buffer.from(JSON.stringify(payload), 'utf8'), - throwOnNotOK: true, - }); - - const name = await db.getName({ - name: 'ape.mega', - includeUnanchored: true, - }); - expect(name.found).toBe(true); - expect(name.result?.namespace_id).toBe('mega'); - expect(name.result?.tx_id).toBe('0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16'); - expect(name.result?.status).toBe('name-transfer'); - expect(name.result?.expire_block).toBe(1002); - expect(name.result?.address).toBe('SPV48Q8E5WP4TCQ63E9TV6KF9R4HP01Z8WS3FBTG'); - - const list = await db.getNamesList({ page: 0, includeUnanchored: true }); - expect(list.results.length).toBe(1); - expect(list.results).toStrictEqual(['ape.mega']); - - const namespaceList = await db.getNamespaceNamesList({ - namespace: 'mega', - page: 0, - includeUnanchored: true - }); - expect(namespaceList.results.length).toBe(1); - expect(namespaceList.results).toStrictEqual(['ape.mega']); - }); -}) diff --git a/src/tests-2.5/block-zero-handling.ts b/tests/2.5/block-zero-handling.test.ts similarity index 95% rename from src/tests-2.5/block-zero-handling.ts rename to tests/2.5/block-zero-handling.test.ts index 542cf75714..925a235ce1 100644 --- a/src/tests-2.5/block-zero-handling.ts +++ b/tests/2.5/block-zero-handling.test.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import * as supertest from 'supertest'; -import { BlockQueryResult } from '../datastore/common'; -import { parseBlockQueryResult } from '../datastore/helpers'; -import { standByUntilBlock, testEnv } from '../test-utils/test-helpers'; +import { BlockQueryResult } from '../../src/datastore/common'; +import { parseBlockQueryResult } from '../../src/datastore/helpers'; +import { standByUntilBlock, testEnv } from '../utils/test-helpers'; import { CoinbaseTransaction, SmartContractTransaction, Transaction, -} from '../api/schemas/entities/transactions'; -import { Block } from '../api/schemas/entities/block'; +} from '../../src/api/schemas/entities/transactions'; +import { Block } from '../../src/api/schemas/entities/block'; describe('Block-zero event handling', () => { const testnetBootAddr = 'ST000000000000000000002AMW42H'; diff --git a/src/tests-2.5/env-setup.ts b/tests/2.5/env-setup.ts similarity index 83% rename from src/tests-2.5/env-setup.ts rename to tests/2.5/env-setup.ts index 714227999d..65e6ce3803 100644 --- a/src/tests-2.5/env-setup.ts +++ b/tests/2.5/env-setup.ts @@ -1,11 +1,11 @@ import { StacksTestnet } from '@stacks/network'; import { ChainID } from '@stacks/transactions'; import { RPCClient } from 'rpc-bitcoin'; -import { startApiServer } from '../api/init'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { loadDotEnv } from '../helpers'; -import { TestEnvContext } from '../test-utils/test-helpers'; +import { startApiServer } from '../../src/api/init'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { loadDotEnv } from '../../src/helpers'; +import { TestEnvContext } from '../utils/test-helpers'; let testEnv: TestEnvContext; diff --git a/src/tests-2.5/faucet-stx.ts b/tests/2.5/faucet-stx.test.ts similarity index 91% rename from src/tests-2.5/faucet-stx.ts rename to tests/2.5/faucet-stx.test.ts index ce907e61e1..654f9e63fe 100644 --- a/src/tests-2.5/faucet-stx.ts +++ b/tests/2.5/faucet-stx.test.ts @@ -6,9 +6,9 @@ import { fetchGet, standByForTxSuccess, testEnv, -} from '../test-utils/test-helpers'; -import { RunFaucetResponse } from '../api/schemas/responses/responses'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +} from '../utils/test-helpers'; +import { RunFaucetResponse } from '../../src/api/schemas/responses/responses'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; describe('STX Faucet', () => { const reqAccountKey = 'b1ee37d996b1cf95ff67996a38426cff398d3adfeccf8ae8b3651a530837dd5801'; diff --git a/src/tests-2.5/global-setup.ts b/tests/2.5/global-setup.ts similarity index 82% rename from src/tests-2.5/global-setup.ts rename to tests/2.5/global-setup.ts index d3948c1091..d8cc2b366d 100644 --- a/src/tests-2.5/global-setup.ts +++ b/tests/2.5/global-setup.ts @@ -1,9 +1,9 @@ -import { loadDotEnv } from '../helpers'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { EventStreamServer, startEventServer } from '../event-stream/event-server'; +import { loadDotEnv } from '../../src/helpers'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { EventStreamServer, startEventServer } from '../../src/event-stream/event-server'; import { ChainID } from '@stacks/transactions'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; import { timeout } from '@hirosystems/api-toolkit'; export interface GlobalTestEnv { diff --git a/src/tests-2.5/global-teardown.ts b/tests/2.5/global-teardown.ts similarity index 100% rename from src/tests-2.5/global-teardown.ts rename to tests/2.5/global-teardown.ts diff --git a/src/tests-2.5/pox-4-btc-address-formats.ts b/tests/2.5/pox-4-btc-address-formats.test.ts similarity index 97% rename from src/tests-2.5/pox-4-btc-address-formats.ts rename to tests/2.5/pox-4-btc-address-formats.test.ts index 43c54355e4..1a6dd6eaf5 100644 --- a/src/tests-2.5/pox-4-btc-address-formats.ts +++ b/tests/2.5/pox-4-btc-address-formats.test.ts @@ -11,26 +11,26 @@ import { uintCV, } from '@stacks/transactions'; import bignumber from 'bignumber.js'; -import { testnetKeys } from '../api/routes/debug'; -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { DbEventTypeId, DbStxLockEvent } from '../datastore/common'; -import { getBitcoinAddressFromKey, privateToPublicKey } from '../ec-helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { CoreRpcPoxInfo } from '../../src/core-rpc/client'; +import { DbEventTypeId, DbStxLockEvent } from '../../src/datastore/common'; +import { getBitcoinAddressFromKey, privateToPublicKey } from '../../src/ec-helpers'; import { fetchGet, standByForPoxCycle, standByForTxSuccess, standByUntilBurnBlock, testEnv, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; import { RPCClient } from 'rpc-bitcoin'; import { hexToBytes } from '@stacks/common'; import { getPublicKeyFromPrivate } from '@stacks/encryption'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; import { BurnchainRewardListResponse, BurnchainRewardSlotHolderListResponse, -} from '../api/schemas/responses/responses'; -import { BurnchainRewardsTotal } from '../api/schemas/entities/burnchain-rewards'; +} from '../../src/api/schemas/responses/responses'; +import { BurnchainRewardsTotal } from '../../src/api/schemas/entities/burnchain-rewards'; const BTC_PRIVATE_KEY = '0000000000000000000000000000000000000000000000000000000000000002'; diff --git a/src/tests-2.5/pox-4-burnchain-delegate-stx.ts b/tests/2.5/pox-4-burnchain-delegate-stx.test.ts similarity index 96% rename from src/tests-2.5/pox-4-burnchain-delegate-stx.ts rename to tests/2.5/pox-4-burnchain-delegate-stx.test.ts index 22b66aa9dd..374fb56385 100644 --- a/src/tests-2.5/pox-4-burnchain-delegate-stx.ts +++ b/tests/2.5/pox-4-burnchain-delegate-stx.test.ts @@ -8,10 +8,10 @@ import { standardPrincipalCV, uintCV, } from '@stacks/transactions'; -import { testnetKeys } from '../api/routes/debug'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { ECPair } from '../ec-helpers'; -import { BootContractAddress } from '../helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { ECPair } from '../../src/ec-helpers'; +import { BootContractAddress } from '../../src/helpers'; import { Account, accountFromKey, @@ -22,25 +22,25 @@ import { standByUntilBurnBlock, testEnv, TestEnvContext, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; import * as btc from 'bitcoinjs-lib'; import { b58ToC32, c32ToB58 } from 'c32check'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { ApiServer } from '../api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { ApiServer } from '../../src/api/init'; import { StacksNetwork } from '@stacks/network'; import { RPCClient } from 'rpc-bitcoin'; import * as supertest from 'supertest'; -import { PoxContractIdentifier } from '../pox-helpers'; +import { PoxContractIdentifier } from '../../src/pox-helpers'; import { ClarityValueUInt, decodeClarityValue } from 'stacks-encoding-native-js'; import { decodeBtcAddress, poxAddressToBtcAddress } from '@stacks/stacking'; import { timeout } from '@hirosystems/api-toolkit'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; -import { ContractCallTransaction } from '../api/schemas/entities/transactions'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; +import { ContractCallTransaction } from '../../src/api/schemas/entities/transactions'; import { AddressTransactionsListResponse, TransactionEventsResponse, -} from '../api/schemas/responses/responses'; -import { StxLockTransactionEvent } from '../api/schemas/entities/transaction-events'; +} from '../../src/api/schemas/responses/responses'; +import { StxLockTransactionEvent } from '../../src/api/schemas/entities/transaction-events'; // Perform Delegate-STX operation on Bitcoin. // See https://github.com/stacksgov/sips/blob/a7f2e58ec90c12ee1296145562eec75029b89c48/sips/sip-015/sip-015-network-upgrade.md#new-burnchain-transaction-delegate-stx diff --git a/src/tests-2.5/pox-4-burnchain-stack-stx.ts b/tests/2.5/pox-4-burnchain-stack-stx.test.ts similarity index 95% rename from src/tests-2.5/pox-4-burnchain-stack-stx.ts rename to tests/2.5/pox-4-burnchain-stack-stx.test.ts index 0239490639..dbc6fe35f2 100644 --- a/src/tests-2.5/pox-4-burnchain-stack-stx.ts +++ b/tests/2.5/pox-4-burnchain-stack-stx.test.ts @@ -8,10 +8,10 @@ import { stringAsciiCV, uintCV, } from '@stacks/transactions'; -import { testnetKeys } from '../api/routes/debug'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { ECPair } from '../ec-helpers'; -import { BootContractAddress } from '../helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { ECPair } from '../../src/ec-helpers'; +import { BootContractAddress } from '../../src/helpers'; import { Account, accountFromKey, @@ -22,11 +22,11 @@ import { standByUntilBurnBlock, testEnv, TestEnvContext, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; import * as btc from 'bitcoinjs-lib'; import { b58ToC32, c32ToB58 } from 'c32check'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { ApiServer } from '../api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { ApiServer } from '../../src/api/init'; import { StacksNetwork } from '@stacks/network'; import { RPCClient } from 'rpc-bitcoin'; import * as supertest from 'supertest'; @@ -34,10 +34,10 @@ import { ClarityValueUInt, decodeClarityValue } from 'stacks-encoding-native-js' import { decodeBtcAddress, poxAddressToTuple } from '@stacks/stacking'; import { timeout } from '@hirosystems/api-toolkit'; import { hexToBytes } from '@stacks/common'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; -import { TransactionEventsResponse } from '../api/schemas/responses/responses'; -import { StxLockTransactionEvent } from '../api/schemas/entities/transaction-events'; -import { ContractCallTransaction } from '../api/schemas/entities/transactions'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; +import { TransactionEventsResponse } from '../../src/api/schemas/responses/responses'; +import { StxLockTransactionEvent } from '../../src/api/schemas/entities/transaction-events'; +import { ContractCallTransaction } from '../../src/api/schemas/entities/transactions'; // Perform Stack-STX operation on Bitcoin. // See https://github.com/stacksgov/sips/blob/0da29c6911c49c45e4125dbeaed58069854591eb/sips/sip-007/sip-007-stacking-consensus.md#stx-operations-on-bitcoin diff --git a/src/tests-2.5/pox-4-delegate-aggregation.ts b/tests/2.5/pox-4-delegate-aggregation.test.ts similarity index 98% rename from src/tests-2.5/pox-4-delegate-aggregation.ts rename to tests/2.5/pox-4-delegate-aggregation.test.ts index fdf18d508e..33d1db5bda 100644 --- a/src/tests-2.5/pox-4-delegate-aggregation.ts +++ b/tests/2.5/pox-4-delegate-aggregation.test.ts @@ -1,5 +1,5 @@ -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { testnetKeys } from '../api/routes/debug'; +import { CoreRpcPoxInfo } from '../../src/core-rpc/client'; +import { testnetKeys } from '../../src/api/routes/debug'; import { Account, accountFromKey, @@ -12,8 +12,8 @@ import { standByForAccountUnlock, testEnv, standByUntilBurnBlock, -} from '../test-utils/test-helpers'; -import { stxToMicroStx } from '../helpers'; +} from '../utils/test-helpers'; +import { stxToMicroStx } from '../../src/helpers'; import { AnchorMode, StacksPrivateKey, @@ -38,7 +38,7 @@ import * as assert from 'assert'; import { hexToBytes } from '@stacks/common'; import { StackingClient } from '@stacks/stacking'; import { getPublicKeyFromPrivate } from '@stacks/encryption'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; describe('PoX-4 - Delegate aggregation increase operations', () => { const seedKey = testnetKeys[4].secretKey; diff --git a/src/tests-2.5/pox-4-delegate-revoked-stacking.ts b/tests/2.5/pox-4-delegate-revoked-stacking.test.ts similarity index 98% rename from src/tests-2.5/pox-4-delegate-revoked-stacking.ts rename to tests/2.5/pox-4-delegate-revoked-stacking.test.ts index a1b95660da..0b21119904 100644 --- a/src/tests-2.5/pox-4-delegate-revoked-stacking.ts +++ b/tests/2.5/pox-4-delegate-revoked-stacking.test.ts @@ -14,10 +14,10 @@ import { uintCV, } from '@stacks/transactions'; import { ClarityValueTuple, ClarityValueUInt, decodeClarityValue } from 'stacks-encoding-native-js'; -import { testnetKeys } from '../api/routes/debug'; -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { DbTxStatus } from '../datastore/common'; -import { stxToMicroStx } from '../helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { CoreRpcPoxInfo } from '../../src/core-rpc/client'; +import { DbTxStatus } from '../../src/datastore/common'; +import { stxToMicroStx } from '../../src/helpers'; import { Account, accountFromKey, @@ -28,10 +28,10 @@ import { standByForTx, standByForTxSuccess, testEnv, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; import { hexToBytes } from '@stacks/common'; import { getPublicKeyFromPrivate } from '@stacks/encryption'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; describe('PoX-4 - Delegate Revoked Stacking', () => { const seedKey = testnetKeys[4].secretKey; diff --git a/src/tests-2.5/pox-4-delegate-stacking.ts b/tests/2.5/pox-4-delegate-stacking.test.ts similarity index 98% rename from src/tests-2.5/pox-4-delegate-stacking.ts rename to tests/2.5/pox-4-delegate-stacking.test.ts index bd634cff3f..ec6b399be2 100644 --- a/src/tests-2.5/pox-4-delegate-stacking.ts +++ b/tests/2.5/pox-4-delegate-stacking.test.ts @@ -1,5 +1,5 @@ -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { testnetKeys } from '../api/routes/debug'; +import { CoreRpcPoxInfo } from '../../src/core-rpc/client'; +import { testnetKeys } from '../../src/api/routes/debug'; import { Account, accountFromKey, @@ -10,8 +10,8 @@ import { standByForTxSuccess, standByUntilBurnBlock, testEnv, -} from '../test-utils/test-helpers'; -import { stxToMicroStx } from '../helpers'; +} from '../utils/test-helpers'; +import { stxToMicroStx } from '../../src/helpers'; import { AnchorMode, StacksPrivateKey, @@ -29,7 +29,7 @@ import * as assert from 'assert'; import { StackingClient } from '@stacks/stacking'; import { getPublicKeyFromPrivate } from '@stacks/encryption'; import { hexToBytes } from '@stacks/common'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; describe('PoX-4 - Delegate Stacking operations', () => { const seedKey = testnetKeys[4].secretKey; diff --git a/src/tests-2.5/pox-4-rosetta-btc-addr-types.ts b/tests/2.5/pox-4-rosetta-btc-addr-types.test.ts similarity index 88% rename from src/tests-2.5/pox-4-rosetta-btc-addr-types.ts rename to tests/2.5/pox-4-rosetta-btc-addr-types.test.ts index b1a611036e..7264443f26 100644 --- a/src/tests-2.5/pox-4-rosetta-btc-addr-types.ts +++ b/tests/2.5/pox-4-rosetta-btc-addr-types.test.ts @@ -1,16 +1,16 @@ import { timeout } from '@hirosystems/api-toolkit'; -import { testnetKeys } from '../api/routes/debug'; -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { DbTxStatus } from '../datastore/common'; -import { getBitcoinAddressFromKey } from '../ec-helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { CoreRpcPoxInfo } from '../../src/core-rpc/client'; +import { DbTxStatus } from '../../src/datastore/common'; +import { getBitcoinAddressFromKey } from '../../src/ec-helpers'; import { fetchGet, stackStxWithRosetta, standByForPoxCycle, standByUntilBurnBlock, testEnv, -} from '../test-utils/test-helpers'; -import { BurnchainRewardSlotHolderListResponse } from '../api/schemas/responses/responses'; +} from '../utils/test-helpers'; +import { BurnchainRewardSlotHolderListResponse } from '../../src/api/schemas/responses/responses'; const BTC_ADDRESS_CASES = [ { addressFormat: 'p2pkh' }, diff --git a/src/tests-2.5/pox-4-rosetta-cycle-phases.ts b/tests/2.5/pox-4-rosetta-cycle-phases.test.ts similarity index 93% rename from src/tests-2.5/pox-4-rosetta-cycle-phases.ts rename to tests/2.5/pox-4-rosetta-cycle-phases.test.ts index 93426b67ec..5777366ea9 100644 --- a/src/tests-2.5/pox-4-rosetta-cycle-phases.ts +++ b/tests/2.5/pox-4-rosetta-cycle-phases.test.ts @@ -1,7 +1,5 @@ -import { bytesToHex } from '@stacks/common'; -import { randomBytes } from '@stacks/transactions'; -import { testnetKeys } from '../api/routes/debug'; -import { stackStxWithRosetta, standByUntilBurnBlock, testEnv } from '../test-utils/test-helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { stackStxWithRosetta, standByUntilBurnBlock, testEnv } from '../utils/test-helpers'; const REWARD_CYCLE_LENGTH = 5; // assuming regtest const BLOCK_SHIFT_COUNT: { shift: number }[] = []; diff --git a/src/tests-2.5/pox-4-rosetta-segwit.ts b/tests/2.5/pox-4-rosetta-segwit.test.ts similarity index 97% rename from src/tests-2.5/pox-4-rosetta-segwit.ts rename to tests/2.5/pox-4-rosetta-segwit.test.ts index 8a6a38f9fd..3f3ea593ee 100644 --- a/src/tests-2.5/pox-4-rosetta-segwit.ts +++ b/tests/2.5/pox-4-rosetta-segwit.test.ts @@ -9,9 +9,8 @@ import { randomBytes, } from '@stacks/transactions'; import bignumber from 'bignumber.js'; -import { testnetKeys } from '../api/routes/debug'; -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { ECPair, getBitcoinAddressFromKey } from '../ec-helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { ECPair, getBitcoinAddressFromKey } from '../../src/ec-helpers'; import { fetchGet, getRosettaAccountBalance, @@ -23,9 +22,9 @@ import { standByUntilBlock, standByUntilBurnBlock, testEnv, -} from '../test-utils/test-helpers'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; -import { BurnchainRewardListResponse } from '../api/schemas/responses/responses'; +} from '../utils/test-helpers'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; +import { BurnchainRewardListResponse } from '../../src/api/schemas/responses/responses'; describe('PoX-4 - Rosetta - Stacking with segwit', () => { let btcAddr: string; diff --git a/src/tests-2.5/pox-4-stack-extend-increase.ts b/tests/2.5/pox-4-stack-extend-increase.test.ts similarity index 97% rename from src/tests-2.5/pox-4-stack-extend-increase.ts rename to tests/2.5/pox-4-stack-extend-increase.test.ts index a39f7b96df..9eb10aed7c 100644 --- a/src/tests-2.5/pox-4-stack-extend-increase.ts +++ b/tests/2.5/pox-4-stack-extend-increase.test.ts @@ -1,6 +1,6 @@ -import { testnetKeys } from '../api/routes/debug'; -import { CoreRpcPoxInfo } from '../core-rpc/client'; -import { getBitcoinAddressFromKey, privateToPublicKey } from '../ec-helpers'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { CoreRpcPoxInfo } from '../../src/core-rpc/client'; +import { getBitcoinAddressFromKey, privateToPublicKey } from '../../src/ec-helpers'; import { AnchorMode, StacksPrivateKey, @@ -12,25 +12,25 @@ import { uintCV, } from '@stacks/transactions'; import bignumber from 'bignumber.js'; -import { DbEventTypeId, DbStxLockEvent } from '../datastore/common'; +import { DbEventTypeId, DbStxLockEvent } from '../../src/datastore/common'; import { fetchGet, standByForPoxCycle, standByForTxSuccess, standByUntilBurnBlock, testEnv, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; import { decodeBtcAddress, StackingClient } from '@stacks/stacking'; import { hexToBuffer } from '@hirosystems/api-toolkit'; import * as assert from 'assert'; import { hexToBytes } from '@stacks/common'; import { getPublicKeyFromPrivate } from '@stacks/encryption'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; import { BurnchainRewardListResponse, BurnchainRewardSlotHolderListResponse, -} from '../api/schemas/responses/responses'; -import { BurnchainRewardsTotal } from '../api/schemas/entities/burnchain-rewards'; +} from '../../src/api/schemas/responses/responses'; +import { BurnchainRewardsTotal } from '../../src/api/schemas/entities/burnchain-rewards'; describe('PoX-4 - Stack extend and increase operations', () => { const account = testnetKeys[1]; diff --git a/src/tests/address-tests.ts b/tests/api/address.test.ts similarity index 99% rename from src/tests/address-tests.ts rename to tests/api/address.test.ts index 1541d1b5dc..f416c2870a 100644 --- a/src/tests/address-tests.ts +++ b/tests/api/address.test.ts @@ -11,7 +11,7 @@ import { stringAsciiCV, serializeCV, } from '@stacks/transactions'; -import { createClarityValueArray } from '../stacks-encoding-helpers'; +import { createClarityValueArray } from '../../src/stacks-encoding-helpers'; import { decodeTransaction } from 'stacks-encoding-native-js'; import { DbBlock, @@ -29,18 +29,18 @@ import { DbTxRaw, DbMempoolTxRaw, DbTx, -} from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX } from '../helpers'; +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX } from '../../src/helpers'; import { TestBlockBuilder, testMempoolTx, TestMicroblockStreamBuilder, -} from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { createDbTxFromCoreMsg } from '../datastore/helpers'; +} from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { createDbTxFromCoreMsg } from '../../src/datastore/helpers'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('address tests', () => { let db: PgWriteStore; diff --git a/src/tests/block-tests.ts b/tests/api/block.test.ts similarity index 99% rename from src/tests/block-tests.ts rename to tests/api/block.test.ts index be07744436..e2d99c5e88 100644 --- a/src/tests/block-tests.ts +++ b/tests/api/block.test.ts @@ -1,19 +1,19 @@ import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { getBlockFromDataStore } from '../api/controllers/db-controller'; +import { getBlockFromDataStore } from '../../src/api/controllers/db-controller'; import { DbBlock, DbTxRaw, DbTxTypeId, DbTxStatus, DataStoreBlockUpdateData, -} from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX, unixEpochToIso } from '../helpers'; -import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX, unixEpochToIso } from '../../src/helpers'; +import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; import { BlockListV2Response } from 'src/api/schemas/responses/responses'; describe('block tests', () => { diff --git a/src/tests/burnchain-tests.ts b/tests/api/burnchain.test.ts similarity index 98% rename from src/tests/burnchain-tests.ts rename to tests/api/burnchain.test.ts index b2b93bb5d5..f811a46a38 100644 --- a/src/tests/burnchain-tests.ts +++ b/tests/api/burnchain.test.ts @@ -1,10 +1,10 @@ import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { DbBurnchainReward, DbRewardSlotHolder } from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { DbBurnchainReward, DbRewardSlotHolder } from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { PgSqlClient } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('burnchain tests', () => { let db: PgWriteStore; diff --git a/src/tests/cache-control-tests.ts b/tests/api/cache-control.test.ts similarity index 97% rename from src/tests/cache-control-tests.ts rename to tests/api/cache-control.test.ts index 18c3c57e6a..92b30122af 100644 --- a/src/tests/cache-control-tests.ts +++ b/tests/api/cache-control.test.ts @@ -1,14 +1,20 @@ import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { getBlockFromDataStore } from '../api/controllers/db-controller'; -import { DbBlock, DbMicroblockPartial, DbTxRaw, DbTxStatus, DbTxTypeId } from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX } from '../helpers'; -import { parseIfNoneMatchHeader } from '../api/controllers/cache-controller'; -import { TestBlockBuilder, testMempoolTx } from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { getBlockFromDataStore } from '../../src/api/controllers/db-controller'; +import { + DbBlock, + DbMicroblockPartial, + DbTxRaw, + DbTxStatus, + DbTxTypeId, +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX } from '../../src/helpers'; +import { parseIfNoneMatchHeader } from '../../src/api/controllers/cache-controller'; +import { TestBlockBuilder, testMempoolTx } from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('cache-control tests', () => { let db: PgWriteStore; diff --git a/src/tests/datastore-tests.ts b/tests/api/datastore.test.ts similarity index 99% rename from src/tests/datastore-tests.ts rename to tests/api/datastore.test.ts index fe36ea8aaa..e24e30ff2e 100644 --- a/src/tests/datastore-tests.ts +++ b/tests/api/datastore.test.ts @@ -21,16 +21,15 @@ import { DbTx, DataStoreBnsBlockTxData, ReOrgUpdatedEntities, -} from '../datastore/common'; -import { getBlocksWithMetadata, parseDbEvent } from '../api/controllers/db-controller'; +} from '../../src/datastore/common'; +import { getBlocksWithMetadata, parseDbEvent } from '../../src/api/controllers/db-controller'; import * as assert from 'assert'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { bnsNameCV, I32_MAX, NETWORK_CHAIN_ID } from '../helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { bnsNameCV, I32_MAX } from '../../src/helpers'; import { ChainID } from '@stacks/transactions'; -import { TestBlockBuilder } from '../test-utils/test-builders'; +import { TestBlockBuilder } from '../utils/test-builders'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; -import { CoreNodeBlockMessage } from '../event-stream/core-node-message'; +import { migrate } from '../utils/test-helpers'; describe('postgres datastore', () => { let db: PgWriteStore; diff --git a/src/tests/event-replay-logs/mainnet-out-of-order-microblock.tsv b/tests/api/event-replay-logs/mainnet-out-of-order-microblock.tsv similarity index 100% rename from src/tests/event-replay-logs/mainnet-out-of-order-microblock.tsv rename to tests/api/event-replay-logs/mainnet-out-of-order-microblock.tsv diff --git a/src/tests/event-replay-logs/mainnet-reorg-scenario1.tsv b/tests/api/event-replay-logs/mainnet-reorg-scenario1.tsv similarity index 100% rename from src/tests/event-replay-logs/mainnet-reorg-scenario1.tsv rename to tests/api/event-replay-logs/mainnet-reorg-scenario1.tsv diff --git a/src/tests/event-replay-logs/mainnet-reorg-scenario2.tsv b/tests/api/event-replay-logs/mainnet-reorg-scenario2.tsv similarity index 100% rename from src/tests/event-replay-logs/mainnet-reorg-scenario2.tsv rename to tests/api/event-replay-logs/mainnet-reorg-scenario2.tsv diff --git a/src/tests/faucet-stx-tests.ts b/tests/api/faucet-stx.test.ts similarity index 92% rename from src/tests/faucet-stx-tests.ts rename to tests/api/faucet-stx.test.ts index 42431e2962..b7fb5f8dfe 100644 --- a/src/tests/faucet-stx-tests.ts +++ b/tests/api/faucet-stx.test.ts @@ -1,5 +1,5 @@ import * as process from 'process'; -import { getStxFaucetNetworks } from '../api/routes/faucets'; +import { getStxFaucetNetworks } from '../../src/helpers'; describe('stx faucet', () => { test('faucet node env var override', () => { diff --git a/src/tests/helpers-tests.ts b/tests/api/helpers.test.ts similarity index 98% rename from src/tests/helpers-tests.ts rename to tests/api/helpers.test.ts index 87c8c22d79..d2c706e111 100644 --- a/src/tests/helpers-tests.ts +++ b/tests/api/helpers.test.ts @@ -1,13 +1,12 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import * as c32check from 'c32check'; import { bitcoinToStacksAddress, stacksToBitcoinAddress } from 'stacks-encoding-native-js'; -import * as c32AddrCache from '../c32-addr-cache'; -import { ADDR_CACHE_ENV_VAR } from '../c32-addr-cache'; -import { isValidBitcoinAddress, getUintEnvOrDefault, BitVec } from '../helpers'; -import { ECPair, getBitcoinAddressFromKey } from '../ec-helpers'; +import * as c32AddrCache from '../../src/c32-addr-cache'; +import { ADDR_CACHE_ENV_VAR } from '../../src/c32-addr-cache'; +import { isValidBitcoinAddress, getUintEnvOrDefault, BitVec } from '../../src/helpers'; +import { ECPair, getBitcoinAddressFromKey } from '../../src/ec-helpers'; import { decodeBtcAddress, poxAddressToBtcAddress } from '@stacks/stacking'; import { has0xPrefix } from '@hirosystems/api-toolkit'; -import { CoreNodeBlockMessage } from '../event-stream/core-node-message'; describe('has0xPrefix()', () => { test('falsy case, where there be no 0x', () => { diff --git a/src/tests/import-genesis-tests.ts b/tests/api/import-genesis.test.ts similarity index 92% rename from src/tests/import-genesis-tests.ts rename to tests/api/import-genesis.test.ts index fa26ae3b32..2fdc3331fd 100644 --- a/src/tests/import-genesis-tests.ts +++ b/tests/api/import-genesis.test.ts @@ -1,7 +1,7 @@ -import { importV1TokenOfferingData } from '../import-v1'; +import { importV1TokenOfferingData } from '../../src/import-v1'; import { bitcoinToStacksAddress } from 'stacks-encoding-native-js'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; describe('import genesis data tests', () => { let db: PgWriteStore; diff --git a/src/tests/mempool-tests.ts b/tests/api/mempool.test.ts similarity index 99% rename from src/tests/mempool-tests.ts rename to tests/api/mempool.test.ts index 3b10fa86ce..4db5dce753 100644 --- a/src/tests/mempool-tests.ts +++ b/tests/api/mempool.test.ts @@ -1,7 +1,7 @@ import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { startApiServer, ApiServer } from '../api/init'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { DbBlock, DbTxRaw, @@ -9,16 +9,16 @@ import { DbMempoolTxRaw, DbTxStatus, DataStoreBlockUpdateData, -} from '../datastore/common'; -import { I32_MAX } from '../helpers'; +} from '../../src/datastore/common'; +import { I32_MAX } from '../../src/helpers'; import { TestBlockBuilder, testMempoolTx, TestMicroblockStreamBuilder, -} from '../test-utils/test-builders'; -import { getPagingQueryLimit, ResourceType } from '../api/pagination'; +} from '../utils/test-builders'; +import { getPagingQueryLimit, ResourceType } from '../../src/api/pagination'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('mempool tests', () => { let db: PgWriteStore; diff --git a/src/tests/microblock-tests.ts b/tests/api/microblock.test.ts similarity index 96% rename from src/tests/microblock-tests.ts rename to tests/api/microblock.test.ts index 75396e0175..fcccf49209 100644 --- a/src/tests/microblock-tests.ts +++ b/tests/api/microblock.test.ts @@ -17,14 +17,14 @@ import { DbMicroblockPartial, DbSmartContractEvent, DbSmartContract, -} from '../datastore/common'; -import { startApiServer } from '../api/init'; -import { httpPostRequest, I32_MAX } from '../helpers'; +} from '../../src/datastore/common'; +import { startApiServer } from '../../src/api/init'; +import { httpPostRequest, I32_MAX } from '../../src/helpers'; import { ContractCallTransaction, MempoolTransaction, Transaction, -} from '../api/schemas/entities/transactions'; +} from '../../src/api/schemas/entities/transactions'; import { AddressStxInboundListResponse, AddressTransactionsListResponse, @@ -32,18 +32,18 @@ import { MempoolTransactionListResponse, MicroblockListResponse, TransactionResults, -} from '../api/schemas/responses/responses'; -import { Microblock } from '../api/schemas/entities/microblock'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; +} from '../../src/api/schemas/responses/responses'; +import { Microblock } from '../../src/api/schemas/entities/microblock'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; import { useWithCleanup } from './test-helpers'; -import { startEventServer } from '../event-stream/event-server'; +import { startEventServer } from '../../src/event-stream/event-server'; import * as fs from 'fs'; -import { createClarityValueArray } from '../stacks-encoding-helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { getRawEventRequests } from '../event-replay/event-requests'; -import { logger } from '../logger'; +import { createClarityValueArray } from '../../src/stacks-encoding-helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { getRawEventRequests } from '../../src/event-replay/event-requests'; +import { logger } from '../../src/logger'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('microblock tests', () => { let db: PgWriteStore; @@ -74,7 +74,7 @@ describe('microblock tests', () => { }, () => { const readStream = fs.createReadStream( - 'src/tests/event-replay-logs/mainnet-out-of-order-microblock.tsv' + 'tests/api/event-replay-logs/mainnet-out-of-order-microblock.tsv' ); const rawEventsIterator = getRawEventRequests(readStream); return [rawEventsIterator, () => readStream.close()] as const; @@ -134,7 +134,7 @@ describe('microblock tests', () => { }, () => { const readStream = fs.createReadStream( - 'src/tests/event-replay-logs/mainnet-reorg-scenario1.tsv' + 'tests/api/event-replay-logs/mainnet-reorg-scenario1.tsv' ); const rawEventsIterator = getRawEventRequests(readStream); return [rawEventsIterator, () => readStream.close()] as const; @@ -198,7 +198,7 @@ describe('microblock tests', () => { }, () => { const readStream = fs.createReadStream( - 'src/tests/event-replay-logs/mainnet-reorg-scenario2.tsv' + 'tests/api/event-replay-logs/mainnet-reorg-scenario2.tsv' ); const rawEventsIterator = getRawEventRequests(readStream); return [rawEventsIterator, () => readStream.close()] as const; diff --git a/src/tests/other-tests.ts b/tests/api/other.test.ts similarity index 96% rename from src/tests/other-tests.ts rename to tests/api/other.test.ts index a8b0201b58..86f8de19bd 100644 --- a/src/tests/other-tests.ts +++ b/tests/api/other.test.ts @@ -8,14 +8,14 @@ import { DbEventTypeId, DbAssetEventTypeId, DbMinerReward, -} from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX, microStxToStx, STACKS_DECIMAL_PLACES } from '../helpers'; -import { FEE_RATE } from '../api/routes/fee-rate'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { getPagingQueryLimit, ResourceType } from '../api/pagination'; +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX, microStxToStx, STACKS_DECIMAL_PLACES } from '../../src/helpers'; +import { FEE_RATE } from '../../src/api/routes/fee-rate'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { getPagingQueryLimit, ResourceType } from '../../src/api/pagination'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('other tests', () => { let db: PgWriteStore; diff --git a/src/tests/out-of-order-multisig-tests.ts b/tests/api/out-of-order-multisig.test.ts similarity index 79% rename from src/tests/out-of-order-multisig-tests.ts rename to tests/api/out-of-order-multisig.test.ts index 766593cfe5..205d969f75 100644 --- a/src/tests/out-of-order-multisig-tests.ts +++ b/tests/api/out-of-order-multisig.test.ts @@ -1,13 +1,13 @@ import * as supertest from 'supertest'; import { PgSqlClient } from '@hirosystems/api-toolkit'; import { ChainID } from '@stacks/common'; -import { ApiServer, startApiServer } from '../api/init'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { importEventsFromTsv } from '../event-replay/event-replay'; -import { migrate } from '../test-utils/test-helpers'; -import { Transaction } from '../api/schemas/entities/transactions'; -import { TransactionResults } from '../api/schemas/responses/responses'; -import { AddressTransaction } from '../api/schemas/entities/addresses'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { importEventsFromTsv } from '../../src/event-replay/event-replay'; +import { migrate } from '../utils/test-helpers'; +import { Transaction } from '../../src/api/schemas/entities/transactions'; +import { TransactionResults } from '../../src/api/schemas/responses/responses'; +import { AddressTransaction } from '../../src/api/schemas/entities/addresses'; describe('Out-of-order-multisig tx tests', () => { let db: PgWriteStore; @@ -39,7 +39,7 @@ describe('Out-of-order-multisig tx tests', () => { test('tsv replay with out-of-order-multisig tx', async () => { await importEventsFromTsv( - 'src/tests/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv', + 'tests/api/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv', 'archival', true, true diff --git a/src/tests/pagination-tests.ts b/tests/api/pagination.test.ts similarity index 96% rename from src/tests/pagination-tests.ts rename to tests/api/pagination.test.ts index bd67c17152..6995db745d 100644 --- a/src/tests/pagination-tests.ts +++ b/tests/api/pagination.test.ts @@ -1,4 +1,4 @@ -import { parsePagingQueryInput, getPagingQueryLimit, ResourceType } from '../api/pagination'; +import { parsePagingQueryInput, getPagingQueryLimit, ResourceType } from '../../src/api/pagination'; describe('parsePagingQueryInput()', () => { test('it returns same input when passed number', () => { diff --git a/src/tests/parse-db-tx.ts b/tests/api/parse-db-tx.test.ts similarity index 100% rename from src/tests/parse-db-tx.ts rename to tests/api/parse-db-tx.test.ts diff --git a/src/tests/pox-tests.ts b/tests/api/pox.test.ts similarity index 95% rename from src/tests/pox-tests.ts rename to tests/api/pox.test.ts index f0d70285ec..eeea423c4c 100644 --- a/src/tests/pox-tests.ts +++ b/tests/api/pox.test.ts @@ -1,10 +1,10 @@ import * as supertest from 'supertest'; import { PgSqlClient, timeout } from '@hirosystems/api-toolkit'; import { ChainID } from '@stacks/common'; -import { ApiServer, startApiServer } from '../api/init'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { importEventsFromTsv } from '../event-replay/event-replay'; -import { migrate } from '../test-utils/test-helpers'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { importEventsFromTsv } from '../../src/event-replay/event-replay'; +import { migrate } from '../utils/test-helpers'; describe('PoX tests', () => { let db: PgWriteStore; @@ -43,7 +43,7 @@ describe('PoX tests', () => { }); test('api', async () => { - await importEventsFromTsv('src/tests/tsv/epoch-3-transition.tsv', 'archival', true, true); + await importEventsFromTsv('tests/api/tsv/epoch-3-transition.tsv', 'archival', true, true); const cycles = await supertest(api.server).get(`/extended/v2/pox/cycles`); expect(cycles.status).toBe(200); expect(cycles.type).toBe('application/json'); @@ -186,7 +186,7 @@ describe('PoX tests', () => { test('snapshot 1', async () => { await importEventsFromTsv( - 'src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv', + 'tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv', 'archival', true, true @@ -200,7 +200,7 @@ describe('PoX tests', () => { test('snapshot 2', async () => { await importEventsFromTsv( - 'src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv', + 'tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv', 'archival', true, true @@ -220,7 +220,7 @@ describe('PoX tests', () => { test('snapshot 3', async () => { await importEventsFromTsv( - 'src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv', + 'tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv', 'archival', true, true diff --git a/src/tests/profiler-tests.ts b/tests/api/profiler.test.ts similarity index 93% rename from src/tests/profiler-tests.ts rename to tests/api/profiler.test.ts index 8c12e763b7..03af600832 100644 --- a/src/tests/profiler-tests.ts +++ b/tests/api/profiler.test.ts @@ -1,8 +1,8 @@ import * as http from 'http'; import * as supertest from 'supertest'; -import { httpGetRequest, readHttpResponse } from '../helpers'; -import { startProfilerServer } from '../inspector-util'; +import { httpGetRequest, readHttpResponse } from '../../src/helpers'; +import { startProfilerServer } from '../../src/inspector-util'; describe('profiler tests', () => { let profiler: { server: http.Server; address: string; close: () => Promise }; diff --git a/src/tests/search-tests.ts b/tests/api/search.test.ts similarity index 99% rename from src/tests/search-tests.ts rename to tests/api/search.test.ts index b767808047..6acf7537cf 100644 --- a/src/tests/search-tests.ts +++ b/tests/api/search.test.ts @@ -13,12 +13,12 @@ import { DbSmartContract, DataStoreBlockUpdateData, DbTxStatus, -} from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX } from '../helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX } from '../../src/helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('search tests', () => { let db: PgWriteStore; diff --git a/src/tests-event-replay/setup.ts b/tests/api/setup.ts similarity index 84% rename from src/tests-event-replay/setup.ts rename to tests/api/setup.ts index 737c21ed32..4cb071dd7e 100644 --- a/src/tests-event-replay/setup.ts +++ b/tests/api/setup.ts @@ -1,4 +1,4 @@ -import { loadDotEnv } from '../helpers'; +import { loadDotEnv } from '../../src/helpers'; // ts-unused-exports:disable-next-line export default (): void => { diff --git a/src/tests/smart-contract-tests.ts b/tests/api/smart-contract.test.ts similarity index 99% rename from src/tests/smart-contract-tests.ts rename to tests/api/smart-contract.test.ts index d8b8faa4e1..f3f53979e9 100644 --- a/src/tests/smart-contract-tests.ts +++ b/tests/api/smart-contract.test.ts @@ -7,13 +7,13 @@ import { DbEventTypeId, DbSmartContract, DbSmartContractEvent, -} from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX } from '../helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX } from '../../src/helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { bufferToHex, PgSqlClient, waiter } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; -import { TestBlockBuilder, testMempoolTx } from '../test-utils/test-builders'; +import { migrate } from '../utils/test-helpers'; +import { TestBlockBuilder, testMempoolTx } from '../utils/test-builders'; describe('smart contract tests', () => { let db: PgWriteStore; diff --git a/src/tests/socket-io-tests.ts b/tests/api/socket-io.test.ts similarity index 98% rename from src/tests/socket-io-tests.ts rename to tests/api/socket-io.test.ts index 42e5638cf7..af2a127b12 100644 --- a/src/tests/socket-io-tests.ts +++ b/tests/api/socket-io.test.ts @@ -1,14 +1,14 @@ import { io } from 'socket.io-client'; import { ChainID } from '@stacks/common'; -import { ApiServer, startApiServer } from '../api/init'; -import { DbAssetEventTypeId, DbTxStatus } from '../datastore/common'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { DbAssetEventTypeId, DbTxStatus } from '../../src/datastore/common'; import { TestBlockBuilder, testMempoolTx, TestMicroblockStreamBuilder, -} from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +} from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; import { Waiter, waiter } from '@hirosystems/api-toolkit'; import { StacksApiSocketClient } from '../../client/src/socket-io'; import { diff --git a/src/tests/synthetic-stx-txs-tests.ts b/tests/api/synthetic-stx-txs.test.ts similarity index 98% rename from src/tests/synthetic-stx-txs-tests.ts rename to tests/api/synthetic-stx-txs.test.ts index c13270bd96..dd88a5b8f7 100644 --- a/src/tests/synthetic-stx-txs-tests.ts +++ b/tests/api/synthetic-stx-txs.test.ts @@ -2,9 +2,9 @@ import { ChainID } from '@stacks/transactions'; import * as fs from 'fs'; import * as path from 'path'; import { DecodedTxResult, TxPayloadTypeID } from 'stacks-encoding-native-js'; -import { CoreNodeBlockMessage } from '../event-stream/core-node-message'; -import { parseMessageTransaction } from '../event-stream/reader'; -import { parseNewBlockMessage } from '../event-stream/event-server'; +import { CoreNodeBlockMessage } from '../../src/event-stream/core-node-message'; +import { parseMessageTransaction } from '../../src/event-stream/reader'; +import { parseNewBlockMessage } from '../../src/event-stream/event-server'; // Test processing of the psuedo-Stacks transactions, i.e. the ones that // originate on the Bitcoin chain, and have a `raw_tx == '0x00'. diff --git a/src/tests/synthetic-tx-payloads/failed-1352-0x2d825fbeb5368dcaeecdce053860e7d900bc66701751037f8b92dd7f8fd2a1b0.json b/tests/api/synthetic-tx-payloads/failed-1352-0x2d825fbeb5368dcaeecdce053860e7d900bc66701751037f8b92dd7f8fd2a1b0.json similarity index 100% rename from src/tests/synthetic-tx-payloads/failed-1352-0x2d825fbeb5368dcaeecdce053860e7d900bc66701751037f8b92dd7f8fd2a1b0.json rename to tests/api/synthetic-tx-payloads/failed-1352-0x2d825fbeb5368dcaeecdce053860e7d900bc66701751037f8b92dd7f8fd2a1b0.json diff --git a/src/tests/synthetic-tx-payloads/failed-6910-0x763e485177d772efdb1baede3276d5091a96e90fbb156d25427c1a2e7ea1d6fd.json b/tests/api/synthetic-tx-payloads/failed-6910-0x763e485177d772efdb1baede3276d5091a96e90fbb156d25427c1a2e7ea1d6fd.json similarity index 100% rename from src/tests/synthetic-tx-payloads/failed-6910-0x763e485177d772efdb1baede3276d5091a96e90fbb156d25427c1a2e7ea1d6fd.json rename to tests/api/synthetic-tx-payloads/failed-6910-0x763e485177d772efdb1baede3276d5091a96e90fbb156d25427c1a2e7ea1d6fd.json diff --git a/src/tests/synthetic-tx-payloads/stx_lock-1379-0xb182e2aacfe2ed4257d66dd2ed4872f672cf10d873852b5218f41594d6b42b11.json b/tests/api/synthetic-tx-payloads/stx_lock-1379-0xb182e2aacfe2ed4257d66dd2ed4872f672cf10d873852b5218f41594d6b42b11.json similarity index 100% rename from src/tests/synthetic-tx-payloads/stx_lock-1379-0xb182e2aacfe2ed4257d66dd2ed4872f672cf10d873852b5218f41594d6b42b11.json rename to tests/api/synthetic-tx-payloads/stx_lock-1379-0xb182e2aacfe2ed4257d66dd2ed4872f672cf10d873852b5218f41594d6b42b11.json diff --git a/src/tests/synthetic-tx-payloads/stx_lock-1994-0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc.json b/tests/api/synthetic-tx-payloads/stx_lock-1994-0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc.json similarity index 100% rename from src/tests/synthetic-tx-payloads/stx_lock-1994-0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc.json rename to tests/api/synthetic-tx-payloads/stx_lock-1994-0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc.json diff --git a/src/tests/synthetic-tx-payloads/stx_lock-51451-0xa64ad136e51a3a50eb1fdfd7eefa0b7aeb89e2521b2a2218d887477baa1775c9.json b/tests/api/synthetic-tx-payloads/stx_lock-51451-0xa64ad136e51a3a50eb1fdfd7eefa0b7aeb89e2521b2a2218d887477baa1775c9.json similarity index 100% rename from src/tests/synthetic-tx-payloads/stx_lock-51451-0xa64ad136e51a3a50eb1fdfd7eefa0b7aeb89e2521b2a2218d887477baa1775c9.json rename to tests/api/synthetic-tx-payloads/stx_lock-51451-0xa64ad136e51a3a50eb1fdfd7eefa0b7aeb89e2521b2a2218d887477baa1775c9.json diff --git a/src/tests/synthetic-tx-payloads/token_transfer-120-0xc0263c14f689ae757290f90765a28314497f52bd22b8bcbf87a12c764dd9d9be.json b/tests/api/synthetic-tx-payloads/token_transfer-120-0xc0263c14f689ae757290f90765a28314497f52bd22b8bcbf87a12c764dd9d9be.json similarity index 100% rename from src/tests/synthetic-tx-payloads/token_transfer-120-0xc0263c14f689ae757290f90765a28314497f52bd22b8bcbf87a12c764dd9d9be.json rename to tests/api/synthetic-tx-payloads/token_transfer-120-0xc0263c14f689ae757290f90765a28314497f52bd22b8bcbf87a12c764dd9d9be.json diff --git a/src/tests/synthetic-tx-payloads/token_transfer-51655-0x2553c7c5b49eab5a0569e5d0f14c8f15945965a51976ac6697641003533986f6.json b/tests/api/synthetic-tx-payloads/token_transfer-51655-0x2553c7c5b49eab5a0569e5d0f14c8f15945965a51976ac6697641003533986f6.json similarity index 100% rename from src/tests/synthetic-tx-payloads/token_transfer-51655-0x2553c7c5b49eab5a0569e5d0f14c8f15945965a51976ac6697641003533986f6.json rename to tests/api/synthetic-tx-payloads/token_transfer-51655-0x2553c7c5b49eab5a0569e5d0f14c8f15945965a51976ac6697641003533986f6.json diff --git a/src/tests-btc-faucet/teardown.ts b/tests/api/teardown.ts similarity index 100% rename from src/tests-btc-faucet/teardown.ts rename to tests/api/teardown.ts diff --git a/src/tests/test-helpers.ts b/tests/api/test-helpers.ts similarity index 91% rename from src/tests/test-helpers.ts rename to tests/api/test-helpers.ts index 5d79c4b273..f961f10885 100644 --- a/src/tests/test-helpers.ts +++ b/tests/api/test-helpers.ts @@ -1,7 +1,3 @@ -// Hack to avoid jest outputting 'Your test suite must contain at least one test.' -// https://stackoverflow.com/a/59864054/794962 -test.skip('test-ignore-kludge', () => undefined); - type Disposable = () => | readonly [item: T, dispose: () => any | Promise] | Promise any | Promise]>; diff --git a/src/tests/token-tests.ts b/tests/api/token.test.ts similarity index 99% rename from src/tests/token-tests.ts rename to tests/api/token.test.ts index d9a90d3017..d6f55e5f6c 100644 --- a/src/tests/token-tests.ts +++ b/tests/api/token.test.ts @@ -1,10 +1,10 @@ import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { ApiServer, startApiServer } from '../api/init'; -import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../test-utils/test-builders'; -import { DbAssetEventTypeId } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../utils/test-builders'; +import { DbAssetEventTypeId } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; describe('/extended/v1/tokens tests', () => { let db: PgWriteStore; diff --git a/src/tests/tsv/epoch-3-transition.tsv b/tests/api/tsv/epoch-3-transition.tsv similarity index 100% rename from src/tests/tsv/epoch-3-transition.tsv rename to tests/api/tsv/epoch-3-transition.tsv diff --git a/src/tests/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv b/tests/api/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv similarity index 100% rename from src/tests/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv rename to tests/api/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv diff --git a/src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv b/tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv similarity index 100% rename from src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv rename to tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv diff --git a/src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv b/tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv similarity index 100% rename from src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv rename to tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv diff --git a/src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv b/tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv similarity index 100% rename from src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv rename to tests/api/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv diff --git a/src/tests/tx-tests.ts b/tests/api/tx.test.ts similarity index 99% rename from src/tests/tx-tests.ts rename to tests/api/tx.test.ts index ba61925e9e..042f477178 100644 --- a/src/tests/tx-tests.ts +++ b/tests/api/tx.test.ts @@ -20,9 +20,9 @@ import { bufferCV, stringAsciiCV, } from '@stacks/transactions'; -import { createClarityValueArray } from '../stacks-encoding-helpers'; +import { createClarityValueArray } from '../../src/stacks-encoding-helpers'; import { decodeTransaction, TxPayloadVersionedSmartContract } from 'stacks-encoding-native-js'; -import { getTxFromDataStore, TransactionType } from '../api/controllers/db-controller'; +import { getTxFromDataStore, TransactionType } from '../../src/api/controllers/db-controller'; import { DbBlock, DbTxRaw, @@ -36,16 +36,16 @@ import { DataStoreBlockUpdateData, DbTxAnchorMode, DbStxEvent, -} from '../datastore/common'; -import { startApiServer, ApiServer } from '../api/init'; -import { I32_MAX } from '../helpers'; -import { TestBlockBuilder } from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { createDbTxFromCoreMsg } from '../datastore/helpers'; -import { getPagingQueryLimit, ResourceType } from '../api/pagination'; +} from '../../src/datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { I32_MAX } from '../../src/helpers'; +import { TestBlockBuilder } from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { createDbTxFromCoreMsg } from '../../src/datastore/helpers'; +import { getPagingQueryLimit, ResourceType } from '../../src/api/pagination'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; -import { Transaction } from '../api/schemas/entities/transactions'; +import { migrate } from '../utils/test-helpers'; +import { Transaction } from '../../src/api/schemas/entities/transactions'; describe('tx tests', () => { let db: PgWriteStore; diff --git a/src/tests/v2-proxy-tests.ts b/tests/api/v2-proxy.test.ts similarity index 94% rename from src/tests/v2-proxy-tests.ts rename to tests/api/v2-proxy.test.ts index 1d540b2663..0fa01aad28 100644 --- a/src/tests/v2-proxy-tests.ts +++ b/tests/api/v2-proxy.test.ts @@ -1,14 +1,14 @@ import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { startApiServer } from '../api/init'; +import { startApiServer } from '../../src/api/init'; import { useWithCleanup, withEnvVars } from './test-helpers'; import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; import * as nock from 'nock'; -import { DbBlock } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +import { DbBlock } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; describe('v2-proxy tests', () => { let db: PgWriteStore; diff --git a/src/tests/websocket-tests.ts b/tests/api/websocket.test.ts similarity index 98% rename from src/tests/websocket-tests.ts rename to tests/api/websocket.test.ts index b5a0da01a7..e69c591f00 100644 --- a/src/tests/websocket-tests.ts +++ b/tests/api/websocket.test.ts @@ -1,6 +1,6 @@ import * as WebSocket from 'ws'; -import { startApiServer, ApiServer } from '../api/init'; -import { DbTxTypeId, DbTxStatus, DbAssetEventTypeId } from '../datastore/common'; +import { startApiServer, ApiServer } from '../../src/api/init'; +import { DbTxTypeId, DbTxStatus, DbAssetEventTypeId } from '../../src/datastore/common'; import { once } from 'events'; import { RpcWebSocketClient } from 'rpc-websocket-client'; import { @@ -26,9 +26,9 @@ import { TestBlockBuilder, testMempoolTx, TestMicroblockStreamBuilder, -} from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +} from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; import { Waiter, waiter } from '@hirosystems/api-toolkit'; describe('websocket notifications', () => { diff --git a/src/tests/ws-transmitter-tests.ts b/tests/api/ws-transmitter.test.ts similarity index 85% rename from src/tests/ws-transmitter-tests.ts rename to tests/api/ws-transmitter.test.ts index d4284a09f8..ebde6c17fc 100644 --- a/src/tests/ws-transmitter-tests.ts +++ b/tests/api/ws-transmitter.test.ts @@ -1,13 +1,13 @@ -import { PgWriteStore } from '../datastore/pg-write-store'; -import { WebSocketTransmitter } from '../api/routes/ws/web-socket-transmitter'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { WebSocketTransmitter } from '../../src/api/routes/ws/web-socket-transmitter'; import { Server } from 'http'; import { ListenerType, WebSocketChannel, WebSocketPayload, WebSocketTopics, -} from '../api/routes/ws/web-socket-channel'; -import { migrate } from '../test-utils/test-helpers'; +} from '../../src/api/routes/ws/web-socket-channel'; +import { migrate } from '../utils/test-helpers'; class TestChannel extends WebSocketChannel { connect(): void { diff --git a/src/tests-bns-e2e/bns-integration-tests.ts b/tests/bns-e2e/bns-integration.test.ts similarity index 98% rename from src/tests-bns-e2e/bns-integration-tests.ts rename to tests/bns-e2e/bns-integration.test.ts index 0b6cfff928..8e505b57f0 100644 --- a/src/tests-bns-e2e/bns-integration-tests.ts +++ b/tests/bns-e2e/bns-integration.test.ts @@ -1,4 +1,4 @@ -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import * as supertest from 'supertest'; import { createHash } from 'crypto'; import { AnchorMode, ChainID, PostConditionMode, someCV } from '@stacks/transactions'; @@ -14,10 +14,10 @@ import { SignedContractCallOptions, noneCV, } from '@stacks/transactions'; -import { logger } from '../logger'; -import { testnetKeys } from '../api/routes/debug'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { standByForTx as standByForTxShared } from '../test-utils/test-helpers'; +import { logger } from '../../src/logger'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { standByForTx as standByForTxShared } from '../utils/test-helpers'; function hash160(bfr: Buffer): Buffer { const hash160 = createHash('ripemd160') diff --git a/src/tests-bns-e2e/setup.ts b/tests/bns-e2e/setup.ts similarity index 72% rename from src/tests-bns-e2e/setup.ts rename to tests/bns-e2e/setup.ts index 7cb3c98c09..5c6469ec41 100644 --- a/src/tests-bns-e2e/setup.ts +++ b/tests/bns-e2e/setup.ts @@ -1,4 +1,4 @@ -import { defaultSetupInit } from '../test-utils/shared-setup'; +import { defaultSetupInit } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { diff --git a/src/tests-bns-e2e/teardown.ts b/tests/bns-e2e/teardown.ts similarity index 72% rename from src/tests-bns-e2e/teardown.ts rename to tests/bns-e2e/teardown.ts index 53858b8433..948c18dcc4 100644 --- a/src/tests-bns-e2e/teardown.ts +++ b/tests/bns-e2e/teardown.ts @@ -1,4 +1,4 @@ -import { defaultSetupTeardown } from '../test-utils/shared-setup'; +import { defaultSetupTeardown } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { diff --git a/src/tests-bns/api.ts b/tests/bns/api.test.ts similarity index 93% rename from src/tests-bns/api.ts rename to tests/bns/api.test.ts index db29058e64..f9d832d19b 100644 --- a/src/tests-bns/api.ts +++ b/tests/bns/api.test.ts @@ -1,12 +1,18 @@ -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import * as supertest from 'supertest'; -import { DbAssetEventTypeId, DbBlock, DbBnsName, DbBnsNamespace, DbBnsSubdomain } from '../datastore/common'; +import { + DbAssetEventTypeId, + DbBlock, + DbBnsName, + DbBnsNamespace, + DbBnsSubdomain, +} from '../../src/datastore/common'; import * as StacksTransactions from '@stacks/transactions'; import { ChainID } from '@stacks/transactions'; -import { bnsNameCV, I32_MAX } from '../helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../test-utils/test-builders'; -import { migrate } from '../test-utils/test-helpers'; +import { bnsNameCV, I32_MAX } from '../../src/helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../utils/test-builders'; +import { migrate } from '../utils/test-helpers'; import { PgSqlClient } from '@hirosystems/api-toolkit'; const nameSpaceExpected = { @@ -32,9 +38,10 @@ jest.mock('@stacks/transactions', () => { const originalModule = jest.requireActual('@stacks/transactions'); const mockReadOnlyFunction = jest - .fn(()=> nameSpaceExpected) + .fn(() => nameSpaceExpected) .mockImplementationOnce(() => nameSpaceExpected) .mockImplementationOnce(() => nameExpected); + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return { __esModule: true, ...originalModule, @@ -200,14 +207,14 @@ describe('BNS API tests', () => { const block2 = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: 'xyz.abc', namespace_id: 'abc', status: 'name-revoke', - address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA' + address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', }) .build(); await db.update(block2); @@ -288,7 +295,7 @@ describe('BNS API tests', () => { const block = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x22' }) .addTxBnsName({ @@ -353,18 +360,18 @@ describe('BNS API tests', () => { const block3 = new TestBlockBuilder({ block_height: 3, index_block_hash: '0x03', - parent_index_block_hash: '0x02' + parent_index_block_hash: '0x02', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: 'test.btc', status: 'name-revoke', - address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA' + address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', }) .addTxBnsName({ name: 'id.blockstack', status: 'name-revoke', - address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA' + address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', }) .build(); await db.update(block3); @@ -421,7 +428,7 @@ describe('BNS API tests', () => { const block = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x22' }) .addTxBnsName({ @@ -459,7 +466,7 @@ describe('BNS API tests', () => { const block = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: dbBlock.index_block_hash + parent_index_block_hash: dbBlock.index_block_hash, }) .addTx({ tx_id: '0x22' }) .addTxBnsName({ @@ -508,10 +515,7 @@ describe('BNS API tests', () => { const query1 = await supertest(api.server).get(`/v1/addresses/${blockchain}/${address}`); expect(query1.status).toBe(200); - expect(query1.body.names).toStrictEqual([ - 'imported.btc', - 'test-name.btc' - ]); + expect(query1.body.names).toStrictEqual(['imported.btc', 'test-name.btc']); expect(query1.type).toBe('application/json'); const subdomain: DbBnsSubdomain = { @@ -547,69 +551,60 @@ describe('BNS API tests', () => { expect(query2.body.names).toStrictEqual([ 'address_test.id.blockstack', 'imported.btc', - 'test-name.btc' + 'test-name.btc', ]); // Transfer name to somebody else. const block3 = new TestBlockBuilder({ block_height: 3, index_block_hash: '0x03', - parent_index_block_hash: '0x02' + parent_index_block_hash: '0x02', }) .addTx({ tx_id: '0xf3f3' }) .addTxNftEvent({ sender: address, recipient: address2, asset_identifier: 'ST000000000000000000002AMW42H.bns::names', - value: bnsNameCV(name) + value: bnsNameCV(name), }) .build(); await db.update(block3); const query3 = await supertest(api.server).get(`/v1/addresses/${blockchain}/${address}`); expect(query3.status).toBe(200); expect(query3.type).toBe('application/json'); - expect(query3.body.names).toStrictEqual([ - 'address_test.id.blockstack', - 'imported.btc' - ]); + expect(query3.body.names).toStrictEqual(['address_test.id.blockstack', 'imported.btc']); // New guy owns the name. const query4 = await supertest(api.server).get(`/v1/addresses/${blockchain}/${address2}`); expect(query4.status).toBe(200); expect(query4.type).toBe('application/json'); - expect(query4.body.names).toStrictEqual([ - 'test-name.btc' - ]); + expect(query4.body.names).toStrictEqual(['test-name.btc']); // Transfer imported name to another user. const block4 = new TestBlockBuilder({ block_height: 4, index_block_hash: '0x04', - parent_index_block_hash: '0x03' + parent_index_block_hash: '0x03', }) .addTx({ tx_id: '0xf3f4' }) .addTxNftEvent({ sender: address, recipient: address3, asset_identifier: 'ST000000000000000000002AMW42H.bns::names', - value: bnsNameCV('imported.btc') + value: bnsNameCV('imported.btc'), }) .build(); await db.update(block4); const query5 = await supertest(api.server).get(`/v1/addresses/${blockchain}/${address}`); expect(query5.status).toBe(200); expect(query5.type).toBe('application/json'); - expect(query5.body.names).toStrictEqual([ - 'address_test.id.blockstack' - ]); + expect(query5.body.names).toStrictEqual(['address_test.id.blockstack']); // Other guy owns the name. const query6 = await supertest(api.server).get(`/v1/addresses/${blockchain}/${address3}`); expect(query6.status).toBe(200); expect(query6.type).toBe('application/json'); - expect(query6.body.names).toStrictEqual([ - 'imported.btc' - ]); + expect(query6.body.names).toStrictEqual(['imported.btc']); await db.resolveBnsSubdomains( { @@ -651,7 +646,7 @@ describe('BNS API tests', () => { tx_index: 0, tx_id: '0x5454', canonical: true, - } + }, ] ); @@ -669,18 +664,18 @@ describe('BNS API tests', () => { const block5 = new TestBlockBuilder({ block_height: 5, index_block_hash: '0x05', - parent_index_block_hash: '0x04' + parent_index_block_hash: '0x04', }) .addTx({ tx_id: '0xf3f5' }) .addTxBnsName({ name: 'imported.btc', status: 'name-revoke', - address: address3 + address: address3, }) .addTxBnsName({ name: 'id.blockstack', status: 'name-revoke', - address: address3 + address: address3, }) .build(); await db.update(block5); @@ -702,7 +697,7 @@ describe('BNS API tests', () => { const block2 = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: dbBlock.index_block_hash + parent_index_block_hash: dbBlock.index_block_hash, }) .addTx({ tx_id: '0x22' }) .addTxBnsName({ @@ -731,7 +726,7 @@ describe('BNS API tests', () => { const block3 = new TestBlockBuilder({ block_height: 3, index_block_hash: '0x03', - parent_index_block_hash: '0x02' + parent_index_block_hash: '0x02', }) .addTx({ tx_id: '0x23' }) .addTxBnsName({ @@ -778,7 +773,7 @@ describe('BNS API tests', () => { const block = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x22' }) .addTxBnsName({ @@ -843,20 +838,18 @@ describe('BNS API tests', () => { const block3 = new TestBlockBuilder({ block_height: 3, index_block_hash: '0x03', - parent_index_block_hash: '0x02' + parent_index_block_hash: '0x02', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: name, status: 'name-revoke', - address: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP' + address: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP', }) .build(); await db.update(block3); - const query3 = await supertest(api.server).get( - `/v1/names/${name}/zonefile` - ); + const query3 = await supertest(api.server).get(`/v1/names/${name}/zonefile`); expect(query3.status).toBe(404); const query4 = await supertest(api.server).get( @@ -882,13 +875,13 @@ describe('BNS API tests', () => { const block2 = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: 'xyz.abc', status: 'name-revoke', - address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA' + address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', }) .build(); await db.update(block2); @@ -912,13 +905,13 @@ describe('BNS API tests', () => { const block2 = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: 'xyz.abc', status: 'name-revoke', - address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA' + address: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', }) .build(); await db.update(block2); @@ -976,13 +969,13 @@ describe('BNS API tests', () => { ); expect(query.status).toBe(200); expect(query.body).toStrictEqual({ - address: "test-address", - blockchain: "stacks", - last_txid: "0x1234", - resolver: "https://registrar.blockstack.org", - status: "registered_subdomain", - zonefile: "test", - zonefile_hash: "test-hash", + address: 'test-address', + blockchain: 'stacks', + last_txid: '0x1234', + resolver: 'https://registrar.blockstack.org', + status: 'registered_subdomain', + zonefile: 'test', + zonefile_hash: 'test-hash', }); }); @@ -1048,22 +1041,20 @@ describe('BNS API tests', () => { [subdomain] ); const query = await supertest(api.server).get(`/v1/names/id.blockstack/subdomains`); - const expectedResult = [ - 'zone_test.id.blockstack', - ]; + const expectedResult = ['zone_test.id.blockstack']; expect(query.body).toEqual(expectedResult); // Revoke name const block2 = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: 'id.blockstack', status: 'name-revoke', - address: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP' + address: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP', }) .build(); await db.update(block2); @@ -1081,7 +1072,7 @@ describe('BNS API tests', () => { const block2 = new TestBlockBuilder({ block_height: 2, index_block_hash: '0x02', - parent_index_block_hash: '0x1234' + parent_index_block_hash: '0x1234', }) .addTx({ tx_id: '0x1111' }) .addTxBnsName({ name: name, status: 'name-register', address: addr1 }) @@ -1112,7 +1103,7 @@ describe('BNS API tests', () => { .addMicroblock({ parent_index_block_hash: '0x02', microblock_hash: '0x12', - microblock_sequence: 0 + microblock_sequence: 0, }) .addTx({ tx_id: '0xf112' }) .addTxBnsName({ name: name, status: 'name-update', address: addr3 }) @@ -1129,7 +1120,7 @@ describe('BNS API tests', () => { block_height: 3, index_block_hash: '0x03', parent_index_block_hash: '0x02', - parent_microblock_hash: '0x11' + parent_microblock_hash: '0x11', }) .addTx() .build(); @@ -1138,5 +1129,5 @@ describe('BNS API tests', () => { const query = await supertest(api.server).get(`/v1/names/${name}`); expect(query.body.address).toEqual(addr2); expect(query.body.last_txid).toEqual('0xf111'); - }) + }); }); diff --git a/src/tests-bns/bns-helpers-tests.ts b/tests/bns/bns-helpers.test.ts similarity index 99% rename from src/tests-bns/bns-helpers-tests.ts rename to tests/bns/bns-helpers.test.ts index 58481de65b..32b1219bea 100644 --- a/src/tests-bns/bns-helpers-tests.ts +++ b/tests/bns/bns-helpers.test.ts @@ -2,7 +2,7 @@ import { parseNamespaceRawValue, parseNameRawValue, parseZoneFileTxt, -} from '../event-stream/bns/bns-helpers'; +} from '../../src/event-stream/bns/bns-helpers'; import * as zoneFileParser from 'zone-file'; describe('BNS helper tests', () => { diff --git a/tests/bns/event-server.test.ts b/tests/bns/event-server.test.ts new file mode 100644 index 0000000000..1660905e0f --- /dev/null +++ b/tests/bns/event-server.test.ts @@ -0,0 +1,1073 @@ +import { ChainID } from '@stacks/transactions'; +import { bnsNameCV, httpPostRequest } from '../../src/helpers'; +import { EventStreamServer, startEventServer } from '../../src/event-stream/event-server'; +import { TestBlockBuilder, TestMicroblockStreamBuilder } from '../utils/test-builders'; +import { DbAssetEventTypeId, DbBnsZoneFile } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { PgSqlClient } from '@hirosystems/api-toolkit'; +import { migrate } from '../utils/test-helpers'; + +describe('BNS event server tests', () => { + let db: PgWriteStore; + let client: PgSqlClient; + let eventServer: EventStreamServer; + + beforeEach(async () => { + await migrate('up'); + db = await PgWriteStore.connect({ usageName: 'tests', withNotifier: true }); + client = db.sql; + eventServer = await startEventServer({ + datastore: db, + chainId: ChainID.Mainnet, + serverHost: '127.0.0.1', + serverPort: 0, + }); + }); + + afterEach(async () => { + await eventServer.closeAsync(); + await db?.close(); + await migrate('down'); + }); + + test('namespace-ready called by a contract other than BNS', async () => { + const block = new TestBlockBuilder({ + block_height: 1, + index_block_hash: '0x29fe7ba9674b9196fefa28764a35a4603065dc25c9dcf83c56648066f36a8dce', + burn_block_height: 749661, + burn_block_hash: '0x000000000000000000021e9777470811a937006cf47efceadefca2e8031c4b5f', + burn_block_time: 1660638853, + }) + .addTx() + .build(); + await db.update(block); + const microblock = new TestMicroblockStreamBuilder() + .addMicroblock({ + microblock_hash: '0x8455c986ef89d09968b96fee0ef5b4625aa3860aa68e70123efa129f48e55c6b', + microblock_sequence: 0, + parent_index_block_hash: + '0x29fe7ba9674b9196fefa28764a35a4603065dc25c9dcf83c56648066f36a8dce', + }) + .build(); + await db.updateMicroblocks(microblock); + const payload = { + events: [ + { + txid: '0x605aa0554fb5ee7995f9780aa54d63b3d32550b0def95e31bdf3beb0fedefdae', + type: 'contract_event', + committed: true, + event_index: 50, + contract_event: { + topic: 'print', + raw_value: + '0x0c00000003096e616d65737061636502000000046672656e0a70726f706572746965730c000000061963616e2d7570646174652d70726963652d66756e6374696f6e030b6c61756e636865642d61740a0100000000000000000000000000011886086c69666574696d65010000000000000000000000000000cd50106e616d6573706163652d696d706f727406161809f2ab9182b6ff1678f82846131c0709e51cf914636f6d6d756e6974792d68616e646c65732d76320e70726963652d66756e6374696f6e0c000000050462617365010000000c9f2c9cd04674edea3fffffff076275636b6574730b00000010010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000101000000000000000000000000000000010100000000000000000000000000000001010000000000000000000000000000000105636f6566660100000000000000000000000000000001116e6f2d766f77656c2d646973636f756e740100000000000000000000000000000001116e6f6e616c7068612d646973636f756e7401000000000000000000000000000000010b72657665616c65642d61740100000000000000000000000000011886067374617475730d000000057265616479', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + ], + block_hash: '0x6be6bfbf5e63ee4333c794b0489a791625ad0724722647b748379fe916bbff55', + miner_txid: '0x1c01668438115f757cfc14210f7f7ba0bee7f9d235c44b8e35c8653ac5879205', + block_height: 2, + transactions: [ + { + txid: '0x605aa0554fb5ee7995f9780aa54d63b3d32550b0def95e31bdf3beb0fedefdae', + raw_tx: + '0x000000000104001809f2ab9182b6ff1678f82846131c0709e51cf900000000000000110000000000000bb80001e2ae2533ed444dcc3dc0118da5c8bbfe5da4c1943b63e3fd9b7389e3f7f384ee417a65d899182ff7791b174a426b947860df5b4006a0cb767aca275af847428d03020000000002161809f2ab9182b6ff1678f82846131c0709e51cf914636f6d6d756e6974792d68616e646c65732d7632106e616d6573706163652d72657665616c0000000402000000046672656e0200000003626f74010000000000000000000000000000cd5009', + status: 'success', + tx_index: 46, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 201050, + read_count: 20, + read_length: 92368, + write_count: 4, + write_length: 1386, + }, + microblock_hash: '0x8455c986ef89d09968b96fee0ef5b4625aa3860aa68e70123efa129f48e55c6b', + microblock_sequence: 0, + microblock_parent_hash: + '0xea7982ba6a5206b9efc2ab2567eedef3babae4d167619bdc74c7e148717dc208', + }, + ], + anchored_cost: { + runtime: 19669668, + read_count: 1420, + read_length: 8457322, + write_count: 143, + write_length: 9331, + }, + burn_block_hash: '0x00000000000000000004afca18622e18a1f36ff19dc1aece341868c042b7f4ac', + burn_block_time: 1660639379, + index_block_hash: '0xd3944c1cf261982ad5d86ad14b1545a2393c0039e378706323927b3a7031a621', + burn_block_height: 749662, + parent_block_hash: '0xea7982ba6a5206b9efc2ab2567eedef3babae4d167619bdc74c7e148717dc208', + parent_microblock: '0x8455c986ef89d09968b96fee0ef5b4625aa3860aa68e70123efa129f48e55c6b', + matured_miner_rewards: [], + parent_burn_block_hash: '0x000000000000000000021e9777470811a937006cf47efceadefca2e8031c4b5f', + parent_index_block_hash: '0x29fe7ba9674b9196fefa28764a35a4603065dc25c9dcf83c56648066f36a8dce', + parent_burn_block_height: 749661, + confirmed_microblocks_cost: { + runtime: 174668984, + read_count: 12067, + read_length: 54026355, + write_count: 1701, + write_length: 134399, + }, + parent_microblock_sequence: 0, + parent_burn_block_timestamp: 1660638853, + }; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/new_block', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + const namespaces = await db.getNamespaceList({ includeUnanchored: true }); + expect(namespaces.results).toStrictEqual(['fren']); + + const namespace = await db.getNamespace({ namespace: 'fren', includeUnanchored: true }); + expect(namespace.found).toBe(true); + expect(namespace.result?.namespace_id).toBe('fren'); + expect(namespace.result?.lifetime).toBe(52560); + expect(namespace.result?.status).toBe('ready'); + expect(namespace.result?.ready_block).toBe(2); + }); + + test('name-transfer called by a contract other than BNS', async () => { + const block = new TestBlockBuilder({ + block_height: 1, + block_hash: '0x09458029b7c0e43e015bd3202c0f9512c2b394e0481bfd2bdd096ae7b5b862f2', + index_block_hash: '0xad9403fc8d8eaef47816555cac51dca9d934384aa9b2581f9b9085509b2af915', + burn_block_height: 743853, + burn_block_hash: '0x00000000000000000008b9d65609c6b39bb89d7da35433e4b287835d7112d6d4', + burn_block_time: 1657123396, + }) + .addTx({ + tx_id: '0x1234', + sender_address: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J', + }) + .addTxBnsNamespace({ + namespace_id: 'btc', + lifetime: 1000, + }) + .addTxBnsName({ + name: 'dayslikewater.btc', + namespace_id: 'btc', + zonefile_hash: 'b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + address: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J', + }) + .addTxNftEvent({ + asset_event_type_id: DbAssetEventTypeId.Mint, + value: bnsNameCV('dayslikewater.btc'), + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + recipient: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J', + }) + .build(); + await db.update(block); + const microblock = new TestMicroblockStreamBuilder() + .addMicroblock({ + microblock_hash: '0xccdd11fef1792979bc54a9b686e9cc4fc3d64f2a9b2d8ee9d34fe27bfab783a4', + microblock_sequence: 0, + parent_index_block_hash: + '0xad9403fc8d8eaef47816555cac51dca9d934384aa9b2581f9b9085509b2af915', + }) + .build(); + await db.updateMicroblocks(microblock); + + const name1 = await db.getName({ + name: 'dayslikewater.btc', + includeUnanchored: true, + }); + expect(name1.found).toBe(true); + expect(name1.result?.namespace_id).toBe('btc'); + expect(name1.result?.tx_id).toBe('0x1234'); + expect(name1.result?.status).toBe('name-register'); + expect(name1.result?.expire_block).toBe(1001); + expect(name1.result?.address).toBe('SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J'); + + const payload = { + events: [ + { + txid: '0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19', + type: 'contract_event', + committed: true, + event_index: 74, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000e52b04686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000d646179736c696b657761746572096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e6465720516016084eead6adbeee180dc0a855609d10eaf4c17', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + { + txid: '0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19', + type: 'nft_transfer_event', + committed: true, + event_index: 73, + nft_transfer_event: { + sender: 'SPP117ENNNDQVQ1G3E0N1AP178GXBTC2YNQ3H7J', + raw_value: + '0x0c00000002046e616d65020000000d646179736c696b657761746572096e616d6573706163650200000003627463', + recipient: 'SP1TY00PDWJVNVEX7H7KJGS2K2YXHTQMY8C0G1NVP', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19', + type: 'stx_transfer_event', + committed: true, + event_index: 71, + stx_transfer_event: { + amount: '2500', + sender: 'SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C.bns-marketplace-v3', + recipient: 'SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C', + }, + }, + ], + block_hash: '0x7d18920cc47f731f186fb9f731d2e8d5029bbab6d73fd012ac3e10637a8e4a37', + miner_txid: '0xbed35e9e7eb7f98583c87743d3860ab63f2506f7f1efe24740cd37f7708de0b4', + block_height: 2, + transactions: [ + { + txid: '0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19', + raw_tx: + '0x00000000010400016084eead6adbeee180dc0a855609d10eaf4c1700000000000000020000000000000bb80000e452e9d87e94a2a4364e89af3ab44b3ce1117afb6505721ff5b801294e1280f0616ee4d21a6ef9bcca1ea15ac65477e79df3427f7fd6c41c80938f8cca6d2cd0030200000002000316a6a7a70f41adbe8eae708ed7ec2cbf41a272182012626e732d6d61726b6574706c6163652d76330500000000000186a0020216016084eead6adbeee180dc0a855609d10eaf4c1716000000000000000000000000000000000000000003626e73056e616d65730c00000002046e616d65020000000d646179736c696b657761746572096e616d6573706163650200000003627463100216a6a7a70f41adbe8eae708ed7ec2cbf41a272182012626e732d6d61726b6574706c6163652d76330a6163636570742d626964000000030200000003627463020000000d646179736c696b6577617465720a0200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + status: 'success', + tx_index: 25, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 381500, + read_count: 42, + read_length: 96314, + write_count: 9, + write_length: 359, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + ], + anchored_cost: { + runtime: 44194708, + read_count: 4105, + read_length: 11476905, + write_count: 546, + write_length: 47312, + }, + burn_block_hash: '0x00000000000000000005e28a41cdb7461953b9424b4fd44a9211a145a1c0346d', + burn_block_time: 1657125225, + index_block_hash: '0xb70205d38a8666cbd071239b4ec28ae7d12a2c32341118d7c6d4d1e22f56014e', + burn_block_height: 743854, + parent_block_hash: '0x09458029b7c0e43e015bd3202c0f9512c2b394e0481bfd2bdd096ae7b5b862f2', + parent_microblock: '0xccdd11fef1792979bc54a9b686e9cc4fc3d64f2a9b2d8ee9d34fe27bfab783a4', + matured_miner_rewards: [], + parent_burn_block_hash: '0x00000000000000000008b9d65609c6b39bb89d7da35433e4b287835d7112d6d4', + parent_index_block_hash: '0xad9403fc8d8eaef47816555cac51dca9d934384aa9b2581f9b9085509b2af915', + parent_burn_block_height: 743853, + confirmed_microblocks_cost: { + runtime: 48798, + read_count: 10, + read_length: 40042, + write_count: 3, + write_length: 19, + }, + parent_microblock_sequence: 0, + parent_burn_block_timestamp: 1657123396, + }; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/new_block', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + const name2 = await db.getName({ + name: 'dayslikewater.btc', + includeUnanchored: true, + }); + expect(name2.found).toBe(true); + expect(name2.result?.namespace_id).toBe('btc'); + expect(name2.result?.tx_id).toBe( + '0xa75ebee2c824c4943bf8494b101ea7ee7d44191b4a8f761582ce99ef28befb19' + ); + expect(name2.result?.status).toBe('name-transfer'); + expect(name2.result?.expire_block).toBe(1001); // Unchanged as it was not renewed + expect(name2.result?.address).toBe('SP1TY00PDWJVNVEX7H7KJGS2K2YXHTQMY8C0G1NVP'); + }); + + test('name-renewal called with no zonefile_hash', async () => { + const block = new TestBlockBuilder({ + block_height: 1, + block_hash: '0xf81ef7f114213b9034a4378345a931a97c781fab398c3d7a2053f0d0bf48d311', + index_block_hash: '0xaec282925b5096c0bd98588d25a97e134bcc4f19b6600859fa267cf0ee4eaf2d', + burn_block_height: 726955, + burn_block_hash: '0x00000000000000000001523f01cb4304d39527454d2eec79817b50c033a5c5d9', + burn_block_time: 1647068146, + }) + .addTx({ + tx_id: '0x1234', + sender_address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ', + }) + .addTxBnsNamespace({ + namespace_id: 'id', + lifetime: 1000, + }) + .addTxBnsName({ + name: 'friedger.id', + namespace_id: 'id', + zonefile_hash: 'b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ', + }) + .addTxNftEvent({ + asset_event_type_id: DbAssetEventTypeId.Mint, + value: bnsNameCV('friedger.id'), + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + recipient: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ', + }) + .build(); + await db.update(block); + const microblock = new TestMicroblockStreamBuilder() + .addMicroblock({ + microblock_hash: '0x640362ec47c40de3337491993e42efe60d05187431633ab03c3f5d33e70d1f8e', + microblock_sequence: 0, + parent_index_block_hash: + '0xaec282925b5096c0bd98588d25a97e134bcc4f19b6600859fa267cf0ee4eaf2d', + }) + .build(); + await db.updateMicroblocks(microblock); + + const name1 = await db.getName({ + name: 'friedger.id', + includeUnanchored: true, + }); + expect(name1.found).toBe(true); + expect(name1.result?.namespace_id).toBe('id'); + expect(name1.result?.tx_id).toBe('0x1234'); + expect(name1.result?.status).toBe('name-register'); + expect(name1.result?.expire_block).toBe(1001); + expect(name1.result?.address).toBe('SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ'); + + const payload = { + events: [], + block_hash: '0xaaee893667244adcb8581abac372f1f8c385d402b71e8e8b4ac91e8066024fd5', + miner_txid: '0x6ff493c6b98b9cff0638c7c5276af8e627b8ed779965a5f1c11bbc0810834b3e', + block_height: 2, + transactions: [ + { + txid: '0xf037c8da8210e2a348bbecd3bc44901de875d3774c5fce49cb75d95f2dc2ca4d', + raw_tx: + '0x00000000010500e1cd6c39a3d316e49bf16b4a20636462231b84f200000000000000000000000000000000000094f2c8529dcb8a55a5cfd4434c68cae9cd54f26f01c656369585db3ba364150a4fead679adf35cf5ba1026656b3873daf3380f48ec6dcc175ada868e531decf5001d04c185cad28a3f5299d3fcbcbcbe66b2e1e227000000000000000000000000000186a0000064cc0eb565e85c0d4110c9a760c8fdad21999409f89320e355f326c144b8ada4268244f80734170cea96f683d2431b59f07f276a10efc80793d4dceef8feb2310302000000000216000000000000000000000000000000000000000003626e730c6e616d652d72656e6577616c000000050200000002696402000000086672696564676572010000000000000000000000000001a72a0909', + status: 'success', + tx_index: 2, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 184253, + read_count: 11, + read_length: 43250, + write_count: 1, + write_length: 143, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + ], + anchored_cost: { + runtime: 28375070, + read_count: 8888, + read_length: 1085153, + write_count: 593, + write_length: 156284, + }, + burn_block_hash: '0x0000000000000000000552fb5fd8c08ad8f1ef30c239369a8a3380ec1566047a', + burn_block_time: 1647068392, + index_block_hash: '0x9ff46918054b1aa94571a60e14921a56977f26af2adcbf4a7f64138566feba48', + burn_block_height: 726956, + parent_block_hash: '0xf81ef7f114213b9034a4378345a931a97c781fab398c3d7a2053f0d0bf48d311', + parent_microblock: '0x640362ec47c40de3337491993e42efe60d05187431633ab03c3f5d33e70d1f8e', + matured_miner_rewards: [], + parent_burn_block_hash: '0x00000000000000000001523f01cb4304d39527454d2eec79817b50c033a5c5d9', + parent_index_block_hash: '0xaec282925b5096c0bd98588d25a97e134bcc4f19b6600859fa267cf0ee4eaf2d', + parent_burn_block_height: 726955, + confirmed_microblocks_cost: { + runtime: 360206, + read_count: 38, + read_length: 95553, + write_count: 8, + write_length: 378, + }, + parent_microblock_sequence: 0, + parent_burn_block_timestamp: 1647068146, + }; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/new_block', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + const name2 = await db.getName({ + name: 'friedger.id', + includeUnanchored: true, + }); + expect(name2.found).toBe(true); + expect(name2.result?.namespace_id).toBe('id'); + expect(name2.result?.tx_id).toBe( + '0xf037c8da8210e2a348bbecd3bc44901de875d3774c5fce49cb75d95f2dc2ca4d' + ); + expect(name2.result?.status).toBe('name-renewal'); + expect(name2.result?.expire_block).toBe(1002); // Updated correctly + expect(name2.result?.address).toBe('SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ'); + }); + + test('/attachments/new with re-orged zonefiles', async () => { + const block1 = new TestBlockBuilder({ + block_height: 1, + index_block_hash: '0x0101', + }) + .addTx() + .addTxBnsNamespace({ namespace_id: 'btc' }) + .addTxBnsName({ name: 'jnj.btc', namespace_id: 'btc' }) + .addTxNftEvent({ + asset_event_type_id: DbAssetEventTypeId.Mint, + value: bnsNameCV('jnj.btc'), + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + recipient: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', + }) + .build(); + await db.update(block1); + + const block2 = new TestBlockBuilder({ + block_height: 2, + index_block_hash: '0x0200', + parent_index_block_hash: '0x0101', + }) + .addTx({ tx_id: '0x1212' }) + .addTxBnsName({ + name: 'jnj.btc', + namespace_id: 'btc', + status: 'name-update', // Canonical update + tx_id: '0x1212', + zonefile_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3', + }) + .build(); + await db.update(block2); + + const block2b = new TestBlockBuilder({ + block_height: 2, + index_block_hash: '0x0201', + parent_index_block_hash: '0x0101', + }) + .addTx({ tx_id: '0x121266' }) + .addTxBnsName({ + name: 'jnj.btc', + namespace_id: 'btc', + status: 'name-update', // Non-canonical update + tx_id: '0x121266', + zonefile_hash: '0xffff', + }) + .build(); + await db.update(block2b); + + const block3 = new TestBlockBuilder({ + block_height: 3, + index_block_hash: '0x0300', + parent_index_block_hash: '0x0200', + }) + .addTx({ tx_id: '0x3333' }) + .build(); + await db.update(block3); + + const payload = [ + { + tx_id: '0x1212', // Canonical + content: + '0x244f524947494e206a6e6a2e6274632e0a2454544c20333630300a5f687474702e5f74637009494e095552490931300931092268747470733a2f2f676169612e626c6f636b737461636b2e6f72672f6875622f317a38417a79684334326e3854766f4661554c326e7363614347487151515755722f70726f66696c652e6a736f6e220a0a', + metadata: + '0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6', + contract_id: 'SP000000000000000000002Q6VF78.bns', + block_height: 17307, + content_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3', + attachment_index: 823, + index_block_hash: '0x0200', + }, + { + tx_id: '0x121266', // Non-canonical + content: '0x', + metadata: + '0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6', + contract_id: 'SP000000000000000000002Q6VF78.bns', + block_height: 17307, + content_hash: '0xffff', + attachment_index: 823, + index_block_hash: '0x0201', + }, + ]; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/attachments/new', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + const name = await db.getName({ name: 'jnj.btc', includeUnanchored: true }); + expect(name.found).toBe(true); + expect(name.result?.zonefile_hash).toBe('9198e0b61a029671e53bd59aa229e7ae05af35a3'); + expect(name.result?.tx_id).toBe('0x1212'); + expect(name.result?.status).toBe('name-update'); + }); + + test('/attachments/new with duplicate zonefiles for the same tx', async () => { + const block1 = new TestBlockBuilder({ + block_height: 1, + index_block_hash: '0x0101', + }) + .addTx({ tx_id: '0x1234' }) + .addTxBnsNamespace({ namespace_id: 'btc' }) + .addTxBnsName({ + name: 'jnj.btc', + namespace_id: 'btc', + zonefile_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3', + }) + .addTxNftEvent({ + asset_event_type_id: DbAssetEventTypeId.Mint, + value: bnsNameCV('jnj.btc'), + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + recipient: 'ST5RRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1ZA', + }) + .build(); + await db.update(block1); + + const payload = [ + { + tx_id: '0x1234', + content: '0x', + metadata: + '0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6', + contract_id: 'SP000000000000000000002Q6VF78.bns', + block_height: 1, + content_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3', + attachment_index: 823, + index_block_hash: '0x0101', + }, + { + tx_id: '0x1234', + content: + '0x244f524947494e206a6e6a2e6274632e0a2454544c20333630300a5f687474702e5f74637009494e095552490931300931092268747470733a2f2f676169612e626c6f636b737461636b2e6f72672f6875622f317a38417a79684334326e3854766f4661554c326e7363614347487151515755722f70726f66696c652e6a736f6e220a0a', + metadata: + '0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6', + contract_id: 'SP000000000000000000002Q6VF78.bns', + block_height: 1, + content_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3', // Same zonefile_hash but different content, this should overwrite the entry above + attachment_index: 823, + index_block_hash: '0x0101', + }, + { + tx_id: '0x1234', + content: + '0x244f524947494e206a6e6a2e6274632e0a2454544c20333630300a5f687474702e5f74637009494e095552490931300931092268747470733a2f2f676169612e626c6f636b737461636b2e6f72672f6875622f317a38417a79684334326e3854766f4661554c326e7363614347487151515755722f70726f66696c652e6a736f6e220a0a', + metadata: + '0x0c00000004046e616d6502000000036a6e6a096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205163763c6b37100efa8261e5fc1b1e8c18cd3fed9b6', + contract_id: 'SP000000000000000000002Q6VF78.bns', + block_height: 1, + content_hash: '0x9198e0b61a029671e53bd59aa229e7ae05af35a3', // Also overwrite + attachment_index: 823, + index_block_hash: '0x0101', + }, + ]; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/attachments/new', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + // To validate table data we'll query it directly. There should only be one zonefile. + const result = await client`SELECT * FROM zonefiles`; + expect(result.count).toBe(1); + expect(result[0].zonefile).toBe( + '$ORIGIN jnj.btc.\n$TTL 3600\n_http._tcp\tIN\tURI\t10\t1\t"https://gaia.blockstack.org/hub/1z8AzyhC42n8TvoFaUL2nscaCGHqQQWUr/profile.json"\n\n' + ); + }); + + test('name-register and name-transfer for several names in one block', async () => { + const block = new TestBlockBuilder({ + block_height: 1, + block_hash: '0x161bd86201417a55fb0dd851ac0e6b10c67a0b443e593008a4cf46fb6938b369', + index_block_hash: '0x8cc3d58350082f3161ae34deaad77c1c8887947ff0295be59ec5caccf984fe78', + burn_block_height: 756266, + burn_block_hash: '0x00000000000000000002e78c9c19a055ca0e680674e1a2f0f01a48c04a24f627', + burn_block_time: 1664489645, + }) + .addTx({ + tx_id: '0x1234', + sender_address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ', + }) + .addTxBnsNamespace({ + namespace_id: 'btc', + lifetime: 1000, + }) + .build(); + await db.update(block); + const microblock = new TestMicroblockStreamBuilder() + .addMicroblock({ + microblock_hash: '0xc44f4e3ed66bacaaa5cbe5b9c35b4e2ce2467933b57974fa03b539a2b2b88063', + microblock_sequence: 0, + parent_index_block_hash: + '0x8cc3d58350082f3161ae34deaad77c1c8887947ff0295be59ec5caccf984fe78', + }) + .build(); + await db.updateMicroblocks(microblock); + + const payload = { + // In the block message, events are not sorted by `event_index`. + events: [ + { + txid: '0xd5803813a0befbf7e426ca897a5940c691a18e5959170e12ddb9e71c91ea4f12', + type: 'nft_mint_event', + committed: true, + event_index: 405, + nft_mint_event: { + raw_value: + '0x0c00000002046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463', + recipient: 'SP253DQBW2ZBKE10PBQVBDJ5XSQQ4P06PVP9PR6S8', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0xd5803813a0befbf7e426ca897a5940c691a18e5959170e12ddb9e71c91ea4f12', + type: 'contract_event', + committed: true, + event_index: 406, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144ea04686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e64657205168a36dd7c17d73704165df6b6c8bdcdee4b00d6dd', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + { + txid: '0xa106e30d1df4607a993ff2ec0d68a4acfb3d5ab2ae597179869df8d6da8f1b95', + type: 'nft_transfer_event', + committed: true, + event_index: 407, + nft_transfer_event: { + sender: 'SP253DQBW2ZBKE10PBQVBDJ5XSQQ4P06PVP9PR6S8', + raw_value: + '0x0c00000002046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463', + recipient: 'SP2WPXVTZE2RG4SZGJT5HTZ7JK6CAWTEV0A55HFH7', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0xa106e30d1df4607a993ff2ec0d68a4acfb3d5ab2ae597179869df8d6da8f1b95', + type: 'contract_event', + committed: true, + event_index: 408, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144eb04686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e64657205168a36dd7c17d73704165df6b6c8bdcdee4b00d6dd', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + { + txid: '0x1784633b879ffcf15c18dcf627047a44358f2f0660c14f5188c9f17b28abb8af', + type: 'nft_mint_event', + committed: true, + event_index: 381, + nft_mint_event: { + raw_value: + '0x0c00000002046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463', + recipient: 'SP2MM4ETXDE26HQ64F29VG05Q577DEPTSDJ2DQV8N', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0x1784633b879ffcf15c18dcf627047a44358f2f0660c14f5188c9f17b28abb8af', + type: 'contract_event', + committed: true, + event_index: 382, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144e204686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463026f700d0000000d6e616d652d72656769737465720974782d73656e6465720516a9423b5d6b8468dcc47893b800b729ced75b596c', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + { + txid: '0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7', + type: 'nft_transfer_event', + committed: true, + event_index: 389, + nft_transfer_event: { + sender: 'SP2MM4ETXDE26HQ64F29VG05Q577DEPTSDJ2DQV8N', + raw_value: + '0x0c00000002046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463', + recipient: 'SP1QFKSVQP3J2PF45KFFCVBR4Q24Y09G0PJDECHS7', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7', + type: 'contract_event', + committed: true, + event_index: 390, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e64657801000000000000000000000000000144e304686173680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb086d657461646174610c00000004046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463026f700d0000000d6e616d652d7472616e736665720974782d73656e6465720516a9423b5d6b8468dcc47893b800b729ced75b596c', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + ], + block_hash: '0x41e158fe192103d2a5f895c6f9093a548ecc35db3a4c3c5de0e616fd3894338e', + miner_txid: '0x9c48f6c748177cd049db40172e5044e5a98f8fe5b798f33212f876121e764b72', + block_height: 2, + transactions: [ + { + txid: '0x1784633b879ffcf15c18dcf627047a44358f2f0660c14f5188c9f17b28abb8af', + raw_tx: + '0x00000000010400a9423b5d6b8468dcc47893b800b729ced75b596c00000000000000010000000000014ed6010055b3a6e2581eaaf686bc9596a4c9cf62cbdb30ffaad167c094824b5d89598ce1101ff56aeb58e2020c10954da05cd80b733ec79ecd71db1921aa202d377aac740302000000000216000000000000000000000000000000000000000003626e730d6e616d652d7265676973746572000000040200000003627463020000000f637269636b6574776972656c65737302000000149a3db4f009ad960c5a0cad7ad9c19f21fa0fe3680200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + status: 'success', + tx_index: 274, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 311527, + read_count: 17, + read_length: 43206, + write_count: 4, + write_length: 242, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + { + txid: '0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7', + raw_tx: + '0x00000000010400a9423b5d6b8468dcc47893b800b729ced75b596c00000000000000020000000000014941010173c47aad0c8e5e8e2c655f488e4b8f514a63fd0190ae392f6cc6f22c1ec93aa44facb412a9d6504efd7945eeb52407011069ca1d3a7138e7a889c7c15aa82df2030200000001020216a9423b5d6b8468dcc47893b800b729ced75b596c16000000000000000000000000000000000000000003626e73056e616d65730c00000002046e616d65020000000f637269636b6574776972656c657373096e616d6573706163650200000003627463100216000000000000000000000000000000000000000003626e730d6e616d652d7472616e73666572000000040200000003627463020000000f637269636b6574776972656c65737305166ef9e777b0e42b3c859bdecdaf04b889e02600b40a0200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + status: 'success', + tx_index: 276, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 183670, + read_count: 19, + read_length: 44047, + write_count: 5, + write_length: 266, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + { + txid: '0xd5803813a0befbf7e426ca897a5940c691a18e5959170e12ddb9e71c91ea4f12', + raw_tx: + '0x000000000104008a36dd7c17d73704165df6b6c8bdcdee4b00d6dd0000000000000001000000000001449f0101bd23afc22da4e356847d76d07261a861488389d4864c8d42ce002be439e0e78b3aa1088a8aaac189f7c85e674fd871b787f1fb0cd5a19acd827a011f5e38921c0302000000000216000000000000000000000000000000000000000003626e730d6e616d652d726567697374657200000004020000000362746302000000086b6574656c6f6e6502000000146cd23e487d9068d24e1e1bc90636a6e48c1546a50200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + status: 'success', + tx_index: 285, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 229244, + read_count: 17, + read_length: 43199, + write_count: 4, + write_length: 228, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + { + txid: '0xa106e30d1df4607a993ff2ec0d68a4acfb3d5ab2ae597179869df8d6da8f1b95', + raw_tx: + '0x000000000104008a36dd7c17d73704165df6b6c8bdcdee4b00d6dd00000000000000020000000000015cb70101ac9a2e87c627c605ac68f0c40d59ff6bd5543705a5710ee4679d936a664d20f60a0b91e98770cb3597ea25af005e9eb083a827e860b6ba975c0a819205b4792f0302000000010202168a36dd7c17d73704165df6b6c8bdcdee4b00d6dd16000000000000000000000000000000000000000003626e73056e616d65730c00000002046e616d6502000000086b6574656c6f6e65096e616d6573706163650200000003627463100216000000000000000000000000000000000000000003626e730d6e616d652d7472616e7366657200000004020000000362746302000000086b6574656c6f6e650516b96eef5f70b10267f0968b1d7cf29998ae69db020a0200000014b472a266d0bd89c13706a4132ccfb16f7c3b9fcb', + status: 'success', + tx_index: 286, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 183264, + read_count: 19, + read_length: 44026, + write_count: 5, + write_length: 252, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + ], + anchored_cost: { + runtime: 37717625, + read_count: 3184, + read_length: 10513899, + write_count: 710, + write_length: 42932, + }, + burn_block_hash: '0x0000000000000000000213c1512c2bffae7378f2b890bfea3ee6dc8e2e7836a2', + burn_block_time: 1664490688, + index_block_hash: '0x2eb444d32bb66a6acc3ba66aedabbb19c3adde8b6a9717765960bdc67ea32070', + burn_block_height: 756268, + parent_block_hash: '0x161bd86201417a55fb0dd851ac0e6b10c67a0b443e593008a4cf46fb6938b369', + parent_microblock: '0xc44f4e3ed66bacaaa5cbe5b9c35b4e2ce2467933b57974fa03b539a2b2b88063', + matured_miner_rewards: [], + parent_burn_block_hash: '0x00000000000000000002e78c9c19a055ca0e680674e1a2f0f01a48c04a24f627', + parent_index_block_hash: '0x8cc3d58350082f3161ae34deaad77c1c8887947ff0295be59ec5caccf984fe78', + parent_burn_block_height: 756266, + confirmed_microblocks_cost: { + runtime: 5707388, + read_count: 545, + read_length: 2095326, + write_count: 127, + write_length: 8025, + }, + parent_microblock_sequence: 0, + parent_burn_block_timestamp: 1664489645, + }; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/new_block', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + const name = await db.getName({ + name: 'cricketwireless.btc', + includeUnanchored: true, + }); + expect(name.found).toBe(true); + expect(name.result?.namespace_id).toBe('btc'); + expect(name.result?.tx_id).toBe( + '0x28715dc6e09e75cec4d26d6a52426c8cc13c6e5a16d5252886c33ffc6bcceef7' + ); + expect(name.result?.status).toBe('name-transfer'); + expect(name.result?.address).toBe('SP1QFKSVQP3J2PF45KFFCVBR4Q24Y09G0PJDECHS7'); + }); + + test('name-register and name-transfer in same tx from non-BNS contract', async () => { + const block = new TestBlockBuilder({ + block_height: 1, + block_hash: '0x08cdd83644176e87cd5fdc584a5193de84c4c54cbe8b3839225e75f396f64468', + index_block_hash: '0x82239cdbd3903ca032d300101990120947132a8a005a92d7a1cdcd5a61b35ba1', + burn_block_height: 749980, + burn_block_hash: '0x000000000000000000089afaf672605818e368521d9ad2d8e4b5763956b75363', + burn_block_time: 1660833970, + }) + .addTx({ + tx_id: '0x1234', + sender_address: 'SP3GWTV1SMF9HDS4VY5NMM833CHH266W4YBASVYMZ', + }) + .addTxBnsNamespace({ + namespace_id: 'mega', + lifetime: 1000, + }) + .build(); + await db.update(block); + const microblock = new TestMicroblockStreamBuilder() + .addMicroblock({ + microblock_hash: '0x2ad76cc1eadb6e0dd155a7b5ac82ff81a2c664552dacb99a524a410856330529', + microblock_sequence: 0, + parent_index_block_hash: + '0x82239cdbd3903ca032d300101990120947132a8a005a92d7a1cdcd5a61b35ba1', + }) + .build(); + await db.updateMicroblocks(microblock); + + const payload = { + events: [ + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'contract_event', + committed: true, + event_index: 85, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000f65804686173680200000000086d657461646174610c00000004046e616d650200000003617065096e616d65737061636502000000046d656761026f700d0000000d6e616d652d7472616e736665720974782d73656e64657206161809f2ab9182b6ff1678f82846131c0709e51cf91b72796465722d68616e646c65732d636f6e74726f6c6c65722d7631', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'stx_burn_event', + committed: true, + event_index: 81, + stx_burn_event: { + amount: '1', + sender: 'SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1', + }, + }, + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'nft_transfer_event', + committed: true, + event_index: 84, + nft_transfer_event: { + sender: 'SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1', + raw_value: + '0x0c00000002046e616d650200000003617065096e616d65737061636502000000046d656761', + recipient: 'SPV48Q8E5WP4TCQ63E9TV6KF9R4HP01Z8WS3FBTG', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'nft_mint_event', + committed: true, + event_index: 82, + nft_mint_event: { + raw_value: + '0x0c00000002046e616d650200000003617065096e616d65737061636502000000046d656761', + recipient: 'SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1', + asset_identifier: 'SP000000000000000000002Q6VF78.bns::names', + }, + }, + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'stx_transfer_event', + committed: true, + event_index: 79, + stx_transfer_event: { + amount: '3000000', + sender: 'SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1', + recipient: 'SP2J9XB6CNJX9C36D5SY4J85SA0P1MQX7R5VFKZZX', + }, + }, + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'stx_transfer_event', + committed: true, + event_index: 80, + stx_transfer_event: { + amount: '1', + sender: 'SP3C8QH2R3909YQZ7WVZ71N8RJ6Y0P317T8MG8XSZ', + recipient: 'SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.ryder-handles-controller-v1', + }, + }, + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + type: 'contract_event', + committed: true, + event_index: 83, + contract_event: { + topic: 'print', + raw_value: + '0x0c000000010a6174746163686d656e740c00000003106174746163686d656e742d696e646578010000000000000000000000000000f65704686173680200000000086d657461646174610c00000004046e616d650200000003617065096e616d65737061636502000000046d656761026f700d0000000d6e616d652d72656769737465720974782d73656e64657206161809f2ab9182b6ff1678f82846131c0709e51cf91b72796465722d68616e646c65732d636f6e74726f6c6c65722d7631', + contract_identifier: 'SP000000000000000000002Q6VF78.bns', + }, + }, + ], + block_hash: '0xbcf632eaa887b66a6356bf9410eb61377cced2d3f444a2286fb59b12a63e48e4', + miner_txid: '0x037d5016d21839a46f136ad846ea99967eda65bf5cdb31feabc60c8eaef5b96d', + block_height: 2, + transactions: [ + { + txid: '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16', + raw_tx: + '0x00000000010400d88bc4581a409f5fe7e6fe70d51891bc0b0c27d2000000000000001100000000000003e80001fff157398074931aca859d34de1f3070359b8493033cd79fde329ecd66e4bd090235cf61f9916f76cdbaa37ff4d2ee3358322f6a58ec2fb05717115c913fd6e103010000000002161809f2ab9182b6ff1678f82846131c0709e51cf91b72796465722d68616e646c65732d636f6e74726f6c6c65722d76310d6e616d652d72656769737465720000000602000000046d656761020000000361706502000000057337306b35020000004107d00910104bba0ee68b131ceead109ccea598a267a2000140b3277809f1ab535dcef753028c00e7239be1477801ac7d5b8c10e0a7b242261285212da194bdad01051636445d0e2f2c4d32e61b93ad9a6f4e091b003f470200000000', + status: 'success', + tx_index: 25, + raw_result: '0x0703', + contract_abi: null, + execution_cost: { + runtime: 643399, + read_count: 69, + read_length: 231108, + write_count: 16, + write_length: 1948, + }, + microblock_hash: null, + microblock_sequence: null, + microblock_parent_hash: null, + }, + ], + anchored_cost: { + runtime: 39996577, + read_count: 4234, + read_length: 13859444, + write_count: 676, + write_length: 53049, + }, + burn_block_hash: '0x0000000000000000000867b5dd6ec7ebb50404acabcdb35193b6b2fcd3ea7a37', + burn_block_time: 1660834638, + index_block_hash: '0xe43e505d4c7ca5f64a6d9617fbb658a84344610eb0e6495f8f9b7ab3b2648f61', + burn_block_height: 749981, + parent_block_hash: '0x08cdd83644176e87cd5fdc584a5193de84c4c54cbe8b3839225e75f396f64468', + parent_microblock: '0x2ad76cc1eadb6e0dd155a7b5ac82ff81a2c664552dacb99a524a410856330529', + matured_miner_rewards: [], + parent_burn_block_hash: '0x000000000000000000089afaf672605818e368521d9ad2d8e4b5763956b75363', + parent_index_block_hash: '0x82239cdbd3903ca032d300101990120947132a8a005a92d7a1cdcd5a61b35ba1', + parent_burn_block_height: 749980, + confirmed_microblocks_cost: { + runtime: 0, + read_count: 0, + read_length: 0, + write_count: 0, + write_length: 0, + }, + parent_microblock_sequence: 0, + parent_burn_block_timestamp: 1660833970, + }; + + await httpPostRequest({ + host: '127.0.0.1', + port: eventServer.serverAddress.port, + path: '/new_block', + headers: { 'Content-Type': 'application/json' }, + body: Buffer.from(JSON.stringify(payload), 'utf8'), + throwOnNotOK: true, + }); + + const name = await db.getName({ + name: 'ape.mega', + includeUnanchored: true, + }); + expect(name.found).toBe(true); + expect(name.result?.namespace_id).toBe('mega'); + expect(name.result?.tx_id).toBe( + '0xf9f9144793f6d4da9aba92a54ab601eb23bfe7f44c1edb29c2920bf5e7d2ac16' + ); + expect(name.result?.status).toBe('name-transfer'); + expect(name.result?.expire_block).toBe(1002); + expect(name.result?.address).toBe('SPV48Q8E5WP4TCQ63E9TV6KF9R4HP01Z8WS3FBTG'); + + const list = await db.getNamesList({ page: 0, includeUnanchored: true }); + expect(list.results.length).toBe(1); + expect(list.results).toStrictEqual(['ape.mega']); + + const namespaceList = await db.getNamespaceNamesList({ + namespace: 'mega', + page: 0, + includeUnanchored: true, + }); + expect(namespaceList.results.length).toBe(1); + expect(namespaceList.results).toStrictEqual(['ape.mega']); + }); +}); diff --git a/src/tests-bns/import-test-files/chainstate.txt b/tests/bns/import-test-files/chainstate.txt similarity index 100% rename from src/tests-bns/import-test-files/chainstate.txt rename to tests/bns/import-test-files/chainstate.txt diff --git a/src/tests-bns/import-test-files/chainstate.txt.sha256 b/tests/bns/import-test-files/chainstate.txt.sha256 similarity index 100% rename from src/tests-bns/import-test-files/chainstate.txt.sha256 rename to tests/bns/import-test-files/chainstate.txt.sha256 diff --git a/src/tests-bns/import-test-files/name_zonefiles.txt b/tests/bns/import-test-files/name_zonefiles.txt similarity index 100% rename from src/tests-bns/import-test-files/name_zonefiles.txt rename to tests/bns/import-test-files/name_zonefiles.txt diff --git a/src/tests-bns/import-test-files/name_zonefiles.txt.sha256 b/tests/bns/import-test-files/name_zonefiles.txt.sha256 similarity index 100% rename from src/tests-bns/import-test-files/name_zonefiles.txt.sha256 rename to tests/bns/import-test-files/name_zonefiles.txt.sha256 diff --git a/src/tests-bns/import-test-files/subdomain_zonefiles.txt b/tests/bns/import-test-files/subdomain_zonefiles.txt similarity index 100% rename from src/tests-bns/import-test-files/subdomain_zonefiles.txt rename to tests/bns/import-test-files/subdomain_zonefiles.txt diff --git a/src/tests-bns/import-test-files/subdomain_zonefiles.txt.sha256 b/tests/bns/import-test-files/subdomain_zonefiles.txt.sha256 similarity index 100% rename from src/tests-bns/import-test-files/subdomain_zonefiles.txt.sha256 rename to tests/bns/import-test-files/subdomain_zonefiles.txt.sha256 diff --git a/src/tests-bns/import-test-files/subdomains.csv b/tests/bns/import-test-files/subdomains.csv similarity index 100% rename from src/tests-bns/import-test-files/subdomains.csv rename to tests/bns/import-test-files/subdomains.csv diff --git a/src/tests-bns/import-test-files/subdomains.csv.sha256 b/tests/bns/import-test-files/subdomains.csv.sha256 similarity index 100% rename from src/tests-bns/import-test-files/subdomains.csv.sha256 rename to tests/bns/import-test-files/subdomains.csv.sha256 diff --git a/src/tests-rpc/setup.ts b/tests/bns/setup.ts similarity index 75% rename from src/tests-rpc/setup.ts rename to tests/bns/setup.ts index 635c52d684..990aee7db9 100644 --- a/src/tests-rpc/setup.ts +++ b/tests/bns/setup.ts @@ -1,4 +1,4 @@ -import { defaultSetupInit } from '../test-utils/shared-setup'; +import { defaultSetupInit } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { diff --git a/src/tests-bns/teardown.ts b/tests/bns/teardown.ts similarity index 72% rename from src/tests-bns/teardown.ts rename to tests/bns/teardown.ts index 53858b8433..948c18dcc4 100644 --- a/src/tests-bns/teardown.ts +++ b/tests/bns/teardown.ts @@ -1,4 +1,4 @@ -import { defaultSetupTeardown } from '../test-utils/shared-setup'; +import { defaultSetupTeardown } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { diff --git a/src/tests-bns/v1-import-tests.ts b/tests/bns/v1-import.test.ts similarity index 51% rename from src/tests-bns/v1-import-tests.ts rename to tests/bns/v1-import.test.ts index accb52ca30..0e85601753 100644 --- a/src/tests-bns/v1-import-tests.ts +++ b/tests/bns/v1-import.test.ts @@ -1,12 +1,12 @@ -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import * as supertest from 'supertest'; import { ChainID } from '@stacks/transactions'; -import { importV1BnsNames, importV1BnsSubdomains } from '../import-v1'; +import { importV1BnsNames, importV1BnsSubdomains } from '../../src/import-v1'; import * as assert from 'assert'; -import { TestBlockBuilder } from '../test-utils/test-builders'; -import { DataStoreBlockUpdateData, DataStoreBnsBlockTxData } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +import { TestBlockBuilder } from '../utils/test-builders'; +import { DataStoreBlockUpdateData, DataStoreBnsBlockTxData } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; describe('BNS V1 import', () => { let db: PgWriteStore; @@ -38,8 +38,8 @@ describe('BNS V1 import', () => { tx_id: block.txs[0].tx.tx_id, tx_index: block.txs[0].tx.tx_index, }; - await importV1BnsNames(db, 'src/tests-bns/import-test-files', genesis); - await importV1BnsSubdomains(db, 'src/tests-bns/import-test-files', genesis); + await importV1BnsNames(db, 'tests/bns/import-test-files', genesis); + await importV1BnsSubdomains(db, 'tests/bns/import-test-files', genesis); // Names const query1 = await supertest(api.server).get(`/v1/names/zumrai.id`); @@ -56,73 +56,137 @@ describe('BNS V1 import', () => { zonefile_hash: '853cd126478237bc7392e65091f7ffa5a1556a33', }); - const query2 = await supertest(api.server).get(`/v1/names/zumrai.id/zonefile/853cd126478237bc7392e65091f7ffa5a1556a33`); + const query2 = await supertest(api.server).get( + `/v1/names/zumrai.id/zonefile/853cd126478237bc7392e65091f7ffa5a1556a33` + ); expect(query2.status).toBe(200); expect(query2.type).toBe('application/json'); expect(query2.body).toEqual({ - zonefile: '$ORIGIN zumrai.id\n$TTL 3600\n_http._tcp IN URI 10 1 "https://gaia.blockstack.org/hub/1EPno1VcdGx89ukN2we4iVpnFtkHzw8i5d/profile.json"\n\n', + zonefile: + '$ORIGIN zumrai.id\n$TTL 3600\n_http._tcp IN URI 10 1 "https://gaia.blockstack.org/hub/1EPno1VcdGx89ukN2we4iVpnFtkHzw8i5d/profile.json"\n\n', }); const query3 = await supertest(api.server).get(`/v1/names/zumrai.id/zonefile`); expect(query3.status).toBe(200); expect(query3.type).toBe('application/json'); expect(query3.body).toEqual({ - zonefile: '$ORIGIN zumrai.id\n$TTL 3600\n_http._tcp IN URI 10 1 "https://gaia.blockstack.org/hub/1EPno1VcdGx89ukN2we4iVpnFtkHzw8i5d/profile.json"\n\n', + zonefile: + '$ORIGIN zumrai.id\n$TTL 3600\n_http._tcp IN URI 10 1 "https://gaia.blockstack.org/hub/1EPno1VcdGx89ukN2we4iVpnFtkHzw8i5d/profile.json"\n\n', }); const query4 = await supertest(api.server).get(`/v1/names/id.blockstack/subdomains`); expect(query4.status).toBe(200); expect(query4.type).toBe('application/json'); - expect(query4.body.sort()).toStrictEqual([ - "12312313231.id.blockstack", "aichamez.id.blockstack", "ale082308as.id.blockstack", - "alejandro772.id.blockstack", "alkorsandor8_2.id.blockstack", "amir4good.id.blockstack", - "anasa680.id.blockstack", "ancafajardo.id.blockstack", "angelessebastian.id.blockstack", - "blafus3l.id.blockstack", "caomicoje.id.blockstack", "con_adrada34516.id.blockstack", - "cryptichorizon.id.blockstack", "drgenius.id.blockstack", "drifting_dude.id.blockstack", - "enavarrocollin.id.blockstack", "entryist.id.blockstack", "flushreset.id.blockstack", - "harukoscarlet.id.blockstack", "hintonh924.id.blockstack", "johnkinney.id.blockstack", - "jokialternative.id.blockstack", "joren_instance.id.blockstack", "kerodriguez.id.blockstack", - "krishares10.id.blockstack", "liviaelyse.id.blockstack", "luke_mwenya1.id.blockstack", - "milkyymocha.id.blockstack", "mithical.id.blockstack", "mrbotham.id.blockstack", - "mymansgotabeefy1.id.blockstack", "neelyblake996.id.blockstack", "nihal_t_m.id.blockstack", - "okamii63.id.blockstack", "robertascardoso.id.blockstack", "sheridoug.id.blockstack", - "sipapi19.id.blockstack", "slemanb44.id.blockstack", "slimttfu.id.blockstack", - "splevine.id.blockstack", "sportsman66.id.blockstack", "starbvuks.id.blockstack", - "subtly_fresh.id.blockstack", "svirchok.id.blockstack", "theironcook.id.blockstack", - "thingnotok.id.blockstack", "ujku1977.id.blockstack", "yanadda9.id.blockstack", - "yoemmx00.id.blockstack", "zachgaming.id.blockstack" - ].sort()); + expect(query4.body.sort()).toStrictEqual( + [ + '12312313231.id.blockstack', + 'aichamez.id.blockstack', + 'ale082308as.id.blockstack', + 'alejandro772.id.blockstack', + 'alkorsandor8_2.id.blockstack', + 'amir4good.id.blockstack', + 'anasa680.id.blockstack', + 'ancafajardo.id.blockstack', + 'angelessebastian.id.blockstack', + 'blafus3l.id.blockstack', + 'caomicoje.id.blockstack', + 'con_adrada34516.id.blockstack', + 'cryptichorizon.id.blockstack', + 'drgenius.id.blockstack', + 'drifting_dude.id.blockstack', + 'enavarrocollin.id.blockstack', + 'entryist.id.blockstack', + 'flushreset.id.blockstack', + 'harukoscarlet.id.blockstack', + 'hintonh924.id.blockstack', + 'johnkinney.id.blockstack', + 'jokialternative.id.blockstack', + 'joren_instance.id.blockstack', + 'kerodriguez.id.blockstack', + 'krishares10.id.blockstack', + 'liviaelyse.id.blockstack', + 'luke_mwenya1.id.blockstack', + 'milkyymocha.id.blockstack', + 'mithical.id.blockstack', + 'mrbotham.id.blockstack', + 'mymansgotabeefy1.id.blockstack', + 'neelyblake996.id.blockstack', + 'nihal_t_m.id.blockstack', + 'okamii63.id.blockstack', + 'robertascardoso.id.blockstack', + 'sheridoug.id.blockstack', + 'sipapi19.id.blockstack', + 'slemanb44.id.blockstack', + 'slimttfu.id.blockstack', + 'splevine.id.blockstack', + 'sportsman66.id.blockstack', + 'starbvuks.id.blockstack', + 'subtly_fresh.id.blockstack', + 'svirchok.id.blockstack', + 'theironcook.id.blockstack', + 'thingnotok.id.blockstack', + 'ujku1977.id.blockstack', + 'yanadda9.id.blockstack', + 'yoemmx00.id.blockstack', + 'zachgaming.id.blockstack', + ].sort() + ); const query5 = await supertest(api.server).get(`/v1/names/`); expect(query5.status).toBe(200); expect(query5.type).toBe('application/json'); - expect(query5.body.sort()).toStrictEqual([ - "id.blockstack", "1.id", "10.id", "10x.id", "111111111.id", "123.id", "zinai.id", "zlh.id", - "zone117x.id", "zumminer_crux.id", "zumminer_dev_crux.id", "zumrai.id", - ].sort()); + expect(query5.body.sort()).toStrictEqual( + [ + 'id.blockstack', + '1.id', + '10.id', + '10x.id', + '111111111.id', + '123.id', + 'zinai.id', + 'zlh.id', + 'zone117x.id', + 'zumminer_crux.id', + 'zumminer_dev_crux.id', + 'zumrai.id', + ].sort() + ); // Namespaces const query6 = await supertest(api.server).get(`/v1/namespaces/`); expect(query6.status).toBe(200); expect(query6.type).toBe('application/json'); expect(query6.body).toEqual({ - namespaces: ["blockstack", "graphite", "helloworld", "id", "podcast"] + namespaces: ['blockstack', 'graphite', 'helloworld', 'id', 'podcast'], }); const query7 = await supertest(api.server).get(`/v1/namespaces/id/names`); expect(query7.status).toBe(200); expect(query7.type).toBe('application/json'); - expect(query7.body.sort()).toStrictEqual([ - "1.id", "10.id", "10x.id", "111111111.id", "123.id", "zinai.id", "zlh.id", - "zone117x.id", "zumminer_crux.id", "zumminer_dev_crux.id", "zumrai.id" - ].sort()); + expect(query7.body.sort()).toStrictEqual( + [ + '1.id', + '10.id', + '10x.id', + '111111111.id', + '123.id', + 'zinai.id', + 'zlh.id', + 'zone117x.id', + 'zumminer_crux.id', + 'zumminer_dev_crux.id', + 'zumrai.id', + ].sort() + ); // Addresses - const query8 = await supertest(api.server).get(`/v1/addresses/stacks/SP1HPCXTGV31W5659M3WTBEFP5AN55HV4B1Q9T31F`); + const query8 = await supertest(api.server).get( + `/v1/addresses/stacks/SP1HPCXTGV31W5659M3WTBEFP5AN55HV4B1Q9T31F` + ); expect(query8.status).toBe(200); expect(query8.type).toBe('application/json'); expect(query8.body).toEqual({ - names: ["id.blockstack"] + names: ['id.blockstack'], }); // Subdomains @@ -140,7 +204,9 @@ describe('BNS V1 import', () => { zonefile_hash: '14dc091ebce8ea117e1276d802ee903cc0fdde81', }); - const query10 = await supertest(api.server).get(`/v1/names/flushreset.id.blockstack/zonefile/14dc091ebce8ea117e1276d802ee903cc0fdde81`); + const query10 = await supertest(api.server).get( + `/v1/names/flushreset.id.blockstack/zonefile/14dc091ebce8ea117e1276d802ee903cc0fdde81` + ); expect(query10.status).toBe(200); expect(query10.type).toBe('application/json'); expect(query10.body).toEqual({ @@ -156,9 +222,14 @@ describe('BNS V1 import', () => { '$ORIGIN flushreset.id.blockstack\n$TTL 3600\n_http._tcp IN URI 10 1 "https://gaia.blockstack.org/hub/1HEznKZ7mK5fmibweM7eAk8SwRgJ1bWY92/profile.json"\n\n', }); - const dbquery = await db.getSubdomain({ subdomain: `flushreset.id.blockstack`, includeUnanchored: false, chainId: ChainID.Testnet }); - assert(dbquery.found) - if (dbquery.result){ - expect(dbquery.result.name).toBe('id.blockstack');} + const dbquery = await db.getSubdomain({ + subdomain: `flushreset.id.blockstack`, + includeUnanchored: false, + chainId: ChainID.Testnet, + }); + assert(dbquery.found); + if (dbquery.result) { + expect(dbquery.result.name).toBe('id.blockstack'); + } }); }); diff --git a/src/tests-btc-faucet/faucet-btc-tests.ts b/tests/btc-faucet/faucet-btc.test.ts similarity index 95% rename from src/tests-btc-faucet/faucet-btc-tests.ts rename to tests/btc-faucet/faucet-btc.test.ts index 8d8dbad4ea..5d2ae10d0e 100644 --- a/src/tests-btc-faucet/faucet-btc-tests.ts +++ b/tests/btc-faucet/faucet-btc.test.ts @@ -1,18 +1,18 @@ import * as supertest from 'supertest'; import * as bitcoin from 'bitcoinjs-lib'; -import { ECPair } from '../ec-helpers'; +import { ECPair } from '../../src/ec-helpers'; import { makeBtcFaucetPayment, getRpcClient, getFaucetAccount, getKeyAddress, getBtcBalance, -} from '../btc-faucet'; -import { ApiServer, startApiServer } from '../api/init'; +} from '../../src/btc-faucet'; +import { ApiServer, startApiServer } from '../../src/api/init'; import { ChainID } from '@stacks/transactions'; -import { PgStore } from '../datastore/pg-store'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +import { PgStore } from '../../src/datastore/pg-store'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; async function getBalanceWithWalletImport(address: string): Promise { const client = getRpcClient(); diff --git a/src/tests-btc-faucet/setup.ts b/tests/btc-faucet/setup.ts similarity index 87% rename from src/tests-btc-faucet/setup.ts rename to tests/btc-faucet/setup.ts index c3d10b9cf7..a645360747 100644 --- a/src/tests-btc-faucet/setup.ts +++ b/tests/btc-faucet/setup.ts @@ -1,5 +1,5 @@ -import { loadDotEnv } from '../helpers'; -import { getRpcClient } from '../btc-faucet'; +import { loadDotEnv } from '../../src/helpers'; +import { getRpcClient } from '../../src/btc-faucet'; import { timeout } from '@hirosystems/api-toolkit'; // ts-unused-exports:disable-next-line diff --git a/src/tests/teardown.ts b/tests/btc-faucet/teardown.ts similarity index 100% rename from src/tests/teardown.ts rename to tests/btc-faucet/teardown.ts diff --git a/src/tests-event-replay/helper-tests.ts b/tests/event-replay/helper.test.ts similarity index 96% rename from src/tests-event-replay/helper-tests.ts rename to tests/event-replay/helper.test.ts index 539fd61a06..ae191c8dd7 100644 --- a/src/tests-event-replay/helper-tests.ts +++ b/tests/event-replay/helper.test.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; -import { findTsvBlockHeight } from '../event-replay/helpers'; -import { readLinesReversed } from '../event-replay/reverse-file-stream'; +import { findTsvBlockHeight } from '../../src/event-replay/helpers'; +import { readLinesReversed } from '../../src/event-replay/reverse-file-stream'; describe('helper tests', () => { function writeTmpFile(fileName: string, contents: string): string { diff --git a/src/tests-event-replay/import-export-tests.ts b/tests/event-replay/import-export.test.ts similarity index 80% rename from src/tests-event-replay/import-export-tests.ts rename to tests/event-replay/import-export.test.ts index c5d71d14d4..c2f7780902 100644 --- a/src/tests-event-replay/import-export-tests.ts +++ b/tests/event-replay/import-export.test.ts @@ -1,15 +1,15 @@ import { ChainID } from '@stacks/transactions'; import * as fs from 'fs'; import * as path from 'path'; -import { getRawEventRequests } from '../event-replay/event-requests'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { exportEventsAsTsv, importEventsFromTsv } from '../event-replay/event-replay'; -import { startEventServer } from '../event-stream/event-server'; -import { httpPostRequest } from '../helpers'; -import { useWithCleanup } from '../tests/test-helpers'; -import { migrate } from '../test-utils/test-helpers'; +import { getRawEventRequests } from '../../src/event-replay/event-requests'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { exportEventsAsTsv, importEventsFromTsv } from '../../src/event-replay/event-replay'; +import { startEventServer } from '../../src/event-stream/event-server'; +import { httpPostRequest } from '../../src/helpers'; +import { useWithCleanup } from '../api/test-helpers'; +import { migrate } from '../utils/test-helpers'; import { PgSqlClient, dangerousDropAllTables, databaseHasData } from '@hirosystems/api-toolkit'; -import { getConnectionArgs } from '../datastore/connection'; +import { getConnectionArgs } from '../../src/datastore/connection'; describe('import/export tests', () => { let db: PgWriteStore; @@ -28,7 +28,7 @@ describe('import/export tests', () => { test('event import and export cycle - remote', async () => { // Import from mocknet TSV - await importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', true, true); + await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true); const chainTip = await db.getChainTip(db.sql); expect(chainTip.block_height).toBe(28); expect(chainTip.index_block_hash).toBe( @@ -39,7 +39,7 @@ describe('import/export tests', () => { ); // Export into temp TSV - const tmpDir = 'src/tests-event-replay/.tmp/remote'; + const tmpDir = 'tests/event-replay/.tmp/remote'; fs.mkdirSync(tmpDir, { recursive: true }); await exportEventsAsTsv(`${tmpDir}/export.tsv`); @@ -55,13 +55,13 @@ describe('import/export tests', () => { '0x7682af212d3c1ef62613412f9b5a727269b4548f14eca2e3f941f7ad8b3c11b2' ); } finally { - fs.rmSync(`${tmpDir}/export.tsv`); + fs.rmSync(`${tmpDir}/export.tsv`, { force: true }); } }); test('event import and export cycle - local', async () => { // Import from mocknet TSV - await importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', true, true); + await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true); const chainTip = await db.getChainTip(db.sql); expect(chainTip.block_height).toBe(28); expect(chainTip.index_block_hash).toBe( @@ -72,7 +72,7 @@ describe('import/export tests', () => { ); // Export into temp TSV - const tmpDir = 'src/tests-event-replay/.tmp/local'; + const tmpDir = 'tests/event-replay/.tmp/local'; fs.mkdirSync(tmpDir, { recursive: true }); await exportEventsAsTsv('local:/root/export.tsv'); @@ -88,7 +88,7 @@ describe('import/export tests', () => { '0x7682af212d3c1ef62613412f9b5a727269b4548f14eca2e3f941f7ad8b3c11b2' ); } finally { - fs.rmSync(`${tmpDir}/export.tsv`); + fs.rmSync(`${tmpDir}/export.tsv`, { force: true }); } }); @@ -96,18 +96,18 @@ describe('import/export tests', () => { // Migrate first so we have some data. await migrate('up'); await expect( - importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', false, false) + importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', false, false) ).rejects.toThrowError('contains existing data'); // Create strange table await db.sql`CREATE TABLE IF NOT EXISTS test (a varchar(10))`; await expect( - importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', true, false) + importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, false) ).rejects.toThrowError('migration cycle failed'); // Force and test await expect( - importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', true, true) + importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true) ).resolves.not.toThrow(); }); @@ -132,21 +132,16 @@ describe('import/export tests', () => { }); test('Bns import occurs (block 1 genesis)', async () => { - process.env.BNS_IMPORT_DIR = 'src/tests-bns/import-test-files'; - await importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', true, true); + process.env.BNS_IMPORT_DIR = 'tests/bns/import-test-files'; + await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true); const configState = await db.getConfigState(); expect(configState.bns_names_onchain_imported).toBe(true); expect(configState.bns_subdomains_imported).toBe(true); }); test('Bns import occurs (block 0 genesis)', async () => { - process.env.BNS_IMPORT_DIR = 'src/tests-bns/import-test-files'; - await importEventsFromTsv( - 'src/tests-event-replay/tsv/mainnet-block0.tsv', - 'archival', - true, - true - ); + process.env.BNS_IMPORT_DIR = 'tests/bns/import-test-files'; + await importEventsFromTsv('tests/event-replay/tsv/mainnet-block0.tsv', 'archival', true, true); const configState = await db.getConfigState(); expect(configState.bns_names_onchain_imported).toBe(true); expect(configState.bns_subdomains_imported).toBe(true); @@ -154,8 +149,8 @@ describe('import/export tests', () => { test('BNS import should be skipped for Stacks subnet nodes', async () => { process.env.STACKS_NODE_TYPE = 'subnet'; - process.env.BNS_IMPORT_DIR = 'src/tests-bns/import-test-files'; - await importEventsFromTsv('src/tests-event-replay/tsv/mocknet.tsv', 'archival', true, true); + process.env.BNS_IMPORT_DIR = 'tests/bns/import-test-files'; + await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true); const configState = await db.getConfigState(); expect(configState.bns_names_onchain_imported).toBe(false); expect(configState.bns_subdomains_imported).toBe(false); @@ -186,7 +181,7 @@ describe('IBD', () => { let ibdResponses = 0; await useWithCleanup( () => { - const readStream = fs.createReadStream('src/tests-event-replay/tsv/mocknet.tsv'); + const readStream = fs.createReadStream('tests/event-replay/tsv/mocknet.tsv'); const rawEventsIterator = getRawEventRequests(readStream); return [rawEventsIterator, () => readStream.close()] as const; }, @@ -238,7 +233,7 @@ describe('IBD', () => { test('IBD mode covers prune mode', async () => { // Import from mocknet TSV const responses = await importEventsFromTsv( - 'src/tests-event-replay/tsv/mocknet.tsv', + 'tests/event-replay/tsv/mocknet.tsv', 'pruned', true, true, diff --git a/src/tests-event-replay/poison-microblock-tests.ts b/tests/event-replay/poison-microblock.test.ts similarity index 87% rename from src/tests-event-replay/poison-microblock-tests.ts rename to tests/event-replay/poison-microblock.test.ts index 9c403c9c43..da1b19e7a2 100644 --- a/src/tests-event-replay/poison-microblock-tests.ts +++ b/tests/event-replay/poison-microblock.test.ts @@ -1,6 +1,6 @@ import { DbTxTypeId } from '../../src/datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { importEventsFromTsv } from '../event-replay/event-replay'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { importEventsFromTsv } from '../../src/event-replay/event-replay'; describe('poison microblock for height 80743', () => { let db: PgWriteStore; @@ -19,7 +19,7 @@ describe('poison microblock for height 80743', () => { test('test that it does not give 500 error', async () => { await importEventsFromTsv( - 'src/tests-event-replay/tsv/poisonmicroblock.tsv', + 'tests/event-replay/tsv/poisonmicroblock.tsv', 'archival', true, true diff --git a/src/tests-event-replay/raw-event-request-tests.ts b/tests/event-replay/raw-event-request.test.ts similarity index 91% rename from src/tests-event-replay/raw-event-request-tests.ts rename to tests/event-replay/raw-event-request.test.ts index 884d35bef9..5d25c57069 100644 --- a/src/tests-event-replay/raw-event-request-tests.ts +++ b/tests/event-replay/raw-event-request.test.ts @@ -1,12 +1,12 @@ import * as fs from 'fs'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { ChainID } from '@stacks/transactions'; -import { httpPostRequest } from '../helpers'; -import { EventStreamServer, startEventServer } from '../event-stream/event-server'; -import { getRawEventRequests } from '../event-replay/event-requests'; -import { useWithCleanup } from '../tests/test-helpers'; +import { httpPostRequest } from '../../src/helpers'; +import { EventStreamServer, startEventServer } from '../../src/event-stream/event-server'; +import { getRawEventRequests } from '../../src/event-replay/event-requests'; +import { useWithCleanup } from '../api/test-helpers'; import { PgSqlClient } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('Events table', () => { let db: PgWriteStore; @@ -37,7 +37,7 @@ describe('Events table', () => { await useWithCleanup( () => { - const readStream = fs.createReadStream('src/tests-event-replay/tsv/mainnet.tsv'); + const readStream = fs.createReadStream('tests/event-replay/tsv/mainnet.tsv'); const rawEventsIterator = getRawEventRequests(readStream); return [rawEventsIterator, () => readStream.close()] as const; }, @@ -101,7 +101,7 @@ describe('Events table', () => { async eventServer => { // split the tsv file into lines, split each line by tab, find the first line that has a cell value of `/new_block` const sampleTsv = fs - .readFileSync('src/tests-event-replay/tsv/mainnet-block0.tsv', 'utf8') + .readFileSync('tests/event-replay/tsv/mainnet-block0.tsv', 'utf8') .split('\n') .map(line => line.split('\t')) .find(line => line[2] === '/new_block'); diff --git a/src/tests/setup.ts b/tests/event-replay/setup.ts similarity index 84% rename from src/tests/setup.ts rename to tests/event-replay/setup.ts index 737c21ed32..4cb071dd7e 100644 --- a/src/tests/setup.ts +++ b/tests/event-replay/setup.ts @@ -1,4 +1,4 @@ -import { loadDotEnv } from '../helpers'; +import { loadDotEnv } from '../../src/helpers'; // ts-unused-exports:disable-next-line export default (): void => { diff --git a/src/tests-event-replay/teardown.ts b/tests/event-replay/teardown.ts similarity index 100% rename from src/tests-event-replay/teardown.ts rename to tests/event-replay/teardown.ts diff --git a/src/tests-event-replay/tsv/mainnet-block0.tsv b/tests/event-replay/tsv/mainnet-block0.tsv similarity index 100% rename from src/tests-event-replay/tsv/mainnet-block0.tsv rename to tests/event-replay/tsv/mainnet-block0.tsv diff --git a/src/tests-event-replay/tsv/mainnet.tsv b/tests/event-replay/tsv/mainnet.tsv similarity index 100% rename from src/tests-event-replay/tsv/mainnet.tsv rename to tests/event-replay/tsv/mainnet.tsv diff --git a/src/tests-event-replay/tsv/mocknet.tsv b/tests/event-replay/tsv/mocknet.tsv similarity index 100% rename from src/tests-event-replay/tsv/mocknet.tsv rename to tests/event-replay/tsv/mocknet.tsv diff --git a/src/tests-event-replay/tsv/poisonmicroblock.tsv b/tests/event-replay/tsv/poisonmicroblock.tsv similarity index 100% rename from src/tests-event-replay/tsv/poisonmicroblock.tsv rename to tests/event-replay/tsv/poisonmicroblock.tsv diff --git a/tests/jest.config.2.5.js b/tests/jest.config.2.5.js index 65102bd234..5144a1dfb6 100644 --- a/tests/jest.config.2.5.js +++ b/tests/jest.config.2.5.js @@ -2,20 +2,13 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-2.5/**/*.ts'], - testPathIgnorePatterns: [ - '/tests-2.5/global-setup.ts', - '/tests-2.5/global-teardown.ts', - '/tests-2.5/env-setup.ts', - '/tests-2.5/test-helpers.ts', - ], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-2.5/global-setup.ts', - globalTeardown: '/tests-2.5/global-teardown.ts', - setupFilesAfterEnv: ['/tests-2.5/env-setup.ts'], + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/2.5/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/2.5/global-setup.ts', + globalTeardown: '/tests/2.5/global-teardown.ts', + setupFilesAfterEnv: ['/tests/2.5/env-setup.ts'], testTimeout: 60_000, verbose: true, bail: true, diff --git a/tests/jest.config.api.js b/tests/jest.config.api.js new file mode 100644 index 0000000000..23f5f160b8 --- /dev/null +++ b/tests/jest.config.api.js @@ -0,0 +1,10 @@ +module.exports = { + preset: 'ts-jest', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/api/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/api/setup.ts', + globalTeardown: '/tests/api/teardown.ts', + testTimeout: 20000, +} diff --git a/tests/jest.config.bns-e2e.js b/tests/jest.config.bns-e2e.js index 9e16b8af8a..38953b7b88 100644 --- a/tests/jest.config.bns-e2e.js +++ b/tests/jest.config.bns-e2e.js @@ -2,15 +2,13 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-bns-e2e/*.ts'], - testPathIgnorePatterns: ['/tests-bns-e2e/setup.ts', '/tests-bns-e2e/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-bns-e2e/setup.ts', - globalTeardown: '/tests-bns-e2e/teardown.ts', - testTimeout: 60000, + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/bns-e2e/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/bns-e2e/setup.ts', + globalTeardown: '/tests/bns-e2e/teardown.ts', + testTimeout: 3600000, verbose: true, }; diff --git a/tests/jest.config.bns.js b/tests/jest.config.bns.js index 4f0e5b2e0e..91b8097abd 100644 --- a/tests/jest.config.bns.js +++ b/tests/jest.config.bns.js @@ -1,12 +1,10 @@ module.exports = { - preset: 'ts-jest', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-bns/*.ts'], - testPathIgnorePatterns: ['/tests-bns/setup.ts', '/tests-bns/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-bns/setup.ts', - globalTeardown: '/tests-bns/teardown.ts', - testTimeout: 60000, - } + preset: 'ts-jest', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/bns/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/bns/setup.ts', + globalTeardown: '/tests/bns/teardown.ts', + testTimeout: 60000, +}; diff --git a/tests/jest.config.btc-faucet.js b/tests/jest.config.btc-faucet.js index 92a04b60a6..2e81b6cada 100644 --- a/tests/jest.config.btc-faucet.js +++ b/tests/jest.config.btc-faucet.js @@ -1,12 +1,10 @@ module.exports = { - preset: 'ts-jest', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-btc-faucet/*.ts'], - testPathIgnorePatterns: ['/tests-btc-faucet/setup.ts', '/tests-btc-faucet/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-btc-faucet/setup.ts', - globalTeardown: '/tests-btc-faucet/teardown.ts', - testTimeout: 60000, - } + preset: 'ts-jest', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/btc-faucet/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/btc-faucet/setup.ts', + globalTeardown: '/tests/btc-faucet/teardown.ts', + testTimeout: 60000, +}; diff --git a/tests/jest.config.event-replay.js b/tests/jest.config.event-replay.js index 2df8bda08e..d1308035d2 100644 --- a/tests/jest.config.event-replay.js +++ b/tests/jest.config.event-replay.js @@ -1,15 +1,10 @@ module.exports = { preset: 'ts-jest', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-event-replay/**/*.ts'], - testPathIgnorePatterns: [ - '/tests-event-replay/setup.ts', - '/tests-event-replay/teardown.ts', - ], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-event-replay/setup.ts', - globalTeardown: '/tests-event-replay/teardown.ts', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/event-replay/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/event-replay/setup.ts', + globalTeardown: '/tests/event-replay/teardown.ts', testTimeout: 20000, }; diff --git a/tests/jest.config.js b/tests/jest.config.js deleted file mode 100644 index 8ff8f60baf..0000000000 --- a/tests/jest.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - preset: 'ts-jest', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests/**/*.ts'], - testPathIgnorePatterns: ['/tests/setup.ts', '/tests/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests/setup.ts', - globalTeardown: '/tests/teardown.ts', - testTimeout: 20000, -} diff --git a/tests/jest.config.rosetta-cli-construction.js b/tests/jest.config.rosetta-cli-construction.js index 7a54741a3a..96d03d5b79 100644 --- a/tests/jest.config.rosetta-cli-construction.js +++ b/tests/jest.config.rosetta-cli-construction.js @@ -2,14 +2,12 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-rosetta-cli-construction/**/*.ts'], - testPathIgnorePatterns: ['/tests-rosetta-cli-construction/setup.ts', '/tests-rosetta-cli-construction/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-rosetta-cli-construction/setup.ts', - globalTeardown: '/tests-rosetta-cli-construction/teardown.ts', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/rosetta-cli-construction/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/rosetta-cli-construction/setup.ts', + globalTeardown: '/tests/rosetta-cli-construction/teardown.ts', testTimeout: 180000, verbose: true, }; diff --git a/tests/jest.config.rosetta-cli-data.js b/tests/jest.config.rosetta-cli-data.js index 3eb99b8a35..cd63ef4a06 100644 --- a/tests/jest.config.rosetta-cli-data.js +++ b/tests/jest.config.rosetta-cli-data.js @@ -2,14 +2,12 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-rosetta-cli-data/**/*.ts'], - testPathIgnorePatterns: ['/tests-rosetta-cli-data/setup.ts', '/tests-rosetta-cli-data/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-rosetta-cli-data/setup.ts', - globalTeardown: '/tests-rosetta-cli-data/teardown.ts', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/rosetta-cli-data/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/rosetta-cli-data/setup.ts', + globalTeardown: '/tests/rosetta-cli-data/teardown.ts', testTimeout: 240000, verbose: true, }; diff --git a/tests/jest.config.rosetta-construction.js b/tests/jest.config.rosetta-construction.js index 166a80e1ce..2054a249b7 100644 --- a/tests/jest.config.rosetta-construction.js +++ b/tests/jest.config.rosetta-construction.js @@ -2,14 +2,12 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-rosetta-construction/**/*.ts'], - testPathIgnorePatterns: ['/tests-rosetta-construction/setup.ts', '/tests-rosetta-construction/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-rosetta-construction/setup.ts', - globalTeardown: '/tests-rosetta-construction/teardown.ts', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/rosetta-construction/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/rosetta-construction/setup.ts', + globalTeardown: '/tests/rosetta-construction/teardown.ts', testTimeout: 60_000, verbose: true, }; diff --git a/tests/jest.config.rosetta.js b/tests/jest.config.rosetta.js index ccf7995f42..8e727f85e5 100644 --- a/tests/jest.config.rosetta.js +++ b/tests/jest.config.rosetta.js @@ -2,14 +2,12 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-rosetta/**/*.ts'], - testPathIgnorePatterns: ['/tests-rosetta/setup.ts', '/tests-rosetta/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-rosetta/setup.ts', - globalTeardown: '/tests-rosetta/teardown.ts', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/rosetta/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/rosetta/setup.ts', + globalTeardown: '/tests/rosetta/teardown.ts', testTimeout: 60_000, verbose: true, }; diff --git a/tests/jest.config.rpc.js b/tests/jest.config.rpc.js index 9a46da747d..a8ab4e8028 100644 --- a/tests/jest.config.rpc.js +++ b/tests/jest.config.rpc.js @@ -2,14 +2,12 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-rpc/*.ts'], - testPathIgnorePatterns: ['/tests-rpc/setup.ts', '/tests-rpc/teardown.ts'], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-rpc/setup.ts', - globalTeardown: '/tests-rpc/teardown.ts', + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/rpc/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/rpc/setup.ts', + globalTeardown: '/tests/rpc/teardown.ts', testTimeout: 60_000, verbose: true, bail: true, diff --git a/tests/jest.config.subnets.js b/tests/jest.config.subnets.js index 75ed27d350..e3dc4a08f2 100644 --- a/tests/jest.config.subnets.js +++ b/tests/jest.config.subnets.js @@ -2,22 +2,14 @@ const config = { preset: 'ts-jest', testEnvironment: 'node', - rootDir: `${require('path').dirname(__dirname)}/src`, - testMatch: ['/tests-subnets/**/*.ts'], - testPathIgnorePatterns: [ - '/tests-subnets/global-setup.ts', - '/tests-subnets/global-teardown.ts', - '/tests-subnets/env-setup.ts', - '/tests-subnets/test-helpers.ts', - '/tests-subnets/set-env.ts', - ], - collectCoverageFrom: ['/**/*.ts'], - coveragePathIgnorePatterns: ['/tests*'], - coverageDirectory: '/../coverage', - globalSetup: '/tests-subnets/global-setup.ts', - globalTeardown: '/tests-subnets/global-teardown.ts', - setupFilesAfterEnv: ['/tests-subnets/env-setup.ts'], - setupFiles: ['/tests-subnets/set-env.ts'], + rootDir: `${require('path').dirname(__dirname)}`, + testMatch: ['/tests/subnets/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + coverageDirectory: '/coverage', + globalSetup: '/tests/subnets/global-setup.ts', + globalTeardown: '/tests/subnets/global-teardown.ts', + setupFilesAfterEnv: ['/tests/subnets/env-setup.ts'], + setupFiles: ['/tests/subnets/set-env.ts'], testTimeout: 60_000, verbose: true, bail: true, diff --git a/src/tests-rosetta-cli-construction/envs/env.construction b/tests/rosetta-cli-construction/envs/env.construction similarity index 100% rename from src/tests-rosetta-cli-construction/envs/env.construction rename to tests/rosetta-cli-construction/envs/env.construction diff --git a/src/tests-rosetta-cli-construction/setup.ts b/tests/rosetta-cli-construction/setup.ts similarity index 74% rename from src/tests-rosetta-cli-construction/setup.ts rename to tests/rosetta-cli-construction/setup.ts index 0b7b18df6e..456b1a9f8f 100644 --- a/src/tests-rosetta-cli-construction/setup.ts +++ b/tests/rosetta-cli-construction/setup.ts @@ -1,6 +1,6 @@ -import { loadDotEnv } from '../helpers'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { loadDotEnv } from '../../src/helpers'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; export interface GlobalServices { db: PgWriteStore; diff --git a/src/tests-rosetta-cli-construction/teardown.ts b/tests/rosetta-cli-construction/teardown.ts similarity index 100% rename from src/tests-rosetta-cli-construction/teardown.ts rename to tests/rosetta-cli-construction/teardown.ts diff --git a/src/tests-rosetta-cli-construction/validate-construction.ts b/tests/rosetta-cli-construction/validate-construction.test.ts similarity index 90% rename from src/tests-rosetta-cli-construction/validate-construction.ts rename to tests/rosetta-cli-construction/validate-construction.test.ts index 34312da444..109ef8fbb9 100644 --- a/src/tests-rosetta-cli-construction/validate-construction.ts +++ b/tests/rosetta-cli-construction/validate-construction.test.ts @@ -1,5 +1,5 @@ -import { ApiServer, startApiServer } from '../api/init'; -import { startEventServer } from '../event-stream/event-server'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { startEventServer } from '../../src/event-stream/event-server'; import { Server } from 'net'; import { AnchorMode, @@ -10,11 +10,11 @@ import { } from '@stacks/transactions'; import { StacksTestnet } from '@stacks/network'; import * as fs from 'fs'; -import { StacksCoreRpcClient, getCoreNodeEndpoint } from '../core-rpc/client'; +import { StacksCoreRpcClient, getCoreNodeEndpoint } from '../../src/core-rpc/client'; import { v2 as compose } from 'docker-compose'; import * as path from 'path'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { NonceJar, migrate, standByForTxSuccess } from '../test-utils/test-helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { NonceJar, migrate, standByForTxSuccess } from '../utils/test-helpers'; import { timeout } from '@hirosystems/api-toolkit'; const sender1 = { @@ -53,7 +53,7 @@ describe('Rosetta API', () => { '-f', 'docker/docker-compose.dev.rosetta-cli.yml', '--env-file', - 'src/tests-rosetta-cli-construction/envs/env.construction', + 'tests/rosetta-cli-construction/envs/env.construction', ], }); console.log('compose build result:', composeBuildResult); @@ -84,7 +84,7 @@ describe('Rosetta API', () => { '-f', 'docker/docker-compose.dev.rosetta-cli.yml', '--env-file', - 'src/tests-rosetta-cli-construction/envs/env.construction', + 'tests/rosetta-cli-construction/envs/env.construction', ], commandOptions: ['--abort-on-container-exit', '--force-recreate'], callback: (chunk, source) => { @@ -120,7 +120,7 @@ describe('Rosetta API', () => { '-f', 'docker/docker-compose.dev.rosetta-cli.yml', '--env-file', - 'src/tests-rosetta-cli-construction/envs/env.construction', + 'tests/rosetta-cli-construction/envs/env.construction', ], }) .catch(error => { diff --git a/src/tests-rosetta-cli-data/contracts/hello-world.clar b/tests/rosetta-cli-data/contracts/hello-world.clar similarity index 100% rename from src/tests-rosetta-cli-data/contracts/hello-world.clar rename to tests/rosetta-cli-data/contracts/hello-world.clar diff --git a/src/tests-rosetta-cli-data/envs/env.data b/tests/rosetta-cli-data/envs/env.data similarity index 100% rename from src/tests-rosetta-cli-data/envs/env.data rename to tests/rosetta-cli-data/envs/env.data diff --git a/src/tests-rosetta-cli-data/setup.ts b/tests/rosetta-cli-data/setup.ts similarity index 82% rename from src/tests-rosetta-cli-data/setup.ts rename to tests/rosetta-cli-data/setup.ts index 07e46a8df6..6b99bf4b41 100644 --- a/src/tests-rosetta-cli-data/setup.ts +++ b/tests/rosetta-cli-data/setup.ts @@ -1,5 +1,5 @@ -import { loadDotEnv } from '../helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { loadDotEnv } from '../../src/helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; export interface GlobalServices { db: PgWriteStore; diff --git a/src/tests-rosetta-cli-data/teardown.ts b/tests/rosetta-cli-data/teardown.ts similarity index 100% rename from src/tests-rosetta-cli-data/teardown.ts rename to tests/rosetta-cli-data/teardown.ts diff --git a/src/tests-rosetta-cli-data/validate-rosetta.ts b/tests/rosetta-cli-data/validate-rosetta.test.ts similarity index 94% rename from src/tests-rosetta-cli-data/validate-rosetta.ts rename to tests/rosetta-cli-data/validate-rosetta.test.ts index fb3e77e19c..683fb858cb 100644 --- a/src/tests-rosetta-cli-data/validate-rosetta.ts +++ b/tests/rosetta-cli-data/validate-rosetta.test.ts @@ -1,4 +1,4 @@ -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import { makeSTXTokenTransfer, makeContractDeploy, @@ -15,13 +15,13 @@ import { } from '@stacks/transactions'; import { StacksTestnet } from '@stacks/network'; import * as fs from 'fs'; -import { StacksCoreRpcClient, getCoreNodeEndpoint } from '../core-rpc/client'; -import { unwrapOptional } from '../helpers'; +import { StacksCoreRpcClient, getCoreNodeEndpoint } from '../../src/core-rpc/client'; +import { unwrapOptional } from '../../src/helpers'; import { v2 as compose } from 'docker-compose'; import * as path from 'path'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { EventStreamServer, startEventServer } from '../event-stream/event-server'; -import { NonceJar, migrate, standByForTxSuccess } from '../test-utils/test-helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { EventStreamServer, startEventServer } from '../../src/event-stream/event-server'; +import { NonceJar, migrate, standByForTxSuccess } from '../utils/test-helpers'; import { timeout } from '@hirosystems/api-toolkit'; const sender1 = { @@ -116,7 +116,7 @@ describe('Rosetta API', () => { '-f', 'docker/docker-compose.dev.rosetta-cli.yml', '--env-file', - 'src/tests-rosetta-cli-data/envs/env.data', + 'tests/rosetta-cli-data/envs/env.data', ], }); console.log('compose build result:', composeBuildResult); @@ -140,7 +140,7 @@ describe('Rosetta API', () => { for (const sender of senders) { const response = await deployContract( sender.privateKey, - 'src/tests-rosetta-cli-data/contracts/hello-world.clar', + 'tests/rosetta-cli-data/contracts/hello-world.clar', nonceJar ); contracts.push(response.contractId); @@ -174,7 +174,7 @@ describe('Rosetta API', () => { '-f', 'docker/docker-compose.dev.rosetta-cli.yml', '--env-file', - 'src/tests-rosetta-cli-data/envs/env.data', + 'tests/rosetta-cli-data/envs/env.data', ], commandOptions: ['--abort-on-container-exit', '--force-recreate'], callback: (chunk, source) => { @@ -230,7 +230,7 @@ describe('Rosetta API', () => { '-f', 'docker/docker-compose.dev.rosetta-cli.yml', '--env-file', - 'src/tests-rosetta-cli-data/envs/env.data', + 'tests/rosetta-cli-data/envs/env.data', ], }) .catch(error => { diff --git a/src/tests-rosetta-construction/construction.ts b/tests/rosetta-construction/construction.test.ts similarity index 99% rename from src/tests-rosetta-construction/construction.ts rename to tests/rosetta-construction/construction.test.ts index 92aa7c82b6..e4ff601612 100644 --- a/src/tests-rosetta-construction/construction.ts +++ b/tests/rosetta-construction/construction.test.ts @@ -16,7 +16,7 @@ import { RosettaConstructionPayloadsRequest, RosettaConstructionPreprocessRequest, RosettaConstructionPreprocessResponse, -} from '../rosetta/types'; +} from '../../src/rosetta/types'; import { AnchorMode, AuthType, @@ -43,7 +43,7 @@ import { } from '@stacks/transactions'; import * as assert from 'assert'; import * as supertest from 'supertest'; -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import { RosettaConstants, RosettaErrors, @@ -51,18 +51,18 @@ import { RosettaOperationStatuses, RosettaOperationTypes, getRosettaNetworkName, -} from '../api/rosetta-constants'; -import { getStacksTestnetNetwork, testnetKeys } from '../api/routes/debug'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { DbBlock } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { FoundOrNot } from '../helpers'; -import { getSignature, getStacksNetwork } from '../rosetta/rosetta-helpers'; +} from '../../src/api/rosetta-constants'; +import { getStacksTestnetNetwork, testnetKeys } from '../../src/api/routes/debug'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { DbBlock } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { FoundOrNot } from '../../src/helpers'; +import { getSignature, getStacksNetwork } from '../../src/rosetta/rosetta-helpers'; import { standByForPoxCycle, standByForTx as standByForTxShared, standByUntilBurnBlock, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; describe('Rosetta Construction', () => { let db: PgWriteStore; diff --git a/src/tests-rosetta-construction/setup.ts b/tests/rosetta-construction/setup.ts similarity index 72% rename from src/tests-rosetta-construction/setup.ts rename to tests/rosetta-construction/setup.ts index 7cb3c98c09..5c6469ec41 100644 --- a/src/tests-rosetta-construction/setup.ts +++ b/tests/rosetta-construction/setup.ts @@ -1,4 +1,4 @@ -import { defaultSetupInit } from '../test-utils/shared-setup'; +import { defaultSetupInit } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { diff --git a/src/tests-rosetta-construction/teardown.ts b/tests/rosetta-construction/teardown.ts similarity index 74% rename from src/tests-rosetta-construction/teardown.ts rename to tests/rosetta-construction/teardown.ts index 46f6b919b4..743f0426d7 100644 --- a/src/tests-rosetta-construction/teardown.ts +++ b/tests/rosetta-construction/teardown.ts @@ -1,4 +1,4 @@ -import { defaultSetupTeardown } from '../test-utils/shared-setup'; +import { defaultSetupTeardown } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async (): Promise => { diff --git a/src/tests-rosetta/account-tests.ts b/tests/rosetta/account.test.ts similarity index 76% rename from src/tests-rosetta/account-tests.ts rename to tests/rosetta/account.test.ts index 7bc99c92ad..787d3496ea 100644 --- a/src/tests-rosetta/account-tests.ts +++ b/tests/rosetta/account.test.ts @@ -1,10 +1,10 @@ import * as supertest from 'supertest'; import { ChainID, cvToHex, stringUtf8CV, uintCV } from '@stacks/transactions'; -import { ApiServer, startApiServer } from '../api/init'; -import { TestBlockBuilder } from '../test-utils/test-builders'; -import { DbAssetEventTypeId } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { migrate } from '../test-utils/test-helpers'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { TestBlockBuilder } from '../utils/test-builders'; +import { DbAssetEventTypeId } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; import nock = require('nock'); describe('/account tests', () => { @@ -20,7 +20,7 @@ describe('/account tests', () => { afterEach(async () => { await api.terminate(); await db?.close(); - await migrate('down') + await migrate('down'); }); test('/account/balance - returns ft balances', async () => { @@ -31,14 +31,18 @@ describe('/account tests', () => { const nodeUrl = `http://${process.env['STACKS_CORE_RPC_HOST']}:${process.env['STACKS_CORE_RPC_PORT']}`; nock(nodeUrl) .persist() - .post('/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-decimals') + .post( + '/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-decimals' + ) .reply(200, { okay: true, result: cvToHex(uintCV(0)), }); nock(nodeUrl) .persist() - .post('/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-symbol') + .post( + '/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-symbol' + ) .reply(200, { okay: true, result: cvToHex(stringUtf8CV('NYC')), @@ -56,20 +60,21 @@ describe('/account tests', () => { block_height: 2, index_block_hash: '0x02', parent_index_block_hash: '0x01', - block_hash: '0xf1f1' + block_hash: '0xf1f1', }) .addTx({ tx_id: '0x1111', sender_address: addr1 }) .addTxStxEvent({ amount: 1200n, sender: addr1, - recipient: addr2 + recipient: addr2, }) .addTxFtEvent({ - asset_identifier: 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', + asset_identifier: + 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', asset_event_type_id: DbAssetEventTypeId.Transfer, amount: 7500n, sender: addr1, - recipient: addr2 + recipient: addr2, }) .build(); await db.update(block2); @@ -78,17 +83,17 @@ describe('/account tests', () => { { currency: { decimals: 6, - symbol: 'STX' + symbol: 'STX', }, - value: '1200' + value: '1200', }, { currency: { decimals: 0, - symbol: 'NYC' + symbol: 'NYC', }, - value: '7500' - } + value: '7500', + }, ]; const query1 = await supertest(api.server) .post(`/rosetta/v1/account/balance`) @@ -114,5 +119,4 @@ describe('/account tests', () => { nock.cleanAll(); }); - }); diff --git a/src/tests-rosetta/api.ts b/tests/rosetta/api.test.ts similarity index 85% rename from src/tests-rosetta/api.ts rename to tests/rosetta/api.test.ts index 77f1fae06e..2bce79f64a 100644 --- a/src/tests-rosetta/api.ts +++ b/tests/rosetta/api.test.ts @@ -1,11 +1,8 @@ -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import * as supertest from 'supertest'; -import { DbMempoolTxRaw, DbTxStatus, DbTxTypeId, DbTxAnchorMode } from '../datastore/common'; +import { DbMempoolTxRaw, DbTxStatus, DbTxTypeId, DbTxAnchorMode } from '../../src/datastore/common'; import * as assert from 'assert'; -import { - AnchorMode, - ChainID, -} from '@stacks/transactions'; +import { ChainID } from '@stacks/transactions'; import { RosettaAccount, RosettaAccountBalanceRequest, @@ -19,25 +16,25 @@ import { RosettaNetworkStatusResponse, RosettaOperation, RosettaTransaction, -} from '../rosetta/types'; +} from '../../src/rosetta/types'; import { RosettaErrors, RosettaOperationType, RosettaOperationTypes, RosettaOperationStatuses, RosettaConstants, -} from '../api/rosetta-constants'; +} from '../../src/api/rosetta-constants'; import { TestBlockArgs, TestBlockBuilder, TestSmartContractEventArgs, TestStxEventArgs, TestTxArgs, -} from '../test-utils/test-builders'; -import { PgWriteStore } from '../datastore/pg-write-store'; +} from '../utils/test-builders'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import * as nock from 'nock'; import { PgSqlClient, bufferToHex } from '@hirosystems/api-toolkit'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; describe('Rosetta API', () => { let db: PgWriteStore; @@ -69,6 +66,7 @@ describe('Rosetta API', () => { test('network/options', async () => { const nodeVersion = process.version; + // eslint-disable-next-line @typescript-eslint/no-var-requires const middlewareVersion = require('../../package.json').version; const query1 = await supertest(api.server) .post(`/rosetta/v1/network/options`) @@ -137,38 +135,35 @@ describe('Rosetta API', () => { block_height: 2, index_block_hash: '0x12345678', burn_block_height: 13334, - } + }; const blockData = new TestBlockBuilder(blockBuilderData).build(); await db.update(genesisData); await db.update(blockData); - const block = blockData.block, genesisBlock = genesisData.block; + const block = blockData.block, + genesisBlock = genesisData.block; - nock('http://127.0.0.1:20443') - .get('/v2/neighbors') - .reply(200, { - sample: [], - inbound: [], - outbound: [] - }); - nock('http://127.0.0.1:20443') - .get('/v2/info') - .reply(200, { - burn_block_height: block.burn_block_height, - burn_consensus: block.burn_block_hash, - exit_at_block_height: null, - network_id: 1, - parent_network_id: 1, - peer_version: 1, - server_version: 1, - stable_burn_block_height: block.burn_block_height, - stable_burn_consensus: block.burn_block_hash, - stacks_tip: block.block_hash, - stacks_tip_burn_block: block.burn_block_height, - stacks_tip_height: block.block_height, - unanchored_tip: '' - }); + nock('http://127.0.0.1:20443').get('/v2/neighbors').reply(200, { + sample: [], + inbound: [], + outbound: [], + }); + nock('http://127.0.0.1:20443').get('/v2/info').reply(200, { + burn_block_height: block.burn_block_height, + burn_consensus: block.burn_block_hash, + exit_at_block_height: null, + network_id: 1, + parent_network_id: 1, + peer_version: 1, + server_version: 1, + stable_burn_block_height: block.burn_block_height, + stable_burn_consensus: block.burn_block_hash, + stacks_tip: block.block_hash, + stacks_tip_burn_block: block.burn_block_height, + stacks_tip_height: block.block_height, + unanchored_tip: '', + }); const query1 = await supertest(api.address) .post(`/rosetta/v1/network/status`) .send({ network_identifier: { blockchain: 'stacks', network: 'testnet' } }); @@ -191,7 +186,7 @@ describe('Rosetta API', () => { current_index: 2, synced: true, target_index: 2, - } + }, }; expect(query1.body).toEqual(expectResponse); }); @@ -203,17 +198,19 @@ describe('Rosetta API', () => { anchor_mode: DbTxAnchorMode.OnChainOnly, status: DbTxStatus.Success, sender_address: 'ST2N3HQ5BZV43J0ZZY4X6T50NTQTQBMZ3AVRQ86A', - coinbase_payload: '' - } + coinbase_payload: '', + }; const parentData = new TestBlockBuilder().addTx().build(); const data = new TestBlockBuilder({ - block_height: 2, - parent_block_hash: parentData.block.block_hash, - block_hash: '0x1234', - parent_index_block_hash: parentData.block.index_block_hash, - index_block_hash: '0x1234' - }).addTx(tx).build(); - await db.update(parentData) + block_height: 2, + parent_block_hash: parentData.block.block_hash, + block_hash: '0x1234', + parent_index_block_hash: parentData.block.index_block_hash, + index_block_hash: '0x1234', + }) + .addTx(tx) + .build(); + await db.update(parentData); await db.update(data); const query1 = await supertest(api.address) .post(`/rosetta/v1/block`) @@ -251,7 +248,7 @@ describe('Rosetta API', () => { ], metadata: { burn_block_height: data.block.burn_block_height, - } + }, }, }; expect(JSON.parse(query1.text)).toEqual(expected); @@ -264,17 +261,19 @@ describe('Rosetta API', () => { anchor_mode: DbTxAnchorMode.OnChainOnly, status: DbTxStatus.Success, sender_address: 'ST2N3HQ5BZV43J0ZZY4X6T50NTQTQBMZ3AVRQ86A', - coinbase_payload: '' - } + coinbase_payload: '', + }; const parentData = new TestBlockBuilder().addTx().build(); const data = new TestBlockBuilder({ - block_height: 2, - parent_block_hash: parentData.block.block_hash, - block_hash: '0x1234', - parent_index_block_hash: parentData.block.index_block_hash, - index_block_hash: '0x1234' - }).addTx(tx).build(); - await db.update(parentData) + block_height: 2, + parent_block_hash: parentData.block.block_hash, + block_hash: '0x1234', + parent_index_block_hash: parentData.block.index_block_hash, + index_block_hash: '0x1234', + }) + .addTx(tx) + .build(); + await db.update(parentData); await db.update(data); const query1 = await supertest(api.address) .post(`/rosetta/v1/block`) @@ -312,7 +311,7 @@ describe('Rosetta API', () => { ], metadata: { burn_block_height: data.block.burn_block_height, - } + }, }, }; expect(JSON.parse(query1.text)).toEqual(expected); @@ -324,7 +323,7 @@ describe('Rosetta API', () => { index_block_hash: '0x2d1a360199f2992176b6c517df02e0350de863ac1d704e27f873aca41d1d5c58', burn_block_time: 1647245793, burn_block_hash: '0x12771355e46cd47c71ed1721fd5319b383cca3a1f9fce3aa1c8cd3bd37af20d7', - } + }; const block2 = { block_hash: '0x152ea79ffe71b835ccb575b732ed70354b169d44c6317752b2e1d48d15decf83', @@ -335,7 +334,7 @@ describe('Rosetta API', () => { burn_block_time: 94869286, burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb', burn_block_height: 1222, - } + }; await db.update(new TestBlockBuilder(block1).addTx().build()); await db.update(new TestBlockBuilder(block2).addTx().build()); @@ -363,7 +362,7 @@ describe('Rosetta API', () => { transactions: expect.objectContaining({}), metadata: { burn_block_height: block2.burn_block_height, - } + }, }, }; expect(JSON.parse(query1.text)).toEqual(expected); @@ -378,7 +377,7 @@ describe('Rosetta API', () => { parent_microblock_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb', miner_txid: '0x0000000000000000000000000000000000000000000000000000000000000000', - } + }; const tx = { tx_id: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', tx_index: 1, @@ -397,7 +396,7 @@ describe('Rosetta API', () => { token_transfer_recipient_address: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP', token_transfer_amount: 3852n, token_transfer_memo: bufferToHex(Buffer.from('test1234')).padEnd(70, '0'), - } + }; const data = new TestBlockBuilder(block).addTx(tx).build(); await db.update(data); const query1 = await supertest(api.server) @@ -472,7 +471,7 @@ describe('Rosetta API', () => { parent_microblock_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb', miner_txid: '0x0000000000000000000000000000000000000000000000000000000000000000', - } + }; const tx: TestTxArgs = { tx_id: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', tx_index: 1, @@ -504,7 +503,11 @@ describe('Rosetta API', () => { contract_source: tx.smart_contract_source_code, abi: tx.abi, }; - const data = new TestBlockBuilder(block).addTx(tx).addTxStxEvent(stxEvent).addTxSmartContract(contract).build(); + const data = new TestBlockBuilder(block) + .addTx(tx) + .addTxStxEvent(stxEvent) + .addTxSmartContract(contract) + .build(); await db.update(parentData); await db.update(data); const query1 = await supertest(api.server) @@ -516,99 +519,97 @@ describe('Rosetta API', () => { }); expect(query1.status).toBe(200); expect(query1.type).toBe('application/json'); - expect(JSON.parse(query1.text)).toEqual( - { - "transaction_identifier": { - "hash": "0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48" - }, - "operations": [ - { - "operation_identifier": { - "index": 0 - }, - "type": "fee", - "status": "success", - "account": { - "address": "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR" - }, - "amount": { - "value": "-180", - "currency": { - "decimals": 6, - "symbol": "STX" - } - } + expect(JSON.parse(query1.text)).toEqual({ + transaction_identifier: { + hash: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', + }, + operations: [ + { + operation_identifier: { + index: 0, }, - { - "operation_identifier": { - "index": 1 - }, - "type": "smart_contract", - "status": "success", - "account": { - "address": "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR" - } + type: 'fee', + status: 'success', + account: { + address: 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR', }, - { - "operation_identifier": { - "index": 2 - }, - "type": "token_transfer", - "status": "success", - "account": { - "address": "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR" + amount: { + value: '-180', + currency: { + decimals: 6, + symbol: 'STX', }, - "amount": { - "value": "-3852", - "currency": { - "decimals": 6, - "symbol": "STX" - } - }, - "coin_change": { - "coin_action": "coin_spent", - "coin_identifier": { - "identifier": "0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48:2" - } + }, + }, + { + operation_identifier: { + index: 1, + }, + type: 'smart_contract', + status: 'success', + account: { + address: 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR', + }, + }, + { + operation_identifier: { + index: 2, + }, + type: 'token_transfer', + status: 'success', + account: { + address: 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR', + }, + amount: { + value: '-3852', + currency: { + decimals: 6, + symbol: 'STX', }, - "metadata": { - "memo": "test memo field" - } }, - { - "operation_identifier": { - "index": 3 + coin_change: { + coin_action: 'coin_spent', + coin_identifier: { + identifier: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48:2', }, - "related_operations": [ - { - "index": 2 - } - ], - "type": "token_transfer", - "status": "success", - "account": { - "address": "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP" + }, + metadata: { + memo: 'test memo field', + }, + }, + { + operation_identifier: { + index: 3, + }, + related_operations: [ + { + index: 2, }, - "amount": { - "value": "3852", - "currency": { - "decimals": 6, - "symbol": "STX" - } + ], + type: 'token_transfer', + status: 'success', + account: { + address: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP', + }, + amount: { + value: '3852', + currency: { + decimals: 6, + symbol: 'STX', }, - "coin_change": { - "coin_action": "coin_created", - "coin_identifier": { - "identifier": "0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48:3" - } + }, + coin_change: { + coin_action: 'coin_created', + coin_identifier: { + identifier: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48:3', }, - "metadata": { - "memo": "test memo field" - } - } - ] - } - ); + }, + metadata: { + memo: 'test memo field', + }, + }, + ], + }); }); test('coinbase-pay-to-alt block/transaction', async () => { @@ -622,7 +623,7 @@ describe('Rosetta API', () => { parent_microblock_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb', miner_txid: '0x0000000000000000000000000000000000000000000000000000000000000000', - } + }; const txCoinbase1: TestTxArgs = { tx_id: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', tx_index: 1, @@ -647,7 +648,7 @@ describe('Rosetta API', () => { parent_microblock_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb', miner_txid: '0x0000000000000000000000000000000000000000000000000000000000000000', - } + }; const txCoinbase2: TestTxArgs = { tx_id: '0x3152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', tx_index: 1, @@ -672,26 +673,29 @@ describe('Rosetta API', () => { .post(`/rosetta/v1/block/transaction`) .send({ network_identifier: { blockchain: 'stacks', network: 'testnet' }, - block_identifier: { index: blockData1.block.block_height, hash: blockData1.block.block_hash }, + block_identifier: { + index: blockData1.block.block_height, + hash: blockData1.block.block_hash, + }, transaction_identifier: { hash: txCoinbase1.tx_id }, }); expect(query1.status).toBe(200); expect(query1.type).toBe('application/json'); expect(JSON.parse(query1.text)).toEqual({ - "operations": [ + operations: [ { - "account": { - "address": "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR", + account: { + address: 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR', }, - "operation_identifier": { - "index": 0, + operation_identifier: { + index: 0, }, - "status": "success", - "type": "coinbase", + status: 'success', + type: 'coinbase', }, ], - "transaction_identifier": { - "hash": "0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48", + transaction_identifier: { + hash: '0xc152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', }, }); @@ -699,26 +703,29 @@ describe('Rosetta API', () => { .post(`/rosetta/v1/block/transaction`) .send({ network_identifier: { blockchain: 'stacks', network: 'testnet' }, - block_identifier: { index: blockData2.block.block_height, hash: blockData2.block.block_hash }, + block_identifier: { + index: blockData2.block.block_height, + hash: blockData2.block.block_hash, + }, transaction_identifier: { hash: txCoinbase2.tx_id }, }); expect(query2.status).toBe(200); expect(query2.type).toBe('application/json'); expect(JSON.parse(query2.text)).toEqual({ - "operations": [ + operations: [ { - "account": { - "address": "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR", + account: { + address: 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR', }, - "operation_identifier": { - "index": 0, + operation_identifier: { + index: 0, }, - "status": "success", - "type": "coinbase", + status: 'success', + type: 'coinbase', }, ], - "transaction_identifier": { - "hash": "0x3152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48", + transaction_identifier: { + hash: '0x3152de9376bab4fc27291c9cd088643698290a12bb511d768f873cb3d280eb48', }, }); }); @@ -748,7 +755,7 @@ describe('Rosetta API', () => { tx_id: `0x891200000000000000000000000000000000000000000000000000000000000${i}`, anchor_mode: 3, nonce: 0, - raw_tx: ('0x6655443322'), + raw_tx: '0x6655443322', type_id: DbTxTypeId.Coinbase, receipt_time: (new Date(`2020-07-09T15:14:0${i}Z`).getTime() / 1000) | 0, coinbase_payload: '0x11818181', @@ -762,7 +769,7 @@ describe('Rosetta API', () => { }; mempoolTxs.push(mempoolTx); } - + await db.updateMempoolTxs({ mempoolTxs }); const request1: RosettaMempoolRequest = { @@ -864,12 +871,12 @@ describe('Rosetta API', () => { const block = { block_hash: '0x6d0df2553d3dd500dec73d00e5252eec09eb6d7cd36999b7dbf011abd186bdf0', index_block_hash: '0x9cd482f368644b5292bf05f5bb59a9e864386f8b96c49091ccf0818fe01c6fc5', - } + }; const stxEvent = { amount: 10000000000003852n, recipient: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP', - } + }; const data = new TestBlockBuilder(block).addTx().addTxStxEvent(stxEvent).build(); @@ -885,7 +892,6 @@ describe('Rosetta API', () => { }, }; - const result1 = await supertest(api.server).post(`/rosetta/v1/account/balance/`).send(request1); expect(result1.status).toBe(200); expect(result1.type).toBe('application/json'); @@ -928,7 +934,7 @@ describe('Rosetta API', () => { index_block_hash: '0x2d1a360199f2992176b6c517df02e0350de863ac1d704e27f873aca41d1d5c58', burn_block_time: 1647245793, burn_block_hash: '0x12771355e46cd47c71ed1721fd5319b383cca3a1f9fce3aa1c8cd3bd37af20d7', - } + }; const block2 = { block_hash: '0x152ea79ffe71b835ccb575b732ed70354b169d44c6317752b2e1d48d15decf83', @@ -938,7 +944,7 @@ describe('Rosetta API', () => { block_height: 2, burn_block_time: 1647245794, burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb', - } + }; const block3 = { block_hash: '0xd20083b03d0908bb7852bfbd7c9c7b5a3220dd6505b73c047da75d9a33bd59c3', @@ -948,7 +954,7 @@ describe('Rosetta API', () => { block_height: 3, burn_block_time: 1647250849, burn_block_hash: '0x376da11fe3ab3d0eaaddb418ccb49b5426d5c2504f526f7766580f6e45984e3b', - } + }; const block4 = { block_hash: '0x7d96609236e7cb6b55e0f3f8e94001e9b9223f5447fc97858137fed0314e0cae', @@ -958,9 +964,9 @@ describe('Rosetta API', () => { block_height: 4, burn_block_time: 1647250850, burn_block_hash: '0x4391a5c79ffdc79883036503ca551673c09deec28df432a8d88debc7fa2ec91e', - } + }; - const tx_1 = { + const tx_1 = { tx_id: '0xa95f0f833cf3b90473a9654526e9cb02626b85f32efae7f05c139d3460225d5f', type_id: DbTxTypeId.TokenTransfer, anchor_mode: DbTxAnchorMode.Any, @@ -971,7 +977,7 @@ describe('Rosetta API', () => { token_transfer_amount: 10000000n, token_transfer_memo: '0x25463526', fee_rate: 180n, - } + }; const tx_2 = { tx_id: '0xf03f217ebd89d2e0fd9bdf56ad2cc09b42455cd0d3442a4ebbb9f9dbf0dcc6b9', @@ -984,7 +990,7 @@ describe('Rosetta API', () => { token_transfer_amount: 10n, token_transfer_memo: '0x25463526', fee_rate: 180n, - } + }; const tx_3 = { tx_id: '0xc9d72d08ae48503e93f54b218b9048b1afdb1054f15baa3244490ad41a5a5902', @@ -998,7 +1004,7 @@ describe('Rosetta API', () => { token_transfer_memo: '0x25463526', nonce: 1, fee_rate: 180n, - } + }; const tx_4 = { tx_id: '0x552e94a0d57683fd8b8e4dfa5c807096e1fa7b6ab67f651f735b9d5e3c8bea93', @@ -1011,35 +1017,35 @@ describe('Rosetta API', () => { token_transfer_amount: 10n, token_transfer_memo: '0x25463526', fee_rate: 180n, - } + }; - const stx1 = { + const stx1 = { tx: tx_1, amount: 10000000n, sender: senderAddr1, - recipient: testAddr1 - } + recipient: testAddr1, + }; const stx2 = { amount: 10n, tx: tx_2, sender: testAddr1, - recipient: testAddr2 - } + recipient: testAddr2, + }; const stx3 = { amount: 10n, tx: tx_3, sender: testAddr1, recipient: testAddr2, - } + }; const stx4 = { amount: 10n, tx: tx_4, sender: testAddr1, - recipient: testAddr2 - } + recipient: testAddr2, + }; const data1 = new TestBlockBuilder(block1).addTx(tx_1).addTxStxEvent(stx1).build(); const data2 = new TestBlockBuilder(block2).addTx(tx_2).addTxStxEvent(stx2).build(); @@ -1063,7 +1069,9 @@ describe('Rosetta API', () => { address: testAddr1, }, }; - const nonceResult1 = await supertest(api.server).post(`/rosetta/v1/account/balance/`).send(request1); + const nonceResult1 = await supertest(api.server) + .post(`/rosetta/v1/account/balance/`) + .send(request1); expect(nonceResult1.status).toBe(200); expect(nonceResult1.type).toBe('application/json'); const expectedResponse1: RosettaAccountBalanceResponse = { @@ -1071,13 +1079,15 @@ describe('Rosetta API', () => { hash: data3.block.block_hash, index: data3.block.block_height, }, - balances: [{ - value: '9999620', - currency: { - symbol: 'STX', - decimals: 6, + balances: [ + { + value: '9999620', + currency: { + symbol: 'STX', + decimals: 6, + }, }, - }], + ], metadata: { sequence_number: 2, }, @@ -1096,7 +1106,9 @@ describe('Rosetta API', () => { address: testAddr1, }, }; - const nonceResult2 = await supertest(api.server).post(`/rosetta/v1/account/balance/`).send(request2); + const nonceResult2 = await supertest(api.server) + .post(`/rosetta/v1/account/balance/`) + .send(request2); expect(nonceResult2.status).toBe(200); expect(nonceResult2.type).toBe('application/json'); const expectedResponse2: RosettaAccountBalanceResponse = { @@ -1104,13 +1116,15 @@ describe('Rosetta API', () => { hash: data2.block.block_hash, index: data2.block.block_height, }, - balances: [{ - value: '9999810', - currency: { - symbol: 'STX', - decimals: 6, + balances: [ + { + value: '9999810', + currency: { + symbol: 'STX', + decimals: 6, + }, }, - }], + ], metadata: { sequence_number: 1, }, @@ -1130,7 +1144,9 @@ describe('Rosetta API', () => { address: testAddr3, }, }; - const nonceResult3 = await supertest(api.server).post(`/rosetta/v1/account/balance/`).send(request3); + const nonceResult3 = await supertest(api.server) + .post(`/rosetta/v1/account/balance/`) + .send(request3); expect(nonceResult3.status).toBe(200); expect(nonceResult3.type).toBe('application/json'); const expectedResponse3: RosettaAccountBalanceResponse = { @@ -1138,13 +1154,15 @@ describe('Rosetta API', () => { hash: data2.block.block_hash, index: data2.block.block_height, }, - balances: [{ - value: '0', - currency: { - symbol: 'STX', - decimals: 6, + balances: [ + { + value: '0', + currency: { + symbol: 'STX', + decimals: 6, + }, }, - }], + ], metadata: { sequence_number: 0, }, @@ -1161,9 +1179,9 @@ describe('Rosetta API', () => { index_block_hash: '0x2d1a360199f2992176b6c517df02e0350de863ac1d704e27f873aca41d1d5c58', burn_block_time: 1647245793, burn_block_hash: '0x12771355e46cd47c71ed1721fd5319b383cca3a1f9fce3aa1c8cd3bd37af20d7', - } + }; - const tx_1 = { + const tx_1 = { tx_id: '0xa95f0f833cf3b90473a9654526e9cb02626b85f32efae7f05c139d3460225d5f', type_id: DbTxTypeId.TokenTransfer, anchor_mode: DbTxAnchorMode.Any, @@ -1173,14 +1191,14 @@ describe('Rosetta API', () => { token_transfer_recipient_address: stxAddress, token_transfer_amount: 10000000000000000n, token_transfer_memo: '0x25463526', - } + }; - const stx1 = { + const stx1 = { tx: tx_1, amount: tx_1.token_transfer_amount, sender: senderAddr, - recipient: stxAddress - } + recipient: stxAddress, + }; const data1 = new TestBlockBuilder(block1).addTx(tx_1).addTxStxEvent(stx1).build(); @@ -1300,17 +1318,17 @@ describe('Rosetta API', () => { const expectResponse = { block_identifier: { index: 1, hash: block_hash }, - balances: [ - { - value: '0', + balances: [ + { + value: '0', currency: { decimals: 6, - symbol: "STX", - } - } + symbol: 'STX', + }, + }, ], - metadata: { sequence_number: 0 } - } + metadata: { sequence_number: 0 }, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); @@ -1332,8 +1350,8 @@ describe('Rosetta API', () => { code: 609, message: 'Invalid params.', retriable: false, - details: { message: "must have required property 'account_identifier'" } - } + details: { message: "must have required property 'account_identifier'" }, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); @@ -1355,11 +1373,11 @@ describe('Rosetta API', () => { expect(result.status).toBe(400); expect(result.type).toBe('application/json'); - const expectResponse = { - code: 605, - message: 'Block not found.', - retriable: true - } + const expectResponse = { + code: 605, + message: 'Block not found.', + retriable: true, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); @@ -1383,11 +1401,11 @@ describe('Rosetta API', () => { expect(result.status).toBe(400); expect(result.type).toBe('application/json'); - const expectResponse = { - code: 606, - message: 'Invalid block hash.', - retriable: true - } + const expectResponse = { + code: 606, + message: 'Invalid block hash.', + retriable: true, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); @@ -1401,7 +1419,7 @@ describe('Rosetta API', () => { account_identifier: { address: 'SP2QXJDSWYFGT9022M6NCA9SS4XNQM79D8E7EDSPQ', sub_account: { - address: 'invalid account' + address: 'invalid account', }, metadata: {}, }, @@ -1414,11 +1432,11 @@ describe('Rosetta API', () => { expect(result.status).toBe(400); expect(result.type).toBe('application/json'); - const expectResponse = { - code: 641, - message: 'Invalid sub-account', - retriable: false - } + const expectResponse = { + code: 641, + message: 'Invalid sub-account', + retriable: false, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); @@ -1434,7 +1452,7 @@ describe('Rosetta API', () => { account_identifier: { address: 'SP2QXJDSWYFGT9022M6NCA9SS4XNQM79D8E7EDSPQ', sub_account: { - address: RosettaConstants.VestingLockedBalance + address: RosettaConstants.VestingLockedBalance, }, metadata: {}, }, @@ -1443,32 +1461,34 @@ describe('Rosetta API', () => { }, }; await db.update(block); - await db.updateBatchTokenOfferingLocked(client, [{ address, block: block.block.block_height, value: 50n }]); + await db.updateBatchTokenOfferingLocked(client, [ + { address, block: block.block.block_height, value: 50n }, + ]); const result = await supertest(api.server).post(`/rosetta/v1/account/balance/`).send(request); expect(result.status).toBe(200); expect(result.type).toBe('application/json'); const expectResponse = { block_identifier: { index: 1, hash: block_hash }, - balances: [ - { - value: '0', + balances: [ + { + value: '0', currency: { decimals: 6, - symbol: 'STX' - }, + symbol: 'STX', + }, metadata: { VestingSchedule: [ JSON.stringify({ amount: '50', - unlock_height: 1 - }) - ] - } - } + unlock_height: 1, + }), + ], + }, + }, ], - metadata: { sequence_number: 0 } - } + metadata: { sequence_number: 0 }, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); @@ -1476,14 +1496,14 @@ describe('Rosetta API', () => { const result = await supertest(api.address) .post(`/rosetta/v1/block`) .send({ - network_identifier: { blockchain: 'stacks', network: 'testnet' } + network_identifier: { blockchain: 'stacks', network: 'testnet' }, }); const expectResponse = { code: 615, message: 'Block identifier is null.', retriable: false, - details: { message: "must have required property 'block_identifier'" } - } + details: { message: "must have required property 'block_identifier'" }, + }; expect(JSON.parse(result.text)).toEqual(expectResponse); }); }); diff --git a/src/tests-rosetta/block-tests.ts b/tests/rosetta/block.test.ts similarity index 80% rename from src/tests-rosetta/block-tests.ts rename to tests/rosetta/block.test.ts index d8e2d67701..e75ea5d23e 100644 --- a/src/tests-rosetta/block-tests.ts +++ b/tests/rosetta/block.test.ts @@ -1,12 +1,21 @@ import * as supertest from 'supertest'; -import { bufferCV, ChainID, cvToHex, listCV, stringAsciiCV, stringUtf8CV, tupleCV, uintCV } from '@stacks/transactions'; -import { ApiServer, startApiServer } from '../api/init'; -import { TestBlockBuilder } from '../test-utils/test-builders'; -import { DbAssetEventTypeId, DbTxTypeId } from '../datastore/common'; -import { createClarityValueArray } from '../stacks-encoding-helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { + bufferCV, + ChainID, + cvToHex, + listCV, + stringAsciiCV, + stringUtf8CV, + tupleCV, + uintCV, +} from '@stacks/transactions'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { TestBlockBuilder } from '../utils/test-builders'; +import { DbAssetEventTypeId, DbTxTypeId } from '../../src/datastore/common'; +import { createClarityValueArray } from '../../src/stacks-encoding-helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { principalCV } from '@stacks/transactions/dist/clarity/types/principalCV'; -import { migrate } from '../test-utils/test-helpers'; +import { migrate } from '../utils/test-helpers'; import { bufferToHex } from '@hirosystems/api-toolkit'; import nock = require('nock'); @@ -74,7 +83,9 @@ describe('/block tests', () => { sender_address: testContractAddr, contract_call_contract_id: testContractAddr, contract_call_function_name: 'test-contract-fn', - contract_call_function_args: bufferToHex(createClarityValueArray(uintCV(123456), stringAsciiCV('hello'))), + contract_call_function_args: bufferToHex( + createClarityValueArray(uintCV(123456), stringAsciiCV('hello')) + ), abi: JSON.stringify(contractJsonAbi), }) .build(); @@ -120,14 +131,18 @@ describe('/block tests', () => { const nodeUrl = `http://${process.env['STACKS_CORE_RPC_HOST']}:${process.env['STACKS_CORE_RPC_PORT']}`; nock(nodeUrl) .persist() - .post('/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-decimals') + .post( + '/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-decimals' + ) .reply(200, { okay: true, result: cvToHex(uintCV(0)), }); nock(nodeUrl) .persist() - .post('/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-symbol') + .post( + '/v2/contracts/call-read/SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5/newyorkcitycoin-token/get-symbol' + ) .reply(200, { okay: true, result: cvToHex(stringUtf8CV('NYC')), @@ -145,15 +160,16 @@ describe('/block tests', () => { block_height: 2, index_block_hash: '0x02', parent_index_block_hash: '0x01', - block_hash: '0xf1f1' + block_hash: '0xf1f1', }) .addTx({ tx_id: '0x1111', sender_address: addr1 }) .addTxFtEvent({ - asset_identifier: 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', + asset_identifier: + 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', asset_event_type_id: DbAssetEventTypeId.Transfer, amount: 7500n, sender: addr1, - recipient: addr2 + recipient: addr2, }) .build(); await db.update(block2); @@ -231,14 +247,15 @@ describe('/block tests', () => { block_height: 3, index_block_hash: '0x03', parent_index_block_hash: '0x02', - block_hash: '0xf1f2' + block_hash: '0xf1f2', }) .addTx({ tx_id: '0x1112', sender_address: addr1 }) .addTxFtEvent({ - asset_identifier: 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', + asset_identifier: + 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', asset_event_type_id: DbAssetEventTypeId.Burn, amount: 100n, - sender: addr1 + sender: addr1, }) .build(); await db.update(block3); @@ -279,14 +296,15 @@ describe('/block tests', () => { block_height: 4, index_block_hash: '0x04', parent_index_block_hash: '0x03', - block_hash: '0xf1f3' + block_hash: '0xf1f3', }) .addTx({ tx_id: '0x1113', sender_address: addr1 }) .addTxFtEvent({ - asset_identifier: 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', + asset_identifier: + 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.newyorkcitycoin-token::newyorkcitycoin', asset_event_type_id: DbAssetEventTypeId.Mint, amount: 500n, - recipient: addr1 + recipient: addr1, }) .build(); await db.update(block4); @@ -328,14 +346,14 @@ describe('/block tests', () => { block_height: 5, index_block_hash: '0x05', parent_index_block_hash: '0x04', - block_hash: '0xf1f4' + block_hash: '0xf1f4', }) .addTx({ tx_id: '0x1114', sender_address: addr1 }) .addTxFtEvent({ asset_identifier: 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.miamicoin-token::miamicoin', asset_event_type_id: DbAssetEventTypeId.Mint, amount: 500n, - recipient: addr1 + recipient: addr1, }) .build(); await db.update(block5); @@ -356,14 +374,14 @@ describe('/block tests', () => { block_height: 6, index_block_hash: '0x06', parent_index_block_hash: '0x05', - block_hash: '0xf1f5' + block_hash: '0xf1f5', }) .addTx({ tx_id: '0x1115', sender_address: addr1 }) .addTxFtEvent({ asset_identifier: 'SP2H8PY27SEZ03MWRKS5XABZYQN17ETGQS3527SA5.miamicoin-token::miamicoin', asset_event_type_id: DbAssetEventTypeId.Mint, amount: 500n, - recipient: addr1 + recipient: addr1, }) .build(); await db.update(block6); @@ -385,84 +403,84 @@ describe('/block tests', () => { test('block/transaction - send-many-memo includes memo metadata', async () => { const sendManyAddr = 'ST3F1X4QGV2SM8XD96X45M6RTQXKA1PZJZZCQAB4B.send-many-memo'; const sendManyAbi = { - "maps": [], - "functions": [ + maps: [], + functions: [ { - "args": [ + args: [ { - "name": "result", - "type": { "response": { "ok": "bool", "error": "uint128" } } + name: 'result', + type: { response: { ok: 'bool', error: 'uint128' } }, }, { - "name": "prior", - "type": { "response": { "ok": "bool", "error": "uint128" } } - } + name: 'prior', + type: { response: { ok: 'bool', error: 'uint128' } }, + }, ], - "name": "check-err", - "access": "private", - "outputs": { - "type": { "response": { "ok": "bool", "error": "uint128" } } - } + name: 'check-err', + access: 'private', + outputs: { + type: { response: { ok: 'bool', error: 'uint128' } }, + }, }, { - "args": [ + args: [ { - "name": "recipient", - "type": { - "tuple": [ - { "name": "memo", "type": { "buffer": { "length": 34 } } }, - { "name": "to", "type": "principal" }, - { "name": "ustx", "type": "uint128" } - ] - } - } + name: 'recipient', + type: { + tuple: [ + { name: 'memo', type: { buffer: { length: 34 } } }, + { name: 'to', type: 'principal' }, + { name: 'ustx', type: 'uint128' }, + ], + }, + }, ], - "name": "send-stx", - "access": "private", - "outputs": { - "type": { "response": { "ok": "bool", "error": "uint128" } } - } + name: 'send-stx', + access: 'private', + outputs: { + type: { response: { ok: 'bool', error: 'uint128' } }, + }, }, { - "args": [ + args: [ { - "name": "recipients", - "type": { - "list": { - "type": { - "tuple": [ - { "name": "memo", "type": { "buffer": { "length": 34 } } }, - { "name": "to", "type": "principal" }, - { "name": "ustx", "type": "uint128" } - ] + name: 'recipients', + type: { + list: { + type: { + tuple: [ + { name: 'memo', type: { buffer: { length: 34 } } }, + { name: 'to', type: 'principal' }, + { name: 'ustx', type: 'uint128' }, + ], }, - "length": 200 - } - } - } + length: 200, + }, + }, + }, ], - "name": "send-many", - "access": "public", - "outputs": { - "type": { "response": { "ok": "bool", "error": "uint128" } } - } + name: 'send-many', + access: 'public', + outputs: { + type: { response: { ok: 'bool', error: 'uint128' } }, + }, }, { - "args": [ - { "name": "ustx", "type": "uint128" }, - { "name": "to", "type": "principal" }, - { "name": "memo", "type": { "buffer": { "length": 34 } } } + args: [ + { name: 'ustx', type: 'uint128' }, + { name: 'to', type: 'principal' }, + { name: 'memo', type: { buffer: { length: 34 } } }, ], - "name": "send-stx-with-memo", - "access": "public", - "outputs": { - "type": { "response": { "ok": "bool", "error": "uint128" } } - } - } + name: 'send-stx-with-memo', + access: 'public', + outputs: { + type: { response: { ok: 'bool', error: 'uint128' } }, + }, + }, ], - "variables": [], - "fungible_tokens": [], - "non_fungible_tokens": [] + variables: [], + fungible_tokens: [], + non_fungible_tokens: [], }; // Deploy @@ -493,16 +511,16 @@ describe('/block tests', () => { tupleCV({ memo: bufferCV(Buffer.from('memo-1')), to: principalCV('SPG7RD94XW8HN5NS7V68YDJAY4PJVZ2KNY79Z518'), - ustx: uintCV(2000) + ustx: uintCV(2000), }), tupleCV({ memo: bufferCV(Buffer.from('memo-2')), to: principalCV('SP2XN3N1C3HM1YFHKBE07EW7AFZBZPXDTHSP92HAX'), - ustx: uintCV(2500) + ustx: uintCV(2500), }), tupleCV({ to: principalCV('SP2PDY84DFFJS0PQN3P0WBYZFW1EZSAC67N08BWH0'), - ustx: uintCV(50000) + ustx: uintCV(50000), }), ]) ) @@ -513,27 +531,27 @@ describe('/block tests', () => { .addTxStxEvent({ sender: sendManyAddr, recipient: 'SPG7RD94XW8HN5NS7V68YDJAY4PJVZ2KNY79Z518', - amount: 2000n + amount: 2000n, }) .addTxContractLogEvent({ contract_identifier: sendManyAddr, topic: 'print', - value: cvToHex(bufferCV(Buffer.from('memo-1'))) + value: cvToHex(bufferCV(Buffer.from('memo-1'))), }) .addTxStxEvent({ sender: sendManyAddr, recipient: 'SP2XN3N1C3HM1YFHKBE07EW7AFZBZPXDTHSP92HAX', - amount: 2500n + amount: 2500n, }) .addTxContractLogEvent({ contract_identifier: sendManyAddr, topic: 'print', - value: cvToHex(bufferCV(Buffer.from('memo-2'))) + value: cvToHex(bufferCV(Buffer.from('memo-2'))), }) .addTxStxEvent({ sender: sendManyAddr, recipient: 'SP2PDY84DFFJS0PQN3P0WBYZFW1EZSAC67N08BWH0', - amount: 50000n + amount: 50000n, }) .build(); await db.update(block2); @@ -578,7 +596,7 @@ describe('/block tests', () => { createClarityValueArray( uintCV(2000), principalCV('SPG7RD94XW8HN5NS7V68YDJAY4PJVZ2KNY79Z518'), - bufferCV(Buffer.from('memo-1')), + bufferCV(Buffer.from('memo-1')) ) ), abi: JSON.stringify(sendManyAbi), @@ -587,7 +605,7 @@ describe('/block tests', () => { .addTxStxEvent({ sender: sendManyAddr, recipient: 'SPG7RD94XW8HN5NS7V68YDJAY4PJVZ2KNY79Z518', - amount: 2000n + amount: 2000n, }) .build(); await db.update(block3); diff --git a/src/tests-rosetta/disable-api.ts b/tests/rosetta/disable-api.test.ts similarity index 74% rename from src/tests-rosetta/disable-api.ts rename to tests/rosetta/disable-api.test.ts index b8df673302..f717bae326 100644 --- a/src/tests-rosetta/disable-api.ts +++ b/tests/rosetta/disable-api.test.ts @@ -1,9 +1,9 @@ import * as supertest from 'supertest'; -import { PgSqlClient } from "@hirosystems/api-toolkit"; -import { ChainID } from "@stacks/common"; -import { ApiServer, startApiServer } from "../api/init"; -import { PgWriteStore } from "../datastore/pg-write-store"; -import { migrate } from "../test-utils/test-helpers"; +import { PgSqlClient } from '@hirosystems/api-toolkit'; +import { ChainID } from '@stacks/common'; +import { ApiServer, startApiServer } from '../../src/api/init'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { migrate } from '../utils/test-helpers'; describe('Rosetta API toggle', () => { let db: PgWriteStore; diff --git a/src/tests-rosetta/offline-api-tests.ts b/tests/rosetta/offline-api.test.ts similarity index 97% rename from src/tests-rosetta/offline-api-tests.ts rename to tests/rosetta/offline-api.test.ts index 1ebdadb7b3..d5c1579c72 100644 --- a/src/tests-rosetta/offline-api-tests.ts +++ b/tests/rosetta/offline-api.test.ts @@ -1,4 +1,4 @@ -import { ApiServer, startApiServer } from '../api/init'; +import { ApiServer, startApiServer } from '../../src/api/init'; import * as supertest from 'supertest'; import { AnchorMode, @@ -37,7 +37,7 @@ import { RosettaConstructionPreprocessRequest, RosettaConstructionPreprocessResponse, RosettaConstructionMetadataResponse, -} from '../rosetta/types'; +} from '../../src/rosetta/types'; import { getRosettaNetworkName, RosettaConstants, @@ -45,12 +45,16 @@ import { RosettaErrorsTypes, RosettaOperationTypes, RosettaOperationStatuses, -} from '../api/rosetta-constants'; -import { OfflineDummyStore } from '../datastore/offline-dummy-store'; -import { getStacksTestnetNetwork, testnetKeys } from '../api/routes/debug'; -import { getSignature, getStacksNetwork, publicKeyToBitcoinAddress } from '../rosetta/rosetta-helpers'; +} from '../../src/api/rosetta-constants'; +import { OfflineDummyStore } from '../../src/datastore/offline-dummy-store'; +import { getStacksTestnetNetwork, testnetKeys } from '../../src/api/routes/debug'; +import { + getSignature, + getStacksNetwork, + publicKeyToBitcoinAddress, +} from '../../src/rosetta/rosetta-helpers'; import * as nock from 'nock'; -import { PgStore } from '../datastore/pg-store'; +import { PgStore } from '../../src/datastore/pg-store'; import { StackingClient, decodeBtcAddress, poxAddressToTuple } from '@stacks/stacking'; import { bufferToHex } from '@hirosystems/api-toolkit'; import { hexToBytes } from '@stacks/common'; @@ -69,7 +73,7 @@ describe('Rosetta offline API', () => { afterAll(async () => { await api.terminate(); nock.cleanAll(); - nock.enableNetConnect() + nock.enableNetConnect(); }); test('Success: offline - network/list', async () => { @@ -83,6 +87,7 @@ describe('Rosetta offline API', () => { test('Success: offline - network/options- offline', async () => { const nodeVersion = process.version; + // eslint-disable-next-line @typescript-eslint/no-var-requires const middlewareVersion = require('../../package.json').version; const query1 = await supertest(api.server) .post(`/rosetta/v1/network/options`) @@ -903,7 +908,7 @@ describe('Rosetta offline API', () => { reward_cycle_id: reward_cycle_id, pox_auth_id: pox_auth_id, signer_signature: signerSig, - } + }, }, ], metadata: { @@ -982,12 +987,11 @@ describe('Rosetta offline API', () => { const contract_address = 'ST000000000000000000002AMW42H'; const contract_name = 'pox-4'; const stacking_amount = 5000; - const burn_block_height = 200; - + const burn_block_height = 200; const metadataResponse: RosettaConstructionMetadataResponse = { metadata: { - fee:fee, + fee: fee, sender_address: sender, type: 'delegate_stx', suggested_fee_multiplier: 1, @@ -1003,8 +1007,8 @@ describe('Rosetta offline API', () => { recent_block_hash: '0x969e494d5aee0166016836f97bbeb3d9473bea8427e477e9de253f78d3212354', burn_block_height: burn_block_height, }, - suggested_fee: [ { value: '390', currency: {symbol: 'STX', decimals: 6} } ] - } + suggested_fee: [{ value: '390', currency: { symbol: 'STX', decimals: 6 } }], + }; const request: RosettaConstructionPayloadsRequest = { network_identifier: { @@ -1051,8 +1055,8 @@ describe('Rosetta offline API', () => { }, metadata: { delegate_to: testnetKeys[1].stacksAddress, - pox_addr : '1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3', - } + pox_addr: '1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3', + }, }, ], metadata: metadataResponse.metadata, @@ -1064,7 +1068,7 @@ describe('Rosetta offline API', () => { ], }; - const poxBTCAddress = '1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3' + const poxBTCAddress = '1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3'; const { version: hashMode, data } = decodeBtcAddress(poxBTCAddress); const hashModeBuffer = bufferCV(Buffer.from([hashMode])); @@ -1074,7 +1078,6 @@ describe('Rosetta offline API', () => { version: hashModeBuffer, }); - const stackingTx: UnsignedContractCallOptions = { contractAddress: contract_address, contractName: contract_name, diff --git a/src/tests-rosetta/setup.ts b/tests/rosetta/setup.ts similarity index 60% rename from src/tests-rosetta/setup.ts rename to tests/rosetta/setup.ts index 93c3db8c10..dd94ea4592 100644 --- a/src/tests-rosetta/setup.ts +++ b/tests/rosetta/setup.ts @@ -1,9 +1,9 @@ -import { defaultSetupInit } from '../test-utils/shared-setup'; +import { defaultSetupInit } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { console.log('Jest - setup..'); - await defaultSetupInit({dummyEventHandler: true}); + await defaultSetupInit({ dummyEventHandler: true }); process.env.PG_DATABASE = 'postgres'; console.log('Jest - setup done'); }; diff --git a/src/tests-rpc/teardown.ts b/tests/rosetta/teardown.ts similarity index 74% rename from src/tests-rpc/teardown.ts rename to tests/rosetta/teardown.ts index 46f6b919b4..743f0426d7 100644 --- a/src/tests-rpc/teardown.ts +++ b/tests/rosetta/teardown.ts @@ -1,4 +1,4 @@ -import { defaultSetupTeardown } from '../test-utils/shared-setup'; +import { defaultSetupTeardown } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async (): Promise => { diff --git a/src/tests-rpc/core-rpc-tests.ts b/tests/rpc/core-rpc.test.ts similarity index 92% rename from src/tests-rpc/core-rpc-tests.ts rename to tests/rpc/core-rpc.test.ts index 1423d66536..11b0e58b9b 100644 --- a/src/tests-rpc/core-rpc-tests.ts +++ b/tests/rpc/core-rpc.test.ts @@ -1,4 +1,4 @@ -import { StacksCoreRpcClient } from '../core-rpc/client'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; describe('core RPC tests', () => { let client: StacksCoreRpcClient; diff --git a/src/tests-bns/setup.ts b/tests/rpc/setup.ts similarity index 75% rename from src/tests-bns/setup.ts rename to tests/rpc/setup.ts index 635c52d684..990aee7db9 100644 --- a/src/tests-bns/setup.ts +++ b/tests/rpc/setup.ts @@ -1,4 +1,4 @@ -import { defaultSetupInit } from '../test-utils/shared-setup'; +import { defaultSetupInit } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async () => { diff --git a/src/tests-rosetta/teardown.ts b/tests/rpc/teardown.ts similarity index 74% rename from src/tests-rosetta/teardown.ts rename to tests/rpc/teardown.ts index 46f6b919b4..743f0426d7 100644 --- a/src/tests-rosetta/teardown.ts +++ b/tests/rpc/teardown.ts @@ -1,4 +1,4 @@ -import { defaultSetupTeardown } from '../test-utils/shared-setup'; +import { defaultSetupTeardown } from '../utils/shared-setup'; // ts-unused-exports:disable-next-line export default async (): Promise => { diff --git a/src/tests-subnets/env-setup.ts b/tests/subnets/env-setup.ts similarity index 85% rename from src/tests-subnets/env-setup.ts rename to tests/subnets/env-setup.ts index c31ecdef4e..d67f460e72 100644 --- a/src/tests-subnets/env-setup.ts +++ b/tests/subnets/env-setup.ts @@ -1,11 +1,11 @@ import { StacksTestnet } from '@stacks/network'; import { ChainID } from '@stacks/transactions'; import { RPCClient } from 'rpc-bitcoin'; -import { startApiServer } from '../api/init'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { loadDotEnv } from '../helpers'; -import { TestEnvContext } from '../test-utils/test-helpers'; +import { startApiServer } from '../../src/api/init'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { loadDotEnv } from '../../src/helpers'; +import { TestEnvContext } from '../utils/test-helpers'; let testEnv: TestEnvContext; diff --git a/src/tests-subnets/global-setup.ts b/tests/subnets/global-setup.ts similarity index 82% rename from src/tests-subnets/global-setup.ts rename to tests/subnets/global-setup.ts index c659867d9d..4de6bff03f 100644 --- a/src/tests-subnets/global-setup.ts +++ b/tests/subnets/global-setup.ts @@ -1,11 +1,11 @@ -import { loadDotEnv } from '../helpers'; -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { EventStreamServer, startEventServer } from '../event-stream/event-server'; +import { loadDotEnv } from '../../src/helpers'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { EventStreamServer, startEventServer } from '../../src/event-stream/event-server'; import { ChainID } from '@stacks/transactions'; import { cycleMigrations, timeout } from '@hirosystems/api-toolkit'; -import { MIGRATIONS_DIR } from '../datastore/pg-store'; -import { getConnectionArgs } from '../datastore/connection'; +import { MIGRATIONS_DIR } from '../../src/datastore/pg-store'; +import { getConnectionArgs } from '../../src/datastore/connection'; export interface GlobalTestEnv { db: PgWriteStore; diff --git a/src/tests-subnets/global-teardown.ts b/tests/subnets/global-teardown.ts similarity index 100% rename from src/tests-subnets/global-teardown.ts rename to tests/subnets/global-teardown.ts diff --git a/src/tests-subnets/l1-contracts/nft-trait.clar b/tests/subnets/l1-contracts/nft-trait.clar similarity index 100% rename from src/tests-subnets/l1-contracts/nft-trait.clar rename to tests/subnets/l1-contracts/nft-trait.clar diff --git a/src/tests-subnets/l1-contracts/simple-ft-l1.clar b/tests/subnets/l1-contracts/simple-ft-l1.clar similarity index 100% rename from src/tests-subnets/l1-contracts/simple-ft-l1.clar rename to tests/subnets/l1-contracts/simple-ft-l1.clar diff --git a/src/tests-subnets/l1-contracts/simple-nft-l1.clar b/tests/subnets/l1-contracts/simple-nft-l1.clar similarity index 100% rename from src/tests-subnets/l1-contracts/simple-nft-l1.clar rename to tests/subnets/l1-contracts/simple-nft-l1.clar diff --git a/src/tests-subnets/l1-contracts/sip-010-trait-ft-standard.clar b/tests/subnets/l1-contracts/sip-010-trait-ft-standard.clar similarity index 100% rename from src/tests-subnets/l1-contracts/sip-010-trait-ft-standard.clar rename to tests/subnets/l1-contracts/sip-010-trait-ft-standard.clar diff --git a/src/tests-subnets/l1-contracts/sip-traits.clar b/tests/subnets/l1-contracts/sip-traits.clar similarity index 100% rename from src/tests-subnets/l1-contracts/sip-traits.clar rename to tests/subnets/l1-contracts/sip-traits.clar diff --git a/src/tests-subnets/l1-contracts/subnet-traits.clar b/tests/subnets/l1-contracts/subnet-traits.clar similarity index 100% rename from src/tests-subnets/l1-contracts/subnet-traits.clar rename to tests/subnets/l1-contracts/subnet-traits.clar diff --git a/src/tests-subnets/l1-contracts/subnet.clar b/tests/subnets/l1-contracts/subnet.clar similarity index 100% rename from src/tests-subnets/l1-contracts/subnet.clar rename to tests/subnets/l1-contracts/subnet.clar diff --git a/src/tests-subnets/l2-contracts/simple-ft-l2.clar b/tests/subnets/l2-contracts/simple-ft-l2.clar similarity index 100% rename from src/tests-subnets/l2-contracts/simple-ft-l2.clar rename to tests/subnets/l2-contracts/simple-ft-l2.clar diff --git a/src/tests-subnets/l2-contracts/simple-nft-l2.clar b/tests/subnets/l2-contracts/simple-nft-l2.clar similarity index 100% rename from src/tests-subnets/l2-contracts/simple-nft-l2.clar rename to tests/subnets/l2-contracts/simple-nft-l2.clar diff --git a/src/tests-subnets/l2-contracts/simple-stx-l2.clar b/tests/subnets/l2-contracts/simple-stx-l2.clar similarity index 100% rename from src/tests-subnets/l2-contracts/simple-stx-l2.clar rename to tests/subnets/l2-contracts/simple-stx-l2.clar diff --git a/src/tests-subnets/set-env.ts b/tests/subnets/set-env.ts similarity index 100% rename from src/tests-subnets/set-env.ts rename to tests/subnets/set-env.ts diff --git a/src/tests-subnets/subnet-tests.ts b/tests/subnets/subnet.test.ts similarity index 99% rename from src/tests-subnets/subnet-tests.ts rename to tests/subnets/subnet.test.ts index 8d3d552133..c478b3756e 100644 --- a/src/tests-subnets/subnet-tests.ts +++ b/tests/subnets/subnet.test.ts @@ -5,7 +5,7 @@ import { standByUntilBlock, standByUntilBurnBlock, testEnv, -} from '../test-utils/test-helpers'; +} from '../utils/test-helpers'; import * as fs from 'fs'; import * as path from 'path'; import { @@ -23,12 +23,15 @@ import { cvToString, noneCV, } from '@stacks/transactions'; -import { StacksCoreRpcClient } from '../core-rpc/client'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; import { StacksTestnet } from '@stacks/network'; import { ClarityTypeID, decodeClarityValue } from 'stacks-encoding-native-js'; import { timeout } from '@hirosystems/api-toolkit'; -import { TransactionEventsResponse, TransactionResults } from '../api/schemas/responses/responses'; -import { ContractCallTransaction } from '../api/schemas/entities/transactions'; +import { + TransactionEventsResponse, + TransactionResults, +} from '../../src/api/schemas/responses/responses'; +import { ContractCallTransaction } from '../../src/api/schemas/entities/transactions'; describe('Subnets tests', () => { let l1Client: StacksCoreRpcClient; diff --git a/src/test-utils/shared-setup.ts b/tests/utils/shared-setup.ts similarity index 90% rename from src/test-utils/shared-setup.ts rename to tests/utils/shared-setup.ts index 8b20d20601..098b236294 100644 --- a/src/test-utils/shared-setup.ts +++ b/tests/utils/shared-setup.ts @@ -1,11 +1,11 @@ -import { StacksCoreRpcClient } from '../core-rpc/client'; -import { loadDotEnv } from '../helpers'; -import { PgWriteStore } from '../datastore/pg-write-store'; +import { StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { loadDotEnv } from '../../src/helpers'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; import { DummyEventMessageHandler, EventStreamServer, startEventServer, -} from '../event-stream/event-server'; +} from '../../src/event-stream/event-server'; import { ChainID } from '@stacks/common'; import * as isCI from 'is-ci'; import { migrate } from './test-helpers'; diff --git a/src/test-utils/test-builders.ts b/tests/utils/test-builders.ts similarity index 99% rename from src/test-utils/test-builders.ts rename to tests/utils/test-builders.ts index 220c2496fd..99a742f520 100644 --- a/src/test-utils/test-builders.ts +++ b/tests/utils/test-builders.ts @@ -27,9 +27,9 @@ import { DbTxRaw, DbTxStatus, DbTxTypeId, -} from '../datastore/common'; +} from '../../src/datastore/common'; import { bufferCV, bufferCVFromString, serializeCV, uintCV } from '@stacks/transactions'; -import { createClarityValueArray } from '../stacks-encoding-helpers'; +import { createClarityValueArray } from '../../src/stacks-encoding-helpers'; import { bufferToHex } from '@hirosystems/api-toolkit'; // Default values when none given. Useful when they are irrelevant for a particular test. diff --git a/src/test-utils/test-helpers.ts b/tests/utils/test-helpers.ts similarity index 95% rename from src/test-utils/test-helpers.ts rename to tests/utils/test-helpers.ts index 3150e33414..519dbba992 100644 --- a/src/test-utils/test-helpers.ts +++ b/tests/utils/test-helpers.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { bytesToHex, hexToBytes } from '@stacks/common'; +import { bytesToHex } from '@stacks/common'; import { StacksNetwork } from '@stacks/network'; -import { decodeBtcAddress, poxAddressToBtcAddress } from '@stacks/stacking'; +import { decodeBtcAddress } from '@stacks/stacking'; import { NetworkIdentifier, RosettaAccountBalanceRequest, @@ -17,7 +17,7 @@ import { RosettaConstructionSubmitRequest, RosettaConstructionSubmitResponse, RosettaOperation, -} from '../rosetta/types'; +} from '../../src/rosetta/types'; import { bufferCV, ChainID, @@ -31,28 +31,25 @@ import { tupleCV, } from '@stacks/transactions'; import { RPCClient } from 'rpc-bitcoin'; -import { getRosettaNetworkName, RosettaConstants } from '../api/rosetta-constants'; +import { getRosettaNetworkName, RosettaConstants } from '../../src/api/rosetta-constants'; import { ClarityTypeID, ClarityValue as NativeClarityValue, - ClarityValueBuffer, - ClarityValueTuple, decodeClarityValue, } from 'stacks-encoding-native-js'; import * as supertest from 'supertest'; -import { ApiServer } from '../api/init'; -import { testnetKeys } from '../api/routes/debug'; -import { CoreRpcPoxInfo, StacksCoreRpcClient } from '../core-rpc/client'; -import { DbBlock, DbTx, DbTxStatus } from '../datastore/common'; -import { PgWriteStore } from '../datastore/pg-write-store'; -import { BitcoinAddressFormat, ECPair, getBitcoinAddressFromKey } from '../ec-helpers'; -import { b58ToC32 } from 'c32check'; -import { coerceToBuffer, hexToBuffer, runMigrations, timeout } from '@hirosystems/api-toolkit'; -import { MIGRATIONS_DIR } from '../datastore/pg-store'; -import { getConnectionArgs } from '../datastore/connection'; -import { AddressStxBalance } from '../api/schemas/entities/addresses'; -import { ServerStatusResponse } from '../api/schemas/responses/responses'; +import { ApiServer } from '../../src/api/init'; +import { testnetKeys } from '../../src/api/routes/debug'; +import { CoreRpcPoxInfo, StacksCoreRpcClient } from '../../src/core-rpc/client'; +import { DbBlock, DbTx, DbTxStatus } from '../../src/datastore/common'; +import { PgWriteStore } from '../../src/datastore/pg-write-store'; +import { BitcoinAddressFormat, ECPair, getBitcoinAddressFromKey } from '../../src/ec-helpers'; +import { coerceToBuffer, runMigrations, timeout } from '@hirosystems/api-toolkit'; +import { MIGRATIONS_DIR } from '../../src/datastore/pg-store'; +import { getConnectionArgs } from '../../src/datastore/connection'; +import { AddressStxBalance } from '../../src/api/schemas/entities/addresses'; +import { ServerStatusResponse } from '../../src/api/schemas/responses/responses'; export async function migrate(direction: 'up' | 'down') { await runMigrations(MIGRATIONS_DIR, direction, getConnectionArgs()); diff --git a/tsconfig.build.json b/tsconfig.build.json index c359f57714..cd551589ae 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -15,5 +15,5 @@ "baseUrl": "." }, "include": ["src/**/*"], - "exclude": ["lib", "node_modules", "src/tests*"] + "exclude": ["lib", "node_modules", "tests/**"] } diff --git a/tsconfig.json b/tsconfig.json index bfe29707ce..682058eecf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,11 +13,8 @@ "outDir": "lib", "noEmit": true, "baseUrl": ".", - "typeRoots": [ - "./src/@types", - "./node_modules/@types" - ] + "typeRoots": ["./src/@types", "./node_modules/@types"] }, - "include": ["src/**/*"], + "include": ["src/**/*", "tests/**/*"], "exclude": ["lib", "node_modules"] }