Skip to content

Commit 05d76d0

Browse files
Saswata BasuSaswata Basu
authored andcommitted
ST changes
1 parent 56552bf commit 05d76d0

21 files changed

+405
-120
lines changed

internal/api/util/client/api_client.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,16 +956,54 @@ func (c *APIClient) RegisterBlobber(t *test.SystemTest,
956956
}
957957

958958
if requireIdVerification {
959-
var storageNode model.StorageNode
959+
// First check if transaction status matches
960+
if registerBlobberTransactionGetConfirmationResponse.Status != requiredTransactionStatus {
961+
t.Logf("Transaction status doesn't match. Expected: %d, Actual: %d, Output: %s",
962+
requiredTransactionStatus, registerBlobberTransactionGetConfirmationResponse.Status,
963+
registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput)
964+
return false
965+
}
960966

967+
// Only try to unmarshal if transaction is successful
968+
transactionOutput := registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput
969+
970+
// Check if output is empty or not valid JSON
971+
if transactionOutput == "" {
972+
t.Log("Transaction output is empty, waiting for confirmation...")
973+
return false
974+
}
975+
976+
// Check if output looks like JSON (starts with '{')
977+
trimmedOutput := strings.TrimSpace(transactionOutput)
978+
if !strings.HasPrefix(trimmedOutput, "{") {
979+
preview := trimmedOutput
980+
if len(preview) > 50 {
981+
preview = preview[:50] + "..."
982+
}
983+
t.Logf("Transaction output is not JSON (starts with: %s), waiting for confirmation...", preview)
984+
return false
985+
}
986+
987+
var storageNode model.StorageNode
961988
// Unmarshal the JSON string into the StorageNode struct
962-
err := json.Unmarshal([]byte(registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput), &storageNode)
989+
err := json.Unmarshal([]byte(transactionOutput), &storageNode)
963990
if err != nil {
964-
t.Log("Error unmarshalling JSON:", err)
991+
t.Logf("Error unmarshalling JSON: %v. Output: %s", err, transactionOutput)
965992
return false
966993
}
967994

968-
return registerBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus && storageNode.ID == expectedResponse
995+
// Verify the ManagingWallet matches (for storage version 2+ blobbers)
996+
// or the ID matches (for legacy blobbers)
997+
if storageNode.ManagingWallet != "" && storageNode.ManagingWallet == expectedResponse {
998+
return true
999+
}
1000+
if storageNode.ID == expectedResponse {
1001+
return true
1002+
}
1003+
1004+
t.Logf("StorageNode verification failed. Expected: %s, Actual ID: %s, Actual ManagingWallet: %s",
1005+
expectedResponse, storageNode.ID, storageNode.ManagingWallet)
1006+
return false
9691007
}
9701008

9711009
// Log the actual status and output for debugging

tests/api_tests/0box_aggregate_endpoints_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,16 @@ func Test0boxGraphAndTotalEndpoints(testSetup *testing.T) {
660660

661661
t.Log("Blobber : ", blobberOwnerWallet.Id)
662662

663+
// Ensure blobberOwnerWallet has sufficient balance and updated nonce
664+
blobberOwnerBalance := apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
665+
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
666+
require.GreaterOrEqual(t, blobberOwnerBalance.Balance, int64(200000000), "blobberOwnerWallet must have at least 0.2 ZCN to pay for update transactions (0.1 ZCN value + fees)")
663667
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[0], client.TxSuccessfulStatus)
668+
669+
// Update nonce before second update
670+
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
671+
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
672+
require.GreaterOrEqual(t, blobberOwnerBalance.Balance, int64(200000000), "blobberOwnerWallet must have at least 0.2 ZCN to pay for update transactions (0.1 ZCN value + fees)")
664673
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[1], client.TxSuccessfulStatus)
665674

666675
wait.PoolImmediately(t, 2*time.Minute, func() bool {
@@ -684,14 +693,24 @@ func Test0boxGraphAndTotalEndpoints(testSetup *testing.T) {
684693
require.Equal(t, 200, resp.StatusCode())
685694

686695
diff := priceAfterStaking - expectedAWP
687-
t.Logf("priceBeforeStaking: %d, priceAfterStaking: %d, expectedAWP: %d, diff: %d", priceBeforeStaking, priceAfterStaking, expectedAWP, diff)
688-
return priceAfterStaking != priceBeforeStaking && diff >= -roundingError && diff <= roundingError && priceAfterStaking == int64(*latest)
696+
latestDiff := priceAfterStaking - int64(*latest)
697+
t.Logf("priceBeforeStaking: %d, priceAfterStaking: %d, expectedAWP: %d, diff: %d, latest: %d, latestDiff: %d", priceBeforeStaking, priceAfterStaking, expectedAWP, diff, int64(*latest), latestDiff)
698+
// Allow tolerance for both expectedAWP and latest value due to timing differences in graph updates
699+
return priceAfterStaking != priceBeforeStaking && diff >= -roundingError && diff <= roundingError && latestDiff >= -roundingError && latestDiff <= roundingError
689700
})
690701

691702
// Cleanup: Revert write price to 0.1
692703
targetBlobbers[0].Terms.WritePrice = *tokenomics.IntToZCN(0.1)
693704
targetBlobbers[1].Terms.WritePrice = *tokenomics.IntToZCN(0.1)
705+
// Update nonce before first cleanup update
706+
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
707+
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
708+
require.GreaterOrEqual(t, blobberOwnerBalance.Balance, int64(200000000), "blobberOwnerWallet must have at least 0.2 ZCN to pay for update transactions (0.1 ZCN value + fees)")
694709
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[0], client.TxSuccessfulStatus)
710+
// Update nonce before second cleanup update
711+
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
712+
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
713+
require.GreaterOrEqual(t, blobberOwnerBalance.Balance, int64(200000000), "blobberOwnerWallet must have at least 0.2 ZCN to pay for update transactions (0.1 ZCN value + fees)")
695714
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[1], client.TxSuccessfulStatus)
696715
})
697716

