@@ -101,6 +101,29 @@ func TestEthClientSendTx_DryRunWithoutEndpoints(t *testing.T) {
101101 require .NoError (t , client .Send (t .Context (), tx ))
102102}
103103
104+ func TestEthClientNonceUsesPending (t * testing.T ) {
105+ api := newMockEthAPI ()
106+ srv := rpc .NewServer ()
107+ require .NoError (t , srv .RegisterName ("eth" , api ))
108+
109+ ts := httptest .NewServer (srv )
110+ defer ts .Close ()
111+
112+ client , err := newEthClient (t .Context (), & ethClientConfig {
113+ ChainID : "test-chain" ,
114+ Endpoints : []string {ts .URL },
115+ ConnsPerEndpoint : 1 ,
116+ Collector : stats .NewCollector (),
117+ })
118+ require .NoError (t , err )
119+ defer client .Close ()
120+
121+ nonce , err := client .Nonce (t .Context (), common .HexToAddress ("0x0000000000000000000000000000000000000123" ))
122+ require .NoError (t , err )
123+ require .EqualValues (t , 7 , nonce )
124+ require .Equal (t , []rpc.BlockNumber {rpc .PendingBlockNumber }, api .TransactionCountRequests ())
125+ }
126+
104127func TestNewEthClientRejectsZeroConnsPerEndpoint (t * testing.T ) {
105128 client , err := newEthClient (t .Context (), & ethClientConfig {
106129 ChainID : "test-chain" ,
@@ -113,12 +136,17 @@ func TestNewEthClientRejectsZeroConnsPerEndpoint(t *testing.T) {
113136}
114137
115138type mockEthAPI struct {
116- rawTxs utils.Mutex [* [][]byte ]
139+ rawTxs utils.Mutex [* [][]byte ]
140+ transactionCountReqs utils.Mutex [* []rpc.BlockNumber ]
117141}
118142
119143func newMockEthAPI () * mockEthAPI {
120144 rawTxs := [][]byte {}
121- return & mockEthAPI {rawTxs : utils .NewMutex (& rawTxs )}
145+ transactionCountReqs := []rpc.BlockNumber {}
146+ return & mockEthAPI {
147+ rawTxs : utils .NewMutex (& rawTxs ),
148+ transactionCountReqs : utils .NewMutex (& transactionCountReqs ),
149+ }
122150}
123151
124152func (m * mockEthAPI ) SendRawTransaction (_ context.Context , rawTx hexutil.Bytes ) (common.Hash , error ) {
@@ -136,6 +164,20 @@ func (m *mockEthAPI) RawTransactions() [][]byte {
136164 panic ("unreachable" )
137165}
138166
167+ func (m * mockEthAPI ) GetTransactionCount (_ context.Context , _ common.Address , block rpc.BlockNumber ) (hexutil.Uint64 , error ) {
168+ for reqs := range m .transactionCountReqs .Lock () {
169+ * reqs = append (* reqs , block )
170+ }
171+ return hexutil .Uint64 (7 ), nil
172+ }
173+
174+ func (m * mockEthAPI ) TransactionCountRequests () []rpc.BlockNumber {
175+ for reqs := range m .transactionCountReqs .Lock () {
176+ return slices .Clone (* reqs )
177+ }
178+ panic ("unreachable" )
179+ }
180+
139181func testLoadTx (t * testing.T ) * types.LoadTx {
140182 t .Helper ()
141183
0 commit comments