diff --git a/go.mod b/go.mod index 2831b5a76a..84d77a90ee 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.1 require ( github.com/0chain/errors v1.0.3 - github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c + github.com/0chain/gosdk v1.17.7-0.20240919221730-fa5e1cec2d89 github.com/go-resty/resty/v2 v2.7.0 github.com/herumi/bls-go-binary v1.31.0 github.com/shopspring/decimal v1.3.1 diff --git a/go.sum b/go.sum index b94d46fc8c..6a0f1f0d12 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565 h1:z+DtCR8mBsjPnEs github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565/go.mod h1:UyDC8Qyl5z9lGkCnf9RHJPMektnFX8XtCJZHXCCVj8E= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c h1:o8SPHAi3/bUMFqMPVNhMs77Ce5qxLzs5Q9YYyuT/llQ= -github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= +github.com/0chain/gosdk v1.17.7-0.20240919221730-fa5e1cec2d89 h1:icV32Kaq/gZbh7bnVVpacOb4eTqWZaIMGOU8LWbzhwc= +github.com/0chain/gosdk v1.17.7-0.20240919221730-fa5e1cec2d89/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Luzifer/go-openssl/v3 v3.1.0 h1:QqKqo6kYXGGUsvtUoCpRZm8lHw+jDfhbzr36gVj+/gw= diff --git a/internal/api/model/api.go b/internal/api/model/api.go index 6d5dca3f79..f7ab16347e 100644 --- a/internal/api/model/api.go +++ b/internal/api/model/api.go @@ -190,18 +190,6 @@ func NewCreateWritePoolTransactionData(createWritePoolRequest CreateWritePoolReq } } -func NewCreateReadPoolTransactionData() TransactionData { - return TransactionData{ - Name: "read_pool_lock", - } -} - -func NewUnlockReadPoolTransactionData() TransactionData { - return TransactionData{ - Name: "read_pool_unlock", - } -} - func NewCreateStackPoolTransactionData(createStakePoolRequest CreateStakePoolRequest) TransactionData { return TransactionData{ Name: "stake_pool_lock", @@ -372,10 +360,6 @@ type ClientGetBalanceResponse struct { Nonce int64 `json:"nonce"` } -type ClientGetReadPoolBalanceRequest struct { - ClientID string -} - type QueryRequest struct { Query string } @@ -389,11 +373,6 @@ type GetAllChallengesForAllocationRequest struct { AllocationID string } -type ClientGetReadPoolBalanceResponse struct { - UserID string `json:"user_id" gorm:"uniqueIndex"` - Balance int64 `json:"balance"` -} - type QueryRewardsResponse struct { TotalProviderReward float64 `json:"total_provider_reward"` TotalDelegateReward float64 `json:"total_delegate_reward"` diff --git a/internal/api/util/client/api_client.go b/internal/api/util/client/api_client.go index 3b325674f5..c14173e538 100644 --- a/internal/api/util/client/api_client.go +++ b/internal/api/util/client/api_client.go @@ -48,7 +48,6 @@ const ( TransactionFeeGet = "/v1/estimate_txn_fee" TransactionGetConfirmation = "/v1/transaction/get/confirmation" ClientGetBalance = "/v1/client/get/balance" - ClientReadPool = "/v1/screst/:sc_address/getReadPoolStat" GetNetworkDetails = "/network" GetFileRef = "/v1/file/refs/:allocation_id" GetFileRefPath = "/v1/file/referencepath/:allocation_id" @@ -497,24 +496,6 @@ func (c *APIClient) V1ClientGetBalance(t *test.SystemTest, clientGetBalanceReque return clientGetBalanceResponse, resp, err } -func (c *APIClient) V1ClientGetReadPoolBalance(t *test.SystemTest, clientGetReadBalanceRequest model.ClientGetReadPoolBalanceRequest, requiredStatusCode int) (*model.ClientGetReadPoolBalanceResponse, *resty.Response, error) { //nolint - var clientGetReadPoolBalanceResponse *model.ClientGetReadPoolBalanceResponse - - urlBuilder := NewURLBuilder().SetPath(ClientReadPool).AddParams("client_id", clientGetReadBalanceRequest.ClientID).SetPathVariable("sc_address", StorageSmartContractAddress) - - resp, err := c.executeForAllServiceProviders( - t, - urlBuilder, - &model.ExecutionRequest{ - Dst: &clientGetReadPoolBalanceResponse, - RequiredStatusCode: requiredStatusCode, - }, - HttpGETMethod, - SharderServiceProvider) - - return clientGetReadPoolBalanceResponse, resp, err -} - func (c *APIClient) V1SCRestGetAllMiners(t *test.SystemTest, requiredStatusCode int) ([]*model.SCRestGetMinerSharderResponse, *resty.Response, error) { var scRestGetMinersResponse *model.SCRestGetMinersShardersResponse @@ -1310,27 +1291,6 @@ func (c *APIClient) GetWalletBalance(t *test.SystemTest, wallet *model.Wallet, r return clientGetBalanceResponse } -func (c *APIClient) GetReadPoolBalance(t *test.SystemTest, wallet *model.Wallet, requiredStatusCode int) *model.ClientGetReadPoolBalanceResponse { - t.Log("Get read pool balance...") - - clientGetReadPoolBalanceResponse, resp, err := c.V1ClientGetReadPoolBalance( - t, - model.ClientGetReadPoolBalanceRequest{ - ClientID: wallet.Id, - }, - requiredStatusCode) - - if err != nil { - t.Logf("Error getting readpool balance: %v", err) - return clientGetReadPoolBalanceResponse - } - require.Nil(t, err) - require.NotNil(t, resp) - require.NotNil(t, clientGetReadPoolBalanceResponse) - - return clientGetReadPoolBalanceResponse -} - func (c *APIClient) GetRewardsByQuery(t *test.SystemTest, query string, requiredStatusCode int) *model.QueryRewardsResponse { t.Log("Get rewards by query...") @@ -1732,99 +1692,6 @@ func (c *APIClient) CreateWritePool(t *test.SystemTest, wallet *model.Wallet, al return createWritePoolTransactionGetConfirmationResponse.Hash } -// CreateReadPoolWrapper does not provide deep test of used components -func (c *APIClient) CreateReadPool(t *test.SystemTest, wallet *model.Wallet, tokens float64, requiredTransactionStatus int) string { - t.Log("Create Read pool...") - - createReadPoolTransactionPutResponse, resp, err := c.V1TransactionPut( - t, - model.InternalTransactionPutRequest{ - Wallet: wallet, - ToClientID: StorageSmartContractAddress, - TransactionData: model.NewCreateReadPoolTransactionData(), - Value: tokenomics.IntToZCN(tokens), - TxnType: SCTxType, - }, - HttpOkStatus) - require.Nil(t, err) - require.NotNil(t, resp) - require.NotNil(t, createReadPoolTransactionPutResponse) - - var createReadPoolTransactionGetConfirmationResponse *model.TransactionGetConfirmationResponse - - wait.PoolImmediately(t, time.Minute*2, func() bool { - createReadPoolTransactionGetConfirmationResponse, resp, err = c.V1TransactionGetConfirmation( - t, - model.TransactionGetConfirmationRequest{ - Hash: createReadPoolTransactionPutResponse.Entity.Hash, - }, - HttpOkStatus) - if err != nil { - return false - } - - if resp == nil { - return false - } - - if createReadPoolTransactionGetConfirmationResponse == nil { - return false - } - - return createReadPoolTransactionGetConfirmationResponse.Status == requiredTransactionStatus - }) - - wallet.IncNonce() - - return createReadPoolTransactionGetConfirmationResponse.Hash -} - -func (c *APIClient) UnlockReadPool(t *test.SystemTest, wallet *model.Wallet, requiredTransactionStatus int) string { - t.Log("Unlock Read pool...") - - unlockReadPoolTransactionPutResponse, resp, err := c.V1TransactionPut( - t, - model.InternalTransactionPutRequest{ - Wallet: wallet, - ToClientID: StorageSmartContractAddress, - TransactionData: model.NewUnlockReadPoolTransactionData(), - Value: tokenomics.IntToZCN(0.1), - TxnType: SCTxType, - }, - HttpOkStatus) - require.Nil(t, err) - require.NotNil(t, resp) - require.NotNil(t, unlockReadPoolTransactionPutResponse) - - var unlockReadPoolTransactionGetConfirmationResponse *model.TransactionGetConfirmationResponse - - wait.PoolImmediately(t, time.Minute*2, func() bool { - unlockReadPoolTransactionGetConfirmationResponse, resp, err = c.V1TransactionGetConfirmation( - t, - model.TransactionGetConfirmationRequest{ - Hash: unlockReadPoolTransactionPutResponse.Entity.Hash, - }, - HttpOkStatus) - if err != nil { - return false - } - - if resp == nil { - return false - } - - if unlockReadPoolTransactionGetConfirmationResponse == nil { - return false - } - - return unlockReadPoolTransactionGetConfirmationResponse.Status == requiredTransactionStatus - }) - - wallet.IncNonce() - - return unlockReadPoolTransactionGetConfirmationResponse.Hash -} - func (c *APIClient) V1SCRestGetStakePoolStat(t *test.SystemTest, scRestGetStakePoolStatRequest model.SCRestGetStakePoolStatRequest, requiredStatusCode int) (*model.SCRestGetStakePoolStatResponse, *resty.Response, error) { //nolint var scRestGetStakePoolStatResponse *model.SCRestGetStakePoolStatResponse diff --git a/internal/cli/model/model.go b/internal/cli/model/model.go index b43542add2..bd748ecfd2 100644 --- a/internal/cli/model/model.go +++ b/internal/cli/model/model.go @@ -108,12 +108,6 @@ type Blobber struct { StakePoolSettings StakePoolSettings `json:"stake_pool_settings"` } -type ReadPoolInfo struct { - Balance int64 `json:"fmt"` - Zcn float64 `json:"zcn"` - Usd float64 `json:"usd"` -} - type RecentlyAddedRefResult struct { Offset int `json:"offset"` Refs []ORef `json:"refs"` diff --git a/tests/api_tests/0box_aggregate_endpoints_test.go b/tests/api_tests/0box_aggregate_endpoints_test.go index 01395a8d48..9ba2a38069 100644 --- a/tests/api_tests/0box_aggregate_endpoints_test.go +++ b/tests/api_tests/0box_aggregate_endpoints_test.go @@ -1453,8 +1453,6 @@ func Test0boxGraphBlobberEndpoints(testSetup *testing.T) { allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus) allocationID := apiClient.CreateAllocationWithLockValue(t, wallet, allocationBlobbers, 0.1, client.TxSuccessfulStatus) - apiClient.CreateReadPool(t, wallet, 100, client.TxSuccessfulStatus) - alloc, _ := sdk.GetAllocation(allocationID) targetBlobber := alloc.BlobberDetails[0].BlobberID diff --git a/tests/api_tests/multi_download_test.go b/tests/api_tests/multi_download_test.go index 0638dbf978..a3597974d0 100644 --- a/tests/api_tests/multi_download_test.go +++ b/tests/api_tests/multi_download_test.go @@ -26,8 +26,6 @@ func TestMultiDownload(testSetup *testing.T) { allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus) allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus) - apiClient.CreateReadPool(t, wallet, float64(1.5), client.TxSuccessfulStatus) - ops := make([]sdk.OperationRequest, 0, 10) for i := 0; i < 10; i++ { diff --git a/tests/api_tests/repair_allocation_test.go b/tests/api_tests/repair_allocation_test.go index d27b8ec916..3cd9d69e9b 100644 --- a/tests/api_tests/repair_allocation_test.go +++ b/tests/api_tests/repair_allocation_test.go @@ -26,8 +26,6 @@ func TestRepairAllocation(testSetup *testing.T) { sdkClient.SetWallet(t, wallet) - apiClient.CreateReadPool(t, wallet, 0.5, client.TxSuccessfulStatus) - t.RunSequentially("Repair allocation after single upload should work", func(t *test.SystemTest) { blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey) blobberRequirements.DataShards = 2 @@ -352,7 +350,6 @@ func TestRepairSize(testSetup *testing.T) { t := test.NewSystemTest(testSetup) wallet := createWallet(t) sdkClient.SetWallet(t, wallet) - apiClient.CreateReadPool(t, wallet, 0.5, client.TxSuccessfulStatus) t.RunSequentiallyWithTimeout("repair size in case of no blobber failure should be zero", 5*time.Minute, func(t *test.SystemTest) { // create allocation with default blobber requirements diff --git a/tests/api_tests/replace_blobber_test.go b/tests/api_tests/replace_blobber_test.go index 9122f98c2c..a3360a17ae 100644 --- a/tests/api_tests/replace_blobber_test.go +++ b/tests/api_tests/replace_blobber_test.go @@ -162,7 +162,6 @@ func TestReplaceBlobber(testSetup *testing.T) { sdkClient.MultiOperation(t, allocationID, []sdk.OperationRequest{uploadOp}) allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus) - apiClient.CreateReadPool(t, wallet, 1.0, client.TxSuccessfulStatus) oldBlobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers) require.NotZero(t, oldBlobberID, "Old blobber ID contains zero value") diff --git a/tests/cli_tests/0_challenge_protocol_test.go b/tests/cli_tests/0_challenge_protocol_test.go index e54066da1f..b76fdbb3a4 100644 --- a/tests/cli_tests/0_challenge_protocol_test.go +++ b/tests/cli_tests/0_challenge_protocol_test.go @@ -60,7 +60,7 @@ func TestProtocolChallenge(testSetup *testing.T) { }) t.RunWithTimeout("Number of challenges between 2 blocks should be equal to the number of blocks after challenge_generation_gap (given that we have active allocations)", 10*time.Minute, func(t *test.SystemTest) { - allocationId := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 9, }) diff --git a/tests/cli_tests/0_expired_allocation_test.go b/tests/cli_tests/0_expired_allocation_test.go index 426c719ce7..110850739d 100644 --- a/tests/cli_tests/0_expired_allocation_test.go +++ b/tests/cli_tests/0_expired_allocation_test.go @@ -75,7 +75,7 @@ func TestExpiredAllocation(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) diff --git a/tests/cli_tests/config/zbox_config.yaml b/tests/cli_tests/config/zbox_config.yaml index 3d36109c59..e93c92478a 100644 --- a/tests/cli_tests/config/zbox_config.yaml +++ b/tests/cli_tests/config/zbox_config.yaml @@ -1,6 +1,6 @@ -block_worker: https://dev.zus.network/dns +block_worker: https://dev-st.devnet-0chain.net/dns confirmation_chain_length: 3 -ethereum_node_url: "https://rpc.tenderly.co/fork/5b7ffac9-50cc-4169-b0ca-6fd203d26ef6" +ethereum_node_url: "https://virtual.mainnet.rpc.tenderly.co/1b2b3323-9a80-49c3-a2ff-50efb7afb359" min_confirmation: 50 min_submit: 50 signature_scheme: bls0chain diff --git a/tests/cli_tests/zboxcli_create_allocation_free_storage_test.go b/tests/cli_tests/zboxcli_create_allocation_free_storage_test.go index 115d479151..871167fe6b 100644 --- a/tests/cli_tests/zboxcli_create_allocation_free_storage_test.go +++ b/tests/cli_tests/zboxcli_create_allocation_free_storage_test.go @@ -140,9 +140,6 @@ func TestCreateAllocationFreeStorage(testSetup *testing.T) { allocation := getAllocation(t, allocationID) require.Equal(t, ConvertToValue(wantWritePoolToken), allocation.WritePool, "Expected write pool amount not met", strings.Join(output, "\n")) require.Equal(t, uint16(63), allocation.FileOptions, "Expected file_options to be 63 (all allowed) by default", strings.Join(output, "\n")) - - readPool := getReadPoolInfo(t) - require.Equal(t, ConvertToValue(wantReadPoolFraction), readPool.Balance, "Read Pool balance must be equal to locked amount") }) t.Run("Create free storage with malformed marker should fail", func(t *test.SystemTest) { diff --git a/tests/cli_tests/zboxcli_download_livestream_test.go b/tests/cli_tests/zboxcli_download_livestream_test.go index afac154fdc..78ddf716df 100644 --- a/tests/cli_tests/zboxcli_download_livestream_test.go +++ b/tests/cli_tests/zboxcli_download_livestream_test.go @@ -50,11 +50,6 @@ func TestLivestreamDownload(testSetup *testing.T) { // nolint cyclomatic complex require.Nil(t, err, "error creating allocation", strings.Join(output, "\n")) - _, err = readPoolLock(t, configPath, createParams(map[string]interface{}{ - "tokens": 1, - }), true) - require.Nil(t, err, "error") - require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected") allocationID := strings.Fields(output[0])[2] @@ -198,11 +193,6 @@ func TestLivestreamDownload(testSetup *testing.T) { // nolint cyclomatic complex t.Log(output) require.Nil(t, err, "error creating allocation", strings.Join(output, "\n")) - _, err = readPoolLock(t, configPath, createParams(map[string]interface{}{ - "tokens": 1, - }), true) - require.Nil(t, err, "error") - require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected") allocationID := strings.Fields(output[0])[2] @@ -352,11 +342,6 @@ func TestLivestreamDownload(testSetup *testing.T) { // nolint cyclomatic complex t.Log(output) require.Nil(t, err, "error creating allocation", strings.Join(output, "\n")) - _, err = readPoolLock(t, configPath, createParams(map[string]interface{}{ - "tokens": 1, - }), true) - require.Nil(t, err, "error") - require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected") allocationID := strings.Fields(output[0])[2] diff --git a/tests/cli_tests/zboxcli_download_token_test.go b/tests/cli_tests/zboxcli_download_token_test.go deleted file mode 100644 index eae659d672..0000000000 --- a/tests/cli_tests/zboxcli_download_token_test.go +++ /dev/null @@ -1,173 +0,0 @@ -package cli_tests - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strconv" - "strings" - "testing" - "time" - - "github.com/0chain/system_test/internal/api/util/test" - - climodel "github.com/0chain/system_test/internal/cli/model" - cliutils "github.com/0chain/system_test/internal/cli/util" - "github.com/stretchr/testify/require" -) - -func TestFileDownloadTokenMovement(testSetup *testing.T) { - t := test.NewSystemTest(testSetup) - t.SetSmokeTests("Downloader's readpool balance should reduce by download cost") - - t.Parallel() - - t.Skip() - - t.RunWithTimeout("Downloader's readpool balance should reduce by download cost", 5*time.Minute, func(t *test.SystemTest) { //TODO: way too slow - walletOwner := escapedTestName(t) - allocSize := int64(50 * MB) - allocationID := setupAllocation(t, configPath, map[string]interface{}{ - "size": allocSize, - }) - - file := generateRandomTestFileName(t) - remoteOwnerPath := "/" + filepath.Base(file) - fileSize := int64(10 * MB) // must upload bigger file to ensure has noticeable cost - err := createFileWithSize(file, fileSize) - require.Nil(t, err) - - uploadParams := map[string]interface{}{ - "allocation": allocationID, - "localpath": file, - "remotepath": remoteOwnerPath, - } - output, err := uploadFile(t, configPath, uploadParams, true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2) - require.Equal(t, fmt.Sprintf("Status completed callback. Type = text/plain. Name = %s", filepath.Base(file)), output[1]) - - // locking 1 read tokens to readPool via wallet - createWalletForNameAndLockReadTokens(t, configPath, walletOwner) - - output, err = readPoolInfoWithWallet(t, walletOwner, configPath) - require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) - require.Len(t, output, 1) - - initialReadPool := climodel.ReadPoolInfo{} - err = json.Unmarshal([]byte(output[0]), &initialReadPool) - require.Nil(t, err, "Error unmarshalling read pool", strings.Join(output, "\n")) - require.NotEmpty(t, initialReadPool) - - // staked a total of 1 ZCN in readpool - require.Equal(t, 1e10, float64(initialReadPool.Balance)) - - output, err = getDownloadCost(t, configPath, createParams(map[string]interface{}{ - "allocation": allocationID, - "remotepath": remoteOwnerPath, - }), true) - require.Nil(t, err, "Could not get download cost", strings.Join(output, "\n")) - require.Len(t, output, 1) - - 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] - expectedDownloadCostInSas := unitToZCN(expectedDownloadCost, unit) * 1e10 - t.Logf("Download cost: %v sas", expectedDownloadCostInSas) - - // Download the file (delete local copy first) - os.Remove(file) - - downloadParams := createParams(map[string]interface{}{ - "localpath": file, - "allocation": allocationID, - "remotepath": remoteOwnerPath, - "blockspermarker": 100, - }) - - // downloading file for wallet - output, err = downloadFileForWallet(t, walletOwner, configPath, downloadParams, true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2, "download file - Unexpected output", strings.Join(output, "\n")) - require.Contains(t, output[1], StatusCompletedCB) - require.Contains(t, output[1], filepath.Base(file)) - - // waiting 60 seconds for blobber to redeem tokens - cliutils.Wait(t, 60*time.Second) - - output, err = readPoolInfoWithWallet(t, walletOwner, configPath) - require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) - require.Len(t, output, 1) - - finalReadPool := climodel.ReadPoolInfo{} - err = json.Unmarshal([]byte(output[0]), &finalReadPool) - require.Nil(t, err, "Error unmarshalling read pool", strings.Join(output, "\n")) - require.NotEmpty(t, finalReadPool) - - expectedRPBalance := float64(initialReadPool.Balance) - expectedDownloadCostInSas - 10 // because download cost is till 3 decimal point only and missing the 4th decimal digit - require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) - - // getDownloadCost returns download cost when all the associated blobbers of an allocation are required - // In current enhancement/verify-download PR, it gets data from minimum blobbers possible. - // So the download cost will be in between initial balance and expected balance. - t.Logf("FinalReadPool.Balance:%d\nInitialReadPool.Balance:%d\nExpectedReadPool.Balance:%d\n", finalReadPool.Balance, initialReadPool.Balance, int64(expectedRPBalance)) - require.Equal(t, true, - finalReadPool.Balance < initialReadPool.Balance && - finalReadPool.Balance >= int64(expectedRPBalance)) - }) -} - -func readPoolInfo(t *test.SystemTest, cliConfigFilename string) ([]string, error) { - return readPoolInfoWithWallet(t, escapedTestName(t), cliConfigFilename) -} - -func readPoolInfoWithWallet(t *test.SystemTest, wallet, cliConfigFilename string) ([]string, error) { - cliutils.Wait(t, 30*time.Second) // TODO replace with poller - t.Logf("Getting read pool info...") - return cliutils.RunCommand(t, "./zbox rp-info"+" --json --silent --wallet "+wallet+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, 3, time.Second*2) -} - -func readPoolLock(t *test.SystemTest, cliConfigFilename, params string, retry bool) ([]string, error) { - return readPoolLockWithWallet(t, escapedTestName(t), cliConfigFilename, params, retry) -} - -func readPoolLockWithWallet(t *test.SystemTest, wallet, cliConfigFilename, params string, retry bool) ([]string, error) { - t.Logf("Locking read tokens...") - cmd := fmt.Sprintf("./zbox rp-lock %s --silent --wallet %s_wallet.json --configDir ./config --config %s", params, wallet, cliConfigFilename) - if retry { - return cliutils.RunCommand(t, cmd, 3, time.Second*2) - } else { - return cliutils.RunCommandWithoutRetry(cmd) - } -} - -func getDownloadCost(t *test.SystemTest, cliConfigFilename, params string, retry bool) ([]string, error) { - return getDownloadCostWithWallet(t, escapedTestName(t), cliConfigFilename, params, retry) -} - -func getDownloadCostWithWallet(t *test.SystemTest, wallet, cliConfigFilename, params string, retry bool) ([]string, error) { - t.Logf("Getting download cost...") - cmd := fmt.Sprintf("./zbox get-download-cost %s --silent --wallet %s_wallet.json --configDir ./config --config %s", params, wallet, cliConfigFilename) - if retry { - return cliutils.RunCommand(t, cmd, 3, time.Second*2) - } else { - return cliutils.RunCommandWithoutRetry(cmd) - } -} - -func unitToZCN(unitCost float64, unit string) float64 { - switch unit { - case "SAS", "sas": - unitCost /= 1e10 - return unitCost - case "uZCN", "uzcn": - unitCost /= 1e6 - return unitCost - case "mZCN", "mzcn": - unitCost /= 1e3 - return unitCost - } - return unitCost -} diff --git a/tests/cli_tests/zboxcli_file_download_resume_test.go b/tests/cli_tests/zboxcli_file_download_resume_test.go index e64055ff9a..92077e719c 100644 --- a/tests/cli_tests/zboxcli_file_download_resume_test.go +++ b/tests/cli_tests/zboxcli_file_download_resume_test.go @@ -27,7 +27,7 @@ func TestResumeDownload(testSetup *testing.T) { filesize := int64(600 * MB) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, "data": 3, diff --git a/tests/cli_tests/zboxcli_file_download_test.go b/tests/cli_tests/zboxcli_file_download_test.go index a855062a05..49ce5cf7d6 100644 --- a/tests/cli_tests/zboxcli_file_download_test.go +++ b/tests/cli_tests/zboxcli_file_download_test.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" "regexp" - "strconv" "strings" "sync" "testing" @@ -37,7 +36,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -70,7 +69,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(1024) remoteFilePaths := [2]string{"/dir1/", "/dir2/"} - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -131,7 +130,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/dir/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -164,7 +163,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/nested/dir/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -197,7 +196,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/nested/dir/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -226,7 +225,7 @@ func TestDownload(testSetup *testing.T) { // This test creates a separate wallet and allocates there, test nesting is required to create another wallet json file t.Run("Share Entire Folder from Another Wallet", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * 1024, "tokens": 9, }) @@ -276,7 +275,7 @@ func TestDownload(testSetup *testing.T) { // This test creates a separate wallet and allocates there, test nesting is required to create another wallet json file t.Run("Share File from Another Wallet", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * 1024, "tokens": 9, }) @@ -304,9 +303,7 @@ func TestDownload(testSetup *testing.T) { require.NotEqual(t, "", authTicket, "Ticket: ", authTicket) }) - // Just create a wallet so that we can work further - err := createWalletAndLockReadTokens(t, configPath) - require.Nil(t, err) + createWalletForName(escapedTestName(t)) // Download file using auth-ticket: should work output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ @@ -329,7 +326,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(10) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -374,7 +371,7 @@ func TestDownload(testSetup *testing.T) { // create viewer wallet viewerWalletName := escapedTestName(t) + "_viewer" - createWalletForNameAndLockReadTokens(t, configPath, viewerWalletName) + createWalletForName(viewerWalletName) viewerWallet, err := getWalletForName(t, configPath, viewerWalletName) require.Nil(t, err) @@ -382,7 +379,7 @@ func TestDownload(testSetup *testing.T) { // This test creates a separate wallet and allocates there, test nesting is required to create another wallet json file t.Run("Share File from Another Wallet", func(t *test.SystemTest) { - allocationID = setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID = setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * 1024, "tokens": 9, }) @@ -447,7 +444,7 @@ func TestDownload(testSetup *testing.T) { // This test creates a separate wallet and allocates there, test nesting is required to create another wallet json file t.Run("Share File from Another Wallet", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * 1024, "tokens": 9, }) @@ -475,8 +472,7 @@ func TestDownload(testSetup *testing.T) { }) // Just create a wallet so that we can work further - err := createWalletAndLockReadTokens(t, configPath) - require.Nil(t, err) + createWalletForName(configPath) // Download file using auth-ticket: should work output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ @@ -503,7 +499,7 @@ func TestDownload(testSetup *testing.T) { // This test creates a separate wallet and allocates there, test nesting is required to create another wallet json file t.Run("Share File from Another Wallet", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * 1024, "tokens": 9, }) @@ -535,8 +531,7 @@ func TestDownload(testSetup *testing.T) { }) // Just create a wallet so that we can work further - err := createWalletAndLockReadTokens(t, configPath) - require.Nil(t, err) + createWalletForName(configPath) // Download file using auth-ticket: should work output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ @@ -564,7 +559,7 @@ func TestDownload(testSetup *testing.T) { // This test creates a separate wallet and allocates there, test nesting is required to create another wallet json file t.Run("Share File from Another Wallet", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * 1024, "tokens": 9, }) @@ -637,8 +632,8 @@ func TestDownload(testSetup *testing.T) { require.NotEqual(t, "", authTicket, "Ticket: ", authTicket) }) - err = createWalletAndLockReadTokens(t, configPath) - require.Nil(t, err) + createWalletForName(configPath) + // Download file using auth-ticket: should work output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ "authticket": authTicket, @@ -656,7 +651,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -699,7 +694,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -743,7 +738,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -781,7 +776,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -834,7 +829,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -865,7 +860,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -921,7 +916,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -954,7 +949,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(10240) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -988,7 +983,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -1021,7 +1016,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -1051,7 +1046,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -1083,7 +1078,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -1164,7 +1159,7 @@ func TestDownload(testSetup *testing.T) { t.Run("Download Non-Existent File Should Fail", func(t *test.SystemTest) { remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10000, "tokens": 9, }) @@ -1191,7 +1186,7 @@ func TestDownload(testSetup *testing.T) { }) t.Run("Download from Allocation without other Parameter Should Fail", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10000, "tokens": 9, }) @@ -1210,7 +1205,7 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -1255,30 +1250,6 @@ func TestDownload(testSetup *testing.T) { }) } -func setupAllocationAndReadLock(t *test.SystemTest, cliConfigFilename string, extraParam map[string]interface{}) string { - tokens := float64(1) - if tok, ok := extraParam["tokens"]; ok { - token, err := strconv.ParseFloat(fmt.Sprintf("%v", tok), 64) - require.Nil(t, err) - tokens = token - // remove "tokens" from extraParam - delete(extraParam, "tokens") - } - - allocationID := setupAllocation(t, cliConfigFilename, extraParam) - - // Lock half the tokens for read pool - readPoolParams := createParams(map[string]interface{}{ - "tokens": tokens / 3, - }) - output, err := readPoolLock(t, cliConfigFilename, readPoolParams, true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - - return allocationID -} - func downloadFile(t *test.SystemTest, cliConfigFilename, param string, retry bool) ([]string, error) { return downloadFileForWallet(t, escapedTestName(t), cliConfigFilename, param, retry) } diff --git a/tests/cli_tests/zboxcli_file_rename_test.go b/tests/cli_tests/zboxcli_file_rename_test.go index b7f0ce0b9f..0aa8b9c6df 100644 --- a/tests/cli_tests/zboxcli_file_rename_test.go +++ b/tests/cli_tests/zboxcli_file_rename_test.go @@ -894,3 +894,18 @@ func renameFileWithWallet(t *test.SystemTest, cliConfigFilename, wallet string, return cliutils.RunCommand(t, cmd, 3, time.Second*20) } + +func unitToZCN(unitCost float64, unit string) float64 { + switch unit { + case "SAS", "sas": + unitCost /= 1e10 + return unitCost + case "uZCN", "uzcn": + unitCost /= 1e6 + return unitCost + case "mZCN", "mzcn": + unitCost /= 1e3 + return unitCost + } + return unitCost +} diff --git a/tests/cli_tests/zboxcli_file_stats_test.go b/tests/cli_tests/zboxcli_file_stats_test.go index eb98ab47a4..265e10cc3d 100644 --- a/tests/cli_tests/zboxcli_file_stats_test.go +++ b/tests/cli_tests/zboxcli_file_stats_test.go @@ -401,7 +401,7 @@ func TestFileStats(testSetup *testing.T) { t.Skip() allocSize := int64(2048) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) diff --git a/tests/cli_tests/zboxcli_file_update_test.go b/tests/cli_tests/zboxcli_file_update_test.go index e70b9a4db0..b37abdb980 100644 --- a/tests/cli_tests/zboxcli_file_update_test.go +++ b/tests/cli_tests/zboxcli_file_update_test.go @@ -29,7 +29,7 @@ func TestFileUpdate(testSetup *testing.T) { t.Run("update file with thumbnail", func(t *test.SystemTest) { // this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 9, }) @@ -119,7 +119,7 @@ func TestFileUpdate(testSetup *testing.T) { t.Run("update thumbnail of uploaded file", func(t *test.SystemTest) { // this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 9, }) @@ -252,7 +252,7 @@ func TestFileUpdate(testSetup *testing.T) { t.Run("update non-encrypted file with encrypted file should work", func(t *test.SystemTest) { // this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 9, }) @@ -296,7 +296,7 @@ func TestFileUpdate(testSetup *testing.T) { t.Run("update encrypted file with non-encrypted file should work", func(t *test.SystemTest) { // this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 9, }) @@ -339,7 +339,7 @@ func TestFileUpdate(testSetup *testing.T) { t.Run("update encrypted file with encrypted file should work", func(t *test.SystemTest) { // this sets allocation of 10MB and locks 0.5 ZCN. Default allocation has 2 data shards and 2 parity shards - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 9, }) diff --git a/tests/cli_tests/zboxcli_restricted_blobber_test.go b/tests/cli_tests/zboxcli_restricted_blobber_test.go index c9b04a8f65..e856995cea 100644 --- a/tests/cli_tests/zboxcli_restricted_blobber_test.go +++ b/tests/cli_tests/zboxcli_restricted_blobber_test.go @@ -180,7 +180,7 @@ func TestRestrictedBlobbers(testSetup *testing.T) { allocSize := int64(4096) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -249,7 +249,7 @@ func TestRestrictedBlobbers(testSetup *testing.T) { allocSize := int64(4096) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) diff --git a/tests/cli_tests/zboxcli_rollback_test.go b/tests/cli_tests/zboxcli_rollback_test.go index bdf20fcecb..83f5d5b0ee 100644 --- a/tests/cli_tests/zboxcli_rollback_test.go +++ b/tests/cli_tests/zboxcli_rollback_test.go @@ -23,7 +23,7 @@ func TestRollbackAllocation(testSetup *testing.T) { require.Nil(t, err) t.Run("rollback allocation after updating a file should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 4 * MB, "tokens": 9, }) @@ -93,7 +93,7 @@ func TestRollbackAllocation(testSetup *testing.T) { }) t.Run("rollback allocation after updating a file multiple times should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 4 * MB, "tokens": 9, }) @@ -152,7 +152,7 @@ func TestRollbackAllocation(testSetup *testing.T) { createAllocationTestTeardown(t, allocationID) }) t.Run("rollback allocation after deleting a file should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 1 * MB, "tokens": 9, }) @@ -414,7 +414,7 @@ func TestRollbackAllocation(testSetup *testing.T) { }) t.Run("rollback allocation after duplicating a file should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 2 * MB, "tokens": 10, }) @@ -486,7 +486,7 @@ func TestRollbackAllocation(testSetup *testing.T) { }) t.Run("rollback allocation after multiple files upload and single file update should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 4 * MB, "tokens": 9, }) @@ -557,7 +557,7 @@ func TestRollbackAllocation(testSetup *testing.T) { }) t.Run("rollback allocation after multiple files upload and single file delete should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 4 * MB, "tokens": 9, }) @@ -650,7 +650,7 @@ func TestRollbackAllocation(testSetup *testing.T) { }) t.Run("rollback allocation in the middle of updating a large file should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 2 * GB, "tokens": 10, }) @@ -693,7 +693,7 @@ func TestRollbackAllocation(testSetup *testing.T) { }) t.Run("rollback allocation after a small file upload in the middle of updating a large file should work", func(t *test.SystemTest) { - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": 2 * GB, "tokens": 10, }) diff --git a/tests/cli_tests/zboxcli_rp_info_test.go b/tests/cli_tests/zboxcli_rp_info_test.go deleted file mode 100644 index e118bdb7de..0000000000 --- a/tests/cli_tests/zboxcli_rp_info_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package cli_tests - -import ( - "encoding/json" - "regexp" - "strings" - "testing" - "time" - - "github.com/0chain/system_test/internal/api/util/test" - climodel "github.com/0chain/system_test/internal/cli/model" - cliutils "github.com/0chain/system_test/internal/cli/util" - "github.com/stretchr/testify/require" -) - -func TestReadPoolInfo(testSetup *testing.T) { - t := test.NewSystemTest(testSetup) - t.SetSmokeTests("Read pool info testing with json parameter") - - t.Skip() - - t.Parallel() - - t.RunWithTimeout("Read pool info testing with json parameter", 90*time.Second, func(t *test.SystemTest) { - createWallet(t) - - // Lock 1 token in read pool distributed amongst all blobbers - lockAmount := 1.0 - readPoolParams := createParams(map[string]interface{}{ - "tokens": lockAmount, - }) - output, err := readPoolLock(t, configPath, readPoolParams, true) - require.Nil(t, err, "Tokens could not be locked", strings.Join(output, "\n")) - - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - - output, err = readPoolInfoWithParams(t, configPath, createParams(map[string]interface{}{ - "json": "", - })) - require.Nil(t, err, "Error fetching read pool info", strings.Join(output, "\n")) - require.Len(t, output, 1) - - rpInfo := climodel.ReadPoolInfo{} - err = json.Unmarshal([]byte(output[0]), &rpInfo) - require.Nil(t, err, "Error unmarshalling read pool", strings.Join(output, "\n")) - require.NotEmpty(t, rpInfo) - }) - - t.RunWithTimeout("Read pool info testing without json parameter", 90*time.Second, func(t *test.SystemTest) { - createWallet(t) - - // Lock 1 token in read pool distributed amongst all blobbers - lockAmount := 1.0 - readPoolParams := createParams(map[string]interface{}{ - "tokens": lockAmount, - }) - output, err := readPoolLock(t, configPath, readPoolParams, true) - require.Nil(t, err, "Tokens could not be locked", strings.Join(output, "\n")) - - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - - output, err = readPoolInfoWithParams(t, configPath, "") - require.Nil(t, err, "Error fetching read pool info", strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Regexp(t, regexp.MustCompile(`Read pool Balance: 1.00\d ZCN \(\d*\.?\d+ USD\)$`), output[0]) - }) -} -func readPoolInfoWithParams(t *test.SystemTest, cliConfigFilename, params string) ([]string, error) { - cliutils.Wait(t, 30*time.Second) // TODO replace with poller - t.Logf("Getting read pool info...") - return cliutils.RunCommand(t, "./zbox rp-info "+params+" --silent --wallet "+escapedTestName(t)+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, 3, time.Second*2) -} diff --git a/tests/cli_tests/zboxcli_rp_lock_unlock_test.go b/tests/cli_tests/zboxcli_rp_lock_unlock_test.go deleted file mode 100644 index 6ec659d923..0000000000 --- a/tests/cli_tests/zboxcli_rp_lock_unlock_test.go +++ /dev/null @@ -1,167 +0,0 @@ -package cli_tests - -import ( - "encoding/json" - "fmt" - "strings" - "testing" - "time" - - "github.com/0chain/system_test/internal/api/util/test" - - climodel "github.com/0chain/system_test/internal/cli/model" - cliutils "github.com/0chain/system_test/internal/cli/util" - "github.com/stretchr/testify/require" -) - -func TestReadPoolLockUnlock(testSetup *testing.T) { - t := test.NewSystemTest(testSetup) - t.SetSmokeTests("Locking read pool tokens moves tokens from wallet to read pool") - - t.Skip() - - t.Parallel() - - t.RunWithTimeout("Locking read pool tokens moves tokens from wallet to read pool", 90*time.Second, func(t *test.SystemTest) { //TOOD: slow - createWallet(t) - - balanceBefore, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - - lockAmount := 1.0 - readPoolParams := createParams(map[string]interface{}{ - "tokens": lockAmount, - }) - output, err := readPoolLock(t, configPath, readPoolParams, true) - require.Nil(t, err, "Tokens could not be locked", strings.Join(output, "\n")) - - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - - // Wallet balance should decrement from 5 to 3.9 (0.01 is fees) ZCN - balanceAfter, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - require.InEpsilon(t, balanceBefore-1.01, balanceAfter, 0.01) - balanceBefore = balanceAfter - - // Read pool balance should increment to 1 - readPool := getReadPoolInfo(t) - require.Equal(t, ConvertToValue(lockAmount), readPool.Balance, "Read Pool balance must be equal to locked amount") - - output, err = readPoolUnlock(t, configPath, "", true) - require.Nil(t, err, "Unable to unlock tokens", strings.Join(output, "\n")) - require.Len(t, output, 1) - - require.Equal(t, "unlocked", output[0]) - - // Wallet balance should increment from 4 to 4.98 (0.01 fees for unlocking) ZCN - balanceAfter, err = getBalanceZCN(t, configPath) - require.NoError(t, err) - - t.Log("balanceBefore : ", balanceBefore, " balanceAfter : ", balanceAfter) - require.InEpsilon(t, balanceBefore+0.99, balanceAfter, 0.01) - }) - - t.Run("Should not be able to lock more read tokens than wallet balance", func(t *test.SystemTest) { - _, err := executeFaucetWithTokens(t, configPath, 1) - require.NoError(t, err) - - balanceBefore, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - - readPoolParams := createParams(map[string]interface{}{ - "tokens": 10, - }) - output, err := readPoolLock(t, configPath, readPoolParams, false) - require.NotNil(t, err, "Locked more tokens than in wallet", strings.Join(output, "\n")) - require.True(t, len(output) > 0, "expected output length be at least 1") - require.Equal(t, "Failed to lock tokens in read pool: read_pool_lock_failed: lock amount is greater than balance", output[0], strings.Join(output, "\n")) - - // Wallet balance reduced due to chargeable error (0.1 fees) - balanceAfter, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - require.InEpsilon(t, balanceBefore-0.01, balanceAfter, 0.01) - }) - - t.Run("Should not be able to lock negative read tokens", func(t *test.SystemTest) { - createWallet(t) - - balanceBefore, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - - // Locking -1 token in read pool should not succeed - readPoolParams := createParams(map[string]interface{}{ - "tokens": -1, - }) - output, err := readPoolLock(t, configPath, readPoolParams, false) - require.NotNil(t, err, "Locked negative tokens", strings.Join(output, "\n")) - require.True(t, len(output) > 0, "expected output length be at least 1") - require.Equal(t, "invalid token amount: negative", output[0], strings.Join(output, "\n")) - - balanceAfter, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - require.Equal(t, balanceBefore, balanceAfter) - }) - - t.Run("Should not be able to lock zero read tokens", func(t *test.SystemTest) { - createWallet(t) - - balanceBefore, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - - // Locking 0 token in read pool should not succeed - readPoolParams := createParams(map[string]interface{}{ - "tokens": 0, - }) - - output, err := readPoolLock(t, configPath, readPoolParams, false) - require.NotNil(t, err, "Locked 0 tokens", strings.Join(output, "\n")) - require.True(t, len(output) > 0, "expected output length be at least 1") - require.Equal(t, "Failed to lock tokens in read pool: read_pool_lock_failed: invalid amount to lock [ensure token > 0].", output[0], strings.Join(output, "\n")) - - // Wallet balance gets reduced due to chargeable error (0.1 fees) - balanceAfter, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - require.InEpsilon(t, balanceBefore-0.01, balanceAfter, 0.01) - }) - - t.Run("Missing tokens flag in rp-lock should result in error", func(t *test.SystemTest) { - createWallet(t) - - balanceBefore, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - - // Not specifying amount to lock should not succeed - readPoolParams := createParams(map[string]interface{}{}) - output, err := readPoolLock(t, configPath, readPoolParams, false) - require.NotNil(t, err, "Locked tokens without providing amount to lock", strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Equal(t, "missing required 'tokens' flag", output[0]) - - // Wallet balance should remain same - balanceAfter, err := getBalanceZCN(t, configPath) - require.NoError(t, err) - require.Equal(t, balanceBefore, balanceAfter) - }) -} - -func readPoolUnlock(t *test.SystemTest, cliConfigFilename, params string, retry bool) ([]string, error) { - t.Logf("Unlocking read tokens...") - cmd := fmt.Sprintf("./zbox rp-unlock %s --silent --wallet %s_wallet.json --configDir ./config --config %s", params, escapedTestName(t), cliConfigFilename) - if retry { - return cliutils.RunCommand(t, cmd, 3, time.Second*2) - } else { - return cliutils.RunCommandWithoutRetry(cmd) - } -} - -func getReadPoolInfo(t *test.SystemTest) climodel.ReadPoolInfo { - output, err := readPoolInfo(t, configPath) - require.Nil(t, err, "Error fetching read pool", strings.Join(output, "\n")) - require.Lenf(t, output, 1, "ouptut: %v", output) - - var readPool climodel.ReadPoolInfo - err = json.Unmarshal([]byte(output[0]), &readPool) - require.Nil(t, err, "Error unmarshalling read pool %s", strings.Join(output, "\n")) - return readPool -} diff --git a/tests/cli_tests/zboxcli_share_file_test.go b/tests/cli_tests/zboxcli_share_file_test.go index fe58afe7bb..c54a712270 100644 --- a/tests/cli_tests/zboxcli_share_file_test.go +++ b/tests/cli_tests/zboxcli_share_file_test.go @@ -38,7 +38,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -90,7 +90,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -180,7 +180,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -260,7 +260,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -311,7 +311,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -375,7 +375,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -472,7 +472,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -559,7 +559,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -621,7 +621,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -675,7 +675,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -728,7 +728,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -781,7 +781,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -934,7 +934,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) shareParams := map[string]interface{}{ "allocation": allocationID, @@ -988,7 +988,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -1046,15 +1046,6 @@ func TestShareFile(testSetup *testing.T) { allocationID := strings.Fields(output[0])[2] - // locking tokens for read pool - readPoolParams := createParams(map[string]interface{}{ - "tokens": 3, - }) - output, err = readPoolLockWithWallet(t, walletOwner, configPath, readPoolParams, true) - require.Nil(t, err, "Tokens could not be locked", strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - // upload file file := generateRandomTestFileName(t) fileSize := int64(102400) // this is big enough to cause problem with download @@ -1076,7 +1067,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -1294,7 +1285,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -1356,7 +1347,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -1419,7 +1410,7 @@ func TestShareFile(testSetup *testing.T) { // receiver wallet operations receiverWallet := escapedTestName(t) + "_second" - createWalletForNameAndLockReadTokens(t, configPath, receiverWallet) + createWalletForName(receiverWallet) walletReceiver, err := getWalletForName(t, configPath, receiverWallet) require.Nil(t, err) @@ -1663,15 +1654,6 @@ func createWalletAndAllocation(t *test.SystemTest, configPath, wallet string) (s allocationID := strings.Fields(output[0])[2] - // locking tokens for read pool - readPoolParams := createParams(map[string]interface{}{ - "tokens": 0.4, - }) - output, err = readPoolLockWithWallet(t, wallet, configPath, readPoolParams, true) - require.Nil(t, err, "Tokens could not be locked", strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - walletModel, err := getWalletForName(t, configPath, wallet) require.Nil(t, err) diff --git a/tests/cli_tests/zboxcli_update_allocation_test.go b/tests/cli_tests/zboxcli_update_allocation_test.go index 47b882816f..ef8132fcfd 100644 --- a/tests/cli_tests/zboxcli_update_allocation_test.go +++ b/tests/cli_tests/zboxcli_update_allocation_test.go @@ -678,7 +678,7 @@ func TestUpdateAllocation(testSetup *testing.T) { allocSize := int64(4096) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) @@ -723,7 +723,7 @@ func TestUpdateAllocation(testSetup *testing.T) { allocSize := int64(4096) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationID := setupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "tokens": 9, }) diff --git a/tests/cli_tests/zwalletcli_register_wallet_test.go b/tests/cli_tests/zwalletcli_register_wallet_test.go index 67a8f2b3ff..d7e1be8fb4 100644 --- a/tests/cli_tests/zwalletcli_register_wallet_test.go +++ b/tests/cli_tests/zwalletcli_register_wallet_test.go @@ -17,21 +17,6 @@ import ( cliutils "github.com/0chain/system_test/internal/cli/util" ) -func createWalletAndLockReadTokens(t *test.SystemTest, cliConfigFilename string) error { - createWalletForName(escapedTestName(t)) - - // Lock half the tokens for read pool - readPoolParams := createParams(map[string]interface{}{ - "tokens": 2, - }) - _, err := readPoolLock(t, cliConfigFilename, readPoolParams, true) - if err != nil { - return err - } - - return nil -} - func createWallet(t *test.SystemTest) { createWalletForName(escapedTestName(t)) } @@ -58,16 +43,6 @@ func createWalletForName(name string) { } } -func createWalletForNameAndLockReadTokens(t *test.SystemTest, cliConfigFilename, name string) { - var tokens = 2.0 - createWalletForName(name) - readPoolParams := createParams(map[string]interface{}{ - "tokens": tokens / 2, - }) - _, err := readPoolLockWithWallet(t, name, cliConfigFilename, readPoolParams, true) - require.NoErrorf(t, err, "error occurred when locking read pool for %s", name) -} - func getBalance(t *test.SystemTest, cliConfigFilename string) ([]string, error) { cliutils.Wait(t, 5*time.Second) return getBalanceForWallet(t, cliConfigFilename, escapedTestName(t)) diff --git a/tests/tokenomics_tests/allocation_test.go b/tests/tokenomics_tests/allocation_test.go index 91cd7dc9e4..98f43a2f09 100644 --- a/tests/tokenomics_tests/allocation_test.go +++ b/tests/tokenomics_tests/allocation_test.go @@ -311,7 +311,7 @@ func TestAllocationRewards(testSetup *testing.T) { // register a new wallet nonAllocationOwnerWallet := "newwallet" - output, err = utils.CreateWalletForName(t, configPath, nonAllocationOwnerWallet) + output, err = utils.createWalletForName(nonAllocationOwnerWallet) require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) _, err = utils.ExecuteFaucetWithTokensForWallet(t, nonAllocationOwnerWallet, configPath, 9) require.Nil(t, err, "Error executing faucet", strings.Join(output, "\n")) @@ -412,7 +412,7 @@ func TestAddOrReplaceBlobberAllocationRewards(testSetup *testing.T) { allocSize := 1 * GB // 1. Create an allocation with 1 data shard and 1 parity shard. - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "data": 1, "tokens": 99, @@ -523,7 +523,7 @@ func TestAddOrReplaceBlobberAllocationRewards(testSetup *testing.T) { require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) _, err = utils.ExecuteFaucetWithTokens(t, configPath, 9) allocSize := 1 * GB // 1. Create an allocation with 1 data shard and 1 parity shard. - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": allocSize, "data": 1, "tokens": 99, diff --git a/tests/tokenomics_tests/blobber_challenge_reward_test.go b/tests/tokenomics_tests/blobber_challenge_reward_test.go index 28173b24bf..784c50f5c8 100644 --- a/tests/tokenomics_tests/blobber_challenge_reward_test.go +++ b/tests/tokenomics_tests/blobber_challenge_reward_test.go @@ -75,7 +75,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) { // Creating Allocation utils.SetupWalletWithCustomTokens(t, configPath, 9.0) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 99, "data": 1, @@ -98,7 +98,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) { // Creating Allocation utils.SetupWalletWithCustomTokens(t, configPath, 9.0) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 99, "data": 1, @@ -122,7 +122,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) { // Creating Allocation _ = utils.SetupWalletWithCustomTokens(t, configPath, 9.0) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 99, "data": 1, @@ -144,7 +144,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) { // Creating Allocation _ = utils.SetupWalletWithCustomTokens(t, configPath, 9.0) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 99, "data": 1, @@ -167,7 +167,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) { // Creating Allocation _ = utils.SetupWalletWithCustomTokens(t, configPath, 9.0) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 99, "data": 1, @@ -189,7 +189,7 @@ func TestBlobberChallengeRewards(testSetup *testing.T) { // Creating Allocation _ = utils.SetupWalletWithCustomTokens(t, configPath, 9.0) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 99, "data": 1, diff --git a/tests/tokenomics_tests/blobber_read_test.go b/tests/tokenomics_tests/blobber_read_test.go index 62ed620cef..1cd4ab026f 100644 --- a/tests/tokenomics_tests/blobber_read_test.go +++ b/tests/tokenomics_tests/blobber_read_test.go @@ -78,7 +78,7 @@ func TestBlobberReadReward(testSetup *testing.T) { require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) // 1. Create an allocation with 1 data shard and 1 parity shard. - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 500 * MB, "tokens": 1, "data": 1, @@ -148,7 +148,7 @@ func TestBlobberReadReward(testSetup *testing.T) { require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) // 1. Create an allocation with 1 data shard and 1 parity shard. - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 500 * MB, "tokens": 1, "data": 1, diff --git a/tests/tokenomics_tests/blobber_slash_penalty_test.go b/tests/tokenomics_tests/blobber_slash_penalty_test.go index 83b0d8b272..96a111e6d4 100644 --- a/tests/tokenomics_tests/blobber_slash_penalty_test.go +++ b/tests/tokenomics_tests/blobber_slash_penalty_test.go @@ -76,7 +76,7 @@ func TestBlobberSlashPenalty(testSetup *testing.T) { require.Nil(t, err, "error registering wallet", strings.Join(output, "\n")) // 1. Create an allocation with 1 data shard and 1 parity shard. - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 1 * GB, "tokens": 1, "data": 1, diff --git a/tests/tokenomics_tests/client_fileops_limits_test.go b/tests/tokenomics_tests/client_fileops_limits_test.go index 5d4f7c11ab..7e598980a7 100644 --- a/tests/tokenomics_tests/client_fileops_limits_test.go +++ b/tests/tokenomics_tests/client_fileops_limits_test.go @@ -61,7 +61,7 @@ func TestClientThrottling(testSetup *testing.T) { require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) // 1. Create an allocation with 1 data shard and 1 parity shard. - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 10 * MB, "tokens": 1, "data": 1, @@ -102,7 +102,7 @@ func TestClientThrottling(testSetup *testing.T) { }) t.RunWithTimeout("File upload should fail on exceeding max number of files", 20*time.Minute, func(t *test.SystemTest) { - output, err := utils.CreateWalletForName(t, configPath, "client_wallet_2") + output, err := utils.createWalletForName("client_wallet_2") require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) _, err = utils.ExecuteFaucetWithTokens(t, configPath, 9) diff --git a/tests/tokenomics_tests/enterprise_blobber_cancel_allocation_test.go b/tests/tokenomics_tests/enterprise_blobber_cancel_allocation_test.go index 0d9738e02f..c36a99fab0 100644 --- a/tests/tokenomics_tests/enterprise_blobber_cancel_allocation_test.go +++ b/tests/tokenomics_tests/enterprise_blobber_cancel_allocation_test.go @@ -319,7 +319,7 @@ func TestCancelEnterpriseAllocation(testSetup *testing.T) { }) t.Run("Cancel Other's Allocation Should Fail", func(t *test.SystemTest) { - output, err := utils.CreateWalletForName(t, configPath, utils.EscapedTestName(t)+"_other") + output, err := utils.createWalletForName(utils.EscapedTestName(t) + "_other") require.Nil(t, err, "Unable to create the wallet", strings.Join(output, "\n")) otherAllocationID := utils.SetupEnterpriseAllocationWithWallet(t, utils.EscapedTestName(t)+"_other", configPath) diff --git a/tests/tokenomics_tests/enterprise_blobber_create_allocation_test.go b/tests/tokenomics_tests/enterprise_blobber_create_allocation_test.go index 546438dfdf..f9a349ecec 100644 --- a/tests/tokenomics_tests/enterprise_blobber_create_allocation_test.go +++ b/tests/tokenomics_tests/enterprise_blobber_create_allocation_test.go @@ -117,7 +117,7 @@ func TestCreateEnterpriseAllocation(testSetup *testing.T) { output, err := utils.CreateWallet(t, configPath) require.Nil(t, err, "Error registering wallet", strings.Join(output, "\n")) - output, err = utils.CreateWalletForName(t, configPath, utils.EscapedTestName(t)+"_other") + output, err = utils.createWalletForName(utils.EscapedTestName(t) + "_other") require.Nil(t, err, "Error creating other wallet", strings.Join(output, "\n")) _, err = utils.ExecuteFaucetWithTokens(t, configPath, 10) diff --git a/tests/tokenomics_tests/enterprise_blobber_finalize_allocation_test.go b/tests/tokenomics_tests/enterprise_blobber_finalize_allocation_test.go index a7f4978410..a00b6ce668 100644 --- a/tests/tokenomics_tests/enterprise_blobber_finalize_allocation_test.go +++ b/tests/tokenomics_tests/enterprise_blobber_finalize_allocation_test.go @@ -191,7 +191,7 @@ func TestFinalizeEnterpriseAllocation(testSetup *testing.T) { }) t.Run("Finalize Other's Allocation Should Fail", func(t *test.SystemTest) { - output, err := utils.CreateWalletForName(t, configPath, utils.EscapedTestName(t)+"_other") + output, err := utils.createWalletForName(utils.EscapedTestName(t) + "_other") require.Nil(t, err, "Unable to create wallet", strings.Join(output, "\n")) var otherAllocationID = utils.SetupEnterpriseAllocationWithWallet(t, utils.EscapedTestName(t)+"_other", configPath) diff --git a/tests/tokenomics_tests/enterprise_blobber_update_allocation_test.go b/tests/tokenomics_tests/enterprise_blobber_update_allocation_test.go index 72681d6565..77c229aab8 100644 --- a/tests/tokenomics_tests/enterprise_blobber_update_allocation_test.go +++ b/tests/tokenomics_tests/enterprise_blobber_update_allocation_test.go @@ -955,7 +955,7 @@ func TestUpdateEnterpriseAllocation(testSetup *testing.T) { nonAllocOwnerWallet := utils.EscapedTestName(t) + "_NON_OWNER" - _, err = utils.CreateWalletForName(t, configPath, nonAllocOwnerWallet) + _, err = utils.createWalletForName(nonAllocOwnerWallet) require.Nil(t, err) params = createParams(map[string]interface{}{ @@ -1261,7 +1261,7 @@ func TestUpdateEnterpriseAllocation(testSetup *testing.T) { myAllocationID := setupAllocation(t, configPath) targetWalletName := utils.EscapedTestName(t) + "_TARGET" - _, err := utils.CreateWalletForName(t, configPath, targetWalletName) + _, err := utils.createWalletForName(targetWalletName) require.Nil(t, err) size := int64(2048) @@ -1397,7 +1397,7 @@ func TestUpdateEnterpriseAllocation(testSetup *testing.T) { nonAllocOwnerWallet := utils.EscapedTestName(t) + "_NON_OWNER" - _, err = utils.CreateWalletForName(t, configPath, nonAllocOwnerWallet) + _, err = utils.createWalletForName(nonAllocOwnerWallet) require.Nil(t, err) params = createParams(map[string]interface{}{ @@ -1432,7 +1432,7 @@ func TestUpdateEnterpriseAllocation(testSetup *testing.T) { nonAllocOwnerWallet := utils.EscapedTestName(t) + "_NON_OWNER" - _, err = utils.CreateWalletForName(t, configPath, nonAllocOwnerWallet) + _, err = utils.createWalletForName(nonAllocOwnerWallet) require.Nil(t, err, "Error creating wallet for non allocaiton owner") params = createParams(map[string]interface{}{ @@ -1490,7 +1490,7 @@ func TestUpdateEnterpriseAllocation(testSetup *testing.T) { } func setupAndParseAllocation(t *test.SystemTest, cliConfigFilename string, extraParams ...map[string]interface{}) (string, climodel.Allocation) { - allocationID := setupAllocation(t, cliConfigFilename, extraParams...) + allocationID := setupAllocation(cliConfigFilename, extraParams...) allocations := parseListAllocations(t, cliConfigFilename) allocation, ok := allocations[allocationID] @@ -1522,7 +1522,7 @@ func setupAllocation(t *test.SystemTest, cliConfigFilename string, extraParams . } func setupAllocationWithWallet(t *test.SystemTest, walletName, cliConfigFilename string, extraParams ...map[string]interface{}) string { - output, err := utils.CreateWalletForName(t, configPath, walletName) + output, err := utils.createWalletForName(walletName) require.Nil(t, err, "Error creating wallet", strings.Join(output, "\n")) output, err = utils.ExecuteFaucetWithTokens(t, configPath, 1000) diff --git a/tests/tokenomics_tests/min_stake_test.go b/tests/tokenomics_tests/min_stake_test.go index 770f5d0f90..0e283cdc91 100644 --- a/tests/tokenomics_tests/min_stake_test.go +++ b/tests/tokenomics_tests/min_stake_test.go @@ -269,7 +269,7 @@ func TestMinStakeForProviders(testSetup *testing.T) { time.Sleep(30 * time.Second) - allocationId := utils.SetupAllocationAndReadLock(t, configPath, map[string]interface{}{ + allocationId := utils.SetupAllocation(t, configPath, map[string]interface{}{ "size": 100 * MB, "tokens": 10, "data": 3, diff --git a/tests/tokenomics_tests/utils/allocation.go b/tests/tokenomics_tests/utils/allocation.go index 9b898a8ddb..a3ff2bceba 100644 --- a/tests/tokenomics_tests/utils/allocation.go +++ b/tests/tokenomics_tests/utils/allocation.go @@ -26,64 +26,11 @@ var ( createAllocationRegex = regexp.MustCompile(`^Allocation created: (.+)$`) ) -func SetupAllocationAndReadLock(t *test.SystemTest, cliConfigFilename string, extraParam map[string]interface{}) string { - tokens := float64(1) - if tok, ok := extraParam["tokens"]; ok { - token, err := strconv.ParseFloat(fmt.Sprintf("%v", tok), 64) - require.Nil(t, err) - tokens = token - } - - allocationID := SetupAllocation(t, cliConfigFilename, extraParam) - - // Lock half the tokens for read pool - readPoolParams := CreateParams(map[string]interface{}{ - "tokens": tokens / 2, - }) - output, err := ReadPoolLock(t, cliConfigFilename, readPoolParams, true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - - return allocationID -} - func SetupEnterpriseAllocationAndReadLock(t *test.SystemTest, cliConfigFilename string, extraParam map[string]interface{}) string { - tokens := float64(1) - if tok, ok := extraParam["tokens"]; ok { - token, err := strconv.ParseFloat(fmt.Sprintf("%v", tok), 64) - require.Nil(t, err) - tokens = token - } - allocationID := SetupEnterpriseAllocation(t, cliConfigFilename, extraParam) - - // Lock half the tokens for read pool - readPoolParams := CreateParams(map[string]interface{}{ - "tokens": tokens / 2, - }) - output, err := ReadPoolLock(t, cliConfigFilename, readPoolParams, true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - require.Equal(t, "locked", output[0]) - return allocationID } -func ReadPoolLock(t *test.SystemTest, cliConfigFilename, params string, retry bool) ([]string, error) { - return readPoolLockWithWallet(t, EscapedTestName(t), cliConfigFilename, params, retry) -} - -func readPoolLockWithWallet(t *test.SystemTest, wallet, cliConfigFilename, params string, retry bool) ([]string, error) { - t.Logf("Locking read tokens...") - cmd := fmt.Sprintf("./zbox rp-lock %s --silent --wallet %s_wallet.json --configDir ./config --config %s", params, wallet, cliConfigFilename) - if retry { - return cliutils.RunCommand(t, cmd, 3, time.Second*2) - } else { - return cliutils.RunCommandWithoutRetry(cmd) - } -} - func SetupAllocation(t *test.SystemTest, cliConfigFilename string, extraParams ...map[string]interface{}) string { return SetupAllocationWithWallet(t, EscapedTestName(t), cliConfigFilename, extraParams...) } diff --git a/tests/tokenomics_tests/utils/wallet.go b/tests/tokenomics_tests/utils/wallet.go index aafc0569f1..2a1c0a3946 100644 --- a/tests/tokenomics_tests/utils/wallet.go +++ b/tests/tokenomics_tests/utils/wallet.go @@ -40,8 +40,7 @@ func CreateWallet(t *test.SystemTest, cliConfigFilename string, opt ...createWal } type createWalletOption struct { - noPourAndReadPool bool - debugLogs bool + debugLogs bool } type createWalletOptionFunc func(*createWalletOption) @@ -53,11 +52,6 @@ func CreateWalletForName(t *test.SystemTest, cliConfigFilename, name string, opt opt(regOpt) } - if regOpt.noPourAndReadPool { - return cliutils.RunCommand(t, "./zwallet create-wallet --silent "+ - "--wallet "+name+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, 3, time.Second*2) - } - if regOpt.debugLogs { return cliutils.RunCommand(t, "./zwallet create-wallet "+ "--wallet "+name+"_wallet.json"+" --configDir ./config --config "+cliConfigFilename, 3, time.Second*2)