-
Notifications
You must be signed in to change notification settings - Fork 45
/
SystemPause.js
142 lines (118 loc) · 4.74 KB
/
SystemPause.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import {constants} from "../../utils/constants"
import chai, {assert, expect} from "chai"
import {solidity} from "ethereum-waffle"
import {ethers} from "hardhat"
import setupIntegrationTest from "../helpers/setupIntegrationTest"
chai.use(solidity)
describe("System Pause", () => {
let controller
let bondingManager
let roundsManager
let token
let transcoder1
let delegator1
let delegator2
let roundLength
before(async () => {
const signers = await ethers.getSigners()
transcoder1 = signers[0]
delegator1 = signers[2]
delegator2 = signers[3]
const fixture = await setupIntegrationTest()
controller = await ethers.getContractAt(
"Controller",
fixture.Controller.address
)
await controller.unpause()
bondingManager = await ethers.getContractAt(
"BondingManager",
fixture.BondingManager.address
)
roundsManager = await ethers.getContractAt(
"AdjustableRoundsManager",
fixture.AdjustableRoundsManager.address
)
token = await ethers.getContractAt(
"LivepeerToken",
fixture.LivepeerToken.address
)
const transferAmount = ethers.BigNumber.from(10).mul(
constants.TOKEN_UNIT.toString()
)
await token
.connect(signers[0])
.transfer(transcoder1.address, transferAmount)
await token
.connect(signers[0])
.transfer(delegator1.address, transferAmount)
await token
.connect(signers[0])
.transfer(delegator2.address, transferAmount)
roundLength = await roundsManager.roundLength()
await roundsManager.mineBlocks(roundLength.mul(1000))
await roundsManager.initializeRound()
})
it("registers transcoder 1 that self bonds", async () => {
await token.connect(transcoder1).approve(bondingManager.address, 1000)
await bondingManager
.connect(transcoder1)
.bond(1000, transcoder1.address)
await bondingManager.connect(transcoder1).transcoder(0, 5)
assert.isTrue(
await bondingManager.isRegisteredTranscoder(transcoder1.address),
"wrong transcoder status"
)
})
it("delegator 1 bonds to transcoder 1", async () => {
await token.connect(delegator1).approve(bondingManager.address, 1000)
await bondingManager.connect(delegator1).bond(500, transcoder1.address)
const bond = (await bondingManager.getDelegator(delegator1.address))[0]
assert.equal(bond, 500, "delegator 1 bonded amount incorrect")
})
it("delegator 2 bonds to transcoder 1", async () => {
await token.connect(delegator2).approve(bondingManager.address, 1000)
await bondingManager.connect(delegator2).bond(500, transcoder1.address)
const bond = (await bondingManager.getDelegator(delegator2.address))[0]
assert.equal(bond, 500, "delegator 2 bonded amount incorrect")
})
it("transcoder calls reward, system is paused and resumed 5 rounds later", async () => {
await roundsManager.mineBlocks(roundLength)
await roundsManager.initializeRound()
await bondingManager.connect(transcoder1).reward()
await controller.pause()
await roundsManager.mineBlocks(roundLength * 5)
await controller.unpause()
await roundsManager.initializeRound()
const currentRound = await roundsManager.currentRound()
const t1Pending = await bondingManager.pendingStake(
transcoder1.address,
currentRound
)
await bondingManager.connect(transcoder1).claimEarnings(currentRound)
const endT1Info = await bondingManager.getDelegator(transcoder1.address)
expect(t1Pending).to.equal(
endT1Info.bondedAmount,
"wrong bonded amount for transcoder 1"
)
const d1Pending = await bondingManager.pendingStake(
delegator1.address,
currentRound
)
await bondingManager.connect(delegator1).claimEarnings(currentRound)
const endD1Info = await bondingManager.getDelegator(delegator1.address)
expect(d1Pending).to.equal(
endD1Info.bondedAmount,
"wrong bonded amount for delegator 1"
)
const d2Pending = await bondingManager.pendingStake(
delegator2.address,
currentRound
)
await bondingManager.connect(delegator2).claimEarnings(currentRound)
const endD2Info = await bondingManager.getDelegator(delegator2.address)
expect(d2Pending).to.equal(
endD2Info.bondedAmount,
"wrong bonded amount for delegator 2"
)
})
})