@@ -22,12 +22,12 @@ func TestSwapMathComputeSwapStepStr(t *testing.T) {
22
22
}{
23
23
{
24
24
name: "exact amount in that gets capped at price target in one for zero",
25
- currentX96: encodePriceSqrt("1", "1"),
26
- targetX96: encodePriceSqrt("101", "100"),
25
+ currentX96: encodePriceSqrt(t, "1", "1"),
26
+ targetX96: encodePriceSqrt(t, "101", "100"),
27
27
liquidity: u256.MustFromDecimal("2000000000000000000"),
28
28
amountRemaining: i256.MustFromDecimal("1000000000000000000"),
29
29
feePips: 600,
30
- sqrtNextX96: encodePriceSqrt("101", "100"),
30
+ sqrtNextX96: encodePriceSqrt(t, "101", "100"),
31
31
chkSqrtNextX96: func(sqrtRatioNextX96, priceTarget *u256.Uint) {
32
32
uassert.True(t, sqrtRatioNextX96.Eq(priceTarget))
33
33
},
@@ -37,12 +37,12 @@ func TestSwapMathComputeSwapStepStr(t *testing.T) {
37
37
},
38
38
{
39
39
name: "exact amount out that gets capped at price target in one for zero",
40
- currentX96: encodePriceSqrt("1", "1"),
41
- targetX96: encodePriceSqrt("101", "100"),
40
+ currentX96: encodePriceSqrt(t, "1", "1"),
41
+ targetX96: encodePriceSqrt(t, "101", "100"),
42
42
liquidity: u256.MustFromDecimal("2000000000000000000"),
43
43
amountRemaining: i256.MustFromDecimal("-1000000000000000000"),
44
44
feePips: 600,
45
- sqrtNextX96: encodePriceSqrt("101", "100"),
45
+ sqrtNextX96: encodePriceSqrt(t, "101", "100"),
46
46
chkSqrtNextX96: func(sqrtRatioNextX96, priceTarget *u256.Uint) {
47
47
uassert.True(t, sqrtRatioNextX96.Eq(priceTarget))
48
48
},
@@ -52,11 +52,11 @@ func TestSwapMathComputeSwapStepStr(t *testing.T) {
52
52
},
53
53
{
54
54
name: "exact amount in that is fully spent in one for zero",
55
- currentX96: encodePriceSqrt("1", "1"),
56
- targetX96: encodePriceSqrt("1000", "100"),
55
+ currentX96: encodePriceSqrt(t, "1", "1"),
56
+ targetX96: encodePriceSqrt(t, "1000", "100"),
57
57
liquidity: u256.MustFromDecimal("2000000000000000000"),
58
58
amountRemaining: i256.MustFromDecimal("1000000000000000000"),
59
- sqrtNextX96: encodePriceSqrt("1000", "100"),
59
+ sqrtNextX96: encodePriceSqrt(t, "1000", "100"),
60
60
feePips: 600,
61
61
chkSqrtNextX96: func(sqrtRatioNextX96, priceTarget *u256.Uint) {
62
62
uassert.True(t, sqrtRatioNextX96.Lte(priceTarget))
@@ -67,12 +67,12 @@ func TestSwapMathComputeSwapStepStr(t *testing.T) {
67
67
},
68
68
{
69
69
name: "exact amount out that is fully received in one for zero",
70
- currentX96: encodePriceSqrt("1", "1"),
71
- targetX96: encodePriceSqrt("1000", "100"),
70
+ currentX96: encodePriceSqrt(t, "1", "1"),
71
+ targetX96: encodePriceSqrt(t, "1000", "100"),
72
72
liquidity: u256.MustFromDecimal("2000000000000000000"),
73
73
amountRemaining: i256.MustFromDecimal("-1000000000000000000"),
74
74
feePips: 600,
75
- sqrtNextX96: encodePriceSqrt("1000", "100"),
75
+ sqrtNextX96: encodePriceSqrt(t, "1000", "100"),
76
76
chkSqrtNextX96: func(sqrtRatioNextX96, priceTarget *u256.Uint) {
77
77
uassert.True(t, sqrtRatioNextX96.Lt(priceTarget))
78
78
},
@@ -169,7 +169,9 @@ func TestSwapMathComputeSwapStepStr(t *testing.T) {
169
169
}
170
170
171
171
// encodePriceSqrt calculates the sqrt((reserve1 << 192) / reserve0)
172
- func encodePriceSqrt(reserve1, reserve0 string) *u256.Uint {
172
+ func encodePriceSqrt(t *testing.T, reserve1, reserve0 string) *u256.Uint {
173
+ t.Helper()
174
+
173
175
reserve1Uint := u256.MustFromDecimal(reserve1)
174
176
reserve0Uint := u256.MustFromDecimal(reserve0)
175
177
@@ -185,11 +187,13 @@ func encodePriceSqrt(reserve1, reserve0 string) *u256.Uint {
185
187
ratioX192 := new(u256.Uint).Div(numerator, reserve0Uint)
186
188
187
189
// Return sqrt(ratioX192)
188
- return sqrt(ratioX192)
190
+ return sqrt(t, ratioX192)
189
191
}
190
192
191
193
// sqrt computes the integer square root of a u256.Uint
192
- func sqrt(x *u256.Uint) *u256.Uint {
194
+ func sqrt(t *testing.T, x *u256.Uint) *u256.Uint {
195
+ t.Helper()
196
+
193
197
if x.IsZero() {
194
198
return u256.NewUint(0)
195
199
}
0 commit comments