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

Debug/tenderly vt #1104

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions .github/workflows/ci-dev-st.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ jobs:
graphnode_ethereum_node_url: https://virtual.mainnet.rpc.tenderly.co/${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
svc_account_secret: ${{ secrets.SVC_ACCOUNT_SECRET }}

- name: "Remove Tenderly virtual testnet"
if: always()
run: |
curl -X DELETE \
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
-H "Content-Type: application/json" \
https://api.tenderly.co/api/v1/account/zus_network/project/project/testnet/container/${{ env.TENDERLY_VIRTUAL_TESTNET_ID }}
# - name: "Remove Tenderly virtual testnet"
# if: always()
# run: |
# curl -X DELETE \
# -H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
# -H "Content-Type: application/json" \
# https://api.tenderly.co/api/v1/account/zus_network/project/project/testnet/container/${{ env.TENDERLY_VIRTUAL_TESTNET_ID }}
29 changes: 29 additions & 0 deletions internal/api/model/zauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package model

// SetupWallet represents wallet used to perform set up.
type SetupWallet struct {
UserID string `json:"user_id"`
ClientID string `json:"client_id"`
ClientKey string `json:"client_key"`
PublicKey string `json:"public_key"`
PrivateKey string `json:"private_key"`
PeerPublicKey string `json:"peer_public_key"`
ExpiredAt int64 `json:"expired_at"`
}

// SetupResponse represents response returned after performance of setup operation.
type SetupResponse struct {
Result string `json:"result"`
}

// SignMessageRequest represents message requested to be signed.
type SignMessageRequest struct {
Hash string `json:"hash"`
Signature string `json:"signature"`
ClientID string `json:"client_id"`
}

// SignMessageResponse represents message sign operation response.
type SignMessageResponse struct {
Sig string `json:"sig"`
}
4 changes: 4 additions & 0 deletions internal/api/model/zbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ type ZboxNftList struct {
NftCount int64 `json:"total"`
}

type ZboxJwtToken struct {
JwtToken string `json:"jwt_token"`
}

