Commit a1ef09dd authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2525 from ethereum-optimism/develop

Develop -> Master
parents 9396c809 36a91c30
---
'@eth-optimism/l2geth': patch
---
Fix `eth_getBlockRange`
---
'@eth-optimism/l2geth': patch
---
Add system addresses for nightly goerli
---
'@eth-optimism/contracts': patch
---
Add Teleportr mainnet deployment
---
'@eth-optimism/core-utils': patch
---
Add a `calldataCost` function that computes the cost of calldata
---
'@eth-optimism/integration-tests': patch
---
Fix various actor tests
---
'@eth-optimism/core-utils': patch
---
Adds a one-liner for getting chain ID from provider
...@@ -49,10 +49,11 @@ actor('Value sender', () => { ...@@ -49,10 +49,11 @@ actor('Value sender', () => {
setupRun(async () => { setupRun(async () => {
const wallet = Wallet.createRandom() const wallet = Wallet.createRandom()
await env.l2Wallet.sendTransaction({ const tx = await env.l2Wallet.sendTransaction({
to: wallet.address, to: wallet.address,
value: utils.parseEther('0.01'), value: utils.parseEther('0.01'),
}) })
await tx.wait()
return { return {
wallet: wallet.connect(env.l2Wallet.provider), wallet: wallet.connect(env.l2Wallet.provider),
} }
...@@ -61,10 +62,11 @@ actor('Value sender', () => { ...@@ -61,10 +62,11 @@ actor('Value sender', () => {
run(async (b, ctx: Context) => { run(async (b, ctx: Context) => {
const randWallet = Wallet.createRandom().connect(env.l2Wallet.provider) const randWallet = Wallet.createRandom().connect(env.l2Wallet.provider)
await b.bench('send funds', async () => { await b.bench('send funds', async () => {
await ctx.wallet.sendTransaction({ const tx = await ctx.wallet.sendTransaction({
to: randWallet.address, to: randWallet.address,
value: 0x42, value: 0x42,
}) })
await tx.wait()
}) })
expect(await randWallet.getBalance()).to.deep.equal(BigNumber.from(0x42)) expect(await randWallet.getBalance()).to.deep.equal(BigNumber.from(0x42))
}) })
...@@ -163,4 +165,4 @@ actor_successful_actor_runs_total{actor_name="value_sender"} 40 ...@@ -163,4 +165,4 @@ actor_successful_actor_runs_total{actor_name="value_sender"} 40
# HELP actor_failed_actor_runs_total Count of total failed actor runs. # HELP actor_failed_actor_runs_total Count of total failed actor runs.
# TYPE actor_failed_actor_runs_total counter # TYPE actor_failed_actor_runs_total counter
``` ```
\ No newline at end of file
...@@ -21,10 +21,11 @@ actor('Funds depositor', () => { ...@@ -21,10 +21,11 @@ actor('Funds depositor', () => {
setupRun(async () => { setupRun(async () => {
const wallet = Wallet.createRandom() const wallet = Wallet.createRandom()
await env.l1Wallet.sendTransaction({ const tx = await env.l1Wallet.sendTransaction({
to: wallet.address, to: wallet.address,
value: utils.parseEther('0.01'), value: utils.parseEther('0.01'),
}) })
await tx.wait()
return { return {
l1Wallet: wallet.connect(env.l1Wallet.provider), l1Wallet: wallet.connect(env.l1Wallet.provider),
l2Wallet: wallet.connect(env.l2Wallet.provider), l2Wallet: wallet.connect(env.l2Wallet.provider),
...@@ -36,7 +37,7 @@ actor('Funds depositor', () => { ...@@ -36,7 +37,7 @@ actor('Funds depositor', () => {
const balBefore = await l2Wallet.getBalance() const balBefore = await l2Wallet.getBalance()
await b.bench('deposit', async () => { await b.bench('deposit', async () => {
await env.waitForXDomainTransaction( await env.waitForXDomainTransaction(
env.l1Bridge env.messenger.contracts.l1.L1StandardBridge
.connect(l1Wallet) .connect(l1Wallet)
.depositETH(DEFAULT_TEST_GAS_L2, '0xFFFF', { .depositETH(DEFAULT_TEST_GAS_L2, '0xFFFF', {
value: 0x42, value: 0x42,
...@@ -44,8 +45,10 @@ actor('Funds depositor', () => { ...@@ -44,8 +45,10 @@ actor('Funds depositor', () => {
}) })
) )
}) })
expect((await l2Wallet.getBalance()).sub(balBefore)).to.deep.equal( // Converting BigNumber to hex string prevents chai from incorrectly considering inherited properties
BigNumber.from(0x42) // for strict equality - https://github.com/chaijs/chai/issues/948
expect((await l2Wallet.getBalance()).sub(balBefore).toString()).to.deep.equal(
BigNumber.from(0x42).toString()
) )
}) })
}) })
...@@ -22,10 +22,11 @@ actor('NFT claimer', () => { ...@@ -22,10 +22,11 @@ actor('NFT claimer', () => {
setupRun(async () => { setupRun(async () => {
const wallet = Wallet.createRandom().connect(env.l2Wallet.provider) const wallet = Wallet.createRandom().connect(env.l2Wallet.provider)
await env.l2Wallet.sendTransaction({ const tx = await env.l2Wallet.sendTransaction({
to: wallet.address, to: wallet.address,
value: utils.parseEther('0.01'), value: utils.parseEther('0.01'),
}) })
await tx.wait()
return { return {
wallet, wallet,
contract: contract.connect(wallet), contract: contract.connect(wallet),
......
...@@ -17,10 +17,11 @@ actor('Value sender', () => { ...@@ -17,10 +17,11 @@ actor('Value sender', () => {
setupRun(async () => { setupRun(async () => {
const wallet = Wallet.createRandom() const wallet = Wallet.createRandom()
await env.l2Wallet.sendTransaction({ const tx = await env.l2Wallet.sendTransaction({
to: wallet.address, to: wallet.address,
value: utils.parseEther('0.01'), value: utils.parseEther('0.01'),
}) })
await tx.wait()
return { return {
wallet: wallet.connect(env.l2Wallet.provider), wallet: wallet.connect(env.l2Wallet.provider),
} }
...@@ -29,10 +30,11 @@ actor('Value sender', () => { ...@@ -29,10 +30,11 @@ actor('Value sender', () => {
run(async (b, ctx: Context) => { run(async (b, ctx: Context) => {
const randWallet = Wallet.createRandom().connect(env.l2Wallet.provider) const randWallet = Wallet.createRandom().connect(env.l2Wallet.provider)
await b.bench('send funds', async () => { await b.bench('send funds', async () => {
await ctx.wallet.sendTransaction({ const tx = await ctx.wallet.sendTransaction({
to: randWallet.address, to: randWallet.address,
value: 0x42, value: 0x42,
}) })
await tx.wait()
}) })
expect((await randWallet.getBalance()).toString()).to.deep.equal('66') expect((await randWallet.getBalance()).toString()).to.deep.equal('66')
}) })
......
...@@ -24,10 +24,11 @@ actor('Trie DoS accounts', () => { ...@@ -24,10 +24,11 @@ actor('Trie DoS accounts', () => {
setupRun(async () => { setupRun(async () => {
const wallet = Wallet.createRandom() const wallet = Wallet.createRandom()
await env.l2Wallet.sendTransaction({ const tx = await env.l2Wallet.sendTransaction({
to: wallet.address, to: wallet.address,
value: utils.parseEther('1'), value: utils.parseEther('1'),
}) })
await tx.wait()
return { return {
wallet: wallet.connect(env.l2Wallet.provider), wallet: wallet.connect(env.l2Wallet.provider),
} }
......
...@@ -50,10 +50,11 @@ actor('Uniswap swapper', () => { ...@@ -50,10 +50,11 @@ actor('Uniswap swapper', () => {
setupRun(async () => { setupRun(async () => {
const wallet = Wallet.createRandom().connect(env.l2Provider) const wallet = Wallet.createRandom().connect(env.l2Provider)
await env.l2Wallet.sendTransaction({ const sendTx = await env.l2Wallet.sendTransaction({
to: wallet.address, to: wallet.address,
value: utils.parseEther('0.1'), value: utils.parseEther('0.1'),
}) })
await sendTx.wait()
for (const token of tokens) { for (const token of tokens) {
let tx = await token.transfer(wallet.address, 1000000) let tx = await token.transfer(wallet.address, 1000000)
......
...@@ -51,8 +51,9 @@ import ( ...@@ -51,8 +51,9 @@ import (
) )
var ( var (
errNoSequencerURL = errors.New("sequencer transaction forwarding not configured") errNoSequencerURL = errors.New("sequencer transaction forwarding not configured")
errStillSyncing = errors.New("sequencer still syncing, cannot accept transactions") errStillSyncing = errors.New("sequencer still syncing, cannot accept transactions")
errBlockNotIndexed = errors.New("block in range not indexed, this should never happen")
) )
const ( const (
...@@ -780,9 +781,12 @@ func (s *PublicBlockChainAPI) GetBlockRange(ctx context.Context, startNumber rpc ...@@ -780,9 +781,12 @@ func (s *PublicBlockChainAPI) GetBlockRange(ctx context.Context, startNumber rpc
// For each block in range, get block and append to array. // For each block in range, get block and append to array.
for number := startNumber; number <= endNumber; number++ { for number := startNumber; number <= endNumber; number++ {
block, err := s.GetBlockByNumber(ctx, number, fullTx) block, err := s.GetBlockByNumber(ctx, number, fullTx)
if block == nil || err != nil { if err != nil {
return nil, err return nil, err
} }
if block == nil {
return nil, errBlockNotIndexed
}
blocks = append(blocks, block) blocks = append(blocks, block)
} }
return blocks, nil return blocks, nil
......
...@@ -66,6 +66,12 @@ var SystemAddressDeployers = map[uint64]SystemAddressDeployer{ ...@@ -66,6 +66,12 @@ var SystemAddressDeployers = map[uint64]SystemAddressDeployer{
common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"), common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"), common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
}, },
// Goerli nightly
421: {
common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
},
} }
var envSystemAddressDeployer SystemAddressDeployer var envSystemAddressDeployer SystemAddressDeployer
......
...@@ -31,6 +31,11 @@ func TestSystemAddressFor(t *testing.T) { ...@@ -31,6 +31,11 @@ func TestSystemAddressFor(t *testing.T) {
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"), common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
420, 420,
}, },
{
common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
421,
},
} }
for _, tt := range tests { for _, tt := range tests {
chainID := big.NewInt(tt.chainId) chainID := big.NewInt(tt.chainId)
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
"ops/docker/js-builder" "ops/docker/js-builder"
], ],
"nohoist": [ "nohoist": [
"examples/*",
"**/typechain", "**/typechain",
"**/@typechain/*" "**/@typechain/*"
] ]
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"address": "0xf2b91614E8826f7A01b13dF8AeC5501403C9B0Fd", "address": "0x2523d13F455531446950DB9C3a88c06431997D97",
"abi": [ "abi": [
{ {
"inputs": [ "inputs": [
...@@ -167,28 +167,28 @@ ...@@ -167,28 +167,28 @@
"type": "function" "type": "function"
} }
], ],
"transactionHash": "0x7def186f652eda213f178ca0f287217030cdee226893ebdc6b0ccc0405a14edc", "transactionHash": "0x2a9a6a33e3601ab2bca01f16f0c2c21f23cc0e39a142b7d218de42fdc2caa0a4",
"receipt": { "receipt": {
"to": null, "to": null,
"from": "0x3a605B442055DF2898E18cF518feb2e2A6BD0D31", "from": "0x26D58aD41d2BE997C02802468B92F1eaB4f8b95C",
"contractAddress": "0xf2b91614E8826f7A01b13dF8AeC5501403C9B0Fd", "contractAddress": "0x2523d13F455531446950DB9C3a88c06431997D97",
"transactionIndex": 7, "transactionIndex": 23,
"gasUsed": "600252", "gasUsed": "600240",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"blockHash": "0xb557f1dcb15b221968f0c33b0f9bcbf0dee42374f9fd00aeb51c64a962bfe5c1", "blockHash": "0xed27d12347f019f5ac699739ca67d6d0ef56ff54b49f8955ed171000288580f9",
"transactionHash": "0x7def186f652eda213f178ca0f287217030cdee226893ebdc6b0ccc0405a14edc", "transactionHash": "0x2a9a6a33e3601ab2bca01f16f0c2c21f23cc0e39a142b7d218de42fdc2caa0a4",
"logs": [], "logs": [],
"blockNumber": 6680783, "blockNumber": 6754215,
"cumulativeGasUsed": "1328789", "cumulativeGasUsed": "5796759",
"status": 1, "status": 1,
"byzantium": true "byzantium": true
}, },
"args": [ "args": [
"0xe352dDE5d101BB422f78C3eD77f2cD8f0b9B0f82", "0x4600216A9C733658A48Ef83Ad218BA221514894E",
"0x4F3F400c20448D33ECc12E7d289F49dA7fC51736", "0x4F3F400c20448D33ECc12E7d289F49dA7fC51736",
"0x2e552c5e1eaa6bcb8ea89d558309b9a8a26daa8cfe310169433a912499962b95", "0x2e552c5e1eaa6bcb8ea89d558309b9a8a26daa8cfe310169433a912499962b95",
"0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000",
"0x00000000000000000000000084a374C4082252FCEc215C242513c15551b15976", "0x000000000000000000000000497cdD0F36b3D3012C1fEa605332E77E942C494a",
"0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000004200000000000000000000000000000000000010" "0x0000000000000000000000004200000000000000000000000000000000000010"
], ],
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -95,6 +95,16 @@ StateCommitmentChain ...@@ -95,6 +95,16 @@ StateCommitmentChain
</a> </a>
</td> </td>
</tr> </tr>
<tr>
<td>
TeleportrDeposit
</td>
<td align="center">
<a href="https://etherscan.io/address/0x52ec2F3d7C5977A8E558C8D9C6000B615098E8fC">
<code>0x52ec2F3d7C5977A8E558C8D9C6000B615098E8fC</code>
</a>
</td>
</tr>
</table> </table>
## Layer 2 Contracts ## Layer 2 Contracts
......
This diff is collapsed.
...@@ -238,10 +238,6 @@ ...@@ -238,10 +238,6 @@
"devdoc", "devdoc",
"userdoc", "userdoc",
"devdoc", "devdoc",
"userdoc",
"devdoc",
"userdoc",
"devdoc",
"userdoc" "userdoc"
], ],
"": [ "": [
......
...@@ -110,7 +110,10 @@ const config: HardhatUserConfig = { ...@@ -110,7 +110,10 @@ const config: HardhatUserConfig = {
outputFile: process.env.CI ? 'gas-report.txt' : undefined, outputFile: process.env.CI ? 'gas-report.txt' : undefined,
}, },
etherscan: { etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY, apiKey: {
mainnet: process.env.ETHERSCAN_API_KEY,
optimisticEthereum: process.env.OPTIMISTIC_ETHERSCAN_API_KEY,
},
}, },
dodoc: { dodoc: {
runOnCompile: true, runOnCompile: true,
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
"@ethersproject/providers": "^5.6.0", "@ethersproject/providers": "^5.6.0",
"@nomiclabs/ethereumjs-vm": "^4.2.2", "@nomiclabs/ethereumjs-vm": "^4.2.2",
"@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.6", "@nomiclabs/hardhat-etherscan": "^3.0.3",
"@nomiclabs/hardhat-waffle": "^2.0.1", "@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "4.3.2", "@openzeppelin/contracts": "4.3.2",
"@openzeppelin/contracts-upgradeable": "4.3.2", "@openzeppelin/contracts-upgradeable": "4.3.2",
......
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { task } from 'hardhat/config' import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes' import * as types from 'hardhat/internal/core/params/argumentTypes'
import { BatchType, SequencerBatch } from '@eth-optimism/core-utils' import {
BatchType,
SequencerBatch,
calldataCost,
} from '@eth-optimism/core-utils'
import { names } from '../src/address-names' import { names } from '../src/address-names'
import { getContractFromArtifact } from '../src/deploy-utils' import { getContractFromArtifact } from '../src/deploy-utils'
...@@ -52,28 +56,42 @@ task('fetch-batches') ...@@ -52,28 +56,42 @@ task('fetch-batches')
const tx = await provider.getTransaction(event.transactionHash) const tx = await provider.getTransaction(event.transactionHash)
const batch = (SequencerBatch as any).fromHex(tx.data) const batch = (SequencerBatch as any).fromHex(tx.data)
// Add an extra field to the resulting json // Add extra fields to the resulting json
// so that the serialization sizes can be observed // so that the serialization sizes and gas usage can be observed
const json = batch.toJSON() const json = batch.toJSON()
json.sizes = { json.sizes = {
legacy: 0, legacy: 0,
zlib: 0, zlib: 0,
} }
json.gasUsage = {
legacy: 0,
zlib: 0,
}
// Create a copy of the batch to serialize in // Create a copy of the batch to serialize in
// the alternative format // the alternative format
const copy = (SequencerBatch as any).fromHex(tx.data) const copy = (SequencerBatch as any).fromHex(tx.data)
let legacy: Buffer
let zlib: Buffer
if (batch.type === BatchType.ZLIB) { if (batch.type === BatchType.ZLIB) {
copy.type = BatchType.LEGACY copy.type = BatchType.LEGACY
json.sizes.legacy = copy.encode().length legacy = copy.encode()
json.sizes.zlib = batch.encode().length zlib = batch.encode()
} else { } else {
copy.type = BatchType.ZLIB copy.type = BatchType.ZLIB
json.sizes.zlib = copy.encode().length zlib = copy.encode()
json.sizes.legacy = batch.encode().length legacy = batch.encode()
} }
json.compressionRatio = json.sizes.zlib / json.sizes.legacy json.sizes.legacy = legacy.length
json.sizes.zlib = zlib.length
json.sizes.compressionRatio = json.sizes.zlib / json.sizes.legacy
json.gasUsage.legacy = calldataCost(legacy).toNumber()
json.gasUsage.zlib = calldataCost(zlib).toNumber()
json.gasUsage.compressionRatio =
json.gasUsage.zlib / json.gasUsage.legacy
batches.push(json) batches.push(json)
} }
......
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract, Signer } from 'ethers' import { Contract } from 'ethers'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from '../../../setup' import { expect } from '../../../setup'
import { deploy, NON_ZERO_ADDRESS } from '../../../helpers' import { deploy, NON_ZERO_ADDRESS } from '../../../helpers'
describe('AddressDictator', () => { describe('AddressDictator', () => {
let signer1: Signer let signer1: SignerWithAddress
let signer2: Signer let signer2: SignerWithAddress
before(async () => { before(async () => {
;[signer1, signer2] = await ethers.getSigners() ;[signer1, signer2] = await ethers.getSigners()
}) })
...@@ -22,15 +23,13 @@ describe('AddressDictator', () => { ...@@ -22,15 +23,13 @@ describe('AddressDictator', () => {
signer: signer1, signer: signer1,
args: [ args: [
Lib_AddressManager.address, Lib_AddressManager.address,
await signer1.getAddress(), signer1.address,
['addr1'], ['addr1'],
[NON_ZERO_ADDRESS], [NON_ZERO_ADDRESS],
], ],
}) })
Lib_AddressManager.connect(signer1).transferOwnership( Lib_AddressManager.transferOwnership(AddressDictator.address)
AddressDictator.address
)
}) })
describe('initialize', () => { describe('initialize', () => {
...@@ -40,7 +39,7 @@ describe('AddressDictator', () => { ...@@ -40,7 +39,7 @@ describe('AddressDictator', () => {
signer: signer1, signer: signer1,
args: [ args: [
Lib_AddressManager.address, Lib_AddressManager.address,
await signer1.getAddress(), signer1.address,
['addr1', 'addr2'], ['addr1', 'addr2'],
[NON_ZERO_ADDRESS], [NON_ZERO_ADDRESS],
], ],
...@@ -70,8 +69,7 @@ describe('AddressDictator', () => { ...@@ -70,8 +69,7 @@ describe('AddressDictator', () => {
describe('returnOwnership', () => { describe('returnOwnership', () => {
it('should transfer contract ownership to finalOwner', async () => { it('should transfer contract ownership to finalOwner', async () => {
await expect(AddressDictator.connect(signer1).returnOwnership()).to.not.be await expect(AddressDictator.returnOwnership()).to.not.be.reverted
.reverted
}) })
it('should revert when called by non-owner', async () => { it('should revert when called by non-owner', async () => {
......
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract, Signer } from 'ethers' import { Contract } from 'ethers'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from '../../../setup' import { expect } from '../../../setup'
import { deploy } from '../../../helpers' import { deploy } from '../../../helpers'
describe('ChugSplashDictator', () => { describe('ChugSplashDictator', () => {
let signer1: Signer let signer1: SignerWithAddress
let signer2: Signer let signer2: SignerWithAddress
before(async () => { before(async () => {
;[signer1, signer2] = await ethers.getSigners() ;[signer1, signer2] = await ethers.getSigners()
}) })
...@@ -16,14 +17,14 @@ describe('ChugSplashDictator', () => { ...@@ -16,14 +17,14 @@ describe('ChugSplashDictator', () => {
beforeEach(async () => { beforeEach(async () => {
L1ChugSplashProxy = await deploy('L1ChugSplashProxy', { L1ChugSplashProxy = await deploy('L1ChugSplashProxy', {
signer: signer1, signer: signer1,
args: [await signer1.getAddress()], args: [signer1.address],
}) })
ChugSplashDictator = await deploy('ChugSplashDictator', { ChugSplashDictator = await deploy('ChugSplashDictator', {
signer: signer1, signer: signer1,
args: [ args: [
L1ChugSplashProxy.address, L1ChugSplashProxy.address,
await signer1.getAddress(), signer1.address,
ethers.utils.keccak256('0x1111'), ethers.utils.keccak256('0x1111'),
ethers.utils.keccak256('0x1234'), ethers.utils.keccak256('0x1234'),
ethers.utils.keccak256('0x5678'), ethers.utils.keccak256('0x5678'),
...@@ -32,9 +33,7 @@ describe('ChugSplashDictator', () => { ...@@ -32,9 +33,7 @@ describe('ChugSplashDictator', () => {
], ],
}) })
await L1ChugSplashProxy.connect(signer1).setOwner( await L1ChugSplashProxy.setOwner(ChugSplashDictator.address)
ChugSplashDictator.address
)
}) })
describe('doActions', () => { describe('doActions', () => {
...@@ -45,15 +44,13 @@ describe('ChugSplashDictator', () => { ...@@ -45,15 +44,13 @@ describe('ChugSplashDictator', () => {
}) })
it('should set the proxy code, storage & owner', async () => { it('should set the proxy code, storage & owner', async () => {
await expect(ChugSplashDictator.connect(signer1).doActions('0x1111')).to await expect(ChugSplashDictator.doActions('0x1111')).to.not.be.reverted
.not.be.reverted
}) })
}) })
describe('returnOwnership', () => { describe('returnOwnership', () => {
it('should transfer contractc ownership to finalOwner', async () => { it('should transfer contractc ownership to finalOwner', async () => {
await expect(ChugSplashDictator.connect(signer1).returnOwnership()).to.not await expect(ChugSplashDictator.returnOwnership()).to.not.be.reverted
.be.reverted
}) })
it('should revert when called by non-owner', async () => { it('should revert when called by non-owner', async () => {
......
...@@ -6,7 +6,6 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' ...@@ -6,7 +6,6 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from '../../../setup' import { expect } from '../../../setup'
import { import {
setProxyTarget,
NON_NULL_BYTES32, NON_NULL_BYTES32,
NON_ZERO_ADDRESS, NON_ZERO_ADDRESS,
DUMMY_BATCH_HEADERS, DUMMY_BATCH_HEADERS,
...@@ -57,10 +56,9 @@ describe('L1CrossDomainMessenger', () => { ...@@ -57,10 +56,9 @@ describe('L1CrossDomainMessenger', () => {
Fake__L2CrossDomainMessenger.address Fake__L2CrossDomainMessenger.address
) )
await setProxyTarget( await AddressManager.setAddress(
AddressManager,
'StateCommitmentChain', 'StateCommitmentChain',
Fake__StateCommitmentChain Fake__StateCommitmentChain.address
) )
CanonicalTransactionChain = await deploy('CanonicalTransactionChain', { CanonicalTransactionChain = await deploy('CanonicalTransactionChain', {
......
...@@ -13,7 +13,6 @@ import { TransactionResponse } from '@ethersproject/abstract-provider' ...@@ -13,7 +13,6 @@ import { TransactionResponse } from '@ethersproject/abstract-provider'
/* Internal Imports */ /* Internal Imports */
import { import {
deploy, deploy,
setProxyTarget,
L2_GAS_DISCOUNT_DIVISOR, L2_GAS_DISCOUNT_DIVISOR,
ENQUEUE_GAS_COST, ENQUEUE_GAS_COST,
getEthTime, getEthTime,
...@@ -59,10 +58,9 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () = ...@@ -59,10 +58,9 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () =
'StateCommitmentChain' 'StateCommitmentChain'
) )
await setProxyTarget( await AddressManager.setAddress(
AddressManager,
'StateCommitmentChain', 'StateCommitmentChain',
Fake__StateCommitmentChain Fake__StateCommitmentChain.address
) )
CanonicalTransactionChain = await deploy('CanonicalTransactionChain', { CanonicalTransactionChain = await deploy('CanonicalTransactionChain', {
......
...@@ -12,7 +12,6 @@ import _ from 'lodash' ...@@ -12,7 +12,6 @@ import _ from 'lodash'
import { expect } from '../../../setup' import { expect } from '../../../setup'
import { import {
deploy, deploy,
setProxyTarget,
L2_GAS_DISCOUNT_DIVISOR, L2_GAS_DISCOUNT_DIVISOR,
ENQUEUE_GAS_COST, ENQUEUE_GAS_COST,
setEthTime, setEthTime,
...@@ -67,10 +66,9 @@ describe('CanonicalTransactionChain', () => { ...@@ -67,10 +66,9 @@ describe('CanonicalTransactionChain', () => {
'StateCommitmentChain' 'StateCommitmentChain'
) )
await setProxyTarget( await AddressManager.setAddress(
AddressManager,
'StateCommitmentChain', 'StateCommitmentChain',
Fake__StateCommitmentChain Fake__StateCommitmentChain.address
) )
CanonicalTransactionChain = await deploy('CanonicalTransactionChain', { CanonicalTransactionChain = await deploy('CanonicalTransactionChain', {
......
...@@ -6,7 +6,6 @@ import { smock, FakeContract } from '@defi-wonderland/smock' ...@@ -6,7 +6,6 @@ import { smock, FakeContract } from '@defi-wonderland/smock'
import { expect } from '../../../setup' import { expect } from '../../../setup'
import { import {
deploy, deploy,
setProxyTarget,
NON_NULL_BYTES32, NON_NULL_BYTES32,
getEthTime, getEthTime,
increaseEthTime, increaseEthTime,
...@@ -30,15 +29,14 @@ describe('StateCommitmentChain', () => { ...@@ -30,15 +29,14 @@ describe('StateCommitmentChain', () => {
'CanonicalTransactionChain' 'CanonicalTransactionChain'
) )
await setProxyTarget( await AddressManager.setAddress(
AddressManager,
'CanonicalTransactionChain', 'CanonicalTransactionChain',
Fake__CanonicalTransactionChain Fake__CanonicalTransactionChain.address
) )
Fake__BondManager = await smock.fake<Contract>('BondManager') Fake__BondManager = await smock.fake<Contract>('BondManager')
await setProxyTarget(AddressManager, 'BondManager', Fake__BondManager) await AddressManager.setAddress('BondManager', Fake__BondManager.address)
Fake__BondManager.isCollateralized.returns(true) Fake__BondManager.isCollateralized.returns(true)
......
/* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract, Signer, ContractFactory } from 'ethers' import { Contract } from 'ethers'
import { import { smock, MockContract } from '@defi-wonderland/smock'
smock, import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
MockContractFactory,
MockContract,
} from '@defi-wonderland/smock'
/* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
describe('WETH9', () => { describe('WETH9', () => {
let signer: Signer let signer: SignerWithAddress
let otherSigner: Signer let otherSigner: SignerWithAddress
let signerAddress: string
let otherSignerAddress: string
let Mock__Factory_WETH9: MockContractFactory<ContractFactory>
let Mock__WETH9: MockContract<Contract>
before(async () => { before(async () => {
;[signer, otherSigner] = await ethers.getSigners() ;[signer, otherSigner] = await ethers.getSigners()
signerAddress = await signer.getAddress()
otherSignerAddress = await otherSigner.getAddress()
}) })
let Mock__WETH9: MockContract<Contract>
beforeEach(async () => { beforeEach(async () => {
Mock__Factory_WETH9 = await smock.mock('WETH9') Mock__WETH9 = await (await smock.mock('WETH9')).deploy()
Mock__WETH9 = await Mock__Factory_WETH9.deploy()
}) })
describe('deposit', () => { describe('deposit', () => {
...@@ -38,26 +27,25 @@ describe('WETH9', () => { ...@@ -38,26 +27,25 @@ describe('WETH9', () => {
}) })
).to.not.be.reverted ).to.not.be.reverted
expect(await Mock__WETH9.balanceOf(signerAddress)).to.be.equal(200) expect(await Mock__WETH9.balanceOf(signer.address)).to.be.equal(200)
}) })
it('should create WETH with deposit function', async () => { it('should create WETH with deposit function', async () => {
await expect(Mock__WETH9.connect(signer).deposit({ value: 100 })).to.not await expect(Mock__WETH9.deposit({ value: 100 })).to.not.be.reverted
.be.reverted
expect(await Mock__WETH9.balanceOf(signerAddress)).to.be.equal(100) expect(await Mock__WETH9.balanceOf(signer.address)).to.be.equal(100)
}) })
}) })
describe('withdraw', () => { describe('withdraw', () => {
it('should revert when withdraw amount is bigger than balance', async () => { it('should revert when withdraw amount is bigger than balance', async () => {
await expect(Mock__WETH9.connect(signer).withdraw(10000)).to.be.reverted await expect(Mock__WETH9.withdraw(10000)).to.be.reverted
}) })
it('should withdraw to eth', async () => { it('should withdraw to eth', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 }) await Mock__WETH9.deposit({ value: 100 })
await expect(Mock__WETH9.connect(signer).withdraw(50)).to.not.be.reverted await expect(Mock__WETH9.withdraw(50)).to.not.be.reverted
expect(await Mock__WETH9.balanceOf(signerAddress)).to.be.equal(50) expect(await Mock__WETH9.balanceOf(signer.address)).to.be.equal(50)
}) })
}) })
...@@ -69,42 +57,41 @@ describe('WETH9', () => { ...@@ -69,42 +57,41 @@ describe('WETH9', () => {
describe('transfer', () => { describe('transfer', () => {
it('should revert when sending more than deposited', async () => { it('should revert when sending more than deposited', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 }) await Mock__WETH9.deposit({ value: 100 })
await expect( await expect(Mock__WETH9.transfer(otherSigner.address, 500)).to.be
Mock__WETH9.connect(signer).transfer(otherSignerAddress, 500) .reverted
).to.be.reverted
}) })
it('should transfer WETH to an other address', async () => { it('should transfer WETH to an other address', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 }) await Mock__WETH9.deposit({ value: 100 })
await expect(Mock__WETH9.connect(signer).transfer(otherSignerAddress, 50)) await expect(Mock__WETH9.transfer(otherSigner.address, 50)).to.not.be
.to.not.be.reverted .reverted
expect(await Mock__WETH9.balanceOf(signerAddress)).to.be.equal(50) expect(await Mock__WETH9.balanceOf(signer.address)).to.be.equal(50)
expect(await Mock__WETH9.balanceOf(otherSignerAddress)).to.be.equal(50) expect(await Mock__WETH9.balanceOf(otherSigner.address)).to.be.equal(50)
}) })
}) })
describe('transferFrom', () => { describe('transferFrom', () => {
it('should revert when there is no allowance', async () => { it('should revert when there is no allowance', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 }) await Mock__WETH9.deposit({ value: 100 })
await expect( await expect(
Mock__WETH9.connect(otherSigner).transferFrom( Mock__WETH9.connect(otherSigner).transferFrom(
signerAddress, signer.address,
otherSignerAddress, otherSigner.address,
50 50
) )
).to.be.reverted ).to.be.reverted
}) })
it('should transfer WETH to an other address when there is approvement', async () => { it('should transfer WETH to an other address when there is approvement', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 }) await Mock__WETH9.deposit({ value: 100 })
await Mock__WETH9.connect(signer).approve(otherSignerAddress, 50) await Mock__WETH9.approve(otherSigner.address, 50)
await expect( await expect(
Mock__WETH9.connect(otherSigner).transferFrom( Mock__WETH9.connect(otherSigner).transferFrom(
signerAddress, signer.address,
otherSignerAddress, otherSigner.address,
50 50
) )
).to.not.be.reverted ).to.not.be.reverted
......
export * from './dummy' export * from './dummy'
export * from './constants' export * from './constants'
export * from './resolver'
export * from './utils' export * from './utils'
export * from './codec' export * from './codec'
export * from './test-runner' export * from './test-runner'
......
/* External Imports */
import { ethers } from 'hardhat'
import { Contract } from 'ethers'
import { FakeContract } from '@defi-wonderland/smock'
export const setProxyTarget = async (
AddressManager: Contract,
name: string,
target: FakeContract
): Promise<void> => {
const SimpleProxy: Contract = await (
await ethers.getContractFactory('Helper_SimpleProxy')
).deploy()
await SimpleProxy.setTarget(target.address)
await AddressManager.setAddress(name, SimpleProxy.address)
}
export const makeAddressManager = async (): Promise<Contract> => {
return (await ethers.getContractFactory('Lib_AddressManager')).deploy()
}
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
*/ */
export * from './fallback-provider' export * from './fallback-provider'
export * from './network'
import { Provider } from '@ethersproject/abstract-provider'
export const getChainId = async (provider: Provider): Promise<number> => {
const network = await provider.getNetwork()
return network.chainId
}
...@@ -6,8 +6,8 @@ import { BigNumber } from 'ethers' ...@@ -6,8 +6,8 @@ import { BigNumber } from 'ethers'
import { remove0x } from '../common' import { remove0x } from '../common'
const txDataZeroGas = 4 export const txDataZeroGas = 4
const txDataNonZeroGasEIP2028 = 16 export const txDataNonZeroGasEIP2028 = 16
const big10 = BigNumber.from(10) const big10 = BigNumber.from(10)
export const scaleDecimals = ( export const scaleDecimals = (
...@@ -63,3 +63,17 @@ export const zeroesAndOnes = (data: Buffer | string): Array<number> => { ...@@ -63,3 +63,17 @@ export const zeroesAndOnes = (data: Buffer | string): Array<number> => {
} }
return [zeros, ones] return [zeros, ones]
} }
/**
* Computes the L1 calldata cost of bytes based
* on the London hardfork.
*
* @param data {Buffer|string} Bytes
* @returns {BigNumber} Gas consumed by the bytes
*/
export const calldataCost = (data: Buffer | string): BigNumber => {
const [zeros, ones] = zeroesAndOnes(data)
const zeroCost = BigNumber.from(zeros).mul(txDataZeroGas)
const nonZeroCost = BigNumber.from(ones).mul(txDataNonZeroGasEIP2028)
return zeroCost.add(nonZeroCost)
}
import { zeroesAndOnes } from '../src' import './setup'
import { BigNumber } from 'ethers'
import { zeroesAndOnes, calldataCost } from '../src'
describe('Fees', () => { describe('Fees', () => {
it('should count zeros and ones', () => { it('should count zeros and ones', () => {
...@@ -15,4 +19,19 @@ describe('Fees', () => { ...@@ -15,4 +19,19 @@ describe('Fees', () => {
ones.should.eq(test.ones) ones.should.eq(test.ones)
} }
}) })
it('should compute calldata costs', () => {
const cases = [
{ input: '0x', output: BigNumber.from(0) },
{ input: '0x00', output: BigNumber.from(4) },
{ input: '0xff', output: BigNumber.from(16) },
{ input: Buffer.alloc(32), output: BigNumber.from(4 * 32) },
{ input: Buffer.alloc(32, 0xff), output: BigNumber.from(16 * 32) },
]
for (const test of cases) {
const cost = calldataCost(test.input)
cost.should.deep.eq(test.output)
}
})
}) })
...@@ -2520,18 +2520,18 @@ ...@@ -2520,18 +2520,18 @@
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-ethers/-/hardhat-ethers-2.0.2.tgz#c472abcba0c5185aaa4ad4070146e95213c68511" resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-ethers/-/hardhat-ethers-2.0.2.tgz#c472abcba0c5185aaa4ad4070146e95213c68511"
integrity sha512-6quxWe8wwS4X5v3Au8q1jOvXYEPkS1Fh+cME5u6AwNdnI4uERvPlVjlgRWzpnb+Rrt1l/cEqiNRH9GlsBMSDQg== integrity sha512-6quxWe8wwS4X5v3Au8q1jOvXYEPkS1Fh+cME5u6AwNdnI4uERvPlVjlgRWzpnb+Rrt1l/cEqiNRH9GlsBMSDQg==
"@nomiclabs/hardhat-etherscan@^2.1.6": "@nomiclabs/hardhat-etherscan@^3.0.3":
version "2.1.6" version "3.0.3"
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-2.1.6.tgz#8d1502f42adc6f7b8ef16fb917c0b5a8780cb83a" resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-3.0.3.tgz#ca54a03351f3de41f9f5240e37bea9d64fa24e64"
integrity sha512-gCvT5fj8GbXS9+ACS3BzrX0pzYHHZqAHCb+NcipOkl2cy48FakUXlzrCf4P4sTH+Y7W10OgT62ezD1sJ+/NikQ== integrity sha512-OfNtUKc/ZwzivmZnnpwWREfaYncXteKHskn3yDnz+fPBZ6wfM4GR+d5RwjREzYFWE+o5iR9ruXhWw/8fejWM9g==
dependencies: dependencies:
"@ethersproject/abi" "^5.1.2" "@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "^5.0.2" "@ethersproject/address" "^5.0.2"
cbor "^5.0.2" cbor "^5.0.2"
debug "^4.1.1" debug "^4.1.1"
fs-extra "^7.0.1" fs-extra "^7.0.1"
node-fetch "^2.6.0"
semver "^6.3.0" semver "^6.3.0"
undici "^4.14.1"
"@nomiclabs/hardhat-waffle@^2.0.1": "@nomiclabs/hardhat-waffle@^2.0.1":
version "2.0.1" version "2.0.1"
...@@ -11566,7 +11566,7 @@ node-fetch@2.6.1: ...@@ -11566,7 +11566,7 @@ node-fetch@2.6.1:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7: node-fetch@^2.6.1, node-fetch@^2.6.7:
version "2.6.7" version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
...@@ -15430,11 +15430,6 @@ typedarray@^0.0.6: ...@@ -15430,11 +15430,6 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
typescript@^4.3.4, typescript@^4.3.5, typescript@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4"
integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==
typedoc@^0.22.13: typedoc@^0.22.13:
version "0.22.13" version "0.22.13"
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.22.13.tgz#d061f8f0fb7c9d686e48814f245bddeea4564e66" resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.22.13.tgz#d061f8f0fb7c9d686e48814f245bddeea4564e66"
...@@ -15446,6 +15441,11 @@ typedoc@^0.22.13: ...@@ -15446,6 +15441,11 @@ typedoc@^0.22.13:
minimatch "^5.0.1" minimatch "^5.0.1"
shiki "^0.10.1" shiki "^0.10.1"
typescript@^4.3.4, typescript@^4.3.5, typescript@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4"
integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==
typewise-core@^1.2, typewise-core@^1.2.0: typewise-core@^1.2, typewise-core@^1.2.0:
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/typewise-core/-/typewise-core-1.2.0.tgz#97eb91805c7f55d2f941748fa50d315d991ef195" resolved "https://registry.yarnpkg.com/typewise-core/-/typewise-core-1.2.0.tgz#97eb91805c7f55d2f941748fa50d315d991ef195"
......
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