-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzboxcli_upload_token_test.go
91 lines (71 loc) · 3.3 KB
/
zboxcli_upload_token_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
package cli_tests
import (
"encoding/json"
"fmt"
"regexp"
"strings"
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
climodel "github.com/0chain/system_test/internal/cli/model"
cliutils "github.com/0chain/system_test/internal/cli/util"
"github.com/stretchr/testify/require"
)
const tokenUnit float64 = 1e+10
func TestFileUploadTokenMovement(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("Challenge pool should be 0 before any write")
t.Parallel()
balance := 0.8 // 800.000 mZCN
t.Run("Challenge pool should be 0 before any write", func(t *test.SystemTest) {
createWallet(t)
allocParam := createParams(map[string]interface{}{
"lock": balance,
"size": 10000,
})
output, err := createNewAllocation(t, configPath, allocParam)
require.Nil(t, err, "Failed to create new allocation", strings.Join(output, "\n"))
require.Len(t, output, 1)
allocationID := strings.Fields(output[0])[2]
output, err = challengePoolInfo(t, configPath, allocationID)
require.Nil(t, err, "Could not fetch challenge pool", strings.Join(output, "\n"))
require.Len(t, output, 1)
challengePool := climodel.ChallengePoolInfo{}
err = json.Unmarshal([]byte(output[0]), &challengePool)
require.Nil(t, err, "Error unmarshalling challenge pool info", strings.Join(output, "\n"))
require.NotEmpty(t, challengePool)
require.Regexp(t, regexp.MustCompile(fmt.Sprintf("([a-f0-9]{64}):challengepool:%s", allocationID)), challengePool.Id)
require.IsType(t, int64(0), challengePool.StartTime)
require.IsType(t, int64(0), challengePool.Expiration)
require.False(t, challengePool.Finalized)
require.Equal(t, float64(0), float64(challengePool.Balance))
})
t.Run("Total balance in blobber pool equals locked tokens", func(t *test.SystemTest) {
createWallet(t)
allocParam := createParams(map[string]interface{}{
"lock": balance,
"size": 10000,
})
output, err := createNewAllocation(t, configPath, allocParam)
require.Nil(t, err, "Failed to create new allocation", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected")
allocationID := strings.Fields(output[0])[2]
allocation := getAllocation(t, allocationID)
require.Equal(t, 0.8, intToZCN(allocation.WritePool))
})
}
func getUploadCostInUnit(t *test.SystemTest, cliConfigFilename, allocationID, localpath string) ([]string, error) {
t.Logf("Getting upload cost...")
output, err := cliutils.RunCommand(t, "./zbox get-upload-cost --allocation "+allocationID+" --end --localpath "+localpath+" --silent --wallet "+escapedTestName(t)+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, 3, time.Second*2)
require.Nil(t, err, "error getting upload cost in unit", strings.Join(output, "\n"))
require.Len(t, output, 1)
return output, err
}
func challengePoolInfo(t *test.SystemTest, cliConfigFilename, allocationID string) ([]string, error) {
t.Logf("Getting challenge pool info...")
return cliutils.RunCommand(t, "./zbox cp-info --allocation "+allocationID+" --json --silent --wallet "+escapedTestName(t)+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, 3, time.Second*2)
}
func intToZCN(balance int64) float64 {
return float64(balance) / tokenUnit
}