Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

PoX-4 tests #1762

Merged
merged 10 commits into from
Dec 12, 2023
Merged
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,24 +520,24 @@ jobs:
flag-name: run-${{ github.job }}
parallel: true

test-2_4:
test-2_5:
strategy:
fail-fast: false
matrix:
suite:
[
block-zero-handling,
faucet-stx,
pox-3-btc-address-formats,
pox-3-delegate-aggregation,
pox-3-delegate-stacking,
pox-3-delegate-revoked-stacking,
pox-3-stack-extend-increase,
pox-3-rosetta-btc-addr-types,
pox-3-rosetta-cycle-phases,
pox-3-rosetta-segwit,
pox-3-burnchain-stack-stx,
pox-3-burnchain-delegate-stx,
pox-4-btc-address-formats,
pox-4-delegate-aggregation,
pox-4-delegate-stacking,
pox-4-delegate-revoked-stacking,
pox-4-stack-extend-increase,
pox-4-rosetta-btc-addr-types,
pox-4-rosetta-cycle-phases,
pox-4-rosetta-segwit,
pox-4-burnchain-stack-stx,
pox-4-burnchain-delegate-stx,
]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -575,7 +575,7 @@ jobs:
npm run devenv:logs-krypton -- --no-color &> docker-compose-logs.txt &

- name: Run tests
run: npm run test:2.4 -- --testPathPattern "${{ matrix.suite }}"
run: npm run test:2.5 -- --testPathPattern "${{ matrix.suite }}"

