Skip to content

Commit f910d58

Browse files
dlachaumesfauvelAlenar
committed
Handle Cardano transactions prover capability in explorer
Co-authored-by: Sébastien Fauvel <[email protected]> Co-authored-by: DJO <[email protected]>
1 parent 1c84074 commit f910d58

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

mithril-explorer/__tests__/CardanoTransactionsFormInput.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { fireEvent, render, screen } from "@testing-library/react";
22
import "@testing-library/jest-dom";
33
import CardanoTransactionsFormInput from "#/CardanoTransactionsFormInput";
44

5-
function setup() {
6-
const utils = [render(<CardanoTransactionsFormInput />)];
5+
function setup(maxHashesAllowedByRequest = 100) {
6+
const utils = [
7+
render(<CardanoTransactionsFormInput maxAllowedHashesByRequest={maxHashesAllowedByRequest} />),
8+
];
79
return {
810
input: screen.getByRole("textbox"),
911
...utils,
@@ -83,4 +85,20 @@ describe("CardanoTransactionsFormInput", () => {
8385
expect(input.checkValidity()).toBeFalsy();
8486
expect(input.value).toBe(transactions);
8587
});
88+
89+
it.each([
90+
["Max 'one'", 1],
91+
["Max 'zero' should be equivalent to max 'one'", 0],
92+
["Max 'two'", 2],
93+
])("Setting more than max hashes allowed by request: %s", (_, maxHashesAllowedByRequest) => {
94+
const { input } = setup(maxHashesAllowedByRequest);
95+
const transactions =
96+
"c44d1f8df92bc75fe74d69b236b1c0ebcab1e3c350ee5ac70e8a8ef53c1e5918,b45d2f9df92bc75fe74e69b236b1c0ebcab1e3c350ee5ac71e8a8ef53c1e5918,a60d2f9df92bc75fe74e69b224b1c0bacab1e3c350ee5ac71e8a8ef65c1e5918";
97+
fireEvent.change(input, {
98+
target: { value: transactions },
99+
});
100+
101+
expect(input.checkValidity()).toBeFalsy();
102+
expect(input.value).toBe(transactions);
103+
});
86104
});

mithril-explorer/src/components/Artifacts/CardanoTransactionsSnapshotsList/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import LocalDateTime from "#/LocalDateTime";
66
import CardanoTransactionsFormInput from "#/CardanoTransactionsFormInput";
77
import CertificateModal from "#/CertificateModal";
88
import CertifyCardanoTransactionsModal from "#/CertifyCardanoTransactionsModal";
9-
import { selectedAggregator } from "@/store/settingsSlice";
9+
import { defaultAggregatorCapabilities } from "@/constants";
10+
import { selectedAggregator, selectedAggregatorCapabilities } from "@/store/settingsSlice";
1011

1112
export default function CardanoTransactionsSnapshotsList(props) {
1213
const [cardanoTransactionsSnapshots, setCardanoTransactionsSnapshots] = useState([]);
@@ -19,6 +20,9 @@ export default function CardanoTransactionsSnapshotsList(props) {
1920
);
2021
const autoUpdate = useSelector((state) => state.settings.autoUpdate);
2122
const updateInterval = useSelector((state) => state.settings.updateInterval);
23+
const currentAggregatorCapabilities = useSelector((state) =>
24+
selectedAggregatorCapabilities(state),
25+
);
2226

2327
useEffect(() => {
2428
if (!autoUpdate) {
@@ -96,7 +100,14 @@ export default function CardanoTransactionsSnapshotsList(props) {
96100
noValidate
97101
validated={showCertificationFormValidation}>
98102
<Row>
99-
<CardanoTransactionsFormInput />
103+
<CardanoTransactionsFormInput
104+
maxAllowedHashesByRequest={
105+
currentAggregatorCapabilities?.cardano_transactions_prover
106+
?.max_hashes_allowed_by_request ??
107+
defaultAggregatorCapabilities.cardano_transactions_prover
108+
.max_hashes_allowed_by_request
109+
}
110+
/>
100111
</Row>
101112
</Form>
102113
</Row>

mithril-explorer/src/components/CardanoTransactionsFormInput.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Button, Form, FormGroup, InputGroup } from "react-bootstrap";
22
import React from "react";
33

4-
export default function CardanoTransactionsFormInput() {
4+
export default function CardanoTransactionsFormInput({ maxAllowedHashesByRequest }) {
5+
const maxHashesAllowed = Math.max(maxAllowedHashesByRequest, 1);
6+
const validationPattern = ` *(\\w+ *, *){0,${maxHashesAllowed - 1}}\\w+,? *`;
7+
58
return (
69
<FormGroup>
710
<InputGroup hasValidation>
@@ -11,7 +14,7 @@ export default function CardanoTransactionsFormInput() {
1114
type="text"
1215
placeholder="comma-separated list of transactions hashes"
1316
required
14-
pattern=" *(\w+ *, *)*\w+,? *"
17+
pattern={validationPattern}
1518
/>
1619
<Form.Control.Feedback type="invalid">
1720
Please provide a comma-separated list of transactions hashes.

mithril-explorer/src/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ export const signedEntityType = {
99

1010
export const defaultAggregatorCapabilities = {
1111
signed_entity_types: [],
12+
cardano_transactions_prover: {
13+
max_hashes_allowed_by_request: 100,
14+
},
1215
};

mithril-explorer/src/store/settingsSlice.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export const {
8787
} = settingsSlice.actions;
8888

8989
export const selectedAggregator = (state) => state.settings.selectedAggregator;
90+
export const selectedAggregatorCapabilities = (state) =>
91+
state.settings?.aggregatorCapabilities ?? defaultAggregatorCapabilities;
9092
export const selectedAggregatorSignedEntities = (state) =>
9193
state.settings?.aggregatorCapabilities?.signed_entity_types ?? [];
9294

0 commit comments

Comments
 (0)