-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
43 lines (40 loc) · 1.13 KB
/
main_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
package main
import (
"context"
"strconv"
"testing"
"github.com/Halimao/NearStakerTool/sdk"
)
func TestGetAccounts(t *testing.T) {
allValidators := make([]ValidatorFullData, 0)
for page := 1; page < 100; page++ {
t.Log("start query validators", "page", page)
validators, err := getValidators(context.Background(), page)
if err != nil {
t.Error(err)
}
size := len(validators)
if size == 0 {
break
}
cumulativePercent, err := strconv.ParseFloat(validators[size-1].CumulativeStake.CumulativePercent, 64)
if err != nil {
t.Error(err)
}
allValidators = append(allValidators, validators...)
if cumulativePercent > 96 {
break
}
}
validator := allValidators[0]
stakeInfos, err := sdk.GetAccounts(context.Background(), validator.AccountID, 0, 1)
if err != nil {
t.Error(err)
}
t.Logf("acc: %s, amt: %.8f", stakeInfos[0].AccountID, FormatHumanityAmount(stakeInfos[0].StakedBalance))
stakeInfos, err = sdk.GetAccounts(context.Background(), validator.AccountID, 1, 2)
if err != nil {
t.Error(err)
}
t.Logf("acc: %s, amt: %.8f", stakeInfos[0].AccountID, FormatHumanityAmount(stakeInfos[0].StakedBalance))
}