Skip to content

Commit 9e2cc4e

Browse files
smaulik13Akhilesh53Jayashsatolia403
authored
updated: added test cases for storage version (#1135)
* updated: added test cases for storage version * updated: resolved comments * updated: added mofied code * updated: added allocagion test * updated: * updated: * updated: removed managing wallet from allocation tc * updated: added update blobber version in api test * updated:modified code * updated: added kill blobber * updated: added kill blobber * updated: added kill blobber * updated: added kill blobber tc * updated: resolved comments * updated: modified register blobber func for id verification * updated: reveretd create wallet * updated: modified register blobber * updated: default storage version to 1 * updated: added get blobber to verify * updated: urls reverted * updated: * updated: comments resolved * updated: comments resolved * updated: comments resolved * lint fix * sys_test * go update * lint fix * lint fix * uncomment * fixeS * expire alloc test fix --------- Co-authored-by: Akhilesh Mahajan <[email protected]> Co-authored-by: Jayash Satolia <[email protected]>
1 parent 2c65a8f commit 9e2cc4e

15 files changed

+328
-20
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22.0
44

55
require (
66
github.com/0chain/errors v1.0.3
7-
github.com/0chain/gosdk v1.18.13-0.20241209154844-07366a2c2666
7+
github.com/0chain/gosdk v1.18.14
88
github.com/go-resty/resty/v2 v2.7.0
99
github.com/herumi/bls-go-binary v1.31.0
1010
github.com/shopspring/decimal v1.3.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
4040
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
4141
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
4242
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
43-
github.com/0chain/gosdk v1.18.13-0.20241209154844-07366a2c2666 h1:xnvnaDeuMFadWR4bM0iiXm7CArjt8V9aBsdx3xcevDs=
44-
github.com/0chain/gosdk v1.18.13-0.20241209154844-07366a2c2666/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
43+
github.com/0chain/gosdk v1.18.14 h1:N/PwLmUVQe1qM0eDuEDSQRB97a03Fp+I5W67cF0Zgsw=
44+
github.com/0chain/gosdk v1.18.14/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
4545
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4646
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
4747
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=

internal/api/model/api.go

+18
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ func NewRegisterBlobberTransactionData(scRegisterBlobberRequest *StorageNode) Tr
176176
}
177177
}
178178

