From 34fa6d2bfb0fbd42698117caf61053bcaef13afe Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Wed, 23 Mar 2022 15:41:37 +0545 Subject: [PATCH 1/6] fix download accounting test --- .../cli_tests/zboxcli_download_token_test.go | 16 ++++--------- tests/cli_tests/zboxcli_share_file_test.go | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/cli_tests/zboxcli_download_token_test.go b/tests/cli_tests/zboxcli_download_token_test.go index 7b430b9ff9..d27feb2170 100644 --- a/tests/cli_tests/zboxcli_download_token_test.go +++ b/tests/cli_tests/zboxcli_download_token_test.go @@ -186,11 +186,11 @@ func TestFileDownloadTokenMovement(t *testing.T) { }), true) require.Nil(t, err, "Could not get download cost", strings.Join(output, "\n")) - expectedDownloadCostInZCN, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64) + expectedDownloadCost, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64) require.Nil(t, err, "Cost couldn't be parsed to float", strings.Join(output, "\n")) unit := strings.Fields(output[0])[1] - expectedDownloadCostInZCN = unitToZCN(expectedDownloadCostInZCN, unit) + expectedDownloadCostInZCN := unitToZCN(expectedDownloadCost, unit) // Download the file output, err = downloadFile(t, configPath, createParams(map[string]interface{}{ @@ -213,8 +213,9 @@ func TestFileDownloadTokenMovement(t *testing.T) { err = json.Unmarshal([]byte(output[0]), &finalReadPool) require.Nil(t, err, "Error unmarshalling read pool", strings.Join(output, "\n")) + expectedRPBalance := 0.4*1e10 - expectedDownloadCostInZCN*1e10 require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) - require.Less(t, intToZCN(finalReadPool[0].Balance), 0.4) + require.Less(t, finalReadPool[0].Balance, expectedRPBalance) require.IsType(t, int64(1), finalReadPool[0].ExpireAt) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) @@ -223,11 +224,7 @@ func TestFileDownloadTokenMovement(t *testing.T) { for i := 0; i < len(finalReadPool[0].Blobber); i++ { require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Blobber[i].BlobberID) require.IsType(t, int64(1), finalReadPool[0].Blobber[i].Balance) - - // amount deducted - diff := intToZCN(initialReadPool[0].Blobber[i].Balance) - intToZCN(finalReadPool[0].Blobber[i].Balance) - t.Logf("blobber [%v] read pool was deducted by [%v]", i, diff) - require.InEpsilon(t, expectedDownloadCostInZCN, diff, epsilon, "blobber [%v] read pool was deducted by [%v] rather than the expected [%v]", i, diff, expectedDownloadCostInZCN) + require.Greater(t, initialReadPool[0].Blobber[i].Balance, finalReadPool[0].Blobber[i].Balance) } }) } @@ -281,9 +278,6 @@ func unitToZCN(unitCost float64, unit string) float64 { case "mZCN", "mzcn": unitCost /= 1e3 return unitCost - case "ZCN", "zcn": - unitCost /= 1e0 - return unitCost } return unitCost } diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 8521863b9a..ae29a882b2 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1046,12 +1046,12 @@ func TestShareFile(t *testing.T) { }), true) require.Nil(t, err, "Could not get download cost", strings.Join(output, "\n")) - expectedDownloadCostInZCN, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64) + expectedDownloadCost, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64) require.Nil(t, err, "Cost couldn't be parsed to float", strings.Join(output, "\n")) unit := strings.Fields(output[0])[1] - expectedDownloadCostInZCN = unitToZCN(expectedDownloadCostInZCN, unit) * 1e10 - t.Logf("Download cost: %v", expectedDownloadCostInZCN) + expectedDownloadCostInSas := unitToZCN(expectedDownloadCost, unit) * 1e10 + t.Logf("Download cost: %v sas", expectedDownloadCostInSas) // Download the file (delete local copy first) os.Remove(file) @@ -1074,8 +1074,10 @@ func TestShareFile(t *testing.T) { err = json.Unmarshal([]byte(output[0]), &finalReadPool) require.Nil(t, err, "Error unmarshalling read pool", strings.Join(output, "\n")) + expectedRPBalance := 0.4*1e10 - expectedDownloadCostInSas + require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) - require.Equal(t, 0.4*1e10, float64(finalReadPool[0].Balance)) + require.Equal(t, expectedRPBalance, float64(finalReadPool[0].Balance)) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) require.True(t, finalReadPool[0].Locked) @@ -1084,7 +1086,7 @@ func TestShareFile(t *testing.T) { for i := 0; i < len(finalReadPool[0].Blobber); i++ { require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Blobber[i].BlobberID) t.Logf("Blobber [%v] balance is [%v]", i, initialReadPool[0].Blobber[i].Balance) - require.Equal(t, initialReadPool[0].Blobber[i].Balance, finalReadPool[0].Blobber[i].Balance) + require.Greater(t, initialReadPool[0].Blobber[i].Balance, finalReadPool[0].Blobber[i].Balance) } }) @@ -1155,12 +1157,12 @@ func TestShareFile(t *testing.T) { }), true) require.Nil(t, err, "Could not get download cost", strings.Join(output, "\n")) - expectedDownloadCostInZCN, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64) + expectedDownloadCost, err := strconv.ParseFloat(strings.Fields(output[0])[0], 64) require.Nil(t, err, "Cost couldn't be parsed to float", strings.Join(output, "\n")) unit := strings.Fields(output[0])[1] - expectedDownloadCostInZCN = unitToZCN(expectedDownloadCostInZCN, unit) * 1e10 - t.Logf("Download cost: %v", expectedDownloadCostInZCN) + expectedDownloadCostInSas := unitToZCN(expectedDownloadCost, unit) * 1e10 + t.Logf("Download cost: %v sas", expectedDownloadCostInSas) // Download the file (delete local copy first) os.Remove(file) @@ -1183,8 +1185,9 @@ func TestShareFile(t *testing.T) { err = json.Unmarshal([]byte(output[0]), &finalReadPool) require.Nil(t, err, "Error unmarshalling read pool", strings.Join(output, "\n")) + expectedRPBalance := 0.4*1e10 - expectedDownloadCostInSas require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) - require.Equal(t, 0.4*1e10, float64(finalReadPool[0].Balance)) + require.Equal(t, expectedRPBalance, float64(finalReadPool[0].Balance)) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) require.True(t, finalReadPool[0].Locked) @@ -1193,7 +1196,7 @@ func TestShareFile(t *testing.T) { for i := 0; i < len(finalReadPool[0].Blobber); i++ { require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Blobber[i].BlobberID) t.Logf("Blobber [%v] balance is [%v]", i, initialReadPool[0].Blobber[i].Balance) - require.Equal(t, initialReadPool[0].Blobber[i].Balance, finalReadPool[0].Blobber[i].Balance) + require.Greater(t, initialReadPool[0].Blobber[i].Balance, finalReadPool[0].Blobber[i].Balance) } }) From 552cea074feef4bd899ba2208a576c9908f98d80 Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Wed, 23 Mar 2022 15:46:04 +0545 Subject: [PATCH 2/6] Add wait period for read-redeem --- tests/cli_tests/zboxcli_download_token_test.go | 4 ++++ tests/cli_tests/zboxcli_share_file_test.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/tests/cli_tests/zboxcli_download_token_test.go b/tests/cli_tests/zboxcli_download_token_test.go index d27feb2170..ce5ba267a3 100644 --- a/tests/cli_tests/zboxcli_download_token_test.go +++ b/tests/cli_tests/zboxcli_download_token_test.go @@ -205,6 +205,10 @@ func TestFileDownloadTokenMovement(t *testing.T) { require.Len(t, output, 2) require.Equal(t, "Status completed callback. Type = application/octet-stream. Name = "+filename, output[1]) + // Wait for blobber to redeem read-tokens + // Blobber runs worker in the interval of usually 10 seconds. + time.Sleep(time.Second * 20) + // Read pool after download output, err = readPoolInfo(t, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index ae29a882b2..3ca78559b6 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1177,6 +1177,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 for blobber to redeem read-tokens + // Blobber runs worker in the interval of usually 10 seconds. + time.Sleep(time.Second * 20) // Read pool after download output, err = readPoolInfo(t, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) @@ -1313,6 +1316,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 for blobber to redeem read-tokens + // Blobber runs worker in the interval of usually 10 seconds. + time.Sleep(time.Second * 20) // Read pool after download output, err = readPoolInfoWithwallet(t, receiverWallet, configPath, allocationID) require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) From bd68eb0bda8b20e6bd07f29de869d71d57b99bfe Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Thu, 24 Mar 2022 10:07:58 +0545 Subject: [PATCH 3/6] Fix balance checking type and quantity --- tests/cli_tests/zboxcli_download_token_test.go | 2 +- tests/cli_tests/zboxcli_share_file_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/cli_tests/zboxcli_download_token_test.go b/tests/cli_tests/zboxcli_download_token_test.go index ce5ba267a3..550ed4e0c4 100644 --- a/tests/cli_tests/zboxcli_download_token_test.go +++ b/tests/cli_tests/zboxcli_download_token_test.go @@ -219,7 +219,7 @@ func TestFileDownloadTokenMovement(t *testing.T) { expectedRPBalance := 0.4*1e10 - expectedDownloadCostInZCN*1e10 require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) - require.Less(t, finalReadPool[0].Balance, expectedRPBalance) + require.Less(t, float64(finalReadPool[0].Balance), expectedRPBalance) require.IsType(t, int64(1), finalReadPool[0].ExpireAt) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 3ca78559b6..2b12620726 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1469,7 +1469,9 @@ func TestShareFile(t *testing.T) { // amount deducted diff := initialReadPool[0].Blobber[i].Balance - finalReadPool[0].Blobber[i].Balance t.Logf("blobber [%v] read pool was deducted by [%v]", i, diff) - require.InEpsilon(t, expectedDownloadCostInZCN, diff, epsilon, "blobber [%v] read pool was deducted by [%v] rather than the expected [%v]", i, diff, expectedDownloadCostInZCN) + initialBalance := initialReadPool[0].Blobber[i].Balance + finalBalance := finalReadPool[0].Blobber[i].Balance + require.Less(t, initialBalance, finalBalance, "blobber [%v] initial balance was [%v] and final balance is [%v]", i, initialBalance, finalBalance) } }) } From 2e9734dad65edb393aae8e55243066086633746f Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Thu, 24 Mar 2022 16:10:07 +0545 Subject: [PATCH 4/6] Fix token accounting tests comparison --- tests/cli_tests/zboxcli_download_token_test.go | 2 +- tests/cli_tests/zboxcli_share_file_test.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/cli_tests/zboxcli_download_token_test.go b/tests/cli_tests/zboxcli_download_token_test.go index 550ed4e0c4..47dc66de6d 100644 --- a/tests/cli_tests/zboxcli_download_token_test.go +++ b/tests/cli_tests/zboxcli_download_token_test.go @@ -219,7 +219,7 @@ func TestFileDownloadTokenMovement(t *testing.T) { expectedRPBalance := 0.4*1e10 - expectedDownloadCostInZCN*1e10 require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) - require.Less(t, float64(finalReadPool[0].Balance), expectedRPBalance) + require.InEpsilon(t, float64(finalReadPool[0].Balance), expectedRPBalance, epsilon) require.IsType(t, int64(1), finalReadPool[0].ExpireAt) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 2b12620726..9c4ccd0d34 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1190,6 +1190,7 @@ func TestShareFile(t *testing.T) { expectedRPBalance := 0.4*1e10 - expectedDownloadCostInSas require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) + require.InEpsilon(t, expectedRPBalance, float64(finalReadPool[0].Balance), epsilon) require.Equal(t, expectedRPBalance, float64(finalReadPool[0].Balance)) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) @@ -1336,11 +1337,11 @@ func TestShareFile(t *testing.T) { for i := 0; i < len(finalReadPool[0].Blobber); i++ { require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Blobber[i].BlobberID) + initialBal := initialReadPool[0].Blobber[i].Balance + finalBal := finalReadPool[0].Blobber[i].Balance + require.Greater(t, initialBal, finalBal, "Blobber [%v] initial balance: [%v] and final balance: [%v]", + i, initialBal, finalBal) - // amount deducted - diff := initialReadPool[0].Blobber[i].Balance - finalReadPool[0].Blobber[i].Balance - t.Logf("blobber [%v] read pool was deducted by [%v]", i, diff) - require.InEpsilon(t, expectedDownloadCostInZCN, diff, epsilon, "blobber [%v] read pool was deducted by [%v] rather than the expected [%v]", i, diff, expectedDownloadCostInZCN) } }) @@ -1471,7 +1472,7 @@ func TestShareFile(t *testing.T) { t.Logf("blobber [%v] read pool was deducted by [%v]", i, diff) initialBalance := initialReadPool[0].Blobber[i].Balance finalBalance := finalReadPool[0].Blobber[i].Balance - require.Less(t, initialBalance, finalBalance, "blobber [%v] initial balance was [%v] and final balance is [%v]", i, initialBalance, finalBalance) + require.Greater(t, initialBalance, finalBalance, "blobber [%v] initial balance was [%v] and final balance is [%v]", i, initialBalance, finalBalance) } }) } From dfcbb5f5102443a4f15180410c004cebab83afe4 Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Thu, 24 Mar 2022 19:50:44 +0545 Subject: [PATCH 5/6] Fix balance comparison --- tests/cli_tests/zboxcli_share_file_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 9c4ccd0d34..a071f52998 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1077,7 +1077,7 @@ func TestShareFile(t *testing.T) { expectedRPBalance := 0.4*1e10 - expectedDownloadCostInSas require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) - require.Equal(t, expectedRPBalance, float64(finalReadPool[0].Balance)) + require.InEpsilon(t, expectedRPBalance, float64(finalReadPool[0].Balance), epsilon) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) require.True(t, finalReadPool[0].Locked) @@ -1191,7 +1191,6 @@ func TestShareFile(t *testing.T) { expectedRPBalance := 0.4*1e10 - expectedDownloadCostInSas require.Regexp(t, regexp.MustCompile("([a-f0-9]{64})"), finalReadPool[0].Id) require.InEpsilon(t, expectedRPBalance, float64(finalReadPool[0].Balance), epsilon) - require.Equal(t, expectedRPBalance, float64(finalReadPool[0].Balance)) require.Equal(t, allocationID, finalReadPool[0].AllocationId) require.Equal(t, len(initialReadPool[0].Blobber), len(finalReadPool[0].Blobber)) require.True(t, finalReadPool[0].Locked) From ee9006ceff9ce4f224740849f6128ae1503ade93 Mon Sep 17 00:00:00 2001 From: Kishan-Dhakan Date: Sun, 27 Mar 2022 23:33:39 +0530 Subject: [PATCH 6/6] lint fix --- tests/cli_tests/zboxcli_share_file_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index 17e5639371..fed905062a 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -1355,7 +1355,6 @@ func TestShareFile(t *testing.T) { finalBal := finalReadPool[0].Blobber[i].Balance require.Greater(t, initialBal, finalBal, "Blobber [%v] initial balance: [%v] and final balance: [%v]", i, initialBal, finalBal) - } })