2018-06-04 13:47:13 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2018-11-14 07:03:58 +00:00
|
|
|
"net"
|
2018-06-27 07:55:25 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-01-02 09:10:19 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb/storage"
|
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
2018-11-14 07:03:58 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2018-10-12 12:58:32 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2019-10-04 15:21:24 +00:00
|
|
|
"github.com/status-im/status-go/t/utils"
|
2018-06-04 13:47:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMakeNodeDefaultConfig(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
config, err := utils.MakeTestNodeConfig(3)
|
2018-06-04 13:47:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
_, err = MakeNode(config, &accounts.Manager{}, db)
|
2018-06-04 13:47:13 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2018-07-25 14:48:02 +00:00
|
|
|
func TestParseNodesToNodeID(t *testing.T) {
|
2018-11-14 07:03:58 +00:00
|
|
|
identity, err := crypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
node := enode.NewV4(&identity.PublicKey, net.IP{10, 10, 10, 10}, 10, 20)
|
2018-07-25 14:48:02 +00:00
|
|
|
nodeIDs := parseNodesToNodeID([]string{
|
|
|
|
"enode://badkey@127.0.0.1:30303",
|
2018-11-14 07:03:58 +00:00
|
|
|
node.String(),
|
2018-07-25 14:48:02 +00:00
|
|
|
})
|
|
|
|
require.Len(t, nodeIDs, 1)
|
2018-11-14 07:03:58 +00:00
|
|
|
require.Equal(t, node.ID(), nodeIDs[0])
|
2018-07-25 14:48:02 +00:00
|
|
|
}
|
2018-10-12 12:58:32 +00:00
|
|
|
|
|
|
|
func TestNewGethNodeConfig(t *testing.T) {
|
2022-10-20 10:33:23 +00:00
|
|
|
config, err := params.NewNodeConfig("", params.GoerliNetworkID)
|
2018-10-12 12:58:32 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
config.HTTPEnabled = true
|
|
|
|
config.HTTPVirtualHosts = []string{"my.domain.com"}
|
|
|
|
config.HTTPCors = []string{"http://my.domain.com"}
|
|
|
|
|
|
|
|
nc, err := newGethNodeConfig(config)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []string{"my.domain.com"}, nc.HTTPVirtualHosts)
|
|
|
|
require.Equal(t, []string{"http://my.domain.com"}, nc.HTTPCors)
|
|
|
|
}
|