-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathController.js
More file actions
120 lines (105 loc) · 3.63 KB
/
Copy pathController.js
File metadata and controls
120 lines (105 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import Fixture from "./helpers/Fixture"
import {contractId} from "../../utils/helpers"
import {ethers} from "hardhat"
import chai, {expect, assert} from "chai"
import {solidity} from "ethereum-waffle"
chai.use(solidity)
describe("Controller", () => {
let fixture
let controller
let signers
let commitHash
before(async () => {
signers = await ethers.getSigners()
fixture = new Fixture(ethers.provider)
await fixture.deploy()
controller = fixture.controller
commitHash = fixture.commitHash
})
beforeEach(async () => {
await fixture.setUp()
})
afterEach(async () => {
await fixture.tearDown()
})
describe("constructor", () => {
it("should create contract", async () => {
assert.equal(
await controller.owner(),
signers[0].address,
"did not set owner correctly"
)
})
})
describe("setContractInfo", () => {
it("should throw when caller is not the owner", async () => {
const randomAddress = "0x0000000000000000000000000000000000001234"
await expect(
controller
.connect(signers[1])
.setContractInfo(
contractId("Manager"),
randomAddress,
commitHash
)
).to.be.reverted
})
it("should set contract info", async () => {
const id = contractId("Manager")
const managerFac = await ethers.getContractFactory("Manager")
const manager = await fixture.deployAndRegister(
managerFac,
"Manager",
controller.address
)
const cInfo = await controller.getContractInfo(id)
assert.equal(
cInfo[0],
manager.address,
"did not register contract address correctly"
)
assert.equal(
cInfo[1],
commitHash,
"did not register commit hash correctly"
)
})
})
describe("updateController", () => {
let id
let manager
beforeEach(async () => {
id = contractId("Manager")
const managerFac = await ethers.getContractFactory("Manager")
manager = await fixture.deployAndRegister(
managerFac,
"Manager",
controller.address
)
})
it("should throw when caller is not the owner", async () => {
const randomAddress = "0x0000000000000000000000000000000000001234"
await expect(
controller
.connect(signers[1])
.updateController(id, randomAddress)
).to.be.reverted
})
it("should throw for invalid key", async () => {
const randomAddress = "0x0000000000000000000000000000000000001234"
const invalidId = "0x1230000000000000000000000000000000000000"
await expect(controller.updateController(invalidId, randomAddress))
.to.be.reverted
})
it("should update a manager's controller", async () => {
const randomAddress = "0x0000000000000000000000000000000000001234"
await controller.updateController(id, randomAddress)
const newController = await manager.controller()
assert.equal(
newController,
randomAddress,
"controller for manager incorrect"
)
})
})
})