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

cowprotocol / cow-sdk / #1780

29 May 2025 01:25PM UTC coverage: 76.278% (-1.2%) from 77.485%
#1780

Pull #324

shoom3301
chore: unknown status
Pull Request #324: feat(bridge): track order progress

485 of 689 branches covered (70.39%)

Branch coverage included in aggregate %.

27 of 76 new or added lines in 13 files covered. (35.53%)

2 existing lines in 2 files now uncovered.

1097 of 1385 relevant lines covered (79.21%)

20.11 hits per line

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

40.0
/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
  }
114

115
  async getNetworks(): Promise<ChainInfo[]> {
116
    return [mainnet, optimism, sepolia]
×
117
  }
118

119
  async getBuyTokens(targetChainId: TargetChainId): Promise<TokenInfo[]> {
120
    return BUY_TOKENS.filter((token) => token.chainId === targetChainId)
×
121
  }
122

123
  async getIntermediateTokens({ sellTokenChainId }: QuoteBridgeRequest): Promise<TokenInfo[]> {
124
    return INTERMEDIATE_TOKENS[sellTokenChainId] ?? []
4!
125
  }
126

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

165
  getGasLimitEstimationForHook(_request: QuoteBridgeRequest): number {
166
    return 110_000
4✔
167
  }
168

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

193
      buyTokenChainId: 1,
194
      buyTokenAddress: '0x0000000000000000000000000000000000000002',
195
      buyTokenDecimals: 18,
196

197
      minBuyAmount: '123456',
198

199
      receiver: '0x0000000000000000000000000000000000000001',
200
      signer: '',
201
      appCode: 'MOCK',
202
    }
203
  }
204

205
  async getBridgingParams(
206
    _chainId: ChainId,
207
    _provider: JsonRpcProvider,
208
    _orderUid: string,
209
    _txHash: string,
210
  ): Promise<BridgingDepositParams> {
NEW
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