-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnode_test.go
98 lines (66 loc) · 2.12 KB
/
node_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package substrate
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestNode(t *testing.T) {
var nodeID uint32
var node *Node
cl := startLocalConnection(t)
defer cl.Close()
identity, err := NewIdentityFromSr25519Phrase(BobMnemonics)
require.NoError(t, err)
farmID, twinID := assertCreateFarm(t, cl)
nodeID = assertCreateNode(t, cl, farmID, twinID, identity)
node, err = cl.GetNode(nodeID)
require.NoError(t, err)
require.Equal(t, twinID, uint32(node.TwinID))
require.Equal(t, farmID, uint32(node.FarmID))
nodeID, err = cl.GetNodeByTwinID(uint32(node.TwinID))
require.NoError(t, err)
require.Equal(t, uint32(node.ID), nodeID)
}
func TestGetNodes(t *testing.T) {
cl := startLocalConnection(t)
defer cl.Close()
farmID, _ := assertCreateFarm(t, cl)
nodes, err := cl.GetNodes(farmID)
require.NoError(t, err)
require.Greater(t, len(nodes), 0)
}
func TestSetDedicatedNodePrice(t *testing.T) {
var nodeID uint32
cl := startLocalConnection(t)
defer cl.Close()
identity, err := NewIdentityFromSr25519Phrase(BobMnemonics)
require.NoError(t, err)
farmID, twinID := assertCreateFarm(t, cl)
nodeID = assertCreateNode(t, cl, farmID, twinID, identity)
price := 100000000
_, err = cl.SetDedicatedNodePrice(identity, nodeID, uint64(price))
require.NoError(t, err)
priceSet, err := cl.GetDedicatedNodePrice(nodeID)
require.NoError(t, err)
require.Equal(t, uint64(price), priceSet)
}
func TestUptimeReport(t *testing.T) {
cl := startLocalConnection(t)
defer cl.Close()
identity, err := NewIdentityFromSr25519Phrase(BobMnemonics)
require.NoError(t, err)
farmID, twinID := assertCreateFarm(t, cl)
_ = assertCreateNode(t, cl, farmID, twinID, identity)
_, err = cl.UpdateNodeUptime(identity, 100)
require.NoError(t, err)
}
func TestUptimeReportV2(t *testing.T) {
cl := startLocalConnection(t)
defer cl.Close()
identity, err := NewIdentityFromSr25519Phrase(BobMnemonics)
require.NoError(t, err)
farmID, twinID := assertCreateFarm(t, cl)
_ = assertCreateNode(t, cl, farmID, twinID, identity)
_, err = cl.UpdateNodeUptimeV2(identity, 100, uint64(time.Now().Unix()))
require.NoError(t, err)
}