diff --git a/src/test-utils/test-helpers.ts b/src/test-utils/test-helpers.ts index c36838963e..05a1ef8163 100644 --- a/src/test-utils/test-helpers.ts +++ b/src/test-utils/test-helpers.ts @@ -54,9 +54,6 @@ import { coerceToBuffer, hexToBuffer, runMigrations, timeout } from '@hirosystem import { MIGRATIONS_DIR } from '../datastore/pg-store'; import { getConnectionArgs } from '../datastore/connection'; -/** A (buff 33) signer key of all zeroes, to be used for testing */ -export const ZERO_SIGNER_KEY_BYTES = hexToBytes('00'.repeat(33)); - export async function migrate(direction: 'up' | 'down') { await runMigrations(MIGRATIONS_DIR, direction, getConnectionArgs()); } @@ -137,6 +134,7 @@ export function accountFromKey( return { secretKey, pubKey, stxAddr, poxAddr, poxAddrClar, btcAddr, btcTestnetAddr, wif }; } +/** Stand by until prepare phase of next pox cycle (still in current cycle) */ export async function standByForNextPoxCycle(): Promise { const firstPoxInfo = await testEnv.client.getPox(); await standByUntilBurnBlock(firstPoxInfo.next_cycle.prepare_phase_start_block_height); @@ -151,6 +149,7 @@ export async function standByForNextPoxCycle(): Promise { return lastPoxInfo; } +/** Stand by until `current_cycle.id` increases */ export async function standByForPoxCycle( apiArg?: ApiServer, clientArg?: StacksCoreRpcClient diff --git a/src/tests-2.5/pox-4-btc-address-formats.ts b/src/tests-2.5/pox-4-btc-address-formats.ts index 5483f37099..b0133095b0 100644 --- a/src/tests-2.5/pox-4-btc-address-formats.ts +++ b/src/tests-2.5/pox-4-btc-address-formats.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { hexToBuffer } from '@hirosystems/api-toolkit'; -import { hexToBytes } from '@stacks/common'; import { decodeBtcAddress } from '@stacks/stacking'; import { AddressStxBalanceResponse, @@ -8,77 +7,71 @@ import { BurnchainRewardSlotHolderListResponse, BurnchainRewardsTotal, } from '@stacks/stacks-blockchain-api-types'; -import { AnchorMode, bufferCV, makeContractCall, tupleCV, uintCV } from '@stacks/transactions'; +import { + AnchorMode, + bufferCV, + makeContractCall, + randomBytes, + tupleCV, + 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 { VerboseKeyOutput, getBitcoinAddressFromKey, privateToPublicKey } from '../ec-helpers'; +import { getBitcoinAddressFromKey, privateToPublicKey } from '../ec-helpers'; import { fetchGet, - standByForNextPoxCycle, + standByForPoxCycle, standByForTxSuccess, standByUntilBurnBlock, testEnv, } from '../test-utils/test-helpers'; -describe('PoX-4 - Stack using supported bitcoin address formats', () => { - let poxInfo: CoreRpcPoxInfo; - let burnBlockHeight: number; - let cycleBlockLength: number; - let contractAddress: string; - let contractName: string; - let ustxAmount: bigint; - const cycleCount = 1; - const btcPrivateKey = '0000000000000000000000000000000000000000000000000000000000000002'; - - describe('PoX-4 - Stacking operations P2SH-P2WPKH', () => { - const account = testnetKeys[1]; - let btcAddr: string; - let btcAddrDecoded: { version: number; data: Uint8Array }; - let btcAddrRegtest: VerboseKeyOutput; - let btcPubKey: string; - - test('P2SH-P2WPKH setup', async () => { - btcAddr = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'testnet', - addressFormat: 'p2sh-p2wpkh', - }); - expect(btcAddr).toBe('2N74VLxyT79VGHiBK2zEg3a9HJG7rEc5F3o'); - btcPubKey = privateToPublicKey(btcPrivateKey).toString('hex'); - expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); - - btcAddrDecoded = decodeBtcAddress(btcAddr); - expect({ - data: Buffer.from(btcAddrDecoded.data).toString('hex'), - version: btcAddrDecoded.version, - }).toEqual({ data: '978a0121f9a24de65a13bab0c43c3a48be074eae', version: 1 }); - - // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses - btcAddrRegtest = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'regtest', - addressFormat: 'p2sh-p2wpkh', - verbose: true, - }); - expect(btcAddrRegtest.address).toBe('2N74VLxyT79VGHiBK2zEg3a9HJG7rEc5F3o'); +const BTC_PRIVATE_KEY = '0000000000000000000000000000000000000000000000000000000000000002'; - await testEnv.bitcoinRpcClient.importaddress({ - address: btcAddrRegtest.address, - label: btcAddrRegtest.address, - }); - // await testEnv.bitcoinRpcClient.importprivkey({ - // privkey: btcAddrRegtest.wif, - // label: btcAddrRegtest.address, - // rescan: false, - // }); - const btcWalletAddrs = await testEnv.bitcoinRpcClient.getaddressesbylabel({ - label: btcAddrRegtest.address, - }); - expect(Object.keys(btcWalletAddrs)).toContain(btcAddrRegtest.address); +describe.each([P2SH_P2WPKH, P2WPKH, P2WSH, P2TR])( + 'PoX-4 - Stack using bitcoin address %p', + addressSetup => { + const account = testnetKeys[1]; - await standByForNextPoxCycle(); + let poxInfo: CoreRpcPoxInfo; + let burnBlockHeight: number; + let cycleBlockLength: number; + let contractAddress: string; + let contractName: string; + let ustxAmount: bigint; + const cycleCount = 1; + + const { btcAddr, btcAddrDecoded, btcAddrRegtest, btcDescriptor } = addressSetup(); + + test('prepare', async () => { + await standByForPoxCycle(); + + try { + // legacy wallets + await testEnv.bitcoinRpcClient.importaddress({ + address: btcAddrRegtest, + label: btcAddrRegtest, + }); + const btcWalletAddrs = await testEnv.bitcoinRpcClient.getaddressesbylabel({ + label: btcAddrRegtest, + }); + expect(Object.keys(btcWalletAddrs)).toContain(btcAddrRegtest); + } catch (e) { + // descriptor wallets, if legacy wallet import fails + await withDescriptorWallet(async walletName => { + const info = await testEnv.bitcoinRpcClient.getdescriptorinfo({ + descriptor: btcDescriptor!, + }); + const request = { label: btcAddrRegtest, desc: info.descriptor, timestamp: 'now' }; + await testEnv.bitcoinRpcClient.rpc( + 'importdescriptors', + { requests: [request] }, + walletName + ); + }); + } poxInfo = await testEnv.client.getPox(); @@ -105,7 +98,7 @@ describe('PoX-4 - Stack using supported bitcoin address formats', () => { }), // pox-addr uintCV(burnBlockHeight), // start-burn-ht uintCV(cycleCount), // lock-period - bufferCV(hexToBytes('1'.padStart(66, '0'))), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, @@ -189,245 +182,6 @@ describe('PoX-4 - Stack using supported bitcoin address formats', () => { expect(rewardSlotHolders.results[0].burn_block_height).toBeLessThanOrEqual(slotEnd); }); - test('stacking rewards - BTC JSON-RPC', async () => { - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - const blockResult: { - tx: { vout?: { scriptPubKey: { address?: string }; value?: number }[] }[]; - } = await testEnv.bitcoinRpcClient.getblock({ - blockhash: hexToBuffer(firstReward.burn_block_hash).toString('hex'), - verbosity: 2, - }); - const vout = blockResult.tx - .flatMap(t => t.vout) - .find(v => v?.value && v.scriptPubKey.address == btcAddrRegtest.address); - if (!vout?.value) { - throw new Error( - `Could not find bitcoin vout for ${btcAddrRegtest.address} in block ${firstReward.burn_block_hash}` - ); - } - const sats = new bignumber(vout.value).shiftedBy(8).toString(); - expect(sats).toBe(firstReward.reward_amount); - }); - - test('stacking rewards - BTC JSON-RPC - listtransactions', async () => { - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - - let received: { - address: string; - category: string; - amount: number; - blockhash: string; - blockheight: number; - }[] = await testEnv.bitcoinRpcClient.listtransactions({ - label: btcAddrRegtest.address, - include_watchonly: true, - }); - received = received.filter(r => r.address === btcAddrRegtest.address); - expect(received.length).toBe(1); - expect(received[0].category).toBe('receive'); - expect(received[0].blockhash).toBe(hexToBuffer(firstReward.burn_block_hash).toString('hex')); - const sats = new bignumber(received[0].amount).shiftedBy(8).toString(); - expect(sats).toBe(firstReward.reward_amount); - }); - - test('stx unlocked - RPC balance endpoint', async () => { - // Wait until account has unlocked (finished Stacking cycles) - const rpcAccountInfo1 = await testEnv.client.getAccount(account.stacksAddress); - const burnBlockUnlockHeight = rpcAccountInfo1.unlock_height + 1; - await standByUntilBurnBlock(burnBlockUnlockHeight); - - // Check that STX are no longer reported as locked by the RPC endpoints: - const rpcAccountInfo = await testEnv.client.getAccount(account.stacksAddress); - expect(BigInt(rpcAccountInfo.locked)).toBe(0n); - expect(rpcAccountInfo.unlock_height).toBe(0); - }); - - test('stx unlocked - API balance endpoint', async () => { - // Check that STX are no longer reported as locked by the API endpoints: - const addrBalance = await fetchGet( - `/extended/v1/address/${account.stacksAddress}/stx` - ); - expect(BigInt(addrBalance.locked)).toBe(0n); - expect(addrBalance.burnchain_unlock_height).toBe(0); - expect(addrBalance.lock_height).toBe(0); - expect(addrBalance.lock_tx_id).toBe(''); - }); - - test('BTC stacking reward received', async () => { - const received: number = await testEnv.bitcoinRpcClient.getreceivedbyaddress({ - address: btcAddrRegtest.address, - minconf: 0, - }); - expect(received).toBeGreaterThan(0); - }); - }); - - describe('PoX-4 - Stacking operations P2WPKH', () => { - const account = testnetKeys[1]; - let btcAddr: string; - let btcAddrDecoded: { version: number; data: Uint8Array }; - let btcPubKey: string; - let btcAddrRegtest: string; - - test('P2WPKH setup', async () => { - btcAddr = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'testnet', - addressFormat: 'p2wpkh', - }); - expect(btcAddr).toBe('tb1qq6hag67dl53wl99vzg42z8eyzfz2xlkvvlryfj'); - btcPubKey = privateToPublicKey(btcPrivateKey).toString('hex'); - expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); - - btcAddrDecoded = decodeBtcAddress(btcAddr); - expect({ - data: Buffer.from(btcAddrDecoded.data).toString('hex'), - version: btcAddrDecoded.version, - }).toEqual({ data: '06afd46bcdfd22ef94ac122aa11f241244a37ecc', version: 4 }); - - // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses - btcAddrRegtest = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'regtest', - addressFormat: 'p2wpkh', - }); - expect(btcAddrRegtest).toBe('bcrt1qq6hag67dl53wl99vzg42z8eyzfz2xlkvwk6f7m'); - - await testEnv.bitcoinRpcClient.importaddress({ - address: btcAddrRegtest, - label: btcAddrRegtest, - }); - const btcWalletAddrs = await testEnv.bitcoinRpcClient.getaddressesbylabel({ - label: btcAddrRegtest, - }); - expect(Object.keys(btcWalletAddrs)).toContain(btcAddrRegtest); - - // If we're close to or in the prepare phase, wait until until the start of the next cycle - // if ((await testEnv.client.getPox()).next_cycle.blocks_until_prepare_phase <= 20) { - if (true) { - await standByForNextPoxCycle(); - } - - poxInfo = await testEnv.client.getPox(); - - burnBlockHeight = poxInfo.current_burnchain_block_height as number; - ustxAmount = BigInt(Math.round(Number(poxInfo.min_amount_ustx) * 1.1).toString()); - cycleBlockLength = cycleCount * poxInfo.reward_cycle_length; - [contractAddress, contractName] = poxInfo.contract_id.split('.'); - - expect(contractName).toBe('pox-4'); - }); - - test('stack-stx tx', async () => { - // Create and broadcast a `stack-stx` tx - const tx1 = await makeContractCall({ - senderKey: account.secretKey, - contractAddress, - contractName, - functionName: 'stack-stx', - functionArgs: [ - uintCV(ustxAmount.toString()), // amount-ustx - tupleCV({ - hashbytes: bufferCV(btcAddrDecoded.data), - version: bufferCV(Buffer.from([btcAddrDecoded.version])), - }), // pox-addr - uintCV(burnBlockHeight), // start-burn-ht - uintCV(cycleCount), // lock-period - bufferCV(hexToBytes('2'.padStart(66, '0'))), // signer-key - ], - network: testEnv.stacksNetwork, - anchorMode: AnchorMode.OnChainOnly, - fee: 10000, - validateWithAbi: false, - }); - const expectedTxId1 = '0x' + tx1.txid(); - const sendResult1 = await testEnv.client.sendTransaction(Buffer.from(tx1.serialize())); - expect(sendResult1.txId).toBe(expectedTxId1); - - // Wait for API to receive and ingest tx - const dbTx1 = await standByForTxSuccess(expectedTxId1); - - const tx1Events = await testEnv.api.datastore.getTxEvents({ - txId: expectedTxId1, - indexBlockHash: dbTx1.index_block_hash, - limit: 99999, - offset: 0, - }); - expect(tx1Events.results).toBeTruthy(); - const lockEvent1 = tx1Events.results.find( - r => r.event_type === DbEventTypeId.StxLock - ) as DbStxLockEvent; - expect(lockEvent1).toBeDefined(); - expect(lockEvent1.locked_address).toBe(account.stacksAddress); - expect(lockEvent1.locked_amount).toBe(ustxAmount); - - // Test that the unlock height event data in the API db matches the expected height from the - // calculated values from the /v2/pox data and the cycle count specified in the `stack-stx` tx. - const expectedUnlockHeight1 = - cycleBlockLength + poxInfo.next_cycle.reward_phase_start_block_height; - expect(lockEvent1.unlock_height).toBe(expectedUnlockHeight1); - - // Test the API address balance data after a `stack-stx` operation - const addrBalance1 = await fetchGet( - `/extended/v1/address/${account.stacksAddress}/stx` - ); - expect(addrBalance1.locked).toBe(ustxAmount.toString()); - expect(addrBalance1.burnchain_unlock_height).toBe(expectedUnlockHeight1); - expect(addrBalance1.lock_height).toBe(dbTx1.block_height); - expect(addrBalance1.lock_tx_id).toBe(dbTx1.tx_id); - }); - - test('stacking rewards - API /burnchain/reward_slot_holders', async () => { - const prepareStart = poxInfo.next_cycle.prepare_phase_start_block_height; - const prepareEnd = prepareStart + poxInfo.prepare_phase_block_length; - - await standByUntilBurnBlock(prepareEnd + 1); - - const rewardSlotHolders = await fetchGet( - `/extended/v1/burnchain/reward_slot_holders/${btcAddr}` - ); - expect(rewardSlotHolders.total).toBe(1); - expect(rewardSlotHolders.results[0].address).toBe(btcAddr); - expect(rewardSlotHolders.results[0].burn_block_height).toBeGreaterThanOrEqual(prepareStart); - expect(rewardSlotHolders.results[0].burn_block_height).toBeLessThanOrEqual(prepareEnd); - }); - - test('stacking rewards - API /burnchain/rewards', async () => { - await standByUntilBurnBlock(poxInfo.next_cycle.reward_phase_start_block_height + 2); - - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - expect(rewards.results.length).toBe(1); - expect(firstReward.reward_recipient).toBe(btcAddr); - expect(Number(firstReward.burn_amount)).toBeGreaterThan(0); - expect(firstReward.burn_block_height).toBeGreaterThanOrEqual( - poxInfo.next_cycle.reward_phase_start_block_height - ); - expect(firstReward.burn_block_height).toBeLessThanOrEqual( - poxInfo.next_cycle.reward_phase_start_block_height + 2 - ); - - const rewardsTotal = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}/total` - ); - expect(rewardsTotal.reward_recipient).toBe(btcAddr); - expect(Number(rewardsTotal.reward_amount)).toBeGreaterThan(0); - }); - test('stacking rewards - BTC JSON-RPC', async () => { const rewards = await fetchGet( `/extended/v1/burnchain/rewards/${btcAddr}` @@ -444,7 +198,7 @@ describe('PoX-4 - Stack using supported bitcoin address formats', () => { const vout = blockResult.tx .flatMap(t => t.vout) .find(v => v?.value && v.scriptPubKey.address == btcAddrRegtest); - if (!vout || !vout.value) { + if (!vout?.value) { throw new Error( `Could not find bitcoin vout for ${btcAddrRegtest} in block ${firstReward.burn_block_hash}` ); @@ -461,23 +215,27 @@ describe('PoX-4 - Stack using supported bitcoin address formats', () => { (a, b) => a.burn_block_height - b.burn_block_height )[0]; - let received: { - address: string; - category: string; - amount: number; - blockhash: string; - blockheight: number; - txid: string; - confirmations: number; - }[] = await testEnv.bitcoinRpcClient.listtransactions({ - label: btcAddrRegtest, - include_watchonly: true, - }); - received = received.filter(r => r.address === btcAddrRegtest); - expect(received.length).toBe(1); - expect(received[0].category).toBe('receive'); - expect(received[0].blockhash).toBe(hexToBuffer(firstReward.burn_block_hash).toString('hex')); - const sats = new bignumber(received[0].amount).shiftedBy(8).toString(); + let txs = await withDescriptorWallet( + async walletName => + (await testEnv.bitcoinRpcClient.listtransactions( + { + label: btcAddrRegtest, + include_watchonly: true, + }, + btcDescriptor ? walletName : undefined + )) as { + address: string; + category: string; + amount: number; + blockhash: string; + blockheight: number; + }[] + ); + txs = txs.filter(r => r.address === btcAddrRegtest); + expect(txs.length).toBe(1); + expect(txs[0].category).toBe('receive'); + expect(txs[0].blockhash).toBe(hexToBuffer(firstReward.burn_block_hash).toString('hex')); + const sats = new bignumber(txs[0].amount).shiftedBy(8).toString(); expect(sats).toBe(firstReward.reward_amount); }); @@ -505,501 +263,177 @@ describe('PoX-4 - Stack using supported bitcoin address formats', () => { }); test('BTC stacking reward received', async () => { - const received: number = await testEnv.bitcoinRpcClient.getreceivedbyaddress({ - address: btcAddrRegtest, - minconf: 0, - }); - expect(received).toBeGreaterThan(0); - }); - }); - - describe('PoX-4 - Stacking operations P2WSH', () => { - const account = testnetKeys[1]; - let btcAddr: string; - let btcAddrDecoded: { version: number; data: Uint8Array }; - let btcPubKey: string; - let btcAddrRegtest: string; - - test('P2WSH setup', async () => { - btcAddr = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'testnet', - addressFormat: 'p2wsh', - }); - expect(btcAddr).toBe('tb1q4qp0380kg75cqv25k4zruwa87wefwz0uefv78jekagm2j8568rwqvz7llf'); - btcPubKey = privateToPublicKey(btcPrivateKey).toString('hex'); - expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); - - btcAddrDecoded = decodeBtcAddress(btcAddr); - expect({ - data: Buffer.from(btcAddrDecoded.data).toString('hex'), - version: btcAddrDecoded.version, - }).toEqual({ - data: 'a802f89df647a9803154b5443e3ba7f3b29709fcca59e3cb36ea36a91e9a38dc', - version: 5, - }); - - // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses - btcAddrRegtest = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'regtest', - addressFormat: 'p2wsh', - }); - expect(btcAddrRegtest).toBe( - 'bcrt1q4qp0380kg75cqv25k4zruwa87wefwz0uefv78jekagm2j8568rwqpm5e2n' + const received = await withDescriptorWallet( + async walletName => + (await testEnv.bitcoinRpcClient.getreceivedbyaddress( + { + address: btcAddrRegtest, + minconf: 0, + }, + btcDescriptor ? walletName : undefined + )) as number ); - - await testEnv.bitcoinRpcClient.importaddress({ - address: btcAddrRegtest, - label: btcAddrRegtest, - }); - const btcWalletAddrs = await testEnv.bitcoinRpcClient.getaddressesbylabel({ - label: btcAddrRegtest, - }); - expect(Object.keys(btcWalletAddrs)).toContain(btcAddrRegtest); - - // If we're close to or in the prepare phase, wait until until the start of the next cycle - // if ((await testEnv.client.getPox()).next_cycle.blocks_until_prepare_phase <= 20) { - if (true) { - await standByForNextPoxCycle(); - } - - poxInfo = await testEnv.client.getPox(); - - burnBlockHeight = poxInfo.current_burnchain_block_height as number; - ustxAmount = BigInt(Math.round(Number(poxInfo.min_amount_ustx) * 1.1).toString()); - cycleBlockLength = cycleCount * poxInfo.reward_cycle_length; - [contractAddress, contractName] = poxInfo.contract_id.split('.'); - - expect(contractName).toBe('pox-4'); + expect(received).toBeGreaterThan(0); }); + } +); - test('stack-stx tx', async () => { - // Create and broadcast a `stack-stx` tx - const tx1 = await makeContractCall({ - senderKey: account.secretKey, - contractAddress, - contractName, - functionName: 'stack-stx', - functionArgs: [ - uintCV(ustxAmount.toString()), // amount-ustx - tupleCV({ - hashbytes: bufferCV(btcAddrDecoded.data), - version: bufferCV(Buffer.from([btcAddrDecoded.version])), - }), // pox-addr - uintCV(burnBlockHeight), // start-burn-ht - uintCV(cycleCount), // lock-period - bufferCV(hexToBytes('3'.padStart(66, '0'))), // signer-key - ], - network: testEnv.stacksNetwork, - anchorMode: AnchorMode.OnChainOnly, - fee: 10000, - validateWithAbi: false, - }); - const expectedTxId1 = '0x' + tx1.txid(); - const sendResult1 = await testEnv.client.sendTransaction(Buffer.from(tx1.serialize())); - expect(sendResult1.txId).toBe(expectedTxId1); +function P2SH_P2WPKH() { + const btcAddr = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'testnet', + addressFormat: 'p2sh-p2wpkh', + }); + expect(btcAddr).toBe('2N74VLxyT79VGHiBK2zEg3a9HJG7rEc5F3o'); + const btcPubKey = privateToPublicKey(BTC_PRIVATE_KEY).toString('hex'); + expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); + + const btcAddrDecoded = decodeBtcAddress(btcAddr); + expect({ + data: Buffer.from(btcAddrDecoded.data).toString('hex'), + version: btcAddrDecoded.version, + }).toEqual({ data: '978a0121f9a24de65a13bab0c43c3a48be074eae', version: 1 }); + + // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses + const btcAddrRegtest = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'regtest', + addressFormat: 'p2sh-p2wpkh', + }); + expect(btcAddrRegtest).toBe('2N74VLxyT79VGHiBK2zEg3a9HJG7rEc5F3o'); + + return { + btcAddr, + btcAddrDecoded, + btcAddrRegtest, + btcPubKey, + btcDescriptor: undefined, + }; +} + +function P2WSH() { + const btcAddr = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'testnet', + addressFormat: 'p2wsh', + }); + expect(btcAddr).toBe('tb1q4qp0380kg75cqv25k4zruwa87wefwz0uefv78jekagm2j8568rwqvz7llf'); + const btcPubKey = privateToPublicKey(BTC_PRIVATE_KEY).toString('hex'); + expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); + + const btcAddrDecoded = decodeBtcAddress(btcAddr); + expect({ + data: Buffer.from(btcAddrDecoded.data).toString('hex'), + version: btcAddrDecoded.version, + }).toEqual({ + data: 'a802f89df647a9803154b5443e3ba7f3b29709fcca59e3cb36ea36a91e9a38dc', + version: 5, + }); - // Wait for API to receive and ingest tx - const dbTx1 = await standByForTxSuccess(expectedTxId1); + // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses + const btcAddrRegtest = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'regtest', + addressFormat: 'p2wsh', + }); + expect(btcAddrRegtest).toBe('bcrt1q4qp0380kg75cqv25k4zruwa87wefwz0uefv78jekagm2j8568rwqpm5e2n'); + + return { + btcAddr, + btcAddrDecoded, + btcAddrRegtest, + btcPubKey, + btcDescriptor: undefined, + }; +} + +function P2WPKH() { + const btcAddr = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'testnet', + addressFormat: 'p2wpkh', + }); + expect(btcAddr).toBe('tb1qq6hag67dl53wl99vzg42z8eyzfz2xlkvvlryfj'); + const btcPubKey = privateToPublicKey(BTC_PRIVATE_KEY).toString('hex'); + expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); + + const btcAddrDecoded = decodeBtcAddress(btcAddr); + expect({ + data: Buffer.from(btcAddrDecoded.data).toString('hex'), + version: btcAddrDecoded.version, + }).toEqual({ data: '06afd46bcdfd22ef94ac122aa11f241244a37ecc', version: 4 }); + + // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses + const btcAddrRegtest = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'regtest', + addressFormat: 'p2wpkh', + }); + expect(btcAddrRegtest).toBe('bcrt1qq6hag67dl53wl99vzg42z8eyzfz2xlkvwk6f7m'); + + return { + btcAddr, + btcAddrDecoded, + btcAddrRegtest, + btcPubKey, + btcDescriptor: undefined, + }; +} + +function P2TR() { + const btcAddr = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'testnet', + addressFormat: 'p2tr', + }); + expect(btcAddr).toBe('tb1pet7ep3czdu9k4wvdlz2fp5p8x2yp7t6ttyqg2c6cmh0lgeuu9lasvfnc28'); + const btcPubKey = privateToPublicKey(BTC_PRIVATE_KEY).toString('hex'); + expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); + + const btcAddrDecoded = decodeBtcAddress(btcAddr); + expect({ + data: Buffer.from(btcAddrDecoded.data).toString('hex'), + version: btcAddrDecoded.version, + }).toEqual({ + data: 'cafd90c7026f0b6ab98df89490d02732881f2f4b5900856358dddff4679c2ffb', + version: 6, + }); - const tx1Events = await testEnv.api.datastore.getTxEvents({ - txId: expectedTxId1, - indexBlockHash: dbTx1.index_block_hash, - limit: 99999, - offset: 0, - }); - expect(tx1Events.results).toBeTruthy(); - const lockEvent1 = tx1Events.results.find( - r => r.event_type === DbEventTypeId.StxLock - ) as DbStxLockEvent; - expect(lockEvent1).toBeDefined(); - expect(lockEvent1.locked_address).toBe(account.stacksAddress); - expect(lockEvent1.locked_amount).toBe(ustxAmount); - - // Test that the unlock height event data in the API db matches the expected height from the - // calculated values from the /v2/pox data and the cycle count specified in the `stack-stx` tx. - const expectedUnlockHeight1 = - cycleBlockLength + poxInfo.next_cycle.reward_phase_start_block_height; - expect(lockEvent1.unlock_height).toBe(expectedUnlockHeight1); - - // Test the API address balance data after a `stack-stx` operation - const addrBalance1 = await fetchGet( - `/extended/v1/address/${account.stacksAddress}/stx` - ); - expect(addrBalance1.locked).toBe(ustxAmount.toString()); - expect(addrBalance1.burnchain_unlock_height).toBe(expectedUnlockHeight1); - expect(addrBalance1.lock_height).toBe(dbTx1.block_height); - expect(addrBalance1.lock_tx_id).toBe(dbTx1.tx_id); - }); - - test('stacking rewards - API /burnchain/reward_slot_holders', async () => { - const prepareStart = poxInfo.next_cycle.prepare_phase_start_block_height; - const prepareEnd = prepareStart + poxInfo.prepare_phase_block_length; - - await standByUntilBurnBlock(prepareEnd + 1); - - const rewardSlotHolders = await fetchGet( - `/extended/v1/burnchain/reward_slot_holders/${btcAddr}` - ); - expect(rewardSlotHolders.total).toBe(1); - expect(rewardSlotHolders.results[0].address).toBe(btcAddr); - expect(rewardSlotHolders.results[0].burn_block_height).toBeGreaterThanOrEqual(prepareStart); - expect(rewardSlotHolders.results[0].burn_block_height).toBeLessThanOrEqual(prepareEnd); - }); - - test('stacking rewards - API /burnchain/rewards', async () => { - await standByUntilBurnBlock(poxInfo.next_cycle.reward_phase_start_block_height + 2); - - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - expect(firstReward.reward_recipient).toBe(btcAddr); - expect(Number(firstReward.burn_amount)).toBeGreaterThan(0); - expect(firstReward.burn_block_height).toBeGreaterThanOrEqual( - poxInfo.next_cycle.reward_phase_start_block_height - ); - expect(firstReward.burn_block_height).toBeLessThanOrEqual( - poxInfo.next_cycle.reward_phase_start_block_height + 2 - ); - - const rewardsTotal = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}/total` - ); - expect(rewardsTotal.reward_recipient).toBe(btcAddr); - expect(Number(rewardsTotal.reward_amount)).toBeGreaterThan(0); - }); - - test('stacking rewards - BTC JSON-RPC', async () => { - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - const blockResult: { - tx: { vout?: { scriptPubKey: { address?: string }; value?: number }[] }[]; - } = await testEnv.bitcoinRpcClient.getblock({ - blockhash: hexToBuffer(firstReward.burn_block_hash).toString('hex'), - verbosity: 2, - }); - const vout = blockResult.tx - .flatMap(t => t.vout) - .find(v => v?.value && v.scriptPubKey.address == btcAddrRegtest); - if (!vout || !vout.value) { - throw new Error( - `Could not find bitcoin vout for ${btcAddrRegtest} in block ${firstReward.burn_block_hash}` - ); - } - const sats = new bignumber(vout.value).shiftedBy(8).toString(); - expect(sats).toBe(firstReward.reward_amount); - }); - - test('stacking rewards - BTC JSON-RPC - listtransactions', async () => { - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - - let received: { - address: string; - category: string; - amount: number; - blockhash: string; - blockheight: number; - txid: string; - confirmations: number; - }[] = await testEnv.bitcoinRpcClient.listtransactions({ - label: btcAddrRegtest, - include_watchonly: true, - }); - received = received.filter(r => r.address === btcAddrRegtest); - expect(received.length).toBe(1); - expect(received[0].category).toBe('receive'); - expect(received[0].blockhash).toBe(hexToBuffer(firstReward.burn_block_hash).toString('hex')); - const sats = new bignumber(received[0].amount).shiftedBy(8).toString(); - expect(sats).toBe(firstReward.reward_amount); - }); - - test('stx unlocked - RPC balance endpoint', async () => { - // Wait until account has unlocked (finished Stacking cycles) - const rpcAccountInfo1 = await testEnv.client.getAccount(account.stacksAddress); - const burnBlockUnlockHeight = rpcAccountInfo1.unlock_height + 1; - await standByUntilBurnBlock(burnBlockUnlockHeight); - - // Check that STX are no longer reported as locked by the RPC endpoints: - const rpcAccountInfo = await testEnv.client.getAccount(account.stacksAddress); - expect(BigInt(rpcAccountInfo.locked)).toBe(0n); - expect(rpcAccountInfo.unlock_height).toBe(0); - }); - - test('stx unlocked - API balance endpoint', async () => { - // Check that STX are no longer reported as locked by the API endpoints: - const addrBalance = await fetchGet( - `/extended/v1/address/${account.stacksAddress}/stx` - ); - expect(BigInt(addrBalance.locked)).toBe(0n); - expect(addrBalance.burnchain_unlock_height).toBe(0); - expect(addrBalance.lock_height).toBe(0); - expect(addrBalance.lock_tx_id).toBe(''); - }); - - test('BTC stacking reward received', async () => { - const received: number = await testEnv.bitcoinRpcClient.getreceivedbyaddress({ - address: btcAddrRegtest, - minconf: 0, - }); - expect(received).toBeGreaterThan(0); - }); - }); - - describe('PoX-4 - Stacking operations P2TR', () => { - const account = testnetKeys[1]; - let btcAddr: string; - let btcAddrDecoded: { version: number; data: Uint8Array }; - let btcPubKey: string; - let btcAddrRegtest: string; - - test('P2TR setup', async () => { - btcAddr = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'testnet', - addressFormat: 'p2tr', - }); - expect(btcAddr).toBe('tb1pet7ep3czdu9k4wvdlz2fp5p8x2yp7t6ttyqg2c6cmh0lgeuu9lasvfnc28'); - btcPubKey = privateToPublicKey(btcPrivateKey).toString('hex'); - expect(btcPubKey).toBe('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'); - - btcAddrDecoded = decodeBtcAddress(btcAddr); - expect({ - data: Buffer.from(btcAddrDecoded.data).toString('hex'), - version: btcAddrDecoded.version, - }).toEqual({ - data: 'cafd90c7026f0b6ab98df89490d02732881f2f4b5900856358dddff4679c2ffb', - version: 6, - }); - - // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses - btcAddrRegtest = getBitcoinAddressFromKey({ - privateKey: btcPrivateKey, - network: 'regtest', - addressFormat: 'p2tr', - }); - expect(btcAddrRegtest).toBe( - 'bcrt1pet7ep3czdu9k4wvdlz2fp5p8x2yp7t6ttyqg2c6cmh0lgeuu9laspse7la' - ); - - await testEnv.bitcoinRpcClient.importaddress({ - address: btcAddrRegtest, - label: btcAddrRegtest, - }); - const btcWalletAddrs = await testEnv.bitcoinRpcClient.getaddressesbylabel({ - label: btcAddrRegtest, - }); - expect(Object.keys(btcWalletAddrs)).toContain(btcAddrRegtest); - - // If we're close to or in the prepare phase, wait until until the start of the next cycle - // if ((await testEnv.client.getPox()).next_cycle.blocks_until_prepare_phase <= 20) { - if (true) { - await standByForNextPoxCycle(); - } - - poxInfo = await testEnv.client.getPox(); - - burnBlockHeight = poxInfo.current_burnchain_block_height as number; - ustxAmount = BigInt(Math.round(Number(poxInfo.min_amount_ustx) * 1.1).toString()); - cycleBlockLength = cycleCount * poxInfo.reward_cycle_length; - [contractAddress, contractName] = poxInfo.contract_id.split('.'); - - expect(contractName).toBe('pox-4'); - }); - - test('stack-stx tx', async () => { - // Create and broadcast a `stack-stx` tx - const tx1 = await makeContractCall({ - senderKey: account.secretKey, - contractAddress, - contractName, - functionName: 'stack-stx', - functionArgs: [ - uintCV(ustxAmount.toString()), // amount-ustx - tupleCV({ - hashbytes: bufferCV(btcAddrDecoded.data), - version: bufferCV(Buffer.from([btcAddrDecoded.version])), - }), // pox-addr - uintCV(burnBlockHeight), // start-burn-ht - uintCV(cycleCount), // lock-period - bufferCV(hexToBytes('4'.padStart(66, '0'))), // signer-key - ], - network: testEnv.stacksNetwork, - anchorMode: AnchorMode.OnChainOnly, - fee: 10000, - validateWithAbi: false, - }); - const expectedTxId1 = '0x' + tx1.txid(); - const sendResult1 = await testEnv.client.sendTransaction(Buffer.from(tx1.serialize())); - expect(sendResult1.txId).toBe(expectedTxId1); - - // Wait for API to receive and ingest tx - const dbTx1 = await standByForTxSuccess(expectedTxId1); - - const tx1Events = await testEnv.api.datastore.getTxEvents({ - txId: expectedTxId1, - indexBlockHash: dbTx1.index_block_hash, - limit: 99999, - offset: 0, - }); - expect(tx1Events.results).toBeTruthy(); - const lockEvent1 = tx1Events.results.find( - r => r.event_type === DbEventTypeId.StxLock - ) as DbStxLockEvent; - expect(lockEvent1).toBeDefined(); - expect(lockEvent1.locked_address).toBe(account.stacksAddress); - expect(lockEvent1.locked_amount).toBe(ustxAmount); - - // Test that the unlock height event data in the API db matches the expected height from the - // calculated values from the /v2/pox data and the cycle count specified in the `stack-stx` tx. - const expectedUnlockHeight1 = - cycleBlockLength + poxInfo.next_cycle.reward_phase_start_block_height; - expect(lockEvent1.unlock_height).toBe(expectedUnlockHeight1); - - // Test the API address balance data after a `stack-stx` operation - const addrBalance1 = await fetchGet( - `/extended/v1/address/${account.stacksAddress}/stx` - ); - expect(addrBalance1.locked).toBe(ustxAmount.toString()); - expect(addrBalance1.burnchain_unlock_height).toBe(expectedUnlockHeight1); - expect(addrBalance1.lock_height).toBe(dbTx1.block_height); - expect(addrBalance1.lock_tx_id).toBe(dbTx1.tx_id); - }); - - test('stacking rewards - API /burnchain/reward_slot_holders', async () => { - const prepareStart = poxInfo.next_cycle.prepare_phase_start_block_height; - const prepareEnd = prepareStart + poxInfo.prepare_phase_block_length; - - await standByUntilBurnBlock(prepareEnd + 1); - - const rewardSlotHolders = await fetchGet( - `/extended/v1/burnchain/reward_slot_holders/${btcAddr}` - ); - expect(rewardSlotHolders.total).toBe(1); - expect(rewardSlotHolders.results[0].address).toBe(btcAddr); - expect(rewardSlotHolders.results[0].burn_block_height).toBeGreaterThanOrEqual(prepareStart); - expect(rewardSlotHolders.results[0].burn_block_height).toBeLessThanOrEqual(prepareEnd); - }); - - test('stacking rewards - API /burnchain/rewards', async () => { - await standByUntilBurnBlock(poxInfo.next_cycle.reward_phase_start_block_height + 2); - - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - expect(firstReward.reward_recipient).toBe(btcAddr); - expect(Number(firstReward.burn_amount)).toBeGreaterThan(0); - expect(firstReward.burn_block_height).toBeGreaterThanOrEqual( - poxInfo.next_cycle.reward_phase_start_block_height - ); - expect(firstReward.burn_block_height).toBeLessThanOrEqual( - poxInfo.next_cycle.reward_phase_start_block_height + 2 - ); - - const rewardsTotal = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}/total` - ); - expect(rewardsTotal.reward_recipient).toBe(btcAddr); - expect(Number(rewardsTotal.reward_amount)).toBeGreaterThan(0); - }); - - test('stacking rewards - BTC JSON-RPC', async () => { - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - const blockResult: { - tx: { vout?: { scriptPubKey: { address?: string }; value?: number }[] }[]; - } = await testEnv.bitcoinRpcClient.getblock({ - blockhash: hexToBuffer(firstReward.burn_block_hash).toString('hex'), - verbosity: 2, - }); - const vout = blockResult.tx - .flatMap(t => t.vout) - .find(v => v?.value && v.scriptPubKey.address == btcAddrRegtest); - if (!vout || !vout.value) { - throw new Error( - `Could not find bitcoin vout for ${btcAddrRegtest} in block ${firstReward.burn_block_hash}` - ); - } - const sats = new bignumber(vout.value).shiftedBy(8).toString(); - expect(sats).toBe(firstReward.reward_amount); - }); - - test('stacking rewards - BTC JSON-RPC - listtransactions', async () => { - const rewards = await fetchGet( - `/extended/v1/burnchain/rewards/${btcAddr}` - ); - const firstReward = rewards.results.sort( - (a, b) => a.burn_block_height - b.burn_block_height - )[0]; - - let received: { - address: string; - category: string; - amount: number; - blockhash: string; - blockheight: number; - txid: string; - confirmations: number; - }[] = await testEnv.bitcoinRpcClient.listtransactions({ - label: btcAddrRegtest, - include_watchonly: true, - }); - received = received.filter(r => r.address === btcAddrRegtest); - expect(received.length).toBe(1); - expect(received[0].category).toBe('receive'); - expect(received[0].blockhash).toBe(hexToBuffer(firstReward.burn_block_hash).toString('hex')); - const sats = new bignumber(received[0].amount).shiftedBy(8).toString(); - expect(sats).toBe(firstReward.reward_amount); - }); - - test('stx unlocked - RPC balance endpoint', async () => { - // Wait until account has unlocked (finished Stacking cycles) - const rpcAccountInfo1 = await testEnv.client.getAccount(account.stacksAddress); - const burnBlockUnlockHeight = rpcAccountInfo1.unlock_height + 1; - await standByUntilBurnBlock(burnBlockUnlockHeight); - - // Check that STX are no longer reported as locked by the RPC endpoints: - const rpcAccountInfo = await testEnv.client.getAccount(account.stacksAddress); - expect(BigInt(rpcAccountInfo.locked)).toBe(0n); - expect(rpcAccountInfo.unlock_height).toBe(0); - }); - - test('stx unlocked - API balance endpoint', async () => { - // Check that STX are no longer reported as locked by the API endpoints: - const addrBalance = await fetchGet( - `/extended/v1/address/${account.stacksAddress}/stx` - ); - expect(BigInt(addrBalance.locked)).toBe(0n); - expect(addrBalance.burnchain_unlock_height).toBe(0); - expect(addrBalance.lock_height).toBe(0); - expect(addrBalance.lock_tx_id).toBe(''); - }); - - test('BTC stacking reward received', async () => { - const received: number = await testEnv.bitcoinRpcClient.getreceivedbyaddress({ - address: btcAddrRegtest, - minconf: 0, - }); - expect(received).toBeGreaterThan(0); - }); + // Create a regtest address to use with bitcoind json-rpc since the krypton-stacks-node uses testnet addresses + const btcAddrRegtest = getBitcoinAddressFromKey({ + privateKey: BTC_PRIVATE_KEY, + network: 'regtest', + addressFormat: 'p2tr', }); -}); + expect(btcAddrRegtest).toBe('bcrt1pet7ep3czdu9k4wvdlz2fp5p8x2yp7t6ttyqg2c6cmh0lgeuu9laspse7la'); + + return { + btcAddr, + btcAddrDecoded, + btcAddrRegtest, + btcPubKey, + btcDescriptor: `tr(${btcPubKey})`, + }; +} + +// helper +async function withDescriptorWallet(fn: (walletName: string) => Promise | R): Promise { + // before: load or create descriptor wallet + try { + await testEnv.bitcoinRpcClient.loadwallet({ filename: 'descriptor-wallet' }); + } catch (e) { + await testEnv.bitcoinRpcClient.createwallet({ + wallet_name: 'descriptor-wallet', + disable_private_keys: true, + descriptors: true, + load_on_startup: false, + } as any); + } + + const res = await fn('descriptor-wallet'); + + // after: unload descriptor walletl + await testEnv.bitcoinRpcClient.unloadwallet({ wallet_name: 'descriptor-wallet' }); + + return res; +} diff --git a/src/tests-2.5/pox-4-burnchain-delegate-stx.ts b/src/tests-2.5/pox-4-burnchain-delegate-stx.ts index ef0e9b089c..d0dea1fd74 100644 --- a/src/tests-2.5/pox-4-burnchain-delegate-stx.ts +++ b/src/tests-2.5/pox-4-burnchain-delegate-stx.ts @@ -10,6 +10,7 @@ import { bufferCV, makeContractCall, makeSTXTokenTransfer, + randomBytes, standardPrincipalCV, uintCV, } from '@stacks/transactions'; @@ -28,7 +29,6 @@ import { standByUntilBurnBlock, testEnv, TestEnvContext, - ZERO_SIGNER_KEY_BYTES, } from '../test-utils/test-helpers'; import * as btc from 'bitcoinjs-lib'; import { b58ToC32, c32ToB58 } from 'c32check'; @@ -403,7 +403,7 @@ describe('PoX-4 - Stack using Bitcoin-chain ops', () => { poxAddrPayoutAccount.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(1), // lock-period - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, diff --git a/src/tests-2.5/pox-4-delegate-aggregation.ts b/src/tests-2.5/pox-4-delegate-aggregation.ts index 1fd44bf548..6dc5c0de8a 100644 --- a/src/tests-2.5/pox-4-delegate-aggregation.ts +++ b/src/tests-2.5/pox-4-delegate-aggregation.ts @@ -11,7 +11,6 @@ import { standByForTxSuccess, standByForAccountUnlock, testEnv, - ZERO_SIGNER_KEY_BYTES, } from '../test-utils/test-helpers'; import { stxToMicroStx } from '../helpers'; import { @@ -20,6 +19,7 @@ import { makeContractCall, makeSTXTokenTransfer, noneCV, + randomBytes, someCV, standardPrincipalCV, uintCV, @@ -205,7 +205,7 @@ describe('PoX-4 - Delegate aggregation increase operations', () => { delegateeAccount.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(1), // lock-period, - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, diff --git a/src/tests-2.5/pox-4-delegate-revoked-stacking.ts b/src/tests-2.5/pox-4-delegate-revoked-stacking.ts index e1d30feff8..34424ea358 100644 --- a/src/tests-2.5/pox-4-delegate-revoked-stacking.ts +++ b/src/tests-2.5/pox-4-delegate-revoked-stacking.ts @@ -8,6 +8,7 @@ import { makeContractCall, makeSTXTokenTransfer, noneCV, + randomBytes, someCV, standardPrincipalCV, uintCV, @@ -19,7 +20,6 @@ import { DbTxStatus } from '../datastore/common'; import { stxToMicroStx } from '../helpers'; import { Account, - ZERO_SIGNER_KEY_BYTES, accountFromKey, fetchGet, readOnlyFnCall, @@ -137,7 +137,7 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { STACKER.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(1), // lock-period - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, @@ -224,7 +224,7 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { STACKER.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(3), // lock-period - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, @@ -329,7 +329,7 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { STACKER.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(1), // lock-period - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, @@ -379,7 +379,7 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { functionArgs: [ standardPrincipalCV(STACKER.stxAddr), // stacker STACKER.poxAddrClar, // pox-addr - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key uintCV(2), // extend-count ], network: testEnv.stacksNetwork, @@ -410,7 +410,7 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { STACKER.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(1), // lock-period - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, diff --git a/src/tests-2.5/pox-4-delegate-stacking.ts b/src/tests-2.5/pox-4-delegate-stacking.ts index 43aa6fbec0..192f55b7be 100644 --- a/src/tests-2.5/pox-4-delegate-stacking.ts +++ b/src/tests-2.5/pox-4-delegate-stacking.ts @@ -2,7 +2,6 @@ import { CoreRpcPoxInfo } from '../core-rpc/client'; import { testnetKeys } from '../api/routes/debug'; import { Account, - ZERO_SIGNER_KEY_BYTES, accountFromKey, fetchGet, readOnlyFnCall, @@ -19,6 +18,7 @@ import { makeContractCall, makeSTXTokenTransfer, noneCV, + randomBytes, someCV, standardPrincipalCV, uintCV, @@ -221,7 +221,7 @@ describe('PoX-4 - Delegate Stacking operations', () => { delegateeAccount.poxAddrClar, // pox-addr uintCV(startBurnHt), // start-burn-ht uintCV(1), // lock-period, - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, @@ -346,7 +346,7 @@ describe('PoX-4 - Delegate Stacking operations', () => { functionArgs: [ standardPrincipalCV(delegateeAccount.stxAddr), // stacker delegateeAccount.poxAddrClar, // pox-addr - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key uintCV(extendCount), // extend-count ], network: testEnv.stacksNetwork, diff --git a/src/tests-2.5/pox-4-stack-extend-increase.ts b/src/tests-2.5/pox-4-stack-extend-increase.ts index f07050c86c..fa466f6300 100644 --- a/src/tests-2.5/pox-4-stack-extend-increase.ts +++ b/src/tests-2.5/pox-4-stack-extend-increase.ts @@ -8,7 +8,14 @@ import { BurnchainRewardSlotHolderListResponse, BurnchainRewardsTotal, } from '@stacks/stacks-blockchain-api-types'; -import { AnchorMode, bufferCV, makeContractCall, tupleCV, uintCV } from '@stacks/transactions'; +import { + AnchorMode, + bufferCV, + makeContractCall, + randomBytes, + tupleCV, + uintCV, +} from '@stacks/transactions'; import bignumber from 'bignumber.js'; import { DbEventTypeId, DbStxLockEvent } from '../datastore/common'; import { @@ -17,7 +24,6 @@ import { standByForTxSuccess, standByUntilBurnBlock, testEnv, - ZERO_SIGNER_KEY_BYTES, } from '../test-utils/test-helpers'; import { decodeBtcAddress } from '@stacks/stacking'; import { hexToBuffer } from '@hirosystems/api-toolkit'; @@ -123,7 +129,7 @@ describe('PoX-4 - Stack extend and increase operations', () => { }), // pox-addr uintCV(burnBlockHeight), // start-burn-ht uintCV(lockPeriod), // lock-period, - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly, @@ -315,7 +321,7 @@ describe('PoX-4 - Stack extend and increase operations', () => { hashbytes: bufferCV(decodedBtcAddr.data), version: bufferCV(Buffer.from([decodedBtcAddr.version])), }), // pox-addr - bufferCV(ZERO_SIGNER_KEY_BYTES), // signer-key + bufferCV(randomBytes(33)), // signer-key ], network: testEnv.stacksNetwork, anchorMode: AnchorMode.OnChainOnly,