mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-24 19:30:34 +00:00
rpcclient: export NewWaiter function
Change first argument of NewWaiter to be able to directly accept RPC Client and export for external usage. Refs #3244. Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
3176f72878
commit
28f1beff64
3 changed files with 14 additions and 11 deletions
|
@ -126,7 +126,7 @@ func New(ra RPCActor, signers []SignerAccount) (*Actor, error) {
|
|||
}
|
||||
return &Actor{
|
||||
Invoker: *inv,
|
||||
Waiter: newWaiter(ra, version),
|
||||
Waiter: NewWaiter(ra, version),
|
||||
client: ra,
|
||||
opts: NewDefaultOptions(),
|
||||
signers: signers,
|
||||
|
|
|
@ -100,10 +100,13 @@ func errIsAlreadyExists(err error) bool {
|
|||
return strings.Contains(strings.ToLower(err.Error()), "already exists")
|
||||
}
|
||||
|
||||
// newWaiter creates Waiter instance. It can be either websocket-based or
|
||||
// polling-base, otherwise Waiter stub is returned.
|
||||
func newWaiter(ra RPCActor, v *result.Version) Waiter {
|
||||
if eventW, ok := ra.(RPCEventWaiter); ok {
|
||||
// NewWaiter creates Waiter instance. It can be either websocket-based or
|
||||
// polling-base, otherwise Waiter stub is returned. As a first argument
|
||||
// it accepts RPCEventWaiter implementation, RPCPollingWaiter implementation
|
||||
// or not an implementation of these two interfaces. It returns websocket-based
|
||||
// waiter, polling-based waiter or a stub correspondingly.
|
||||
func NewWaiter(base any, v *result.Version) Waiter {
|
||||
if eventW, ok := base.(RPCEventWaiter); ok {
|
||||
return &EventWaiter{
|
||||
ws: eventW,
|
||||
polling: &PollingWaiter{
|
||||
|
@ -112,7 +115,7 @@ func newWaiter(ra RPCActor, v *result.Version) Waiter {
|
|||
},
|
||||
}
|
||||
}
|
||||
if pollW, ok := ra.(RPCPollingWaiter); ok {
|
||||
if pollW, ok := base.(RPCPollingWaiter); ok {
|
||||
return &PollingWaiter{
|
||||
polling: pollW,
|
||||
version: v,
|
||||
|
|
|
@ -38,15 +38,15 @@ func (c *AwaitableRPCClient) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr
|
|||
func (c *AwaitableRPCClient) Unsubscribe(id string) error { return nil }
|
||||
|
||||
func TestNewWaiter(t *testing.T) {
|
||||
w := newWaiter((RPCActor)(nil), nil)
|
||||
w := NewWaiter((RPCActor)(nil), nil)
|
||||
_, ok := w.(NullWaiter)
|
||||
require.True(t, ok)
|
||||
|
||||
w = newWaiter(&RPCClient{}, &result.Version{})
|
||||
w = NewWaiter(&RPCClient{}, &result.Version{})
|
||||
_, ok = w.(*PollingWaiter)
|
||||
require.True(t, ok)
|
||||
|
||||
w = newWaiter(&AwaitableRPCClient{RPCClient: RPCClient{}}, &result.Version{})
|
||||
w = NewWaiter(&AwaitableRPCClient{RPCClient: RPCClient{}}, &result.Version{})
|
||||
_, ok = w.(*EventWaiter)
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func TestPollingWaiter_Wait(t *testing.T) {
|
|||
expected := &state.AppExecResult{Container: h, Execution: state.Execution{}}
|
||||
c := &RPCClient{appLog: appLog}
|
||||
c.bCount.Store(bCount)
|
||||
w := newWaiter(c, &result.Version{Protocol: result.Protocol{MillisecondsPerBlock: 1}}) // reduce testing time.
|
||||
w := NewWaiter(c, &result.Version{Protocol: result.Protocol{MillisecondsPerBlock: 1}}) // reduce testing time.
|
||||
_, ok := w.(*PollingWaiter)
|
||||
require.True(t, ok)
|
||||
|
||||
|
@ -123,7 +123,7 @@ func TestWSWaiter_Wait(t *testing.T) {
|
|||
expected := &state.AppExecResult{Container: h, Execution: state.Execution{}}
|
||||
c := &AwaitableRPCClient{RPCClient: RPCClient{appLog: appLog}}
|
||||
c.bCount.Store(bCount)
|
||||
w := newWaiter(c, &result.Version{Protocol: result.Protocol{MillisecondsPerBlock: 1}}) // reduce testing time.
|
||||
w := NewWaiter(c, &result.Version{Protocol: result.Protocol{MillisecondsPerBlock: 1}}) // reduce testing time.
|
||||
_, ok := w.(*EventWaiter)
|
||||
require.True(t, ok)
|
||||
|
||||
|
|
Loading…
Reference in a new issue