Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 42 additions & 4 deletions internal/api/util/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,16 +956,54 @@ func (c *APIClient) RegisterBlobber(t *test.SystemTest,
}

if requireIdVerification {
var storageNode model.StorageNode
// First check if transaction status matches
if registerBlobberTransactionGetConfirmationResponse.Status != requiredTransactionStatus {
t.Logf("Transaction status doesn't match. Expected: %d, Actual: %d, Output: %s",
requiredTransactionStatus, registerBlobberTransactionGetConfirmationResponse.Status,
registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput)
return false
}

// Only try to unmarshal if transaction is successful
transactionOutput := registerBlobberTransactionGetConfirmationResponse.Transaction.TransactionOutput

// Check if output is empty or not valid JSON
if transactionOutput == "" {
t.Log("Transaction output is empty, waiting for confirmation...")
return false
}

// Check if output looks like JSON (starts with '{')
trimmedOutput := strings.TrimSpace(transactionOutput)
if !strings.HasPrefix(trimmedOutput, "{") {
preview := trimmedOutput
if len(preview) > 50 {
preview = preview[:50] + "..."
}
t.Logf("Transaction output is not JSON (starts with: %s), waiting for confirmation...", preview)
return false
}

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

return registerBlobberTransactionGetConfirmationResponse.Status == requiredTransactionStatus && storageNode.ID == expectedResponse
// Verify the ManagingWallet matches (for storage version 2+ blobbers)
// or the ID matches (for legacy blobbers)
if storageNode.ManagingWallet != "" && storageNode.ManagingWallet == expectedResponse {
return true
}
if storageNode.ID == expectedResponse {
return true
}

t.Logf("StorageNode verification failed. Expected: %s, Actual ID: %s, Actual ManagingWallet: %s",
expectedResponse, storageNode.ID, storageNode.ManagingWallet)
return false
}

// Log the actual status and output for debugging
Expand Down
53 changes: 47 additions & 6 deletions tests/api_tests/0box_aggregate_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,16 @@ func Test0boxGraphAndTotalEndpoints(testSetup *testing.T) {

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

// Ensure blobberOwnerWallet has sufficient balance and updated nonce
blobberOwnerBalance := apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
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)")
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[0], client.TxSuccessfulStatus)

// Update nonce before second update
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
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)")
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[1], client.TxSuccessfulStatus)

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

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

// Cleanup: Revert write price to 0.1
targetBlobbers[0].Terms.WritePrice = *tokenomics.IntToZCN(0.1)
targetBlobbers[1].Terms.WritePrice = *tokenomics.IntToZCN(0.1)
// Update nonce before first cleanup update
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
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)")
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[0], client.TxSuccessfulStatus)
// Update nonce before second cleanup update
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
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)")
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[1], client.TxSuccessfulStatus)
})

Expand Down Expand Up @@ -1052,11 +1071,13 @@ func Test0boxGraphAndTotalEndpoints(testSetup *testing.T) {

targetBlobbers[0].Capacity += 10 * 1024 * 1024 * 1024
targetBlobbers[1].Capacity += 5 * 1024 * 1024 * 1024
t.Logf("Updating blobber 0 capacity to: %d", targetBlobbers[0].Capacity)
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[0], client.TxSuccessfulStatus)

// Update nonce before second update
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
t.Logf("Updating blobber 1 capacity to: %d", targetBlobbers[1].Capacity)
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[1], client.TxSuccessfulStatus)

// Check increase
Expand All @@ -1065,8 +1086,12 @@ func Test0boxGraphAndTotalEndpoints(testSetup *testing.T) {
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode())
totalBlobberCapacityAfter := int64(*data)
t.Logf("Current total capacity: %d, expected > %d", totalBlobberCapacityAfter, totalBlobberCapacity)
cond := totalBlobberCapacityAfter > totalBlobberCapacity
totalBlobberCapacity = totalBlobberCapacityAfter
if cond {
totalBlobberCapacity = totalBlobberCapacityAfter
t.Logf("Total capacity increased successfully to: %d", totalBlobberCapacity)
}
return cond
})

Expand All @@ -1078,26 +1103,36 @@ func Test0boxGraphAndTotalEndpoints(testSetup *testing.T) {

targetBlobbers[0].Capacity -= 10 * 1024 * 1024 * 1024
targetBlobbers[1].Capacity -= 5 * 1024 * 1024 * 1024
t.Logf("Updating blobber 0 capacity back to: %d", targetBlobbers[0].Capacity)
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[0], client.TxSuccessfulStatus)

// Update nonce before second decrease
blobberOwnerBalance = apiClient.GetWalletBalance(t, blobberOwnerWallet, client.HttpOkStatus)
blobberOwnerWallet.Nonce = int(blobberOwnerBalance.Nonce)
t.Logf("Updating blobber 1 capacity back to: %d", targetBlobbers[1].Capacity)
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobbers[1], client.TxSuccessfulStatus)

