mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
rpc: move Request, Params and related code server-side
It's absolutely irrelevant for the client and request/response packages should only contain code that is useful on both sides of the conversation. It's OK for client tests to reuse this code, but the package is used by external developers and they shouldn't be bothered with it. Nothing changed functionally here except WSClient simplification. Fixes #2236.
This commit is contained in:
parent
bbeef6ec24
commit
adab83496c
13 changed files with 319 additions and 294 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server/params"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/atomic"
|
||||
|
@ -189,7 +190,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
var cases = []struct {
|
||||
name string
|
||||
clientCode func(*testing.T, *WSClient)
|
||||
serverCode func(*testing.T, *request.Params)
|
||||
serverCode func(*testing.T, *params.Params)
|
||||
}{
|
||||
{"blocks",
|
||||
func(t *testing.T, wsc *WSClient) {
|
||||
|
@ -197,7 +198,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForNewBlocks(&primary)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.BlockFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -210,7 +211,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForNewTransactions(&sender, nil)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.TxFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -224,7 +225,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForNewTransactions(nil, &signer)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.TxFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -239,7 +240,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForNewTransactions(&sender, &signer)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.TxFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -253,7 +254,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForExecutionNotifications(&contract, nil)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.NotificationFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -267,7 +268,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForExecutionNotifications(nil, &name)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.NotificationFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -282,7 +283,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForExecutionNotifications(&contract, &name)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.NotificationFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -296,7 +297,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
_, err := wsc.SubscribeForTransactionExecutions(&state)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
func(t *testing.T, p *request.Params) {
|
||||
func(t *testing.T, p *params.Params) {
|
||||
param := p.Value(1)
|
||||
filt := new(request.ExecutionFilter)
|
||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||
|
@ -313,10 +314,10 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = ws.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||
require.NoError(t, err)
|
||||
req := request.In{}
|
||||
req := params.In{}
|
||||
err = ws.ReadJSON(&req)
|
||||
require.NoError(t, err)
|
||||
params := request.Params(req.RawParams)
|
||||
params := params.Params(req.RawParams)
|
||||
c.serverCode(t, ¶ms)
|
||||
err = ws.SetWriteDeadline(time.Now().Add(2 * time.Second))
|
||||
require.NoError(t, err)
|
||||
|
@ -370,7 +371,7 @@ func TestWSConcurrentAccess(t *testing.T) {
|
|||
if err != nil {
|
||||
break
|
||||
}
|
||||
r := request.NewIn()
|
||||
r := params.NewIn()
|
||||
err = json.Unmarshal(p, r)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot decode request body: %s", req.Body)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue