Skip to content

Commit

Permalink
System test 508 - 0Box Allocation system tests (#519)
Browse files Browse the repository at this point in the history
* created list and create allocation method for 0box allocation test

* modified allocation struct

* refactor

* remove unused import

* completed the issue

* removed lint issues

* Fix panic in 0box tests (#507)

Add nil check in 0box tests

* Skip tests due to slow goerli

* Worked upon review provided

* created get allocation method

* added one ore test case

* rebasing

* added testcases for get allocation

* added few more testcases

* worked upon review comment

* corrected spelling which was causing lint issues in system tests

* worked upon review and added update allocation

* ready to merge

* ready to merge

---------

Co-authored-by: Kishan-Dhakan <[email protected]>
Co-authored-by: Ryan <[email protected]>
Co-authored-by: Kishan Dhakan <[email protected]>
  • Loading branch information
4 people authored and boddumanohar committed Feb 5, 2023
1 parent 072ace0 commit c297c52
Show file tree
Hide file tree
Showing 3 changed files with 549 additions and 7 deletions.
28 changes: 28 additions & 0 deletions internal/api/model/zbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ type ZboxWalletAlt struct { // FIXME THIS IS INCONSISTENT AND SHOULD BE FIXED SE
LastUpdate string `json:"last_update"`
}

type ZboxAllocation struct {
Id string `json:"id"`
WalletId int `json:"wallet_id"`
Name string `json:"name"`
Description string `json:"random_description"`
AllocationType string `json:"allocation_type"`
AppType string `json:"app_type"`
NftState NftState `json:"nft_state"`
LastUpdate string `json:"last_update"`
}

type NftState struct {
AllocationId string `json:"allocation_id"`
CollectionId string `json:"collection_id"`
OwnedBy string `json:"owned_by"`
Stage string `json:"stage"`
Reference string `json:"reference"`
NftActivity string `json:"nft_activity"`
Metadata string `json:"meta_data"`
NftImage string `json:"nft_image"`
}

type ZboxWallet struct {
ClientId string `json:"client_id"`
WalletId int `json:"wallet_id"`
Expand All @@ -38,13 +60,19 @@ type ZboxWallet struct {
}

type MessageContainer struct {
Message string `json:"message"`
}

type ZboxWalletList struct {
MessageContainer
Data []ZboxWalletAlt `json:"data"`
}

type ZboxAllocationList struct {
WalletName string `json:"wallet_name"`
Allocs []ZboxAllocation `json:"allocs"`
}

type ZboxWalletKeys []struct {
ZboxWallet
}
Expand Down
146 changes: 139 additions & 7 deletions internal/api/util/client/zbox_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import (

type ZboxClient struct {
BaseHttpClient
zboxEntrypoint string
DefaultPhoneNumber string
DefaultMnemonic string
zboxEntrypoint string
DefaultPhoneNumber string
DefaultMnemonic string
DefaultAllocationId string
DefaultAllocationName string
}

func NewZboxClient(zboxEntrypoint, defaultPhoneNumber string) *ZboxClient {
zboxClient := &ZboxClient{
zboxEntrypoint: zboxEntrypoint,
DefaultPhoneNumber: defaultPhoneNumber,
DefaultMnemonic: "613ed9fb5b9311f6f22080eb1db69b2e786c990706c160faf1f9bdd324fd909bc640ad6a3a44cb4248ddcd92cc1fabf66a69ac4eb38a102b984b98becb0674db7d69c5727579d5f756bb8c333010866d4d871dae1b7032d6140db897e4349f60f94f1eb14a3b7a14a489226a1f35952472c9b2b13e3698523a8be2dcba91c344f55da17c21c403543d82fe5a32cb0c8133759ab67c31f1405163a2a255ec270b1cca40d9f236e007a3ba8f6be4eaeaad10376c5f224bad45c597d85a3b8b984f46c597f6cf561405bd0b0007ac6833cfff408aeb51c0d2fX",
zboxEntrypoint: zboxEntrypoint,
DefaultPhoneNumber: defaultPhoneNumber,
DefaultAllocationName: "DefaultName",
DefaultAllocationId: "7df193bcbe12fc3ef9ff143b7825d9afadc3ce3d7214162f13ffad2510494d41",
DefaultMnemonic: "613ed9fb5b9311f6f22080eb1db69b2e786c990706c160faf1f9bdd324fd909bc640ad6a3a44cb4248ddcd92cc1fabf66a69ac4eb38a102b984b98becb0674db7d69c5727579d5f756bb8c333010866d4d871dae1b7032d6140db897e4349f60f94f1eb14a3b7a14a489226a1f35952472c9b2b13e3698523a8be2dcba91c344f55da17c21c403543d82fe5a32cb0c8133759ab67c31f1405163a2a255ec270b1cca40d9f236e007a3ba8f6be4eaeaad10376c5f224bad45c597d85a3b8b984f46c597f6cf561405bd0b0007ac6833cfff408aeb51c0d2fX",
}
zboxClient.HttpClient = resty.New()

Expand Down Expand Up @@ -117,6 +121,69 @@ func (c *ZboxClient) ListWallets(t *test.SystemTest, idToken, csrfToken, phoneNu
return zboxWallets, resp, err
}

func (c *ZboxClient) GetAllocation(t *test.SystemTest, idToken, csrfToken, phoneNumber, allocationId, allocationName string) (model.ZboxAllocation, *resty.Response, error) {
t.Logf("Getting allocation for allocationId [%v] using 0box...", allocationId)
var allocation model.ZboxAllocation

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

formData := map[string]string{
"id": allocationId,
"name": allocationName,
}

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &allocation,
QueryParams: formData,
Headers: map[string]string{
"X-App-Client-ID": "31f740fb12cf72464419a7e860591058a248b01e34b13cbf71d5a107b7bdc1e9",
"X-App-Client-Key": "b6d86a895b9ab247b9d19280d142ffb68c3d89833db368d9a2ee9346fa378a05441635a5951d2f6a209c9ca63dc903353739bfa8ba79bad17690fe8e38622e96",
"X-App-Timestamp": "1618213324",
"X-App-ID-TOKEN": idToken,
"X-App-Phone-Number": phoneNumber,
"X-CSRF-TOKEN": csrfToken,
"X-APP-TYPE": "chimney",
"X-App-Client-Signature": "d903d0f57c96b052d907afddb62777a1f77a147aee5ed2b5d8bab60a9319b09a",
},
RequiredStatusCode: 200,
}, HttpGETMethod)

return allocation, resp, err
}

func (c *ZboxClient) ListAllocation(t *test.SystemTest, idToken, csrfToken, phoneNumber string) ([]model.ZboxAllocation, *resty.Response, error) {
t.Logf("Listing all allocations for [%v] using 0box...", phoneNumber)
var allocWalletList []model.ZboxAllocation

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

formData := map[string]string{}

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &allocWalletList,
FormData: formData,
Headers: map[string]string{
"X-App-Client-ID": "31f740fb12cf72464419a7e860591058a248b01e34b13cbf71d5a107b7bdc1e9",
"X-App-Client-Key": "b6d86a895b9ab247b9d19280d142ffb68c3d89833db368d9a2ee9346fa378a05441635a5951d2f6a209c9ca63dc903353739bfa8ba79bad17690fe8e38622e96",
"X-App-Timestamp": "1618213324",
"X-App-ID-TOKEN": idToken,
"X-App-Phone-Number": phoneNumber,
"X-CSRF-TOKEN": csrfToken,
"X-APP-TYPE": "chimney",
"X-App-Client-Signature": "d903d0f57c96b052d907afddb62777a1f77a147aee5ed2b5d8bab60a9319b09a",
},
RequiredStatusCode: 200,
}, HttpGETMethod)

return allocWalletList, resp, err
}

func (c *ZboxClient) PostWallet(t *test.SystemTest, mnemonic, walletName, walletDescription, idToken, csrfToken, phoneNumber string) (*model.ZboxWalletAlt, *resty.Response, error) {
t.Logf("Posting wallet using 0box...")
var zboxWallet *model.ZboxWalletAlt
Expand Down Expand Up @@ -151,6 +218,72 @@ func (c *ZboxClient) PostWallet(t *test.SystemTest, mnemonic, walletName, wallet
return zboxWallet, resp, err
}

func (c *ZboxClient) PostAllocation(t *test.SystemTest, allocationId, allocationName, allocationDescription, allocationType, idToken, csrfToken, phoneNumber string) (*model.MessageContainer, *resty.Response, error) {
t.Logf("Posting Allocation using 0box...")
var message *model.MessageContainer

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

formData := map[string]string{
"name": allocationName,
"id": allocationId,
"description": allocationDescription,
"allocation_type": allocationType,
}

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &message,
FormData: formData,
Headers: map[string]string{
"X-App-Client-ID": "31f740fb12cf72464419a7e860591058a248b01e34b13cbf71d5a107b7bdc1e9",
"X-App-Client-Key": "b6d86a895b9ab247b9d19280d142ffb68c3d89833db368d9a2ee9346fa378a05441635a5951d2f6a209c9ca63dc903353739bfa8ba79bad17690fe8e38622e96",
"X-App-Timestamp": "1618213324",
"X-App-ID-TOKEN": idToken,
"X-App-Phone-Number": phoneNumber,
"X-CSRF-TOKEN": csrfToken,
"X-APP-TYPE": "chimney",
},
RequiredStatusCode: 200,
}, HttpPOSTMethod)
return message, resp, err
}

func (c *ZboxClient) UpdateAllocation(t *test.SystemTest, allocationId, allocationName, allocationDescription, allocationType, idToken, csrfToken, phoneNumber string) (*model.MessageContainer, *resty.Response, error) {
t.Logf("Posting Allocation using 0box...")
var message *model.MessageContainer

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

formData := map[string]string{
"name": allocationName,
"id": allocationId,
"description": allocationDescription,
"allocation_type": allocationType,
}

resp, err := c.executeForServiceProvider(t, urlBuilder.String(), model.ExecutionRequest{
Dst: &message,
FormData: formData,
Headers: map[string]string{
"X-App-Client-ID": "31f740fb12cf72464419a7e860591058a248b01e34b13cbf71d5a107b7bdc1e9",
"X-App-Client-Key": "b6d86a895b9ab247b9d19280d142ffb68c3d89833db368d9a2ee9346fa378a05441635a5951d2f6a209c9ca63dc903353739bfa8ba79bad17690fe8e38622e96",
"X-App-Timestamp": "1618213324",
"X-App-ID-TOKEN": idToken,
"X-App-Phone-Number": phoneNumber,
"X-CSRF-TOKEN": csrfToken,
"X-APP-TYPE": "chimney",
},
RequiredStatusCode: 200,
}, HttpPUTMethod)
return message, resp, err
}

func (c *ZboxClient) DeleteWallet(t *test.SystemTest, walletId int, idToken, csrfToken, phoneNumber string) (*model.MessageContainer, *resty.Response, error) {
t.Logf("Deleting wallet id [%v] using 0box...", walletId)
var message *model.MessageContainer
Expand Down Expand Up @@ -182,7 +315,6 @@ func (c *ZboxClient) DeleteWallet(t *test.SystemTest, walletId int, idToken, csr

return message, resp, err
}

func (c *ZboxClient) ListWalletKeys(t *test.SystemTest, idToken, csrfToken, phoneNumber string) (model.ZboxWalletKeys, *resty.Response, error) {
t.Logf("Listing wallets keys for [%v] using 0box...", phoneNumber)
var zboxWallets *model.ZboxWalletKeys
Expand Down
Loading

0 comments on commit c297c52

Please sign in to comment.