generated from BreadchainCoop/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update deploy scripts and integration tests to make better …
…use of common scripts
- Loading branch information
Showing
8 changed files
with
91 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.28; | ||
|
||
import {IERC20} from '@openzeppelin/token/ERC20/IERC20.sol'; | ||
import {Greeter, IGreeter} from 'contracts/Greeter.sol'; | ||
import {ProxyAdmin} from '@openzeppelin/proxy/transparent/ProxyAdmin.sol'; | ||
import {TransparentUpgradeableProxy} from '@openzeppelin/proxy/transparent/TransparentUpgradeableProxy.sol'; | ||
import {Script} from 'forge-std/Script.sol'; | ||
// solhint-disable-next-line | ||
import 'script/Registry.sol'; | ||
|
||
import {SavingCircles} from '../src/contracts/SavingCircles.sol'; | ||
|
||
/** | ||
* @title Common Contract | ||
* @author Breadchain | ||
* @notice This contract is used to deploy the Greeter contract | ||
* @notice This contract is used to deploy an upgradable Saving Circles contract | ||
* @dev This contract is intended for use in Scripts and Integration Tests | ||
*/ | ||
contract Common is Script { | ||
struct DeploymentParams { | ||
string greeting; | ||
IERC20 token; | ||
} | ||
|
||
IGreeter public greeter; | ||
function setUp() public virtual {} | ||
|
||
/// @notice Deployment parameters for each chain | ||
mapping(uint256 _chainId => DeploymentParams _params) internal _deploymentParams; | ||
|
||
function setUp() public virtual { | ||
// Optimism | ||
_deploymentParams[10] = DeploymentParams('Hello, Optimism!', IERC20(OPTIMISM_DAI)); | ||
function _deploySavingCircles() internal returns (SavingCircles) { | ||
return new SavingCircles(); | ||
} | ||
|
||
// Gnosis | ||
_deploymentParams[100] = DeploymentParams('Hello, Gnosis!', IERC20(GNOSIS_BREAD)); | ||
function _deployProxyAdmin(address _admin) internal returns (ProxyAdmin) { | ||
return new ProxyAdmin(_admin); | ||
} | ||
|
||
function _deployContracts() internal { | ||
DeploymentParams memory _params = _deploymentParams[block.chainid]; | ||
function _deployTransparentProxy( | ||
address _implementation, | ||
address _proxyAdmin, | ||
bytes memory _initData | ||
) internal returns (TransparentUpgradeableProxy) { | ||
return new TransparentUpgradeableProxy(_implementation, _proxyAdmin, _initData); | ||
} | ||
|
||
greeter = new Greeter(_params.greeting, _params.token); | ||
function _deployContracts(address _admin) internal returns (TransparentUpgradeableProxy) { | ||
return _deployTransparentProxy( | ||
address(_deploySavingCircles()), | ||
address(_deployProxyAdmin(_admin)), | ||
abi.encodeWithSelector(SavingCircles.initialize.selector, _admin) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,83 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.28; | ||
|
||
import {IERC20} from '@openzeppelin/token/ERC20/IERC20.sol'; | ||
import {Test} from 'forge-std/Test.sol'; | ||
import {Common} from 'script/Common.sol'; | ||
|
||
import {SavingCircles} from '../../src/contracts/SavingCircles.sol'; | ||
import {ISavingCircles} from '../../src/interfaces/ISavingCircles.sol'; | ||
import {MockERC20} from '../mocks/MockERC20.sol'; | ||
|
||
// solhint-disable-next-line | ||
import 'script/Registry.sol'; | ||
|
||
contract IntegrationBase is Common, Test { | ||
uint256 public constant INIT_BALANCE = 1 ether; | ||
SavingCircles public circle; | ||
MockERC20 public token; | ||
|
||
address public user = makeAddr('user'); | ||
address public alice = makeAddr('alice'); | ||
address public bob = makeAddr('bob'); | ||
address public carol = makeAddr('carol'); | ||
address public owner = makeAddr('owner'); | ||
address[] public members; | ||
|
||
ISavingCircles.Circle public baseCircle; | ||
|
||
IERC20 public bread = IERC20(GNOSIS_BREAD); | ||
string public constant BASE_CIRCLE_NAME = 'Test Circle'; | ||
uint256 public constant DEPOSIT_AMOUNT = 1000e18; | ||
uint256 public constant DEPOSIT_INTERVAL = 7 days; | ||
uint256 public constant BASE_CURRENT_INDEX = 0; | ||
uint256 public constant BASE_MAX_DEPOSITS = 1000; | ||
bytes32 public constant BASE_CIRCLE_ID = keccak256(abi.encodePacked(BASE_CIRCLE_NAME)); | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
vm.createSelectFork(vm.rpcUrl('gnosis')); | ||
|
||
vm.startPrank(owner); | ||
circle = SavingCircles(address(_deployContracts(owner))); | ||
token = new MockERC20('Test Token', 'TEST'); | ||
vm.stopPrank(); | ||
|
||
_setUpAccounts(); | ||
|
||
baseCircle = ISavingCircles.Circle({ | ||
owner: alice, | ||
name: BASE_CIRCLE_NAME, | ||
members: members, | ||
currentIndex: BASE_CURRENT_INDEX, | ||
circleStart: block.timestamp, | ||
token: address(token), | ||
depositAmount: DEPOSIT_AMOUNT, | ||
depositInterval: DEPOSIT_INTERVAL, | ||
maxDeposits: BASE_MAX_DEPOSITS | ||
}); | ||
} | ||
|
||
/// @dev deploy contracts methods are located in script/Common.sol | ||
_deployContracts(); | ||
function createBaseCircle() public { | ||
vm.prank(owner); | ||
circle.setTokenAllowed(address(token), true); | ||
|
||
vm.prank(alice); | ||
circle.create(baseCircle); | ||
} | ||
|
||
function _setUpAccounts() internal { | ||
vm.startPrank(alice); | ||
token.mint(alice, DEPOSIT_AMOUNT * 10); | ||
token.approve(address(circle), type(uint256).max); | ||
members.push(alice); | ||
vm.stopPrank(); | ||
|
||
vm.startPrank(bob); | ||
token.mint(bob, DEPOSIT_AMOUNT * 10); | ||
token.approve(address(circle), type(uint256).max); | ||
members.push(bob); | ||
vm.stopPrank(); | ||
|
||
vm.startPrank(carol); | ||
token.mint(carol, DEPOSIT_AMOUNT * 10); | ||
token.approve(address(circle), type(uint256).max); | ||
members.push(carol); | ||
vm.stopPrank(); | ||
deal(GNOSIS_BREAD, address(greeter), INIT_BALANCE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.