Skip to content

Commit

Permalink
Added coverage for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayashsatolia403 committed Aug 24, 2023
1 parent a07f4fe commit dfce204
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
72 changes: 56 additions & 16 deletions tests/tokenomics_tests/blobber_challenge_reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,29 @@ func TestBlobberChallengeRewards(testSetup *testing.T) {
"parity": 1,
})

assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.1*GB)
assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.1*GB, 1, 0)
})

t.RunSequentiallyWithTimeout("Client Uploads 20% of Allocation and delete 10% immediately and 1 delegate each (equal stake)", 100*time.Minute, func(t *test.SystemTest) {
t.Cleanup(func() {
tearDownRewardsTests(t, blobberListString, validatorListString, configPath, 1)
})

stakeTokensToBlobbersAndValidators(t, blobberListString, validatorListString, configPath, []float64{
1, 1, 1, 1,
}, 1)

// Creating Allocation
_ = utils.SetupWalletWithCustomTokens(t, configPath, 9.0)

allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{
"size": 1 * GB,
"tokens": 99,
"data": 1,
"parity": 1,
})

assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.1*GB, 2, 1)
})

t.RunSequentiallyWithTimeout("Client Uploads 30% of Allocation and 1 delegate each (equal stake)", 100*time.Minute, func(t *test.SystemTest) {
Expand All @@ -133,7 +155,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) {
"parity": 1,
})

assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.3*GB)
assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.3*GB, 1, 0)
})

t.RunSequentiallyWithTimeout("Client Uploads 10% of Allocation and 1 delegate each (unequal stake 2:1)", 100*time.Minute, func(t *test.SystemTest) {
Expand All @@ -156,7 +178,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) {
"parity": 1,
})

assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.1*GB)
assertChallengeRewardsForOneDelegateEach(t, allocationId, blobberListString, validatorListString, 0.1*GB, 1, 0)
})

t.RunSequentiallyWithTimeout("Client Uploads 10% of Allocation and 2 delegate each (equal stake)", 100*time.Minute, func(t *test.SystemTest) {
Expand Down Expand Up @@ -359,7 +381,7 @@ func waitUntilAllocationIsFinalized(t *test.SystemTest, allocationID string) {
}
}

func assertChallengeRewardsForOneDelegateEach(t *test.SystemTest, allocationId string, blobberListString, validatorListString []string, filesize float64) {
func assertChallengeRewardsForOneDelegateEach(t *test.SystemTest, allocationId string, blobberListString, validatorListString []string, filesize float64, numFiles, numDeletes int) {
t.Cleanup(func() {
waitUntilAllocationIsFinalized(t, allocationId)
})
Expand All @@ -375,19 +397,37 @@ func assertChallengeRewardsForOneDelegateEach(t *test.SystemTest, allocationId s
v1D1Wallet, _ := utils.GetWalletForName(t, configPath, validator1Delegate1Wallet)
v2D1Wallet, _ := utils.GetWalletForName(t, configPath, validator2Delegate1Wallet)

remotepath := "/dir/"
filename := utils.GenerateRandomTestFileName(t)
var fileNames []string

err := utils.CreateFileWithSize(filename, int64(filesize))
require.Nil(t, err)
for i := 0; i < numFiles; i++ {
remotepath := "/dir/"
filename := utils.GenerateRandomTestFileName(t)

output, err := utils.UploadFile(t, configPath, map[string]interface{}{
// fetch the latest block in the chain
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
"localpath": filename,
}, true)
require.Nil(t, err, "error uploading file", strings.Join(output, "\n"))
err := utils.CreateFileWithSize(filename, int64(filesize))
require.Nil(t, err)

output, err := utils.UploadFile(t, configPath, map[string]interface{}{
// fetch the latest block in the chain
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
"localpath": filename,
}, true)
require.Nil(t, err, "error uploading file", strings.Join(output, "\n"))

fileNames = append(fileNames, filename)
}

for i := 0; i < numDeletes; i++ {
remotepath := "/dir/"
filename := fileNames[i]

output, err := utils.DeleteFile(t, utils.EscapedTestName(t), utils.CreateParams(map[string]interface{}{
// fetch the latest block in the chain
"allocation": allocationId,
"remotepath": remotepath + filepath.Base(filename),
}), true)
require.Nil(t, err, "error deleting file", strings.Join(output, "\n"))
}

// sleep for 10 minutes
time.Sleep(15 * time.Minute)
Expand All @@ -399,7 +439,7 @@ func assertChallengeRewardsForOneDelegateEach(t *test.SystemTest, allocationId s
totalExpectedReward := allocation.MovedToChallenge - allocation.MovedBack

challengeRewards, err := getAllAllocationChallengeRewards(t, allocationId)
require.Nil(t, err, "Error getting challenge rewards", strings.Join(output, "\n"))
require.Nil(t, err, "Error getting challenge rewards")

blobber1TotalReward := challengeRewards[blobber1].Amount
blobber2TotalReward := challengeRewards[blobber2].Amount
Expand Down
16 changes: 16 additions & 0 deletions tests/tokenomics_tests/utils/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,19 @@ func UpdateAllocationWithWallet(t *test.SystemTest, wallet, cliConfigFilename, p
return cliutils.RunCommandWithoutRetry(cmd)
}
}

func DeleteFile(t *test.SystemTest, walletName, params string, retry bool) ([]string, error) {
t.Logf("Deleting file...")
cmd := fmt.Sprintf(
"./zbox delete %s --silent --wallet %s "+
"--configDir ./config --config %s",
params,
walletName+"_wallet.json",
configPath,
)
if retry {
return cliutils.RunCommand(t, cmd, 3, time.Second*20)
} else {
return cliutils.RunCommandWithoutRetry(cmd)
}
}

0 comments on commit dfce204

Please sign in to comment.