forked from btcsuite/btcwallet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chain: add
NewRPCClientWithConfig
to init client using config
This commit adds a new method to init the RPC client. Unlike the `NewRPCClient`, it now takes a config to allow users specifying notification handlers. In the future, `NewRPCClient` should be replaced by this method. For now we implement it this way so other callsites relying on this method can stay out of being affected.
- Loading branch information
1 parent
edb6ec9
commit 524b1eb
Showing
2 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package chain | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/btcsuite/btcd/chaincfg" | ||
"github.com/btcsuite/btcd/rpcclient" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestValidateConfig checks the `validate` method on the RPCClientConfig | ||
// behaves as expected. | ||
func TestValidateConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
rt := require.New(t) | ||
|
||
// ReconnectAttempts must be positive. | ||
cfg := &RPCClientConfig{ | ||
ReconnectAttempts: -1, | ||
} | ||
rt.ErrorContains(cfg.validate(), "reconnectAttempts") | ||
|
||
// Must specify a chain params. | ||
cfg = &RPCClientConfig{ | ||
ReconnectAttempts: 1, | ||
} | ||
rt.ErrorContains(cfg.validate(), "chain params") | ||
|
||
// Must specify a connection config. | ||
cfg = &RPCClientConfig{ | ||
ReconnectAttempts: 1, | ||
Chain: &chaincfg.Params{}, | ||
} | ||
rt.ErrorContains(cfg.validate(), "conn config") | ||
|
||
// Must specify a certificate when using TLS. | ||
cfg = &RPCClientConfig{ | ||
ReconnectAttempts: 1, | ||
Chain: &chaincfg.Params{}, | ||
Conn: &rpcclient.ConnConfig{}, | ||
} | ||
rt.ErrorContains(cfg.validate(), "certs") | ||
|
||
// Validate config. | ||
cfg = &RPCClientConfig{ | ||
ReconnectAttempts: 1, | ||
Chain: &chaincfg.Params{}, | ||
Conn: &rpcclient.ConnConfig{ | ||
DisableTLS: true, | ||
}, | ||
} | ||
rt.NoError(cfg.validate()) | ||
|
||
// When a nil config is provided, it should return an error. | ||
_, err := NewRPCClientWithConfig(nil) | ||
rt.ErrorContains(err, "missing rpc config") | ||
} |