Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/max file size #923

Merged
merged 10 commits into from
Nov 1, 2023
1 change: 0 additions & 1 deletion tests/cli_tests/zboxcli_list_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
98 changes: 98 additions & 0 deletions tests/cli_tests/zboxcli_max_file_test.go
Original file line number Diff line number Diff line change
@@ -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")
})
}
6 changes: 2 additions & 4 deletions tests/cli_tests/zboxcli_update_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading