forked from dymensionxyz/dymint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.go
38 lines (33 loc) · 1010 Bytes
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package testutil
import (
"fmt"
"net"
"testing"
"github.com/dymensionxyz/dymint/rpc"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"golang.org/x/net/nettest"
)
func CreateLocalServer(t *testing.T) (*rpc.Server, net.Listener) {
// Create a new local listener
listener, err := nettest.NewLocalListener("tcp")
require.NoError(t, err)
serverReadyCh := make(chan bool, 1)
var server *rpc.Server
// Start server with listener
go func() {
node, err := CreateNode(true, nil, GenerateGenesis(0))
require.NoError(t, err)
err = node.Start()
require.NoError(t, err)
rpcConfig := &config.RPCConfig{ListenAddress: fmt.Sprintf("tcp://%s", listener.Addr().String())}
options := []rpc.Option{rpc.WithListener(listener)}
server = rpc.NewServer(node, rpcConfig, log.TestingLogger(), options...)
err = server.Start()
require.NoError(t, err)
serverReadyCh <- true
}()
<-serverReadyCh
return server, listener
}