This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from thehubbleproject/deposit-and-vault-acces…
…s-control Add access control to setRollupAddress in DepositManager and Vault contracts
- Loading branch information
Showing
8 changed files
with
170 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.12; | ||
|
||
/** | ||
* Immutable, non-transferable version of openzeppelin/contracts/access/Ownable | ||
*/ | ||
abstract contract ImmutableOwnable { | ||
address private immutable _owner; | ||
|
||
/** | ||
* @dev Initializes the contract setting the deployer as the initial owner. | ||
*/ | ||
constructor() internal { | ||
_owner = msg.sender; | ||
} | ||
|
||
/** | ||
* @dev Returns the address of the current owner. | ||
*/ | ||
function owner() public view virtual returns (address) { | ||
return _owner; | ||
} | ||
|
||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require( | ||
msg.sender == _owner, | ||
"ImmutableOwnable: caller is not the owner" | ||
); | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | ||
import chai, { assert } from "chai"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
import { ethers } from "hardhat"; | ||
import { TESTING_PARAMS as params } from "../../ts/constants"; | ||
import { randomAddress } from "../../ts/utils"; | ||
import { DepositManagerFactory } from "../../types/ethers-contracts"; | ||
import { DepositManager } from "../../types/ethers-contracts/DepositManager"; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe("DepositManager", () => { | ||
let owner: SignerWithAddress; | ||
let otherSigner: SignerWithAddress; | ||
let depositManager: DepositManager; | ||
|
||
beforeEach(async function() { | ||
const signers = await ethers.getSigners(); | ||
owner = signers[0]; | ||
otherSigner = signers[1]; | ||
|
||
const fakeAddress = randomAddress(); | ||
depositManager = await new DepositManagerFactory(owner).deploy( | ||
fakeAddress, | ||
fakeAddress, | ||
params.MAX_DEPOSIT_SUBTREE_DEPTH | ||
); | ||
}); | ||
|
||
describe("setRollupAddress", () => { | ||
it("fails if sender is not owner", async function() { | ||
await assert.isRejected( | ||
depositManager | ||
.connect(otherSigner) | ||
.setRollupAddress(randomAddress()), | ||
/.*Ownable: caller is not the owner/ | ||
); | ||
}); | ||
|
||
it("sets rollup contract address and fails if called again", async function() { | ||
const rollupAddress = randomAddress(); | ||
await depositManager.setRollupAddress(rollupAddress); | ||
assert.equal(await depositManager.rollup(), rollupAddress); | ||
await assert.isRejected( | ||
depositManager.setRollupAddress(randomAddress()), | ||
/.*Initializable: contract is already initialized/ | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | ||
import chai, { assert } from "chai"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
import { ethers } from "hardhat"; | ||
import { randomAddress } from "../../ts/utils"; | ||
import { Vault } from "../../types/ethers-contracts/Vault"; | ||
import { VaultFactory } from "../../types/ethers-contracts/VaultFactory"; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe("Vault", () => { | ||
let owner: SignerWithAddress; | ||
let otherSigner: SignerWithAddress; | ||
let vault: Vault; | ||
|
||
beforeEach(async function() { | ||
const signers = await ethers.getSigners(); | ||
owner = signers[0]; | ||
otherSigner = signers[1]; | ||
|
||
const fakeAddress = randomAddress(); | ||
vault = await new VaultFactory(owner).deploy(fakeAddress, fakeAddress); | ||
}); | ||
|
||
describe("setRollupAddress", () => { | ||
it("fails if sender is not owner", async function() { | ||
await assert.isRejected( | ||
vault.connect(otherSigner).setRollupAddress(randomAddress()), | ||
/.*Ownable: caller is not the owner/ | ||
); | ||
}); | ||
|
||
it("sets rollup contract address and fails if called again", async function() { | ||
const rollupAddress = randomAddress(); | ||
await vault.setRollupAddress(rollupAddress); | ||
assert.equal(await vault.rollup(), rollupAddress); | ||
await assert.isRejected( | ||
vault.setRollupAddress(randomAddress()), | ||
/.*Initializable: contract is already initialized/ | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters