-
Notifications
You must be signed in to change notification settings - Fork 2
/
collection_test.go
45 lines (38 loc) · 975 Bytes
/
collection_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package opensea
import (
"math"
"math/big"
"testing"
)
func TestCollection(t *testing.T) {
req := CollectionRequest{
CollectionSlug: "mineablepunks",
}
if collection, err := client.Collection(&req); err != nil {
t.Error(err)
} else {
t.Log(EthToWei(collection.Stats.FloorPrice))
}
}
func TestCollectionStats(t *testing.T) {
req := CollectionRequest{
CollectionSlug: "hpprs-collection",
}
if stats, err := client.CollectionStats(&req); err != nil {
t.Error(err)
} else {
t.Log(stats.FloorPrice)
}
}
// EthToWei converts Gwei as a float to Wei as a big int
func EthToWei(n float64) *big.Int {
return floatToBigInt(n, 18)
}
func floatToBigInt(amount float64, decimal int64) *big.Int {
// 6 is our smallest precision
if decimal < 6 {
return big.NewInt(int64(amount * math.Pow10(int(decimal))))
}
result := big.NewInt(int64(amount * math.Pow10(6)))
return result.Mul(result, big.NewInt(0).Exp(big.NewInt(10), big.NewInt(decimal-6), nil))
}