-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest-orbiters.ts
155 lines (136 loc) · 5.35 KB
/
test-orbiters.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
import { describeSuite, expect } from "@moonwall/cli";
import "@moonbeam-network/api-augment";
import { alith, baltathar, charleth, dorothy, ethan, faith, goliath } from "@moonwall/util";
import { jumpRounds } from "../../../../helpers";
describeSuite({
id: "D012601",
title: "Orbiters",
foundationMethods: "dev",
testCases: ({ it, context, log }) => {
it({
id: "T01",
title: "Marking orbiters offline is a noop",
test: async function () {
const minCandidateStk = context.polkadotJs().consts.parachainStaking.minCandidateStk;
await context.createBlock(
[
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parachainStaking.setBlocksPerRound(10))
.signAsync(alith),
],
{ allowFailures: false }
);
await context.createBlock(
[
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parachainStaking.enableMarkingOffline(true))
.signAsync(alith),
],
{ allowFailures: false }
);
// ceil(2 / 3 * 8) = 6 collators are needed to be able to mark
// collators offline. Alith is arleady a collator so 5 extra
// are added.
const collators = [baltathar, charleth, dorothy, ethan, faith];
const joinCandidateTxs = collators.map((c, i) =>
context
.polkadotJs()
.tx.parachainStaking.joinCandidates(minCandidateStk, 1 + i)
.signAsync(c)
);
await context.createBlock(joinCandidateTxs, { allowFailures: false });
const orbiterPool = collators[1];
const orbiter = goliath;
await context.createBlock(
[
context
.polkadotJs()
.tx.sudo.sudo(
context.polkadotJs().tx.moonbeamOrbiters.addCollator(orbiterPool.address)
)
.signAsync(alith),
],
{ allowFailures: false }
);
await context.createBlock(
context.polkadotJs().tx.moonbeamOrbiters.orbiterRegister().signAsync(orbiter),
{ allowFailures: false }
);
await context.createBlock(
context
.polkadotJs()
.tx.moonbeamOrbiters.collatorAddOrbiter(orbiter.address)
.signAsync(orbiterPool),
{ allowFailures: false }
);
// Advance some rounds so orbiter is set to active and it goes
// some rounds without producing blocks
await jumpRounds(context, 6);
const afterOrbiterActiveRound = await context.polkadotJs().query.parachainStaking.round();
const afterOrbiterActiveOrbiter = await context
.polkadotJs()
.query.moonbeamOrbiters.orbiterPerRound(
afterOrbiterActiveRound.current,
orbiterPool.address
);
expect(afterOrbiterActiveOrbiter.toString()).toEqual(orbiter.address);
const notifyInactiveOrbiter = await context.createBlock(
context
.polkadotJs()
.tx.parachainStaking.notifyInactiveCollator(orbiter.address)
.signAsync(alith),
{ allowFailures: true }
);
expect(notifyInactiveOrbiter.result!.successful).toEqual(false);
expect(notifyInactiveOrbiter.result!.error!.name).toEqual("CannotBeNotifiedAsInactive");
// Call to mark an orbiterPool that has not produced blocks offline
// should succeed but it should be an noop (pool will still be active) if there are is an
// active orbiter in the pool
await context.createBlock(
context
.polkadotJs()
.tx.parachainStaking.notifyInactiveCollator(orbiterPool.address)
.signAsync(alith),
{ allowFailures: false }
);
const afterNoopNotifyInfo = await context
.polkadotJs()
.query.parachainStaking.candidateInfo(orbiterPool.address);
expect(afterNoopNotifyInfo.unwrap().status.isActive).toBe(true);
await context.createBlock(
context
.polkadotJs()
.tx.moonbeamOrbiters.collatorRemoveOrbiter(orbiter.address)
.signAsync(orbiterPool),
{ allowFailures: false }
);
// Advance rounds so that the orbiter gets rotated out of the pool
// and the OrbiterPerRoundEntry is cleared
await jumpRounds(context, 6);
// Marking the orbiter pool without active orbiters should
// make the orbiter pool idle
await context.createBlock(
context
.polkadotJs()
.tx.parachainStaking.notifyInactiveCollator(orbiterPool.address)
.signAsync(alith),
{ allowFailures: false }
);
const afterRemoveOrbiterRound = await context.polkadotJs().query.parachainStaking.round();
const afterRemoveOrbiterOrbiter = await context
.polkadotJs()
.query.moonbeamOrbiters.orbiterPerRound(
afterRemoveOrbiterRound.current,
orbiterPool.address
);
expect(afterRemoveOrbiterOrbiter.isNone).toBe(true);
const afterOrbiterRemoveInfo = await context
.polkadotJs()
.query.parachainStaking.candidateInfo(orbiterPool.address);
expect(afterOrbiterRemoveInfo.unwrap().status.isIdle).toBe(true);
},
});
},
});