2024-06-24 14:29:40 +00:00
|
|
|
package connector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2024-09-20 09:08:11 +00:00
|
|
|
"go.uber.org/mock/gomock"
|
2024-06-24 14:29:40 +00:00
|
|
|
|
|
|
|
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
|
|
|
"github.com/status-im/status-go/params"
|
|
|
|
statusRPC "github.com/status-im/status-go/rpc"
|
2024-07-18 15:30:10 +00:00
|
|
|
"github.com/status-im/status-go/services/connector/commands"
|
2024-06-24 14:29:40 +00:00
|
|
|
"github.com/status-im/status-go/transactions/fake"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewService(t *testing.T) {
|
2024-07-18 15:30:10 +00:00
|
|
|
db, close := createDB(t)
|
|
|
|
defer close()
|
2024-06-24 14:29:40 +00:00
|
|
|
|
|
|
|
txServiceMockCtrl := gomock.NewController(t)
|
|
|
|
server, _ := fake.NewTestServer(txServiceMockCtrl)
|
|
|
|
|
|
|
|
// Creating a dummy status node to simulate what it's done in get_status_node.go
|
|
|
|
upstreamConfig := params.UpstreamRPCConfig{
|
|
|
|
URL: "https://mainnet.infura.io/v3/fake",
|
|
|
|
Enabled: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
client := gethrpc.DialInProc(server)
|
2024-07-31 06:21:11 +00:00
|
|
|
rpcClient, err := statusRPC.NewClient(client, 1, upstreamConfig, nil, db, nil)
|
2024-06-24 14:29:40 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-07-18 15:30:10 +00:00
|
|
|
service := NewService(db, rpcClient, rpcClient.NetworkManager)
|
2024-06-24 14:29:40 +00:00
|
|
|
|
|
|
|
assert.NotNil(t, service)
|
2024-07-18 15:30:10 +00:00
|
|
|
assert.Equal(t, rpcClient.NetworkManager, service.nm)
|
2024-06-24 14:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestService_Start(t *testing.T) {
|
2024-07-18 15:30:10 +00:00
|
|
|
db, close := createDB(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
service := NewService(db, &commands.RPCClientMock{}, &commands.NetworkManagerMock{})
|
2024-06-24 14:29:40 +00:00
|
|
|
err := service.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestService_Stop(t *testing.T) {
|
2024-07-18 15:30:10 +00:00
|
|
|
db, close := createDB(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
service := NewService(db, &commands.RPCClientMock{}, &commands.NetworkManagerMock{})
|
2024-06-24 14:29:40 +00:00
|
|
|
err := service.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestService_APIs(t *testing.T) {
|
|
|
|
api, cancel := setupTestAPI(t)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
apis := api.s.APIs()
|
|
|
|
|
|
|
|
assert.Len(t, apis, 1)
|
|
|
|
assert.Equal(t, "connector", apis[0].Namespace)
|
|
|
|
assert.Equal(t, "0.1.0", apis[0].Version)
|
|
|
|
assert.NotNil(t, apis[0].Service)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestService_Protocols(t *testing.T) {
|
2024-07-18 15:30:10 +00:00
|
|
|
db, close := createDB(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
service := NewService(db, &commands.RPCClientMock{}, &commands.NetworkManagerMock{})
|
2024-06-24 14:29:40 +00:00
|
|
|
protocols := service.Protocols()
|
|
|
|
assert.Nil(t, protocols)
|
|
|
|
}
|