Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
02623baa
Commit
02623baa
authored
May 30, 2023
by
Ratimon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: Adding tests for Burn library
parent
941ae589
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
158 additions
and
0 deletions
+158
-0
Burn.Eth.t.sol
...ontracts-bedrock/contracts/test/invariants/Burn.Eth.t.sol
+72
-0
Burn.Gas.t.sol
...ontracts-bedrock/contracts/test/invariants/Burn.Gas.t.sol
+72
-0
Burn.Eth.md
packages/contracts-bedrock/invariant-docs/Burn.Eth.md
+6
-0
Burn.Gas.md
packages/contracts-bedrock/invariant-docs/Burn.Gas.md
+6
-0
README.md
packages/contracts-bedrock/invariant-docs/README.md
+2
-0
No files found.
packages/contracts-bedrock/contracts/test/invariants/Burn.Eth.t.sol
0 → 100644
View file @
02623baa
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { StdUtils } from "forge-std/StdUtils.sol";
import { Test } from "forge-std/Test.sol";
import { Vm } from "forge-std/Vm.sol";
import { StdInvariant } from "forge-std/StdInvariant.sol";
import { Burn } from "../../libraries/Burn.sol";
contract Burn_EthBurner is StdUtils {
Vm internal vm;
bool public failedEthBurn;
constructor(Vm _vm) {
vm = _vm;
}
/**
* @notice Takes an integer amount of eth to burn through the Burn library and
* updates the contract state if an incorrect amount of eth moved from the contract
*/
function burnEth(uint256 _value) external {
uint256 preBurnvalue = bound(_value, 0, type(uint128).max);
// Give the burner some ether for gas being used
vm.deal(address(this), preBurnvalue);
// cache the contract's eth balance
uint256 preBurnBalance = address(this).balance;
uint256 value = bound(preBurnvalue, 0, preBurnBalance);
// execute a burn of _value eth
Burn.eth(value);
// check that exactly value eth was transfered from the contract
unchecked {
if (address(this).balance != preBurnBalance - value) {
failedEthBurn = true;
}
}
}
}
contract Burn_BurnEth_Invariant is StdInvariant, Test {
Burn_EthBurner internal actor;
function setUp() public {
// Create a Eth burner actor.
actor = new Burn_EthBurner(vm);
targetContract(address(actor));
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = actor.burnEth.selector;
FuzzSelector memory selector = FuzzSelector({ addr: address(actor), selectors: selectors });
targetSelector(selector);
}
/**
* @custom:invariant `eth(uint256)` always burns the exact amount of eth passed.
*
* Asserts that when `Burn.eth(uint256)` is called, it always burns the exact amount
* of ETH passed to the function.
*/
function invariant_burn_eth() external {
// ASSERTION: The amount burned should always match the amount passed exactly
assertEq(actor.failedEthBurn(), false);
}
}
packages/contracts-bedrock/contracts/test/invariants/Burn.Gas.t.sol
0 → 100644
View file @
02623baa
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { StdUtils } from "forge-std/StdUtils.sol";
import { Test } from "forge-std/Test.sol";
import { Vm } from "forge-std/Vm.sol";
import { StdInvariant } from "forge-std/StdInvariant.sol";
import { Burn } from "../../libraries/Burn.sol";
contract Burn_GasBurner is StdUtils {
Vm internal vm;
bool public failedGasBurn;
constructor(Vm _vm) {
vm = _vm;
}
/**
* @notice Takes an integer amount of gas to burn through the Burn library and
* updates the contract state if at least that amount of gas was not burned
* by the library
*/
function burnGas(uint256 _value) external {
// cap the value to the max resource limit
uint256 MAX_RESOURCE_LIMIT = 8_000_000;
uint256 value = bound(_value, 0, MAX_RESOURCE_LIMIT);
// cache the contract's current remaining gas
uint256 preBurnGas = gasleft();
// execute the gas burn
Burn.gas(value);
// cache the remaining gas post burn
uint256 postBurnGas = gasleft();
// check that at least value gas was burnt (and that there was no underflow)
unchecked {
if (postBurnGas - preBurnGas <= value && preBurnGas - value > preBurnGas) {
failedGasBurn = true;
}
}
}
}
contract Burn_BurnGas_Invariant is StdInvariant, Test {
Burn_GasBurner internal actor;
function setUp() public {
// Create a gas burner actor.
actor = new Burn_GasBurner(vm);
targetContract(address(actor));
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = actor.burnGas.selector;
FuzzSelector memory selector = FuzzSelector({ addr: address(actor), selectors: selectors });
targetSelector(selector);
}
/**
* @custom:invariant `gas(uint256)` always burns at least the amount of gas passed.
*
* Asserts that when `Burn.gas(uint256)` is called, it always burns at least the amount
* of gas passed to the function.
*/
function invariant_burn_gas() external {
// ASSERTION: The amount burned should always match the amount passed exactly
assertEq(actor.failedGasBurn(), false);
}
}
packages/contracts-bedrock/invariant-docs/Burn.Eth.md
0 → 100644
View file @
02623baa
# `Burn.Eth` Invariants
## `eth(uint256)` always burns the exact amount of eth passed.
**Test:**
[
`Burn.Eth.t.sol#L68`
](
../contracts/test/invariants/Burn.Eth.t.sol#L68
)
Asserts that when
`Burn.eth(uint256)`
is called, it always burns the exact amount of ETH passed to the function.
packages/contracts-bedrock/invariant-docs/Burn.Gas.md
0 → 100644
View file @
02623baa
# `Burn.Gas` Invariants
## `gas(uint256)` always burns at least the amount of gas passed.
**Test:**
[
`Burn.Gas.t.sol#L68`
](
../contracts/test/invariants/Burn.Gas.t.sol#L68
)
Asserts that when
`Burn.gas(uint256)`
is called, it always burns at least the amount of gas passed to the function.
packages/contracts-bedrock/invariant-docs/README.md
View file @
02623baa
...
@@ -7,6 +7,8 @@ This directory contains documentation for all defined invariant tests within `co
...
@@ -7,6 +7,8 @@ This directory contains documentation for all defined invariant tests within `co
## Table of Contents
## Table of Contents
-
[
AddressAliasing
](
./AddressAliasing.md
)
-
[
AddressAliasing
](
./AddressAliasing.md
)
-
[
Burn.Eth
](
./Burn.Eth.md
)
-
[
Burn.Gas
](
./Burn.Gas.md
)
-
[
Burn
](
./Burn.md
)
-
[
Burn
](
./Burn.md
)
-
[
CrossDomainMessenger
](
./CrossDomainMessenger.md
)
-
[
CrossDomainMessenger
](
./CrossDomainMessenger.md
)
-
[
Encoding
](
./Encoding.md
)
-
[
Encoding
](
./Encoding.md
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment