|
| 1 | +import * as supertest from 'supertest'; |
| 2 | +import { PgSqlClient } from '@hirosystems/api-toolkit'; |
| 3 | +import { ChainID } from '@stacks/common'; |
| 4 | +import { ApiServer, startApiServer } from '../api/init'; |
| 5 | +import { PgWriteStore } from '../datastore/pg-write-store'; |
| 6 | +import { importEventsFromTsv } from '../event-replay/event-replay'; |
| 7 | +import { migrate } from '../test-utils/test-helpers'; |
| 8 | +import { Transaction } from '../api/schemas/entities/transactions'; |
| 9 | +import { TransactionResults } from '../api/schemas/responses/responses'; |
| 10 | +import { AddressTransaction } from '../api/schemas/entities/addresses'; |
| 11 | + |
| 12 | +describe('Out-of-order-multisig tx tests', () => { |
| 13 | + let db: PgWriteStore; |
| 14 | + let client: PgSqlClient; |
| 15 | + let api: ApiServer; |
| 16 | + |
| 17 | + const oooMultiSigTxId = '0xdbc0172e2230a3e9d937762754e407574872f1bc3fdbaf74eb73413433d4ad59'; |
| 18 | + const oooMultiSigSenderAddress = 'SN581ZYV1BAKNXQV95HWS53SB4N3ZVSEPNNCM8ZV'; |
| 19 | + |
| 20 | + beforeAll(async () => { |
| 21 | + await migrate('up'); |
| 22 | + db = await PgWriteStore.connect({ |
| 23 | + usageName: 'tests', |
| 24 | + withNotifier: true, |
| 25 | + skipMigrations: true, |
| 26 | + }); |
| 27 | + client = db.sql; |
| 28 | + api = await startApiServer({ datastore: db, chainId: ChainID.Testnet }); |
| 29 | + |
| 30 | + // set chainId env, because TSV import reads it manually |
| 31 | + process.env['STACKS_CHAIN_ID'] = ChainID.Testnet.toString(); |
| 32 | + }); |
| 33 | + |
| 34 | + afterAll(async () => { |
| 35 | + await api.terminate(); |
| 36 | + await db?.close(); |
| 37 | + await migrate('down'); |
| 38 | + }); |
| 39 | + |
| 40 | + test('tsv replay with out-of-order-multisig tx', async () => { |
| 41 | + await importEventsFromTsv( |
| 42 | + 'src/tests/tsv/regtest-env-pox-4-out-of-order-multisig-tx.tsv', |
| 43 | + 'archival', |
| 44 | + true, |
| 45 | + true |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + test('ooo-multisig tx well formed', async () => { |
| 50 | + const { body: tx }: { body: Transaction } = await supertest(api.server).get( |
| 51 | + `/extended/v1/tx/${oooMultiSigTxId}` |
| 52 | + ); |
| 53 | + expect(tx.tx_id).toBe(oooMultiSigTxId); |
| 54 | + expect(tx.sender_address).toBe(oooMultiSigSenderAddress); |
| 55 | + expect(tx.tx_type).toBe('token_transfer'); |
| 56 | + expect(tx.tx_status).toBe('success'); |
| 57 | + }); |
| 58 | + |
| 59 | + test('lookup tx by sender address', async () => { |
| 60 | + const { body }: { body: TransactionResults } = await supertest(api.server).get( |
| 61 | + `/extended/v1/tx?from_address=${oooMultiSigSenderAddress}` |
| 62 | + ); |
| 63 | + expect(body.results).toEqual( |
| 64 | + expect.arrayContaining([expect.objectContaining({ tx_id: oooMultiSigTxId })]) |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + test('lookup address txs', async () => { |
| 69 | + const { body }: { body: { results: AddressTransaction[] } } = await supertest(api.server).get( |
| 70 | + `/extended/v2/addresses/${oooMultiSigSenderAddress}/transactions` |
| 71 | + ); |
| 72 | + expect(body.results[0].tx).toEqual(expect.objectContaining({ tx_id: oooMultiSigTxId })); |
| 73 | + }); |
| 74 | +}); |
0 commit comments