Move mocking ship keys to resolver methods
This commit is contained in:
parent
10e7199cb0
commit
f65d60624f
@ -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<ValueResult> {
|
||||
// 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<ValueResult> {
|
||||
// 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.');
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user