Mock ship keys for usage in e2e tests #9

Merged
prathamesh merged 2 commits from deep-stack/azimuth-watcher-ts:sk-mock-ship-keys into main 2025-11-28 10:07:58 +00:00
2 changed files with 38 additions and 0 deletions
Showing only changes of commit 10e7199cb0 - Show all commits
@@ -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
+35
View File
@@ -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<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.');
@@ -158,6 +176,23 @@ 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.');