From c6cad02c349cfbcf17322178cb7f1f090fb20b41 Mon Sep 17 00:00:00 2001 From: Lz Date: Tue, 14 Dec 2021 16:50:43 +0800 Subject: [PATCH 1/8] fix(share): Folder not shared should fail to download --- tests/cli_tests/zboxcli_share_file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index d6ccc4ec58..7acba7e619 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -846,7 +846,7 @@ func TestShareFile(t *testing.T) { output, err = downloadFileForWallet(t, receiverWallet, configPath, downloadParams, false) require.NotNil(t, err, strings.Join(output, "\n")) require.Len(t, output, 1, "download file - Unexpected output", strings.Join(output, "\n")) - require.Equal(t, "Error in file operation: No minimum consensus for file meta data of file", output[0], + require.Equal(t, "Error in file operation: Cannot download directory", output[0], "download file - Unexpected output", strings.Join(output, "\n")) }) From 1cc034c52b3ba3e572198ec6a7ee8145a08e3eea Mon Sep 17 00:00:00 2001 From: Lz Date: Wed, 15 Dec 2021 11:48:22 +0800 Subject: [PATCH 2/8] fix(share): 0chain/zboxcli#145 fixed share folder bug --- tests/cli_tests/zboxcli_share_file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 7acba7e619..aaaababf41 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -846,7 +846,7 @@ func TestShareFile(t *testing.T) { output, err = downloadFileForWallet(t, receiverWallet, configPath, downloadParams, false) require.NotNil(t, err, strings.Join(output, "\n")) require.Len(t, output, 1, "download file - Unexpected output", strings.Join(output, "\n")) - require.Equal(t, "Error in file operation: Cannot download directory", output[0], + require.Equal(t, "Error in file operation: please get files from folder, and download them one by one", output[0], "download file - Unexpected output", strings.Join(output, "\n")) }) From 7deeec466590d9d1b5415d990a68383db3273b6c Mon Sep 17 00:00:00 2001 From: Lz Date: Wed, 15 Dec 2021 14:31:24 +0800 Subject: [PATCH 3/8] fix(share): 0chain/zboxcli#145 fixed 'get file stats for an allocation you dont own' --- tests/cli_tests/zboxcli_file_stats_test.go | 23 +++------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/tests/cli_tests/zboxcli_file_stats_test.go b/tests/cli_tests/zboxcli_file_stats_test.go index 70cdfb39e7..b4146e7068 100644 --- a/tests/cli_tests/zboxcli_file_stats_test.go +++ b/tests/cli_tests/zboxcli_file_stats_test.go @@ -230,8 +230,6 @@ func TestFileStats(t *testing.T) { t.Run("get file stats for an allocation you dont own", func(t *testing.T) { t.Parallel() - var stats map[string]climodel.FileStats - otherAllocationID := "" remotepath := "/" filesize := int64(533) @@ -252,7 +250,7 @@ func TestFileStats(t *testing.T) { }), true) require.Nil(t, err, strings.Join(output, "\n")) require.Len(t, output, 1) - + var stats map[string]climodel.FileStats err = json.Unmarshal([]byte(output[0]), &stats) require.Nil(t, err) @@ -285,25 +283,10 @@ func TestFileStats(t *testing.T) { require.Nil(t, err, strings.Join(output, "\n")) require.Len(t, output, 1) - + var stats map[string]climodel.FileStats err = json.Unmarshal([]byte(output[0]), &stats) require.Nil(t, err) - - for _, data := range stats { - require.Equal(t, "", data.Name) - require.Equal(t, "", data.Path) - require.Equal(t, "", data.PathHash) - require.Equal(t, int64(0), data.Size) - require.Equal(t, int64(0), data.NumOfBlocks) - require.Equal(t, int64(0), data.NumOfBlockDownloads) - require.Equal(t, int64(0), data.NumOfChallenges) - require.Equal(t, int64(0), data.NumOfUpdates) - require.Equal(t, "", data.WriteMarkerTxn) - require.Equal(t, "", data.LastChallengeTxn) - require.Equal(t, "", data.BlobberID) - require.Equal(t, "", data.BlobberURL) - require.Equal(t, false, data.BlockchainAware) - } + require.Len(t, stats, 0) }) t.Run("get file stats with no params supplied", func(t *testing.T) { From d76075039fbe95c13687e992e0dc7c2a8344866a Mon Sep 17 00:00:00 2001 From: Lz Date: Wed, 15 Dec 2021 14:36:02 +0800 Subject: [PATCH 4/8] fix(share): 0chain/zboxcli#145 fixed 'Share folder with encrypted file using auth ticket - proxy re-encryption' --- tests/cli_tests/zboxcli_share_file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index aaaababf41..d6ccc4ec58 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -846,7 +846,7 @@ func TestShareFile(t *testing.T) { output, err = downloadFileForWallet(t, receiverWallet, configPath, downloadParams, false) require.NotNil(t, err, strings.Join(output, "\n")) require.Len(t, output, 1, "download file - Unexpected output", strings.Join(output, "\n")) - require.Equal(t, "Error in file operation: please get files from folder, and download them one by one", output[0], + require.Equal(t, "Error in file operation: No minimum consensus for file meta data of file", output[0], "download file - Unexpected output", strings.Join(output, "\n")) }) From 8e86679c4b1df8dd1d3aebf3be95bf1528ba0456 Mon Sep 17 00:00:00 2001 From: Lz Date: Wed, 15 Dec 2021 22:07:51 +0800 Subject: [PATCH 5/8] fix(share): 0chain/zboxcli#145 added wait before readPoolInfoWithWallet --- tests/cli_tests/zboxcli_share_file_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index d6ccc4ec58..7a9a2b3eb4 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1288,6 +1288,9 @@ func TestShareFile(t *testing.T) { require.Equal(t, "Status completed callback. Type = application/octet-stream. Name = "+filepath.Base(file), output[1], "download file - Unexpected output", strings.Join(output, "\n")) + // wait ReadMarker to redeem + cliutils.Wait(t, 30*time.Second) + // Read pool after download output, err = readPoolInfoWithwallet(t, receiverWallet, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) @@ -1413,6 +1416,9 @@ func TestShareFile(t *testing.T) { require.Equal(t, "Status completed callback. Type = application/octet-stream. Name = "+filepath.Base(filename), output[1], "download file - Unexpected output", strings.Join(output, "\n")) + // wait ReadMarker to redeem + cliutils.Wait(t, 30*time.Second) + // Read pool after download output, err = readPoolInfoWithwallet(t, receiverWallet, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) From b093312121b73689dc8e7f912452d259a7f58d8b Mon Sep 17 00:00:00 2001 From: Lz Date: Sat, 25 Dec 2021 14:43:23 +0800 Subject: [PATCH 6/8] fix(download):improved register wallet --- tests/cli_tests/zboxcli_share_file_test.go | 35 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 7a9a2b3eb4..05140e9d75 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1,6 +1,7 @@ package cli_tests import ( + "encoding/hex" "encoding/json" "fmt" "os" @@ -14,6 +15,7 @@ import ( climodel "github.com/0chain/system_test/internal/cli/model" cliutils "github.com/0chain/system_test/internal/cli/util" "github.com/stretchr/testify/require" + "golang.org/x/crypto/sha3" ) func TestShareFile(t *testing.T) { @@ -1281,6 +1283,7 @@ func TestShareFile(t *testing.T) { downloadParams := createParams(map[string]interface{}{ "localpath": file, "authticket": authTicket, + "lookuphash": GetReferenceLookup(allocationID, file), }) output, err = downloadFileForWallet(t, receiverWallet, configPath, downloadParams, false) require.Nil(t, err, strings.Join(output, "\n")) @@ -1288,9 +1291,6 @@ func TestShareFile(t *testing.T) { require.Equal(t, "Status completed callback. Type = application/octet-stream. Name = "+filepath.Base(file), output[1], "download file - Unexpected output", strings.Join(output, "\n")) - // wait ReadMarker to redeem - cliutils.Wait(t, 30*time.Second) - // Read pool after download output, err = readPoolInfoWithwallet(t, receiverWallet, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) @@ -1409,6 +1409,7 @@ func TestShareFile(t *testing.T) { downloadParams := createParams(map[string]interface{}{ "localpath": filename, "authticket": authTicket, + "lookuphash": GetReferenceLookup(allocationID, filename), }) output, err = downloadFileForWallet(t, receiverWallet, configPath, downloadParams, false) require.Nil(t, err, strings.Join(output, "\n")) @@ -1465,8 +1466,16 @@ func shareFileWithWallet(t *testing.T, wallet, cliConfigFilename string, param m func registerAndCreateAllocation(t *testing.T, configPath, wallet string) (string, *climodel.Wallet) { faucetTokens := 3.0 // First create a wallet and run faucet command + // Output: + // [0]:"ZCN wallet created" + // [1]:"Creating related read pool for storage smart-contract..." + // [2]:"Read pool created successfully" + // [3]:"Wallet registered" output, err := registerWalletForName(t, configPath, wallet) require.Nil(t, err, "registering wallet failed", err, strings.Join(output, "\n")) + require.Len(t, len(output), 4, strings.Join(output, "\n")) + require.Equal(t, "Read pool created successfully", output[2], strings.Join(output, "\n")) + require.Equal(t, "Wallet registered", output[3], strings.Join(output, "\n")) output, err = executeFaucetWithTokensForWallet(t, wallet, configPath, faucetTokens) require.Nil(t, err, "faucet execution failed", err, strings.Join(output, "\n")) @@ -1474,7 +1483,7 @@ func registerAndCreateAllocation(t *testing.T, configPath, wallet string) (strin allocParam := createParams(map[string]interface{}{ "lock": 0.5, "size": 10485760, - "expire": "1h", + "expire": "2h", "parity": 1, "data": 1, }) @@ -1505,3 +1514,21 @@ func registerAndCreateAllocation(t *testing.T, configPath, wallet string) (strin return allocationID, walletModel } + +// Hash - hash the given data and return the hash as hex string +func Hash(data string) string { + return hex.EncodeToString(RawHash(data)) +} + +// RawHash - Logic to hash the text and return the hash bytes +func RawHash(data string) []byte { + hash := sha3.New256() + hash.Write([]byte(data)) + var buf []byte + return hash.Sum(buf) +} + +// GetReferenceLookup hash(allocationID + ":" + path) +func GetReferenceLookup(allocationID, path string) string { + return Hash(allocationID + ":" + path) +} From 5f5ba7a99d06d20a8f6d48e879826b6bc034dc30 Mon Sep 17 00:00:00 2001 From: Lz Date: Sat, 25 Dec 2021 14:50:11 +0800 Subject: [PATCH 7/8] fix(download):removed duplicated wait --- tests/cli_tests/zboxcli_share_file_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 05140e9d75..53f459f42d 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1417,9 +1417,6 @@ func TestShareFile(t *testing.T) { require.Equal(t, "Status completed callback. Type = application/octet-stream. Name = "+filepath.Base(filename), output[1], "download file - Unexpected output", strings.Join(output, "\n")) - // wait ReadMarker to redeem - cliutils.Wait(t, 30*time.Second) - // Read pool after download output, err = readPoolInfoWithwallet(t, receiverWallet, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) From 4135118d6e3ecf1c8b848fc447c0aecb248c5d49 Mon Sep 17 00:00:00 2001 From: Lz Date: Sat, 25 Dec 2021 15:04:15 +0800 Subject: [PATCH 8/8] fix(download):improved register wallet --- tests/cli_tests/zboxcli_share_file_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 53f459f42d..3f40acf84a 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1210,6 +1210,9 @@ func TestShareFile(t *testing.T) { output, err = registerWalletForName(t, configPath, receiverWallet) require.Nil(t, err, "registering wallet failed", err, strings.Join(output, "\n")) + require.Len(t, output, 4, strings.Join(output, "\n")) + require.Equal(t, "Read pool created successfully", output[2], strings.Join(output, "\n")) + require.Equal(t, "Wallet registered", output[3], strings.Join(output, "\n")) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -1344,6 +1347,9 @@ func TestShareFile(t *testing.T) { output, err = registerWalletForName(t, configPath, receiverWallet) require.Nil(t, err, "registering wallet failed", err, strings.Join(output, "\n")) + require.Len(t, output, 4, strings.Join(output, "\n")) + require.Equal(t, "Read pool created successfully", output[2], strings.Join(output, "\n")) + require.Equal(t, "Wallet registered", output[3], strings.Join(output, "\n")) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -1470,7 +1476,7 @@ func registerAndCreateAllocation(t *testing.T, configPath, wallet string) (strin // [3]:"Wallet registered" output, err := registerWalletForName(t, configPath, wallet) require.Nil(t, err, "registering wallet failed", err, strings.Join(output, "\n")) - require.Len(t, len(output), 4, strings.Join(output, "\n")) + require.Len(t, output, 4, strings.Join(output, "\n")) require.Equal(t, "Read pool created successfully", output[2], strings.Join(output, "\n")) require.Equal(t, "Wallet registered", output[3], strings.Join(output, "\n"))