github.com/status-im/status-go@v1.1.0/services/connector/service_test.go (about) 1 package connector 2 3 import ( 4 "testing" 5 6 "github.com/golang/mock/gomock" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 gethrpc "github.com/ethereum/go-ethereum/rpc" 11 "github.com/status-im/status-go/params" 12 statusRPC "github.com/status-im/status-go/rpc" 13 "github.com/status-im/status-go/services/connector/commands" 14 "github.com/status-im/status-go/transactions/fake" 15 ) 16 17 func TestNewService(t *testing.T) { 18 db, close := createDB(t) 19 defer close() 20 21 txServiceMockCtrl := gomock.NewController(t) 22 server, _ := fake.NewTestServer(txServiceMockCtrl) 23 24 // Creating a dummy status node to simulate what it's done in get_status_node.go 25 upstreamConfig := params.UpstreamRPCConfig{ 26 URL: "https://mainnet.infura.io/v3/fake", 27 Enabled: true, 28 } 29 30 client := gethrpc.DialInProc(server) 31 rpcClient, err := statusRPC.NewClient(client, 1, upstreamConfig, nil, db, nil) 32 require.NoError(t, err) 33 34 service := NewService(db, rpcClient, rpcClient.NetworkManager) 35 36 assert.NotNil(t, service) 37 assert.Equal(t, rpcClient.NetworkManager, service.nm) 38 } 39 40 func TestService_Start(t *testing.T) { 41 db, close := createDB(t) 42 defer close() 43 44 service := NewService(db, &commands.RPCClientMock{}, &commands.NetworkManagerMock{}) 45 err := service.Start() 46 assert.NoError(t, err) 47 } 48 49 func TestService_Stop(t *testing.T) { 50 db, close := createDB(t) 51 defer close() 52 53 service := NewService(db, &commands.RPCClientMock{}, &commands.NetworkManagerMock{}) 54 err := service.Stop() 55 assert.NoError(t, err) 56 } 57 58 func TestService_APIs(t *testing.T) { 59 api, cancel := setupTestAPI(t) 60 defer cancel() 61 62 apis := api.s.APIs() 63 64 assert.Len(t, apis, 1) 65 assert.Equal(t, "connector", apis[0].Namespace) 66 assert.Equal(t, "0.1.0", apis[0].Version) 67 assert.NotNil(t, apis[0].Service) 68 } 69 70 func TestService_Protocols(t *testing.T) { 71 db, close := createDB(t) 72 defer close() 73 74 service := NewService(db, &commands.RPCClientMock{}, &commands.NetworkManagerMock{}) 75 protocols := service.Protocols() 76 assert.Nil(t, protocols) 77 }