1
1
import * as supertest from 'supertest' ;
2
- import { PgSqlClient } from '@hirosystems/api-toolkit' ;
2
+ import { PgSqlClient , timeout } from '@hirosystems/api-toolkit' ;
3
3
import { ChainID } from '@stacks/common' ;
4
4
import { ApiServer , startApiServer } from '../api/init' ;
5
5
import { PgWriteStore } from '../datastore/pg-write-store' ;
@@ -19,7 +19,10 @@ describe('PoX tests', () => {
19
19
skipMigrations : true ,
20
20
} ) ;
21
21
client = db . sql ;
22
- api = await startApiServer ( { datastore : db , chainId : ChainID . Mainnet } ) ;
22
+ api = await startApiServer ( { datastore : db , chainId : ChainID . Testnet } ) ;
23
+
24
+ // set chainId env, because TSV import reads it manually
25
+ process . env [ 'STACKS_CHAIN_ID' ] = ChainID . Testnet . toString ( ) ;
23
26
} ) ;
24
27
25
28
afterEach ( async ( ) => {
@@ -147,12 +150,168 @@ describe('PoX tests', () => {
147
150
offset : 0 ,
148
151
results : [
149
152
{
150
- pox_address : '15Z2sAvjgVDpcBh4vx9g2XKU8FVHYcXNaj ' ,
153
+ pox_address : 'mk4zAE1iVWf5PJAgeX83rSXnzF5zQBiqf1 ' ,
151
154
stacked_amount : '686251350000000000' ,
152
155
stacker_address : 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP' ,
153
156
} ,
154
157
] ,
155
158
total : 1 ,
156
159
} ) ;
157
160
} ) ;
161
+
162
+ describe ( 'regtest-env stack-stx in-reward-phase' , ( ) => {
163
+ // TEST CASE
164
+ // steph (STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6) stacks (using signer 029fb154a570a1645af3dd43c3c668a979b59d21a46dd717fd799b13be3b2a0dc7)
165
+ //
166
+ // current cycle: 5
167
+ // stephs stacks
168
+ // snapshot 1
169
+ // wait for prepare phase (i.e. pox-anchor block mined)
170
+ // snapshot 2
171
+ // wait for cycle 6
172
+ // snapshot 3
173
+
174
+ test ( 'snapshot 1' , async ( ) => {
175
+ await importEventsFromTsv (
176
+ 'src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S1.tsv' ,
177
+ 'archival' ,
178
+ true ,
179
+ true
180
+ ) ;
181
+
182
+ const cycles = await supertest ( api . server ) . get ( `/extended/v2/pox/cycles` ) ;
183
+ expect ( cycles . status ) . toBe ( 200 ) ;
184
+ expect ( cycles . type ) . toBe ( 'application/json' ) ;
185
+ expect ( JSON . parse ( cycles . text ) . results . length ) . toBe ( 0 ) ; // regtest doesn't send pox-set earlier
186
+ } ) ;
187
+
188
+ test ( 'snapshot 2' , async ( ) => {
189
+ await importEventsFromTsv (
190
+ 'src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S2.tsv' ,
191
+ 'archival' ,
192
+ true ,
193
+ true
194
+ ) ;
195
+
196
+ const cycles = await supertest ( api . server ) . get ( `/extended/v2/pox/cycles` ) ;
197
+ expect ( cycles . status ) . toBe ( 200 ) ;
198
+ expect ( cycles . type ) . toBe ( 'application/json' ) ;
199
+ expect ( JSON . parse ( cycles . text ) . results [ 0 ] ) . toEqual (
200
+ expect . objectContaining ( {
201
+ cycle_number : 6 , // !!! next cycle (even though we're still in cycle 5)
202
+ total_signers : 3 , // no addition signer
203
+ total_weight : 21 , // additional weight from steph's stacking
204
+ } )
205
+ ) ;
206
+ } ) ;
207
+
208
+ test ( 'snapshot 3' , async ( ) => {
209
+ await importEventsFromTsv (
210
+ 'src/tests/tsv/regtest-env-pox-4-stack-stx-in-reward-phase-S3.tsv' ,
211
+ 'archival' ,
212
+ true ,
213
+ true
214
+ ) ;
215
+
216
+ const cycles = await supertest ( api . server ) . get ( `/extended/v2/pox/cycles` ) ;
217
+ expect ( cycles . status ) . toBe ( 200 ) ;
218
+ expect ( cycles . type ) . toBe ( 'application/json' ) ;
219
+ expect ( JSON . parse ( cycles . text ) ) . toStrictEqual ( {
220
+ limit : 20 ,
221
+ offset : 0 ,
222
+ results : [
223
+ {
224
+ block_height : 14 ,
225
+ cycle_number : 6 , // current cycle
226
+ index_block_hash : '0xb2c9e06611349a04e98012748547a5dea6d60fd6d69e43244b9c0a483f1f7c86' ,
227
+ total_signers : 3 ,
228
+ total_stacked_amount : '17501190000000000' ,
229
+ total_weight : 21 ,
230
+ } ,
231
+ ] ,
232
+ total : 1 ,
233
+ } ) ;
234
+
235
+ const cycle = await supertest ( api . server ) . get ( `/extended/v2/pox/cycles/6` ) ;
236
+ expect ( cycle . status ) . toBe ( 200 ) ;
237
+ expect ( cycle . type ) . toBe ( 'application/json' ) ;
238
+ expect ( JSON . parse ( cycle . text ) ) . toStrictEqual ( {
239
+ block_height : 14 ,
240
+ cycle_number : 6 ,
241
+ index_block_hash : '0xb2c9e06611349a04e98012748547a5dea6d60fd6d69e43244b9c0a483f1f7c86' ,
242
+ total_signers : 3 ,
243
+ total_stacked_amount : '17501190000000000' ,
244
+ total_weight : 21 ,
245
+ } ) ;
246
+
247
+ const signers = await supertest ( api . server ) . get ( `/extended/v2/pox/cycles/6/signers` ) ;
248
+ expect ( signers . status ) . toBe ( 200 ) ;
249
+ expect ( signers . type ) . toBe ( 'application/json' ) ;
250
+ expect ( JSON . parse ( signers . text ) ) . toStrictEqual ( {
251
+ limit : 100 ,
252
+ offset : 0 ,
253
+ results : [
254
+ {
255
+ signing_key : '0x028efa20fa5706567008ebaf48f7ae891342eeb944d96392f719c505c89f84ed8d' ,
256
+ stacked_amount : '7500510000000000' ,
257
+ stacked_amount_percent : 42.857142857142854 ,
258
+ weight : 9 ,
259
+ weight_percent : 42.857142857142854 ,
260
+ } ,
261
+ {
262
+ signing_key : '0x023f19d77c842b675bd8c858e9ac8b0ca2efa566f17accf8ef9ceb5a992dc67836' ,
263
+ stacked_amount : '5000340000000000' ,
264
+ stacked_amount_percent : 28.571428571428573 ,
265
+ weight : 6 ,
266
+ weight_percent : 28.57142857142857 ,
267
+ } ,
268
+ {
269
+ // steph doubled the weight of this signer
270
+ signing_key : '0x029fb154a570a1645af3dd43c3c668a979b59d21a46dd717fd799b13be3b2a0dc7' ,
271
+ stacked_amount : '5000340000000000' ,
272
+ stacked_amount_percent : 28.571428571428573 ,
273
+ weight : 6 ,
274
+ weight_percent : 28.57142857142857 ,
275
+ } ,
276
+ ] ,
277
+ total : 3 ,
278
+ } ) ;
279
+
280
+ const signer = await supertest ( api . server ) . get (
281
+ `/extended/v2/pox/cycles/6/signers/0x029fb154a570a1645af3dd43c3c668a979b59d21a46dd717fd799b13be3b2a0dc7`
282
+ ) ;
283
+ expect ( signer . status ) . toBe ( 200 ) ;
284
+ expect ( signer . type ) . toBe ( 'application/json' ) ;
285
+ expect ( JSON . parse ( signer . text ) ) . toStrictEqual ( {
286
+ signing_key : '0x029fb154a570a1645af3dd43c3c668a979b59d21a46dd717fd799b13be3b2a0dc7' ,
287
+ stacked_amount : '5000340000000000' ,
288
+ stacked_amount_percent : 28.571428571428573 ,
289
+ weight : 6 ,
290
+ weight_percent : 28.57142857142857 ,
291
+ } ) ;
292
+
293
+ const stackers = await supertest ( api . server ) . get (
294
+ `/extended/v2/pox/cycles/6/signers/0x029fb154a570a1645af3dd43c3c668a979b59d21a46dd717fd799b13be3b2a0dc7/stackers`
295
+ ) ;
296
+ expect ( stackers . status ) . toBe ( 200 ) ;
297
+ expect ( stackers . type ) . toBe ( 'application/json' ) ;
298
+ expect ( JSON . parse ( stackers . text ) ) . toStrictEqual ( {
299
+ limit : 100 ,
300
+ offset : 0 ,
301
+ results : [
302
+ {
303
+ pox_address : 'n2v875jbJ4RjBnTjgbfikDfnwsDV5iUByw' ,
304
+ stacked_amount : '2500170000000000' ,
305
+ stacker_address : 'ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP' , // signer
306
+ } ,
307
+ {
308
+ pox_address : 'mhYeZXrSEuyf2wbJ14qZ2apG7ofMLDj9Ss' ,
309
+ stacked_amount : '2500170000000000' ,
310
+ stacker_address : 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6' , // steph
311
+ } ,
312
+ ] ,
313
+ total : 2 ,
314
+ } ) ;
315
+ } ) ;
316
+ } ) ;
158
317
} ) ;
0 commit comments