type ReferralCodeOfUser struct {
ReferrerCode string `json:"referral_code"`
ReferrerLink string `json:"referral_link"`
Expand Down
46 changes: 46 additions & 0 deletions internal/api/model/zvault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package model

// SplitWallet represents both split wallet and split key after generation operation.
type SplitWallet struct {
ClientID string `json:"client_id"`
ClientKey string `json:"client_key"`
PeerPublicKey string `json:"peer_public_key"`
Keys []KeyPair `json:"keys"`
Mnemonic string `json:"mnemonics"`
Version string `json:"version"`
DateCreated string `json:"date_created"`
Nonce int64 `json:"nonce"`
IsSplit bool `json:"is_split"`
}

// GetKeyResponse represents retrieved set of split keys.
type GetKeyResponse struct {
Keys []*SplitKey `json:"keys"`
}

// SplitKey represents retrieved split key.
type SplitKey struct {
UserID string `json:"user_id"`
ClientID string `json:"client_id"`
ClientKey string `json:"client_key"`
PrivateKey string `gorm:"unique" json:"private_key"`
PublicKey string `gorm:"unique" json:"public_key"`
PeerPublicKey string `gorm:"unique" json:"peer_public_key"`
Mnemonic string `json:"mnemonics"`
SharedTo string `json:"shared_to"`
IsRevoked bool `json:"is_revoked"`
CreatedAt int64 `json:"created_at"`
ExpiresAt int64 `json:"expires_at"`
}

// StoreRequest represents store request payload.
type StoreRequest struct {
Mnemonic string `json:"mnemonic"`
PrivateKey string `json:"private_key"`
}

// ShareWalletRequest represents share wallet request payload.
type ShareWalletRequest struct {
PublicKey string `json:"public_key"`
TargetUserID string `json:"target_user_id"`
}
142 changes: 142 additions & 0 deletions internal/api/util/client/zauth_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package client

import (
"encoding/json"
"fmt"

"github.com/0chain/gosdk/core/transaction"
"github.com/0chain/system_test/internal/api/model"
"github.com/0chain/system_test/internal/api/util/test"
"github.com/go-resty/resty/v2"
"github.com/stretchr/testify/require"
)

type ZauthClient struct {
BaseHttpClient
zauthEntrypoint string
}

func NewZauthClient(zauthEntrypoint string) *ZauthClient {
zauthClient := &ZauthClient{
zauthEntrypoint: zauthEntrypoint,
}
zauthClient.HttpClient = resty.New()

return zauthClient
}

func (c *ZauthClient) NewZauthHeaders(jwtToken, peerPublicKey string) map[string]string {
zauthHeaders := map[string]string{
"X-Jwt-Token": jwtToken,
"X-Peer-Public-Key": peerPublicKey,
}

return zauthHeaders
}

func (c *ZauthClient) Setup(t *test.SystemTest, setupWallet *model.SetupWallet, headers map[string]string) (*model.SetupResponse, *resty.Response, error) {
t.Logf("performing setup of split wallet for jwt token [%v] using zauth...", headers["X-Jwt-Token"])
var setupResponse *model.SetupResponse

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zauthEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/setup")

var body []byte

body, err = json.Marshal(setupWallet)
require.NoError(t, err)

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &setupResponse,
Headers: headers,
Body: body,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return setupResponse, resp, err
}

func (c *ZauthClient) SignTransaction(t *test.SystemTest, signTransactionRequest *transaction.Transaction, headers map[string]string) (*transaction.Transaction, *resty.Response, error) {
t.Logf("signing transaction for peer public key [%v] and for jwt token [%v] using zauth...", headers["X-Peer-Public-Key"], headers["X-Jwt-Token"])
var signTransactionResponse *transaction.Transaction

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zauthEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/sign/txn")

var body []byte

body, err = json.Marshal(signTransactionRequest)
require.NoError(t, err)

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &signTransactionResponse,
Headers: headers,
Body: body,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return signTransactionResponse, resp, err
}

func (c *ZauthClient) SignMessage(t *test.SystemTest, message *model.SignMessageRequest, headers map[string]string) (*model.SignMessageResponse, *resty.Response, error) {
t.Logf("signing message for peer public key [%v] and for jwt token [%v] using zauth...", headers["X-Peer-Public-Key"], headers["X-Jwt-Token"])
var signMessageResponse *model.SignMessageResponse

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zauthEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/sign/msg")

var body []byte

body, err = json.Marshal(message)
require.NoError(t, err)

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &signMessageResponse,
Headers: headers,
Body: body,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return signMessageResponse, resp, err
}

func (c *ZauthClient) Revoke(t *test.SystemTest, clientID, peerPublicKey string, headers map[string]string) (*resty.Response, error) {
t.Logf("revoking split key including split wallet for client id [%v] and for peer public key [%v] and for jwt token [%v] using zauth...", clientID, peerPublicKey, headers["X-Jwt-Token"])

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zauthEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath(fmt.Sprintf("/revoke/%s", clientID))

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Headers: headers,
FormData: map[string]string{
"peer_public_key": peerPublicKey,
},
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return resp, err
}

func (c *ZauthClient) Delete(t *test.SystemTest, clientID string, headers map[string]string) (*resty.Response, error) {
t.Logf("deleting split keys including split wallet for client id [%v] for jwt token [%v] using zauth...", clientID, headers["X-Jwt-Token"])

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zauthEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath(fmt.Sprintf("/delete/%s", clientID))

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Headers: headers,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return resp, err
}
76 changes: 69 additions & 7 deletions internal/api/util/client/zbox_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import (

const (
X_APP_USER_ID = "test_user_id"
X_APP_ID_TOKEN = "test_firebase_token"
X_APP_CLIENT_ID = "31f740fb12cf72464419a7e860591058a248b01e34b13cbf71d5a107b7bdc1e9"
X_APP_CLIENT_KEY = "b6d86a895b9ab247b9d19280d142ffb68c3d89833db368d9a2ee9346fa378a05441635a5951d2f6a209c9ca63dc903353739bfa8ba79bad17690fe8e38622e96"
X_APP_CLIENT_SIGNATURE = "d903d0f57c96b052d907afddb62777a1f77a147aee5ed2b5d8bab60a9319b09a"
X_APP_CLIENT_ID = "caae5a9d48b1a0cd01a5da982807d7ad6fcc8a8367b79c6adbe48e7c632544f2"
X_APP_CLIENT_KEY = "91a3a29f4c05b82f2a83f9d4b405976637a4a29f11b1918de30fc319ab87db191b195d9f3e6eecf588e1b83d195931d12760f303c3d1845144f07617022faa8f"
X_APP_CLIENT_SIGNATURE = "6de25e5a202614216610558ec68346a9aca97165e29a12cc047fbeb8c696d420"
X_APP_USER_ID_A = "test_user_id_alternative"
X_APP_CLIENT_ID_A = "2e16f28602959e23e0f5b153e298fc5dbfb02dcb089cfa74bd46f158c2f02ab7"
X_APP_CLIENT_KEY_A = "f615cfbb9154c99bf6e1d87e26397e987ee345c2e98c7a652326a3744f15ea100e22506fccf75515d9379f3275386f4401e2dbd1aafc4ef8f18af58a8c68fc02"
X_APP_CLIENT_SIGNATURE_A = "db4bf04ab302a4dde154804334d0eeb512d875585a4092c7776cf3505ba9e793"
X_APP_USER_ID_R = "test_user_id_referred_user"
X_APP_CLIENT_ID_R = "3fb9694ebf47b5a51c050025d9c807c3319a05499b1eb980bbb9f1e27e119c9f"
X_APP_CLIENT_KEY_R = "9a8a960db2dd93eb35f26e8f7e84976349064cae3246da23abd575f05e7ed31bd90726cfcc960e017a9246d080f5419ada219d03758c370208c5b688e5ec7a9c"
X_APP_CLIENT_SIGNATURE_R = "6b710d015b9e5e4734c08ac2de79ffeeeb49e53571cce8f71f21e375e5eca916"
X_APP_CLIENT_ID_R = "bcf5f517be521e0ffdb22d1fc26a35abdec8556bcb9ed075244a358df7337cd0"
X_APP_CLIENT_KEY_R = "de9351bbf460c761ea979764831759369ced3c6de38b856e7921eee9cc034323cce23c562c74a0629867fbea33d5009b9f473bc3b766871b65e7cf864ba4301d"
X_APP_CLIENT_SIGNATURE_R = "43fa947257ae0b5da8b073f0efeaa2570c4faf66fcabd93407e3597bc34e440b"
X_APP_ID_TOKEN = "test_firebase_token"
X_APP_TIMESTAMP = "123456789"
X_APP_CSRF = "test_csrf_token"
X_APP_BLIMP = "blimp"
Expand Down Expand Up @@ -1284,3 +1288,61 @@ func (c *ZboxClient) GetGraphBlobberTotalRewards(t *test.SystemTest, blobberId s

return &data, resp, err
}

func (c *ZboxClient) CreateJwtSession(t *test.SystemTest, headers map[string]string) (int64, *resty.Response, error) {
t.Logf("creating jwt session owner for userID [%v] using 0box...", headers["X-App-User-ID"])
var sessionID int64

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zboxEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/jwt/session")

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &sessionID,
Headers: headers,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return sessionID, resp, err
}

func (c *ZboxClient) CreateJwtToken(t *test.SystemTest, sessionID int64, headers map[string]string) (*model.ZboxJwtToken, *resty.Response, error) {
t.Logf("creating jwt token for userID [%v] and session [%v] using 0box...", headers["X-App-User-ID"], sessionID)
var zboxJwtToken *model.ZboxJwtToken

headers["X-JWT-Session-ID"] = strconv.FormatInt(sessionID, 10)

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zboxEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/jwt/token")

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &zboxJwtToken,
Headers: headers,
RequiredStatusCode: 201,
}, HttpPOSTMethod)

return zboxJwtToken, resp, err
}

func (c *ZboxClient) RefreshJwtToken(t *test.SystemTest, token string, headers map[string]string) (*model.ZboxJwtToken, *resty.Response, error) {
t.Logf("refreshing jwt token for userID [%v] and token [%v] using 0box...", headers["X-App-User-ID"], token)
var zboxJwtToken *model.ZboxJwtToken

headers["X-Jwt-Token"] = token

urlBuilder := NewURLBuilder()
err := urlBuilder.MustShiftParse(c.zboxEntrypoint)
require.NoError(t, err, "URL parse error")
urlBuilder.SetPath("/v2/jwt/token")

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &zboxJwtToken,
Headers: headers,
RequiredStatusCode: 201,
}, HttpPUTMethod)

return zboxJwtToken, resp, err
}
Loading
Loading