• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cowprotocol / cow-sdk / 14001954831

21 Mar 2025 10:26PM UTC coverage: 73.659% (-3.4%) from 77.101%
14001954831

Pull #253

github

anxolin
chore: improve signatures
Pull Request #253: feat(bridging): get quote + post cross-chain swap

392 of 552 branches covered (71.01%)

Branch coverage included in aggregate %.

41 of 126 new or added lines in 16 files covered. (32.54%)

23 existing lines in 5 files now uncovered.

844 of 1126 relevant lines covered (74.96%)

16.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/bridging/providers/mock/MockBridgeProvider.ts
1
/* eslint-disable @typescript-eslint/no-unused-vars */
2
import {
3
  BridgeDeposit,
4
  BridgeHook,
5
  BridgeProvider,
6
  BridgeProviderInfo,
7
  BridgeQuoteResult,
8
  BridgeStatus,
9
  BridgeStatusResult,
10
  GetBuyTokensParams,
11
  QuoteBridgeRequest,
12
} from '../../types'
13

14
import { OrderKind } from '../../../order-book'
15
import { mainnet } from '../../../chains/details/mainnet'
16
import { optimism } from '../../../chains/details/optimism'
17
import { sepolia } from '../../../chains/details/sepolia'
18
import { EvmCall, TokenInfo } from '../../../common'
19
import { ChainInfo, SupportedChainId } from '../../../chains'
20
import { RAW_PROVIDERS_FILES_PATH } from '../../const'
21
import { Signer } from '@ethersproject/abstract-signer'
22

23
const BRIDGING_ID = '123456789asdfg'
×
NEW
UNCOV
24
const MOCK_CALL: EvmCall = {
×
25
  to: '0x0000000000000000000000000000000000000001',
26
  data: '0x0',
27
  value: BigInt(0),
28
}
29

30
export class MockBridgeProvider implements BridgeProvider<BridgeQuoteResult> {
31
  info: BridgeProviderInfo = {
×
32
    name: 'Mock',
33
    logoUrl: `${RAW_PROVIDERS_FILES_PATH}/mock/mock-logo.png`,
34
  }
35

36
  async getNetworks(): Promise<ChainInfo[]> {
37
    return [mainnet, optimism, sepolia]
×
38
  }
39

40
  async getBuyTokens(param: GetBuyTokensParams): Promise<TokenInfo[]> {
41
    const { targetChainId } = param
×
42
    return [
×
43
      {
44
        chainId: targetChainId,
45
        address: '0x0000000000000000000000000000000000000001',
46
        logoUrl: 'https://swap.cow.fi/assets/network-mainnet-logo-BJe1wK_m.svg',
47
        name: 'Mock token 1',
48
        symbol: 'MOCK1',
49
        decimals: 18,
50
      },
51
      {
52
        chainId: targetChainId,
53
        address: '0x0000000000000000000000000000000000000002',
54
        logoUrl: 'https://swap.cow.fi/assets/network-gnosis-chain-logo-Do_DEWQv.svg',
55
        name: 'Mock token 2',
56
        symbol: 'MOCK2',
57
        decimals: 18,
58
      },
59
      {
60
        chainId: targetChainId,
61
        address: '0x0000000000000000000000000000000000000003',
62
        logoUrl: 'https://swap.cow.fi/assets/network-mainnet-logo-BJe1wK_m.svg',
63
        name: 'Mock token 3',
64
        symbol: 'MOCK3',
65
        decimals: 18,
66
      },
67
    ]
68
  }
69

70
  async getIntermediateTokens(_request: QuoteBridgeRequest): Promise<string[]> {
71
    return ['0x0000000000000000000000000000000000000000']
×
72
  }
73

74
  async getQuote(_request: QuoteBridgeRequest): Promise<BridgeQuoteResult> {
UNCOV
75
    return {
×
76
      isSell: true,
77
      amountsAndCosts: {
78
        costs: {
79
          bridgingFee: {
80
            feeBps: 10,
81
            amountInSellCurrency: 123456n,
82
            amountInBuyCurrency: 123456n,
83
          },
84
        },
85
        beforeFee: {
86
          sellAmount: 123456n,
87
          buyAmount: 123456n,
88
        },
89
        afterFee: {
90
          sellAmount: 123456n,
91
          buyAmount: 123456n,
92
        },
93
        afterSlippage: {
94
          sellAmount: 123456n,
95
          buyAmount: 123456n,
96
        },
97
        slippageBps: 0,
98
      },
99
      quoteTimestamp: Date.now(),
100
      expectedFillTimeSeconds: 128,
101
    }
102
  }
103

104
  getGasLimitEstimationForHook(_request: QuoteBridgeRequest): number {
NEW
105
    return 110_000
×
106
  }
107

108
  async getUnsignedBridgeCall(_request: QuoteBridgeRequest, _quote: BridgeQuoteResult): Promise<EvmCall> {
NEW
109
    return MOCK_CALL
×
110
  }
111
  async getSignedHook(_chainId: SupportedChainId, _unsignedCall: EvmCall, _signer: Signer): Promise<BridgeHook> {
112
    return {
×
113
      recipient: '0x0000000000000000000000000000000000000001',
114
      postHook: {
115
        target: '0x0000000000000000000000000000000000000002',
116
        callData: '0x1',
117
        gasLimit: '0x2',
118
        dappId: 'MockBridgeProvider',
119
      },
120
    }
121
  }
122
  async decodeBridgeHook(_hook: BridgeHook): Promise<BridgeDeposit> {
123
    return {
×
124
      kind: OrderKind.SELL,
125
      provider: this.info,
126
      account: '0x0000000000000000000000000000000000000001',
127
      sellTokenChainId: 1,
128
      sellTokenAddress: '0x0000000000000000000000000000000000000001',
129
      sellTokenAmount: '123456',
130
      sellTokenDecimals: 18,
131

132
      buyTokenChainId: 1,
133
      buyTokenAddress: '0x0000000000000000000000000000000000000002',
134
      buyTokenDecimals: 18,
135

136
      minBuyAmount: '123456',
137

138
      receiver: '0x0000000000000000000000000000000000000001',
139
      signer: '',
140
      appCode: 'MOCK',
141
    }
142
  }
143

144
  async getBridgingId(_orderUid: string, _settlementTx: string): Promise<string> {
UNCOV
145
    return BRIDGING_ID
×
146
  }
147

148
  getExplorerUrl(bridgingId: string): string {
UNCOV
149
    return 'https://www.google.com/search?q=' + bridgingId
×
150
  }
151

152
  async getStatus(_bridgingId: string): Promise<BridgeStatusResult> {
153
    return {
×
154
      status: BridgeStatus.IN_PROGRESS,
155
      fillTimeInSeconds: 67,
156
    }
157
  }
158

159
  async getCancelBridgingTx(_bridgingId: string): Promise<EvmCall> {
NEW
UNCOV
160
    return MOCK_CALL
×
161
  }
162
  async getRefundBridgingTx(_bridgingId: string): Promise<EvmCall> {
NEW
163
    return MOCK_CALL
×
164
  }
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc