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 { Contract, Signer, ContractFactory } from 'ethers'
import { Contract } from 'ethers'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
/* Internal Imports */
import { expect } from '../../../setup'
import { makeAddressManager, NON_NULL_BYTES32 } from '../../../helpers'
import { deploy, NON_NULL_BYTES32 } from '../../../helpers'
describe('ChainStorageContainer', () => {
let sequencer: Signer
let otherSigner: Signer
let signer: Signer
let signerAddress: string
let AddressManager: Contract
let Factory__ChainStorageContainer: ContractFactory
let signer1: SignerWithAddress
let signer2: SignerWithAddress
before(async () => {
;[sequencer, otherSigner, signer] = await ethers.getSigners()
signerAddress = await otherSigner.getAddress()
AddressManager = await makeAddressManager()
await AddressManager.setAddress(
'OVM_Sequencer',
await sequencer.getAddress()
)
Factory__ChainStorageContainer = await ethers.getContractFactory(
'ChainStorageContainer'
)
;[signer1, signer2] = await ethers.getSigners()
})
let AddressManager: Contract
let ChainStorageContainer: Contract
beforeEach(async () => {
ChainStorageContainer = await Factory__ChainStorageContainer.connect(
otherSigner
).deploy(AddressManager.address, signerAddress)
await AddressManager.setAddress(
'ChainStorageContainer',
ChainStorageContainer.address
)
AddressManager = await deploy('Lib_AddressManager')
ChainStorageContainer = await deploy('ChainStorageContainer', {
signer: signer1,
args: [AddressManager.address, signer1.address],
})
await AddressManager.setAddress(signerAddress, signerAddress)
// ChainStorageContainer uses name resolution to check the owner address.
await AddressManager.setAddress(signer1.address, signer1.address)
})
describe('push', () => {
for (const len of [1, 2, 4, 8, 32]) {
it(`it should be able to add ${len} element(s) to the array`, async () => {
for (let i = 0; i < len; i++) {
await expect(
ChainStorageContainer.connect(otherSigner)['push(bytes32)'](
NON_NULL_BYTES32
)
).to.not.be.reverted
await expect(ChainStorageContainer['push(bytes32)'](NON_NULL_BYTES32))
.to.not.be.reverted
}
})
}
......@@ -60,9 +39,7 @@ describe('ChainStorageContainer', () => {
describe('setGlobalMetadata', () => {
it('should modify the extra data', async () => {
const globalMetaData = `0x${'11'.repeat(27)}`
await ChainStorageContainer.connect(otherSigner).setGlobalMetadata(
globalMetaData
)
await ChainStorageContainer.setGlobalMetadata(globalMetaData)
expect(await ChainStorageContainer.getGlobalMetadata()).to.equal(
globalMetaData
......@@ -73,15 +50,13 @@ describe('ChainStorageContainer', () => {
describe('deleteElementsAfterInclusive', () => {
it('should revert when the array is empty', async () => {
await expect(
ChainStorageContainer.connect(otherSigner)[
'deleteElementsAfterInclusive(uint256)'
](0)
ChainStorageContainer['deleteElementsAfterInclusive(uint256)'](0)
).to.be.reverted
})
it('should revert when called by non-owner', async () => {
await expect(
ChainStorageContainer.connect(signer)[
ChainStorageContainer.connect(signer2)[
'deleteElementsAfterInclusive(uint256)'
](0)
).to.be.revertedWith(
......@@ -96,18 +71,14 @@ describe('ChainStorageContainer', () => {
for (let i = 0; i < len; i++) {
const value = NON_NULL_BYTES32
values.push(value)
await ChainStorageContainer.connect(otherSigner)['push(bytes32)'](
value
)
await ChainStorageContainer['push(bytes32)'](value)
}
})
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 () => {
await expect(
ChainStorageContainer.connect(otherSigner)[
'deleteElementsAfterInclusive(uint256)'
](i)
ChainStorageContainer['deleteElementsAfterInclusive(uint256)'](i)
).to.not.be.reverted
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