Skip to content

Commit 9aa16c9

Browse files
committed
fix: tests
1 parent 1eee607 commit 9aa16c9

10 files changed

+51
-31
lines changed

src/api/routes/faucets.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ interface SeededAccount {
6363
pubKey: string;
6464
}
6565

66-
const testnetKeys: SeededAccount[] = testnetAccounts.map(t => ({
66+
export const FAUCET_TESTNET_KEYS: SeededAccount[] = testnetAccounts.map(t => ({
6767
secretKey: t.secretKey,
6868
stacksAddress: t.stacksAddress,
6969
pubKey: publicKeyToString(pubKeyfromPrivKey(t.secretKey)),
@@ -281,7 +281,9 @@ export const FaucetRoutes: FastifyPluginAsync<
281281
const FAUCET_STACKING_TRIGGER_COUNT = 1;
282282

283283
const STX_FAUCET_NETWORK = () => getStxFaucetNetwork();
284-
const STX_FAUCET_KEYS = (process.env.FAUCET_PRIVATE_KEY ?? testnetKeys[0].secretKey).split(',');
284+
const STX_FAUCET_KEYS = (
285+
process.env.FAUCET_PRIVATE_KEY ?? FAUCET_TESTNET_KEYS[0].secretKey
286+
).split(',');
285287

286288
async function calculateSTXFaucetAmount(
287289
network: StacksNetwork,

tests/2.5/pox-4-btc-address-formats.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
uintCV,
1212
} from '@stacks/transactions';
1313
import bignumber from 'bignumber.js';
14-
import { testnetKeys } from '../../src/api/routes/debug';
1514
import { CoreRpcPoxInfo } from '../../src/core-rpc/client';
1615
import { DbEventTypeId, DbStxLockEvent } from '../../src/datastore/common';
1716
import { getBitcoinAddressFromKey, privateToPublicKey } from '../../src/ec-helpers';
@@ -31,13 +30,14 @@ import {
3130
BurnchainRewardSlotHolderListResponse,
3231
} from '../../src/api/schemas/responses/responses';
3332
import { BurnchainRewardsTotal } from '../../src/api/schemas/entities/burnchain-rewards';
33+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
3434

3535
const BTC_PRIVATE_KEY = '0000000000000000000000000000000000000000000000000000000000000002';
3636

3737
describe.each([P2SH_P2WPKH, P2WPKH, P2WSH, P2TR])(
3838
'PoX-4 - Stack using bitcoin address %p',
3939
addressSetup => {
40-
const account = testnetKeys[1];
40+
const account = FAUCET_TESTNET_KEYS[1];
4141

4242
let poxInfo: CoreRpcPoxInfo;
4343
let burnBlockHeight: number;

tests/2.5/pox-4-burnchain-delegate-stx.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
standardPrincipalCV,
99
uintCV,
1010
} from '@stacks/transactions';
11-
import { testnetKeys } from '../../src/api/routes/debug';
1211
import { StacksCoreRpcClient } from '../../src/core-rpc/client';
1312
import { ECPair } from '../../src/ec-helpers';
1413
import { BootContractAddress } from '../../src/helpers';
@@ -41,6 +40,7 @@ import {
4140
TransactionEventsResponse,
4241
} from '../../src/api/schemas/responses/responses';
4342
import { StxLockTransactionEvent } from '../../src/api/schemas/entities/transaction-events';
43+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
4444

4545
// Perform Delegate-STX operation on Bitcoin.
4646
// See https://github.com/stacksgov/sips/blob/a7f2e58ec90c12ee1296145562eec75029b89c48/sips/sip-015/sip-015-network-upgrade.md#new-burnchain-transaction-delegate-stx
@@ -175,7 +175,7 @@ async function createPox2DelegateStx(args: {
175175
}
176176

177177
describe('PoX-4 - Stack using Bitcoin-chain delegate ops', () => {
178-
const seedAccount = testnetKeys[0];
178+
const seedAccount = FAUCET_TESTNET_KEYS[0];
179179

180180
let db: PgWriteStore;
181181
let api: ApiServer;

tests/2.5/pox-4-burnchain-stack-stx.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
stringAsciiCV,
99
uintCV,
1010
} from '@stacks/transactions';
11-
import { testnetKeys } from '../../src/api/routes/debug';
1211
import { StacksCoreRpcClient } from '../../src/core-rpc/client';
1312
import { ECPair } from '../../src/ec-helpers';
1413
import { BootContractAddress } from '../../src/helpers';
@@ -38,6 +37,7 @@ import { AddressStxBalance } from '../../src/api/schemas/entities/addresses';
3837
import { TransactionEventsResponse } from '../../src/api/schemas/responses/responses';
3938
import { StxLockTransactionEvent } from '../../src/api/schemas/entities/transaction-events';
4039
import { ContractCallTransaction } from '../../src/api/schemas/entities/transactions';
40+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
4141

4242
// Perform Stack-STX operation on Bitcoin.
4343
// See https://github.com/stacksgov/sips/blob/0da29c6911c49c45e4125dbeaed58069854591eb/sips/sip-007/sip-007-stacking-consensus.md#stx-operations-on-bitcoin
@@ -148,7 +148,7 @@ async function createPox4StackStx(args: {
148148
}
149149

150150
describe('PoX-4 - Stack using Bitcoin-chain stack ops', () => {
151-
const seedAccount = testnetKeys[0];
151+
const seedAccount = FAUCET_TESTNET_KEYS[0];
152152

153153
let db: PgWriteStore;
154154
let api: ApiServer;

tests/2.5/pox-4-delegate-aggregation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CoreRpcPoxInfo } from '../../src/core-rpc/client';
2-
import { testnetKeys } from '../../src/api/routes/debug';
32
import {
43
Account,
54
accountFromKey,
@@ -39,9 +38,10 @@ import { hexToBytes } from '@stacks/common';
3938
import { StackingClient } from '@stacks/stacking';
4039
import { getPublicKeyFromPrivate } from '@stacks/encryption';
4140
import { AddressStxBalance } from '../../src/api/schemas/entities/addresses';
41+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
4242

4343
describe('PoX-4 - Delegate aggregation increase operations', () => {
44-
const seedKey = testnetKeys[4].secretKey;
44+
const seedKey = FAUCET_TESTNET_KEYS[4].secretKey;
4545
const delegatorKey = '04608922f3ce63971bb120fa9c9454c5bd06370f61414040a737a6ee8ef8a10f01';
4646
const delegateeKey = 'b038e143cf4ee4c079b3c3605a8ed28732e5745c138b728408e80faf7a59b8c201';
4747

tests/2.5/pox-4-delegate-revoked-stacking.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ClarityValueUInt,
1919
decodeClarityValue,
2020
} from '@hirosystems/stacks-encoding-native-js';
21-
import { testnetKeys } from '../../src/api/routes/debug';
2221
import { CoreRpcPoxInfo } from '../../src/core-rpc/client';
2322
import { DbTxStatus } from '../../src/datastore/common';
2423
import { stxToMicroStx } from '../../src/helpers';
@@ -35,9 +34,10 @@ import {
3534
import { hexToBytes } from '@stacks/common';
3635
import { getPublicKeyFromPrivate } from '@stacks/encryption';
3736
import { AddressStxBalance } from '../../src/api/schemas/entities/addresses';
37+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
3838

3939
describe('PoX-4 - Delegate Revoked Stacking', () => {
40-
const seedKey = testnetKeys[4].secretKey;
40+
const seedKey = FAUCET_TESTNET_KEYS[4].secretKey;
4141
const delegatorKey = '72e8e3725324514c38c2931ed337ab9ab8d8abaae83ed2275456790194b1fd3101';
4242
const delegateeKey = '0d174cf0be276cedcf21727611ef2504aed093d8163f65985c07760fda12a7ea01';
4343

tests/2.5/pox-4-delegate-stacking.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CoreRpcPoxInfo } from '../../src/core-rpc/client';
2-
import { testnetKeys } from '../../src/api/routes/debug';
32
import {
43
Account,
54
accountFromKey,
@@ -30,9 +29,10 @@ import { StackingClient } from '@stacks/stacking';
3029
import { getPublicKeyFromPrivate } from '@stacks/encryption';
3130
import { hexToBytes } from '@stacks/common';
3231
import { AddressStxBalance } from '../../src/api/schemas/entities/addresses';
32+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
3333

3434
describe('PoX-4 - Delegate Stacking operations', () => {
35-
const seedKey = testnetKeys[4].secretKey;
35+
const seedKey = FAUCET_TESTNET_KEYS[4].secretKey;
3636
const delegatorKey = '72e8e3725324514c38c2931ed337ab9ab8d8abaae83ed2275456790194b1fd3101';
3737
const delegateeKey = '0d174cf0be276cedcf21727611ef2504aed093d8163f65985c07760fda12a7ea01';
3838

tests/2.5/pox-4-stack-extend-increase.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { testnetKeys } from '../../src/api/routes/debug';
21
import { CoreRpcPoxInfo } from '../../src/core-rpc/client';
32
import { getBitcoinAddressFromKey, privateToPublicKey } from '../../src/ec-helpers';
43
import {
@@ -31,9 +30,10 @@ import {
3130
BurnchainRewardSlotHolderListResponse,
3231
} from '../../src/api/schemas/responses/responses';
3332
import { BurnchainRewardsTotal } from '../../src/api/schemas/entities/burnchain-rewards';
33+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
3434

3535
describe('PoX-4 - Stack extend and increase operations', () => {
36-
const account = testnetKeys[1];
36+
const account = FAUCET_TESTNET_KEYS[1];
3737
let btcAddr: string;
3838
let btcAddrRegtest: string;
3939
let btcPubKey: string;

tests/bns-e2e/bns-integration.test.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
noneCV,
1616
} from '@stacks/transactions';
1717
import { logger } from '../../src/logger';
18-
import { testnetKeys } from '../../src/api/routes/debug';
1918
import { PgWriteStore } from '../../src/datastore/pg-write-store';
2019
import { standByForTx as standByForTxShared } from '../utils/test-helpers';
20+
import { FAUCET_TESTNET_KEYS } from 'src/api/routes/faucets';
2121

2222
function hash160(bfr: Buffer): Buffer {
2323
const hash160 = createHash('ripemd160')
@@ -346,7 +346,10 @@ describe('BNS integration tests', () => {
346346
const name = 'alice';
347347
const importZonefile = `$ORIGIN ${name}.${namespace}\n$TTL 3600\n_http._tcp IN URI 10 1 "https://blockstack.s3.amazonaws.com/${name}.${namespace}"\n`;
348348
const namespaceHash = hash160(Buffer.concat([Buffer.from(namespace), salt]));
349-
const testnetKey = { pkey: testnetKeys[0].secretKey, address: testnetKeys[0].stacksAddress };
349+
const testnetKey = {
350+
pkey: FAUCET_TESTNET_KEYS[0].secretKey,
351+
address: FAUCET_TESTNET_KEYS[0].stacksAddress,
352+
};
350353

351354
// initalizing namespace network - preorder and reveal
352355
await initiateNamespaceNetwork(namespace, salt, namespaceHash, testnetKey, 12);
@@ -379,7 +382,10 @@ describe('BNS integration tests', () => {
379382
const name = 'update';
380383
const importZonefile = `$ORIGIN ${name}.${namespace}\n$TTL 3600\n_http._tcp IN URI 10 1 "https://blockstack.s3.amazonaws.com/${name}.${namespace}"\n`;
381384
const namespaceHash = hash160(Buffer.concat([Buffer.from(namespace), salt]));
382-
const testnetKey = { pkey: testnetKeys[1].secretKey, address: testnetKeys[1].stacksAddress };
385+
const testnetKey = {
386+
pkey: FAUCET_TESTNET_KEYS[1].secretKey,
387+
address: FAUCET_TESTNET_KEYS[1].stacksAddress,
388+
};
383389

384390
// initalizing namespace network - preorder and reveal
385391
await initiateNamespaceNetwork(namespace, salt, namespaceHash, testnetKey, 12);
@@ -475,7 +481,10 @@ describe('BNS integration tests', () => {
475481
const namespaceHash = hash160(Buffer.concat([Buffer.from(namespace), salt]));
476482
const zonefile = `$ORIGIN ${name}.${namespace}\n$TTL 3600\n_http._tcp IN URI 10 1 "https://blockstack.s3.amazonaws.com/${name}.${namespace}"\n`;
477483
const importZonefile = `$ORIGIN ${name}.${namespace}\n$TTL 3600\n_http._tcp IN URI 10 1 "https://blockstack.s3.amazonaws.com/${name}.${namespace}"\n`;
478-
const testnetKey = { pkey: testnetKeys[2].secretKey, address: testnetKeys[2].stacksAddress };
484+
const testnetKey = {
485+
pkey: FAUCET_TESTNET_KEYS[2].secretKey,
486+
address: FAUCET_TESTNET_KEYS[2].stacksAddress,
487+
};
479488
// initializing namespace network
480489
await initiateNamespaceNetwork(namespace, salt, namespaceHash, testnetKey, 12);
481490
await namespaceReady(namespace, testnetKey.pkey);
@@ -495,8 +504,8 @@ describe('BNS integration tests', () => {
495504
}
496505
// testing name transfer
497506
const transferTestnetKey = {
498-
pkey: testnetKeys[2].secretKey,
499-
address: testnetKeys[3].stacksAddress,
507+
pkey: FAUCET_TESTNET_KEYS[2].secretKey,
508+
address: FAUCET_TESTNET_KEYS[3].stacksAddress,
500509
};
501510
await nameTransfer(namespace, name, transferTestnetKey);
502511

@@ -512,7 +521,10 @@ describe('BNS integration tests', () => {
512521
const namespace = 'name-revoke';
513522
const name = 'foo';
514523
const namespaceHash = hash160(Buffer.concat([Buffer.from(namespace), salt]));
515-
const testnetKey = { pkey: testnetKeys[4].secretKey, address: testnetKeys[4].stacksAddress };
524+
const testnetKey = {
525+
pkey: FAUCET_TESTNET_KEYS[4].secretKey,
526+
address: FAUCET_TESTNET_KEYS[4].stacksAddress,
527+
};
516528
const zonefile = `$ORIGIN ${name}.${namespace}\n$TTL 3600\n_http._tcp IN URI 10 1 "https://blockstack.s3.amazonaws.com/${name}.${namespace}"\n`;
517529

518530
// initializing namespace network
@@ -532,7 +544,10 @@ describe('BNS integration tests', () => {
532544
const namespace = 'name-renewal';
533545
const name = 'renewal';
534546
const namespaceHash = hash160(Buffer.concat([Buffer.from(namespace), salt]));
535-
const testnetKey = { pkey: testnetKeys[5].secretKey, address: testnetKeys[5].stacksAddress };
547+
const testnetKey = {
548+
pkey: FAUCET_TESTNET_KEYS[5].secretKey,
549+
address: FAUCET_TESTNET_KEYS[5].stacksAddress,
550+
};
536551

537552
// initializing namespace network
538553
await initiateNamespaceNetwork(namespace, salt, namespaceHash, testnetKey, 1);
@@ -572,7 +587,10 @@ describe('BNS integration tests', () => {
572587
const namespace = 'name-renewal2';
573588
const name = 'renewal2';
574589
const namespaceHash = hash160(Buffer.concat([Buffer.from(namespace), salt]));
575-
const testnetKey = { pkey: testnetKeys[5].secretKey, address: testnetKeys[5].stacksAddress };
590+
const testnetKey = {
591+
pkey: FAUCET_TESTNET_KEYS[5].secretKey,
592+
address: FAUCET_TESTNET_KEYS[5].stacksAddress,
593+
};
576594

577595
// initializing namespace network
578596
await initiateNamespaceNetwork(namespace, salt, namespaceHash, testnetKey, 1);

tests/event-replay/raw-event-request.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ describe('Events table', () => {
3232
});
3333

3434
test('If there is an event request error, then the event will not be recorded in the events_observer_request table', async () => {
35-
const getRawEventCount = async () =>
36-
await client<Promise<number>[]>`SELECT count(*) from event_observer_requests`;
35+
const getRawEventCount = async (): Promise<number> => {
36+
const [row] = await client<{ count: string }[]>`SELECT count(*) from event_observer_requests`;
37+
return Number(row.count);
38+
};
3739

3840
await useWithCleanup(
3941
() => {
@@ -60,8 +62,7 @@ describe('Events table', () => {
6062
rawEvent.payload = JSON.stringify(payloadJson);
6163
}
6264
} catch (error) {}
63-
const rawEventRequestCountResultBefore = await getRawEventCount();
64-
const rawEventRequestCountBefore = rawEventRequestCountResultBefore[0];
65+
const rawEventRequestCountBefore = await getRawEventCount();
6566
const response = await httpPostRequest({
6667
host: '127.0.0.1',
6768
port: eventServer.serverAddress.port,
@@ -72,8 +73,7 @@ describe('Events table', () => {
7273
});
7374
if (rawEvent.event_path === '/new_block') {
7475
expect(response.statusCode).toBe(500);
75-
const rawEventRequestCountResultAfter = await getRawEventCount();
76-
const rawEventRequestCountAfter = rawEventRequestCountResultAfter[0];
76+
const rawEventRequestCountAfter = await getRawEventCount();
7777
expect(rawEventRequestCountBefore).toEqual(rawEventRequestCountAfter);
7878
}
7979
}

0 commit comments

Comments
 (0)