Skip to content

Commit

Permalink
fix: chainhook client upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Jul 3, 2023
1 parent 7f853bc commit 9a96492
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 59 deletions.
76 changes: 46 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
"@fastify/multipart": "^7.1.0",
"@fastify/swagger": "^8.3.1",
"@fastify/type-provider-typebox": "^3.2.0",
"@hirosystems/chainhook-client": "^1.0.3",
"@sinclair/typebox": "^0.28.17",
"@hirosystems/chainhook-client": "^1.3.1",
"@types/node": "^18.13.0",
"bignumber.js": "^9.1.1",
"bitcoinjs-lib": "^6.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/chainhook/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function startChainhookServer(args: { db: PgStore }): Promise<Chain
port: ENV.EVENT_PORT,
auth_token: ENV.CHAINHOOK_NODE_AUTH_TOKEN,
external_base_url: `http://${ENV.EXTERNAL_HOSTNAME}`,
wait_for_chainhook_node: ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION,
validate_chainhook_payloads: true,
body_limit: 41943040, // 40MB
};
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class TestChainhookPayloadBuilder {
};
private action: 'apply' | 'rollback' = 'apply';
private get lastBlock(): BitcoinEvent {
return this.payload[this.action][this.payload[this.action].length - 1];
return this.payload[this.action][this.payload[this.action].length - 1] as BitcoinEvent;
}
private get lastBlockTx(): BitcoinTransaction {
return this.lastBlock.transactions[this.lastBlock.transactions.length - 1];
Expand Down
32 changes: 6 additions & 26 deletions tests/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MockAgent, setGlobalDispatcher } from 'undici';
import { CHAINHOOK_BASE_PATH, PREDICATE_UUID, startChainhookServer } from '../src/chainhook/server';
import { MockAgent } from 'undici';
import { PREDICATE_UUID, startChainhookServer } from '../src/chainhook/server';
import { ENV } from '../src/env';
import { cycleMigrations } from '../src/pg/migrations';
import { PgStore } from '../src/pg/pg-store';
Expand All @@ -8,41 +8,21 @@ import { ChainhookEventObserver, Payload } from '@hirosystems/chainhook-client';

describe('EventServer', () => {
let db: PgStore;
let server: ChainhookEventObserver;

beforeEach(async () => {
db = await PgStore.connect({ skipMigrations: true });
await cycleMigrations();
ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION = false;
server = await startChainhookServer({ db });
});

afterEach(async () => {
await db.close();
await server.close();
});

describe('parser', () => {
let server: ChainhookEventObserver;
let agent: MockAgent;

beforeEach(async () => {
agent = new MockAgent();
agent.disableNetConnect();
const interceptor = agent.get(CHAINHOOK_BASE_PATH);
interceptor.intercept({ path: '/ping', method: 'GET' }).reply(200);
interceptor.intercept({ path: '/v1/chainhooks', method: 'POST' }).reply(200).times(2);
interceptor
.intercept({
path: `/v1/chainhooks/bitcoin/${PREDICATE_UUID}`,
method: 'DELETE',
})
.reply(200);
setGlobalDispatcher(agent);
server = await startChainhookServer({ db });
});

afterEach(async () => {
await server.close();
await agent.close();
});

test('parses inscription_reveal apply and rollback', async () => {
const reveal = {
block_identifier: {
Expand Down

0 comments on commit 9a96492

Please sign in to comment.