/
tick_math_test.go
40 lines (31 loc) · 1.36 KB
/
tick_math_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
package uniswap_v3_simulator
import (
"github.com/daoleno/uniswapv3-sdk/constants"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"math/big"
"testing"
)
func TestGetSqrtRatioAtTick(t *testing.T) {
_, err := GetSqrtRatioAtTick(MIN_TICK - 1)
assert.ErrorIs(t, err, INVALID_TICK, "tick tool small")
_, err = GetSqrtRatioAtTick(MAX_TICK + 1)
assert.ErrorIs(t, err, INVALID_TICK, "tick tool large")
rmax, _ := GetSqrtRatioAtTick(MIN_TICK)
assert.Equal(t, rmax, MIN_SQRT_RATIO, "returns the correct value for min tick")
r0, _ := GetSqrtRatioAtTick(0)
assert.Condition(t, func() (success bool) {
return r0.Equal(decimal.NewFromBigInt(new(big.Int).Lsh(constants.One, 96), 0))
})
rmin, _ := GetSqrtRatioAtTick(MAX_TICK)
assert.Equal(t, rmin, MAX_SQRT_RATIO, "returns the correct value for max tick")
}
func TestGetTickAtSqrtRatio(t *testing.T) {
tmin, _ := GetTickAtSqrtRatio(MIN_SQRT_RATIO)
assert.Equal(t, tmin, MIN_TICK, "returns the correct value for sqrt ratio at min tick")
tmax, _ := GetTickAtSqrtRatio(MAX_SQRT_RATIO.Sub(ONE))
assert.Equal(t, tmax, MAX_TICK-1, "returns the correct value for sqrt ratio at max tick")
r, _ := new(big.Int).SetString("79228162514264337593543950336", 10)
tRandom, _ := GetTickAtSqrtRatio(decimal.NewFromBigInt(r, 0))
assert.Equal(t, tRandom, 0, "returns the correct value for sqrt ratio at random tick")
}