Commit 56efac5b authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #4820 from ethereum-optimism/cleanup/remove-final-hh-tests

ctp: remove final hh tests
parents 4f168994 2190c57d
......@@ -4,15 +4,15 @@ AssetReceiverTest:testFail_withdrawERC721() (gas: 55908)
AssetReceiverTest:testFail_withdrawETH() (gas: 10457)
AssetReceiverTest:testFail_withdrawETHwithAmount() (gas: 10594)
AssetReceiverTest:test_constructor() (gas: 9794)
AssetReceiverTest:test_receive() (gas: 18860)
AssetReceiverTest:test_withdrawERC20() (gas: 183064)
AssetReceiverTest:test_withdrawERC20withAmount() (gas: 182146)
AssetReceiverTest:test_withdrawERC721() (gas: 49097)
AssetReceiverTest:test_withdrawETH() (gas: 26179)
AssetReceiverTest:test_withdrawETHwithAmount() (gas: 26108)
AssetReceiverTest:test_attest_bulk() (gas: 611440)
AssetReceiverTest:test_attest_individual() (gas: 538514)
AssetReceiverTest:test_attest_single() (gas: 558962)
AssetReceiverTest:test_receive() (gas: 21010)
AssetReceiverTest:test_withdrawERC20() (gas: 185529)
AssetReceiverTest:test_withdrawERC20withAmount() (gas: 184609)
AssetReceiverTest:test_withdrawERC721() (gas: 51565)
AssetReceiverTest:test_withdrawETH() (gas: 28774)
AssetReceiverTest:test_withdrawETHwithAmount() (gas: 28703)
AssetReceiverTest:test_attest_bulk() (gas: 611417)
AssetReceiverTest:test_attest_individual() (gas: 538536)
AssetReceiverTest:test_attest_single() (gas: 558939)
CheckBalanceHighTest:testFuzz_check_fails(address,uint256) (runs: 256, μ: 12352, ~: 12382)
CheckBalanceHighTest:testFuzz_check_succeeds(address,uint256) (runs: 256, μ: 10284, ~: 10284)
CheckBalanceLowTest:testFuzz_check_fails(address,uint256) (runs: 256, μ: 10262, ~: 10262)
......@@ -45,7 +45,7 @@ OptimistTest:test_optimist_baseURI() (gas: 116809)
OptimistTest:test_optimist_burn() (gas: 77526)
OptimistTest:test_optimist_initialize() (gas: 23095)
OptimistTest:test_optimist_is_on_allow_list() (gas: 52616)
OptimistTest:test_optimist_mint_already_minted() (gas: 98911)
OptimistTest:test_optimist_mint_already_minted() (gas: 98823)
OptimistTest:test_optimist_mint_happy_path() (gas: 99175)
OptimistTest:test_optimist_mint_no_attestation() (gas: 15897)
OptimistTest:test_optimist_mint_secondary_minter() (gas: 100576)
......@@ -54,9 +54,9 @@ OptimistTest:test_optimist_sbt_transfer() (gas: 102331)
OptimistTest:test_optimist_set_approval_for_all() (gas: 100907)
OptimistTest:test_optimist_supports_interface() (gas: 5797)
OptimistTest:test_optimist_token_id_of_owner() (gas: 95045)
OptimistTest:test_optimist_token_uri() (gas: 213950)
TransactorTest:testFail_CALL() (gas: 15658)
OptimistTest:test_optimist_token_uri() (gas: 213972)
TransactorTest:testFail_CALL() (gas: 15636)
TransactorTest:testFail_DELEGATECALLL() (gas: 15632)
TransactorTest:test_CALL() (gas: 26977)
TransactorTest:test_DELEGATECALL() (gas: 21122)
TransactorTest:test_constructor() (gas: 9782)
TransactorTest:test_CALL() (gas: 26969)
TransactorTest:test_DELEGATECALL() (gas: 21189)
TransactorTest:test_constructor() (gas: 9772)
......@@ -17,7 +17,22 @@ contract AssetReceiver_Initializer is Test {
TestERC721 testERC721;
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
testERC20 = new TestERC20();
testERC721 = new TestERC721();
......@@ -38,10 +53,6 @@ contract AssetReceiver_Initializer is Test {
}
contract AssetReceiverTest is AssetReceiver_Initializer {
function setUp() public {
super._setUp();
}
// Tests if the owner was set correctly during deploy
function test_constructor() external {
assertEq(address(alice), assetReceiver.owner());
......@@ -52,6 +63,8 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
// Check that contract balance is 0 initially
assertEq(address(assetReceiver).balance, 0);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit ReceivedETH(alice, 100);
// Send funds
vm.prank(alice);
(bool success, ) = address(assetReceiver).call{ value: 100 }(hex"");
......@@ -71,6 +84,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(address(alice).balance, 1 ether);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewETH(alice, alice, 1 ether);
// call withdrawETH
vm.prank(alice);
assetReceiver.withdrawETH(payable(alice));
......@@ -96,6 +112,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(address(alice).balance, 1 ether);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewETH(alice, alice, 0.5 ether);
// call withdrawETH
vm.prank(alice);
assetReceiver.withdrawETH(payable(alice), 0.5 ether);
......@@ -121,6 +140,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(testERC20.balanceOf(address(assetReceiver)), 100_000);
assertEq(testERC20.balanceOf(alice), 0);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewERC20(alice, alice, address(testERC20), 100_000);
// call withdrawERC20
vm.prank(alice);
assetReceiver.withdrawERC20(testERC20, alice);
......@@ -146,6 +168,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
assertEq(testERC20.balanceOf(address(assetReceiver)), 100_000);
assertEq(testERC20.balanceOf(alice), 0);
vm.expectEmit(true, true, true, true, address(assetReceiver));
emit WithdrewERC20(alice, alice, address(testERC20), 50_000);
// call withdrawERC20
vm.prank(alice);
assetReceiver.withdrawERC20(testERC20, alice, 50_000);
......@@ -172,6 +197,9 @@ contract AssetReceiverTest is AssetReceiver_Initializer {
testERC721.transferFrom(alice, address(assetReceiver), DEFAULT_TOKEN_ID);
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
vm.prank(alice);
assetReceiver.withdrawERC721(testERC721, alice, DEFAULT_TOKEN_ID);
......
......@@ -11,7 +11,7 @@ contract AssetReceiver_Initializer is Test {
address bob = address(256);
address sally = address(512);
function _setUp() public {
function setUp() public {
// Give alice and bob some ETH
vm.deal(alice_attestor, 1 ether);
......@@ -22,10 +22,6 @@ contract AssetReceiver_Initializer is Test {
}
contract AssetReceiverTest is AssetReceiver_Initializer {
function setUp() public {
super._setUp();
}
event AttestationCreated(
address indexed creator,
address indexed about,
......
......@@ -47,7 +47,7 @@ contract Optimist_Initializer is Test {
attestationStation.attest(attestationData);
}
function _setUp() public {
function setUp() public {
// Give alice and bob and sally some ETH
vm.deal(alice_admin, 1 ether);
vm.deal(bob, 1 ether);
......@@ -68,11 +68,6 @@ contract Optimist_Initializer is Test {
}
contract OptimistTest is Optimist_Initializer {
function setUp() public {
super._setUp();
_initializeContracts();
}
function test_optimist_initialize() external {
// expect name to be set
assertEq(optimist.name(), name);
......
......@@ -15,7 +15,7 @@ contract Transactor_Initializer is Test {
Reverter reverter;
CallRecorder callRecorded;
function _setUp() public {
function setUp() public {
// Deploy Reverter and CallRecorder helper contracts
reverter = new Reverter();
callRecorded = new CallRecorder();
......@@ -34,10 +34,6 @@ contract Transactor_Initializer is Test {
}
contract TransactorTest is Transactor_Initializer {
function setUp() public {
super._setUp();
}
// Tests if the owner was set correctly during deploy
function test_constructor() external {
assertEq(address(alice), transactor.owner());
......@@ -49,7 +45,7 @@ contract TransactorTest is Transactor_Initializer {
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
// Run CALL
vm.prank(alice);
vm.expectCall(address(callRecorded), data);
vm.expectCall(address(callRecorded), 200_000 wei, data);
transactor.CALL(address(callRecorded), data, 200_000 wei);
}
......
......@@ -16,10 +16,9 @@
"build": "yarn build:hh",
"build:hh": "hardhat compile --show-stack-traces",
"build:forge": "forge build",
"test": "yarn test:contracts",
"test:contracts": "hardhat test --show-stack-traces",
"test": "yarn test:forge",
"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:slither": "slither .",
"gas-snapshot": "forge snapshot",
......@@ -64,8 +63,6 @@
"@rari-capital/solmate": "7.0.0-alpha.3",
"@openzeppelin/contracts": "4.7.3",
"@openzeppelin/contracts-upgradeable": "4.7.3",
"@types/chai": "^4.2.18",
"@types/mocha": "^8.2.2",
"@types/node": "^17.0.21",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
......@@ -81,7 +78,6 @@
"hardhat-deploy": "^0.11.10",
"hardhat-gas-reporter": "^1.0.8",
"lint-staged": "11.0.0",
"mocha": "^10.0.0",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.7",
"prettier": "^2.8.0",
......
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')
})
})
})
})
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')
})
})
})
})
export const NON_NULL_BYTES32 = '0x' + '11'.repeat(32)
export const NON_ZERO_ADDRESS = '0x' + '11'.repeat(20)
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 || []))
}
export * from './deploy'
export * from './solidity'
export * from './constants'
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]
}
/* 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 }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment