Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import { Lib_Buffer } from "../../libraries/utils/Lib_Buffer.sol";
*/
contract TestLib_Buffer {
using Lib_Buffer for Lib_Buffer.Buffer;
using Lib_Buffer for Lib_Buffer.BufferContext;

Lib_Buffer.Buffer internal buf;

function push(bytes32 _value, bytes27 _extraData) public {
buf.push(_value, _extraData);
}

function push(bytes32 _value) public {
buf.push(_value);
}

function get(uint256 _index) public view returns (bytes32) {
return buf.get(_index);
}
Expand All @@ -39,4 +44,16 @@ contract TestLib_Buffer {
function getExtraData() public view returns (bytes27) {
return buf.getExtraData();
}

function getContext() public view returns (Lib_Buffer.BufferContext memory) {
return buf.getContext();
}

function setContext(uint40 _index, bytes27 _extraData) public {
Lib_Buffer.BufferContext memory _ctx = Lib_Buffer.BufferContext({
length: _index,
extraData: _extraData
});
return buf.setContext(_ctx);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* External Imports */
import { ethers } from 'hardhat'
import { Contract, Signer, ContractFactory } from 'ethers'

/* Internal Imports */
import { expect } from '../../../setup'
import { NON_ZERO_ADDRESS } from '../../../helpers'

describe('AddressDictator', () => {
let signer: Signer
let otherSigner: Signer
let signerAddress: string
let Factory__AddressDictator: ContractFactory
let Factory__Lib_AddressManager: ContractFactory
before(async () => {
;[signer, otherSigner] = await ethers.getSigners()

Factory__AddressDictator = await ethers.getContractFactory(
'AddressDictator'
)

Factory__Lib_AddressManager = await ethers.getContractFactory(
'Lib_AddressManager'
)

signerAddress = await signer.getAddress()
})

let AddressDictator: Contract
let Lib_AddressManager: Contract
beforeEach(async () => {
Lib_AddressManager = await Factory__Lib_AddressManager.connect(
signer
).deploy()

AddressDictator = await Factory__AddressDictator.connect(signer).deploy(
Lib_AddressManager.address,
signerAddress,
['addr1'],
[NON_ZERO_ADDRESS]
)

Lib_AddressManager.transferOwnership(AddressDictator.address)
})

describe('initialize', () => {
it('should revert when providing wrong arguments', async () => {
await expect(
Factory__AddressDictator.connect(signer).deploy(
Lib_AddressManager.address,
signerAddress,
['addr1', 'addr2'],
[NON_ZERO_ADDRESS]
)
).to.be.revertedWith(
'AddressDictator: Must provide an equal number of names and addresses.'
)
})
})

describe('setAddresses', async () => {
it('should change the addresses associated with a name', async () => {
await AddressDictator.setAddresses()
expect(await Lib_AddressManager.getAddress('addr1')).to.be.equal(
NON_ZERO_ADDRESS
)
})
})

describe('getNamedAddresses', () => {
it('should return all the addresses and their names', async () => {
expect(await AddressDictator.getNamedAddresses()).to.be.deep.equal([
['addr1', NON_ZERO_ADDRESS],
])
})
})

describe('returnOwnership', () => {
it('should transfer contract ownership to finalOwner', async () => {
await expect(AddressDictator.connect(signer).returnOwnership()).to.not.be
.reverted
})

it('should revert when called by non-owner', async () => {
await expect(
AddressDictator.connect(otherSigner).returnOwnership()
).to.be.revertedWith('AddressDictator: only callable by finalOwner')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* External Imports */
import { ethers } from 'hardhat'
import { Contract, Signer, ContractFactory } from 'ethers'

/* Internal Imports */
import { expect } from '../../../setup'

describe('ChugSplashDictator', () => {
let signer: Signer
let otherSigner: Signer
let signerAddress: string

let Factory__L1ChugSplashProxy: ContractFactory
let Factory__ChugSplashDictator: ContractFactory
before(async () => {
;[signer, otherSigner] = await ethers.getSigners()

Factory__L1ChugSplashProxy = await ethers.getContractFactory(
'L1ChugSplashProxy'
)

Factory__ChugSplashDictator = await ethers.getContractFactory(
'ChugSplashDictator'
)

signerAddress = await signer.getAddress()
})

let L1ChugSplashProxy: Contract
let ChugSplashDictator: Contract
beforeEach(async () => {
L1ChugSplashProxy = await Factory__L1ChugSplashProxy.connect(signer).deploy(
signerAddress
)

ChugSplashDictator = await Factory__ChugSplashDictator.connect(
signer
).deploy(
L1ChugSplashProxy.address,
signerAddress,
ethers.utils.keccak256('0x1111'),
ethers.utils.keccak256('0x1234'),
ethers.utils.keccak256('0x5678'),
ethers.utils.keccak256('0x1234'),
ethers.utils.keccak256('0x1234')
)

await L1ChugSplashProxy.connect(signer).setOwner(ChugSplashDictator.address)
})

describe('doActions', () => {
it('should revert when sent wrong code', async () => {
await expect(ChugSplashDictator.doActions('0x2222')).to.be.revertedWith(
'ChugSplashDictator: Incorrect code hash.'
)
})

it('should set the proxy code, storage & owner', async () => {
await expect(ChugSplashDictator.connect(signer).doActions('0x1111')).to
.not.be.reverted
})
})

describe('returnOwnership', () => {
it('should transfer contractc ownership to finalOwner', async () => {
await expect(ChugSplashDictator.connect(signer).returnOwnership()).to.not
.be.reverted
})

it('should revert when called by non-owner', async () => {
await expect(
ChugSplashDictator.connect(otherSigner).returnOwnership()
).to.be.revertedWith('ChugSplashDictator: only callable by finalOwner')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, BigNumber } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock'
import { smock, MockContractFactory } from '@defi-wonderland/smock'
import {
remove0x,
toHexString,
Expand Down Expand Up @@ -347,6 +348,28 @@ describe('L1CrossDomainMessenger', () => {
})
})

describe('xDomainMessageSender', () => {
let Mock__Factory__L1CrossDomainMessenger: MockContractFactory<ContractFactory>
let Mock__L1CrossDomainMessenger
before(async () => {
Mock__Factory__L1CrossDomainMessenger = await smock.mock(
'L1CrossDomainMessenger'
)
Mock__L1CrossDomainMessenger =
await Mock__Factory__L1CrossDomainMessenger.deploy()
})

it('should return the xDomainMsgSender address', async () => {
await Mock__L1CrossDomainMessenger.setVariable(
'xDomainMsgSender',
'0x0000000000000000000000000000000000000000'
)
expect(
await Mock__L1CrossDomainMessenger.xDomainMessageSender()
).to.equal('0x0000000000000000000000000000000000000000')
})
})

const generateMockRelayMessageProof = async (
target: string,
sender: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ describe('L1StandardBridge', () => {
})
})

describe('receive', () => {
it('should send an amount of ETH to the callers balance on L2', async () => {
await expect(
alice.sendTransaction({
to: L1StandardBridge.address,
data: '0x',
})
).to.not.be.reverted
})
})

describe('ETH deposits', () => {
const depositAmount = 1_000

Expand Down Expand Up @@ -564,4 +575,18 @@ describe('L1StandardBridge', () => {
)
})
})

describe('donateETH', () => {
it('it should just call the function', async () => {
await expect(L1StandardBridge.donateETH()).to.not.be.reverted
})

it('should send ETH to the contract account', async () => {
await expect(
L1StandardBridge.donateETH({
value: 100,
})
).to.not.be.reverted
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ describe('CanonicalTransactionChain', () => {
).to.be.revertedWith('Insufficient gas for L2 rate limiting burn.')
})

it('should burn L1 gas when L2 gas limit is high', async () => {
const _enqueueL2GasPrepaid =
await CanonicalTransactionChain.enqueueL2GasPrepaid()
const data = '0x' + '12'.repeat(1234)

// Create a tx with high L2 gas limit
const l2GasLimit = 4 * _enqueueL2GasPrepaid

await expect(CanonicalTransactionChain.enqueue(target, l2GasLimit, data))
.to.not.be.reverted
})

describe('with valid input parameters', () => {
it('should emit a TransactionEnqueued event', async () => {
const timestamp = (await getEthTime(ethers.provider)) + 100
Expand Down
Loading