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', () => {
setupRun(async () => {
const wallet = Wallet.createRandom()
await env.l2Wallet.sendTransaction({
const tx = await env.l2Wallet.sendTransaction({
to: wallet.address,
value: utils.parseEther('0.01'),
})
await tx.wait()
return {
wallet: wallet.connect(env.l2Wallet.provider),
}
......@@ -61,10 +62,11 @@ actor('Value sender', () => {
run(async (b, ctx: Context) => {
const randWallet = Wallet.createRandom().connect(env.l2Wallet.provider)
await b.bench('send funds', async () => {
await ctx.wallet.sendTransaction({
const tx = await ctx.wallet.sendTransaction({
to: randWallet.address,
value: 0x42,
})
await tx.wait()
})
expect(await randWallet.getBalance()).to.deep.equal(BigNumber.from(0x42))
})
......@@ -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.
# TYPE actor_failed_actor_runs_total counter
```
\ No newline at end of file
```
......@@ -21,10 +21,11 @@ actor('Funds depositor', () => {
setupRun(async () => {
const wallet = Wallet.createRandom()
await env.l1Wallet.sendTransaction({
const tx = await env.l1Wallet.sendTransaction({
to: wallet.address,
value: utils.parseEther('0.01'),
})
await tx.wait()
return {
l1Wallet: wallet.connect(env.l1Wallet.provider),
l2Wallet: wallet.connect(env.l2Wallet.provider),
......@@ -36,7 +37,7 @@ actor('Funds depositor', () => {
const balBefore = await l2Wallet.getBalance()
await b.bench('deposit', async () => {
await env.waitForXDomainTransaction(
env.l1Bridge
env.messenger.contracts.l1.L1StandardBridge
.connect(l1Wallet)
.depositETH(DEFAULT_TEST_GAS_L2, '0xFFFF', {
value: 0x42,
......@@ -44,8 +45,10 @@ actor('Funds depositor', () => {
})
)
})
expect((await l2Wallet.getBalance()).sub(balBefore)).to.deep.equal(
BigNumber.from(0x42)
// Converting BigNumber to hex string prevents chai from incorrectly considering inherited properties
// 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', () => {
setupRun(async () => {
const wallet = Wallet.createRandom().connect(env.l2Wallet.provider)
await env.l2Wallet.sendTransaction({
const tx = await env.l2Wallet.sendTransaction({
to: wallet.address,
value: utils.parseEther('0.01'),
})
await tx.wait()
return {
wallet,
contract: contract.connect(wallet),
......
......@@ -17,10 +17,11 @@ actor('Value sender', () => {
setupRun(async () => {
const wallet = Wallet.createRandom()
await env.l2Wallet.sendTransaction({
const tx = await env.l2Wallet.sendTransaction({
to: wallet.address,
value: utils.parseEther('0.01'),
})
await tx.wait()
return {
wallet: wallet.connect(env.l2Wallet.provider),
}
......@@ -29,10 +30,11 @@ actor('Value sender', () => {
run(async (b, ctx: Context) => {
const randWallet = Wallet.createRandom().connect(env.l2Wallet.provider)
await b.bench('send funds', async () => {
await ctx.wallet.sendTransaction({
const tx = await ctx.wallet.sendTransaction({
to: randWallet.address,
value: 0x42,
})
await tx.wait()
})
expect((await randWallet.getBalance()).toString()).to.deep.equal('66')
})
......
......@@ -24,10 +24,11 @@ actor('Trie DoS accounts', () => {
setupRun(async () => {
const wallet = Wallet.createRandom()
await env.l2Wallet.sendTransaction({
const tx = await env.l2Wallet.sendTransaction({
to: wallet.address,
value: utils.parseEther('1'),
})
await tx.wait()
return {
wallet: wallet.connect(env.l2Wallet.provider),
}
......
......@@ -50,10 +50,11 @@ actor('Uniswap swapper', () => {
setupRun(async () => {
const wallet = Wallet.createRandom().connect(env.l2Provider)
await env.l2Wallet.sendTransaction({
const sendTx = await env.l2Wallet.sendTransaction({
to: wallet.address,
value: utils.parseEther('0.1'),
})
await sendTx.wait()
for (const token of tokens) {
let tx = await token.transfer(wallet.address, 1000000)
......
......@@ -51,8 +51,9 @@ import (
)
var (
errNoSequencerURL = errors.New("sequencer transaction forwarding not configured")
errStillSyncing = errors.New("sequencer still syncing, cannot accept transactions")
errNoSequencerURL = errors.New("sequencer transaction forwarding not configured")
errStillSyncing = errors.New("sequencer still syncing, cannot accept transactions")
errBlockNotIndexed = errors.New("block in range not indexed, this should never happen")
)
const (
......@@ -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 number := startNumber; number <= endNumber; number++ {
block, err := s.GetBlockByNumber(ctx, number, fullTx)
if block == nil || err != nil {
if err != nil {
return nil, err
}
if block == nil {
return nil, errBlockNotIndexed
}
blocks = append(blocks, block)
}
return blocks, nil
......
......@@ -66,6 +66,12 @@ var SystemAddressDeployers = map[uint64]SystemAddressDeployer{
common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
},
// Goerli nightly
421: {
common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
},
}
var envSystemAddressDeployer SystemAddressDeployer
......
......@@ -31,6 +31,11 @@ func TestSystemAddressFor(t *testing.T) {
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
420,
},
{
common.HexToAddress("0xc30276833798867c1dbc5c468bf51ca900b44e4c"),
common.HexToAddress("0x5c679a57e018f5f146838138d3e032ef4913d551"),
421,
},
}
for _, tt := range tests {
chainID := big.NewInt(tt.chainId)
......
......@@ -15,7 +15,6 @@
"ops/docker/js-builder"
],
"nohoist": [
"examples/*",
"**/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": [
{
"inputs": [
......@@ -167,28 +167,28 @@
"type": "function"
}
],
"transactionHash": "0x7def186f652eda213f178ca0f287217030cdee226893ebdc6b0ccc0405a14edc",
"transactionHash": "0x2a9a6a33e3601ab2bca01f16f0c2c21f23cc0e39a142b7d218de42fdc2caa0a4",
"receipt": {
"to": null,
"from": "0x3a605B442055DF2898E18cF518feb2e2A6BD0D31",
"contractAddress": "0xf2b91614E8826f7A01b13dF8AeC5501403C9B0Fd",
"transactionIndex": 7,
"gasUsed": "600252",
"from": "0x26D58aD41d2BE997C02802468B92F1eaB4f8b95C",
"contractAddress": "0x2523d13F455531446950DB9C3a88c06431997D97",
"transactionIndex": 23,
"gasUsed": "600240",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"blockHash": "0xb557f1dcb15b221968f0c33b0f9bcbf0dee42374f9fd00aeb51c64a962bfe5c1",
"transactionHash": "0x7def186f652eda213f178ca0f287217030cdee226893ebdc6b0ccc0405a14edc",
"blockHash": "0xed27d12347f019f5ac699739ca67d6d0ef56ff54b49f8955ed171000288580f9",
"transactionHash": "0x2a9a6a33e3601ab2bca01f16f0c2c21f23cc0e39a142b7d218de42fdc2caa0a4",
"logs": [],
"blockNumber": 6680783,
"cumulativeGasUsed": "1328789",
"blockNumber": 6754215,
"cumulativeGasUsed": "5796759",
"status": 1,
"byzantium": true
},
"args": [
"0xe352dDE5d101BB422f78C3eD77f2cD8f0b9B0f82",
"0x4600216A9C733658A48Ef83Ad218BA221514894E",
"0x4F3F400c20448D33ECc12E7d289F49dA7fC51736",
"0x2e552c5e1eaa6bcb8ea89d558309b9a8a26daa8cfe310169433a912499962b95",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x00000000000000000000000084a374C4082252FCEc215C242513c15551b15976",
"0x000000000000000000000000497cdD0F36b3D3012C1fEa605332E77E942C494a",
"0x0000000000000000000000000000000000000000000000000000000000000001",
"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
</a>
</td>
</tr>
<tr>
<td>
TeleportrDeposit
</td>
<td align="center">
<a href="https://etherscan.io/address/0x52ec2F3d7C5977A8E558C8D9C6000B615098E8fC">
<code>0x52ec2F3d7C5977A8E558C8D9C6000B615098E8fC</code>
</a>
</td>
</tr>
</table>
## Layer 2 Contracts
......
This diff is collapsed.
......@@ -110,7 +110,10 @@ const config: HardhatUserConfig = {
outputFile: process.env.CI ? 'gas-report.txt' : undefined,
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
apiKey: {
mainnet: process.env.ETHERSCAN_API_KEY,
optimisticEthereum: process.env.OPTIMISTIC_ETHERSCAN_API_KEY,
},
},
dodoc: {
runOnCompile: true,
......
......@@ -70,7 +70,7 @@
"@ethersproject/providers": "^5.6.0",
"@nomiclabs/ethereumjs-vm": "^4.2.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",
"@openzeppelin/contracts": "4.3.2",
"@openzeppelin/contracts-upgradeable": "4.3.2",
......
import { ethers } from 'ethers'
import { task } from 'hardhat/config'
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 { getContractFromArtifact } from '../src/deploy-utils'
......@@ -52,28 +56,42 @@ task('fetch-batches')
const tx = await provider.getTransaction(event.transactionHash)
const batch = (SequencerBatch as any).fromHex(tx.data)
// Add an extra field to the resulting json
// so that the serialization sizes can be observed
// Add extra fields to the resulting json
// so that the serialization sizes and gas usage can be observed
const json = batch.toJSON()
json.sizes = {
legacy: 0,
zlib: 0,
}
json.gasUsage = {
legacy: 0,
zlib: 0,
}
// Create a copy of the batch to serialize in
// the alternative format
const copy = (SequencerBatch as any).fromHex(tx.data)
let legacy: Buffer
let zlib: Buffer
if (batch.type === BatchType.ZLIB) {
copy.type = BatchType.LEGACY
json.sizes.legacy = copy.encode().length
json.sizes.zlib = batch.encode().length
legacy = copy.encode()
zlib = batch.encode()
} else {
copy.type = BatchType.ZLIB
json.sizes.zlib = copy.encode().length
json.sizes.legacy = batch.encode().length
zlib = copy.encode()
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)
}
......
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 { deploy, NON_ZERO_ADDRESS } from '../../../helpers'
describe('AddressDictator', () => {
let signer1: Signer
let signer2: Signer
let signer1: SignerWithAddress
let signer2: SignerWithAddress
before(async () => {
;[signer1, signer2] = await ethers.getSigners()
})
......@@ -22,15 +23,13 @@ describe('AddressDictator', () => {
signer: signer1,
args: [
Lib_AddressManager.address,
await signer1.getAddress(),
signer1.address,
['addr1'],
[NON_ZERO_ADDRESS],
],
})
Lib_AddressManager.connect(signer1).transferOwnership(
AddressDictator.address
)
Lib_AddressManager.transferOwnership(AddressDictator.address)
})
describe('initialize', () => {
......@@ -40,7 +39,7 @@ describe('AddressDictator', () => {
signer: signer1,
args: [
Lib_AddressManager.address,
await signer1.getAddress(),
signer1.address,
['addr1', 'addr2'],
[NON_ZERO_ADDRESS],
],
......@@ -70,8 +69,7 @@ describe('AddressDictator', () => {
describe('returnOwnership', () => {
it('should transfer contract ownership to finalOwner', async () => {
await expect(AddressDictator.connect(signer1).returnOwnership()).to.not.be
.reverted
await expect(AddressDictator.returnOwnership()).to.not.be.reverted
})
it('should revert when called by non-owner', async () => {
......
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 { deploy } from '../../../helpers'
describe('ChugSplashDictator', () => {
let signer1: Signer
let signer2: Signer
let signer1: SignerWithAddress
let signer2: SignerWithAddress
before(async () => {
;[signer1, signer2] = await ethers.getSigners()
})
......@@ -16,14 +17,14 @@ describe('ChugSplashDictator', () => {
beforeEach(async () => {
L1ChugSplashProxy = await deploy('L1ChugSplashProxy', {
signer: signer1,
args: [await signer1.getAddress()],
args: [signer1.address],
})
ChugSplashDictator = await deploy('ChugSplashDictator', {
signer: signer1,
args: [
L1ChugSplashProxy.address,
await signer1.getAddress(),
signer1.address,
ethers.utils.keccak256('0x1111'),
ethers.utils.keccak256('0x1234'),
ethers.utils.keccak256('0x5678'),
......@@ -32,9 +33,7 @@ describe('ChugSplashDictator', () => {
],
})
await L1ChugSplashProxy.connect(signer1).setOwner(
ChugSplashDictator.address
)
await L1ChugSplashProxy.setOwner(ChugSplashDictator.address)
})
describe('doActions', () => {
......@@ -45,15 +44,13 @@ describe('ChugSplashDictator', () => {
})
it('should set the proxy code, storage & owner', async () => {
await expect(ChugSplashDictator.connect(signer1).doActions('0x1111')).to
.not.be.reverted
await expect(ChugSplashDictator.doActions('0x1111')).to.not.be.reverted
})
})
describe('returnOwnership', () => {
it('should transfer contractc ownership to finalOwner', async () => {
await expect(ChugSplashDictator.connect(signer1).returnOwnership()).to.not
.be.reverted
await expect(ChugSplashDictator.returnOwnership()).to.not.be.reverted
})
it('should revert when called by non-owner', async () => {
......
......@@ -6,7 +6,6 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from '../../../setup'
import {
setProxyTarget,
NON_NULL_BYTES32,
NON_ZERO_ADDRESS,
DUMMY_BATCH_HEADERS,
......@@ -57,10 +56,9 @@ describe('L1CrossDomainMessenger', () => {
Fake__L2CrossDomainMessenger.address
)
await setProxyTarget(
AddressManager,
await AddressManager.setAddress(
'StateCommitmentChain',
Fake__StateCommitmentChain
Fake__StateCommitmentChain.address
)
CanonicalTransactionChain = await deploy('CanonicalTransactionChain', {
......
......@@ -13,7 +13,6 @@ import { TransactionResponse } from '@ethersproject/abstract-provider'
/* Internal Imports */
import {
deploy,
setProxyTarget,
L2_GAS_DISCOUNT_DIVISOR,
ENQUEUE_GAS_COST,
getEthTime,
......@@ -59,10 +58,9 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain [ @skip-on-coverage ]', () =
'StateCommitmentChain'
)
await setProxyTarget(
AddressManager,
await AddressManager.setAddress(
'StateCommitmentChain',
Fake__StateCommitmentChain
Fake__StateCommitmentChain.address
)
CanonicalTransactionChain = await deploy('CanonicalTransactionChain', {
......
......@@ -12,7 +12,6 @@ import _ from 'lodash'
import { expect } from '../../../setup'
import {
deploy,
setProxyTarget,
L2_GAS_DISCOUNT_DIVISOR,
ENQUEUE_GAS_COST,
setEthTime,
......@@ -67,10 +66,9 @@ describe('CanonicalTransactionChain', () => {
'StateCommitmentChain'
)
await setProxyTarget(
AddressManager,
await AddressManager.setAddress(
'StateCommitmentChain',
Fake__StateCommitmentChain
Fake__StateCommitmentChain.address
)
CanonicalTransactionChain = await deploy('CanonicalTransactionChain', {
......
......@@ -6,7 +6,6 @@ import { smock, FakeContract } from '@defi-wonderland/smock'
import { expect } from '../../../setup'
import {
deploy,
setProxyTarget,
NON_NULL_BYTES32,
getEthTime,
increaseEthTime,
......@@ -30,15 +29,14 @@ describe('StateCommitmentChain', () => {
'CanonicalTransactionChain'
)
await setProxyTarget(
AddressManager,
await AddressManager.setAddress(
'CanonicalTransactionChain',
Fake__CanonicalTransactionChain
Fake__CanonicalTransactionChain.address
)
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)
......
/* External Imports */
import { ethers } from 'hardhat'
import { Contract, Signer, ContractFactory } from 'ethers'
import {
smock,
MockContractFactory,
MockContract,
} from '@defi-wonderland/smock'
/* Internal Imports */
import { Contract } from 'ethers'
import { smock, MockContract } from '@defi-wonderland/smock'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from '../../../setup'
describe('WETH9', () => {
let signer: Signer
let otherSigner: Signer
let signerAddress: string
let otherSignerAddress: string
let signer: SignerWithAddress
let otherSigner: SignerWithAddress
let Mock__Factory_WETH9: MockContractFactory<ContractFactory>
let Mock__WETH9: MockContract<Contract>
before(async () => {
;[signer, otherSigner] = await ethers.getSigners()
signerAddress = await signer.getAddress()
otherSignerAddress = await otherSigner.getAddress()
})
let Mock__WETH9: MockContract<Contract>
beforeEach(async () => {
Mock__Factory_WETH9 = await smock.mock('WETH9')
Mock__WETH9 = await Mock__Factory_WETH9.deploy()
Mock__WETH9 = await (await smock.mock('WETH9')).deploy()
})
describe('deposit', () => {
......@@ -38,26 +27,25 @@ describe('WETH9', () => {
})
).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 () => {
await expect(Mock__WETH9.connect(signer).deposit({ value: 100 })).to.not
.be.reverted
await expect(Mock__WETH9.deposit({ value: 100 })).to.not.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', () => {
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 () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 })
await expect(Mock__WETH9.connect(signer).withdraw(50)).to.not.be.reverted
expect(await Mock__WETH9.balanceOf(signerAddress)).to.be.equal(50)
await Mock__WETH9.deposit({ value: 100 })
await expect(Mock__WETH9.withdraw(50)).to.not.be.reverted
expect(await Mock__WETH9.balanceOf(signer.address)).to.be.equal(50)
})
})
......@@ -69,42 +57,41 @@ describe('WETH9', () => {
describe('transfer', () => {
it('should revert when sending more than deposited', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 })
await expect(
Mock__WETH9.connect(signer).transfer(otherSignerAddress, 500)
).to.be.reverted
await Mock__WETH9.deposit({ value: 100 })
await expect(Mock__WETH9.transfer(otherSigner.address, 500)).to.be
.reverted
})
it('should transfer WETH to an other address', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 })
await expect(Mock__WETH9.connect(signer).transfer(otherSignerAddress, 50))
.to.not.be.reverted
await Mock__WETH9.deposit({ value: 100 })
await expect(Mock__WETH9.transfer(otherSigner.address, 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)
expect(await Mock__WETH9.balanceOf(otherSignerAddress)).to.be.equal(50)
expect(await Mock__WETH9.balanceOf(otherSigner.address)).to.be.equal(50)
})
})
describe('transferFrom', () => {
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(
Mock__WETH9.connect(otherSigner).transferFrom(
signerAddress,
otherSignerAddress,
signer.address,
otherSigner.address,
50
)
).to.be.reverted
})
it('should transfer WETH to an other address when there is approvement', async () => {
await Mock__WETH9.connect(signer).deposit({ value: 100 })
await Mock__WETH9.connect(signer).approve(otherSignerAddress, 50)
await Mock__WETH9.deposit({ value: 100 })
await Mock__WETH9.approve(otherSigner.address, 50)
await expect(
Mock__WETH9.connect(otherSigner).transferFrom(
signerAddress,
otherSignerAddress,
signer.address,
otherSigner.address,
50
)
).to.not.be.reverted
......
export * from './dummy'
export * from './constants'
export * from './resolver'
export * from './utils'
export * from './codec'
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 @@
*/
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'
import { remove0x } from '../common'
const txDataZeroGas = 4
const txDataNonZeroGasEIP2028 = 16
export const txDataZeroGas = 4
export const txDataNonZeroGasEIP2028 = 16
const big10 = BigNumber.from(10)
export const scaleDecimals = (
......@@ -63,3 +63,17 @@ export const zeroesAndOnes = (data: Buffer | string): Array<number> => {
}
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', () => {
it('should count zeros and ones', () => {
......@@ -15,4 +19,19 @@ describe('Fees', () => {
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 @@
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-ethers/-/hardhat-ethers-2.0.2.tgz#c472abcba0c5185aaa4ad4070146e95213c68511"
integrity sha512-6quxWe8wwS4X5v3Au8q1jOvXYEPkS1Fh+cME5u6AwNdnI4uERvPlVjlgRWzpnb+Rrt1l/cEqiNRH9GlsBMSDQg==
"@nomiclabs/hardhat-etherscan@^2.1.6":
version "2.1.6"
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-2.1.6.tgz#8d1502f42adc6f7b8ef16fb917c0b5a8780cb83a"
integrity sha512-gCvT5fj8GbXS9+ACS3BzrX0pzYHHZqAHCb+NcipOkl2cy48FakUXlzrCf4P4sTH+Y7W10OgT62ezD1sJ+/NikQ==
"@nomiclabs/hardhat-etherscan@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-3.0.3.tgz#ca54a03351f3de41f9f5240e37bea9d64fa24e64"
integrity sha512-OfNtUKc/ZwzivmZnnpwWREfaYncXteKHskn3yDnz+fPBZ6wfM4GR+d5RwjREzYFWE+o5iR9ruXhWw/8fejWM9g==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "^5.0.2"
cbor "^5.0.2"
debug "^4.1.1"
fs-extra "^7.0.1"
node-fetch "^2.6.0"
semver "^6.3.0"
undici "^4.14.1"
"@nomiclabs/hardhat-waffle@^2.0.1":
version "2.0.1"
......@@ -11566,7 +11566,7 @@ node-fetch@2.6.1:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
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"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
......@@ -15430,11 +15430,6 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
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:
version "0.22.13"
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.22.13.tgz#d061f8f0fb7c9d686e48814f245bddeea4564e66"
......@@ -15446,6 +15441,11 @@ typedoc@^0.22.13:
minimatch "^5.0.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:
version "1.2.0"
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