- name: Print integration environment logs
run: cat docker-compose-logs.txt
Expand Down Expand Up @@ -855,7 +855,7 @@ jobs:
- lint
- lint-docs
- test
- test-2_4
- test-2_5
- test-bns
- test-rosetta
- test-rosetta-cli-construction
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@
{
"type": "node",
"request": "launch",
"name": "Jest: 2.4",
"name": "Jest: 2.5",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--testTimeout=3600000",
"--runInBand",
"--no-cache",
"--config",
"${workspaceRoot}/tests/jest.config.2.4.js"
"${workspaceRoot}/tests/jest.config.2.5.js",
],
"outputCapture": "std",
"console": "integratedTerminal",
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.dev.stacks-blockchain.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
stacks-blockchain:
image: "hirosystems/stacks-api-e2e:stacks2.4-f930deb"
image: "hirosystems/stacks-api-e2e:stacks3.0-800259e"
restart: on-failure
environment:
STACKS_EVENT_OBSERVER: host.docker.internal:3700
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.dev.stacks-krypton.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
stacks-blockchain:
image: "hirosystems/stacks-api-e2e:stacks2.4-f930deb"
image: "hirosystems/stacks-api-e2e:stacks3.0-800259e"
ports:
- "18443:18443" # bitcoin regtest JSON-RPC interface
- "18444:18444" # bitcoin regtest p2p
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"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.4": "cross-env NODE_ENV=test jest --config ./tests/jest.config.2.4.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",
Expand All @@ -24,7 +24,7 @@
"test:watch": "cross-env NODE_ENV=test jest --config ./tests/jest.config.js --watch",
"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.4": "concurrently --hide \"devenv:deploy-krypton\" \"npm:devenv:deploy-krypton\" \"cross-env NODE_ENV=test jest --config ./tests/jest.config.2.4.js --no-cache --runInBand; npm run devenv:stop-krypton\"",
"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\"",
"test:integration:rosetta": "concurrently \"npm:devenv:deploy-krypton\" \"cross-env NODE_ENV=test jest --config ./tests/jest.config.rosetta.js --no-cache --runInBand; npm run devenv:stop-krypton\"",
"test:integration:rosetta-construction": "concurrently \"npm:devenv:deploy-krypton\" \"cross-env NODE_ENV=test jest --config ./tests/jest.config.rosetta-construction.js --no-cache --runInBand; npm run devenv:stop-krypton\"",
"test:integration:rosetta-cli:data": "concurrently \"npm:devenv:deploy-krypton\" \"cross-env NODE_ENV=test STACKS_CHAIN_ID=0x80000000 jest --config ./tests/jest.config.rosetta-cli-data.js --no-cache --runInBand; npm run devenv:stop-krypton\"",
Expand Down
3 changes: 2 additions & 1 deletion src/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ export async function startApiServer(opts: {
const legacyPoxPathRouter: express.RequestHandler = (req, res) => {
// Redirect old pox routes paths to new one above
const newPath = req.path === '/' ? '/events' : req.path;
const baseUrl = req.baseUrl.replace(/(pox[23])_events/, '$1');
const baseUrl = req.baseUrl.replace(/(pox[\d])_events/, '$1');
const redirectPath = `${baseUrl}${newPath}${getReqQuery(req)}`;
return res.redirect(redirectPath);
};
router.use('/pox2_events', legacyPoxPathRouter);
router.use('/pox3_events', legacyPoxPathRouter);
router.use('/pox4_events', legacyPoxPathRouter);

if (getChainIDNetwork(chainId) === 'testnet' && writeDatastore) {
router.use('/faucets', createFaucetRouter(writeDatastore));
Expand Down
6 changes: 5 additions & 1 deletion src/api/routes/faucets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ export function createFaucetRouter(db: PgWriteStore): express.Router {
try {
return await makeSTXTokenTransfer(txOpts);
} catch (error: any) {
if (fee === undefined && (error as Error).message?.includes('NoEstimateAvailable')) {
if (
fee === undefined &&
(error as Error).message &&
/estimating transaction fee|NoEstimateAvailable/.test(error.message)
) {
const defaultFee = 200n;
return await generateTx(network, nonce, defaultFee);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test-utils/shared-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ async function standByForPoxToBeReady(client: StacksCoreRpcClient): Promise<void
try {
tries++;
const poxInfo = await client.getPox();
if (!poxInfo.contract_id.includes('pox-3')) {
if (!poxInfo.contract_id.includes('pox-4')) {
throw new Error(`Unexpected PoX version: ${poxInfo.contract_id}`);
}
break;
} catch (error) {
console.log(`Waiting on PoX-3 to be ready, retrying after ${error}`);
console.log(`Waiting on PoX-4 to be ready, retrying after ${error}`);
await timeout(500);
}
}
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/tests-2.4/global-setup.ts → src/tests-2.5/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export interface GlobalTestEnv {
eventServer: EventStreamServer;
}

async function standByForPox3ToBeReady(client: StacksCoreRpcClient): Promise<void> {
async function standByForPox4ToBeReady(client: StacksCoreRpcClient): Promise<void> {
let tries = 0;
while (true) {
try {
tries++;
const poxInfo = await client.getPox();
if (poxInfo.contract_id.includes('pox-3')) {
console.log(`PoX-3 ready.`);
if (poxInfo.contract_id.includes('pox-4')) {
console.log(`PoX-4 ready.`);
return;
}
console.log(`Waiting on PoX-3 to be ready`);
console.log(`Waiting on PoX-4 to be ready`);
await timeout(500);
} catch (error) {
console.log(`Waiting on PoX-3 to be ready, retrying after ${error}`);
console.log(`Waiting on PoX-4 to be ready, retrying after ${error}`);
await timeout(500);
}
}
Expand All @@ -45,7 +45,7 @@ export default async (): Promise<void> => {
const eventServer = await startEventServer({ datastore: db, chainId: ChainID.Testnet });

const client = new StacksCoreRpcClient();
await standByForPox3ToBeReady(client);
await standByForPox4ToBeReady(client);

const testEnv: GlobalTestEnv = {
db: db,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import {
} from '../test-utils/test-helpers';
import { hexToBuffer } from '@hirosystems/api-toolkit';

describe('PoX-3 - Stack using supported bitcoin address formats', () => {
describe('PoX-4 - Stack using supported bitcoin address formats', () => {
test('Standby for next cycle', async () => {
const poxInfo = await testEnv.client.getPox();
await standByUntilBurnBlock(poxInfo.next_cycle.reward_phase_start_block_height); // a good time to stack
});

describe('PoX-3 - Stacking operations P2SH-P2WPKH', () => {
describe('PoX-4 - Stacking operations P2SH-P2WPKH', () => {
const account = testnetKeys[1];
let btcAddr: string;
let btcRegtestAccount: VerboseKeyOutput;
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
cycleBlockLength = cycleCount * poxInfo.reward_cycle_length;

[contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('stack-stx tx', async () => {
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
});
});

describe('PoX-3 - Stacking operations P2WPKH', () => {
describe('PoX-4 - Stacking operations P2WPKH', () => {
const account = testnetKeys[1];
let btcAddr: string;
let btcRegtestAddr: string;
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
cycleBlockLength = cycleCount * poxInfo.reward_cycle_length;

[contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('stack-stx tx', async () => {
Expand Down Expand Up @@ -524,7 +524,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
});
});

describe('PoX-3 - Stacking operations P2WSH', () => {
describe('PoX-4 - Stacking operations P2WSH', () => {
const account = testnetKeys[1];
let btcAddr: string;
let btcRegtestAddr: string;
Expand Down Expand Up @@ -584,7 +584,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
cycleBlockLength = cycleCount * poxInfo.reward_cycle_length;

[contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('stack-stx tx', async () => {
Expand Down Expand Up @@ -776,7 +776,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
});
});

describe('PoX-3 - Stacking operations P2TR', () => {
describe('PoX-4 - Stacking operations P2TR', () => {
const account = testnetKeys[2];
let btcAddr: string;
let btcRegtestAddr: string;
Expand Down Expand Up @@ -836,7 +836,7 @@ describe('PoX-3 - Stack using supported bitcoin address formats', () => {
cycleBlockLength = cycleCount * poxInfo.reward_cycle_length;

[contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('stack-stx tx', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async function createPox2DelegateStx(args: {
};
}

describe('PoX-3 - Stack using Bitcoin-chain ops', () => {
describe('PoX-4 - Stack using Bitcoin-chain ops', () => {
const seedAccount = testnetKeys[0];

let db: PgWriteStore;
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('PoX-3 - Stack using Bitcoin-chain ops', () => {

const poxInfo = await client.getPox();
const [contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('Fund STX to new account for testing', async () => {
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('PoX-3 - Stack using Bitcoin-chain ops', () => {

test('Ensure delegate-stx BitcoinOp parsed', async () => {
const pox2Txs = await supertest(api.server)
.get(`/extended/v1/address/${BootContractAddress.testnet}.pox-3/transactions`)
.get(`/extended/v1/address/${BootContractAddress.testnet}.pox-4/transactions`)
.expect(200);
const delegateStxTxResp = await supertest(api.server)
.get(`/extended/v1/tx/${pox2Txs.body.results[0].tx_id}`)
Expand All @@ -351,7 +351,7 @@ describe('PoX-3 - Stack using Bitcoin-chain ops', () => {
)})))`;

expect(delegateStxTx.contract_call).toEqual({
contract_id: 'ST000000000000000000002AMW42H.pox-3',
contract_id: 'ST000000000000000000002AMW42H.pox-4',
function_name: 'delegate-stx',
function_signature:
'(define-public (delegate-stx (amount-ustx uint) (delegate-to principal) (until-burn-ht (optional uint)) (pox-addr (optional (tuple (hashbytes (buff 32)) (version (buff 1)))))))',
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('PoX-3 - Stack using Bitcoin-chain ops', () => {
expect(coreBalanceInfo.unlock_height).toBeGreaterThan(0);

// validate delegate-stack-stx pox2 event for this tx
const res: any = await fetchGet(`/extended/v1/pox3_events/tx/${delegateStackStxTxId}`);
const res: any = await fetchGet(`/extended/v1/pox4_events/tx/${delegateStackStxTxId}`);
expect(res).toBeDefined();
expect(res.results).toHaveLength(1);
expect(res.results[0]).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function createPox2StackStx(args: {
};
}

describe('PoX-3 - Stack using Bitcoin-chain ops', () => {
describe('PoX-4 - Stack using Bitcoin-chain ops', () => {
const seedAccount = testnetKeys[0];

let db: PgWriteStore;
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('PoX-3 - Stack using Bitcoin-chain ops', () => {

const poxInfo = await client.getPox();
const [contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('Fund STX to new account for testing', async () => {
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('PoX-3 - Stack using Bitcoin-chain ops', () => {
expect(txObj.tx_type).toBe('contract_call');
expect(txObj.tx_status).toBe('success');
expect(txObj.sender_address).toBe(account.stxAddr);
expect(txObj.contract_call.contract_id).toBe(`${BootContractAddress.testnet}.pox-3`);
expect(txObj.contract_call.contract_id).toBe(`${BootContractAddress.testnet}.pox-4`);
expect(txObj.contract_call.function_name).toBe('stack-stx');

const callArg1 = txObj.contract_call.function_args![0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from 'stacks-encoding-native-js';
import { AddressStxBalanceResponse } from '@stacks/stacks-blockchain-api-types';

describe('PoX-3 - Delegate aggregation increase operations', () => {
describe('PoX-4 - Delegate aggregation increase operations', () => {
const seedKey = testnetKeys[4].secretKey;
const delegatorKey = '04608922f3ce63971bb120fa9c9454c5bd06370f61414040a737a6ee8ef8a10f01';
const delegateeKey = 'b038e143cf4ee4c079b3c3605a8ed28732e5745c138b728408e80faf7a59b8c201';
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('PoX-3 - Delegate aggregation increase operations', () => {
// wait until the start of the next cycle so we have enough blocks within the cycle to perform the various txs
poxInfo = await standByForNextPoxCycle();
[contractAddress, contractName] = poxInfo.contract_id.split('.');
expect(contractName).toBe('pox-3');
expect(contractName).toBe('pox-4');
});

test('Perform delegate-stx operation', async () => {
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('PoX-3 - Delegate aggregation increase operations', () => {

// validate pool delegations
const stackersRes: any = await fetchGet(
`/extended/beta/stacking/${delegatorAccount.stxAddr}/delegations`
`/extended/v1/pox4/${delegatorAccount.stxAddr}/delegations`
);
expect(stackersRes).toBeDefined();
expect(stackersRes.total).toBe(1);
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('PoX-3 - Delegate aggregation increase operations', () => {
expect(coreBalanceInfo.unlock_height).toBeGreaterThan(0);

// validate delegate-stack-stx pox2 event for this tx
const res: any = await fetchGet(`/extended/v1/pox3_events/tx/${delegateStackStxTxId}`);
const res: any = await fetchGet(`/extended/v1/pox4_events/tx/${delegateStackStxTxId}`);
expect(res).toBeDefined();
expect(res.results).toHaveLength(1);
expect(res.results[0]).toEqual(
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('PoX-3 - Delegate aggregation increase operations', () => {
expect(poxCycleAddressIndex).toEqual(0n);

// validate stack-aggregation-commit pox2 event for this tx
const res: any = await fetchGet(`/extended/v1/pox3_events/tx/${stackAggrCommitTxId}`);
const res: any = await fetchGet(`/extended/v1/pox4_events/tx/${stackAggrCommitTxId}`);
expect(res).toBeDefined();
expect(res.results).toHaveLength(1);
expect(res.results[0]).toEqual(
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('PoX-3 - Delegate aggregation increase operations', () => {

// validate delegate-stack-stx pox2 event for this tx
const delegateStackIncreasePoxEvents: any = await fetchGet(
`/extended/v1/pox3_events/tx/${delegateStackIncreaseDbTx.tx_id}`
`/extended/v1/pox4_events/tx/${delegateStackIncreaseDbTx.tx_id}`
);
expect(delegateStackIncreasePoxEvents).toBeDefined();
expect(delegateStackIncreasePoxEvents.results).toHaveLength(1);
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('PoX-3 - Delegate aggregation increase operations', () => {

// validate stack-aggregation-commit pox2 event for this tx
const stackAggreIncreasePoxEvents: any = await fetchGet(
`/extended/v1/pox3_events/tx/${stackAggrIncreaseTxId}`
`/extended/v1/pox4_events/tx/${stackAggrIncreaseTxId}`
);
expect(stackAggreIncreasePoxEvents).toBeDefined();
expect(stackAggreIncreasePoxEvents.results).toHaveLength(1);
Expand Down
Loading
Loading