tests/api_tests/0box_allocation_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
6161
err := Create0boxTestWallet(t, headers)
6262
require.NoError(t, err)
6363

64+
// Refresh CSRF token after wallet creation to ensure it's valid
65+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
66+
6467
allocationList, response, err := zboxClient.ListAllocation(t, headers)
6568
require.NoError(t, err)
6669
require.Equal(t, 200, response.StatusCode(), "Response status code does not match expected. Output: [%v]", response.String())
@@ -74,6 +77,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
7477
err := Create0boxTestWallet(t, headers)
7578
require.NoError(t, err)
7679

80+
// Refresh CSRF token after wallet creation to ensure it's valid
81+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
82+
7783
allocInput := NewTestAllocation()
7884
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
7985
require.NoError(t, err)
@@ -92,6 +98,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
9298
err := Create0boxTestWallet(t, headers)
9399
require.NoError(t, err)
94100

101+
// Refresh CSRF token after wallet creation to ensure it's valid
102+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
103+
95104
allocInput := NewTestAllocation()
96105
allocInput["id"] = "c0360331837a7376d27007614e124db83811e4416dd2f1577345dd96c8621bf6"
97106
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
@@ -137,6 +146,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
137146
err := Create0boxTestWallet(t, headers)
138147
require.NoError(t, err)
139148

149+
// Refresh CSRF token after wallet creation to ensure it's valid
150+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_CHIMNEY)
151+
140152
allocInput := NewTestAllocation()
141153
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
142154
require.NoError(t, err)
@@ -150,6 +162,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
150162
err := Create0boxTestWallet(t, headers)
151163
require.NoError(t, err)
152164

165+
// Refresh CSRF token after wallet creation to ensure it's valid
166+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
167+
153168
allocInput := NewTestAllocation()
154169
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
155170
require.NoError(t, err)
@@ -167,6 +182,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
167182
err := Create0boxTestWallet(t, headers)
168183
require.NoError(t, err)
169184

185+
// Refresh CSRF token after wallet creation to ensure it's valid
186+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
187+
170188
allocInput := NewTestAllocation()
171189
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
172190
require.NoError(t, err)
@@ -188,6 +206,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
188206
err := Create0boxTestWallet(t, headers)
189207
require.NoError(t, err)
190208

209+
// Refresh CSRF token after wallet creation to ensure it's valid
210+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
211+
191212
allocInput := NewTestAllocation()
192213

193214
_, response, err := zboxClient.GetAllocation(t, headers, allocInput["id"])
@@ -202,6 +223,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
202223
err := Create0boxTestWallet(t, headers)
203224
require.NoError(t, err)
204225

226+
// Refresh CSRF token after wallet creation to ensure it's valid
227+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
228+
205229
allocInput := NewTestAllocation()
206230
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
207231
require.NoError(t, err)
@@ -229,6 +253,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
229253
err := Create0boxTestWallet(t, headers)
230254
require.NoError(t, err)
231255

256+
// Refresh CSRF token after wallet creation to ensure it's valid
257+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
258+
232259
allocInput := NewTestAllocation()
233260
allocInput["name"] = "new_alloc_name"
234261
allocInput["description"] = "new_alloc_description"

