forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverridden_manager_test.go
75 lines (61 loc) · 2.57 KB
/
overridden_manager_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package node
import (
"math"
"testing"
"github.com/stretchr/testify/require"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
)
func TestOverriddenManager(t *testing.T) {
require := require.New(t)
nodeID0 := ids.GenerateTestNodeID()
nodeID1 := ids.GenerateTestNodeID()
subnetID0 := ids.GenerateTestID()
subnetID1 := ids.GenerateTestID()
m := validators.NewManager()
require.NoError(m.AddStaker(subnetID0, nodeID0, nil, ids.Empty, 1))
require.NoError(m.AddStaker(subnetID1, nodeID1, nil, ids.Empty, 1))
om := newOverriddenManager(subnetID0, m)
_, ok := om.GetValidator(subnetID0, nodeID0)
require.True(ok)
_, ok = om.GetValidator(subnetID0, nodeID1)
require.False(ok)
_, ok = om.GetValidator(subnetID1, nodeID0)
require.True(ok)
_, ok = om.GetValidator(subnetID1, nodeID1)
require.False(ok)
require.NoError(om.RemoveWeight(subnetID1, nodeID0, 1))
_, ok = om.GetValidator(subnetID0, nodeID0)
require.False(ok)
_, ok = om.GetValidator(subnetID0, nodeID1)
require.False(ok)
_, ok = om.GetValidator(subnetID1, nodeID0)
require.False(ok)
_, ok = om.GetValidator(subnetID1, nodeID1)
require.False(ok)
}
func TestOverriddenString(t *testing.T) {
require := require.New(t)
nodeID0 := ids.EmptyNodeID
nodeID1, err := ids.NodeIDFromString("NodeID-QLbz7JHiBTspS962RLKV8GndWFwdYhk6V")
require.NoError(err)
subnetID0, err := ids.FromString("TtF4d2QWbk5vzQGTEPrN48x6vwgAoAmKQ9cbp79inpQmcRKES")
require.NoError(err)
subnetID1, err := ids.FromString("2mcwQKiD8VEspmMJpL1dc7okQQ5dDVAWeCBZ7FWBFAbxpv3t7w")
require.NoError(err)
m := validators.NewManager()
require.NoError(m.AddStaker(subnetID0, nodeID0, nil, ids.Empty, 1))
require.NoError(m.AddStaker(subnetID0, nodeID1, nil, ids.Empty, math.MaxInt64-1))
require.NoError(m.AddStaker(subnetID1, nodeID1, nil, ids.Empty, 1))
om := newOverriddenManager(subnetID0, m)
expected := `Overridden Validator Manager (SubnetID = TtF4d2QWbk5vzQGTEPrN48x6vwgAoAmKQ9cbp79inpQmcRKES): Validator Manager: (Size = 2)
Subnet[TtF4d2QWbk5vzQGTEPrN48x6vwgAoAmKQ9cbp79inpQmcRKES]: Validator Set: (Size = 2, Weight = 9223372036854775807)
Validator[0]: NodeID-111111111111111111116DBWJs, 1
Validator[1]: NodeID-QLbz7JHiBTspS962RLKV8GndWFwdYhk6V, 9223372036854775806
Subnet[2mcwQKiD8VEspmMJpL1dc7okQQ5dDVAWeCBZ7FWBFAbxpv3t7w]: Validator Set: (Size = 1, Weight = 1)
Validator[0]: NodeID-QLbz7JHiBTspS962RLKV8GndWFwdYhk6V, 1`
result := om.String()
require.Equal(expected, result)
}