From ae36f8ba046db0b673d1d924ec5316fdd60d471c Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 31 Oct 2023 04:30:30 +0530 Subject: [PATCH 1/7] Added max_file_size --- tests/cli_tests/zboxcli_list_file_test.go | 1 - tests/cli_tests/zboxcli_max_file_test.go | 94 +++++++++++++++++++ .../zboxcli_update_allocation_test.go | 6 +- 3 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 tests/cli_tests/zboxcli_max_file_test.go 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..711182ce42 --- /dev/null +++ b/tests/cli_tests/zboxcli_max_file_test.go @@ -0,0 +1,94 @@ +package cli_tests + +import ( + "github.com/0chain/system_test/internal/api/util/test" + "github.com/0chain/system_test/tests/tokenomics_tests/utils" + "github.com/stretchr/testify/require" + "path/filepath" + "strings" + "testing" +) + +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")) + }) + + 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) + + output, err = utils.UploadFile(t, configPath, map[string]interface{}{ + "allocation": allocationId, + "remotepath": remotepath + filepath.Base(filename), + "localpath": filename, + }, true) + 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] From 603797cb831ee6ff0f676d757abe366de4c5c84f Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 31 Oct 2023 06:33:28 +0530 Subject: [PATCH 2/7] Updated actions branch for debugging --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd9b8368b5..2868ac5c8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: github-token: ${{ github.token }} - name: "Set PR status as pending" - uses: 0chain/actions/set-pr-status@master + uses: 0chain/actions/set-pr-status@feature/max-file-size if: steps.findPr.outputs.number && github.event.inputs.test_file_filter == '' with: pr_number: ${{ steps.findPr.outputs.pr }} @@ -109,7 +109,7 @@ jobs: - name: "Deploy 0Chain" if: github.event_name == 'push' || github.event.inputs.existing_network == '' - uses: 0chain/actions/deploy-0chain@master + uses: 0chain/actions/deploy-0chain@feature/max-file-size with: repo_snapshots_branch: "${{ env.REPO_SNAPSHOTS_BRANCH }}" kube_config: ${{ secrets[format('DEV{0}KC', env.RUNNER_NUMBER)] }} @@ -122,7 +122,7 @@ jobs: svc_account_secret: ${{ secrets.SVC_ACCOUNT_SECRET }} - name: "Run System tests" - uses: 0chain/actions/run-system-tests@master + uses: 0chain/actions/run-system-tests@feature/max-file-size with: repo_snapshots_branch: "${{ env.REPO_SNAPSHOTS_BRANCH }}" system_tests_branch: ${{ env.CURRENT_BRANCH }} @@ -142,7 +142,7 @@ jobs: - name: "Set PR status as ${{ job.status }}" if: ${{ (success() || failure()) && steps.findPr.outputs.number && github.event.inputs.test_file_filter == '' }} - uses: 0chain/actions/set-pr-status@master + uses: 0chain/actions/set-pr-status@feature/max-file-size with: pr_number: ${{ steps.findPr.outputs.pr }} description: "System tests with default config ${{ job.status }}" From bc8f5ea008ef72839249ffedc7a1d265e072607f Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 31 Oct 2023 19:25:26 +0530 Subject: [PATCH 3/7] Fix --- tests/cli_tests/zboxcli_max_file_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cli_tests/zboxcli_max_file_test.go b/tests/cli_tests/zboxcli_max_file_test.go index 711182ce42..3696e4a147 100644 --- a/tests/cli_tests/zboxcli_max_file_test.go +++ b/tests/cli_tests/zboxcli_max_file_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "strings" "testing" + "time" ) func TestMaxFileSize(testSetup *testing.T) { @@ -17,6 +18,8 @@ func TestMaxFileSize(testSetup *testing.T) { "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() { From 44dc59ea574e9eef85cd8ac67225117341a9a99c Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 31 Oct 2023 23:49:47 +0530 Subject: [PATCH 4/7] Fix --- tests/cli_tests/zboxcli_max_file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_max_file_test.go b/tests/cli_tests/zboxcli_max_file_test.go index 3696e4a147..7715399b5e 100644 --- a/tests/cli_tests/zboxcli_max_file_test.go +++ b/tests/cli_tests/zboxcli_max_file_test.go @@ -91,7 +91,7 @@ func TestMaxFileSize(testSetup *testing.T) { "allocation": allocationId, "remotepath": remotepath + filepath.Base(filename), "localpath": filename, - }, true) + }, false) require.Error(t, err, "Upload should fail") }) } From b34b83c4b911508e94832ebb01bbaaef0217875a Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Wed, 1 Nov 2023 00:59:26 +0530 Subject: [PATCH 5/7] Fix --- tests/cli_tests/zboxcli_max_file_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/cli_tests/zboxcli_max_file_test.go b/tests/cli_tests/zboxcli_max_file_test.go index 7715399b5e..8dd169aedf 100644 --- a/tests/cli_tests/zboxcli_max_file_test.go +++ b/tests/cli_tests/zboxcli_max_file_test.go @@ -1,13 +1,14 @@ package cli_tests import ( - "github.com/0chain/system_test/internal/api/util/test" - "github.com/0chain/system_test/tests/tokenomics_tests/utils" - "github.com/stretchr/testify/require" "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) { From 72065a7861ee74d57d33dc9f980364de07949abb Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Wed, 1 Nov 2023 01:01:17 +0530 Subject: [PATCH 6/7] Fix lint --- tests/cli_tests/zboxcli_max_file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_max_file_test.go b/tests/cli_tests/zboxcli_max_file_test.go index 8dd169aedf..53ebba3fb0 100644 --- a/tests/cli_tests/zboxcli_max_file_test.go +++ b/tests/cli_tests/zboxcli_max_file_test.go @@ -88,7 +88,7 @@ func TestMaxFileSize(testSetup *testing.T) { err = utils.CreateFileWithSize(filename, int64(filesize)) require.Nil(t, err) - output, err = utils.UploadFile(t, configPath, map[string]interface{}{ + _, err = utils.UploadFile(t, configPath, map[string]interface{}{ "allocation": allocationId, "remotepath": remotepath + filepath.Base(filename), "localpath": filename, From ddfab1d75ce7e296e0f02f0383169e40908bd7df Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Wed, 1 Nov 2023 03:19:43 +0530 Subject: [PATCH 7/7] Reverted CI changes --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2868ac5c8b..fd9b8368b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: github-token: ${{ github.token }} - name: "Set PR status as pending" - uses: 0chain/actions/set-pr-status@feature/max-file-size + uses: 0chain/actions/set-pr-status@master if: steps.findPr.outputs.number && github.event.inputs.test_file_filter == '' with: pr_number: ${{ steps.findPr.outputs.pr }} @@ -109,7 +109,7 @@ jobs: - name: "Deploy 0Chain" if: github.event_name == 'push' || github.event.inputs.existing_network == '' - uses: 0chain/actions/deploy-0chain@feature/max-file-size + uses: 0chain/actions/deploy-0chain@master with: repo_snapshots_branch: "${{ env.REPO_SNAPSHOTS_BRANCH }}" kube_config: ${{ secrets[format('DEV{0}KC', env.RUNNER_NUMBER)] }} @@ -122,7 +122,7 @@ jobs: svc_account_secret: ${{ secrets.SVC_ACCOUNT_SECRET }} - name: "Run System tests" - uses: 0chain/actions/run-system-tests@feature/max-file-size + uses: 0chain/actions/run-system-tests@master with: repo_snapshots_branch: "${{ env.REPO_SNAPSHOTS_BRANCH }}" system_tests_branch: ${{ env.CURRENT_BRANCH }} @@ -142,7 +142,7 @@ jobs: - name: "Set PR status as ${{ job.status }}" if: ${{ (success() || failure()) && steps.findPr.outputs.number && github.event.inputs.test_file_filter == '' }} - uses: 0chain/actions/set-pr-status@feature/max-file-size + uses: 0chain/actions/set-pr-status@master with: pr_number: ${{ steps.findPr.outputs.pr }} description: "System tests with default config ${{ job.status }}"