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
@@ -1,57 +1,50 @@
/* External Imports */
import { ethers } from 'hardhat'
import { Contract, Signer, ContractFactory } from 'ethers'
import { Contract, Signer } from 'ethers'

/* Internal Imports */
import { expect } from '../../../setup'
import { NON_ZERO_ADDRESS } from '../../../helpers'
import { deploy, 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
let signer1: Signer
let signer2: Signer
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()
;[signer1, signer2] = await ethers.getSigners()
})

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

AddressDictator = await Factory__AddressDictator.connect(signer).deploy(
Lib_AddressManager.address,
signerAddress,
['addr1'],
[NON_ZERO_ADDRESS]
)
AddressDictator = await deploy('AddressDictator', {
signer: signer1,
args: [
Lib_AddressManager.address,
await signer1.getAddress(),
['addr1'],
[NON_ZERO_ADDRESS],
],
})

Lib_AddressManager.transferOwnership(AddressDictator.address)
Lib_AddressManager.connect(signer1).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]
)
deploy('AddressDictator', {
signer: signer1,
args: [
Lib_AddressManager.address,
await signer1.getAddress(),
['addr1', 'addr2'],
[NON_ZERO_ADDRESS],
],
})
).to.be.revertedWith(
'AddressDictator: Must provide an equal number of names and addresses.'
)
Expand All @@ -61,29 +54,29 @@ describe('AddressDictator', () => {
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(
expect(await Lib_AddressManager.getAddress('addr1')).to.equal(
NON_ZERO_ADDRESS
)
})
})

describe('getNamedAddresses', () => {
it('should return all the addresses and their names', async () => {
expect(await AddressDictator.getNamedAddresses()).to.be.deep.equal([
expect(await AddressDictator.getNamedAddresses()).to.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
await expect(AddressDictator.connect(signer1).returnOwnership()).to.not.be
.reverted
})

it('should revert when called by non-owner', async () => {
await expect(
AddressDictator.connect(otherSigner).returnOwnership()
AddressDictator.connect(signer2).returnOwnership()
).to.be.revertedWith('AddressDictator: only callable by finalOwner')
})
})
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ethers } from 'hardhat'
import { Contract, Signer } from 'ethers'

import { expect } from '../../../setup'
import { deploy } from '../../../helpers'

describe('ChugSplashDictator', () => {
let signer1: Signer
let signer2: Signer
before(async () => {
;[signer1, signer2] = await ethers.getSigners()
})

let L1ChugSplashProxy: Contract
let ChugSplashDictator: Contract
beforeEach(async () => {
L1ChugSplashProxy = await deploy('L1ChugSplashProxy', {
signer: signer1,
args: [await signer1.getAddress()],
})

ChugSplashDictator = await deploy('ChugSplashDictator', {
signer: signer1,
args: [
L1ChugSplashProxy.address,
await signer1.getAddress(),
ethers.utils.keccak256('0x1111'),
ethers.utils.keccak256('0x1234'),
ethers.utils.keccak256('0x5678'),
ethers.utils.keccak256('0x1234'),
ethers.utils.keccak256('0x1234'),
],
})

await L1ChugSplashProxy.connect(signer1).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(signer1).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
})

it('should revert when called by non-owner', async () => {
await expect(
ChugSplashDictator.connect(signer2).returnOwnership()
).to.be.revertedWith('ChugSplashDictator: only callable by finalOwner')
})
})
})
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* Imports: External */
import hre from 'hardhat'
import { Contract, Signer } from 'ethers'
import { smock } from '@defi-wonderland/smock'

/* Imports: Internal */
import { expect } from '../../setup'
import { getContractInterface } from '../../../src'
import { deploy } from '../../helpers'

describe('L1ChugSplashProxy', () => {
let signer1: Signer
Expand All @@ -16,12 +15,9 @@ describe('L1ChugSplashProxy', () => {

let L1ChugSplashProxy: Contract
beforeEach(async () => {
const Factory__L1ChugSplashProxy = await hre.ethers.getContractFactory(
'L1ChugSplashProxy'
)
L1ChugSplashProxy = await Factory__L1ChugSplashProxy.deploy(
await signer1.getAddress()
)
L1ChugSplashProxy = await deploy('L1ChugSplashProxy', {
args: [await signer1.getAddress()],
})
})

describe('getOwner', () => {
Expand Down Expand Up @@ -173,14 +169,16 @@ describe('L1ChugSplashProxy', () => {
const owner = await smock.fake<Contract>(
getContractInterface('iL1ChugSplashDeployer')
)
const factory = await hre.ethers.getContractFactory('L1ChugSplashProxy')
const proxy = await factory.deploy(owner.address)

L1ChugSplashProxy = await deploy('L1ChugSplashProxy', {
args: [owner.address],
})

owner.isUpgrading.returns(true)

await expect(
owner.wallet.sendTransaction({
to: proxy.address,
to: L1ChugSplashProxy.address,
data: '0x',
})
).to.be.revertedWith(
Expand Down
12 changes: 12 additions & 0 deletions packages/contracts/test/helpers/utils/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 || []))
}
1 change: 1 addition & 0 deletions packages/contracts/test/helpers/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './eth-time'
export * from './deploy'