Skip to content

Commit

Permalink
test: add tests for block query
Browse files Browse the repository at this point in the history
  • Loading branch information
boray committed Jan 10, 2025
1 parent 9e4e7ce commit fdaace2
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
ActionOutput,
EventData,
EventOutput,
MaxBlockHeightInfo,
Maybe,
} from 'src/resolvers-types.js';

Expand All @@ -47,6 +48,9 @@ interface ExecutorResult {
}
| {
actions: Array<ActionOutput>;
}
| {
block: MaxBlockHeightInfo;
};
}

Expand All @@ -62,6 +66,12 @@ interface ActionQueryResult extends ExecutorResult {
};
}

interface BlockQueryResult extends ExecutorResult {
data: {
block: MaxBlockHeightInfo;
};
}

const eventsQuery = `
query getEvents($input: EventFilterOptionsInput!) {
events(input: $input) {
Expand Down Expand Up @@ -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 ';

Expand All @@ -131,6 +150,9 @@ interface ExecutorResult {
}
| {
actions: Array<ActionOutput>;
}
| {
block: MaxBlockHeightInfo;
};
}

Expand All @@ -146,6 +168,12 @@ interface ActionQueryResult extends ExecutorResult {
};
}

interface BlockQueryResult extends ExecutorResult {
data: {
block: MaxBlockHeightInfo;
};
}

describe('Query Resolvers', async () => {
let executor: AsyncExecutor<GraphQLContext, HTTPExecutorOptions>;
let senderKeypair: Keypair;
Expand Down Expand Up @@ -174,6 +202,12 @@ describe('Query Resolvers', async () => {
})) as EventQueryResult;
}

async function executeBlockQuery(): Promise<BlockQueryResult> {
return (await executor({
document: parse(`${blockQuery}`),
})) as BlockQueryResult;
}

before(async () => {
try {
setNetworkConfig();
Expand Down Expand Up @@ -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<EventData>[];
Expand Down Expand Up @@ -508,8 +561,11 @@ describe('Query Resolvers', async () => {
});
});
});


});


function structToAction(s: TestStruct) {
return [
s.x.toString(),
Expand Down

0 comments on commit fdaace2

Please sign in to comment.