179+
func NewKillBlobberTransactionData(killBlobberRequest *KillBlobberRequest) TransactionData {
180+
return TransactionData{
181+
Name: "kill_blobber",
182+
Input: *killBlobberRequest,
183+
}
184+
}
185+
179186
func NewCreateFreeAllocationTransactionData(scRestGetFreeAllocationBlobbersResponse *SCRestGetFreeAllocationBlobbersResponse) TransactionData {
180187
return TransactionData{
181188
Name: "free_allocation_request",
@@ -507,6 +514,7 @@ type BlobberRequirements struct {
507514
ExpirationDate int64 `json:"expiration_date"`
508515
ReadPriceRange PriceRange `json:"read_price_range"`
509516
WritePriceRange PriceRange `json:"write_price_range"`
517+
StorageVersion int64 `json:"storage_version"`
510518
}
511519

512520
type PriceRange struct {
@@ -630,6 +638,10 @@ type SCRestGetBlobberResponse struct {
630638
ReadData int64 `json:"read_data"`
631639
ChallengesPassed int64 `json:"challenges_passed"`
632640
ChallengesCompleted int64 `json:"challenges_completed"`
641+
642+
//todo:
643+
StorageVersion int64 `json:"storage_version"`
644+
ManagingWallet string `json:"managing_wallet"`
633645
}
634646

635647
type SCRestGetBlobbersResponse struct {
@@ -670,6 +682,10 @@ type FreeAllocationRequest struct {
670682
Marker string `json:"marker,omitempty"`
671683
}
672684

685+
type KillBlobberRequest struct {
686+
ProviderID string `json:"provider_id,omitempty"`
687+
}
688+
673689
type SCRestGetAllocationResponse struct {
674690
ID string `json:"id"`
675691
Tx string `json:"tx"`
@@ -712,6 +728,8 @@ type StorageNode struct {
712728
LastHealthCheck int64 `json:"last_health_check"`
713729
PublicKey string `json:"-"`
714730
StakePoolSettings StakePoolSettings `json:"stake_pool_settings"`
731+
StorageVersion int64 `json:"storage_version"`
732+
ManagingWallet string `json:"managing_wallet"`
715733
}
716734

717735
type StorageNodeGeolocation struct {

internal/api/model/helper.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func DefaultBlobberRequirements(id, publicKey string) BlobberRequirements {
1818
},
1919
OwnerId: id,
2020
OwnerPublicKey: publicKey,
21+
StorageVersion: 1,
2122
}
2223
}

internal/api/util/client/api_client.go

+67-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,8 @@ func (c *APIClient) RegisterBlobber(t *test.SystemTest,
914914
wallet *model.Wallet,
915915
storageNode *model.StorageNode,
916916
requiredTransactionStatus int,
917-
expectedResponse string) string {
917+
expectedResponse string,
918+
requireIdVerification bool) string {
918919
t.Log("Registering blobber...")
919920

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

958+
if requireIdVerification {
959+
var storageNode model.StorageNode
960+
961+
// Unmarshal the JSON string into the StorageNode struct
962+
err := json.Unmarshal([]byte(registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput), &storageNode)
963+
if err != nil {
964+
t.Log("Error unmarshalling JSON:", err)
965+
return false
966+
}
967+
968+
return registerBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus && storageNode.ID == expectedResponse
969+
}
970+
957971
return registerBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus && registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput == expectedResponse
958972
})
959973

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

979+
func (c *APIClient) KillBlobber(t *test.SystemTest,
980+
wallet *model.Wallet,
981+
killBlobberRequest *model.KillBlobberRequest,
982+
requiredTransactionStatus int) string {
983+
t.Log("Killing blobber...")
984+
985+
killBlobberTransactionPutResponse, resp, err := c.V1TransactionPut(
986+
t,
987+
model.InternalTransactionPutRequest{
988+
Wallet: wallet,
989+
ToClientID: StorageSmartContractAddress,
990+
TransactionData: model.NewKillBlobberTransactionData(killBlobberRequest),
991+
Value: tokenomics.IntToZCN(0),
992+
TxnType: SCTxType,
993+
},
994+
HttpOkStatus)
995+
require.Nil(t, err)
996+
require.NotNil(t, resp)
997+
require.NotNil(t, killBlobberTransactionPutResponse)
998+
999+
var killBlobberTransactionGetConfirmationResponse *model.TransactionGetConfirmationResponse
1000+
1001+
wait.PoolImmediately(t, time.Minute*2, func() bool {
1002+
killBlobberTransactionGetConfirmationResponse, resp, err = c.V1TransactionGetConfirmation(
1003+
t,
1004+
model.TransactionGetConfirmationRequest{
1005+
Hash: killBlobberTransactionPutResponse.Entity.Hash,
1006+
},
1007+
HttpOkStatus)
1008+
1009+
if err != nil {
1010+
t.Log("Error killing blobber : ", err)
1011+
return false
1012+
}
1013+
1014+
if resp == nil {
1015+
fmt.Println("got nil response : ", resp)
1016+
return false
1017+
}
1018+
1019+
if killBlobberTransactionGetConfirmationResponse == nil {
1020+
fmt.Println("got nil txn confirmation response : ", killBlobberTransactionGetConfirmationResponse)
1021+
return false
1022+
}
1023+
1024+
return killBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus
1025+
})
1026+
1027+
wallet.IncNonce()
1028+
return killBlobberTransactionPutResponse.Entity.Hash
1029+
}
1030+
9651031
func (c *APIClient) CreateFreeAllocation(t *test.SystemTest,
9661032
wallet *model.Wallet,
9671033
scRestGetFreeAllocationBlobbersResponse *model.SCRestGetFreeAllocationBlobbersResponse,

internal/cli/model/model.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ type Terms struct {
158158
WritePrice int64 `json:"write_price"`
159159
}
160160

161-
type Settings struct {
162-
Delegate_wallet string `json:"delegate_wallet"`
163-
Num_delegates int `json:"num_delegates"`
164-
Service_charge float64 `json:"service_charge"`
165-
}
166-
167161
type BlobberInfo struct {
168162
Id string `json:"id"`
169163
Url string `json:"url"`
@@ -380,6 +374,7 @@ type BlobberDetails struct {
380374
IsShutdown bool `json:"is_shutdown"`
381375
IsRestricted bool `json:"is_restricted"`
382376
NotAvailable bool `json:"not_available"`
377+
StorageVersion int64 `json:"storage_version"`
383378
}
384379

385380
type Validator struct {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"client_id": "1746b06bb09f55ee01b33b5e2e055d6cc7a900cb57c0a3a5eaabb8a0e7745802",
3+
"client_key": "7b630ba670dac2f22d43c2399b70eff378689a53ee03ea20957bb7e73df016200fea410ba5102558b0c39617e5afd2c1843b161a1dedec15e1ab40543a78a518",
4+
"keys": [
5+
{
6+
"public_key": "7b630ba670dac2f22d43c2399b70eff378689a53ee03ea20957bb7e73df016200fea410ba5102558b0c39617e5afd2c1843b161a1dedec15e1ab40543a78a518",
7+
"private_key": "c06b6f6945ba02d5a3be86b8779deca63bb636ce7e46804a479c50e53c864915"
8+
}
9+
],
10+
"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",
11+
"version": "1.0",
12+
"date_created": "2023-11-26T01:23:58Z"
13+
}

tests/api_tests/main_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,45 @@ func TestMain(m *testing.M) {
130130
os.Exit(m.Run())
131131
}
132132

133+
func initialiseSCWallet() *model.Wallet {
134+
// read the file sc_owner_wallet.json
135+
fileContent, err := os.ReadFile("./config/sc_owner_wallet.json")
136+
if err != nil {
137+
log.Println("Error reading file:", err)
138+
return nil
139+
}
140+
141+
fileWallet := WalletFile{}
142+
143+
// Parse the JSON data into a list of strings
144+
err = json.Unmarshal(fileContent, &fileWallet)
145+
146+
if err != nil {
147+
log.Println("Error decoding JSON:", err)
148+
return nil
149+
}
150+
151+
wallet := &model.Wallet{
152+
Id: fileWallet.ClientId,
153+
Version: fileWallet.Version,
154+
PublicKey: fileWallet.Keys[0].PublicKey,
155+
Nonce: 0,
156+
Keys: &model.KeyPair{},
157+
Mnemonics: fileWallet.Mnemonics,
158+
}
159+
160+
err = wallet.Keys.PublicKey.DeserializeHexStr(fileWallet.Keys[0].PublicKey)
161+
if err != nil {
162+
log.Println("Error decoding JSON:", err)
163+
}
164+
err = wallet.Keys.PrivateKey.DeserializeHexStr(fileWallet.Keys[0].PrivateKey)
165+
if err != nil {
166+
log.Println("Error decoding JSON:", err)
167+
}
168+
169+
return wallet
170+
}
171+
133172
type WalletFile struct {
134173
ClientId string `json:"client_id"`
135174
ClientKey string `json:"client_key"`

tests/api_tests/register_blobber_test.go

+49-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ func TestRegisterBlobber(testSetup *testing.T) {
1717
t := test.NewSystemTest(testSetup)
1818
t.Parallel()
1919

20+
// write a test case to register a blobber with storage version
21+
t.Run("Register blobber with storage version", func(t *test.SystemTest) {
22+
wallet := createWallet(t)
23+
24+
defer killBlobber(t, wallet.Id)
25+
26+
walletBalance := apiClient.GetWalletBalance(t, wallet, client.HttpOkStatus)
27+
t.Logf("wallet balance: %v", wallet)
28+
wallet.Nonce = int(walletBalance.Nonce)
29+
30+
sn := &model.StorageNode{}
31+
32+
sn.ID = uuid.New().String()
33+
sn.BaseURL = generateRandomURL()
34+
35+
sn.Capacity = 10240 * GB
36+
sn.Terms.ReadPrice = 1000000000
37+
sn.Terms.WritePrice = 1000000000
38+
39+
sn.StakePoolSettings.DelegateWallet = "config.Configuration.DelegateWallet"
40+
sn.StakePoolSettings.NumDelegates = 2
41+
sn.StakePoolSettings.ServiceCharge = 0.2
42+
43+
//todo: make check to this
44+
sn.StorageVersion = 2
45+
sn.ManagingWallet = wallet.Id
46+
47+
apiClient.RegisterBlobber(t, wallet, sn, 1, wallet.Id, true)
48+
})
49+
2050
t.Run("Write price lower than min_write_price should not allow register", func(t *test.SystemTest) {
2151
wallet := createWallet(t)
2252

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

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

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

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

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

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

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

105-
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)")
135+
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)
106136
})
107137

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

127-
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: insufficient blobber capacity")
157+
apiClient.RegisterBlobber(t, wallet, sn, 2, "add_or_update_blobber_failed: invalid blobber params: insufficient blobber capacity", false)
128158
})
129159
}
130160

@@ -145,3 +175,17 @@ func generateRandomString(length int) string {
145175
func generateRandomURL() string {
146176
return fmt.Sprintf("http://%s.com/%s", generateRandomString(10), generateRandomString(8))
147177
}
178+
179+
func killBlobber(t *test.SystemTest, providerId string) {
180+
var killBlobberReq = &model.KillBlobberRequest{
181+
ProviderID: providerId,
182+
}
183+
184+
scWallet := initialiseSCWallet()
185+
186+
// get wallet balance
187+
walletBalance := apiClient.GetWalletBalance(t, scWallet, client.HttpOkStatus)
188+
scWallet.Nonce = int(walletBalance.Nonce)
189+
190+
apiClient.KillBlobber(t, scWallet, killBlobberReq, 1)
191+
}

0 commit comments

Comments
 (0)