|
1 | 1 | import { readFileSync } from 'node:fs';
|
2 | 2 | import { join } from 'node:path';
|
3 | 3 |
|
| 4 | +import { createSha256Hash, serializePlainObject } from '@api3/commons'; |
4 | 5 | import * as promiseUtilsModule from '@api3/promise-utils';
|
| 6 | +import { ethers } from 'ethers'; |
5 | 7 |
|
6 | 8 | import packageJson from '../../package.json';
|
7 | 9 | import { config, verifyHeartbeatLog } from '../../test/fixtures';
|
8 | 10 | import * as stateModule from '../state';
|
9 | 11 | import * as configModule from '../validation/config';
|
10 | 12 |
|
| 13 | +import { signHeartbeat } from './heartbeat-utils'; |
11 | 14 | import { heartbeatLogger } from './logger';
|
12 | 15 |
|
13 | 16 | import { initiateHeartbeatLoop, logHeartbeat } from '.';
|
@@ -46,29 +49,34 @@ describe(logHeartbeat.name, () => {
|
46 | 49 | });
|
47 | 50 |
|
48 | 51 | describe(verifyHeartbeatLog.name, () => {
|
49 |
| - it('heartbeat payload can be parsed from JSON log', () => { |
| 52 | + it('heartbeat payload can be parsed from JSON log', async () => { |
| 53 | + const rawConfig = JSON.parse(readFileSync(join(__dirname, '../../config/airnode-feed.example.json'), 'utf8')); |
| 54 | + const serializedConfig = serializePlainObject(rawConfig); |
| 55 | + const configHash = createSha256Hash(serializedConfig); |
| 56 | + const unsignedPayload = { |
| 57 | + airnode: '0xbF3137b0a7574563a23a8fC8badC6537F98197CC', |
| 58 | + configHash, |
| 59 | + currentTimestamp: '1674172803', |
| 60 | + deploymentTimestamp: '1674172800', |
| 61 | + nodeVersion: '0.1.0', |
| 62 | + stage: 'test', |
| 63 | + }; |
| 64 | + const signature = await signHeartbeat( |
| 65 | + ethers.Wallet.fromMnemonic('diamond result history offer forest diagram crop armed stumble orchard stage glance'), |
| 66 | + unsignedPayload |
| 67 | + ); |
50 | 68 | const jsonLog = {
|
51 | 69 | context: {
|
52 |
| - airnode: '0xbF3137b0a7574563a23a8fC8badC6537F98197CC', |
53 |
| - configHash: '0x0a36630da26fa987561ff8b692f2015a6fe632bdabcf3dcdd010ccc8262f4a3a', |
54 |
| - currentTimestamp: '1674172803', |
55 |
| - deploymentTimestamp: '1674172800', |
56 |
| - nodeVersion: '0.1.0', |
57 |
| - signature: |
58 |
| - '0x15fb32178d3c6e30385e448b21a4b9086c715a11e8044513bf3b6a578643f7a327498b59cc3d9442fbd2f3b3b4991f94398727e54558ac24871e2df44d1664e11c', |
59 |
| - stage: 'test', |
| 70 | + ...unsignedPayload, |
| 71 | + signature, |
60 | 72 | },
|
61 | 73 | level: 'info',
|
62 | 74 | message: 'Sending heartbeat log',
|
63 | 75 | ms: '+0ms',
|
64 | 76 | timestamp: '2023-01-20T00:00:03.000Z',
|
65 | 77 | };
|
66 |
| - // The config hash was taken from the example config at a certain version with all spaces removed. |
67 |
| - const rawConfig = JSON.parse(readFileSync(join(__dirname, '../../config/airnode-feed.example.json'), 'utf8')); |
68 |
| - rawConfig.nodeSettings.nodeVersion = '0.1.0'; |
69 |
| - const stringifiedConfig = JSON.stringify(rawConfig); |
70 | 78 |
|
71 |
| - expect(() => verifyHeartbeatLog(jsonLog.context, stringifiedConfig)).not.toThrow(); |
| 79 | + expect(() => verifyHeartbeatLog(jsonLog.context, serializedConfig)).not.toThrow(); |
72 | 80 | });
|
73 | 81 | });
|
74 | 82 |
|
|
0 commit comments