Commit 888f2486 authored by smartcontracts's avatar smartcontracts Committed by GitHub

tests: Improve coverage for StateTransitionerFactory (#365)

* tests: Improve coverage for StateTransitionerFactory

* fix failing test because of missing contract
Co-authored-by: default avatarMaurelian <maurelian@protonmail.ch>
parent aed344de
...@@ -23,15 +23,20 @@ import { OVM_StateTransitioner } from "./OVM_StateTransitioner.sol"; ...@@ -23,15 +23,20 @@ import { OVM_StateTransitioner } from "./OVM_StateTransitioner.sol";
*/ */
contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory, Lib_AddressResolver { contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory, Lib_AddressResolver {
/***************
* Constructor *
***************/
constructor( constructor(
address _libAddressManager address _libAddressManager
) )
Lib_AddressResolver(_libAddressManager) Lib_AddressResolver(_libAddressManager)
{} {}
/***************************************
* Public Functions: Contract Creation * /********************
***************************************/ * Public Functions *
********************/
/** /**
* Creates a new OVM_StateTransitioner * Creates a new OVM_StateTransitioner
...@@ -39,7 +44,7 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory, Lib_Addr ...@@ -39,7 +44,7 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory, Lib_Addr
* @param _stateTransitionIndex Index of the state transition being verified. * @param _stateTransitionIndex Index of the state transition being verified.
* @param _preStateRoot State root before the transition was executed. * @param _preStateRoot State root before the transition was executed.
* @param _transactionHash Hash of the executed transaction. * @param _transactionHash Hash of the executed transaction.
* @return _ovmStateTransitioner New OVM_StateTransitioner instance. * @return New OVM_StateTransitioner instance.
*/ */
function create( function create(
address _libAddressManager, address _libAddressManager,
...@@ -50,13 +55,14 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory, Lib_Addr ...@@ -50,13 +55,14 @@ contract OVM_StateTransitionerFactory is iOVM_StateTransitionerFactory, Lib_Addr
override override
public public
returns ( returns (
iOVM_StateTransitioner _ovmStateTransitioner iOVM_StateTransitioner
) )
{ {
require( require(
msg.sender == resolve("OVM_FraudVerifier"), msg.sender == resolve("OVM_FraudVerifier"),
"Create can only be done by the OVM_FraudVerifier." "Create can only be done by the OVM_FraudVerifier."
); );
return new OVM_StateTransitioner( return new OVM_StateTransitioner(
_libAddressManager, _libAddressManager,
_stateTransitionIndex, _stateTransitionIndex,
......
...@@ -2,7 +2,8 @@ import { expect } from '../../../setup' ...@@ -2,7 +2,8 @@ import { expect } from '../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { ContractFactory, Contract, constants } from 'ethers' import { ContractFactory, Contract, constants, Signer } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock'
/* Internal Imports */ /* Internal Imports */
import { import {
...@@ -14,6 +15,11 @@ import { ...@@ -14,6 +15,11 @@ import {
const DUMMY_HASH = hashTransaction(DUMMY_OVM_TRANSACTIONS[0]) const DUMMY_HASH = hashTransaction(DUMMY_OVM_TRANSACTIONS[0])
describe('OVM_StateTransitionerFactory', () => { describe('OVM_StateTransitionerFactory', () => {
let signer1: Signer
before(async () => {
;[signer1] = await ethers.getSigners()
})
let AddressManager: Contract let AddressManager: Contract
before(async () => { before(async () => {
AddressManager = await makeAddressManager() AddressManager = await makeAddressManager()
...@@ -27,15 +33,26 @@ describe('OVM_StateTransitionerFactory', () => { ...@@ -27,15 +33,26 @@ describe('OVM_StateTransitionerFactory', () => {
}) })
let OVM_StateTransitionerFactory: Contract let OVM_StateTransitionerFactory: Contract
let Mock__OVM_StateManagerFactory: MockContract
beforeEach(async () => { beforeEach(async () => {
OVM_StateTransitionerFactory = await Factory__OVM_StateTransitionerFactory.deploy( OVM_StateTransitionerFactory = await Factory__OVM_StateTransitionerFactory.deploy(
AddressManager.address AddressManager.address
) )
Mock__OVM_StateManagerFactory = await smockit('OVM_StateManagerFactory')
Mock__OVM_StateManagerFactory.smocked.create.will.return.with(
ethers.constants.AddressZero
)
await AddressManager.setAddress(
'OVM_StateManagerFactory',
Mock__OVM_StateManagerFactory.address
)
}) })
describe('create', () => { describe('create', () => {
describe('when the sender is not the OVM_FraudVerifier', () => { describe('when the sender is not the OVM_FraudVerifier', () => {
before(async () => { beforeEach(async () => {
await AddressManager.setAddress( await AddressManager.setAddress(
'OVM_FraudVerifier', 'OVM_FraudVerifier',
constants.AddressZero constants.AddressZero
...@@ -55,5 +72,25 @@ describe('OVM_StateTransitionerFactory', () => { ...@@ -55,5 +72,25 @@ describe('OVM_StateTransitionerFactory', () => {
) )
}) })
}) })
describe('when the sender is the OVM_FraudVerifier', () => {
beforeEach(async () => {
await AddressManager.setAddress(
'OVM_FraudVerifier',
await signer1.getAddress()
)
})
it('should not revert', async () => {
await expect(
OVM_StateTransitionerFactory.connect(signer1).create(
AddressManager.address,
ethers.constants.HashZero,
ethers.constants.HashZero,
DUMMY_HASH
)
).to.not.be.reverted
})
})
}) })
}) })
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