Skip to content

Commit 23d10f5

Browse files
DLC.BTC throw on RPC errors (#3469)
* rpc error handling * change changeset version to minor
1 parent 883ee13 commit 23d10f5

File tree

4 files changed

+53
-92
lines changed

4 files changed

+53
-92
lines changed

.changeset/sour-scissors-teach.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/dlc-btc-por-adapter': minor
3+
---
4+
5+
Changed error handling for missing transactions or RPC issues

packages/sources/dlc-btc-por/src/transport/proof-of-reserves.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ export class DLCBTCPorTransport extends SubscriptionTransport<TransportTypes> {
107107
}
108108
const deposits = await Promise.all(
109109
group.map(async (vault) => {
110-
try {
111-
return await this.verifyVaultDeposit(vault, attestorPublicKey)
112-
} catch (e) {
113-
logger.error(e, `Error while verifying Deposit for Vault: ${vault.uuid}. ${e}`)
114-
return 0
115-
}
110+
return await this.verifyVaultDeposit(vault, attestorPublicKey)
116111
}),
117112
)
118113
// totalPoR represents total proof of reserves value in bitcoins
@@ -165,6 +160,10 @@ export class DLCBTCPorTransport extends SubscriptionTransport<TransportTypes> {
165160
// Get the bitcoin transaction
166161
const fundingTransaction = await this.fetchFundingTransaction(txID)
167162

163+
if (!fundingTransaction) {
164+
throw new Error(`Funding transaction not found for vault ${vault.uuid}`)
165+
}
166+
168167
// Check and filter transactions that have less than [settings.CONFIRMATIONS] confirmations
169168
if (fundingTransaction.confirmations < this.settings.CONFIRMATIONS) {
170169
return 0

packages/sources/dlc-btc-por/test/integration/adapter.test.ts

+43-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,49 @@ import {
33
setEnvVariables,
44
} from '@chainlink/external-adapter-framework/util/testing-utils'
55
import * as nock from 'nock'
6-
import { mockBitcoinRPCResponseSuccess, mockContractCallResponseSuccess } from './fixtures'
6+
import { mockBitcoinRPCResponseSuccess } from './fixtures'
7+
import { ethers } from 'ethers'
8+
9+
jest.mock('ethers', () => {
10+
const actualModule = jest.requireActual('ethers')
11+
return {
12+
...actualModule,
13+
ethers: {
14+
...actualModule.ethers,
15+
providers: {
16+
JsonRpcProvider: function (): ethers.providers.JsonRpcProvider {
17+
return {} as ethers.providers.JsonRpcProvider
18+
},
19+
},
20+
Contract: function () {
21+
return {
22+
attestorGroupPubKey: jest.fn().mockImplementation(() => {
23+
return 'xpub6C1F2SwADP3TNajQjg2PaniEGpZLvWdMiFP8ChPjQBRWD1XUBeMdE4YkQYvnNhAYGoZKfcQbsRCefserB5DyJM7R9VR6ce6vLrXHVfeqyH3'
24+
}),
25+
getAllDLCs: jest.fn().mockImplementation(() => {
26+
return [
27+
{
28+
uuid: '0x9399fc7c386e7357fc101e638f3e208dcb95fbe06c47e3ff4219d5c726635222',
29+
protocolContract: '0x2940FcBb3C32901Df405da0E96fd97D1E2a53f34',
30+
timestamp: 0x665f1dd7,
31+
valueLocked: 0x01312d00,
32+
creator: '0x0DD4f29E21F10cb2E485cf9bDAb9F2dD1f240Bfa',
33+
status: 1,
34+
fundingTxId: '2d64eefe48cd209c4d549b065d3c04dcb29af57b01ca2a98c24274eae2732029',
35+
closingTxId: '',
36+
btcFeeRecipient:
37+
'021b34f36d8487ce3a7a6f0124f58854d561cb52077593d1e86973fac0fea1a8b1',
38+
btcMintFeeBasisPoints: 0x64,
39+
btcRedeemFeeBasisPoints: 0x64,
40+
taprootPubKey: 'b362931e3e4cf3cc20f75ae11ff5a4c115ec1548cb5f2c7c48294929f1e8979c',
41+
},
42+
]
43+
}),
44+
}
45+
},
46+
},
47+
}
48+
})
749

850
describe('execute', () => {
951
let spy: jest.SpyInstance
@@ -40,7 +82,6 @@ describe('execute', () => {
4082

4183
describe('por endpoint', () => {
4284
it('should return success', async () => {
43-
mockContractCallResponseSuccess()
4485
mockBitcoinRPCResponseSuccess()
4586
const response = await testAdapter.request({
4687
network: 'arbitrum',

0 commit comments

Comments
 (0)