tests/api_tests/0box_dex_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ func Test0BoxDex(testSetup *testing.T) {
2121
t := test.NewSystemTest(testSetup)
2222

2323
t.RunSequentially("Create dex should work", func(t *test.SystemTest) {
24-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
24+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
2525
Teardown(t, headers)
26+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
2627

2728
err := Create0boxTestWallet(t, headers)
2829
require.NoError(t, err)
2930

31+
// Refresh CSRF token after wallet creation to ensure it's valid
32+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
33+
3034
dexData := NewTestDex()
3135

3236
_, response, err := zboxClient.CreateDexState(t, headers, dexData)
@@ -40,12 +44,16 @@ func Test0BoxDex(testSetup *testing.T) {
4044
})
4145

4246
t.RunSequentially("Update dex should work", func(t *test.SystemTest) {
43-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
47+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4448
Teardown(t, headers)
49+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4550

4651
err := Create0boxTestWallet(t, headers)
4752
require.NoError(t, err)
4853

54+
// Refresh CSRF token after wallet creation to ensure it's valid
55+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
56+
4957
dexData := NewTestDex()
5058

5159
_, response, err := zboxClient.CreateDexState(t, headers, dexData)

tests/api_tests/0box_free_storage_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ func Test0BoxFreeStorage(testSetup *testing.T) {
2121
t.SetSmokeTests("List allocation with zero allocation should work")
2222

2323
t.RunSequentiallyWithTimeout("Create FreeStorage should work", 3*time.Minute, func(t *test.SystemTest) {
24-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
24+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
2525
Teardown(t, headers)
26+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
2627

2728
err := Create0boxTestWallet(t, headers)
2829
require.NoError(t, err)
2930

31+
// Refresh CSRF token after wallet creation to ensure it's valid
32+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
33+
3034
storageMarker, response, err := zboxClient.CreateFreeStorage(t, headers)
3135
require.NoError(t, err)
3236
require.Equal(t, 200, response.StatusCode(), "Response status code does not match expected. Output: [%v]", response.String())
@@ -40,8 +44,9 @@ func Test0BoxFreeStorage(testSetup *testing.T) {
4044
})
4145

4246
t.RunSequentially("Create FreeStorage without existing wallet should not work", func(t *test.SystemTest) {
43-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
47+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4448
Teardown(t, headers)
49+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4550

4651
_, response, err := zboxClient.CreateFreeStorage(t, headers)
4752
require.NoError(t, err)

tests/api_tests/0box_jwt_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ func Test0BoxJWT(testSetup *testing.T) {
1212
t := test.NewSystemTest(testSetup)
1313

1414
t.RunSequentially("Create JWT token", func(t *test.SystemTest) {
15-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
15+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
1616
Teardown(t, headers)
17+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
1718

1819
_, response, err := zboxClient.CreateJwtToken(t, headers)
1920
require.NoError(t, err)
2021
require.Equal(t, 200, response.StatusCode(), "Response status code does not match expected. Output: [%v]", response.String())
2122
})
2223

2324
t.RunSequentially("Refresh JWT token with user id, which differs from the one used by the given old JWT token", func(t *test.SystemTest) {
24-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
25+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
2526
Teardown(t, headers)
27+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
2628

2729
jwtToken, response, err := zboxClient.CreateJwtToken(t, headers)
2830
require.NoError(t, err)
@@ -40,8 +42,9 @@ func Test0BoxJWT(testSetup *testing.T) {
4042
})
4143

4244
t.RunSequentially("Refresh JWT token with incorrect old JWT token", func(t *test.SystemTest) {
43-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
45+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4446
Teardown(t, headers)
47+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4548

4649
jwtToken, response, err := zboxClient.CreateJwtToken(t, headers)
4750
require.NoError(t, err)
@@ -54,8 +57,9 @@ func Test0BoxJWT(testSetup *testing.T) {
5457
})
5558

5659
t.RunSequentially("Refresh JWT token with user id, which equals to the one used by the given old JWT token", func(t *test.SystemTest) {
57-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
60+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
5861
Teardown(t, headers)
62+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
5963

6064
jwtToken, response, err := zboxClient.CreateJwtToken(t, headers)
6165
require.NoError(t, err)

tests/api_tests/0box_owner_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ func Test0BoxOwner(testSetup *testing.T) {
3737
t := test.NewSystemTest(testSetup)
3838

3939
t.RunSequentially("create owner without existing userID should work", func(t *test.SystemTest) {
40-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
40+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4141
Teardown(t, headers)
42+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
4243

4344
verifyOtpInput := NewVerifyOtpDetails()
4445
_, response, err := zboxClient.VerifyOtpDetails(t, headers, verifyOtpInput)
@@ -54,8 +55,9 @@ func Test0BoxOwner(testSetup *testing.T) {
5455
})
5556

5657
t.RunSequentially("create owner with existing userID should not work", func(t *test.SystemTest) {
57-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
58+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
5859
Teardown(t, headers)
60+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
5961

6062
verifyOtpInput := NewVerifyOtpDetails()
6163
_, _, err := zboxClient.VerifyOtpDetails(t, headers, verifyOtpInput)
@@ -67,8 +69,9 @@ func Test0BoxOwner(testSetup *testing.T) {
6769
})
6870

6971
t.RunSequentially("update owner with existing owner should work", func(t *test.SystemTest) {
70-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
72+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
7173
Teardown(t, headers)
74+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
7275

7376
verifyOtpInput := NewVerifyOtpDetails()
7477
_, _, err := zboxClient.VerifyOtpDetails(t, headers, verifyOtpInput)
@@ -91,8 +94,9 @@ func Test0BoxOwner(testSetup *testing.T) {
9194
})
9295

9396
t.RunSequentially("update owner without existing owner should not work", func(t *test.SystemTest) {
94-
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
97+
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
9598
Teardown(t, headers)
99+
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
96100

97101
ownerInput := NewTestOwner()
98102
message, _, err := zboxClient.UpdateOwner(t, headers, ownerInput)

0 commit comments

Comments
 (0)