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{
|
return &Actor{
|
||||||
Invoker: *inv,
|
Invoker: *inv,
|
||||||
Waiter: newWaiter(ra, version),
|
Waiter: NewWaiter(ra, version),
|
||||||
client: ra,
|
client: ra,
|
||||||
opts: NewDefaultOptions(),
|
opts: NewDefaultOptions(),
|
||||||
signers: signers,
|
signers: signers,
|
||||||
|
|
|
@ -100,10 +100,13 @@ func errIsAlreadyExists(err error) bool {
|
||||||
return strings.Contains(strings.ToLower(err.Error()), "already exists")
|
return strings.Contains(strings.ToLower(err.Error()), "already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
// newWaiter creates Waiter instance. It can be either websocket-based or
|
// NewWaiter creates Waiter instance. It can be either websocket-based or
|
||||||
// polling-base, otherwise Waiter stub is returned.
|
// polling-base, otherwise Waiter stub is returned. As a first argument
|
||||||
func newWaiter(ra RPCActor, v *result.Version) Waiter {
|
// it accepts RPCEventWaiter implementation, RPCPollingWaiter implementation
|
||||||
if eventW, ok := ra.(RPCEventWaiter); ok {
|
// 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{
|
return &EventWaiter{
|
||||||
ws: eventW,
|
ws: eventW,
|
||||||
polling: &PollingWaiter{
|
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{
|
return &PollingWaiter{
|
||||||
polling: pollW,
|
polling: pollW,
|
||||||
version: v,
|
version: v,
|
||||||
|
|
|
@ -38,15 +38,15 @@ func (c *AwaitableRPCClient) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr
|
||||||
func (c *AwaitableRPCClient) Unsubscribe(id string) error { return nil }
|
func (c *AwaitableRPCClient) Unsubscribe(id string) error { return nil }
|
||||||
|
|
||||||
func TestNewWaiter(t *testing.T) {
|
func TestNewWaiter(t *testing.T) {
|
||||||
w := newWaiter((RPCActor)(nil), nil)
|
w := NewWaiter((RPCActor)(nil), nil)
|
||||||
_, ok := w.(NullWaiter)
|
_, ok := w.(NullWaiter)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
w = newWaiter(&RPCClient{}, &result.Version{})
|
w = NewWaiter(&RPCClient{}, &result.Version{})
|
||||||
_, ok = w.(*PollingWaiter)
|
_, ok = w.(*PollingWaiter)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
w = newWaiter(&AwaitableRPCClient{RPCClient: RPCClient{}}, &result.Version{})
|
w = NewWaiter(&AwaitableRPCClient{RPCClient: RPCClient{}}, &result.Version{})
|
||||||
_, ok = w.(*EventWaiter)
|
_, ok = w.(*EventWaiter)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func TestPollingWaiter_Wait(t *testing.T) {
|
||||||
expected := &state.AppExecResult{Container: h, Execution: state.Execution{}}
|
expected := &state.AppExecResult{Container: h, Execution: state.Execution{}}
|
||||||
c := &RPCClient{appLog: appLog}
|
c := &RPCClient{appLog: appLog}
|
||||||
c.bCount.Store(bCount)
|
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)
|
_, ok := w.(*PollingWaiter)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func TestWSWaiter_Wait(t *testing.T) {
|
||||||
expected := &state.AppExecResult{Container: h, Execution: state.Execution{}}
|
expected := &state.AppExecResult{Container: h, Execution: state.Execution{}}
|
||||||
c := &AwaitableRPCClient{RPCClient: RPCClient{appLog: appLog}}
|
c := &AwaitableRPCClient{RPCClient: RPCClient{appLog: appLog}}
|
||||||
c.bCount.Store(bCount)
|
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)
|
_, ok := w.(*EventWaiter)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue