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,12 +1,13 @@
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()
})
Expand All @@ -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', () => {
Expand All @@ -40,7 +39,7 @@ describe('AddressDictator', () => {
signer: signer1,
args: [
Lib_AddressManager.address,
await signer1.getAddress(),
signer1.address,
['addr1', 'addr2'],
[NON_ZERO_ADDRESS],
],
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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()
})
Expand All @@ -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'),
Expand All @@ -32,9 +33,7 @@ describe('ChugSplashDictator', () => {
],
})

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

describe('doActions', () => {
Expand All @@ -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 () => {
Expand Down
73 changes: 30 additions & 43 deletions packages/contracts/test/contracts/L2/predeploys/WETH9.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
/* 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', () => {
Expand All @@ -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)
})
})

Expand All @@ -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
Expand Down