curve-crypto-contract
curve-crypto-contract copied to clipboard
bug report: wrong input params in newton_y() test case
Wrong input params of test_newton_y()
The parameters here need to be modified, from A * 3**3 * 10000
to A
https://github.com/curvefi/curve-crypto-contract/blob/master/tests/tricrypto/test_math.py#L114
A_MUL = 10000 * 3**3
MIN_A = int(0.01 * A_MUL)
MAX_A = 1000 * A_MUL
...
# MIN_A and MAX_A have multiplied N**N * A_MUL.
@given(
A=strategy('uint256', min_value=MIN_A, max_value=MAX_A),
...
)
@settings(max_examples=MAX_SAMPLES)
def test_newton_y(crypto_math, A, D, xD, yD, zD, gamma, j):
...
try:
# A is already ANN now, shouldn't multiply N**N * A_MUL any more.
result_contract = crypto_math.newton_y(A * 3**3 * 10000, gamma, X, D, j)
except Exception:
...
Params given by strategy are always inappropriate to newton's method
For example, run test of newton_D()
, strategy will give 50 sets of input data, may only a few of them fit. Most of them could not match the condition, causes the test cannot be performed effectively.
The main reason for improper test data is that yx
or zx
is too small, causes the xp in newton_D are very imbalanced. So the result of python simulation always fails to match the conditions.
@given(
A=strategy('uint256', min_value=MIN_A, max_value=MAX_A),
x=strategy('uint256', min_value=10**9, max_value=10**14 * 10**18), # 1e-9 USD to 100T USD
yx=strategy('uint256', min_value=int(1.1e11), max_value=10**18), # <- ratio 1e18 * y/x, typically 1e18 * 1
zx=strategy('uint256', min_value=int(1.1e11), max_value=10**18), # <- ratio 1e18 * z/x, typically 1e18 * 1
perm=strategy('uint8', max_value=5), # Permutation
gamma=strategy('uint256', min_value=MIN_GAMMA, max_value=MAX_GAMMA)
)
@settings(max_examples=MAX_SAMPLES)
def test_newton_D(crypto_math, A, x, yx, zx, perm, gamma):
...
# Most of test data would not match the condition below.
# Because the xps of the pool are very imbalanced.
if all(f >= 1.1e16 and f <= 0.9e20 for f in [_x * 10**18 / result_sim for _x in X]):
# Very few test data could reach here
result_contract = crypto_math.newton_D(A, gamma, X)
newton_y()
test case has the same problem.