-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblobber_hashnode_test.go
110 lines (83 loc) · 4.21 KB
/
blobber_hashnode_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package api_tests
import (
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
"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/crypto"
"github.com/stretchr/testify/require"
)
func TestHashnodeRoot(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.Parallel()
t.SetSmokeTests("Get hashnode root from blobber for an empty allocation should work")
t.Run("Get hashnode root from blobber for an empty allocation should work", func(t *test.SystemTest) {
wallet := createWallet(t)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
usedBlobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, usedBlobberID, "Old blobber ID contains zero value")
sign, err := crypto.SignHashUsingSignatureScheme(crypto.Sha3256([]byte(allocation.ID)), "bls0chain", []*model.KeyPair{wallet.Keys})
require.Nil(t, err)
blobberUrl := getBlobberURL(usedBlobberID, allocation.Blobbers)
blobberRequest := &model.BlobberGetHashnodeRequest{
AllocationID: allocation.ID,
URL: blobberUrl,
ClientId: wallet.Id,
ClientKey: wallet.PublicKey,
ClientSignature: sign,
}
getBlobberResponse, restyResponse, err := apiClient.V1BlobberGetHashNodeRoot(t, blobberRequest, client.HttpOkStatus)
require.Nil(t, err)
require.NotNil(t, restyResponse)
require.NotNil(t, getBlobberResponse)
require.Equal(t, getBlobberResponse.AllocationID, allocationID)
require.Equal(t, getBlobberResponse.Type, "d")
require.Equal(t, getBlobberResponse.Path, "/")
})
t.RunWithTimeout("Get hashnode root for non-existent allocation should fail", 90*time.Second, func(t *test.SystemTest) { //TODO: why is this so slow (67s) ?
wallet := createWallet(t)
allocationID := "badallocation"
blobberUrl := apiClient.HealthyServiceProviders.Blobbers[0]
sign, err := crypto.SignHashUsingSignatureScheme(crypto.Sha3256([]byte(allocationID)), "bls0chain", []*model.KeyPair{wallet.Keys})
require.Nil(t, err)
blobberRequest := &model.BlobberGetHashnodeRequest{
AllocationID: allocationID,
URL: blobberUrl,
ClientId: wallet.Id,
ClientKey: wallet.PublicKey,
ClientSignature: sign,
}
getBlobberResponse, restyResponse, err := apiClient.V1BlobberGetHashNodeRoot(t, blobberRequest, client.HttpOkStatus)
require.NotNil(t, err)
require.Equal(t, 500, restyResponse.StatusCode())
require.Contains(t, string(restyResponse.Body()), "record not found")
require.Nil(t, getBlobberResponse)
})
t.Run("Get hashnode root with bad signature should fail", func(t *test.SystemTest) {
wallet := createWallet(t)
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)
allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
usedBlobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, usedBlobberID, "Old blobber ID contains zero value")
sign := "badsign"
blobberUrl := getBlobberURL(usedBlobberID, allocation.Blobbers)
blobberRequest := &model.BlobberGetHashnodeRequest{
AllocationID: allocation.ID,
URL: blobberUrl,
ClientId: wallet.Id,
ClientKey: wallet.PublicKey,
ClientSignature: sign,
}
getBlobberResponse, restyResponse, err := apiClient.V1BlobberGetHashNodeRoot(t, blobberRequest, client.HttpOkStatus)
require.NotNil(t, err)
require.Equal(t, "bad request: invalid signature badsign\n", string(restyResponse.Body()))
require.Nil(t, getBlobberResponse)
})
// TODO: add a case for hasnoderoot of an allocation with a file in it.
}