-
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.
- Loading branch information
Showing
15 changed files
with
278 additions
and
17 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
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 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 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 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import {CardFactoryMock} from "./utils/mocks/CardFactoryMock.sol"; | ||
import {EurB} from "../src/token/EurB.sol"; | ||
import {Test} from "../lib/forge-std/src/Test.sol"; | ||
import {Users} from "./utils/Types.sol"; | ||
|
||
/// @notice Base test contract with common logic needed by all tests. | ||
abstract contract Base_Test is Test { | ||
/*////////////////////////////////////////////////////////////////////////// | ||
CONSTANTS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
Users internal users; | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
TEST CONTRACTS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
SET-UP FUNCTION | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
constructor() {} | ||
|
||
function setUp() public virtual { | ||
// Create users for testing. | ||
users = Users({ | ||
dao: createUser("dao"), | ||
treasury: createUser("treasury"), | ||
unprivilegedAddress: createUser("unprivilegedAddress") | ||
}); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
HELPER FUNCTIONS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Generates a user, labels its address, and funds it with test assets. | ||
function createUser(string memory name) internal returns (address payable) { | ||
address payable user = payable(makeAddr(name)); | ||
vm.deal({account: user, newBalance: 100 ether}); | ||
return user; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import {EurB_Fuzz_Test} from "./_EurB.fuzz.t.sol"; | ||
|
||
import {EurB} from "../../../src/token/EurB.sol"; | ||
import {IERC20} from "../../../lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol"; | ||
|
||
/** | ||
* @notice Fuzz tests for the function "constructor" of contract "EurB". | ||
*/ | ||
contract Constructor_EurB_Fuzz_Test is EurB_Fuzz_Test { | ||
/* /////////////////////////////////////////////////////////////// | ||
SETUP | ||
/////////////////////////////////////////////////////////////// */ | ||
|
||
function setUp() public override { | ||
EurB_Fuzz_Test.setUp(); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
TESTS | ||
//////////////////////////////////////////////////////////////*/ | ||
function testFuzz_Success_deployment(address treasury) public { | ||
// When: Deploying EURB. | ||
vm.prank(users.dao); | ||
EurB eurB = new EurB(IERC20(address(EURE)), treasury, address(CARD_FACTORY)); | ||
|
||
// Then: Correct variables should be set. | ||
assertEq(address(eurB.underlying()), address(EURE)); | ||
assertEq(eurB.treasury(), treasury); | ||
assertEq(eurB.owner(), users.dao); | ||
assertEq(eurB.name(), "EuroBrussels"); | ||
assertEq(eurB.symbol(), "EURB"); | ||
assertEq(address(eurB.cardFactory()), address(CARD_FACTORY)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import {Fuzz_Test} from "../Fuzz.t.sol"; | ||
|
||
/** | ||
* @notice Common logic needed by all "EurB" fuzz tests. | ||
*/ | ||
abstract contract EurB_Fuzz_Test is Fuzz_Test { | ||
/* /////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
/////////////////////////////////////////////////////////////// */ | ||
|
||
/* /////////////////////////////////////////////////////////////// | ||
TEST CONTRACTS | ||
/////////////////////////////////////////////////////////////// */ | ||
|
||
/* /////////////////////////////////////////////////////////////// | ||
SETUP | ||
/////////////////////////////////////////////////////////////// */ | ||
|
||
function setUp() public virtual override(Fuzz_Test) { | ||
Fuzz_Test.setUp(); | ||
} | ||
|
||
/* /////////////////////////////////////////////////////////////// | ||
HELPER FUNCTIONS | ||
/////////////////////////////////////////////////////////////// */ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import {Base_Test} from "../Base.t.sol"; | ||
import {CardFactoryMock} from "../utils/mocks/CardFactoryMock.sol"; | ||
import {CommissionModule} from "../../src/modules/CommissionModule.sol"; | ||
import {ERC20Mock} from "../utils/mocks/ERC20Mock.sol"; | ||
import {EurB} from "../../src/token/EurB.sol"; | ||
import {IERC20} from "../../lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol"; | ||
import {SafeMock} from "../utils/mocks/SafeMock.sol"; | ||
|
||
/** | ||
* @notice Common logic needed by all fuzz tests. | ||
*/ | ||
abstract contract Fuzz_Test is Base_Test { | ||
/*////////////////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
TEST CONTRACTS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
CardFactoryMock public CARD_FACTORY; | ||
CommissionModule public COMMISSION_MODULE; | ||
ERC20Mock public EURE; | ||
EurB public EURB; | ||
|
||
SafeMock public SAFE1; | ||
SafeMock public SAFE2; | ||
SafeMock public SAFE3; | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
SET-UP FUNCTION | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
function setUp() public virtual override { | ||
Base_Test.setUp(); | ||
|
||
// Warp to have a timestamp of at least two days old. | ||
vm.warp(2 days); | ||
|
||
// Deploy contracts. | ||
vm.startPrank(users.dao); | ||
COMMISSION_MODULE = new CommissionModule(); | ||
CARD_FACTORY = new CardFactoryMock(address(COMMISSION_MODULE)); | ||
EURE = new ERC20Mock("Monerium EUR", "EURE", 18); | ||
EURB = new EurB(IERC20(address(EURE)), users.treasury, address(CARD_FACTORY)); | ||
|
||
SAFE1 = new SafeMock(); | ||
SAFE2 = new SafeMock(); | ||
SAFE3 = new SafeMock(); | ||
vm.stopPrank(); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
HELPERS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
struct Users { | ||
address payable dao; | ||
address payable treasury; | ||
address payable unprivilegedAddress; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
contract CardFactoryMock { | ||
address public COMMISSION_HOOK_MODULE; | ||
|
||
constructor(address commissionHookModule) { | ||
COMMISSION_HOOK_MODULE = commissionHookModule; | ||
} | ||
|
||
function setCommissionHookModule(address commissionHookModule) public { | ||
COMMISSION_HOOK_MODULE = commissionHookModule; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import {ERC20} from "../../../lib/solmate/src/tokens/ERC20.sol"; | ||
|
||
contract ERC20Mock is ERC20 { | ||
constructor(string memory name_, string memory symbol_, uint8 decimalsInput_) | ||
ERC20(name_, symbol_, decimalsInput_) | ||
{} | ||
|
||
function mint(address to, uint256 amount) public { | ||
_mint(to, amount); | ||
} | ||
|
||
function burn(uint256 amount) public { | ||
_burn(msg.sender, amount); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
contract SafeMock { | ||
mapping(address module => bool enabled) public moduleEnabled; | ||
|
||
function setModule(address module) external { | ||
moduleEnabled[module] = true; | ||
} | ||
|
||
function removeModule(address module) external { | ||
moduleEnabled[module] = false; | ||
} | ||
|
||
function isModuleEnabled(address module) external view returns (bool enabled) { | ||
enabled = moduleEnabled[module]; | ||
} | ||
} |