• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cartesi / rollups-explorer / 11325739702

14 Oct 2024 10:31AM UTC coverage: 84.669% (-1.7%) from 86.415%
11325739702

Pull #256

github

nevendyulgerov
chore(apps/web): Cleanup
Pull Request #256: #251 Add ABI encoding for raw input form

1303 of 1566 branches covered (83.21%)

Branch coverage included in aggregate %.

709 of 901 new or added lines in 13 files covered. (78.69%)

145 existing lines in 1 file now uncovered.

9174 of 10808 relevant lines covered (84.88%)

46.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.5
/packages/ui/src/GenericInputForm/validations.ts
1
import { isAddress, isHex, parseAbi, parseAbiParameters } from "viem";
1✔
2
import { FormValues } from "./types";
3
import { isBlank } from "ramda-adjunct";
1✔
4
import { prepareSignatures } from "web/src/components/specification/utils";
1✔
5

6
export const validateApplication = (value: string) =>
1✔
7
    value !== "" && isAddress(value) ? null : "Invalid application";
250✔
8

9
export const validateHexInput = (value: string) =>
1✔
10
    isHex(value) ? null : "Invalid hex value";
250✔
11

12
export const validateAbiMethod = (value: string, values: FormValues) =>
1✔
13
    values.mode !== "abi" || value === "new" || value === "existing"
250✔
14
        ? null
250!
NEW
15
        : "Invalid ABI method";
×
16

17
export const validateSpecificationId = (value: string, values: FormValues) =>
1✔
18
    values.mode !== "abi" || values.abiMethod === "new" || value !== ""
250✔
19
        ? null
231✔
20
        : "Invalid specification";
19✔
21

22
export const validateAbiFunctionName = (value: string, values: FormValues) =>
1✔
23
    values.mode !== "abi" ||
250✔
24
    values.specificationMode !== "json_abi" ||
133✔
25
    value !== ""
94✔
26
        ? null
200✔
27
        : "Invalid ABI function";
50✔
28

29
export const validateAbiFunctionParamValue = (
1✔
30
    value: string,
132✔
31
    values: FormValues,
132✔
32
    key: string,
132✔
33
) => {
132✔
34
    if (values.mode !== "abi") {
132!
NEW
35
        return null;
×
NEW
36
    }
×
37

38
    const [paramIndex] = key
132✔
39
        .split(".")
132✔
40
        .map((part) => parseInt(part))
132✔
41
        .filter((n) => !isNaN(n));
132✔
42
    const param = values.abiFunctionParams[paramIndex];
132✔
43

44
    if (!param) {
132!
NEW
45
        return null;
×
NEW
46
    }
×
47

48
    const message = `Invalid ${param.type} value`;
132✔
49
    let error: string | null = null;
132✔
50

51
    // Validate the field for non-empty content
52
    if (value === "") {
132✔
53
        return message;
51✔
54
    }
51✔
55

56
    // Otherwise, if some content exists, validate it based on the type
57
    switch (param.type) {
81✔
58
        case "uint":
132!
59
        case "uint8":
132!
60
        case "uint16":
132!
61
        case "uint32":
132!
62
        case "uint64":
132!
63
        case "uint128":
132!
64
        case "uint256":
132✔
65
            try {
54✔
66
                BigInt(value);
54✔
67
            } catch (e) {
54✔
68
                error = message;
15✔
69
            }
15✔
70
            break;
54✔
71
        case "bool":
132✔
72
            error = value === "true" || value === "false" ? null : message;
27✔
73
            break;
27✔
74
        case "bytes":
132!
NEW
75
            error = isHex(value) ? null : message;
×
NEW
76
            break;
×
77
        case "address":
132!
NEW
78
            error = isAddress(value) ? null : message;
×
NEW
79
            break;
×
80
        // All other types like 'string' are handled in the non-empty content check above
81
        default:
132!
NEW
82
            break;
×
83
    }
132✔
84

85
    return error;
81✔
86
};
81✔
87

88
export const validateHumanAbi = (value: string, values: FormValues) => {
1✔
89
    if (
250✔
90
        values.abiMethod === "existing" ||
250✔
91
        values.specificationMode === "abi_params"
85✔
92
    ) {
250✔
93
        return null;
204✔
94
    }
204✔
95

96
    if (isBlank(value)) {
250✔
97
        return "The ABI signature definition is required";
12✔
98
    }
12✔
99

100
    const items = prepareSignatures(value);
34✔
101
    try {
34✔
102
        parseAbi(items);
34✔
103
    } catch (error: any) {
250✔
104
        return error.message;
3✔
105
    }
3✔
106

107
    return null;
31✔
108
};
31✔
109

110
export const validateAbiParam = (value: string, values: FormValues) => {
1✔
111
    if (
250✔
112
        values.abiMethod === "existing" ||
250✔
113
        values.specificationMode === "json_abi"
85✔
114
    ) {
250✔
115
        return null;
211✔
116
    }
211✔
117

118
    if (isBlank(value)) {
250✔
119
        return "ABI parameter is required.";
8✔
120
    }
8✔
121

122
    try {
31✔
123
        parseAbiParameters(value);
31✔
124
        return null;
31✔
125
    } catch (error: any) {
250✔
126
        return error.message as string;
3✔
127
    }
3✔
128
};
250✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc