Skip to content

Commit

Permalink
Add variable token precision for ERC721Pool invariants (#755)
Browse files Browse the repository at this point in the history
* Add multiple precision of quote token in erc721Pool invariants

* Add shebang and set -e option
  • Loading branch information
prateek105 authored Apr 26, 2023
1 parent 2be0f7b commit 02b6082
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ make test-invariant-erc721 QUOTE_PRECISION=<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
Expand Down
2 changes: 2 additions & 0 deletions tests/forge/invariants/test-invariant-erc20-buckets.sh
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 2 additions & 0 deletions tests/forge/invariants/test-invariant-erc20-precision.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
set -e
for quote_precision in 6 8 18
do
for collateral_precision in 6 8 18
Expand Down
2 changes: 2 additions & 0 deletions tests/forge/invariants/test-invariant-erc721-buckets.sh
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
6 changes: 6 additions & 0 deletions tests/forge/invariants/test-invariant-erc721-precision.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 02b6082

Please sign in to comment.