Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated: added test cases for storage version #1135

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cdc92fd
updated: added test cases for storage version
Akhilesh53 Oct 7, 2024
b1881ce
updated: resolved comments
Akhilesh53 Oct 8, 2024
4cc270e
updated: added mofied code
Akhilesh53 Oct 10, 2024
42e1fee
updated: added allocagion test
Akhilesh53 Oct 10, 2024
4d5ad54
updated:
Akhilesh53 Oct 10, 2024
0d399a3
updated:
Akhilesh53 Oct 11, 2024
3cec9c1
updated: removed managing wallet from allocation tc
Akhilesh53 Oct 11, 2024
871a7f0
updated: added update blobber version in api test
Akhilesh53 Oct 11, 2024
92bd6ea
updated:modified code
Akhilesh53 Oct 12, 2024
7691d81
updated: added kill blobber
Akhilesh53 Oct 12, 2024
3c4cb39
updated: added kill blobber
Akhilesh53 Oct 13, 2024
4958aa4
updated: added kill blobber
Akhilesh53 Oct 13, 2024
b412308
updated: added kill blobber tc
Akhilesh53 Oct 13, 2024
cff0464
updated: resolved comments
Akhilesh53 Oct 14, 2024
d11974c
updated: modified register blobber func for id verification
Akhilesh53 Oct 14, 2024
fef2d7a
updated: reveretd create wallet
Akhilesh53 Oct 14, 2024
988b4f0
updated: modified register blobber
Akhilesh53 Oct 14, 2024
8e3afa3
updated: default storage version to 1
Akhilesh53 Oct 14, 2024
5a11ec9
updated: added get blobber to verify
Akhilesh53 Oct 14, 2024
c1e4152
updated: urls reverted
Akhilesh53 Oct 14, 2024
330fc7e
updated:
Akhilesh53 Oct 14, 2024
59d991a
updated: comments resolved
Akhilesh53 Oct 15, 2024
6b8a708
updated: comments resolved
Akhilesh53 Oct 15, 2024
809f315
updated: comments resolved
Akhilesh53 Oct 15, 2024
e642a73
lint fix
smaulik13 Dec 18, 2024
dabc24b
sys_test
smaulik13 Dec 18, 2024
8ab38f1
go update
smaulik13 Dec 18, 2024
5c193a7
lint fix
smaulik13 Dec 18, 2024
1858d43
lint fix
smaulik13 Dec 18, 2024
3643f92
uncomment
smaulik13 Dec 19, 2024
6d44a41
fixeS
smaulik13 Dec 23, 2024
2da427e
expire alloc test fix
smaulik13 Jan 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.18.13-0.20241209154844-07366a2c2666
github.com/0chain/gosdk v1.18.14
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
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.18.13-0.20241209154844-07366a2c2666 h1:xnvnaDeuMFadWR4bM0iiXm7CArjt8V9aBsdx3xcevDs=
github.com/0chain/gosdk v1.18.13-0.20241209154844-07366a2c2666/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
github.com/0chain/gosdk v1.18.14 h1:N/PwLmUVQe1qM0eDuEDSQRB97a03Fp+I5W67cF0Zgsw=
github.com/0chain/gosdk v1.18.14/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
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=
Expand Down
18 changes: 18 additions & 0 deletions internal/api/model/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ func NewRegisterBlobberTransactionData(scRegisterBlobberRequest *StorageNode) Tr
}
}

func NewKillBlobberTransactionData(killBlobberRequest *KillBlobberRequest) TransactionData {
return TransactionData{
Name: "kill_blobber",
Input: *killBlobberRequest,
}
}

