config_test.go 1.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package api

import (
20
	"reflect"
21 22 23 24 25 26
	"testing"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/crypto"
)

27
func TestConfig(t *testing.T) {
28

29
	var hexprvkey = "65138b2aa745041b372153550584587da326ab440576b2a1191dd95cee30039c"
30
	var hexnodekey = "75138b2aa745041b372153550584587da326ab440576b2a1191dd95cee30039c"
31

32 33 34 35
	prvkey, err := crypto.HexToECDSA(hexprvkey)
	if err != nil {
		t.Fatalf("failed to load private key: %v", err)
	}
36 37 38 39
	nodekey, err := crypto.HexToECDSA(hexnodekey)
	if err != nil {
		t.Fatalf("failed to load private key: %v", err)
	}
40

41 42
	one := NewConfig()
	two := NewConfig()
43

44
	one.LocalStoreParams = two.LocalStoreParams
45
	if equal := reflect.DeepEqual(one, two); !equal {
46
		t.Fatal("Two default configs are not equal")
47
	}
48

49 50 51 52
	err = one.Init(prvkey, nodekey)
	if err != nil {
		t.Fatal(err)
	}
53 54 55 56

	//the init function should set the following fields
	if one.BzzKey == "" {
		t.Fatal("Expected BzzKey to be set")
57
	}
58 59
	if one.PublicKey == "" {
		t.Fatal("Expected PublicKey to be set")
60
	}
61
	if one.Swap.PayProfile.Beneficiary == (common.Address{}) && one.SwapEnabled {
62
		t.Fatal("Failed to correctly initialize SwapParams")
63
	}
64
	if one.ChunkDbPath == one.Path {
65 66
		t.Fatal("Failed to correctly initialize StoreParams")
	}
67
}