mirror of
https://github.com/status-im/status-go.git
synced 2025-01-10 06:36:32 +00:00
e67592d556
* Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
154 lines
3.4 KiB
Go
154 lines
3.4 KiB
Go
package node
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/status-im/status-go/appdatabase"
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
"github.com/status-im/status-go/params"
|
|
)
|
|
|
|
type TestServiceAPI struct{}
|
|
|
|
func (api *TestServiceAPI) SomeMethod(_ context.Context) (string, error) {
|
|
return "some method result", nil
|
|
}
|
|
|
|
func setupTestDB() (*sql.DB, func() error, error) {
|
|
tmpfile, err := ioutil.TempFile("", "tests")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
db, err := appdatabase.InitializeDB(tmpfile.Name(), "tests")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return db, func() error {
|
|
err := db.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.Remove(tmpfile.Name())
|
|
}, nil
|
|
}
|
|
|
|
func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
|
|
tmpfile, err := ioutil.TempFile("", "tests")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
db, err := multiaccounts.InitializeDB(tmpfile.Name())
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return db, func() error {
|
|
err := db.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.Remove(tmpfile.Name())
|
|
}, nil
|
|
}
|
|
|
|
func createAndStartStatusNode(config *params.NodeConfig) (*StatusNode, error) {
|
|
statusNode := New(nil)
|
|
|
|
db, stop, err := setupTestDB()
|
|
defer func() {
|
|
err := stop()
|
|
if err != nil {
|
|
statusNode.log.Error("stopping db", err)
|
|
}
|
|
}()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
statusNode.appDB = db
|
|
|
|
ma, stop2, err := setupTestMultiDB()
|
|
defer func() {
|
|
err := stop2()
|
|
if err != nil {
|
|
statusNode.log.Error("stopping multiaccount db", err)
|
|
}
|
|
}()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
statusNode.multiaccountsDB = ma
|
|
|
|
err = statusNode.Start(config, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return statusNode, nil
|
|
}
|
|
|
|
func TestNodeRPCClientCallOnlyPublicAPIs(t *testing.T) {
|
|
var err error
|
|
|
|
statusNode, err := createAndStartStatusNode(¶ms.NodeConfig{
|
|
APIModules: "", // no whitelisted API modules; use only public APIs
|
|
UpstreamConfig: params.UpstreamRPCConfig{
|
|
URL: "https://infura.io",
|
|
Enabled: true},
|
|
WakuConfig: params.WakuConfig{
|
|
Enabled: true,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
defer func() {
|
|
err := statusNode.Stop()
|
|
require.NoError(t, err)
|
|
}()
|
|
|
|
client := statusNode.RPCClient()
|
|
require.NotNil(t, client)
|
|
|
|
// call public API with public RPC Client
|
|
result, err := statusNode.CallRPC(`{"jsonrpc": "2.0", "id": 1, "method": "eth_uninstallFilter", "params": ["id"]}`)
|
|
require.NoError(t, err)
|
|
|
|
// the call is successful
|
|
require.False(t, strings.Contains(result, "error"))
|
|
|
|
result, err = statusNode.CallRPC(`{"jsonrpc": "2.0", "id": 1, "method": "waku_info"}`)
|
|
require.NoError(t, err)
|
|
|
|
// call private API with public RPC client
|
|
require.Equal(t, ErrRPCMethodUnavailable, result)
|
|
|
|
}
|
|
|
|
func TestNodeRPCPrivateClientCallPrivateService(t *testing.T) {
|
|
var err error
|
|
|
|
statusNode, err := createAndStartStatusNode(¶ms.NodeConfig{
|
|
WakuConfig: params.WakuConfig{
|
|
Enabled: true,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
defer func() {
|
|
err := statusNode.Stop()
|
|
require.NoError(t, err)
|
|
}()
|
|
|
|
result, err := statusNode.CallPrivateRPC(`{"jsonrpc": "2.0", "id": 1, "method": "waku_info"}`)
|
|
require.NoError(t, err)
|
|
|
|
// the call is successful
|
|
require.False(t, strings.Contains(result, "error"))
|
|
|
|
_, err = statusNode.CallPrivateRPC(`{"jsonrpc": "2.0", "id": 1, "method": "settings_getSettings"}`)
|
|
require.NoError(t, err)
|
|
}
|