Skip to content

Commit

Permalink
test: bPool unit tests scaffolding (#8)
Browse files Browse the repository at this point in the history
* test: wip initial test structure

* test: complete scaffolding

* test: add happy path for joinPool

* test: wip

* test: tweak assume

* test: wip, improve fuzzing

* test: improve assume

* test: assumes are working now

* test: increase tokens to 8

* test: finish happyPath for joinPool

* fix: lint

* test: improve happyPath

* fix: avoid empty tests from running

* test: small improvements

* fix: small compilation error

* test: create Utils library

* fix: moving happy path to specific test contract (#11)

* fix: moving happy path to specific test contract

* fix: linter errors

* feat: adding smock package (#10)

* feat: adding smock package

* fix: moving happy path to specific test contract

* fix: linter errors

* feat: implementing smock to unit test

* fix: adding smock to ci

* fix: ci

* fix: addressing comments in pr

---------

Co-authored-by: Weißer Hase <[email protected]>
Co-authored-by: Weißer Hase <[email protected]>
  • Loading branch information
3 people authored May 9, 2024
1 parent 7efd54a commit 1a87b42
Show file tree
Hide file tree
Showing 12 changed files with 788 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1

- name: Create mock files with smock
run: yarn smock

- name: Precompile using 0.8.14 and via-ir=false
run: yarn build

Expand Down Expand Up @@ -58,6 +61,9 @@ jobs:
- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1

- name: Create mock files with smock
run: yarn smock

- name: Precompile using 0.8.14 and via-ir=false
run: yarn build

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ broadcast/*/*/*

# Out dir
out

# Smock dir
test/smock
5 changes: 4 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"immutable-name-snakecase": "warn",
"avoid-low-level-calls": "off",
"no-console": "off",
"max-line-length": ["warn", 120]
"max-line-length": ["warn", 120],
"TODO": "REMOVE_TEMPORARY_LINTER_SETTINGS_BELOW",
"custom-errors": "warn",
"definition-name-capwords": "warn"
}
}
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ src = 'src/interfaces/'

[fuzz]
runs = 1000
max_test_rejects = 500000

[rpc_endpoints]
mainnet = "${MAINNET_RPC}"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"lint:sol-logic": "solhint -c .solhint.json 'src/**/*.sol' 'script/**/*.sol'",
"lint:sol-tests": "solhint -c .solhint.tests.json 'test/**/*.sol'",
"prepare": "husky install",
"smock": "smock-foundry --contracts src/contracts",
"test": "forge test -vvv",
"test:integration": "forge test --match-contract Integration -vvv",
"test:unit": "forge test --match-contract Unit -vvv",
Expand All @@ -36,12 +37,13 @@
"package.json": "sort-package-json"
},
"dependencies": {
"solmate": "github:transmissions11/solmate#a9e3ea2"
"solmate": "github:transmissions11/solmate#c892309"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@defi-wonderland/natspec-smells": "1.1.1",
"@defi-wonderland/smock-foundry": "1.5.0",
"forge-std": "github:foundry-rs/forge-std#5475f85",
"husky": ">=8",
"lint-staged": ">=10",
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/BFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract BFactory is BBronze {

event LOG_BLABS(address indexed caller, address indexed blabs);

Check warning on line 23 in src/contracts/BFactory.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

event name must be in CapWords

mapping(address => bool) private _isBPool;
mapping(address => bool) internal _isBPool;

Check warning on line 25 in src/contracts/BFactory.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, state variable declaration can not go after event definition (line 23)

function isBPool(address b) external view returns (bool) {
return _isBPool[b];
Expand All @@ -36,7 +36,7 @@ contract BFactory is BBronze {
return bpool;
}

address private _blabs;
address internal _blabs;

constructor() {
_blabs = msg.sender;
Expand Down
20 changes: 10 additions & 10 deletions src/contracts/BPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import './BToken.sol';
contract BPool is BBronze, BToken, BMath {
struct Record {
bool bound; // is token bound to pool
uint256 index; // private
uint256 index; // internal
uint256 denorm; // denormalized weight
uint256 balance;
}
Expand Down Expand Up @@ -55,20 +55,20 @@ contract BPool is BBronze, BToken, BMath {
_;
}

bool private _mutex;
bool internal _mutex;

address private _factory; // BFactory address to push token exitFee to
address private _controller; // has CONTROL role
bool private _publicSwap; // true if PUBLIC can call SWAP functions
address internal _factory; // BFactory address to push token exitFee to
address internal _controller; // has CONTROL role
bool internal _publicSwap; // true if PUBLIC can call SWAP functions

// `setSwapFee` and `finalize` require CONTROL
// `finalize` sets `PUBLIC can SWAP`, `PUBLIC can JOIN`
uint256 private _swapFee;
bool private _finalized;
uint256 internal _swapFee;
bool internal _finalized;

address[] private _tokens;
mapping(address => Record) private _records;
uint256 private _totalWeight;
address[] internal _tokens;
mapping(address => Record) internal _records;
uint256 internal _totalWeight;

constructor() {
_controller = msg.sender;
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/BToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ abstract contract BTokenBase is BNum, IERC20 {
}

contract BToken is BTokenBase {
string private _name = 'Balancer Pool Token';
string private _symbol = 'BPT';
uint8 private _decimals = 18;
string internal _name = 'Balancer Pool Token';
string internal _symbol = 'BPT';
uint8 internal _decimals = 18;

function name() public view returns (string memory) {
return _name;
Expand Down
23 changes: 0 additions & 23 deletions src/contracts/Migrations.sol

This file was deleted.

Loading

0 comments on commit 1a87b42

Please sign in to comment.