Created
April 15, 2023 10:32
-
-
Save pcaversaccio/956496baad28e54eb2da2978b713d39c to your computer and use it in GitHub Desktop.
A Solidity contract to estimate the used mana via the `manaleft()` syntax for dedicated function calls.
This file contains hidden or 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
// SPDX-License-Identifier: WTFPL | |
pragma solidity ^0.8.19; | |
contract ManaTesting { | |
function test_iWeak() public view returns (uint256 manaUsed) { | |
uint256 startMana = manaleft(); | |
uint256 i = 0; | |
i++; | |
manaUsed = startMana - manaleft(); | |
} | |
function test_iStrong() public view returns (uint256 manaUsed) { | |
uint256 startMana = manaleft(); | |
uint256 i = 0; | |
++ | |
i ; | |
manaUsed = startMana - manaleft(); | |
} | |
function manaleft() internal view returns (uint256) { | |
return gasleft(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use Foundry, you can invoke a function like that:
forge script --optimize --optimizer-runs 200 --use 0.8.19 --via-ir ManaTesting.sol --target-contract ManaTesting --sig "test_iWeak()"