// Check decrease
// Check decrease - allow for small differences due to timing/rounding
wait.PoolImmediately(t, 2*time.Minute, func() bool {
data, resp, err := zboxClient.GetTotalBlobberCapacity(t)
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode())
totalBlobberCapacityAfter := int64(*data)
totalBlobberCapacity = totalBlobberCapacityAfter

blobbers, resp, err := apiClient.V1SCRestGetAllBlobbers(t, client.HttpOkStatus)
require.NoError(t, err)
require.Equal(t, 200, resp.StatusCode())
expectedCapacity := calculateCapacity(blobbers)
cond := expectedCapacity == totalBlobberCapacityAfter
diff := expectedCapacity - totalBlobberCapacityAfter
if diff < 0 {
diff = -diff
}
// Allow for small differences (within 1GB) due to timing/rounding in graph aggregation
cond := diff <= 1024*1024*1024
t.Logf("Total capacity from API: %d, calculated from blobbers: %d, difference: %d", totalBlobberCapacityAfter, expectedCapacity, diff)
if cond {
t.Logf("Total capacity matches expected value (within tolerance)")
}
return cond
})
})
Expand Down Expand Up @@ -1291,6 +1326,7 @@ func Test0boxGraphBlobberEndpoints(testSetup *testing.T) {

// Increase capacity
targetBlobber.Capacity += 1000000000
t.Logf("Updating blobber capacity to: %d", targetBlobber.Capacity)
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobber, client.TxSuccessfulStatus)

// Check increased for the same blobber
Expand All @@ -1300,9 +1336,11 @@ func Test0boxGraphBlobberEndpoints(testSetup *testing.T) {
require.Equal(t, 200, resp.StatusCode())
require.Len(t, *data, 1)
afterValue := (*data)[0]
t.Logf("Current capacity: %d, expected > %d", afterValue, capacity)
cond := afterValue > capacity
if cond {
capacity = afterValue
t.Logf("Capacity increased successfully to: %d", capacity)
}
return cond
})
Expand All @@ -1314,6 +1352,7 @@ func Test0boxGraphBlobberEndpoints(testSetup *testing.T) {
require.GreaterOrEqual(t, blobberOwnerBalance.Balance, int64(200000000), "blobberOwnerWallet must have at least 0.2 ZCN to pay for update transaction (0.1 ZCN value + fees)")

targetBlobber.Capacity -= 1000000000
t.Logf("Updating blobber capacity back to: %d", targetBlobber.Capacity)
apiClient.UpdateBlobber(t, blobberOwnerWallet, targetBlobber, client.TxSuccessfulStatus)

// Check decreased for the same blobber
Expand All @@ -1323,9 +1362,11 @@ func Test0boxGraphBlobberEndpoints(testSetup *testing.T) {
require.Equal(t, 200, resp.StatusCode())
require.Len(t, *data, 1)
afterValue := (*data)[0]
t.Logf("Current capacity: %d, expected < %d", afterValue, capacity)
cond := afterValue < capacity
if cond {
capacity = afterValue
t.Logf("Capacity decreased successfully to: %d", capacity)
}
return cond
})
Expand Down
27 changes: 27 additions & 0 deletions tests/api_tests/0box_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocationList, response, err := zboxClient.ListAllocation(t, headers)
require.NoError(t, err)
require.Equal(t, 200, response.StatusCode(), "Response status code does not match expected. Output: [%v]", response.String())
Expand All @@ -74,6 +77,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
require.NoError(t, err)
Expand All @@ -92,6 +98,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()
allocInput["id"] = "c0360331837a7376d27007614e124db83811e4416dd2f1577345dd96c8621bf6"
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
Expand Down Expand Up @@ -137,6 +146,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_CHIMNEY)

allocInput := NewTestAllocation()
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
require.NoError(t, err)
Expand All @@ -150,6 +162,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
require.NoError(t, err)
Expand All @@ -167,6 +182,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
require.NoError(t, err)
Expand All @@ -188,6 +206,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()

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

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()
_, response, err := zboxClient.CreateAllocation(t, headers, allocInput)
require.NoError(t, err)
Expand Down Expand Up @@ -229,6 +253,9 @@ func Test0BoxAllocation(testSetup *testing.T) {
err := Create0boxTestWallet(t, headers)
require.NoError(t, err)

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

allocInput := NewTestAllocation()
allocInput["name"] = "new_alloc_name"
allocInput["description"] = "new_alloc_description"
Expand Down
12 changes: 10 additions & 2 deletions tests/api_tests/0box_dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ func Test0BoxDex(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)

t.RunSequentially("Create dex should work", func(t *test.SystemTest) {
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
Teardown(t, headers)
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

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

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

dexData := NewTestDex()

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

t.RunSequentially("Update dex should work", func(t *test.SystemTest) {
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
Teardown(t, headers)
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

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

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

dexData := NewTestDex()

_, response, err := zboxClient.CreateDexState(t, headers, dexData)
Expand Down
9 changes: 7 additions & 2 deletions tests/api_tests/0box_free_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ func Test0BoxFreeStorage(testSetup *testing.T) {
t.SetSmokeTests("List allocation with zero allocation should work")

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

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

// Refresh CSRF token after wallet creation to ensure it's valid
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

storageMarker, response, err := zboxClient.CreateFreeStorage(t, headers)
require.NoError(t, err)
require.Equal(t, 200, response.StatusCode(), "Response status code does not match expected. Output: [%v]", response.String())
Expand All @@ -40,8 +44,9 @@ func Test0BoxFreeStorage(testSetup *testing.T) {
})

t.RunSequentially("Create FreeStorage without existing wallet should not work", func(t *test.SystemTest) {
headers := zboxClient.NewZboxHeaders(client.X_APP_BLIMP)
headers := zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)
Teardown(t, headers)
headers = zboxClient.NewZboxHeadersWithCSRF(t, client.X_APP_BLIMP)

_, response, err := zboxClient.CreateFreeStorage(t, headers)
require.NoError(t, err)
Expand Down
Loading
Loading