-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathHubPool.ProposeRootBundle.ts
74 lines (67 loc) · 3.3 KB
/
HubPool.ProposeRootBundle.ts
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
import { SignerWithAddress, seedWallet, expect, Contract, ethers } from "../utils/utils";
import * as consts from "./constants";
import { hubPoolFixture } from "./fixtures/HubPool.Fixture";
let hubPool: Contract, weth: Contract, dataWorker: SignerWithAddress, owner: SignerWithAddress;
describe("HubPool Root Bundle Proposal", function () {
beforeEach(async function () {
[owner, dataWorker] = await ethers.getSigners();
({ weth, hubPool } = await hubPoolFixture());
await seedWallet(dataWorker, [], weth, consts.totalBond);
});
it("Proposal of root bundle correctly stores data, emits events and pulls the bond", async function () {
const expectedchallengePeriodEndTimestamp = Number(await hubPool.getCurrentTime()) + consts.refundProposalLiveness;
await weth.connect(dataWorker).approve(hubPool.address, consts.totalBond);
const dataWorkerWethBalancerBefore = await weth.callStatic.balanceOf(dataWorker.address);
await expect(
hubPool
.connect(dataWorker)
.proposeRootBundle(
consts.mockBundleEvaluationBlockNumbers,
consts.mockPoolRebalanceLeafCount,
consts.mockPoolRebalanceRoot,
consts.mockRelayerRefundRoot,
consts.mockSlowRelayRoot
)
)
.to.emit(hubPool, "ProposeRootBundle")
.withArgs(
expectedchallengePeriodEndTimestamp,
consts.mockPoolRebalanceLeafCount,
consts.mockBundleEvaluationBlockNumbers,
consts.mockPoolRebalanceRoot,
consts.mockRelayerRefundRoot,
consts.mockSlowRelayRoot,
dataWorker.address
);
// Balances of the hubPool should have incremented by the bond and the dataWorker should have decremented by the bond.
expect(await weth.balanceOf(hubPool.address)).to.equal(consts.totalBond);
expect(await weth.balanceOf(dataWorker.address)).to.equal(dataWorkerWethBalancerBefore.sub(consts.totalBond));
const rootBundle = await hubPool.rootBundleProposal();
expect(rootBundle.challengePeriodEndTimestamp).to.equal(expectedchallengePeriodEndTimestamp);
expect(rootBundle.unclaimedPoolRebalanceLeafCount).to.equal(consts.mockPoolRebalanceLeafCount);
expect(rootBundle.poolRebalanceRoot).to.equal(consts.mockPoolRebalanceRoot);
expect(rootBundle.relayerRefundRoot).to.equal(consts.mockRelayerRefundRoot);
expect(rootBundle.claimedBitMap).to.equal(0); // no claims yet so everything should be marked at 0.
expect(rootBundle.proposer).to.equal(dataWorker.address);
// Can not re-initialize if the previous bundle has unclaimed leaves.
await expect(
hubPool
.connect(dataWorker)
.proposeRootBundle(
consts.mockBundleEvaluationBlockNumbers,
consts.mockPoolRebalanceLeafCount,
consts.mockPoolRebalanceRoot,
consts.mockRelayerRefundRoot,
consts.mockSlowRelayRoot
)
).to.be.revertedWith("Proposal has unclaimed leaves");
});
it("Cannot propose while paused", async function () {
await seedWallet(owner, [], weth, consts.totalBond);
await weth.approve(hubPool.address, consts.totalBond);
await hubPool.connect(owner).setPaused(true);
await expect(
hubPool.proposeRootBundle([1, 2, 3], 5, consts.mockTreeRoot, consts.mockTreeRoot, consts.mockSlowRelayRoot)
).to.be.revertedWith("Contract is paused");
});
});