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

cowprotocol / cow-sdk / #1878

25 Jun 2025 10:06AM UTC coverage: 73.99% (-0.2%) from 74.222%
#1878

push

shoom3301
fix(bridge): use gasLimit for hook depending on proxy deployment

613 of 875 branches covered (70.06%)

Branch coverage included in aggregate %.

15 of 26 new or added lines in 9 files covered. (57.69%)

2 existing lines in 2 files now uncovered.

1273 of 1674 relevant lines covered (76.05%)

18.14 hits per line

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

38.1
/src/bridging/providers/mock/MockBridgeProvider.ts
1
import { latest as latestAppData } from '@cowprotocol/app-data'
2
import {
3
  BridgeDeposit,
4
  BridgeHook,
5
  BridgeProvider,
6
  BridgeProviderInfo,
7
  BridgeQuoteResult,
8
  BridgeStatus,
9
  BridgeStatusResult,
10
  BridgingDepositParams,
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 { AdditionalTargetChainId, ChainId, ChainInfo, SupportedChainId, TargetChainId } from '../../../chains'
20
import { RAW_PROVIDERS_FILES_PATH } from '../../const'
21
import { Signer } from '@ethersproject/abstract-signer'
22
import { JsonRpcProvider } from '@ethersproject/providers'
23

24
const BRIDGING_PARAMS: BridgingDepositParams = {
2✔
25
  inputTokenAddress: '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
26
  outputTokenAddress: '0x000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913',
27
  inputAmount: 24023409n,
28
  outputAmount: 24020093n,
29
  owner: '0x0000000000000000000000002bfcacf7ff137289a2c4841ea90413ab51103032',
30
  quoteTimestamp: 1747223915,
31
  fillDeadline: 1747235809,
32
  recipient: '0x000000000000000000000000bbcf91605c18a9859c1d47abfeed5d2cca7097cf',
33
  sourceChainId: 1,
34
  destinationChainId: 8453,
35
  bridgingId: '2595561',
36
}
37
const MOCK_CALL: EvmCall = {
2✔
38
  to: '0x0000000000000000000000000000000000000001',
39
  data: '0x0',
40
  value: BigInt(0),
41
}
42

43
const BUY_TOKENS = [
2✔
44
  {
45
    chainId: SupportedChainId.MAINNET,
46
    address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
47
    logoUrl: 'https://swap.cow.fi/assets/network-mainnet-logo-BJe1wK_m.svg',
48
    name: 'USD Coin',
49
    symbol: 'USDC',
50
    decimals: 6,
51
  },
52
  {
53
    chainId: SupportedChainId.MAINNET,
54
    address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
55
    logoUrl: 'https://swap.cow.fi/assets/network-gnosis-chain-logo-Do_DEWQv.svg',
56
    name: 'Wrapped Ether',
57
    symbol: 'WETH',
58
    decimals: 18,
59
  },
60
  {
61
    chainId: SupportedChainId.SEPOLIA,
62
    address: '0x0625aFB445C3B6B7B929342a04A22599fd5dBB59',
63
    logoUrl: 'https://swap.cow.fi/assets/network-mainnet-logo-BJe1wK_m.svg',
64
    name: 'CoW Protocol Token',
65
    symbol: 'COW',
66
    decimals: 18,
67
  },
68
  {
69
    chainId: AdditionalTargetChainId.OPTIMISM,
70
    address: '0x4200000000000000000000000000000000000006',
71
    logoUrl: 'https://swap.cow.fi/assets/network-mainnet-logo-BJe1wK_m.svg',
72
    name: 'Wrapped Ether',
73
    symbol: 'WETH',
74
    decimals: 18,
75
  },
76
]
77

78
const INTERMEDIATE_TOKENS: Partial<Record<TargetChainId, TokenInfo[]>> = {
2✔
79
  [SupportedChainId.MAINNET]: [
80
    {
81
      address: '0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB',
82
      chainId: SupportedChainId.MAINNET,
83
      name: 'COW',
84
      symbol: 'COW',
85
      decimals: 18,
86
    },
87
  ],
88
  [AdditionalTargetChainId.OPTIMISM]: [
89
    {
90
      address: '0x68f180fcCe6836688e9084f035309E29Bf0A2095',
91
      chainId: AdditionalTargetChainId.OPTIMISM,
92
      name: 'Wrapped BTC ',
93
      symbol: 'WBTC',
94
      decimals: 8,
95
    },
96
  ],
97
  [SupportedChainId.SEPOLIA]: [
98
    {
99
      address: '0xB4F1737Af37711e9A5890D9510c9bB60e170CB0D',
100
      chainId: SupportedChainId.SEPOLIA,
101
      name: 'DAI (test)',
102
      symbol: 'DAI',
103
      decimals: 18,
104
    },
105
  ],
106
}
107

108
export class MockBridgeProvider implements BridgeProvider<BridgeQuoteResult> {
109
  info: BridgeProviderInfo = {
5✔
110
    name: 'Mock',
111
    logoUrl: `${RAW_PROVIDERS_FILES_PATH}/mock/mock-logo.png`,
112
    dappId: 'mockProvider',
113
    website: 'https://across.to',
114
  }
115

116
  public getRpcProvider() {
NEW
117
    return {} as unknown as JsonRpcProvider
×
118
  }
119

120
  async getNetworks(): Promise<ChainInfo[]> {
121
    return [mainnet, optimism, sepolia]
×
122
  }
123

124
  async getBuyTokens(targetChainId: TargetChainId): Promise<TokenInfo[]> {
125
    return BUY_TOKENS.filter((token) => token.chainId === targetChainId)
×
126
  }
127

128
  async getIntermediateTokens({ sellTokenChainId }: QuoteBridgeRequest): Promise<TokenInfo[]> {
129
    return INTERMEDIATE_TOKENS[sellTokenChainId] ?? []
4!
130
  }
131

132
  async getQuote(_request: QuoteBridgeRequest): Promise<BridgeQuoteResult> {
133
    return {
×
134
      isSell: true,
135
      amountsAndCosts: {
136
        costs: {
137
          bridgingFee: {
138
            feeBps: 10,
139
            amountInSellCurrency: 123456n,
140
            amountInBuyCurrency: 123456n,
141
          },
142
        },
143
        beforeFee: {
144
          sellAmount: 123456n,
145
          buyAmount: 123456n,
146
        },
147
        afterFee: {
148
          sellAmount: 123456n,
149
          buyAmount: 123456n,
150
        },
151
        afterSlippage: {
152
          sellAmount: 123456n,
153
          buyAmount: 123456n,
154
        },
155
        slippageBps: 0,
156
      },
157
      quoteTimestamp: Date.now(),
158
      expectedFillTimeSeconds: 128,
159
      fees: {
160
        bridgeFee: 1n,
161
        destinationGasFee: 2n,
162
      },
163
      limits: {
164
        minDeposit: 1n,
165
        maxDeposit: 100_000n,
166
      },
167
    }
168
  }
169

170
  async getGasLimitEstimationForHook(_request: QuoteBridgeRequest): Promise<number> {
171
    return 110_000
4✔
172
  }
173

174
  async getUnsignedBridgeCall(_request: QuoteBridgeRequest, _quote: BridgeQuoteResult): Promise<EvmCall> {
175
    return MOCK_CALL
×
176
  }
177
  async getSignedHook(_chainId: SupportedChainId, _unsignedCall: EvmCall, _signer: Signer): Promise<BridgeHook> {
178
    return {
×
179
      recipient: '0x0000000000000000000000000000000000000001',
180
      postHook: {
181
        target: '0x0000000000000000000000000000000000000002',
182
        callData: '0x1',
183
        gasLimit: '0x2',
184
        dappId: 'MockBridgeProvider',
185
      },
186
    }
187
  }
188
  async decodeBridgeHook(_hook: latestAppData.CoWHook): Promise<BridgeDeposit> {
189
    return {
×
190
      kind: OrderKind.SELL,
191
      provider: this.info,
192
      account: '0x0000000000000000000000000000000000000001',
193
      sellTokenChainId: 1,
194
      sellTokenAddress: '0x0000000000000000000000000000000000000001',
195
      sellTokenAmount: '123456',
196
      sellTokenDecimals: 18,
197

198
      buyTokenChainId: 1,
199
      buyTokenAddress: '0x0000000000000000000000000000000000000002',
200
      buyTokenDecimals: 18,
201

202
      minBuyAmount: '123456',
203

204
      receiver: '0x0000000000000000000000000000000000000001',
205
      signer: '',
206
      appCode: 'MOCK',
207
    }
208
  }
209

210
  async getBridgingParams(_chainId: ChainId, _orderUid: string, _txHash: string): Promise<BridgingDepositParams> {
UNCOV
211
    return BRIDGING_PARAMS
×
212
  }
213

214
  getExplorerUrl(bridgingId: string): string {
215
    return 'https://www.google.com/search?q=' + bridgingId
×
216
  }
217

218
  async getStatus(_bridgingId: string): Promise<BridgeStatusResult> {
219
    return {
×
220
      status: BridgeStatus.IN_PROGRESS,
221
      fillTimeInSeconds: 67,
222
    }
223
  }
224

225
  async getCancelBridgingTx(_bridgingId: string): Promise<EvmCall> {
226
    return MOCK_CALL
×
227
  }
228
  async getRefundBridgingTx(_bridgingId: string): Promise<EvmCall> {
229
    return MOCK_CALL
×
230
  }
231
}
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