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

cartesi / rollups-explorer-api / 10967725754

20 Sep 2024 11:43PM UTC coverage: 99.294%. Remained the same
10967725754

Pull #49

github

web-flow
Merge e6cbf7991 into 59affc166
Pull Request #49: chore(deps): bump body-parser and express

76 of 80 branches covered (95.0%)

Branch coverage included in aggregate %.

627 of 628 relevant lines covered (99.84%)

5.77 hits per line

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

98.18
/src/utils.ts
1
import { existsSync, readFileSync } from 'node:fs';
1✔
2
import {
3
    arbitrum,
4
    arbitrumSepolia,
5
    base,
6
    baseSepolia,
7
    foundry,
8
    mainnet,
9
    optimism,
10
    optimismSepolia,
11
    sepolia,
12
} from 'viem/chains';
1✔
13

14
type ApplicationMetadata = {
15
    height: number;
16
    addresses: Record<string, string[]>;
17
};
18

19
/**
20
 * Load application metadata structure containing block height and the list of
21
 * application addresses from specified CartesiDAppFactory address.
22
 * @param chainId
23
 * @returns {ApplicationMetadata | null}
24
 */
25
export function loadApplications(chainId: number): ApplicationMetadata | null {
1✔
26
    const filePath = `./assets/applications-${chainId}.json`;
23✔
27

28
    if (!existsSync(filePath)) return null;
23✔
29

30
    const file = readFileSync(filePath, 'utf-8');
6✔
31
    return JSON.parse(file) as ApplicationMetadata;
6✔
32
}
6✔
33

34
export const supportedChains = new Set<number>([
1✔
35
    mainnet.id,
1✔
36
    sepolia.id,
1✔
37
    foundry.id,
1✔
38
    base.id,
1✔
39
    baseSepolia.id,
1✔
40
    optimism.id,
1✔
41
    optimismSepolia.id,
1✔
42
    arbitrum.id,
1✔
43
    arbitrumSepolia.id,
1✔
44
]);
1✔
45

46
/**
47
 * Read the environment variable CHAIN_IDS and filter by
48
 * supported chains, if none the chain 31337 is returned as default.
49
 * @example
50
 *  // Return when multiple supported chains are defined.
51
 *  {chains: [1, 10, 11155111], usingDefault: false}
52
 * @example
53
 *  // Return when no valid chains are defined.
54
 * { chains: [31337], usingDefault: true}
55
 * @returns {number[]}
56
 */
57
export function loadChainsToIndexFromEnvironment() {
1✔
58
    const stringList = (process.env.CHAIN_IDS ?? '').split(',');
4!
59
    const setOfIds = new Set(
4✔
60
        stringList
4✔
61
            .map((value) => parseIntOr({ value, defaultVal: -1 }))
4✔
62
            .filter((id) => supportedChains.has(id)),
4✔
63
    );
4✔
64

65
    if (setOfIds.size === 0)
4✔
66
        return { chains: [foundry.id], usingDefault: true };
4✔
67

68
    return {
3✔
69
        chains: Array.from(setOfIds),
3✔
70
        usingDefault: false,
3✔
71
    };
3✔
72
}
3✔
73
interface ParseIntOr {
74
    value?: string;
75
    defaultVal: number;
76
}
77

78
export function parseIntOr({ value, defaultVal }: ParseIntOr) {
1✔
79
    const number = parseInt(value ?? '');
58✔
80
    return Number.isNaN(number) ? defaultVal : number;
58✔
81
}
58✔
82

83
/**
84
 * Utility to generate standard format IDs based on array of values.
85
 * That makes the id creation between entities less error prone.
86
 * The separator used is "-"
87
 * @example
88
 *  applicationId = "5-0xcbceaf7c9085e33629bcb8f5b6a6d230cf9ece61"
89
 *  inputId = "5-0xcbceaf7c9085e33629bcb8f5b6a6d230cf9ece61-209"
90
 * @param values List of values for ID generation
91
 * @returns
92
 */
93
export function generateIDFrom(values: unknown[] = []) {
1✔
94
    const separator = '-';
52✔
95
    return values.join(separator);
52✔
96
}
52✔
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