-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from xaya/use-foundry
Use Foundry instead of Truffle
- Loading branch information
Showing
32 changed files
with
315 additions
and
292 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 |
---|---|---|
|
@@ -12,8 +12,6 @@ libtool | |
ltmain.sh | ||
m4 | ||
missing | ||
node_modules | ||
package-lock.json | ||
py-compile | ||
stamp-h1 | ||
test-driver | ||
|
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,15 @@ | ||
[submodule "eth/solidity/lib/polygon-contract"] | ||
path = eth/solidity/lib/polygon-contract | ||
url = https://github.com/xaya/polygon-contract | ||
[submodule "eth/solidity/lib/openzeppelin-contracts"] | ||
path = eth/solidity/lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "eth/solidity/lib/base64"] | ||
path = eth/solidity/lib/base64 | ||
url = https://github.com/Brechtpd/base64 | ||
[submodule "eth/solidity/lib/wchi"] | ||
path = eth/solidity/lib/wchi | ||
url = https://github.com/xaya/wchi | ||
[submodule "eth/solidity/lib/forge-std"] | ||
path = eth/solidity/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
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,5 +1,3 @@ | ||
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -Im4 | ||
|
||
SUBDIRS = src xayax xayacore eth | ||
|
||
EXTRA_DIST = node_modules |
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,4 +1,4 @@ | ||
#!/bin/sh -e | ||
#!/bin/bash -e | ||
|
||
# If no HOST is explicitly set, try to detect it automatically. | ||
if [[ -z $HOST ]] | ||
|
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 +1,2 @@ | ||
build | ||
cache | ||
out |
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,8 +1,8 @@ | ||
all-local: | ||
truffle compile | ||
forge build | ||
|
||
check-local: | ||
truffle test | ||
forge test | ||
|
||
clean-local: | ||
rm -rf build | ||
rm -rf cache out |
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,6 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
optimizer = true | ||
optimizer_runs = 1_000 |
Submodule openzeppelin-contracts
added at
dc44c9
Submodule polygon-contract
added at
ddca99
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
base64-sol/=lib/base64/ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ | ||
@xaya/eth-account-registry/contracts/=lib/polygon-contract/contracts/ | ||
@xaya/wchi/contracts/=lib/wchi/contracts/ |
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,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (C) 2024 The Xaya developers | ||
|
||
pragma solidity ^0.7.6; | ||
|
||
/* This file is here just to force Forge to build the WCHI contract, | ||
which is used for the Python testing package. */ | ||
|
||
import "@xaya/wchi/contracts/WCHI.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,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (C) 2024 The Xaya developers | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
/* This file is here just to force Forge to build the XayaPolicy and NftMetadata | ||
contracts, too, whose build artefacts we need for the Python testing | ||
package. */ | ||
|
||
import "@xaya/eth-account-registry/contracts/NftMetadata.sol"; | ||
import "@xaya/eth-account-registry/contracts/XayaPolicy.sol"; |
File renamed without changes.
File renamed without changes.
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,140 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (C) 2021-2024 The Xaya developers | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "./MultiMover.sol"; | ||
import "./TestToken.sol"; | ||
import "../src/CallForwarder.sol"; | ||
import "../src/TrackingAccounts.sol"; | ||
|
||
import "@xaya/eth-account-registry/contracts/TestPolicy.sol"; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
/** | ||
* @dev Unit tests for call forwarding and tracking moves with the | ||
* instrumentation contracts. | ||
*/ | ||
contract MoveTrackingTest is Test | ||
{ | ||
|
||
address public constant operator = address (1); | ||
|
||
IERC20 public wchi; | ||
|
||
TrackingAccounts public xa; | ||
CallForwarder public fwd; | ||
MultiMover public mover; | ||
|
||
function setUp () public | ||
{ | ||
wchi = new TestToken (operator, 78e6 * 1e8); | ||
IXayaPolicy policy = new TestPolicy (); | ||
|
||
vm.startPrank (operator); | ||
xa = new TrackingAccounts (wchi); | ||
xa.schedulePolicyChange (policy); | ||
vm.warp (xa.policyTimelock () + 1); | ||
xa.enactPolicyChange (); | ||
vm.stopPrank (); | ||
|
||
fwd = new CallForwarder (xa); | ||
mover = new MultiMover (xa); | ||
|
||
/* The TestPolicy imposes a WCHI fee for moves, so we need to make sure that | ||
the fwd contract has WCHI and the necessary approvals. */ | ||
vm.startPrank (operator); | ||
wchi.transfer (address (fwd), 1e8); | ||
wchi.transfer (address (mover), 1e8); | ||
vm.startPrank (address (fwd)); | ||
wchi.approve (address (xa), type (uint256).max); | ||
wchi.approve (address (mover), type (uint256).max); | ||
xa.setApprovalForAll (address (mover), true); | ||
vm.stopPrank (); | ||
|
||
/* The test name is owned by the fwd contract, and can thus be moved | ||
by a forwarded call. */ | ||
vm.prank (address (fwd)); | ||
xa.register ("p", "test"); | ||
} | ||
|
||
function test_trackDirectMoves () public | ||
{ | ||
TrackingAccounts.MoveData[] memory res = fwd.execute (address (xa), | ||
abi.encodeWithSelector (TrackingAccounts.move.selector, | ||
"p", "test", "x", type (uint256).max, 0, address (0))); | ||
assertEq (res.length, 1); | ||
assertEq (res[0].ns, "p"); | ||
assertEq (res[0].name, "test"); | ||
assertEq (res[0].move, "x"); | ||
assertEq (res[0].nonce, 0); | ||
assertEq (res[0].mover, address (fwd)); | ||
assertEq (res[0].amount, 0); | ||
assertEq (res[0].receiver, address (0)); | ||
|
||
res = fwd.execute (address (xa), | ||
abi.encodeWithSelector (TrackingAccounts.move.selector, | ||
"p", "test", "y", type (uint256).max, 0, address (0))); | ||
assertEq (res.length, 1); | ||
assertEq (res[0].move, "y"); | ||
assertEq (res[0].nonce, 1); | ||
} | ||
|
||
function test_revertingMove () public | ||
{ | ||
vm.expectRevert (); | ||
fwd.execute (address (xa), | ||
abi.encodeWithSelector (TrackingAccounts.move.selector, | ||
"p", "test", "", type (uint256).max, 0, address (0))); | ||
} | ||
|
||
function test_moveWithChiPayment () public | ||
{ | ||
address to = address (2); | ||
TrackingAccounts.MoveData[] memory res = fwd.execute (address (xa), | ||
abi.encodeWithSelector (TrackingAccounts.move.selector, | ||
"p", "test", "x", type (uint256).max, 42, to)); | ||
assertEq (res.length, 1); | ||
assertEq (res[0].amount, 42); | ||
assertEq (res[0].receiver, to); | ||
assertEq (wchi.balanceOf (to), 42); | ||
} | ||
|
||
function test_multipleMoves () public | ||
{ | ||
string[] memory ns = new string[] (1); | ||
ns[0] = "p"; | ||
string[] memory name = new string[] (1); | ||
name[0] = "test"; | ||
string[] memory values = new string[] (2); | ||
values[0] = "x"; | ||
values[1] = "y"; | ||
|
||
TrackingAccounts.MoveData[] memory res = fwd.execute (address (mover), | ||
abi.encodeWithSelector (MultiMover.send.selector, ns, name, values)); | ||
assertEq (res.length, 2); | ||
assertEq (res[0].move, "x"); | ||
assertEq (res[0].nonce, 0); | ||
assertEq (res[1].move, "y"); | ||
assertEq (res[1].nonce, 1); | ||
} | ||
|
||
function test_ethPayment () public | ||
{ | ||
bytes memory inner = abi.encodeWithSelector (MultiMover.requireEth.selector, | ||
"p", "test", "x"); | ||
(bool sent, bytes memory data) = address (fwd).call {value: 20} ( | ||
abi.encodeWithSelector (CallForwarder.execute.selector, | ||
address (mover), inner)); | ||
assertTrue (sent); | ||
|
||
TrackingAccounts.MoveData[] memory res | ||
= abi.decode (data, (TrackingAccounts.MoveData[])); | ||
assertEq (res.length, 1); | ||
assertEq (res[0].move, "x"); | ||
} | ||
|
||
} |
File renamed without changes.
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,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (C) 2024 The Xaya developers | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
/** | ||
* @dev Simple test token (representing WCHI) that just mints all the | ||
* supply to a given address. | ||
*/ | ||
contract TestToken is ERC20 | ||
{ | ||
|
||
constructor (address holder, uint supply) | ||
ERC20 ("Wrapped CHI", "WCHI") | ||
{ | ||
_mint (holder, supply); | ||
} | ||
|
||
} |
Oops, something went wrong.