-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ compiler: | |
version: 0.8.11 | ||
remappings: | ||
- "@openzeppelin=OpenZeppelin/[email protected]" | ||
|
||
viaIR: true | ||
optimizer: | ||
details: | ||
yul: true |
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,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.11; | ||
|
||
import "../VM.sol"; | ||
|
||
contract TestableVMWithMath is VM { | ||
function execute(bytes32[] calldata commands, bytes[] memory state) | ||
public | ||
payable | ||
returns (bytes[] memory) | ||
{ | ||
return _execute(commands, state); | ||
} | ||
|
||
function sum(uint256 a, uint256 b) external pure returns (uint256) { | ||
return a + b; | ||
} | ||
|
||
|
||
function dispatch(bytes memory inputs) | ||
internal | ||
override | ||
returns (bool _success, bytes memory _ret) | ||
{ | ||
bytes4 _selector = bytes4(bytes32(inputs)); | ||
if (this.sum.selector == _selector) { | ||
uint256 a; | ||
uint256 b; | ||
assembly { | ||
a := mload(add(inputs, 36)) | ||
b := mload(add(inputs, 68)) | ||
} | ||
uint256 res = this.sum(a, b); | ||
_ret = new bytes(32); | ||
assembly { | ||
mstore(add(_ret, 32), res) | ||
} | ||
return (true, _ret); | ||
} | ||
} | ||
} |
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,20 @@ | ||
from brownie import Contract, accounts, Wei, chain, TestableVM | ||
from weiroll import WeirollContract, WeirollPlanner | ||
|
||
|
||
def test_vm_with_math(weiroll_vm_with_math): | ||
weiroll_vm = weiroll_vm_with_math | ||
whale = accounts.at("0x57757E3D981446D585Af0D9Ae4d7DF6D64647806", force=True) | ||
|
||
planner = WeirollPlanner(weiroll_vm) | ||
sum = planner.call(weiroll_vm, "sum", 1, 2) | ||
sum_2 = planner.call(weiroll_vm, "sum", sum, 3) | ||
sum_2 = planner.call(weiroll_vm, "sum", 3, sum_2) | ||
|
||
cmds, state = planner.plan() | ||
weiroll_tx = weiroll_vm.execute( | ||
cmds, state, {"from": whale, "gas_limit": 8_000_000, "gas_price": 0} | ||
) | ||
|
||
print(weiroll_tx.return_value) | ||
#assert False |