func NewCreateFreeAllocationTransactionData(scRestGetFreeAllocationBlobbersResponse *SCRestGetFreeAllocationBlobbersResponse) TransactionData {
return TransactionData{
Name: "free_allocation_request",
Expand Down Expand Up @@ -507,6 +514,7 @@ type BlobberRequirements struct {
ExpirationDate int64 `json:"expiration_date"`
ReadPriceRange PriceRange `json:"read_price_range"`
WritePriceRange PriceRange `json:"write_price_range"`
StorageVersion int64 `json:"storage_version"`
}

type PriceRange struct {
Expand Down Expand Up @@ -630,6 +638,10 @@ type SCRestGetBlobberResponse struct {
ReadData int64 `json:"read_data"`
ChallengesPassed int64 `json:"challenges_passed"`
ChallengesCompleted int64 `json:"challenges_completed"`

//todo:
StorageVersion int64 `json:"storage_version"`
ManagingWallet string `json:"managing_wallet"`
}

type SCRestGetBlobbersResponse struct {
Expand Down Expand Up @@ -670,6 +682,10 @@ type FreeAllocationRequest struct {
Marker string `json:"marker,omitempty"`
}

type KillBlobberRequest struct {
ProviderID string `json:"provider_id,omitempty"`
}

type SCRestGetAllocationResponse struct {
ID string `json:"id"`
Tx string `json:"tx"`
Expand Down Expand Up @@ -712,6 +728,8 @@ type StorageNode struct {
LastHealthCheck int64 `json:"last_health_check"`
PublicKey string `json:"-"`
StakePoolSettings StakePoolSettings `json:"stake_pool_settings"`
StorageVersion int64 `json:"storage_version"`
ManagingWallet string `json:"managing_wallet"`
}

type StorageNodeGeolocation struct {
Expand Down
1 change: 1 addition & 0 deletions internal/api/model/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ func DefaultBlobberRequirements(id, publicKey string) BlobberRequirements {
},
OwnerId: id,
OwnerPublicKey: publicKey,
StorageVersion: 1,
}
}
68 changes: 67 additions & 1 deletion internal/api/util/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,8 @@ func (c *APIClient) RegisterBlobber(t *test.SystemTest,
wallet *model.Wallet,
storageNode *model.StorageNode,
requiredTransactionStatus int,
expectedResponse string) string {
expectedResponse string,
requireIdVerification bool) string {
t.Log("Registering blobber...")

registerBlobberTransactionPutResponse, resp, err := c.V1TransactionPut(
Expand Down Expand Up @@ -954,6 +955,19 @@ func (c *APIClient) RegisterBlobber(t *test.SystemTest,
return false
}

if requireIdVerification {
var storageNode model.StorageNode

// Unmarshal the JSON string into the StorageNode struct
err := json.Unmarshal([]byte(registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput), &storageNode)
if err != nil {
t.Log("Error unmarshalling JSON:", err)
return false
}

return registerBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus && storageNode.ID == expectedResponse
}

return registerBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus && registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput == expectedResponse
})

Expand All @@ -962,6 +976,58 @@ func (c *APIClient) RegisterBlobber(t *test.SystemTest,
return registerBlobberTransactionPutResponse.Entity.Hash
}

func (c *APIClient) KillBlobber(t *test.SystemTest,
wallet *model.Wallet,
killBlobberRequest *model.KillBlobberRequest,
requiredTransactionStatus int) string {
t.Log("Killing blobber...")

killBlobberTransactionPutResponse, resp, err := c.V1TransactionPut(
t,
model.InternalTransactionPutRequest{
Wallet: wallet,
ToClientID: StorageSmartContractAddress,
TransactionData: model.NewKillBlobberTransactionData(killBlobberRequest),
Value: tokenomics.IntToZCN(0),
TxnType: SCTxType,
},
HttpOkStatus)
require.Nil(t, err)
require.NotNil(t, resp)
require.NotNil(t, killBlobberTransactionPutResponse)

var killBlobberTransactionGetConfirmationResponse *model.TransactionGetConfirmationResponse

wait.PoolImmediately(t, time.Minute*2, func() bool {
killBlobberTransactionGetConfirmationResponse, resp, err = c.V1TransactionGetConfirmation(
t,
model.TransactionGetConfirmationRequest{
Hash: killBlobberTransactionPutResponse.Entity.Hash,
},
HttpOkStatus)

if err != nil {
t.Log("Error killing blobber : ", err)
return false
}

if resp == nil {
fmt.Println("got nil response : ", resp)
return false
}

if killBlobberTransactionGetConfirmationResponse == nil {
fmt.Println("got nil txn confirmation response : ", killBlobberTransactionGetConfirmationResponse)
return false
}

return killBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus
})

wallet.IncNonce()
return killBlobberTransactionPutResponse.Entity.Hash
}

func (c *APIClient) CreateFreeAllocation(t *test.SystemTest,
wallet *model.Wallet,
scRestGetFreeAllocationBlobbersResponse *model.SCRestGetFreeAllocationBlobbersResponse,
Expand Down
7 changes: 1 addition & 6 deletions internal/cli/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ type Terms struct {
WritePrice int64 `json:"write_price"`
}

type Settings struct {
Delegate_wallet string `json:"delegate_wallet"`
Num_delegates int `json:"num_delegates"`
Service_charge float64 `json:"service_charge"`
}

type BlobberInfo struct {
Id string `json:"id"`
Url string `json:"url"`
Expand Down Expand Up @@ -380,6 +374,7 @@ type BlobberDetails struct {
IsShutdown bool `json:"is_shutdown"`
IsRestricted bool `json:"is_restricted"`
NotAvailable bool `json:"not_available"`
StorageVersion int64 `json:"storage_version"`
}

type Validator struct {
Expand Down
13 changes: 13 additions & 0 deletions tests/api_tests/config/sc_owner_wallet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"client_id": "1746b06bb09f55ee01b33b5e2e055d6cc7a900cb57c0a3a5eaabb8a0e7745802",
"client_key": "7b630ba670dac2f22d43c2399b70eff378689a53ee03ea20957bb7e73df016200fea410ba5102558b0c39617e5afd2c1843b161a1dedec15e1ab40543a78a518",
"keys": [
{
"public_key": "7b630ba670dac2f22d43c2399b70eff378689a53ee03ea20957bb7e73df016200fea410ba5102558b0c39617e5afd2c1843b161a1dedec15e1ab40543a78a518",
"private_key": "c06b6f6945ba02d5a3be86b8779deca63bb636ce7e46804a479c50e53c864915"
}
],
"mnemonics": "cactus panther essence ability copper fox wise actual need cousin boat uncover ride diamond group jacket anchor current float rely tragic omit child payment",
"version": "1.0",
"date_created": "2023-11-26T01:23:58Z"
}
39 changes: 39 additions & 0 deletions tests/api_tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,45 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func initialiseSCWallet() *model.Wallet {
// read the file sc_owner_wallet.json
fileContent, err := os.ReadFile("./config/sc_owner_wallet.json")
if err != nil {
log.Println("Error reading file:", err)
return nil
}

fileWallet := WalletFile{}

// Parse the JSON data into a list of strings
err = json.Unmarshal(fileContent, &fileWallet)

if err != nil {
log.Println("Error decoding JSON:", err)
return nil
}

wallet := &model.Wallet{
Id: fileWallet.ClientId,
Version: fileWallet.Version,
PublicKey: fileWallet.Keys[0].PublicKey,
Nonce: 0,
Keys: &model.KeyPair{},
Mnemonics: fileWallet.Mnemonics,
}

err = wallet.Keys.PublicKey.DeserializeHexStr(fileWallet.Keys[0].PublicKey)
if err != nil {
log.Println("Error decoding JSON:", err)
}
err = wallet.Keys.PrivateKey.DeserializeHexStr(fileWallet.Keys[0].PrivateKey)
if err != nil {
log.Println("Error decoding JSON:", err)
}

return wallet
}

type WalletFile struct {
ClientId string `json:"client_id"`
ClientKey string `json:"client_key"`
Expand Down
54 changes: 49 additions & 5 deletions tests/api_tests/register_blobber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ func TestRegisterBlobber(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.Parallel()

// write a test case to register a blobber with storage version
t.Run("Register blobber with storage version", func(t *test.SystemTest) {
wallet := createWallet(t)

defer killBlobber(t, wallet.Id)

walletBalance := apiClient.GetWalletBalance(t, wallet, client.HttpOkStatus)
t.Logf("wallet balance: %v", wallet)
wallet.Nonce = int(walletBalance.Nonce)

sn := &model.StorageNode{}

sn.ID = uuid.New().String()
sn.BaseURL = generateRandomURL()

sn.Capacity = 10240 * GB
sn.Terms.ReadPrice = 1000000000
sn.Terms.WritePrice = 1000000000

sn.StakePoolSettings.DelegateWallet = "config.Configuration.DelegateWallet"
sn.StakePoolSettings.NumDelegates = 2
sn.StakePoolSettings.ServiceCharge = 0.2

//todo: make check to this
sn.StorageVersion = 2
sn.ManagingWallet = wallet.Id

apiClient.RegisterBlobber(t, wallet, sn, 1, wallet.Id, true)
})

t.Run("Write price lower than min_write_price should not allow register", func(t *test.SystemTest) {
wallet := createWallet(t)

Expand All @@ -36,7 +66,7 @@ func TestRegisterBlobber(testSetup *testing.T) {
sn.StakePoolSettings.NumDelegates = 2
sn.StakePoolSettings.ServiceCharge = 0.2

apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: write_price is less than min_write_price allowed")
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: write_price is less than min_write_price allowed", false)
})

t.Run("Write price higher than max_write_price should not allow register", func(t *test.SystemTest) {
Expand All @@ -58,7 +88,7 @@ func TestRegisterBlobber(testSetup *testing.T) {
sn.StakePoolSettings.NumDelegates = 2
sn.StakePoolSettings.ServiceCharge = 0.2

apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: write_price is greater than max_write_price allowed")
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: write_price is greater than max_write_price allowed", false)
})

t.Run("Read price higher than max_read_price should not allow register", func(t *test.SystemTest) {
Expand All @@ -80,7 +110,7 @@ func TestRegisterBlobber(testSetup *testing.T) {
sn.StakePoolSettings.NumDelegates = 2
sn.StakePoolSettings.ServiceCharge = 0.2

apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: read_price is greater than max_read_price allowed")
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: read_price is greater than max_read_price allowed", false)
})

t.Run("Service charge higher than max_service_charge should not allow register", func(t *test.SystemTest) {
Expand All @@ -102,7 +132,7 @@ func TestRegisterBlobber(testSetup *testing.T) {
sn.StakePoolSettings.NumDelegates = 2
sn.StakePoolSettings.ServiceCharge = 0.6

apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: creating stake pool: invalid stake_pool settings: service_charge (0.600000) is greater than max allowed by SC (0.500000)")
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: creating stake pool: invalid stake_pool settings: service_charge (0.600000) is greater than max allowed by SC (0.500000)", false)
})

t.Run("Capacity lower than min_blobber_capacity should not allow register", func(t *test.SystemTest) {
Expand All @@ -124,7 +154,7 @@ func TestRegisterBlobber(testSetup *testing.T) {
sn.StakePoolSettings.NumDelegates = 2
sn.StakePoolSettings.ServiceCharge = 0.2

apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: insufficient blobber capacity")
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: insufficient blobber capacity", false)
})
}

Expand All @@ -145,3 +175,17 @@ func generateRandomString(length int) string {
func generateRandomURL() string {
return fmt.Sprintf("http://%s.com/%s", generateRandomString(10), generateRandomString(8))
}

func killBlobber(t *test.SystemTest, providerId string) {
var killBlobberReq = &model.KillBlobberRequest{
ProviderID: providerId,
}

scWallet := initialiseSCWallet()

// get wallet balance
walletBalance := apiClient.GetWalletBalance(t, scWallet, client.HttpOkStatus)
scWallet.Nonce = int(walletBalance.Nonce)

apiClient.KillBlobber(t, scWallet, killBlobberReq, 1)
}
Loading
Loading