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
56efac5b
Unverified
Commit
56efac5b
authored
Feb 01, 2023
by
Mark Tyneway
Committed by
GitHub
Feb 01, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4820 from ethereum-optimism/cleanup/remove-final-hh-tests
ctp: remove final hh tests
parents
4f168994
2190c57d
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
54 additions
and
427 deletions
+54
-427
.gas-snapshot
packages/contracts-periphery/.gas-snapshot
+15
-15
AssetReceiver.t.sol
...cts-periphery/contracts/foundry-tests/AssetReceiver.t.sol
+33
-5
AttestationStation.t.sol
...eriphery/contracts/foundry-tests/AttestationStation.t.sol
+1
-5
Optimist.t.sol
...ontracts-periphery/contracts/foundry-tests/Optimist.t.sol
+1
-6
Transactor.t.sol
...tracts-periphery/contracts/foundry-tests/Transactor.t.sol
+2
-6
package.json
packages/contracts-periphery/package.json
+2
-6
AssetReceiver.spec.ts
...-periphery/test/contracts/universal/AssetReceiver.spec.ts
+0
-243
Transactor.spec.ts
...cts-periphery/test/contracts/universal/Transactor.spec.ts
+0
-93
constants.ts
packages/contracts-periphery/test/helpers/constants.ts
+0
-2
deploy.ts
packages/contracts-periphery/test/helpers/deploy.ts
+0
-12
index.ts
packages/contracts-periphery/test/helpers/index.ts
+0
-3
solidity.ts
packages/contracts-periphery/test/helpers/solidity.ts
+0
-21
setup.ts
packages/contracts-periphery/test/setup.ts
+0
-10
No files found.
packages/contracts-periphery/.gas-snapshot
View file @
56efac5b
...
@@ -4,15 +4,15 @@ AssetReceiverTest:testFail_withdrawERC721() (gas: 55908)
...
@@ -4,15 +4,15 @@ AssetReceiverTest:testFail_withdrawERC721() (gas: 55908)
AssetReceiverTest:testFail_withdrawETH() (gas: 10457)
AssetReceiverTest:testFail_withdrawETH() (gas: 10457)
AssetReceiverTest:testFail_withdrawETHwithAmount() (gas: 10594)
AssetReceiverTest:testFail_withdrawETHwithAmount() (gas: 10594)
AssetReceiverTest:test_constructor() (gas: 9794)
AssetReceiverTest:test_constructor() (gas: 9794)
AssetReceiverTest:test_receive() (gas:
1886
0)
AssetReceiverTest:test_receive() (gas:
2101
0)
AssetReceiverTest:test_withdrawERC20() (gas: 18
3064
)
AssetReceiverTest:test_withdrawERC20() (gas: 18
5529
)
AssetReceiverTest:test_withdrawERC20withAmount() (gas: 18
2146
)
AssetReceiverTest:test_withdrawERC20withAmount() (gas: 18
4609
)
AssetReceiverTest:test_withdrawERC721() (gas:
49097
)
AssetReceiverTest:test_withdrawERC721() (gas:
51565
)
AssetReceiverTest:test_withdrawETH() (gas: 2
6179
)
AssetReceiverTest:test_withdrawETH() (gas: 2
8774
)
AssetReceiverTest:test_withdrawETHwithAmount() (gas: 2
6108
)
AssetReceiverTest:test_withdrawETHwithAmount() (gas: 2
8703
)
AssetReceiverTest:test_attest_bulk() (gas: 6114
40
)
AssetReceiverTest:test_attest_bulk() (gas: 6114
17
)
AssetReceiverTest:test_attest_individual() (gas: 5385
14
)
AssetReceiverTest:test_attest_individual() (gas: 5385
36
)
AssetReceiverTest:test_attest_single() (gas: 5589
62
)
AssetReceiverTest:test_attest_single() (gas: 5589
39
)
CheckBalanceHighTest:testFuzz_check_fails(address,uint256) (runs: 256, μ: 12352, ~: 12382)
CheckBalanceHighTest:testFuzz_check_fails(address,uint256) (runs: 256, μ: 12352, ~: 12382)
CheckBalanceHighTest:testFuzz_check_succeeds(address,uint256) (runs: 256, μ: 10284, ~: 10284)
CheckBalanceHighTest:testFuzz_check_succeeds(address,uint256) (runs: 256, μ: 10284, ~: 10284)
CheckBalanceLowTest:testFuzz_check_fails(address,uint256) (runs: 256, μ: 10262, ~: 10262)
CheckBalanceLowTest:testFuzz_check_fails(address,uint256) (runs: 256, μ: 10262, ~: 10262)
...
@@ -45,7 +45,7 @@ OptimistTest:test_optimist_baseURI() (gas: 116809)
...
@@ -45,7 +45,7 @@ OptimistTest:test_optimist_baseURI() (gas: 116809)
OptimistTest:test_optimist_burn() (gas: 77526)
OptimistTest:test_optimist_burn() (gas: 77526)
OptimistTest:test_optimist_initialize() (gas: 23095)
OptimistTest:test_optimist_initialize() (gas: 23095)
OptimistTest:test_optimist_is_on_allow_list() (gas: 52616)
OptimistTest:test_optimist_is_on_allow_list() (gas: 52616)
OptimistTest:test_optimist_mint_already_minted() (gas: 98
911
)
OptimistTest:test_optimist_mint_already_minted() (gas: 98
823
)
OptimistTest:test_optimist_mint_happy_path() (gas: 99175)
OptimistTest:test_optimist_mint_happy_path() (gas: 99175)
OptimistTest:test_optimist_mint_no_attestation() (gas: 15897)
OptimistTest:test_optimist_mint_no_attestation() (gas: 15897)
OptimistTest:test_optimist_mint_secondary_minter() (gas: 100576)
OptimistTest:test_optimist_mint_secondary_minter() (gas: 100576)
...
@@ -54,9 +54,9 @@ OptimistTest:test_optimist_sbt_transfer() (gas: 102331)
...
@@ -54,9 +54,9 @@ OptimistTest:test_optimist_sbt_transfer() (gas: 102331)
OptimistTest:test_optimist_set_approval_for_all() (gas: 100907)
OptimistTest:test_optimist_set_approval_for_all() (gas: 100907)
OptimistTest:test_optimist_supports_interface() (gas: 5797)
OptimistTest:test_optimist_supports_interface() (gas: 5797)
OptimistTest:test_optimist_token_id_of_owner() (gas: 95045)
OptimistTest:test_optimist_token_id_of_owner() (gas: 95045)
OptimistTest:test_optimist_token_uri() (gas: 2139
50
)
OptimistTest:test_optimist_token_uri() (gas: 2139
72
)
TransactorTest:testFail_CALL() (gas: 156
58
)
TransactorTest:testFail_CALL() (gas: 156
36
)
TransactorTest:testFail_DELEGATECALLL() (gas: 15632)
TransactorTest:testFail_DELEGATECALLL() (gas: 15632)
TransactorTest:test_CALL() (gas: 269
77
)
TransactorTest:test_CALL() (gas: 269
69
)
TransactorTest:test_DELEGATECALL() (gas: 211
22
)
TransactorTest:test_DELEGATECALL() (gas: 211
89
)
TransactorTest:test_constructor() (gas: 97
8
2)
TransactorTest:test_constructor() (gas: 97
7
2)
packages/contracts-periphery/contracts/foundry-tests/AssetReceiver.t.sol
View file @
56efac5b
...
@@ -17,7 +17,22 @@ contract AssetReceiver_Initializer is Test {
...
@@ -17,7 +17,22 @@ contract AssetReceiver_Initializer is Test {
TestERC721 testERC721;
TestERC721 testERC721;
AssetReceiver assetReceiver;
AssetReceiver assetReceiver;
function _setUp() public {
event ReceivedETH(address indexed from, uint256 amount);
event WithdrewETH(address indexed withdrawer, address indexed recipient, uint256 amount);
event WithdrewERC20(
address indexed withdrawer,
address indexed recipient,
address indexed asset,
uint256 amount
);
event WithdrewERC721(
address indexed withdrawer,
address indexed recipient,
address indexed asset,
uint256 id
);
function setUp() public {
// Deploy ERC20 and ERC721 tokens
// Deploy ERC20 and ERC721 tokens
testERC20 = new TestERC20();
testERC20 = new TestERC20();
testERC721 = new TestERC721();
testERC721 = new TestERC721();
...
@@ -38,10 +53,6 @@ contract AssetReceiver_Initializer is Test {
...
@@ -38,10 +53,6 @@ contract AssetReceiver_Initializer is Test {
}
}
contract AssetReceiverTest is AssetReceiver_Initializer {
contract AssetReceiverTest is AssetReceiver_Initializer {
function setUp() public {
super._setUp();
}
// Tests if the owner was set correctly during deploy
// Tests if the owner was set correctly during deploy
function test_constructor() external {
function test_constructor() external {
assertEq(address(alice), assetReceiver.owner());
assertEq(address(alice), assetReceiver.owner());
...
@@ -52,6 +63,8 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
...
@@ -52,6 +63,8 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
// Check that contract balance is 0 initially
// Check that contract balance is 0 initially
assertEq(address(assetReceiver).balance, 0);
assertEq(address(assetReceiver).balance, 0);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit ReceivedETH(alice, 100);
// Send funds
// Send funds
vm.prank(alice);
vm.prank(alice);
(bool success, ) = address(assetReceiver).call{ value: 100 }(hex"");
(bool success, ) = address(assetReceiver).call{ value: 100 }(hex"");
...
@@ -71,6 +84,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
...
@@ -71,6 +84,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(address(alice).balance, 1 ether);
assertEq(address(alice).balance, 1 ether);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewETH(alice, alice, 1 ether);
// call withdrawETH
// call withdrawETH
vm.prank(alice);
vm.prank(alice);
assetReceiver.withdrawETH(payable(alice));
assetReceiver.withdrawETH(payable(alice));
...
@@ -96,6 +112,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
...
@@ -96,6 +112,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(address(alice).balance, 1 ether);
assertEq(address(alice).balance, 1 ether);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewETH(alice, alice, 0.5 ether);
// call withdrawETH
// call withdrawETH
vm.prank(alice);
vm.prank(alice);
assetReceiver.withdrawETH(payable(alice), 0.5 ether);
assetReceiver.withdrawETH(payable(alice), 0.5 ether);
...
@@ -121,6 +140,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
...
@@ -121,6 +140,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(testERC20.balanceOf(address(assetReceiver)), 100_000);
assertEq(testERC20.balanceOf(address(assetReceiver)), 100_000);
assertEq(testERC20.balanceOf(alice), 0);
assertEq(testERC20.balanceOf(alice), 0);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewERC20(alice, alice, address(testERC20), 100_000);
// call withdrawERC20
// call withdrawERC20
vm.prank(alice);
vm.prank(alice);
assetReceiver.withdrawERC20(testERC20, alice);
assetReceiver.withdrawERC20(testERC20, alice);
...
@@ -146,6 +168,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
...
@@ -146,6 +168,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(testERC20.balanceOf(address(assetReceiver)), 100_000);
assertEq(testERC20.balanceOf(address(assetReceiver)), 100_000);
assertEq(testERC20.balanceOf(alice), 0);
assertEq(testERC20.balanceOf(alice), 0);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewERC20(alice, alice, address(testERC20), 50_000);
// call withdrawERC20
// call withdrawERC20
vm.prank(alice);
vm.prank(alice);
assetReceiver.withdrawERC20(testERC20, alice, 50_000);
assetReceiver.withdrawERC20(testERC20, alice, 50_000);
...
@@ -172,6 +197,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
...
@@ -172,6 +197,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
testERC721.transferFrom(alice, address(assetReceiver), DEFAULT_TOKEN_ID);
testERC721.transferFrom(alice, address(assetReceiver), DEFAULT_TOKEN_ID);
assertEq(testERC721.ownerOf(DEFAULT_TOKEN_ID), address(assetReceiver));
assertEq(testERC721.ownerOf(DEFAULT_TOKEN_ID), address(assetReceiver));
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewERC721(alice, alice, address(testERC721), DEFAULT_TOKEN_ID);
// Call withdrawERC721
// Call withdrawERC721
vm.prank(alice);
vm.prank(alice);
assetReceiver.withdrawERC721(testERC721, alice, DEFAULT_TOKEN_ID);
assetReceiver.withdrawERC721(testERC721, alice, DEFAULT_TOKEN_ID);
...
...
packages/contracts-periphery/contracts/foundry-tests/AttestationStation.t.sol
View file @
56efac5b
...
@@ -11,7 +11,7 @@ contract AssetReceiver_Initializer is Test {
...
@@ -11,7 +11,7 @@ contract AssetReceiver_Initializer is Test {
address bob = address(256);
address bob = address(256);
address sally = address(512);
address sally = address(512);
function
_
setUp() public {
function setUp() public {
// Give alice and bob some ETH
// Give alice and bob some ETH
vm.deal(alice_attestor, 1 ether);
vm.deal(alice_attestor, 1 ether);
...
@@ -22,10 +22,6 @@ contract AssetReceiver_Initializer is Test {
...
@@ -22,10 +22,6 @@ contract AssetReceiver_Initializer is Test {
}
}
contract AssetReceiverTest is AssetReceiver_Initializer {
contract AssetReceiverTest is AssetReceiver_Initializer {
function setUp() public {
super._setUp();
}
event AttestationCreated(
event AttestationCreated(
address indexed creator,
address indexed creator,
address indexed about,
address indexed about,
...
...
packages/contracts-periphery/contracts/foundry-tests/Optimist.t.sol
View file @
56efac5b
...
@@ -47,7 +47,7 @@ contract Optimist_Initializer is Test {
...
@@ -47,7 +47,7 @@ contract Optimist_Initializer is Test {
attestationStation.attest(attestationData);
attestationStation.attest(attestationData);
}
}
function
_
setUp() public {
function setUp() public {
// Give alice and bob and sally some ETH
// Give alice and bob and sally some ETH
vm.deal(alice_admin, 1 ether);
vm.deal(alice_admin, 1 ether);
vm.deal(bob, 1 ether);
vm.deal(bob, 1 ether);
...
@@ -68,11 +68,6 @@ contract Optimist_Initializer is Test {
...
@@ -68,11 +68,6 @@ contract Optimist_Initializer is Test {
}
}
contract OptimistTest is Optimist_Initializer {
contract OptimistTest is Optimist_Initializer {
function setUp() public {
super._setUp();
_initializeContracts();
}
function test_optimist_initialize() external {
function test_optimist_initialize() external {
// expect name to be set
// expect name to be set
assertEq(optimist.name(), name);
assertEq(optimist.name(), name);
...
...
packages/contracts-periphery/contracts/foundry-tests/Transactor.t.sol
View file @
56efac5b
...
@@ -15,7 +15,7 @@ contract Transactor_Initializer is Test {
...
@@ -15,7 +15,7 @@ contract Transactor_Initializer is Test {
Reverter reverter;
Reverter reverter;
CallRecorder callRecorded;
CallRecorder callRecorded;
function
_
setUp() public {
function setUp() public {
// Deploy Reverter and CallRecorder helper contracts
// Deploy Reverter and CallRecorder helper contracts
reverter = new Reverter();
reverter = new Reverter();
callRecorded = new CallRecorder();
callRecorded = new CallRecorder();
...
@@ -34,10 +34,6 @@ contract Transactor_Initializer is Test {
...
@@ -34,10 +34,6 @@ contract Transactor_Initializer is Test {
}
}
contract TransactorTest is Transactor_Initializer {
contract TransactorTest is Transactor_Initializer {
function setUp() public {
super._setUp();
}
// Tests if the owner was set correctly during deploy
// Tests if the owner was set correctly during deploy
function test_constructor() external {
function test_constructor() external {
assertEq(address(alice), transactor.owner());
assertEq(address(alice), transactor.owner());
...
@@ -49,7 +45,7 @@ contract TransactorTest is Transactor_Initializer {
...
@@ -49,7 +45,7 @@ contract TransactorTest is Transactor_Initializer {
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
// Run CALL
// Run CALL
vm.prank(alice);
vm.prank(alice);
vm.expectCall(address(callRecorded), data);
vm.expectCall(address(callRecorded),
200_000 wei,
data);
transactor.CALL(address(callRecorded), data, 200_000 wei);
transactor.CALL(address(callRecorded), data, 200_000 wei);
}
}
...
...
packages/contracts-periphery/package.json
View file @
56efac5b
...
@@ -16,10 +16,9 @@
...
@@ -16,10 +16,9 @@
"build"
:
"yarn build:hh"
,
"build"
:
"yarn build:hh"
,
"build:hh"
:
"hardhat compile --show-stack-traces"
,
"build:hh"
:
"hardhat compile --show-stack-traces"
,
"build:forge"
:
"forge build"
,
"build:forge"
:
"forge build"
,
"test"
:
"yarn test:contracts"
,
"test"
:
"yarn test:forge"
,
"test:contracts"
:
"hardhat test --show-stack-traces"
,
"test:forge"
:
"forge test"
,
"test:forge"
:
"forge test"
,
"test:coverage"
:
"
NODE_OPTIONS=--max_old_space_size=8192 hardhat coverage &&
yarn test:coverage:forge"
,
"test:coverage"
:
"yarn test:coverage:forge"
,
"test:coverage:forge"
:
"forge coverage"
,
"test:coverage:forge"
:
"forge coverage"
,
"test:slither"
:
"slither ."
,
"test:slither"
:
"slither ."
,
"gas-snapshot"
:
"forge snapshot"
,
"gas-snapshot"
:
"forge snapshot"
,
...
@@ -64,8 +63,6 @@
...
@@ -64,8 +63,6 @@
"@rari-capital/solmate"
:
"7.0.0-alpha.3"
,
"@rari-capital/solmate"
:
"7.0.0-alpha.3"
,
"@openzeppelin/contracts"
:
"4.7.3"
,
"@openzeppelin/contracts"
:
"4.7.3"
,
"@openzeppelin/contracts-upgradeable"
:
"4.7.3"
,
"@openzeppelin/contracts-upgradeable"
:
"4.7.3"
,
"@types/chai"
:
"^4.2.18"
,
"@types/mocha"
:
"^8.2.2"
,
"@types/node"
:
"^17.0.21"
,
"@types/node"
:
"^17.0.21"
,
"@typechain/ethers-v5"
:
"^10.1.0"
,
"@typechain/ethers-v5"
:
"^10.1.0"
,
"@typechain/hardhat"
:
"^6.1.2"
,
"@typechain/hardhat"
:
"^6.1.2"
,
...
@@ -81,7 +78,6 @@
...
@@ -81,7 +78,6 @@
"hardhat-deploy"
:
"^0.11.10"
,
"hardhat-deploy"
:
"^0.11.10"
,
"hardhat-gas-reporter"
:
"^1.0.8"
,
"hardhat-gas-reporter"
:
"^1.0.8"
,
"lint-staged"
:
"11.0.0"
,
"lint-staged"
:
"11.0.0"
,
"mocha"
:
"^10.0.0"
,
"mkdirp"
:
"^1.0.4"
,
"mkdirp"
:
"^1.0.4"
,
"node-fetch"
:
"^2.6.7"
,
"node-fetch"
:
"^2.6.7"
,
"prettier"
:
"^2.8.0"
,
"prettier"
:
"^2.8.0"
,
...
...
packages/contracts-periphery/test/contracts/universal/AssetReceiver.spec.ts
deleted
100644 → 0
View file @
4f168994
import
hre
from
'
hardhat
'
import
{
SignerWithAddress
}
from
'
@nomiclabs/hardhat-ethers/signers
'
import
{
Contract
}
from
'
ethers
'
import
{
expect
}
from
'
../../setup
'
import
{
deploy
}
from
'
../../helpers
'
describe
(
'
AssetReceiver
'
,
()
=>
{
const
DEFAULT_TOKEN_ID
=
0
const
DEFAULT_AMOUNT
=
hre
.
ethers
.
constants
.
WeiPerEther
const
DEFAULT_RECIPIENT
=
'
0x
'
+
'
11
'
.
repeat
(
20
)
let
signer1
:
SignerWithAddress
let
signer2
:
SignerWithAddress
before
(
'
signer setup
'
,
async
()
=>
{
;[
signer1
,
signer2
]
=
await
hre
.
ethers
.
getSigners
()
})
let
TestERC20
:
Contract
let
TestERC721
:
Contract
let
AssetReceiver
:
Contract
beforeEach
(
'
deploy contracts
'
,
async
()
=>
{
TestERC20
=
await
deploy
(
'
TestERC20
'
,
{
signer
:
signer1
})
TestERC721
=
await
deploy
(
'
TestERC721
'
,
{
signer
:
signer1
})
AssetReceiver
=
await
deploy
(
'
AssetReceiver
'
,
{
signer
:
signer1
,
args
:
[
signer1
.
address
],
})
})
beforeEach
(
'
balance setup
'
,
async
()
=>
{
await
TestERC20
.
mint
(
signer1
.
address
,
hre
.
ethers
.
constants
.
MaxUint256
)
await
TestERC721
.
mint
(
signer1
.
address
,
DEFAULT_TOKEN_ID
)
await
hre
.
ethers
.
provider
.
send
(
'
hardhat_setBalance
'
,
[
DEFAULT_RECIPIENT
,
'
0x0
'
,
])
})
describe
(
'
receive
'
,
()
=>
{
it
(
'
should be able to receive ETH
'
,
async
()
=>
{
await
expect
(
signer1
.
sendTransaction
({
to
:
AssetReceiver
.
address
,
value
:
DEFAULT_AMOUNT
,
})
).
to
.
not
.
be
.
reverted
expect
(
await
hre
.
ethers
.
provider
.
getBalance
(
AssetReceiver
.
address
)
).
to
.
equal
(
DEFAULT_AMOUNT
)
})
})
describe
(
'
withdrawETH(address)
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should withdraw all ETH in the contract
'
,
async
()
=>
{
await
signer1
.
sendTransaction
({
to
:
AssetReceiver
.
address
,
value
:
DEFAULT_AMOUNT
,
})
await
expect
(
AssetReceiver
[
'
withdrawETH(address)
'
](
DEFAULT_RECIPIENT
))
.
to
.
emit
(
AssetReceiver
,
'
WithdrewETH
'
)
.
withArgs
(
signer1
.
address
,
DEFAULT_RECIPIENT
,
DEFAULT_AMOUNT
)
expect
(
await
hre
.
ethers
.
provider
.
getBalance
(
AssetReceiver
.
address
)
).
to
.
equal
(
0
)
expect
(
await
hre
.
ethers
.
provider
.
getBalance
(
DEFAULT_RECIPIENT
)
).
to
.
equal
(
DEFAULT_AMOUNT
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
AssetReceiver
.
connect
(
signer2
)[
'
withdrawETH(address)
'
](
signer2
.
address
)
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
describe
(
'
withdrawETH(address,uint256)
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should withdraw the given amount of ETH
'
,
async
()
=>
{
await
signer1
.
sendTransaction
({
to
:
AssetReceiver
.
address
,
value
:
DEFAULT_AMOUNT
.
mul
(
2
),
})
await
expect
(
AssetReceiver
[
'
withdrawETH(address,uint256)
'
](
DEFAULT_RECIPIENT
,
DEFAULT_AMOUNT
)
)
.
to
.
emit
(
AssetReceiver
,
'
WithdrewETH
'
)
.
withArgs
(
signer1
.
address
,
DEFAULT_RECIPIENT
,
DEFAULT_AMOUNT
)
expect
(
await
hre
.
ethers
.
provider
.
getBalance
(
AssetReceiver
.
address
)
).
to
.
equal
(
DEFAULT_AMOUNT
)
expect
(
await
hre
.
ethers
.
provider
.
getBalance
(
DEFAULT_RECIPIENT
)
).
to
.
equal
(
DEFAULT_AMOUNT
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
AssetReceiver
.
connect
(
signer2
)[
'
withdrawETH(address,uint256)
'
](
DEFAULT_RECIPIENT
,
DEFAULT_AMOUNT
)
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
describe
(
'
withdrawERC20(address,address)
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should withdraw all ERC20 balance held by the contract
'
,
async
()
=>
{
await
TestERC20
.
transfer
(
AssetReceiver
.
address
,
DEFAULT_AMOUNT
)
await
expect
(
AssetReceiver
[
'
withdrawERC20(address,address)
'
](
TestERC20
.
address
,
DEFAULT_RECIPIENT
)
)
.
to
.
emit
(
AssetReceiver
,
'
WithdrewERC20
'
)
.
withArgs
(
signer1
.
address
,
DEFAULT_RECIPIENT
,
TestERC20
.
address
,
DEFAULT_AMOUNT
)
expect
(
await
TestERC20
.
balanceOf
(
DEFAULT_RECIPIENT
)).
to
.
equal
(
DEFAULT_AMOUNT
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
AssetReceiver
.
connect
(
signer2
)[
'
withdrawERC20(address,address)
'
](
TestERC20
.
address
,
DEFAULT_RECIPIENT
)
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
describe
(
'
withdrawERC20(address,address,uint256)
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should withdraw the given ERC20 amount
'
,
async
()
=>
{
await
TestERC20
.
transfer
(
AssetReceiver
.
address
,
DEFAULT_AMOUNT
.
mul
(
2
))
await
expect
(
AssetReceiver
[
'
withdrawERC20(address,address,uint256)
'
](
TestERC20
.
address
,
DEFAULT_RECIPIENT
,
DEFAULT_AMOUNT
)
)
.
to
.
emit
(
AssetReceiver
,
'
WithdrewERC20
'
)
.
withArgs
(
signer1
.
address
,
DEFAULT_RECIPIENT
,
TestERC20
.
address
,
DEFAULT_AMOUNT
)
expect
(
await
TestERC20
.
balanceOf
(
DEFAULT_RECIPIENT
)).
to
.
equal
(
DEFAULT_AMOUNT
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
AssetReceiver
.
connect
(
signer2
)[
'
withdrawERC20(address,address,uint256)
'
](
TestERC20
.
address
,
DEFAULT_RECIPIENT
,
DEFAULT_AMOUNT
)
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
describe
(
'
withdrawERC721
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should withdraw the token
'
,
async
()
=>
{
await
TestERC721
.
transferFrom
(
signer1
.
address
,
AssetReceiver
.
address
,
DEFAULT_TOKEN_ID
)
await
expect
(
AssetReceiver
.
withdrawERC721
(
TestERC721
.
address
,
DEFAULT_RECIPIENT
,
DEFAULT_TOKEN_ID
)
)
.
to
.
emit
(
AssetReceiver
,
'
WithdrewERC721
'
)
.
withArgs
(
signer1
.
address
,
DEFAULT_RECIPIENT
,
TestERC721
.
address
,
DEFAULT_TOKEN_ID
)
expect
(
await
TestERC721
.
ownerOf
(
DEFAULT_TOKEN_ID
)).
to
.
equal
(
DEFAULT_RECIPIENT
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should revert
'
,
async
()
=>
{
await
expect
(
AssetReceiver
.
connect
(
signer2
).
withdrawERC721
(
TestERC721
.
address
,
DEFAULT_RECIPIENT
,
DEFAULT_TOKEN_ID
)
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
})
packages/contracts-periphery/test/contracts/universal/Transactor.spec.ts
deleted
100644 → 0
View file @
4f168994
import
hre
from
'
hardhat
'
import
{
SignerWithAddress
}
from
'
@nomiclabs/hardhat-ethers/signers
'
import
{
Contract
}
from
'
ethers
'
import
{
expect
}
from
'
../../setup
'
import
{
decodeSolidityRevert
,
deploy
}
from
'
../../helpers
'
describe
(
'
Transactor
'
,
()
=>
{
let
signer1
:
SignerWithAddress
let
signer2
:
SignerWithAddress
before
(
'
signer setup
'
,
async
()
=>
{
;[
signer1
,
signer2
]
=
await
hre
.
ethers
.
getSigners
()
})
let
CallRecorder
:
Contract
let
Reverter
:
Contract
let
Transactor
:
Contract
beforeEach
(
'
deploy contracts
'
,
async
()
=>
{
CallRecorder
=
await
deploy
(
'
CallRecorder
'
)
Reverter
=
await
deploy
(
'
Reverter
'
)
Transactor
=
await
deploy
(
'
Transactor
'
,
{
signer
:
signer1
,
args
:
[
signer1
.
address
],
})
})
describe
(
'
CALL
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should do a call to the target contract
'
,
async
()
=>
{
const
data
=
CallRecorder
.
interface
.
encodeFunctionData
(
'
record
'
)
await
Transactor
.
CALL
(
CallRecorder
.
address
,
data
,
0
,
{
gasLimit
:
2
_000_000
,
})
const
call
=
await
CallRecorder
.
lastCall
()
expect
(
call
.
data
).
to
.
equal
(
data
)
expect
(
call
.
sender
).
to
.
equal
(
Transactor
.
address
)
})
it
(
'
should be able to call with value
'
,
async
()
=>
{
const
data
=
CallRecorder
.
interface
.
encodeFunctionData
(
'
record
'
)
const
value
=
69
await
Transactor
.
CALL
(
CallRecorder
.
address
,
data
,
value
,
{
gasLimit
:
2
_000_000
,
value
,
})
const
call
=
await
CallRecorder
.
lastCall
()
expect
(
call
.
value
).
to
.
equal
(
value
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should be reverted
'
,
async
()
=>
{
const
data
=
CallRecorder
.
interface
.
encodeFunctionData
(
'
record
'
)
await
expect
(
Transactor
.
connect
(
signer2
).
CALL
(
CallRecorder
.
address
,
data
,
0
,
{
gasLimit
:
2
_000_000
,
})
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
describe
(
'
DELEGATECALL
'
,
()
=>
{
describe
(
'
when called by authorized address
'
,
()
=>
{
it
(
'
should do a delegatecall to the target contract
'
,
async
()
=>
{
const
data
=
Reverter
.
interface
.
encodeFunctionData
(
'
doRevert
'
)
const
ret
=
await
Transactor
.
callStatic
.
DELEGATECALL
(
Reverter
.
address
,
data
,
{
gasLimit
:
2
_000_000
,
}
)
expect
(
ret
[
0
]).
to
.
equal
(
false
)
expect
(
decodeSolidityRevert
(
ret
[
1
])).
to
.
deep
.
equal
(
'
Reverter reverted
'
)
})
})
describe
(
'
when called by not authorized address
'
,
()
=>
{
it
(
'
should be reverted
'
,
async
()
=>
{
const
data
=
Reverter
.
interface
.
encodeFunctionData
(
'
doRevert
'
)
await
expect
(
Transactor
.
connect
(
signer2
).
DELEGATECALL
(
Reverter
.
address
,
data
,
{
gasLimit
:
2
_000_000
,
})
).
to
.
be
.
revertedWith
(
'
UNAUTHORIZED
'
)
})
})
})
})
packages/contracts-periphery/test/helpers/constants.ts
deleted
100644 → 0
View file @
4f168994
export
const
NON_NULL_BYTES32
=
'
0x
'
+
'
11
'
.
repeat
(
32
)
export
const
NON_ZERO_ADDRESS
=
'
0x
'
+
'
11
'
.
repeat
(
20
)
packages/contracts-periphery/test/helpers/deploy.ts
deleted
100644 → 0
View file @
4f168994
import
hre
from
'
hardhat
'
export
const
deploy
=
async
(
name
:
string
,
opts
?:
{
args
?:
any
[]
signer
?:
any
}
)
=>
{
const
factory
=
await
hre
.
ethers
.
getContractFactory
(
name
,
opts
?.
signer
)
return
factory
.
deploy
(...(
opts
?.
args
||
[]))
}
packages/contracts-periphery/test/helpers/index.ts
deleted
100644 → 0
View file @
4f168994
export
*
from
'
./deploy
'
export
*
from
'
./solidity
'
export
*
from
'
./constants
'
packages/contracts-periphery/test/helpers/solidity.ts
deleted
100644 → 0
View file @
4f168994
import
{
ethers
}
from
'
ethers
'
export
const
decodeSolidityRevert
=
(
revert
:
string
)
=>
{
const
iface
=
new
ethers
.
utils
.
Interface
([
{
inputs
:
[
{
internalType
:
'
string
'
,
name
:
'
message
'
,
type
:
'
string
'
,
},
],
name
:
'
Error
'
,
outputs
:
[],
stateMutability
:
'
nonpayable
'
,
type
:
'
function
'
,
},
])
return
iface
.
decodeFunctionData
(
'
Error
'
,
revert
)[
0
]
}
packages/contracts-periphery/test/setup.ts
deleted
100644 → 0
View file @
4f168994
/* External Imports */
import
chai
=
require
(
'
chai
'
)
import
Mocha
from
'
mocha
'
import
{
solidity
}
from
'
ethereum-waffle
'
chai
.
use
(
solidity
)
const
should
=
chai
.
should
()
const
expect
=
chai
.
expect
export
{
should
,
expect
,
Mocha
}
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