-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: chrismaree <christopher.maree@gmail.com>
- Loading branch information
1 parent
0c2402f
commit e6ed161
Showing
7 changed files
with
185 additions
and
36 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,37 @@ | ||
import {ImmutableUnlockersOvalChainlinkFactory} from "../../src/factories/ImmutableOvalChainlinkFactory.sol"; | ||
import {OvalChainlinkImmutable} from "../../src/factories/ImmutableOvalChainlinkFactory.sol"; | ||
import {IAggregatorV3Source} from "../../src/interfaces/chainlink/IAggregatorV3Source.sol"; | ||
import {MockChainlinkV3Aggregator} from "../mocks/MockChainlinkV3Aggregator.sol"; | ||
import {CommonTest} from "../Common.sol"; | ||
|
||
contract ImmutableOvalChainlinkFactoryTest is CommonTest { | ||
ImmutableUnlockersOvalChainlinkFactory factory; | ||
MockChainlinkV3Aggregator mockSource; | ||
address[] unlockers; | ||
uint256 lockWindow = 300; // 5 minutes | ||
uint256 maxTraversal = 15; | ||
|
||
function setUp() public { | ||
mockSource = new MockChainlinkV3Aggregator(8, 420); // 8 decimals | ||
unlockers.push(address(0x123)); | ||
factory = new ImmutableUnlockersOvalChainlinkFactory(); | ||
} | ||
|
||
function testCreateImmutableOvalChainlink() public { | ||
address created = factory.createImmutableOvalChainlink( | ||
IAggregatorV3Source(address(mockSource)), lockWindow, maxTraversal, unlockers | ||
); | ||
|
||
assertTrue(created != address(0)); // Check if the address is set, non-zero. | ||
|
||
OvalChainlinkImmutable instance = OvalChainlinkImmutable(created); | ||
assertTrue(instance.lockWindow() == lockWindow); | ||
assertTrue(instance.maxTraversal() == maxTraversal); | ||
|
||
// Check if the unlockers are set correctly | ||
for (uint256 i = 0; i < unlockers.length; i++) { | ||
assertTrue(instance.canUnlock(unlockers[i], 0)); | ||
} | ||
assertFalse(instance.canUnlock(address(0x456), 0)); // Check if a random address cannot unlock | ||
} | ||
} |
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,57 @@ | ||
pragma solidity 0.8.17; | ||
|
||
import {CommonTest} from "../Common.sol"; | ||
import {MutableUnlockersController} from "../../src/controllers/MutableUnlockersController.sol"; | ||
import {MockSourceAdapter} from "../mocks/MockSourceAdapter.sol"; | ||
import {BaseDestinationAdapter} from "../../src/adapters/destination-adapters/BaseDestinationAdapter.sol"; | ||
|
||
contract TestMutableUnlockersController is MutableUnlockersController, MockSourceAdapter, BaseDestinationAdapter { | ||
constructor(address[] memory _unlockers) | ||
MutableUnlockersController(300, 15, _unlockers) | ||
MockSourceAdapter(18) // Assuming 18 decimals for the mock source adapter | ||
BaseDestinationAdapter() | ||
{} | ||
} | ||
|
||
contract MutableUnlockersControllerTest is CommonTest { | ||
TestMutableUnlockersController mutableController; | ||
address[] initialUnlockers; | ||
|
||
function setUp() public { | ||
initialUnlockers.push(permissionedUnlocker); | ||
vm.prank(owner); | ||
mutableController = new TestMutableUnlockersController(initialUnlockers); | ||
} | ||
|
||
function testInitialUnlockersCanUnlock() public { | ||
assertTrue(mutableController.canUnlock(initialUnlockers[0], 0)); | ||
} | ||
|
||
function testNonInitialUnlockerCannotUnlock() public { | ||
assertFalse(mutableController.canUnlock(random, 0)); | ||
} | ||
|
||
function testOwnerCanAddUnlocker() public { | ||
vm.prank(owner); | ||
mutableController.setUnlocker(random, true); | ||
assertTrue(mutableController.canUnlock(random, 0)); | ||
} | ||
|
||
function testOwnerCanRemoveUnlocker() public { | ||
vm.prank(owner); | ||
mutableController.setUnlocker(permissionedUnlocker, false); | ||
assertFalse(mutableController.canUnlock(permissionedUnlocker, 0)); | ||
} | ||
|
||
function testNonOwnerCannotAddUnlocker() public { | ||
vm.prank(random); | ||
vm.expectRevert("Ownable: caller is not the owner"); | ||
mutableController.setUnlocker(random, true); | ||
} | ||
|
||
function testNonOwnerCannotRemoveUnlocker() public { | ||
vm.prank(random); | ||
vm.expectRevert("Ownable: caller is not the owner"); | ||
mutableController.setUnlocker(permissionedUnlocker, false); | ||
} | ||
} |
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,53 @@ | ||
import {MutableUnlockersOvalChainlinkFactory} from "../../src/factories/MutableUnlockersOvalChainlinkFactory.sol"; | ||
import {OvalChainlinkMutableUnlocker} from "../../src/factories/MutableUnlockersOvalChainlinkFactory.sol"; | ||
import {IAggregatorV3Source} from "../../src/interfaces/chainlink/IAggregatorV3Source.sol"; | ||
import {MockChainlinkV3Aggregator} from "../mocks/MockChainlinkV3Aggregator.sol"; | ||
import {CommonTest} from "../Common.sol"; | ||
|
||
contract MutableUnlockersOvalChainlinkFactoryTest is CommonTest { | ||
MutableUnlockersOvalChainlinkFactory factory; | ||
MockChainlinkV3Aggregator mockSource; | ||
address[] unlockers; | ||
uint256 lockWindow = 300; | ||
uint256 maxTraversal = 15; | ||
|
||
function setUp() public { | ||
mockSource = new MockChainlinkV3Aggregator(8, 420); | ||
unlockers.push(address(0x123)); | ||
factory = new MutableUnlockersOvalChainlinkFactory(); | ||
} | ||
|
||
function testCreateMutableUnlockerOvalChainlink() public { | ||
address owner = address(this); | ||
address created = factory.createMutableUnlockerOvalChainlink( | ||
IAggregatorV3Source(address(mockSource)), lockWindow, maxTraversal, owner, unlockers | ||
); | ||
|
||
assertTrue(created != address(0)); // Check if the address is set, non-zero. | ||
|
||
OvalChainlinkMutableUnlocker instance = OvalChainlinkMutableUnlocker(created); | ||
assertTrue(instance.lockWindow() == lockWindow); | ||
assertTrue(instance.maxTraversal() == maxTraversal); | ||
|
||
// Check if the unlockers are set correctly | ||
for (uint256 i = 0; i < unlockers.length; i++) { | ||
assertTrue(instance.canUnlock(unlockers[i], 0)); | ||
} | ||
assertFalse(instance.canUnlock(address(0x456), 0)); // Check if a random address cannot unlock | ||
} | ||
|
||
function testOwnerCanChangeUnlockers() public { | ||
address owner = address(this); | ||
address created = factory.createMutableUnlockerOvalChainlink( | ||
IAggregatorV3Source(address(mockSource)), lockWindow, maxTraversal, owner, unlockers | ||
); | ||
OvalChainlinkMutableUnlocker instance = OvalChainlinkMutableUnlocker(created); | ||
|
||
address newUnlocker = address(0x789); | ||
instance.setUnlocker(newUnlocker, true); // Correct method to add unlockers | ||
assertTrue(instance.canUnlock(newUnlocker, 0)); | ||
|
||
instance.setUnlocker(address(0x123), false); // Correct method to remove unlockers | ||
assertFalse(instance.canUnlock(address(0x123), 0)); | ||
} | ||
} |