1+ import { ExplorerService } from './explorer.service' ;
2+
3+ describe ( 'ExplorerService' , ( ) => {
4+ let explorerService : ExplorerService ;
5+
6+ beforeEach ( ( ) => {
7+ explorerService = new ExplorerService ( ) ;
8+ } ) ;
9+
10+ describe ( 'getTransactionLink' , ( ) => {
11+ it ( 'should return Etherscan link for Ethereum mainnet (chainId: 1)' , ( ) => {
12+ const hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ;
13+ const result = explorerService . getTransactionLink ( 1 , hash ) ;
14+ expect ( result ) . toBe ( 'https://etherscan.io/tx/0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ) ;
15+ } ) ;
16+
17+ it ( 'should return Arbiscan link for Arbitrum (chainId: 42161)' , ( ) => {
18+ const hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ;
19+ const result = explorerService . getTransactionLink ( 42161 , hash ) ;
20+ expect ( result ) . toBe ( 'https://arbiscan.io/tx/0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ) ;
21+ } ) ;
22+
23+ it ( 'should return Optimistic Etherscan link for Optimism (chainId: 10)' , ( ) => {
24+ const hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ;
25+ const result = explorerService . getTransactionLink ( 10 , hash ) ;
26+ expect ( result ) . toBe ( 'https://optimistic.etherscan.io/tx/0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ) ;
27+ } ) ;
28+
29+ it ( 'should return empty string for unknown chain' , ( ) => {
30+ const hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ;
31+ const result = explorerService . getTransactionLink ( 999999 , hash ) ;
32+ expect ( result ) . toBe ( '' ) ;
33+ } ) ;
34+
35+ it ( 'should return empty string for invalid hash format' , ( ) => {
36+ const hash = 'invalid-hash' ;
37+ const result = explorerService . getTransactionLink ( 1 , hash ) ;
38+ expect ( result ) . toBe ( '' ) ;
39+ } ) ;
40+
41+ it ( 'should return empty string for empty hash' , ( ) => {
42+ const result = explorerService . getTransactionLink ( 1 , '' ) ;
43+ expect ( result ) . toBe ( '' ) ;
44+ } ) ;
45+
46+ it ( 'should return empty string for 0x-only hash' , ( ) => {
47+ const result = explorerService . getTransactionLink ( 1 , '0x' ) ;
48+ expect ( result ) . toBe ( '' ) ;
49+ } ) ;
50+
51+ it ( 'should handle undefined chainId gracefully' , ( ) => {
52+ const hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ;
53+ const result = explorerService . getTransactionLink ( undefined as any , hash ) ;
54+ expect ( result ) . toBe ( '' ) ;
55+ } ) ;
56+
57+ it ( 'should handle null chainId gracefully' , ( ) => {
58+ const hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ;
59+ const result = explorerService . getTransactionLink ( null as any , hash ) ;
60+ expect ( result ) . toBe ( '' ) ;
61+ } ) ;
62+ } ) ;
63+
64+ } ) ;
0 commit comments