Commit dbd38d0d authored by smartcontracts's avatar smartcontracts Committed by GitHub

maint(ct): clean up CSC tests (#2463)

Yet another test cleanup commit. Cleans up the ChainStorageContainer
tests with the same techniques as the previous commits along the same
lines.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent b62f5a8e
/* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract, Signer, ContractFactory } from 'ethers' import { Contract } from 'ethers'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
/* Internal Imports */
import { expect } from '../../../setup' import { expect } from '../../../setup'
import { makeAddressManager, NON_NULL_BYTES32 } from '../../../helpers' import { deploy, NON_NULL_BYTES32 } from '../../../helpers'
describe('ChainStorageContainer', () => { describe('ChainStorageContainer', () => {
let sequencer: Signer let signer1: SignerWithAddress
let otherSigner: Signer let signer2: SignerWithAddress
let signer: Signer
let signerAddress: string
let AddressManager: Contract
let Factory__ChainStorageContainer: ContractFactory
before(async () => { before(async () => {
;[sequencer, otherSigner, signer] = await ethers.getSigners() ;[signer1, signer2] = await ethers.getSigners()
signerAddress = await otherSigner.getAddress()
AddressManager = await makeAddressManager()
await AddressManager.setAddress(
'OVM_Sequencer',
await sequencer.getAddress()
)
Factory__ChainStorageContainer = await ethers.getContractFactory(
'ChainStorageContainer'
)
}) })
let AddressManager: Contract
let ChainStorageContainer: Contract let ChainStorageContainer: Contract
beforeEach(async () => { beforeEach(async () => {
ChainStorageContainer = await Factory__ChainStorageContainer.connect( AddressManager = await deploy('Lib_AddressManager')
otherSigner ChainStorageContainer = await deploy('ChainStorageContainer', {
).deploy(AddressManager.address, signerAddress) signer: signer1,
args: [AddressManager.address, signer1.address],
await AddressManager.setAddress( })
'ChainStorageContainer',
ChainStorageContainer.address
)
await AddressManager.setAddress(signerAddress, signerAddress) // ChainStorageContainer uses name resolution to check the owner address.
await AddressManager.setAddress(signer1.address, signer1.address)
}) })
describe('push', () => { describe('push', () => {
for (const len of [1, 2, 4, 8, 32]) { for (const len of [1, 2, 4, 8, 32]) {
it(`it should be able to add ${len} element(s) to the array`, async () => { it(`it should be able to add ${len} element(s) to the array`, async () => {
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
await expect( await expect(ChainStorageContainer['push(bytes32)'](NON_NULL_BYTES32))
ChainStorageContainer.connect(otherSigner)['push(bytes32)']( .to.not.be.reverted
NON_NULL_BYTES32
)
).to.not.be.reverted
} }
}) })
} }
...@@ -60,9 +39,7 @@ describe('ChainStorageContainer', () => { ...@@ -60,9 +39,7 @@ describe('ChainStorageContainer', () => {
describe('setGlobalMetadata', () => { describe('setGlobalMetadata', () => {
it('should modify the extra data', async () => { it('should modify the extra data', async () => {
const globalMetaData = `0x${'11'.repeat(27)}` const globalMetaData = `0x${'11'.repeat(27)}`
await ChainStorageContainer.connect(otherSigner).setGlobalMetadata( await ChainStorageContainer.setGlobalMetadata(globalMetaData)
globalMetaData
)
expect(await ChainStorageContainer.getGlobalMetadata()).to.equal( expect(await ChainStorageContainer.getGlobalMetadata()).to.equal(
globalMetaData globalMetaData
...@@ -73,15 +50,13 @@ describe('ChainStorageContainer', () => { ...@@ -73,15 +50,13 @@ describe('ChainStorageContainer', () => {
describe('deleteElementsAfterInclusive', () => { describe('deleteElementsAfterInclusive', () => {
it('should revert when the array is empty', async () => { it('should revert when the array is empty', async () => {
await expect( await expect(
ChainStorageContainer.connect(otherSigner)[ ChainStorageContainer['deleteElementsAfterInclusive(uint256)'](0)
'deleteElementsAfterInclusive(uint256)'
](0)
).to.be.reverted ).to.be.reverted
}) })
it('should revert when called by non-owner', async () => { it('should revert when called by non-owner', async () => {
await expect( await expect(
ChainStorageContainer.connect(signer)[ ChainStorageContainer.connect(signer2)[
'deleteElementsAfterInclusive(uint256)' 'deleteElementsAfterInclusive(uint256)'
](0) ](0)
).to.be.revertedWith( ).to.be.revertedWith(
...@@ -96,18 +71,14 @@ describe('ChainStorageContainer', () => { ...@@ -96,18 +71,14 @@ describe('ChainStorageContainer', () => {
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
const value = NON_NULL_BYTES32 const value = NON_NULL_BYTES32
values.push(value) values.push(value)
await ChainStorageContainer.connect(otherSigner)['push(bytes32)']( await ChainStorageContainer['push(bytes32)'](value)
value
)
} }
}) })
for (let i = len - 1; i > 0; i -= Math.max(1, len / 4)) { for (let i = len - 1; i > 0; i -= Math.max(1, len / 4)) {
it(`should be able to delete everything after and including the ${i}th/st/rd/whatever element`, async () => { it(`should be able to delete everything after and including the ${i}th/st/rd/whatever element`, async () => {
await expect( await expect(
ChainStorageContainer.connect(otherSigner)[ ChainStorageContainer['deleteElementsAfterInclusive(uint256)'](i)
'deleteElementsAfterInclusive(uint256)'
](i)
).to.not.be.reverted ).to.not.be.reverted
expect(await ChainStorageContainer.length()).to.equal(i) expect(await ChainStorageContainer.length()).to.equal(i)
......
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