2023-02-21 09:05:16 +00:00
|
|
|
package opensea
|
2021-08-20 19:53:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-02-28 03:10:38 +00:00
|
|
|
"math/big"
|
2021-08-20 19:53:24 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2023-02-28 03:10:38 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/bigint"
|
|
|
|
|
2021-08-20 19:53:24 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFetchAllCollectionsByOwner(t *testing.T) {
|
2023-02-28 03:10:38 +00:00
|
|
|
expected := []OwnedCollection{{
|
|
|
|
Collection: Collection{
|
|
|
|
Name: "Rocky",
|
|
|
|
Slug: "rocky",
|
|
|
|
ImageURL: "ImageUrl",
|
|
|
|
},
|
|
|
|
OwnedAssetCount: &bigint.BigInt{Int: big.NewInt(1)},
|
|
|
|
}}
|
2021-08-20 19:53:24 +00:00
|
|
|
response, _ := json.Marshal(expected)
|
|
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(200)
|
|
|
|
_, err := w.Write(response)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
defer srv.Close()
|
|
|
|
|
2023-02-21 09:05:16 +00:00
|
|
|
opensea := &Client{
|
2021-08-20 19:53:24 +00:00
|
|
|
client: srv.Client(),
|
|
|
|
url: srv.URL,
|
|
|
|
}
|
2023-02-21 09:05:16 +00:00
|
|
|
res, err := opensea.FetchAllCollectionsByOwner(common.Address{1})
|
2021-08-20 19:53:24 +00:00
|
|
|
assert.Equal(t, expected, res)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFetchAllAssetsByOwnerAndCollection(t *testing.T) {
|
2023-02-28 03:10:38 +00:00
|
|
|
expected := []Asset{{
|
2021-08-20 19:53:24 +00:00
|
|
|
ID: 1,
|
|
|
|
Name: "Rocky",
|
|
|
|
Description: "Rocky Balboa",
|
|
|
|
Permalink: "permalink",
|
|
|
|
ImageThumbnailURL: "ImageThumbnailURL",
|
|
|
|
ImageURL: "ImageUrl",
|
2023-02-21 09:05:16 +00:00
|
|
|
Contract: Contract{Address: "1"},
|
2023-02-28 03:10:38 +00:00
|
|
|
Collection: Collection{Name: "Rocky"},
|
2021-08-20 19:53:24 +00:00
|
|
|
}}
|
2023-02-21 09:05:16 +00:00
|
|
|
response, _ := json.Marshal(AssetContainer{Assets: expected})
|
2021-08-20 19:53:24 +00:00
|
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(200)
|
|
|
|
_, err := w.Write(response)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
defer srv.Close()
|
|
|
|
|
2023-02-21 09:05:16 +00:00
|
|
|
opensea := &Client{
|
2021-08-20 19:53:24 +00:00
|
|
|
client: srv.Client(),
|
|
|
|
url: srv.URL,
|
|
|
|
}
|
2023-02-21 09:05:16 +00:00
|
|
|
res, err := opensea.FetchAllAssetsByOwnerAndCollection(common.Address{1}, "rocky", 200)
|
2021-08-20 19:53:24 +00:00
|
|
|
assert.Equal(t, expected, res)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|