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/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,