-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full test coverage for trust contracts
- Loading branch information
Showing
5 changed files
with
162 additions
and
13 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,51 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "contracts/trust/TrustFactory.sol"; | ||
|
||
import "foundry_test/base/AdvTest.sol"; | ||
|
||
contract TrustFactoryTest is AdvTest { | ||
TrustFactory private factory; | ||
|
||
function setUp() external { | ||
factory = new TrustFactory(); | ||
} | ||
|
||
function test_create_trust(address _owner, address _beneficiary, uint256 _duration) external { | ||
Trust trust = factory.deploy(_owner, _beneficiary, _duration); | ||
address trustAddress = address(trust); | ||
|
||
assertEq(trust.owner(), _owner); | ||
assertEq(trust.beneficiary(), _beneficiary); | ||
assertEq(trust.duration(), _duration); | ||
|
||
uint256 codeSize; assembly { codeSize := extcodesize(trustAddress) } | ||
assertGt(codeSize, 0); | ||
} | ||
|
||
function test_predict_address(address _owner, address _beneficiary, uint256 _duration) external { | ||
address expected = factory.addressOf(_owner, _beneficiary, _duration); | ||
address actual = address(factory.deploy(_owner, _beneficiary, _duration)); | ||
assertEq(actual, expected); | ||
} | ||
|
||
function test_fail_deploy_twice(address _owner, address _beneficiary, uint256 _duration) external { | ||
factory.deploy(_owner, _beneficiary, _duration); | ||
vm.expectRevert(); | ||
factory.deploy(_owner, _beneficiary, _duration); | ||
} | ||
|
||
function test_fail_deploy_low_gas(address _owner, address _beneficiary, uint256 _duration, uint256 _gas) external { | ||
_gas = bound(_gas, 21000, block.gaslimit); | ||
try factory.deploy{ gas: _gas }(_owner, _beneficiary, _duration) returns (Trust trust) { | ||
address trustAddress = address(trust); | ||
// The address should have code, and never be the zero address | ||
assertNotEq(trustAddress, address(0)); | ||
uint256 codeSize; assembly { codeSize := extcodesize(trustAddress) } | ||
assertGt(codeSize, 0); | ||
} catch { | ||
// Ignore errors from low gas | ||
} | ||
} | ||
} |