1
1
import type { EthereumProvider } from "hardhat/types" ;
2
2
3
- import { assert } from "chai" ;
3
+ import { assert , expect } from "chai" ;
4
4
import * as chains from "viem/chains" ;
5
5
6
6
import {
@@ -32,6 +32,7 @@ describe("clients", () => {
32
32
33
33
assert . equal ( client . pollingInterval , 1000 ) ;
34
34
assert . equal ( client . cacheTime , 2000 ) ;
35
+ assert . equal ( client . transport . retryCount , 3 ) ;
35
36
} ) ;
36
37
37
38
it ( "should return a public client with default parameters for development networks" , async ( ) => {
@@ -41,6 +42,29 @@ describe("clients", () => {
41
42
42
43
assert . equal ( client . pollingInterval , 50 ) ;
43
44
assert . equal ( client . cacheTime , 0 ) ;
45
+ assert . equal ( client . transport . retryCount , 0 ) ;
46
+ } ) ;
47
+
48
+ it ( "should retry failed calls on public client" , async ( ) => {
49
+ const provider = new EthereumMockedProvider ( ) ;
50
+
51
+ const client = await innerGetPublicClient ( provider , chains . mainnet ) ;
52
+
53
+ await expect ( client . getBlockNumber ( ) ) . to . eventually . be . rejectedWith (
54
+ / u n k n o w n R P C e r r o r /
55
+ ) ;
56
+ assert . equal ( provider . calledCount , 4 ) ;
57
+ } ) ;
58
+
59
+ it ( "should not retry failed calls on public client when using a development network" , async ( ) => {
60
+ const provider = new EthereumMockedProvider ( ) ;
61
+
62
+ const client = await innerGetPublicClient ( provider , chains . hardhat ) ;
63
+
64
+ await expect ( client . getBlockNumber ( ) ) . to . eventually . be . rejectedWith (
65
+ / u n k n o w n R P C e r r o r /
66
+ ) ;
67
+ assert . equal ( provider . calledCount , 1 ) ;
44
68
} ) ;
45
69
} ) ;
46
70
@@ -97,9 +121,36 @@ describe("clients", () => {
97
121
clients . forEach ( ( client ) => {
98
122
assert . equal ( client . pollingInterval , 50 ) ;
99
123
assert . equal ( client . cacheTime , 0 ) ;
124
+ assert . equal ( client . transport . retryCount , 0 ) ;
100
125
} ) ;
101
126
} ) ;
102
127
128
+ it ( "should retry failed calls on wallet client" , async ( ) => {
129
+ const provider = new EthereumMockedProvider ( ) ;
130
+
131
+ const [ client ] = await innerGetWalletClients ( provider , chains . mainnet , [
132
+ "0x1" ,
133
+ ] ) ;
134
+
135
+ await expect ( client . getChainId ( ) ) . to . eventually . be . rejectedWith (
136
+ / u n k n o w n R P C e r r o r /
137
+ ) ;
138
+ assert . equal ( provider . calledCount , 4 ) ;
139
+ } ) ;
140
+
141
+ it ( "should not retry failed calls on wallet client when using a development network" , async ( ) => {
142
+ const provider = new EthereumMockedProvider ( ) ;
143
+
144
+ const [ client ] = await innerGetWalletClients ( provider , chains . hardhat , [
145
+ "0x1" ,
146
+ ] ) ;
147
+
148
+ await expect ( client . getChainId ( ) ) . to . eventually . be . rejectedWith (
149
+ / u n k n o w n R P C e r r o r /
150
+ ) ;
151
+ assert . equal ( provider . calledCount , 1 ) ;
152
+ } ) ;
153
+
103
154
it ( "should return an empty array if there are no accounts owned by the user" , async ( ) => {
104
155
const provider : EthereumProvider = new EthereumMockedProvider ( ) ;
105
156
@@ -169,6 +220,22 @@ describe("clients", () => {
169
220
170
221
assert . equal ( client . pollingInterval , 50 ) ;
171
222
assert . equal ( client . cacheTime , 0 ) ;
223
+ assert . equal ( client . transport . retryCount , 0 ) ;
224
+ } ) ;
225
+
226
+ it ( "should not retry failed calls on test client" , async ( ) => {
227
+ const provider = new EthereumMockedProvider ( ) ;
228
+
229
+ const client = await innerGetTestClient (
230
+ provider ,
231
+ chains . hardhat ,
232
+ "hardhat"
233
+ ) ;
234
+
235
+ await expect ( client . getAutomine ( ) ) . to . eventually . be . rejectedWith (
236
+ / u n k n o w n R P C e r r o r /
237
+ ) ;
238
+ assert . equal ( provider . calledCount , 1 ) ;
172
239
} ) ;
173
240
} ) ;
174
241
} ) ;
0 commit comments