diff --git a/go.mod b/go.mod index fdaa2dfecf..b2365d9143 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,10 @@ module github.com/0chain/system_test -go 1.21 - -toolchain go1.22.1 +go 1.22.0 require ( github.com/0chain/errors v1.0.3 - github.com/0chain/gosdk v1.17.12-0.20241014153936-4301b5659140 + github.com/0chain/gosdk v1.18.0-RC1.0.20241019160820-24aad2c5153e 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 5c956acd1b..6b7eda596c 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/0chain/common v1.13.1-0.20240926135437-61b88d39bbbd h1:PDnzyJJA4rF2LB github.com/0chain/common v1.13.1-0.20240926135437-61b88d39bbbd/go.mod h1:vHK9Q0/nz28PxmKsLSMLzEs5iK6QVgl1LxdDQdR7y6s= 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.12-0.20241014153936-4301b5659140 h1:eTIe2w8HUhuRNv8j+AdhFyMZOlAYfOX4W+JzSfrPDzo= -github.com/0chain/gosdk v1.17.12-0.20241014153936-4301b5659140/go.mod h1:mr7LcQicFFrSzFujItjkLP1LvXz9S0j73i7KDEpMXLo= +github.com/0chain/gosdk v1.18.0-RC1.0.20241019160820-24aad2c5153e h1:sZv2kJX61rSAgSBVyMsiHXRD/L69LyPZAm2yed18fjI= +github.com/0chain/gosdk v1.18.0-RC1.0.20241019160820-24aad2c5153e/go.mod h1:OxXnxfqGJ9OIwX7WITV/A9ZctYorVMbaHuqkhERAImU= 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/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= @@ -97,7 +97,6 @@ github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= diff --git a/internal/api/model/api.go b/internal/api/model/api.go index 7f8f50096d..eeafe345b9 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 28a6fb72a3..6c7b1f89eb 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 @@ -1313,27 +1294,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...") @@ -1735,99 +1695,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/api/util/client/sdk.go b/internal/api/util/client/sdk.go index fe8e4e1d92..cbc83100f2 100644 --- a/internal/api/util/client/sdk.go +++ b/internal/api/util/client/sdk.go @@ -3,6 +3,7 @@ package client import ( "bytes" "crypto/rand" + "github.com/0chain/gosdk/core/client" "io" "os" "path/filepath" @@ -96,13 +97,12 @@ func (c *SDKClient) SetWallet(t *test.SystemTest, wallet *model.Wallet) { serializedWallet, err := c.wallet.String() require.NoError(t, err, "failed to serialize wallet object", wallet) - err = sdk.InitStorageSDK( + err = client.InitSDK( serializedWallet, c.blockWorker, "", crypto.BLS0Chain, - nil, - int64(wallet.Nonce), + int64(wallet.Nonce), false, true, ) require.NoError(t, err, ErrInitStorageSDK) } 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 f45807b5c6..bbca192569 100644 --- a/tests/api_tests/0box_aggregate_endpoints_test.go +++ b/tests/api_tests/0box_aggregate_endpoints_test.go @@ -1454,8 +1454,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/client_send_nonce_greater_than_some_nonce_test.go b/tests/api_tests/client_send_nonce_greater_than_some_nonce_test.go index e866dc24f7..7d34232a0d 100644 --- a/tests/api_tests/client_send_nonce_greater_than_some_nonce_test.go +++ b/tests/api_tests/client_send_nonce_greater_than_some_nonce_test.go @@ -2,10 +2,12 @@ package api_tests import ( "encoding/json" + "github.com/0chain/gosdk/core/transaction" "strconv" "testing" "time" + coreClient "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/zcncore" "github.com/0chain/system_test/internal/api/model" "github.com/0chain/system_test/internal/api/util/client" @@ -23,8 +25,7 @@ func TestClientSendNonceGreaterThanFutureNonceLimit(testSetup *testing.T) { wallet1 := initialisedWallets[walletIdx] walletIdx++ - err := zcncore.SetWallet(*wallet1.ToZCNCryptoWallet(wallet1.Mnemonics), false) - require.NoError(t, err) + coreClient.SetWallet(*wallet1.ToZCNCryptoWallet(wallet1.Mnemonics)) faucetAmount := float64(9) balResp := apiClient.GetWalletBalance(t, wallet1, client.HttpOkStatus) @@ -64,8 +65,7 @@ func TestClientSendSameNonceForDifferentTransactions(testSetup *testing.T) { wallet1 := initialisedWallets[walletIdx] walletIdx++ - err := zcncore.SetWallet(*wallet1.ToZCNCryptoWallet(wallet1.Mnemonics), false) - require.NoError(t, err) + coreClient.SetWallet(*wallet1.ToZCNCryptoWallet(wallet1.Mnemonics)) faucetAmount := float64(9) balResp := apiClient.GetWalletBalance(t, wallet1, client.HttpOkStatus) @@ -183,8 +183,7 @@ func TestClientSendTransactionToOnlyOneMiner(testSetup *testing.T) { wallet1 := initialisedWallets[walletIdx] walletIdx++ - err := zcncore.SetWallet(*wallet1.ToZCNCryptoWallet(wallet1.Mnemonics), false) - require.NoError(t, err) + coreClient.SetWallet(*wallet1.ToZCNCryptoWallet(wallet1.Mnemonics)) faucetAmount := float64(9) balResp := apiClient.GetWalletBalance(t, wallet1, client.HttpOkStatus) @@ -248,27 +247,11 @@ func TestClientSendTransactionToOnlyOneMiner(testSetup *testing.T) { require.Equal(t, txnResp.Request.Hash, confResp.Transaction.Hash) } -func GetGlobalConfig(t *test.SystemTest) map[string]interface{} { - cb := GlobalCB{ - Globals: make(map[string]interface{}), - doneCh: make(chan struct{}), - errCh: make(chan error), - } - - err := zcncore.GetMinerSCGlobals(&cb) +func GetGlobalConfig(t *test.SystemTest) map[string]string { + res, err := transaction.GetConfig("miner_sc_globals") require.NoError(t, err) - dur := time.Minute - tm := time.NewTimer(dur) - select { - case <-cb.doneCh: - case err := <-cb.errCh: - t.Error(err) - case <-tm.C: - t.Errorf("Timeout occurred while waiting for global config after %v", dur) - } - - return cb.Globals + return res.Fields } func GetTransactionTimeOut(t *test.SystemTest) time.Duration { @@ -276,8 +259,7 @@ func GetTransactionTimeOut(t *test.SystemTest) time.Duration { tmKey := "server_chain.transaction.timeout" i, ok := globalConfig[tmKey] require.True(t, ok) - s := i.(string) - tm, err := strconv.Atoi(s) + tm, err := strconv.Atoi(i) require.NoError(t, err) return time.Duration(tm) * time.Second } @@ -287,8 +269,7 @@ func GetFutureNonceConfig(t *test.SystemTest) int { fnKey := "server_chain.transaction.future_nonce" // future nonce key i, ok := globalConfig[fnKey] require.True(t, ok) - s := i.(string) - n, err := strconv.Atoi(s) + n, err := strconv.Atoi(i) require.NoError(t, err) return n } diff --git a/tests/api_tests/main_test.go b/tests/api_tests/main_test.go index c56e5f340e..c546c013be 100644 --- a/tests/api_tests/main_test.go +++ b/tests/api_tests/main_test.go @@ -1,7 +1,10 @@ package api_tests import ( + "context" "encoding/json" + coreClient "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/conf" "log" "os" "strconv" @@ -9,7 +12,6 @@ import ( "testing" "time" - "github.com/0chain/gosdk/zcncore" "github.com/0chain/system_test/internal/api/model" "github.com/0chain/system_test/internal/api/util/client" "github.com/0chain/system_test/internal/api/util/config" @@ -68,7 +70,15 @@ func TestMain(m *testing.M) { t := test.NewSystemTest(new(testing.T)) - err = zcncore.Init(getConfigForZcnCoreInit(parsedConfig.BlockWorker)) + err = coreClient.Init(context.Background(), conf.Config{ + BlockWorker: parsedConfig.BlockWorker, + SignatureScheme: "bls0chain", + ChainID: "0afc093ffb509f059c55478bc1a60351cef7b4e9c008a53a6cc8241ca8617dfe", + MaxTxnQuery: 5, + QuerySleepTime: 5, + MinSubmit: 10, + MinConfirmation: 10, + }) require.NoError(t, err) blobberOwnerWalletMnemonics = parsedConfig.BlobberOwnerWalletMnemonics 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 777b922ef9..bf49ecc2b7 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 @@ -353,7 +351,6 @@ func TestRepairSize(testSetup *testing.T) { t.Skip("Skipping as repair size is not implemented for V2") 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 2df8a79bc7..729d6c9b9b 100644 --- a/tests/cli_tests/0_expired_allocation_test.go +++ b/tests/cli_tests/0_expired_allocation_test.go @@ -75,9 +75,9 @@ func TestExpiredAllocation(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) 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/readmarker_test.go b/tests/cli_tests/readmarker_test.go deleted file mode 100644 index d599327541..0000000000 --- a/tests/cli_tests/readmarker_test.go +++ /dev/null @@ -1,392 +0,0 @@ -package cli_tests - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strings" - "testing" - "time" - - "github.com/0chain/system_test/internal/api/util/test" - - cliutils "github.com/0chain/system_test/internal/cli/util" - - climodel "github.com/0chain/system_test/internal/cli/model" - "github.com/stretchr/testify/require" -) - -func TestReadMarker(testSetup *testing.T) { - t := test.NewSystemTest(testSetup) - t.SetSmokeTests("After downloading a file, return a readmarker for each blobber used in download") - - t.Skip() - - // t.Parallel() - - const blobbersRequiredForDownload = 3 // download needs (data shards) number of blobbers - - var sharderUrl string - t.TestSetup("Create wallet and temp directories, get sharder url", func() { - createWallet(t) - sharderUrl = getSharderUrl(t) - - err := os.MkdirAll("tmp", os.ModePerm) - require.Nil(t, err) - }) - - t.Run("After downloading a file, return a readmarker for each blobber used in download", func(t *test.SystemTest) { - allocSize := int64(2048) - filesize := int64(256) - remotePath := "/dir/" - - allocationId := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, - "data": 3, - "parity": 1, - }) - - filename := generateFileAndUpload(t, allocationId, remotePath, filesize) - - err := os.Remove(filename) - require.Nil(t, err) - - beforeCount := CountReadMarkers(t, allocationId, sharderUrl) - require.Zero(t, beforeCount.ReadMarkersCount, "non zero read-marker count before download") - - output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ - "allocation": allocationId, - "remotepath": remotePath + filepath.Base(filename), - "localpath": os.TempDir() + string(os.PathSeparator), - }), true) - require.Nil(t, err, "error downloading file", strings.Join(output, "\n")) - - time.Sleep(time.Second * 20) - - readMarkers := GetReadMarkers(t, allocationId, sharderUrl) - require.Equal(t, len(readMarkers), blobbersRequiredForDownload+1) // Sends data+1 readmarkers. Needs only len(data), 1 is a failover. - - afterCount := CountReadMarkers(t, allocationId, sharderUrl) - require.EqualValuesf(t, afterCount.ReadMarkersCount, len(readMarkers), "should equal length of read-markers", len(readMarkers)) - }) - - t.Run("After downloading an encrypted file, return a readmarker for each blobber used in download", func(t *test.SystemTest) { - allocSize := int64(10 * MB) - filesize := int64(10) - remotePath := "/" - - allocationId := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, - "data": 3, - "parity": 1, - }) - - filename := generateRandomTestFileName(t) - err := createFileWithSize(filename, filesize) - require.Nil(t, err) - - // Upload parameters - uploadWithParam(t, configPath, map[string]interface{}{ - "allocation": allocationId, - "localpath": filename, - "remotepath": remotePath + filepath.Base(filename), - "encrypt": "", - }) - - // Delete the uploaded file, since we will be downloading it now - err = os.Remove(filename) - require.Nil(t, err) - - sharderUrl := getSharderUrl(t) - beforeCount := CountReadMarkers(t, allocationId, sharderUrl) - require.Zero(t, beforeCount.ReadMarkersCount, "non zero read-marker count before download") - - // Downloading encrypted file should work - output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ - "allocation": allocationId, - "remotepath": remotePath + filepath.Base(filename), - "localpath": os.TempDir(), - }), true) - require.Nil(t, err, strings.Join(output, "\n")) - - time.Sleep(time.Second * 20) - - readMarkers := GetReadMarkers(t, allocationId, sharderUrl) - require.Equal(t, len(readMarkers), blobbersRequiredForDownload+1) // Sends data+1 readmarkers. Needs only len(data), 1 is a failover. - - afterCount := CountReadMarkers(t, allocationId, sharderUrl) - require.EqualValuesf(t, afterCount.ReadMarkersCount, len(readMarkers), "should equal length of read-markers", len(readMarkers)) - }) - - t.RunWithTimeout("After downloading a shared file, return a readmarker for each blobber used in download", 120*time.Second, func(t *test.SystemTest) { - var authTicket, filename, allocationID string - - filesize := int64(10) - remotepath := "/" - - // 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{}{ - "size": 10 * 1024, - "tokens": 9, - "data": 3, - "parity": 1, - }) - filename = generateFileAndUpload(t, allocationID, remotepath, filesize) - - require.NotEqual(t, "", filename) - - // Delete the uploaded file from tmp folder if it exist, - // since we will be downloading it now - err := os.RemoveAll("tmp/" + filepath.Base(filename)) - require.Nil(t, err) - - shareParam := createParams(map[string]interface{}{ - "allocation": allocationID, - "remotepath": remotepath + filepath.Base(filename), - }) - - output, err := shareFolderInAllocation(t, configPath, shareParam) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - - authTicket, err = extractAuthToken(output[0]) - require.Nil(t, err, "extract auth token failed") - require.NotEqual(t, "", authTicket, "Ticket: ", authTicket) - }) - - // Just create a wallet so that we can work further - err := createWalletAndLockReadTokens(t, configPath) - require.Nil(t, err) - - // Download file using auth-ticket: should work - output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ - "authticket": authTicket, - "localpath": "tmp/", - }), true) - require.Nil(t, err, strings.Join(output, "\n")) - - time.Sleep(time.Second * 20) - - readMarkers := GetReadMarkers(t, allocationID, sharderUrl) - require.Equal(t, len(readMarkers), blobbersRequiredForDownload+1) // Sends data+1 readmarkers. Needs only len(data), 1 is a failover. - - afterCount := CountReadMarkers(t, allocationID, sharderUrl) - require.EqualValuesf(t, afterCount.ReadMarkersCount, len(readMarkers), "should equal length of read-markers", len(readMarkers)) - }) - - t.RunWithTimeout("After downloading a shared encrypted file, return a readmarker for each blobber used in download", 3*time.Minute, func(t *test.SystemTest) { - var authTicket, filename string - - filesize := int64(10) - remotepath := "/" - var allocationID string - - // create viewer wallet - viewerWalletName := escapedTestName(t) + "_viewer" - createWalletForNameAndLockReadTokens(t, configPath, viewerWalletName) - - viewerWallet, err := getWalletForName(t, configPath, viewerWalletName) - require.Nil(t, err) - require.NotNil(t, viewerWallet) - - // 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{}{ - "size": 10 * 1024, - "tokens": 9, - "data": 3, - "parity": 1, - }) - filename = generateFileAndUploadWithParam(t, allocationID, remotepath, filesize, map[string]interface{}{ - "encrypt": "", - }) - require.NotEqual(t, "", filename) - - // Delete the uploaded file from tmp folder if it exist, - // since we will be downloading it now - err := os.RemoveAll("tmp/" + filepath.Base(filename)) - require.Nil(t, err) - - shareParam := createParams(map[string]interface{}{ - "allocation": allocationID, - "remotepath": remotepath + filepath.Base(filename), - "encryptionpublickey": viewerWallet.EncryptionPublicKey, - }) - - output, err := shareFolderInAllocation(t, configPath, shareParam) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - - authTicket, err = extractAuthToken(output[0]) - require.Nil(t, err, "extract auth token failed") - require.NotEqual(t, "", authTicket, "Ticket: ", authTicket) - }) - - file := "tmp/" + filepath.Base(filename) - - // Download file using auth-ticket: should work - output, err := downloadFileForWallet(t, viewerWalletName, configPath, createParams(map[string]interface{}{ - "authticket": authTicket, - "localpath": file, - }), true) - require.NoError(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2) - - require.Contains(t, output[len(output)-1], StatusCompletedCB) - require.Contains(t, output[len(output)-1], filepath.Base(filename)) - - time.Sleep(time.Second * 20) - - readMarkers := GetReadMarkers(t, allocationID, sharderUrl) - require.Equal(t, len(readMarkers), blobbersRequiredForDownload+1) // Sends data+1 readmarkers. Needs only len(data), 1 is a failover. - - afterCount := CountReadMarkers(t, allocationID, sharderUrl) - require.EqualValuesf(t, afterCount.ReadMarkersCount, len(readMarkers), "should equal length of read-markers", len(readMarkers)) - }) - - t.RunWithTimeout("After downloading a shared encrypted file by lookuphash, return a readmarker for each blobber used in download", 120*time.Second, func(t *test.SystemTest) { - var authTicket, filename string - - filesize := int64(10) - remotepath := "/" - var allocationID string - - // create viewer wallet - viewerWalletName := escapedTestName(t) + "_viewer" - createWalletForNameAndLockReadTokens(t, configPath, viewerWalletName) - - viewerWallet, err := getWalletForName(t, configPath, viewerWalletName) - require.Nil(t, err) - require.NotNil(t, viewerWallet) - - // 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{}{ - "size": 10 * 1024, - "tokens": 9, - "data": 3, - "parity": 1, - }) - filename = generateFileAndUploadWithParam(t, allocationID, remotepath, filesize, map[string]interface{}{ - "encrypt": "", - }) - require.NotEqual(t, "", filename) - - // Delete the uploaded file from tmp folder if it exist, - // since we will be downloading it now - err := os.RemoveAll("tmp/" + filepath.Base(filename)) - require.Nil(t, err) - - shareParam := createParams(map[string]interface{}{ - "allocation": allocationID, - "remotepath": remotepath + filepath.Base(filename), - "encryptionpublickey": viewerWallet.EncryptionPublicKey, - }) - - output, err := shareFolderInAllocation(t, configPath, shareParam) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - - authTicket, err = extractAuthToken(output[0]) - require.Nil(t, err, "extract auth token failed") - require.NotEqual(t, "", authTicket, "Ticket: ", authTicket) - }) - - file := "tmp/" + filepath.Base(filename) - - // Download file using auth-ticket and lookuphash: should work - output, err := downloadFileForWallet(t, viewerWalletName, configPath, createParams(map[string]interface{}{ - "authticket": authTicket, - "lookuphash": GetReferenceLookup(allocationID, remotepath+filepath.Base(filename)), - "localpath": file, - }), true) - require.Nil(t, err, strings.Join(output, "\n")) - - time.Sleep(time.Second * 20) - - readMarkers := GetReadMarkers(t, allocationID, sharderUrl) - require.Equal(t, len(readMarkers), blobbersRequiredForDownload+1) // Sends data+1 readmarkers. Needs only len(data), 1 is a failover. - - afterCount := CountReadMarkers(t, allocationID, sharderUrl) - require.EqualValuesf(t, afterCount.ReadMarkersCount, len(readMarkers), "should equal length of read-markers", len(readMarkers)) - }) - - t.Run("After downloading a file by blocks, return a readmarker for each blobber used in download", func(t *test.SystemTest) { - // 1 block is of size 65536, we upload 20 blocks and download 1 block - allocSize := int64(655360 * 4) - filesize := int64(655360 * 2) - remotepath := "/" - - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, - "data": 3, - "parity": 1, - }) - - filename := generateFileAndUpload(t, allocationID, remotepath, filesize) - - // Delete the uploaded file, since we will be downloading it now - err := os.Remove(filename) - require.Nil(t, err) - - output, err := getFileStats(t, configPath, createParams(map[string]interface{}{ - "allocation": allocationID, - "remotepath": "/" + filepath.Base(filename), - "json": "", - }), true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 1) - - var stats map[string]climodel.FileStats - - err = json.Unmarshal([]byte(output[0]), &stats) - require.Nil(t, err) - - startBlock := 1 - endBlock := 6 - // Minimum Startblock value should be 1 (since gosdk subtracts 1 from start block, so 0 would lead to startblock being -1). - output, err = downloadFile(t, configPath, createParams(map[string]interface{}{ - "allocation": allocationID, - "remotepath": remotepath + filepath.Base(filename), - "localpath": "tmp/", - "startblock": startBlock, - "endblock": endBlock, - }), true) - require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2) - - time.Sleep(time.Second * 20) - - readMarkers := GetReadMarkers(t, allocationID, sharderUrl) - require.Equal(t, len(readMarkers), blobbersRequiredForDownload+1) // Sends data+1 readmarkers. Needs only len(data), 1 is a failover. - - for _, rm := range readMarkers { - require.Equal(t, int64(6), rm.ReadCounter) - } - - afterCount := CountReadMarkers(t, allocationID, sharderUrl) - require.EqualValuesf(t, afterCount.ReadMarkersCount, len(readMarkers), "should equal length of read-markers", len(readMarkers)) - }) -} - -func CountReadMarkers(t *test.SystemTest, allocationId, sharderBaseUrl string) *climodel.ReadMarkersCount { - url := fmt.Sprintf(sharderBaseUrl + "/v1/screst/" + cliutils.StorageScAddress + "/count_readmarkers") - params := map[string]string{ - "allocation_id": allocationId, - } - return cliutils.ApiGet[climodel.ReadMarkersCount](t, url, params) -} - -func GetReadMarkers(t *test.SystemTest, allocationId, sharderBaseUrl string) []climodel.ReadMarker { - url := fmt.Sprintf(sharderBaseUrl + "/v1/screst/" + cliutils.StorageScAddress + "/readmarkers") - params := make(map[string]string) - if allocationId != "" { - params["allocation_id"] = allocationId - } - return cliutils.ApiGetList[climodel.ReadMarker](t, url, params, 0, 100) -} diff --git a/tests/cli_tests/sdk.go b/tests/cli_tests/sdk.go index c27bf92054..37f814293d 100644 --- a/tests/cli_tests/sdk.go +++ b/tests/cli_tests/sdk.go @@ -1,9 +1,10 @@ package cli_tests import ( + "context" "crypto/rand" - "encoding/json" "fmt" + "github.com/0chain/gosdk/core/client" "io" "math/big" "os" @@ -11,7 +12,6 @@ import ( "github.com/0chain/gosdk/core/conf" "github.com/0chain/gosdk/zboxcore/fileref" "github.com/0chain/gosdk/zboxcore/sdk" - "github.com/0chain/gosdk/zcncore" ) func InitSDK(wallet, configFile string) error { @@ -30,22 +30,26 @@ func InitSDK(wallet, configFile string) error { return err } - marshal, err := json.Marshal(parsed) - if err != nil { - return err - } - err = zcncore.Init(string(marshal)) + err = client.Init(context.Background(), conf.Config{ + BlockWorker: parsed.BlockWorker, + SignatureScheme: parsed.SignatureScheme, + ChainID: parsed.ChainID, + MaxTxnQuery: 5, + QuerySleepTime: 5, + MinSubmit: 10, + MinConfirmation: 10, + }) if err != nil { return err } - err = sdk.InitStorageSDK( + err = client.InitSDK( walletJSON, parsed.BlockWorker, parsed.ChainID, parsed.SignatureScheme, - nil, 0, + false, true, ) return err } 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..5dea41baa0 100644 --- a/tests/cli_tests/zboxcli_file_download_resume_test.go +++ b/tests/cli_tests/zboxcli_file_download_resume_test.go @@ -27,9 +27,9 @@ 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, + "lock": 9, "data": 3, "parity": 1, }) diff --git a/tests/cli_tests/zboxcli_file_download_test.go b/tests/cli_tests/zboxcli_file_download_test.go index c896defc74..1f2504b0d9 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,9 +36,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -70,9 +69,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(1024) remoteFilePaths := [2]string{"/dir1/", "/dir2/"} - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) fileNameOfFirstDirectory := generateFileAndUpload(t, allocationID, remoteFilePaths[0], filesize) @@ -131,9 +130,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/dir/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -164,9 +163,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/nested/dir/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -197,9 +196,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/nested/dir/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -226,9 +225,9 @@ 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{}{ - "size": 64 * KB * 2, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 64 * KB * 2, + "lock": 9, }) filename = generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -276,9 +275,9 @@ 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{}{ - "size": 64 * KB * 2, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 64 * KB * 2, + "lock": 9, }) filename = generateFileAndUpload(t, allocationID, remotepath, filesize) originalFileChecksum = generateChecksum(t, filename) @@ -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,9 +326,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(10) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateRandomTestFileName(t) @@ -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,9 +379,9 @@ 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{}{ - "size": 64 * KB * 2, - "tokens": 9, + allocationID = setupAllocation(t, configPath, map[string]interface{}{ + "size": 64 * KB * 2, + "lock": 9, }) filename = generateFileAndUploadWithParam(t, allocationID, remotepath, filesize, map[string]interface{}{ "encrypt": "", @@ -447,9 +444,9 @@ 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{}{ - "size": 64 * KB * 2, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 64 * KB * 2, + "lock": 9, }) filename = generateFileAndUpload(t, allocationID, remotepath, filesize) originalFileChecksum = generateChecksum(t, filename) @@ -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{}{ @@ -485,10 +481,10 @@ func TestDownload(testSetup *testing.T) { "remotepath": remotepath + filepath.Base(filename), }), true) require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2) + require.Len(t, output, 3) - require.Contains(t, output[1], StatusCompletedCB) - require.Contains(t, output[1], filepath.Base(filename)) + require.Contains(t, output[2], StatusCompletedCB) + require.Contains(t, output[2], filepath.Base(filename)) downloadedFileChecksum := generateChecksum(t, "tmp/"+filepath.Base(filename)) @@ -503,9 +499,9 @@ 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{}{ - "size": 64 * KB * 2, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 64 * KB * 2, + "lock": 9, }) filename = generateFileAndUpload(t, allocationID, remotepath, filesize) originalFileChecksum = generateChecksum(t, filename) @@ -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{}{ @@ -545,10 +540,10 @@ func TestDownload(testSetup *testing.T) { "lookuphash": lookuphash, }), true) require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2) + require.Len(t, output, 3) - require.Contains(t, output[1], StatusCompletedCB) - require.Contains(t, output[1], filepath.Base(filename)) + require.Contains(t, output[2], StatusCompletedCB) + require.Contains(t, output[2], filepath.Base(filename)) downloadedFileChecksum := generateChecksum(t, "tmp/"+filepath.Base(filename)) @@ -564,9 +559,9 @@ 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{}{ - "size": 64 * KB * 2, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 10 * 1024, + "lock": 9, }) filename = generateFileAndUpload(t, allocationID, remotepath, filesize) require.NotEqual(t, "", filename) @@ -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, @@ -646,7 +641,7 @@ func TestDownload(testSetup *testing.T) { }), false) require.Nil(t, err, strings.Join(output, "\n")) - require.Len(t, output, 2) + require.Len(t, output, 3) aggregatedOutput := strings.Join(output, " ") require.Contains(t, aggregatedOutput, filepath.Base(filename)) }) @@ -656,9 +651,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) thumbnail := escapedTestName(t) + "thumbnail.png" @@ -699,9 +694,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) thumbnail := escapedTestName(t) + "thumbnail.png" @@ -743,9 +738,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -781,9 +776,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -834,9 +829,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -865,9 +860,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -921,9 +916,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -954,9 +949,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(10240) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -988,9 +983,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -1021,9 +1016,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -1051,9 +1046,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(655360 * 2) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -1083,9 +1078,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -1164,9 +1159,9 @@ 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": 64 * KB * 2, - "tokens": 9, + "lock": 9, }) output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ @@ -1191,9 +1186,9 @@ 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": 64 * KB * 2, - "tokens": 9, + "lock": 9, }) output, err := downloadFile(t, configPath, createParams(map[string]interface{}{ @@ -1210,9 +1205,9 @@ func TestDownload(testSetup *testing.T) { filesize := int64(256) remotepath := "/" - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) filename := generateFileAndUpload(t, allocationID, remotepath, filesize) @@ -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 8cad885d2b..ebffbd1577 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..0d7e7ae000 100644 --- a/tests/cli_tests/zboxcli_file_update_test.go +++ b/tests/cli_tests/zboxcli_file_update_test.go @@ -29,9 +29,9 @@ 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{}{ - "size": 10 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 10 * MB, + "lock": 9, }) filesize := int64(0.5 * MB) @@ -119,9 +119,9 @@ 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{}{ - "size": 10 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 10 * MB, + "lock": 9, }) filesize := int64(0.5 * MB) @@ -252,9 +252,9 @@ 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{}{ - "size": 10 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 10 * MB, + "lock": 9, }) filesize := int64(0.5 * MB) @@ -296,9 +296,9 @@ 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{}{ - "size": 10 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 10 * MB, + "lock": 9, }) filesize := int64(0.5 * MB) @@ -339,9 +339,9 @@ 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{}{ - "size": 10 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 10 * MB, + "lock": 9, }) filesize := int64(0.5 * MB) diff --git a/tests/cli_tests/zboxcli_restricted_blobber_test.go b/tests/cli_tests/zboxcli_restricted_blobber_test.go index d707df9f01..ae2d924bd0 100644 --- a/tests/cli_tests/zboxcli_restricted_blobber_test.go +++ b/tests/cli_tests/zboxcli_restricted_blobber_test.go @@ -180,9 +180,9 @@ func TestRestrictedBlobbers(testSetup *testing.T) { allocSize := int64(64 * KB * 2) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) // faucet tokens @@ -249,9 +249,9 @@ func TestRestrictedBlobbers(testSetup *testing.T) { allocSize := int64(64 * KB * 2) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) // faucet tokens diff --git a/tests/cli_tests/zboxcli_rollback_test.go b/tests/cli_tests/zboxcli_rollback_test.go index 267957d048..d5ba0c6dd4 100644 --- a/tests/cli_tests/zboxcli_rollback_test.go +++ b/tests/cli_tests/zboxcli_rollback_test.go @@ -23,9 +23,9 @@ 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{}{ - "size": 4 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 4 * MB, + "lock": 9, }) filesize := int64(0.5 * MB) @@ -93,9 +93,9 @@ 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{}{ - "size": 4 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 4 * MB, + "lock": 9, }) fileSize := int64(1 * MB) @@ -152,9 +152,9 @@ 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{}{ - "size": 1 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 1 * MB, + "lock": 9, }) createAllocationTestTeardown(t, allocationID) @@ -416,9 +416,9 @@ 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{}{ - "size": 2 * MB, - "tokens": 10, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 2 * MB, + "lock": 10, }) remotePath := "/" @@ -488,9 +488,9 @@ 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{}{ - "size": 4 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 4 * MB, + "lock": 9, }) remotepath := "/" @@ -559,9 +559,9 @@ 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{}{ - "size": 4 * MB, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 4 * MB, + "lock": 9, }) remotepath := "/" @@ -652,9 +652,9 @@ 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{}{ - "size": 2 * GB, - "tokens": 10, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 2 * GB, + "lock": 10, }) filesize := int64(1.5 * GB) @@ -695,9 +695,9 @@ 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{}{ - "size": 2 * GB, - "tokens": 10, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": 2 * GB, + "lock": 10, }) filesize := int64(1.5 * GB) 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 a6b0c3b498..d36f7eb374 100644 --- a/tests/cli_tests/zboxcli_update_allocation_test.go +++ b/tests/cli_tests/zboxcli_update_allocation_test.go @@ -678,9 +678,9 @@ func TestUpdateAllocation(testSetup *testing.T) { allocSize := int64(64 * KB * 2) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) // faucet tokens @@ -723,9 +723,9 @@ func TestUpdateAllocation(testSetup *testing.T) { allocSize := int64(64 * KB * 2) fileSize := int64(1024) - allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{ - "size": allocSize, - "tokens": 9, + allocationID := setupAllocation(t, configPath, map[string]interface{}{ + "size": allocSize, + "lock": 9, }) // faucet tokens diff --git a/tests/cli_tests/zwalletcli_miner_stake_test.go b/tests/cli_tests/zwalletcli_miner_stake_test.go index 38b020e4f8..43de050eaf 100644 --- a/tests/cli_tests/zwalletcli_miner_stake_test.go +++ b/tests/cli_tests/zwalletcli_miner_stake_test.go @@ -62,7 +62,7 @@ func TestMinerStake(testSetup *testing.T) { poolsInfo, err := pollForPoolInfo(t, miner.ID) require.Nil(t, err) - require.Equal(t, float64(2.0), intToZCN(poolsInfo.Balance)) + require.Equal(t, 2.0, intToZCN(poolsInfo.Balance)) // Unlock should work output, err = minerOrSharderUnlock(t, configPath, createParams(map[string]interface{}{ @@ -280,6 +280,8 @@ func pollForPoolInfo(t *test.SystemTest, minerID string) (climodel.DelegatePool, t.Log(`polling for pool info till it is "ACTIVE"...`) timeout := time.After(time.Minute * 5) + time.Sleep(10 * time.Second) + var poolsInfo climodel.DelegatePool for { output, err := minerSharderPoolInfo(t, configPath, createParams(map[string]interface{}{ 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/cli_tests/zwalletcli_send_and_balance_test.go b/tests/cli_tests/zwalletcli_send_and_balance_test.go index 87b1526d94..440223b597 100644 --- a/tests/cli_tests/zwalletcli_send_and_balance_test.go +++ b/tests/cli_tests/zwalletcli_send_and_balance_test.go @@ -17,9 +17,6 @@ import ( cliutils "github.com/0chain/system_test/internal/cli/util" ) -// address of minersc -const MINER_SC_ADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d9" - func TestSendAndBalance(testSetup *testing.T) { t := test.NewSystemTest(testSetup) t.SetSmokeTests("Send with description") @@ -130,7 +127,7 @@ func TestSendAndBalance(testSetup *testing.T) { target, err := getWalletForName(t, configPath, targetWallet) require.Nil(t, err, "Error occurred when retrieving target wallet") - wantFailureMsg := `Send tokens failed. submit transaction failed. {"error":"insufficient balance to send"}` + wantFailureMsg := `Send tokens failed. submit transaction failed: {"error":"insufficient balance to send"}` output, err := sendZCN(t, configPath, target.ClientID, "1", "", createParams(map[string]interface{}{}), false) require.NotNil(t, err, "Expected send to fail", strings.Join(output, "\n")) @@ -143,7 +140,7 @@ func TestSendAndBalance(testSetup *testing.T) { createWallet(t) invalidClientID := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb" // more than 64 chars - wantFailureMsg := "Send tokens failed. submit transaction failed. {\"error\":\"invalid to client id\"}" + wantFailureMsg := "Send tokens failed. submit transaction failed: {\"error\":\"invalid to client id\"}" output, err := sendZCN(t, configPath, invalidClientID, "1", "", createParams(map[string]interface{}{}), false) require.NotNil(t, err, "Expected send to fail", strings.Join(output, "\n")) @@ -183,7 +180,7 @@ func TestSendAndBalance(testSetup *testing.T) { target, err := getWalletForName(t, configPath, targetWallet) require.Nil(t, err, "Error occurred when retrieving target wallet") - wantFailureMsg := `Send tokens failed. submit transaction failed. {"error":"insufficient balance to send"}` + wantFailureMsg := `Send tokens failed. submit transaction failed: {"error":"insufficient balance to send"}` tokens := strconv.Itoa(int(balance) + 1) output, err := sendZCN(t, configPath, target.ClientID, tokens, "", createParams(map[string]interface{}{}), false) @@ -228,7 +225,7 @@ func TestSendAndBalance(testSetup *testing.T) { } longDesc := string(b) - wantFailureMsg := "Send tokens failed. submit transaction failed. {\"code\":\"txn_exceed_max_payload\"," + + wantFailureMsg := "Send tokens failed. submit transaction failed: {\"code\":\"txn_exceed_max_payload\"," + "\"error\":\"txn_exceed_max_payload: transaction payload exceeds the max payload (98304)\"}" output, err := sendZCN(t, configPath, target.ClientID, "1", longDesc, createParams(map[string]interface{}{}), false) @@ -244,7 +241,7 @@ func TestSendAndBalance(testSetup *testing.T) { wallet, err := getWallet(t, configPath) require.Nil(t, err, "Get wallet failed") - wantFailureMsg := "Send tokens failed. submit transaction failed. {\"code\":\"invalid_request\"," + + wantFailureMsg := "Send tokens failed. submit transaction failed: {\"code\":\"invalid_request\"," + "\"error\":\"invalid_request: Invalid request (from and to client should be different)\"}" output, err := sendZCN(t, configPath, wallet.ClientID, "1", "", createParams(map[string]interface{}{}), false) 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..1046743c3d 100644 --- a/tests/tokenomics_tests/blobber_read_test.go +++ b/tests/tokenomics_tests/blobber_read_test.go @@ -20,6 +20,7 @@ import ( func TestBlobberReadReward(testSetup *testing.T) { t := test.NewSystemTest(testSetup) + t.Skip() t.TestSetup("set storage config to use time_unit as 5 minutes", func() { output, err := utils.UpdateStorageSCConfig(t, scOwnerWallet, map[string]string{ @@ -78,7 +79,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 +149,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 f3fe460786..37a48de554 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 8af8233b46..fb752d102e 100644 --- a/tests/tokenomics_tests/utils/allocation.go +++ b/tests/tokenomics_tests/utils/allocation.go @@ -1,10 +1,12 @@ package utils import ( + "context" "crypto/rand" "encoding/json" "errors" "fmt" + coreClient "github.com/0chain/gosdk/core/client" "io" "os" "regexp" @@ -14,8 +16,6 @@ import ( "github.com/0chain/gosdk/core/conf" "github.com/0chain/gosdk/zboxcore/sdk" - "github.com/0chain/gosdk/zcncore" - "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" @@ -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...) } @@ -379,22 +326,17 @@ func InitSDK(wallet, configFile string) error { return err } - marshal, err := json.Marshal(parsed) - if err != nil { - return err - } - err = zcncore.Init(string(marshal)) + err = coreClient.Init(context.Background(), parsed) if err != nil { return err } - err = sdk.InitStorageSDK( + err = coreClient.InitSDK( walletJSON, parsed.BlockWorker, parsed.ChainID, parsed.SignatureScheme, - nil, - 0, + 0, false, true, ) return err } 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)