From 02b6082542526b62b8c689bde22f87db31681a66 Mon Sep 17 00:00:00 2001 From: Prateek Gupta Date: Wed, 26 Apr 2023 10:55:24 +0530 Subject: [PATCH] Add variable token precision for ERC721Pool invariants (#755) * Add multiple precision of quote token in erc721Pool invariants * Add shebang and set -e option --- Makefile | 27 ++++++++++--------- tests/README.md | 3 +++ .../test-invariant-erc20-buckets.sh | 2 ++ .../test-invariant-erc20-precision.sh | 2 ++ .../test-invariant-erc721-buckets.sh | 2 ++ .../test-invariant-erc721-precision.sh | 6 +++++ 6 files changed, 29 insertions(+), 13 deletions(-) create mode 100755 tests/forge/invariants/test-invariant-erc721-precision.sh diff --git a/Makefile b/Makefile index e0d3f619a..e14e2ba83 100644 --- a/Makefile +++ b/Makefile @@ -23,19 +23,20 @@ install :; git submodule update --init --recursive build :; forge clean && forge build # Tests -test :; forge test --no-match-test "testLoad|invariant|test_regression" # --ffi # enable if you need the `ffi` cheat code on HEVM -test-with-gas-report :; forge test --no-match-test "testLoad|invariant|test_regression" --gas-report # --ffi # enable if you need the `ffi` cheat code on HEVM -test-load :; forge test --match-test testLoad --gas-report -test-invariant :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest -test-invariant-erc20 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest --mc ERC20 -test-invariant-erc721 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest --mc ERC721 -test-regression :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression -test-regression-erc20 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression --mc ERC20 -test-regression-erc721 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression --mc ERC721 -coverage :; forge coverage --no-match-test "testLoad|invariant" -test-invariant-erc20-precision :; ./tests/forge/invariants/test-invariant-erc20-precision.sh -test-invariant-erc20-buckets :; ./tests/forge/invariants/test-invariant-erc20-buckets.sh -test-invariant-erc721-buckets :; ./tests/forge/invariants/test-invariant-erc721-buckets.sh +test :; forge test --no-match-test "testLoad|invariant|test_regression" # --ffi # enable if you need the `ffi` cheat code on HEVM +test-with-gas-report :; forge test --no-match-test "testLoad|invariant|test_regression" --gas-report # --ffi # enable if you need the `ffi` cheat code on HEVM +test-load :; forge test --match-test testLoad --gas-report +test-invariant :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest +test-invariant-erc20 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest --mc ERC20 +test-invariant-erc721 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt invariant --nmc RegressionTest --mc ERC721 +test-regression :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression +test-regression-erc20 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} COLLATERAL_PRECISION=${COLLATERAL_PRECISION} BUCKET_INDEX_ERC20=${BUCKET_INDEX_ERC20} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression --mc ERC20 +test-regression-erc721 :; eval QUOTE_PRECISION=${QUOTE_PRECISION} BUCKET_INDEX_ERC721=${BUCKET_INDEX_ERC721} NO_OF_BUCKETS=${NO_OF_BUCKETS} forge t --mt test_regression --mc ERC721 +coverage :; forge coverage --no-match-test "testLoad|invariant" +test-invariant-erc20-precision :; ./tests/forge/invariants/test-invariant-erc20-precision.sh +test-invariant-erc721-precision :; ./tests/forge/invariants/test-invariant-erc721-precision.sh +test-invariant-erc20-buckets :; ./tests/forge/invariants/test-invariant-erc20-buckets.sh +test-invariant-erc721-buckets :; ./tests/forge/invariants/test-invariant-erc721-buckets.sh # Generate Gas Snapshots snapshot :; forge clean && forge snapshot diff --git a/tests/README.md b/tests/README.md index 0f7aa902d..ca66c7949 100644 --- a/tests/README.md +++ b/tests/README.md @@ -36,6 +36,9 @@ make test-invariant-erc721 QUOTE_PRECISION= ```bash make test-invariant-erc20-precision ``` +- run ERC721 Pool invariant tests for most popular token precision(6,8 and 18): +```bash +make test-invariant-erc721-precision - run ERC20 Pool invariant tests for multiple bucket ranges: ```bash make test-invariant-erc20-buckets diff --git a/tests/forge/invariants/test-invariant-erc20-buckets.sh b/tests/forge/invariants/test-invariant-erc20-buckets.sh index 4e76a2c0e..efb3a880e 100755 --- a/tests/forge/invariants/test-invariant-erc20-buckets.sh +++ b/tests/forge/invariants/test-invariant-erc20-buckets.sh @@ -1,3 +1,5 @@ +#!/bin/bash +set -e for bucket_index in 1 500 1500 2500 3500 4500 5500 6500 7369 do make test-invariant-erc20 QUOTE_PRECISION=18 COLLATERAL_PRECISION=18 BUCKET_INDEX_ERC20=${bucket_index} diff --git a/tests/forge/invariants/test-invariant-erc20-precision.sh b/tests/forge/invariants/test-invariant-erc20-precision.sh index 5ef95d260..2aa431a44 100755 --- a/tests/forge/invariants/test-invariant-erc20-precision.sh +++ b/tests/forge/invariants/test-invariant-erc20-precision.sh @@ -1,3 +1,5 @@ +#!/bin/bash +set -e for quote_precision in 6 8 18 do for collateral_precision in 6 8 18 diff --git a/tests/forge/invariants/test-invariant-erc721-buckets.sh b/tests/forge/invariants/test-invariant-erc721-buckets.sh index 897400f1a..f5cad99d8 100755 --- a/tests/forge/invariants/test-invariant-erc721-buckets.sh +++ b/tests/forge/invariants/test-invariant-erc721-buckets.sh @@ -1,3 +1,5 @@ +#!/bin/bash +set -e for bucket_index in 1 500 1500 2500 3500 4500 5500 6500 7369 do make test-invariant-erc721 QUOTE_PRECISION=18 BUCKET_INDEX_ERC721=${bucket_index} diff --git a/tests/forge/invariants/test-invariant-erc721-precision.sh b/tests/forge/invariants/test-invariant-erc721-precision.sh new file mode 100755 index 000000000..3cd205142 --- /dev/null +++ b/tests/forge/invariants/test-invariant-erc721-precision.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e +for quote_precision in 6 8 18 +do + make test-invariant-erc721 QUOTE_PRECISION=${quote_precision} +done \ No newline at end of file