From 10e7199cb0a0add0128539c0ba30b460d1a966d8 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Mon, 24 Nov 2025 14:10:15 +0530 Subject: [PATCH 1/2] Add flag to enable mocking ship keys --- .../azimuth-watcher/environments/local.toml | 3 ++ packages/azimuth-watcher/src/indexer.ts | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/azimuth-watcher/environments/local.toml b/packages/azimuth-watcher/environments/local.toml index ea5a5f1..ba8d343 100644 --- a/packages/azimuth-watcher/environments/local.toml +++ b/packages/azimuth-watcher/environments/local.toml @@ -30,6 +30,9 @@ # Flag to enable injecting mock events for testing enableMockEvents = false + # Flag to enable mocking ship keys for testing + enableMockShipKeys = false + # GQL cache settings [server.gql.cache] enabled = true diff --git a/packages/azimuth-watcher/src/indexer.ts b/packages/azimuth-watcher/src/indexer.ts index b82ab98..5442747 100644 --- a/packages/azimuth-watcher/src/indexer.ts +++ b/packages/azimuth-watcher/src/indexer.ts @@ -48,6 +48,12 @@ const JSONbigNative = JSONbig({ useNativeBigInt: true }); const KIND_AZIMUTH = 'Azimuth'; +// Mock ship keys environment variables +const TEST_MOCK_POINT = process.env.TEST_MOCK_POINT; +const TEST_MOCK_ENCRYPTION_KEY = process.env.TEST_MOCK_ENCRYPTION_KEY; +const TEST_MOCK_AUTHENTICATION_KEY = process.env.TEST_MOCK_AUTHENTICATION_KEY; +const TEST_MOCK_LIFE = process.env.TEST_MOCK_LIFE; + export class Indexer implements IndexerInterface { _db: Database; _ethClient: EthClient; @@ -128,6 +134,18 @@ export class Indexer implements IndexerInterface { } async isActive (blockHash: string, contractAddress: string, _point: bigint): Promise { + // Check if we should return mocked active status for this point + const mockShipKeysEnabled = (this._serverConfig.gql as any).enableMockShipKeys; + const shouldMock = mockShipKeysEnabled && TEST_MOCK_POINT && _point === BigInt(TEST_MOCK_POINT); + + if (shouldMock) { + log('isActive: returning mocked value (true) for point:', _point.toString()); + return { + value: true, + proof: undefined + }; + } + const entity = await this._db.getIsActive({ blockHash, contractAddress, _point }); if (entity) { log('isActive: db hit.'); @@ -158,6 +176,23 @@ export class Indexer implements IndexerInterface { } async getKeys (blockHash: string, contractAddress: string, _point: bigint): Promise { + // Check if we should return mocked keys for this point + const mockShipKeysEnabled = (this._serverConfig.gql as any).enableMockShipKeys; + const shouldMock = mockShipKeysEnabled && TEST_MOCK_POINT && _point === BigInt(TEST_MOCK_POINT) && TEST_MOCK_ENCRYPTION_KEY && TEST_MOCK_AUTHENTICATION_KEY && TEST_MOCK_LIFE; + + if (shouldMock) { + log('getKeys: returning mocked keys for point:', _point.toString()); + return { + value: { + value0: TEST_MOCK_ENCRYPTION_KEY, + value1: TEST_MOCK_AUTHENTICATION_KEY, + value2: BigInt(0), + value3: BigInt(TEST_MOCK_LIFE) + }, + proof: undefined + }; + } + const entity = await this._db.getGetKeys({ blockHash, contractAddress, _point }); if (entity) { log('getKeys: db hit.'); -- 2.45.2 From f65d60624f893ce3270d50fddc43f8deef1fffe8 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Fri, 28 Nov 2025 12:20:44 +0530 Subject: [PATCH 2/2] Move mocking ship keys to resolver methods --- packages/azimuth-watcher/src/indexer.ts | 35 ----------------------- packages/azimuth-watcher/src/resolvers.ts | 34 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/packages/azimuth-watcher/src/indexer.ts b/packages/azimuth-watcher/src/indexer.ts index 5442747..b82ab98 100644 --- a/packages/azimuth-watcher/src/indexer.ts +++ b/packages/azimuth-watcher/src/indexer.ts @@ -48,12 +48,6 @@ const JSONbigNative = JSONbig({ useNativeBigInt: true }); const KIND_AZIMUTH = 'Azimuth'; -// Mock ship keys environment variables -const TEST_MOCK_POINT = process.env.TEST_MOCK_POINT; -const TEST_MOCK_ENCRYPTION_KEY = process.env.TEST_MOCK_ENCRYPTION_KEY; -const TEST_MOCK_AUTHENTICATION_KEY = process.env.TEST_MOCK_AUTHENTICATION_KEY; -const TEST_MOCK_LIFE = process.env.TEST_MOCK_LIFE; - export class Indexer implements IndexerInterface { _db: Database; _ethClient: EthClient; @@ -134,18 +128,6 @@ export class Indexer implements IndexerInterface { } async isActive (blockHash: string, contractAddress: string, _point: bigint): Promise { - // Check if we should return mocked active status for this point - const mockShipKeysEnabled = (this._serverConfig.gql as any).enableMockShipKeys; - const shouldMock = mockShipKeysEnabled && TEST_MOCK_POINT && _point === BigInt(TEST_MOCK_POINT); - - if (shouldMock) { - log('isActive: returning mocked value (true) for point:', _point.toString()); - return { - value: true, - proof: undefined - }; - } - const entity = await this._db.getIsActive({ blockHash, contractAddress, _point }); if (entity) { log('isActive: db hit.'); @@ -176,23 +158,6 @@ export class Indexer implements IndexerInterface { } async getKeys (blockHash: string, contractAddress: string, _point: bigint): Promise { - // Check if we should return mocked keys for this point - const mockShipKeysEnabled = (this._serverConfig.gql as any).enableMockShipKeys; - const shouldMock = mockShipKeysEnabled && TEST_MOCK_POINT && _point === BigInt(TEST_MOCK_POINT) && TEST_MOCK_ENCRYPTION_KEY && TEST_MOCK_AUTHENTICATION_KEY && TEST_MOCK_LIFE; - - if (shouldMock) { - log('getKeys: returning mocked keys for point:', _point.toString()); - return { - value: { - value0: TEST_MOCK_ENCRYPTION_KEY, - value1: TEST_MOCK_AUTHENTICATION_KEY, - value2: BigInt(0), - value3: BigInt(TEST_MOCK_LIFE) - }, - proof: undefined - }; - } - const entity = await this._db.getGetKeys({ blockHash, contractAddress, _point }); if (entity) { log('getKeys: db hit.'); diff --git a/packages/azimuth-watcher/src/resolvers.ts b/packages/azimuth-watcher/src/resolvers.ts index b7c3828..8f8ebb2 100644 --- a/packages/azimuth-watcher/src/resolvers.ts +++ b/packages/azimuth-watcher/src/resolvers.ts @@ -27,6 +27,12 @@ import { mockEventStore, MockEventInput } from './mock-event-store'; const log = debug('vulcanize:resolver'); +// Mock ship keys environment variables +const TEST_MOCK_POINT = process.env.TEST_MOCK_POINT; +const TEST_MOCK_ENCRYPTION_KEY = process.env.TEST_MOCK_ENCRYPTION_KEY; +const TEST_MOCK_AUTHENTICATION_KEY = process.env.TEST_MOCK_AUTHENTICATION_KEY; +const TEST_MOCK_LIFE = process.env.TEST_MOCK_LIFE; + const executeAndRecordMetrics = async ( indexer: Indexer, gqlLogger: winston.Logger, @@ -80,6 +86,7 @@ export const createResolvers = async ( // eslint-disable-next-line @typescript-eslint/no-unused-vars const gqlConfig = indexer.serverConfig.gql; + const mockShipKeysEnabled = (gqlConfig as any).enableMockShipKeys; return { BigInt: GraphQLBigInt, @@ -134,6 +141,17 @@ export const createResolvers = async ( // Set cache-control hints // setGQLCacheHints(info, {}, gqlCacheConfig); + // Check if we should return mocked active status for this point + const shouldMock = mockShipKeysEnabled && TEST_MOCK_POINT && _point === BigInt(TEST_MOCK_POINT); + + if (shouldMock) { + log('isActive: returning mocked value (true) for point:', _point.toString()); + return Promise.resolve({ + value: true, + proof: undefined + }); + } + return executeAndRecordMetrics( indexer, gqlLogger, @@ -156,6 +174,22 @@ export const createResolvers = async ( // Set cache-control hints // setGQLCacheHints(info, {}, gqlCacheConfig); + // Check if we should return mocked keys for this point + const shouldMock = mockShipKeysEnabled && TEST_MOCK_POINT && _point === BigInt(TEST_MOCK_POINT); + + if (shouldMock) { + log('getKeys: returning mocked keys for point:', _point.toString()); + return Promise.resolve({ + value: { + value0: TEST_MOCK_ENCRYPTION_KEY, + value1: TEST_MOCK_AUTHENTICATION_KEY, + value2: BigInt(0), + value3: BigInt(TEST_MOCK_LIFE ?? 1) + }, + proof: undefined + }); + } + return executeAndRecordMetrics( indexer, gqlLogger, -- 2.45.2