-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate HardHat tests to DS-tests (Solidity tests) #601
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6bb15f7
Migrate HardHat tests to DS-Test
richardpringle 93d1571
Remove solidity 0.8.5 dependency
richardpringle 3d0dc81
Add comments to example-deployer contract
richardpringle 11c8d0b
Merge remote-tracking branch 'origin/master' into migrate-hardhat-to-…
richardpringle 84a27c4
Move AllowListTest into test directory
richardpringle ba3cde5
Move ERC20NativeMinter test
richardpringle 04b6924
Move ExampleDeployerList test
richardpringle 926bd97
Change test_ to step_ for ds-tests
richardpringle d9dd232
Move ExampleFeeManagerTest
richardpringle 1e1044e
Move ExampleRewardManagerTest
richardpringle 59b1c79
Move ExampleTxAllowListTest
richardpringle 82c47ae
Rename tests with Test suffix
richardpringle 37a2737
Remove redundant native-minter variable
richardpringle 6770605
Initialize interfaces as contract variables
richardpringle b315b50
Merge remote-tracking branch 'origin/master' into migrate-hardhat-to-…
richardpringle aaf472c
Move comments
richardpringle 9bc25bf
Remove unused constant from example contract
richardpringle 9f2e2e9
Fix allow-list role check in test
richardpringle 83312f8
Check balances instead of roles in native-minter test
richardpringle b1e193a
Update contract-examples/test/contract_native_minter.ts
richardpringle db2cde0
Merge remote-tracking branch 'origin/master' into migrate-hardhat-to-…
richardpringle 0b13065
Try to speed up e2e tests
richardpringle e049a0d
Make e2e-test block-rate 0
richardpringle f3e7fde
Revert "Make e2e-test block-rate 0"
richardpringle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,14 +1,21 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "./AllowList.sol"; | ||
import "./IAllowList.sol"; | ||
|
||
// Precompiled Allow List Contract Address | ||
address constant TX_ALLOW_LIST = 0x0200000000000000000000000000000000000002; | ||
address constant OTHER_ADDRESS = 0x0Fa8EA536Be85F32724D57A37758761B86416123; | ||
|
||
// ExampleTxAllowList shows how TxAllowList precompile can be used in a smart contract | ||
// All methods of [allowList] can be directly called. There are example calls as tasks in hardhat.config.ts file. | ||
contract ExampleTxAllowList is AllowList { | ||
// Precompiled Allow List Contract Address | ||
address constant TX_ALLOW_LIST = 0x0200000000000000000000000000000000000002; | ||
|
||
constructor() AllowList(TX_ALLOW_LIST) {} | ||
|
||
function deployContract() public { | ||
new Example(); | ||
} | ||
} | ||
|
||
contract Example {} |
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,11 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../AllowList.sol"; | ||
import "ds-test/src/test.sol"; | ||
|
||
contract AllowListTest is DSTest { | ||
function assertRole(uint result, AllowList.Role role) internal { | ||
assertEq(result, uint(role)); | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
contract-examples/contracts/test/ERC20NativeMinterTest.sol
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,144 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../ERC20NativeMinter.sol"; | ||
import "../INativeMinter.sol"; | ||
import "./AllowListTest.sol"; | ||
|
||
// TODO: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for stripping this down to only the testing logic |
||
// this contract adds another (unwanted) layer of indirection | ||
// but it's the easiest way to match the previous HardHat testing functionality. | ||
// Once we completely migrate to DS-test, we can simplify this set of tests. | ||
contract Minter { | ||
ERC20NativeMinter token; | ||
|
||
constructor(address tokenAddress) { | ||
token = ERC20NativeMinter(tokenAddress); | ||
} | ||
|
||
function mintdraw(uint amount) external { | ||
token.mintdraw(amount); | ||
} | ||
|
||
function deposit(uint value) external { | ||
token.deposit{value: value}(); | ||
} | ||
} | ||
|
||
contract ERC20NativeMinterTest is AllowListTest { | ||
INativeMinter nativeMinter = INativeMinter(MINTER_ADDRESS); | ||
|
||
function setUp() public { | ||
// noop | ||
} | ||
|
||
function step_mintdrawFailure() public { | ||
ERC20NativeMinter token = new ERC20NativeMinter(1000); | ||
address tokenAddress = address(token); | ||
|
||
assertRole(nativeMinter.readAllowList(tokenAddress), AllowList.Role.None); | ||
|
||
try token.mintdraw(100) { | ||
assertTrue(false, "mintdraw should fail"); | ||
} catch {} // TODO should match on an error to make sure that this is failing in the way that's expected | ||
} | ||
|
||
function step_addMinter() public { | ||
ERC20NativeMinter token = new ERC20NativeMinter(1000); | ||
address tokenAddress = address(token); | ||
|
||
assertRole(nativeMinter.readAllowList(tokenAddress), AllowList.Role.None); | ||
|
||
nativeMinter.setEnabled(tokenAddress); | ||
|
||
assertRole(nativeMinter.readAllowList(tokenAddress), AllowList.Role.Enabled); | ||
} | ||
|
||
function step_adminMintdraw() public { | ||
ERC20NativeMinter token = new ERC20NativeMinter(1000); | ||
address tokenAddress = address(token); | ||
|
||
address testAddress = address(this); | ||
|
||
nativeMinter.setEnabled(tokenAddress); | ||
|
||
uint initialTokenBalance = token.balanceOf(testAddress); | ||
uint initialNativeBalance = testAddress.balance; | ||
|
||
uint amount = 100; | ||
|
||
token.mintdraw(amount); | ||
|
||
assertEq(token.balanceOf(testAddress), initialTokenBalance - amount); | ||
assertEq(testAddress.balance, initialNativeBalance + amount); | ||
} | ||
|
||
function step_minterMintdrawFailure() public { | ||
ERC20NativeMinter token = new ERC20NativeMinter(1000); | ||
address tokenAddress = address(token); | ||
|
||
Minter minter = new Minter(tokenAddress); | ||
address minterAddress = address(minter); | ||
|
||
nativeMinter.setEnabled(tokenAddress); | ||
|
||
uint initialTokenBalance = token.balanceOf(minterAddress); | ||
uint initialNativeBalance = minterAddress.balance; | ||
|
||
assertEq(initialTokenBalance, 0); | ||
|
||
try minter.mintdraw(100) { | ||
assertTrue(false, "mintdraw should fail"); | ||
} catch {} // TODO should match on an error to make sure that this is failing in the way that's expected | ||
|
||
assertEq(token.balanceOf(minterAddress), initialTokenBalance); | ||
assertEq(minterAddress.balance, initialNativeBalance); | ||
} | ||
|
||
function step_minterDeposit() public { | ||
ERC20NativeMinter token = new ERC20NativeMinter(1000); | ||
address tokenAddress = address(token); | ||
|
||
Minter minter = new Minter(tokenAddress); | ||
address minterAddress = address(minter); | ||
|
||
nativeMinter.setEnabled(tokenAddress); | ||
|
||
uint amount = 100; | ||
|
||
nativeMinter.mintNativeCoin(minterAddress, amount); | ||
|
||
uint initialTokenBalance = token.balanceOf(minterAddress); | ||
uint initialNativeBalance = minterAddress.balance; | ||
|
||
minter.deposit(amount); | ||
|
||
assertEq(token.balanceOf(minterAddress), initialTokenBalance + amount); | ||
assertEq(minterAddress.balance, initialNativeBalance - amount); | ||
} | ||
|
||
function step_mintdraw() public { | ||
ERC20NativeMinter token = new ERC20NativeMinter(1000); | ||
address tokenAddress = address(token); | ||
|
||
Minter minter = new Minter(tokenAddress); | ||
address minterAddress = address(minter); | ||
|
||
nativeMinter.setEnabled(tokenAddress); | ||
|
||
uint amount = 100; | ||
|
||
uint initialNativeBalance = minterAddress.balance; | ||
assertEq(initialNativeBalance, 0); | ||
|
||
token.mint(minterAddress, amount); | ||
|
||
uint initialTokenBalance = token.balanceOf(minterAddress); | ||
assertEq(initialTokenBalance, amount); | ||
|
||
minter.mintdraw(amount); | ||
|
||
assertEq(token.balanceOf(minterAddress), 0); | ||
assertEq(minterAddress.balance, amount); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we remove these in favor of the new enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do that in a new PR... Otherwise, this PR will never get over the line.
Originally, I didn't want some weird intermediate state with half JS tests and half Solidity tests, but in hindsight, that was a mistake.