Skip to content

Commit 1141911

Browse files
authored
Merge pull request #1709 from input-output-hk/djo/1686/explorer_in-out_signers
New Explorer page: 'in'/'out' registrations
2 parents 87d9d71 + bfd3010 commit 1141911

19 files changed

+733
-69
lines changed

mithril-explorer/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ build: package-lock.json
1313
mkdir out/registrations
1414
cp out/registrations.html out/registrations/index.html
1515
cp out/registrations.txt out/registrations/index.txt
16+
mkdir out/registrations-in-out
17+
cp out/registrations-in-out.html out/registrations-in-out/index.html
18+
cp out/registrations-in-out.txt out/registrations-in-out/index.txt
1619

1720
serve: build
1821
if [ -d "explorer/" ]; then rm -rf explorer/; fi
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { compareRegistrations } from "@/utils";
2+
import { reg } from "../helpers";
3+
4+
describe("Compare registrations", () => {
5+
it("empty registrations return empty result", () => {
6+
const result = compareRegistrations([], []);
7+
8+
expect(result).toEqual({ in: [], out: [] });
9+
});
10+
11+
it("One registration 'still there'", () => {
12+
const result = compareRegistrations([reg("party1", 10)], [reg("party1", 10)]);
13+
14+
expect(result).toEqual({ in: [], out: [] });
15+
});
16+
17+
it("One 'in' registration", () => {
18+
const result = compareRegistrations([reg("party1", 10)], []);
19+
20+
expect(result).toEqual({ in: [reg("party1", 10)], out: [] });
21+
});
22+
23+
it("One 'out' registration", () => {
24+
const result = compareRegistrations([], [reg("party1", 10)]);
25+
26+
expect(result).toEqual({ in: [], out: [reg("party1", 10)] });
27+
});
28+
29+
it("'In', 'out', and 'still there' all together", () => {
30+
const result = compareRegistrations(
31+
[reg("party1", 10), reg("party3", 12), reg("party4", 13)],
32+
[reg("party1", 10), reg("party2", 11), reg("party3", 12)],
33+
);
34+
35+
expect(result).toEqual({ in: [reg("party4", 13)], out: [reg("party2", 11)] });
36+
});
37+
});
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { computeInOutRegistrations } from "@/utils";
2+
import { reg } from "../helpers";
3+
4+
describe("In/Out registrations computation", () => {
5+
it("giving only one registrations return empty result", () => {
6+
const result = computeInOutRegistrations({ registered_at: 4, registrations: [] });
7+
8+
expect(result).toEqual({});
9+
});
10+
11+
it("empty registrations return empty result", () => {
12+
const result = computeInOutRegistrations(
13+
{ registered_at: 4, registrations: [] },
14+
{ registered_at: 3, registrations: [] },
15+
{ registered_at: 2, registrations: [] },
16+
);
17+
18+
expect(result).toEqual({});
19+
});
20+
21+
it("In/Out list show latest stakes values", () => {
22+
const result = computeInOutRegistrations(
23+
{ registered_at: 4, registrations: [reg("party1", 15)] },
24+
{ registered_at: 3, registrations: [reg("party2", 20)] },
25+
{ registered_at: 2, registrations: [reg("party1", 10), reg("party2", 11)] },
26+
);
27+
28+
expect(result).toEqual({
29+
4: {
30+
in: [reg("party1", 15)],
31+
out: [reg("party2", 20)],
32+
},
33+
3: {
34+
in: [],
35+
out: [reg("party1", 10)],
36+
},
37+
});
38+
});
39+
40+
it("Compare two epochs registrations", () => {
41+
const result = computeInOutRegistrations(
42+
{
43+
registered_at: 4,
44+
registrations: [reg("party1", 10), reg("party3", 12), reg("party4", 13)],
45+
},
46+
{
47+
registered_at: 3,
48+
registrations: [reg("party1", 10), reg("party2", 11), reg("party3", 12)],
49+
},
50+
);
51+
52+
expect(result).toEqual({
53+
4: {
54+
in: [reg("party4", 13)],
55+
out: [reg("party2", 11)],
56+
},
57+
});
58+
});
59+
60+
it("Compare three epochs registrations", () => {
61+
const result = computeInOutRegistrations(
62+
{
63+
registered_at: 4,
64+
registrations: [reg("party2", 11), reg("party4", 13), reg("party5", 14)],
65+
},
66+
{
67+
registered_at: 3,
68+
registrations: [reg("party1", 10), reg("party2", 11), reg("party4", 13)],
69+
},
70+
{
71+
registered_at: 2,
72+
registrations: [reg("party1", 10), reg("party2", 11), reg("party3", 12)],
73+
},
74+
);
75+
76+
expect(result).toEqual({
77+
4: {
78+
in: [reg("party5", 14)],
79+
out: [reg("party1", 10)],
80+
},
81+
3: {
82+
in: [reg("party4", 13)],
83+
out: [reg("party3", 12)],
84+
},
85+
});
86+
});
87+
88+
it("Compare four epochs registrations", () => {
89+
const result = computeInOutRegistrations(
90+
{
91+
registered_at: 5,
92+
registrations: [reg("party1", 10), reg("party2", 11), reg("party6", 15), reg("party7", 16)],
93+
},
94+
{
95+
registered_at: 4,
96+
registrations: [reg("party2", 11), reg("party4", 13), reg("party5", 14)],
97+
},
98+
{
99+
registered_at: 3,
100+
registrations: [reg("party1", 10), reg("party2", 11), reg("party4", 13)],
101+
},
102+
{
103+
registered_at: 2,
104+
registrations: [reg("party1", 10), reg("party2", 11), reg("party3", 12)],
105+
},
106+
);
107+
108+
expect(result).toEqual({
109+
5: {
110+
in: [reg("party1", 10), reg("party6", 15), reg("party7", 16)],
111+
out: [reg("party4", 13), reg("party5", 14)],
112+
},
113+
4: {
114+
in: [reg("party5", 14)],
115+
out: [reg("party1", 10)],
116+
},
117+
3: {
118+
in: [reg("party4", 13)],
119+
out: [reg("party3", 12)],
120+
},
121+
});
122+
});
123+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { dedupInOutRegistrations } from "@/utils";
2+
import { reg } from "../helpers";
3+
4+
describe("In/Out registrations deduplication", () => {
5+
it("should remove duplicate 'in' registrations", () => {
6+
const registrations = {
7+
4: {
8+
in: [],
9+
out: [reg("party1", 10), reg("party2", 20)],
10+
},
11+
3: {
12+
in: [reg("party2", 20)],
13+
out: [],
14+
},
15+
2: {
16+
in: [reg("party1", 10)],
17+
out: [],
18+
},
19+
};
20+
21+
const result = dedupInOutRegistrations(registrations);
22+
23+
expect(result).toEqual({
24+
4: {
25+
in: [],
26+
out: [reg("party1", 10), reg("party2", 20)],
27+
},
28+
});
29+
});
30+
31+
it("should remove duplicate 'out' registrations", () => {
32+
const registrations = {
33+
4: {
34+
in: [reg("party1", 10), reg("party2", 20)],
35+
out: [],
36+
},
37+
3: {
38+
in: [],
39+
out: [reg("party2", 20)],
40+
},
41+
2: {
42+
in: [],
43+
out: [reg("party1", 10)],
44+
},
45+
};
46+
47+
const result = dedupInOutRegistrations(registrations);
48+
49+
expect(result).toEqual({
50+
4: {
51+
in: [reg("party1", 10), reg("party2", 20)],
52+
out: [],
53+
},
54+
});
55+
});
56+
});

mithril-explorer/__tests__/helpers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,18 @@ function setLocationToAggregator(aggregatorUrl) {
6363
setLocation(new URL(`?aggregator=${aggregatorUrl}`, baseLocation));
6464
}
6565

66+
/**
67+
* Helper function to create a signer registration as returned in the `signers/registered/{epoch}` API
68+
*/
69+
function reg(party_id, stake) {
70+
return { party_id, stake };
71+
}
72+
6673
module.exports = {
6774
initStore,
6875
mockNextNavigation,
6976
setLocation,
7077
setLocationToAggregator,
7178
resetLocation,
79+
reg,
7280
};

0 commit comments

Comments
 (0)