-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage. Update more comments
- Loading branch information
Showing
7 changed files
with
88 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 20 additions & 18 deletions
38
typescript/ccip-server/src/services/__mocks__/HyperlaneService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import { MessageTx } from 'hyperlane-explorer/src/types'; | ||
|
||
const BLOCK: MessageTx = { | ||
timestamp: 123456789, | ||
hash: '0x123abc456def789', | ||
from: '0x9876543210abcdef', | ||
to: '0xabcdef0123456789', | ||
blockHash: '0x456789abc123def', | ||
blockNumber: 12345, | ||
mailbox: '0xabcdef0123456789', | ||
nonce: 0, | ||
gasLimit: 1000000, | ||
gasPrice: 100, | ||
effectiveGasPrice: 90, | ||
gasUsed: 50000, | ||
cumulativeGasUsed: 1234567, | ||
maxFeePerGas: 150, | ||
maxPriorityPerGas: 100, | ||
}; | ||
|
||
class HyperlaneService { | ||
async getOriginBlockByMessageId(id: string): Promise<MessageTx> { | ||
return { | ||
timestamp: 123456789, | ||
hash: '0x123abc456def789', | ||
from: '0x9876543210abcdef', | ||
to: '0xabcdef0123456789', | ||
blockHash: '0x456789abc123def', | ||
blockNumber: 12345, | ||
mailbox: '0xabcdef0123456789', | ||
nonce: 0, | ||
gasLimit: 1000000, | ||
gasPrice: 100, | ||
effectiveGasPrice: 90, | ||
gasUsed: 50000, | ||
cumulativeGasUsed: 1234567, | ||
maxFeePerGas: 150, | ||
maxPriorityPerGas: 100, | ||
}; | ||
return BLOCK; | ||
} | ||
} | ||
|
||
export { HyperlaneService }; | ||
export { HyperlaneService, BLOCK }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 37 additions & 4 deletions
41
typescript/ccip-server/tests/services/HyperlaneService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,51 @@ | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { describe, expect, jest, test } from '@jest/globals'; | ||
import { Spied } from 'jest-mock'; | ||
|
||
import { HyperlaneService } from '../../src/services/HyperlaneService'; | ||
|
||
describe('HyperlaneServiceTest', () => { | ||
let hyperlaneService: HyperlaneService; | ||
let fetchSpied: Spied<typeof fetch>; | ||
beforeEach(() => { | ||
hyperlaneService = new HyperlaneService( | ||
'https://explorer.hyperlane.xyz/api', | ||
); | ||
|
||
fetchSpied = jest.spyOn(global, 'fetch'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
test('should get the block by messageId', async () => { | ||
await hyperlaneService.getOriginBlockByMessageId( | ||
test('should get the block timestamp by messageId', async () => { | ||
const block = await hyperlaneService.getOriginBlockByMessageId( | ||
'0xb0430e396f4014883c01bb3ee43df17ce93d8257a0a0b5778d9d3229a1bf02bb', | ||
); | ||
expect(true).toBe(true); | ||
expect(block.timestamp).toBe(1708538979000); | ||
}); | ||
|
||
test('should throw if messageId does not exist', async () => { | ||
const badMessageId = '10xdeadbeef'; | ||
try { | ||
await hyperlaneService.getOriginBlockByMessageId(badMessageId); | ||
} catch (e: any) { | ||
expect(e.message).toBe(`No message found for id: ${badMessageId}`); | ||
} | ||
}); | ||
|
||
test('should throw an error if module or action no longer exists', async () => { | ||
fetchSpied.mockImplementation(() => | ||
Promise.resolve({ | ||
status: 200, | ||
json: async () => ({ status: 0, message: 'Invalid module or action' }), | ||
} as Response), | ||
); | ||
try { | ||
await hyperlaneService.getOriginBlockByMessageId( | ||
'0xb0430e396f4014883c01bb3ee43df17ce93d8257a0a0b5778d9d3229a1bf02bb', | ||
); | ||
} catch (e: any) { | ||
expect(e.message).toBe('Invalid module or action'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters