Skip to content

Commit

Permalink
update accountmeta test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwalong committed Jan 23, 2024
1 parent beb36a7 commit 34c9ba8
Show file tree
Hide file tree
Showing 39 changed files with 1,358 additions and 77 deletions.
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
module github.com/xyield/xumm-go-client

go 1.16
go 1.18

require (
github.com/gorilla/websocket v1.4.2
github.com/json-iterator/go v1.1.12
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/stretchr/testify v1.7.0
github.com/ugorji/go/codec v1.2.7
github.com/xyield/xumm-user-device v0.0.0-20220315190815-aed3ae39e4ab
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -19,13 +17,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/xyield/xumm-go-client v0.0.0-20220310192812-590915fe9937/go.mod h1:0LoPhdN9OpjWZJaZ86y1sz/oc57PbuAIB5ORwSX5kyc=
github.com/xyield/xumm-user-device v0.0.0-20220315190815-aed3ae39e4ab h1:8tFBu+hvANduwkQutWsFDWVR60bXdZ1uoyA7nJgG6FE=
github.com/xyield/xumm-user-device v0.0.0-20220315190815-aed3ae39e4ab/go.mod h1:VwNyuWpcqbDmKq6IvvXTDJAFf+skL6M9/pDgQYNyYRk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
1 change: 1 addition & 0 deletions xumm-go-client
Submodule xumm-go-client added at 96aadd
2 changes: 1 addition & 1 deletion xumm/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type JwtInterface interface {
GetPayloadByCustomId(customId string, jwt ...string) (*models.XummPayload, error)
GetRatesForCurrency(cur string, jwt ...string) (*models.RatesCurrencyResponse, error)
PostPayload(body models.XummPostPayload, jwt ...string) (*models.CreatedPayload, error)
Ping(Jwt ...string) (*models.Pong, error)
Ping(Jwt ...string) (*models.JwtPong, error)
}

type Jwt struct {
Expand Down
4 changes: 2 additions & 2 deletions xumm/jwt/jwt_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
)

// Ping method tests connectivity to XUMM api.
func (j *Jwt) Ping(jwt ...string) (*models.Pong, error) {
func (j *Jwt) Ping(jwt ...string) (*models.JwtPong, error) {
req, err := http.NewRequest(http.MethodGet, j.Cfg.BaseURL+JWTPINGENDPOINT, nil)

if jwt == nil {
Expand All @@ -36,7 +36,7 @@ func (j *Jwt) Ping(jwt ...string) (*models.Pong, error) {
log.Println(err)
return nil, err
}
var p models.Pong
var p models.JwtPong
_, err = utils.DeserialiseRequest(&p, res.Body)
if err != nil {
return nil, err
Expand Down
24 changes: 24 additions & 0 deletions xumm/meta/get_account_meta_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package meta

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xumm-go-client/xumm"
statictestdata "github.com/xyield/xumm-go-client/xumm/meta/static-test-data"
)

func TestGetAccountMetaIntegrationTest(t *testing.T) {

cfg, err := xumm.NewConfig()
assert.NoError(t, err)
m := &Meta{
Cfg: cfg,
}

am, err := m.GetAccountMeta(statictestdata.AccountMetaTestResult.Account)

assert.NoError(t, err)
assert.NotEmpty(t, am)
assert.Equal(t, statictestdata.AccountMetaTestResult, am)
}
91 changes: 91 additions & 0 deletions xumm/meta/get_account_meta_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package meta

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
testutils "github.com/xyield/xumm-go-client/utils/test-utils"
"github.com/xyield/xumm-go-client/xumm"
statictestdata "github.com/xyield/xumm-go-client/xumm/meta/static-test-data"
"github.com/xyield/xumm-go-client/xumm/models"
)

func TestGetAccountMeta(t *testing.T) {

jsonResponse := `{
"account": "rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ",
"kycApproved": true,
"xummPro": true,
"blocked": false,
"force_dtag": false,
"avatar": "https://xumm.app/avatar/rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ.png",
"xummProfile": {
"accountAlias": "XRPL Labs - Wietse Wind",
"ownerAlias": "Wietse Wind",
"slug": "wietsewind",
"profileUrl": "https://xumm.me/wietsewind",
"accountSlug": null,
"payString": "wietsewind$xumm.me"
},
"thirdPartyProfiles": [
{
"accountAlias": "Wietse Wind",
"source": "xumm.app"
},
{
"accountAlias": "wietse.com",
"source": "xrpl"
},
{
"accountAlias": "XRPL-Labs",
"source": "bithomp.com"
}
],
"globalid": {
"linked": "2021-06-29T10:22:25.000Z",
"profileUrl": "https://app.global.id/u/wietse",
"sufficientTrust": true
}
}`

tests := []struct {
testName string
inputValue string
expectedOutput *models.AccountMetaResponse
expectedError error
httpStatusCode int
}{
{testName: "correctData", inputValue: jsonResponse, expectedOutput: statictestdata.AccountMetaTestResult, expectedError: nil, httpStatusCode: 200},
}

for _, tt := range tests {

t.Run(tt.testName, func(t *testing.T) {
m := &testutils.MockClient{}
m.DoFunc = testutils.MockResponse(tt.inputValue, tt.httpStatusCode, m)
cfg, err := xumm.NewConfig(xumm.WithHttpClient(m), xumm.WithAuth("testApiKey", "testApiSecret"))
assert.NoError(t, err)
meta := &Meta{
Cfg: cfg,
}
ca, err := meta.GetAccountMeta(statictestdata.AccountMetaTestResult.Account)

if tt.expectedError != nil {
assert.Nil(t, ca)
assert.Error(t, err)
assert.EqualError(t, err, tt.expectedError.Error())
} else {
assert.Equal(t, http.Header{
"X-API-Key": {"testApiKey"},
"X-API-Secret": {"testApiSecret"},
"Content-Type": {"application/json"},
}, m.Spy.Header)
assert.NoError(t, err)
assert.Equal(t, tt.expectedOutput, ca)
}
})

}

}
22 changes: 19 additions & 3 deletions xumm/meta/get_curated_assets_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,39 @@ func TestCuratedAssetsIntegration(t *testing.T) {
Id: 185,
Name: "Bitstamp",
Domain: "bitstamp.net",
Avatar: "https://xumm.app/assets/icons/currencies/ex-bitstamp.png",
Avatar: "https://xumm.app/cdn-cgi/image/width=250,height=250,quality=75,fit=crop/assets/icons/currencies/ex-bitstamp.png",
Currencies: map[string]models.CurrencyInfo{
"BTC": {
Id: 492,
IssuerId: 185,
Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
Currency: "BTC",
Name: "Bitcoin",
Avatar: "https://xumm.app/assets/icons/currencies/crypto-btc.png",
Avatar: "https://xumm.app/cdn-cgi/image/width=250,height=250,quality=75,fit=crop/assets/icons/currencies/crypto-btc.png",
},
"EUR": {
Id: 13854758,
IssuerId: 185,
Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
Currency: "EUR",
Name: "Euro",
Avatar: "https://xumm.app/cdn-cgi/image/width=250,height=250,quality=75,fit=crop/assets/icons/currencies/fiat-euro.png",
},
"GBP": {
Id: 13854774,
IssuerId: 185,
Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
Currency: "GBP",
Name: "British Pound",
Avatar: "https://cdn.xumm.pro/cdn-cgi/image/width=250,height=250,quality=75,fit=crop/currencies-tokens/fiat-brpnd.png",
},
"USD": {
Id: 178,
IssuerId: 185,
Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
Currency: "USD",
Name: "US Dollar",
Avatar: "https://xumm.app/assets/icons/currencies/fiat-dollar.png",
Avatar: "https://xumm.app/cdn-cgi/image/width=250,height=250,quality=75,fit=crop/assets/icons/currencies/fiat-dollar.png",
},
},
}, bitstamp)
Expand Down
25 changes: 24 additions & 1 deletion xumm/meta/get_hookhash.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package meta

import (
"encoding/hex"
"fmt"
"net/http"

"github.com/xyield/xumm-go-client/utils"
Expand All @@ -12,7 +14,28 @@ const (
HOOKHASHENDPOINT = "/platform/hookhash/"
)

func (m *Meta) GetHookhash(h string) (*models.HookHashResponse, error) {
type EmptyHookHash struct{}

func (e *EmptyHookHash) Error() string {
return fmt.Sprintln("No hookhash provided")
}

type InvalidHookHash struct{}

func (e *InvalidHookHash) Error() string {
return fmt.Sprintln("Invalid hookhash provided, must be 64 hexadecimal characters")
}

func (m *Meta) GetHookHash(h string) (*models.HookHashResponse, error) {

if len(h) != 64 {
return nil, &InvalidHookHash{}
}

_, err := hex.DecodeString(h)
if err != nil {
return nil, &InvalidHookHash{}
}

req, err := http.NewRequest(http.MethodGet, m.Cfg.BaseURL+HOOKHASHENDPOINT+h, nil)
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions xumm/meta/get_hookhash_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build integration
// +build integration

package meta

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xumm-go-client/xumm"
"github.com/xyield/xumm-go-client/xumm/models"
)

func TestGetHookHashIntegrationTest(t *testing.T) {

cfg, err := xumm.NewConfig()
assert.NoError(t, err)
m := &Meta{
Cfg: cfg,
}

hookHash := "31C3EC186C367DA66DFBD0E576D6170A2C1AB846BFC35FC0B49D202F2A8CDFD8"

hh, err := m.GetHookHash(hookHash)

assert.NoError(t, err)
assert.IsType(t, &models.HookHashResponse{}, hh)
assert.NotEmpty(t, hh.Name)
assert.NotEmpty(t, hh.Description)
}
Loading

0 comments on commit 34c9ba8

Please sign in to comment.