-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzboxcli_finalize_allocation_test.go
74 lines (60 loc) · 2.53 KB
/
zboxcli_finalize_allocation_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
package cli_tests
import (
"fmt"
"strings"
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
cliutils "github.com/0chain/system_test/internal/cli/util"
"github.com/stretchr/testify/require"
)
func TestFinalizeAllocation(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.Parallel()
t.Run("Finalize Non-Expired Allocation Should Fail", func(t *test.SystemTest) {
allocationID := setupAllocation(t, configPath)
output, err := finalizeAllocation(t, configPath, allocationID, false)
require.NotNil(t, err, "expected error updating allocation", strings.Join(output, "\n"))
require.True(t, len(output) > 0, "expected output length be at least 1", strings.Join(output, "\n"))
require.Equal(t, "Error finalizing allocation:fini_alloc_failed: allocation is not expired yet", output[0])
})
t.Run("Finalize Other's Allocation Should Fail", func(t *test.SystemTest) {
var otherAllocationID = setupAllocationWithWallet(t, escapedTestName(t)+"_other_wallet.json", configPath)
// create wallet
createWallet(t)
// Then try updating with otherAllocationID: should not work
output, err := finalizeAllocation(t, configPath, otherAllocationID, false)
// Error should not be nil since finalize is not working
require.NotNil(t, err, "expected error finalizing allocation", strings.Join(output, "\n"))
require.True(t, len(output) > 0, "expected output length be at least 1", strings.Join(output, "\n"))
require.Equal(t, "Error finalizing allocation:fini_alloc_failed: not allowed, unknown finalization initiator", output[len(output)-1])
})
t.Run("No allocation param should fail", func(t *test.SystemTest) {
createWallet(t)
cmd := fmt.Sprintf(
"./zbox alloc-fini --silent "+
"--wallet %s --configDir ./config --config %s",
escapedTestName(t)+"_wallet.json",
configPath,
)
output, err := cliutils.RunCommandWithoutRetry(cmd)
require.Error(t, err, "expected error finalizing allocation", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Equal(t, "Error: allocation flag is missing", output[len(output)-1])
})
}
func finalizeAllocation(t *test.SystemTest, cliConfigFilename, allocationID string, retry bool) ([]string, error) {
t.Logf("Finalizing allocation...")
cmd := fmt.Sprintf(
"./zbox alloc-fini --allocation %s "+
"--silent --wallet %s --configDir ./config --config %s",
allocationID,
escapedTestName(t)+"_wallet.json",
cliConfigFilename,
)
if retry {
return cliutils.RunCommand(t, cmd, 3, time.Second*2)
} else {
return cliutils.RunCommandWithoutRetry(cmd)
}
}