Skip to content

Commit

Permalink
fix: fix CoinGecko enterprise response model definition (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: VM <arimas@foxmail.com>
  • Loading branch information
sysvm and VM authored Nov 14, 2023
1 parent 2bdfef0 commit 8564cba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 84 deletions.
107 changes: 36 additions & 71 deletions coingecko/enterprise_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,12 @@ func TestClient_GetCirculatingSupplyChartByCoinID(t *testing.T) {
wantedErrStr string
}{
{
name: "success",
server: mockHTTPServer(t, &CoinCirculatingSupplyChartResponse{CirculatingSupply: []struct {
CoinsIDCirculatingSupplyChartItem
}{
{
CoinsIDCirculatingSupplyChartItem{
"1666224000000",
"19184000.0",
},
},
}}),
name: "success",
server: mockStringHTTPServer(t, `{"circulating_supply": [[1666224000000,"19184000.0"]]}`),
id: "ethereum",
wantedIsErr: false,
wantedResult: &CoinCirculatingSupplyChartResponse{CirculatingSupply: []struct {
CoinsIDCirculatingSupplyChartItem
}{
{
CoinsIDCirculatingSupplyChartItem{
"1666224000000",
"19184000.0",
},
},
}},
wantedResult: &CoinCirculatingSupplyChartResponse{CirculatingSupply: []CoinsIDCirculatingSupplyChartItem{
{"1666224000000", "19184000.0"}}},
wantedErrStr: "",
},
{
Expand Down Expand Up @@ -99,29 +82,12 @@ func TestClient_GetCirculatingSupplyChartRangeByCoinID(t *testing.T) {
wantedErrStr string
}{
{
name: "success",
server: mockHTTPServer(t, &CoinCirculatingSupplyChartResponse{CirculatingSupply: []struct {
CoinsIDCirculatingSupplyChartItem
}{
{
CoinsIDCirculatingSupplyChartItem{
"1666224000000",
"19184000.0",
},
},
}}),
name: "success",
server: mockStringHTTPServer(t, `{"circulating_supply": [[1666224000000,"19184000.0"]]}`),
id: "ethereum",
wantedIsErr: false,
wantedResult: &CoinCirculatingSupplyChartResponse{CirculatingSupply: []struct {
CoinsIDCirculatingSupplyChartItem
}{
{
CoinsIDCirculatingSupplyChartItem{
"1666224000000",
"19184000.0",
},
},
}},
wantedResult: &CoinCirculatingSupplyChartResponse{CirculatingSupply: []CoinsIDCirculatingSupplyChartItem{
{"1666224000000", "19184000.0"}}},
wantedErrStr: "",
},
{
Expand Down Expand Up @@ -171,27 +137,6 @@ func TestClient_GetCirculatingSupplyChartRangeByCoinID(t *testing.T) {
}

func TestClient_ListAllTokensByAssetPlatformID(t *testing.T) {
// resp := &ListAllTokensResponse{
// Name: "CoinGecko",
// LogoURI: "https://www.coingecko.com/assets/thumbnail-007177f3eca19695592f0b8b0eabbdae282b54154e1be912285c9034ea6cbaf2.png",
// Keywords: []string{"defi"},
// Timestamp: time.Unix(1666224000, 0),
// Tokens: []TokensListAllItem{
// {
// ChainID: 137,
// Address: "0xb33eaad8d922b1083446dc23f610c2567fb5180f",
// Name: "Uniswap",
// Symbol: "UNI",
// Decimals: 18,
// LogoURI: "https://assets.coingecko.com/coins/images/12504/thumb/uniswap-uni.png?1600306604",
// },
// },
// Version: struct {
// Major int `json:"major"`
// Minor int `json:"minor"`
// Patch int `json:"patch"`
// }{141, 4, 0},
// }
cases := []struct {
name string
server *httptest.Server
Expand All @@ -200,14 +145,34 @@ func TestClient_ListAllTokensByAssetPlatformID(t *testing.T) {
wantedResult *ListAllTokensResponse
wantedErrStr string
}{
// {
// name: "success",
// server: mockHTTPServer(t, resp),
// id: "polygon-pos",
// wantedIsErr: false,
// wantedResult: resp,
// wantedErrStr: "",
// },
{
name: "success",
server: mockStringHTTPServer(t, `{"name":"CoinGecko","logoURI":"https://www.coingecko.com/assets/thumbnail-007177f3eca19695592f0b8b0eabbdae282b54154e1be912285c9034ea6cbaf2.png","keywords": ["defi"],"timestamp": "2022-10-21T02:05:57.841+00:00","tokens": [{"chainId":137,"address":"0xb33eaad8d922b1083446dc23f610c2567fb5180f","name":"Uniswap","symbol":"UNI","decimals":18,"logoURI":"https://assets.coingecko.com/coins/images/12504/thumb/uniswap-uni.png?1600306604"}],"version":{"major":141,"minor":4,"patch":0}}`),
id: "polygon-pos",
wantedIsErr: false,
wantedResult: &ListAllTokensResponse{
Name: "CoinGecko",
LogoURI: "https://www.coingecko.com/assets/thumbnail-007177f3eca19695592f0b8b0eabbdae282b54154e1be912285c9034ea6cbaf2.png",
Keywords: []string{"defi"},
Timestamp: "2022-10-21T02:05:57.841+00:00",
Tokens: []TokensListAllItem{
{
ChainID: 137,
Address: "0xb33eaad8d922b1083446dc23f610c2567fb5180f",
Name: "Uniswap",
Symbol: "UNI",
Decimals: 18,
LogoURI: "https://assets.coingecko.com/coins/images/12504/thumb/uniswap-uni.png?1600306604",
},
},
Version: struct {
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
}{141, 4, 0},
},
wantedErrStr: "",
},
{
name: "empty id param",
id: "",
Expand Down
8 changes: 8 additions & 0 deletions coingecko/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func mockHTTPServer(t *testing.T, resp any) *httptest.Server {
return svr
}

func mockStringHTTPServer(t *testing.T, resp string) *httptest.Server {
t.Helper()
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(resp))
}))
return svr
}

func mockErrorHTTPServer(t *testing.T) *httptest.Server {
t.Helper()
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 2 additions & 4 deletions coingecko/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,15 @@ type NFTTickersResponse struct {

// CoinCirculatingSupplyChartResponse returned by GetCirculatingSupplyChartByCoinID API.
type CoinCirculatingSupplyChartResponse struct {
CirculatingSupply []struct {
CoinsIDCirculatingSupplyChartItem
} `json:"circulating_supply"`
CirculatingSupply []CoinsIDCirculatingSupplyChartItem `json:"circulating_supply"`
}

// ListAllTokensResponse returned by ListAllTokensByAssetPlatformID API.
type ListAllTokensResponse struct {
Name string `json:"name"`
LogoURI string `json:"logoURI"`
Keywords []string `json:"keywords"`
Timestamp time.Time `json:"timestamp"`
Timestamp string `json:"timestamp"`
Tokens []TokensListAllItem `json:"tokens"`
Version struct {
Major int `json:"major"`
Expand Down
9 changes: 0 additions & 9 deletions coingecko/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,3 @@ type TokensListAllItem struct {
Decimals int `json:"decimals"`
LogoURI string `json:"logoURI"`
}

// {
// "chainId": 137,
// "address": "0x52468c88e8b4f5bcca20a6a7813355637dc5e3ad",
// "name": "Power Of Deep Ocean",
// "symbol": "PODO",
// "decimals": 18,
// "logoURI": "https://assets.coingecko.com/coins/images/27645/thumb/PODO_TICKER_200.png?1665020330"
// },

0 comments on commit 8564cba

Please sign in to comment.