diff --git a/tests/resolvers.test.ts b/tests/resolvers.test.ts index dd64749..d64eb5b 100644 --- a/tests/resolvers.test.ts +++ b/tests/resolvers.test.ts @@ -37,6 +37,7 @@ import { ActionOutput, EventData, EventOutput, + MaxBlockHeightInfo, Maybe, } from 'src/resolvers-types.js'; @@ -47,6 +48,9 @@ interface ExecutorResult { } | { actions: Array; + } + | { + block: MaxBlockHeightInfo; }; } @@ -62,6 +66,12 @@ interface ActionQueryResult extends ExecutorResult { }; } +interface BlockQueryResult extends ExecutorResult { + data: { + block: MaxBlockHeightInfo; + }; +} + const eventsQuery = ` query getEvents($input: EventFilterOptionsInput!) { events(input: $input) { @@ -121,6 +131,15 @@ query getActions($input: ActionFilterOptionsInput!) { } `; +const blockQuery = ` +query maxBlockHeightInfo { + block { + canonicalMaxBlockHeight + pendingMaxBlockHeight + } +} +`; + // This is the default connection string provided by the lightnet postgres container const PG_CONN = 'postgresql://postgres:postgres@localhost:5432/archive '; @@ -131,6 +150,9 @@ interface ExecutorResult { } | { actions: Array; + } + | { + block: MaxBlockHeightInfo; }; } @@ -146,6 +168,12 @@ interface ActionQueryResult extends ExecutorResult { }; } +interface BlockQueryResult extends ExecutorResult { + data: { + block: MaxBlockHeightInfo; + }; +} + describe('Query Resolvers', async () => { let executor: AsyncExecutor; let senderKeypair: Keypair; @@ -174,6 +202,12 @@ describe('Query Resolvers', async () => { })) as EventQueryResult; } + async function executeBlockQuery(): Promise { + return (await executor({ + document: parse(`${blockQuery}`), + })) as BlockQueryResult; + } + before(async () => { try { setNetworkConfig(); @@ -216,6 +250,25 @@ describe('Query Resolvers', async () => { process.exit(0); }); + describe("Block", async () => { + let blockResponse: MaxBlockHeightInfo; + let results: BlockQueryResult; + + test("Fetching the max block height should not throw", async () => { + assert.doesNotThrow(async () => { + await executeBlockQuery(); + }); + }); + + test("Fetching the max block height should return the max block height", async () => { + results = await executeBlockQuery(); + blockResponse = results.data.block; + assert.ok(blockResponse.canonicalMaxBlockHeight > 0); + assert.ok(blockResponse.pendingMaxBlockHeight > 0); + }); + + }); + describe('Events', async () => { let eventsResponse: EventOutput[]; let lastBlockEvents: Maybe[]; @@ -508,8 +561,11 @@ describe('Query Resolvers', async () => { }); }); }); + + }); + function structToAction(s: TestStruct) { return [ s.x.toString(),