Skip to content

Commit 1b036ad

Browse files
committed
Fix failing tests & adjustments from self review
* Some test were failing due to an incorrect import * Make some tests name more clear * Factorise `epoch-setting` fetch since it's used the same way across the two 'registrations' pages. * Change the layout of the Discord Formatted code block modal a little: apply a light background + a colored border to the code block.
1 parent ae2cb6d commit 1b036ad

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

mithril-explorer/__tests__/InOutRegistrations/compareRegistrations.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ describe("Compare registrations", () => {
88
expect(result).toEqual({ in: [], out: [] });
99
});
1010

11-
it("One registration still there", () => {
11+
it("One registration 'still there'", () => {
1212
const result = compareRegistrations([reg("party1", 10)], [reg("party1", 10)]);
1313

1414
expect(result).toEqual({ in: [], out: [] });
1515
});
1616

17-
it("One in registration", () => {
17+
it("One 'in' registration", () => {
1818
const result = compareRegistrations([reg("party1", 10)], []);
1919

2020
expect(result).toEqual({ in: [reg("party1", 10)], out: [] });
2121
});
2222

23-
it("One out registration", () => {
23+
it("One 'out' registration", () => {
2424
const result = compareRegistrations([], [reg("party1", 10)]);
2525

2626
expect(result).toEqual({ in: [], out: [reg("party1", 10)] });
2727
});
2828

29-
it("In, out, and still there altogether", () => {
29+
it("'In', 'out', and 'still there' altogether", () => {
3030
const result = compareRegistrations(
3131
[reg("party1", 10), reg("party3", 12), reg("party4", 13)],
3232
[reg("party1", 10), reg("party2", 11), reg("party3", 12)],

mithril-explorer/__tests__/InOutRegistrations/dedupInOutRegistrations.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { dedupInOutRegistrations } from "@/utils";
2-
import reg from "../helpers";
2+
import { reg } from "../helpers";
33

44
describe("In/Out registrations deduplication", () => {
55
it("should remove duplicate 'in' registrations", () => {

mithril-explorer/src/aggregator-api.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ function fetchSignersTickers(aggregator) {
1818
});
1919
}
2020

21+
function fetchEpochSettings(aggregator) {
22+
return fetch(`${aggregator}/epoch-settings`)
23+
.then((response) => (response.status === 200 ? response.json() : {}))
24+
.catch((error) => {
25+
console.error("Fetch epoch settings error:", error);
26+
});
27+
}
28+
2129
function fetchRegistrations(aggregator, epoch) {
2230
return fetch(`${aggregator}/signers/registered/${epoch}`)
2331
.then((response) => (response.status === 200 ? response.json() : {}))
@@ -29,5 +37,6 @@ function fetchRegistrations(aggregator, epoch) {
2937
module.exports = {
3038
fetchAggregatorCapabilities,
3139
fetchSignersTickers,
40+
fetchEpochSettings,
3241
fetchRegistrations,
3342
};

mithril-explorer/src/app/registrations-in-out/page.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { checkUrl, computeInOutRegistrations, dedupInOutRegistrations } from "@/
77
import { Col, Alert, Row, Spinner, Stack, Table } from "react-bootstrap";
88
import { aggregatorSearchParam } from "@/constants";
99
import { updatePoolsForAggregator } from "@/store/poolsSlice";
10-
import { fetchRegistrations } from "@/aggregator-api";
10+
import { fetchEpochSettings, fetchRegistrations } from "@/aggregator-api";
1111
import RegistrationDiscordFormatModal from "#/RegistrationDiscordFormatModal";
1212
import RegistrationsMovementsList from "@/app/registrations-in-out/RegistrationsMovementsList";
1313

@@ -34,8 +34,7 @@ export default function RegistrationsChanges() {
3434
if (error === undefined) {
3535
setIsLoading(true);
3636

37-
fetch(`${aggregator}/epoch-settings`)
38-
.then((response) => (response.status === 200 ? response.json() : {}))
37+
fetchEpochSettings(aggregator)
3938
.then((data) => {
4039
let epoch = data?.epoch;
4140
setCurrentEpoch(epoch);
@@ -49,9 +48,8 @@ export default function RegistrationsChanges() {
4948
setDedupDiff(dedupInOutRegistrations(inOutRegistrations));
5049
})
5150
.then(() => setIsLoading(false))
52-
.catch((error) => {
51+
.catch(() => {
5352
setCurrentEpoch(undefined);
54-
console.error("Fetch current epoch in epoch-settings error:", error);
5553
});
5654

5755
dispatch(updatePoolsForAggregator(aggregator));

mithril-explorer/src/app/registrations/page.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import LinkButton from "#/LinkButton";
2727
import Stake from "#/Stake";
2828
import RawJsonButton from "#/RawJsonButton";
2929
import SignerTable from "#/SignerTable";
30-
import { fetchRegistrations } from "@/aggregator-api";
30+
import { fetchEpochSettings, fetchRegistrations } from "@/aggregator-api";
3131

3232
Chart.register(ArcElement, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend);
3333
setChartJsDefaults(Chart);
@@ -71,18 +71,16 @@ export default function Registrations() {
7171
});
7272
setIsLoading(false);
7373
})
74-
.catch((error) => {
74+
.catch(() => {
7575
setSigningEpoch(undefined);
7676
setRegistrations([]);
7777
setIsLoading(false);
7878
});
7979

80-
fetch(`${aggregator}/epoch-settings`)
81-
.then((response) => (response.status === 200 ? response.json() : {}))
80+
fetchEpochSettings(aggregator)
8281
.then((data) => setCurrentEpoch(data?.epoch))
83-
.catch((error) => {
82+
.catch(() => {
8483
setCurrentEpoch(undefined);
85-
console.error("Fetch current epoch in epoch-settings error:", error);
8684
});
8785

8886
dispatch(updatePoolsForAggregator(aggregator));

mithril-explorer/src/components/RegistrationDiscordFormatModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function RegistrationDiscordFormatModal({ registrations, onClose,
7474
</Modal.Header>
7575
<Modal.Body>
7676
{registrations !== undefined && (
77-
<Card>
77+
<Card bg="light" border={mode === "out" ? "danger" : "success"}>
7878
<Card.Body>
7979
<pre>
8080
<code>{textToCopy}</code>

mithril-explorer/src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ async function fetchGenesisVerificationKey(aggregator) {
108108
* All registrations are expected to use the following format:
109109
* `{ registered_at: number, registrations: [{ party_id: string, stake: number }] }`;
110110
*/
111-
function computeInOutRegistrations(lastEpochRegistrations, ...PreviousEpochsRegistrations) {
111+
function computeInOutRegistrations(lastEpochRegistrations, ...previousEpochsRegistrations) {
112112
const result = {};
113113
let currentRegistrations = lastEpochRegistrations.registrations;
114114

115-
for (const { registered_at, registrations } of PreviousEpochsRegistrations) {
115+
for (const { registered_at, registrations } of previousEpochsRegistrations) {
116116
const epochOfChange = registered_at + 1;
117117
const diff = compareRegistrations(currentRegistrations, registrations);
118118

0 commit comments

Comments
 (0)