diff --git a/tests/cli_tests/zboxcli_list_file_test.go b/tests/cli_tests/zboxcli_list_file_test.go index 7b548eaa0a..7030831b8d 100644 --- a/tests/cli_tests/zboxcli_list_file_test.go +++ b/tests/cli_tests/zboxcli_list_file_test.go @@ -609,7 +609,6 @@ func createFileWithSize(name string, size int64) error { func generateRandomTestFileName(t *test.SystemTest) string { path := strings.TrimSuffix(os.TempDir(), string(os.PathSeparator)) - //FIXME: Filenames longer than 100 characters are rejected see https://github.com/0chain/zboxcli/issues/249 randomFilename := cliutils.RandomAlphaNumericString(10) return fmt.Sprintf("%s%s%s_test.txt", path, string(os.PathSeparator), randomFilename) } diff --git a/tests/cli_tests/zboxcli_max_file_test.go b/tests/cli_tests/zboxcli_max_file_test.go new file mode 100644 index 0000000000..53ebba3fb0 --- /dev/null +++ b/tests/cli_tests/zboxcli_max_file_test.go @@ -0,0 +1,98 @@ +package cli_tests + +import ( + "path/filepath" + "strings" + "testing" + "time" + + "github.com/0chain/system_test/internal/api/util/test" + "github.com/0chain/system_test/tests/tokenomics_tests/utils" + "github.com/stretchr/testify/require" +) + +func TestMaxFileSize(testSetup *testing.T) { + t := test.NewSystemTest(testSetup) + + t.TestSetup("Create new owner wallet", func() { + output, err := updateStorageSCConfig(t, scOwnerWallet, map[string]string{ + "max_file_size": "1024", + }, true) + require.Nil(t, err, strings.Join(output, "\n")) + + time.Sleep(2 * time.Minute) // Wait for config to take effect on blobber + }) + + t.Cleanup(func() { + output, err := updateStorageSCConfig(t, scOwnerWallet, map[string]string{ + "max_file_size": "1000000000000", + }, true) + require.Nil(t, err, strings.Join(output, "\n")) + }) + + t.Run("should be able to upload files equal or smaller than max_file_size per blobber", func(t *test.SystemTest) { + output, err := utils.CreateWallet(t, configPath) + require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) + + _, err = utils.ExecuteFaucetWithTokens(t, configPath, 9) + require.Nil(t, err, "Error executing faucet", strings.Join(output, "\n")) + + output, err = utils.CreateNewAllocation(t, configPath, utils.CreateParams(map[string]interface{}{ + "size": 10 * MB, + "data": 1, + "lock": 2, + "parity": 1, + })) + require.Nil(t, err, "Error creating allocation", strings.Join(output, "\n")) + + allocationId, err := utils.GetAllocationID(output[0]) + require.Nil(t, err, "Error getting allocation ID", strings.Join(output, "\n")) + + remotepath := "/dir/" + filesize := 1024 + filename := utils.GenerateRandomTestFileName(t) + + err = utils.CreateFileWithSize(filename, int64(filesize)) + require.Nil(t, err) + + output, err = utils.UploadFile(t, configPath, map[string]interface{}{ + "allocation": allocationId, + "remotepath": remotepath + filepath.Base(filename), + "localpath": filename, + }, true) + require.Nil(t, err, "error uploading file", strings.Join(output, "\n")) + }) + + t.Run("upload should fail on sizes higher than max_file_size per blobber", func(t *test.SystemTest) { + output, err := utils.CreateWallet(t, configPath) + require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) + + _, err = utils.ExecuteFaucetWithTokens(t, configPath, 9) + require.Nil(t, err, "Error executing faucet", strings.Join(output, "\n")) + + output, err = utils.CreateNewAllocation(t, configPath, utils.CreateParams(map[string]interface{}{ + "size": 10 * MB, + "data": 1, + "lock": 2, + "parity": 1, + })) + require.Nil(t, err, "Error creating allocation", strings.Join(output, "\n")) + + allocationId, err := utils.GetAllocationID(output[0]) + require.Nil(t, err, "Error getting allocation ID", strings.Join(output, "\n")) + + remotepath := "/dir/" + filesize := 2048 + filename := utils.GenerateRandomTestFileName(t) + + err = utils.CreateFileWithSize(filename, int64(filesize)) + require.Nil(t, err) + + _, err = utils.UploadFile(t, configPath, map[string]interface{}{ + "allocation": allocationId, + "remotepath": remotepath + filepath.Base(filename), + "localpath": filename, + }, false) + require.Error(t, err, "Upload should fail") + }) +} diff --git a/tests/cli_tests/zboxcli_update_allocation_test.go b/tests/cli_tests/zboxcli_update_allocation_test.go index 29b34e44e9..3cf0d76ea6 100644 --- a/tests/cli_tests/zboxcli_update_allocation_test.go +++ b/tests/cli_tests/zboxcli_update_allocation_test.go @@ -792,10 +792,8 @@ func TestUpdateAllocation(testSetup *testing.T) { func setupAndParseAllocation(t *test.SystemTest, cliConfigFilename string, extraParams ...map[string]interface{}) (string, climodel.Allocation) { allocationID := setupAllocation(t, cliConfigFilename, extraParams...) - for i := 0; i < 2; i++ { - _, err := executeFaucetWithTokens(t, configPath, 10) - require.NoError(t, err, "faucet execution failed") - } + _, err := executeFaucetWithTokens(t, configPath, 20) + require.NoError(t, err, "faucet execution failed") allocations := parseListAllocations(t, cliConfigFilename) allocation, ok := allocations[allocationID]