github
513 of 538 branches covered (95.35%)
Branch coverage included in aggregate %.
298 of 350 new or added lines in 11 files covered. (85.14%)
8 existing lines in 2 files now uncovered.13236 of 13332 relevant lines covered (99.28%)
39.0 hits per line
|
import bech32 from "bech32";
|
2✔ |
|
|
2✔ |
|
import {find} from "lodash-es";
|
2✔ |
4 |
|
2✔ |
5 |
import type {Token} from "@token";
|
2✔ |
6 |
import {Tokens} from "@tokens";
|
2✔ |
7 |
|
2✔ |
8 |
function tokenReducer(check: Token): Token { |
|
|
const ret: Token = find(Tokens.AllTokens, (t => check.isEqual(t)));
|
|
10 |
|
2,108✔ |
11 |
return !ret ? undefined : ret
|
|
12 |
} |
2,108✔ |
13 |
|
2✔ |
14 |
export const tokenSwitch = (check: Token): Token => tokenReducer(check); |
|
|
|
2✔ |
|
|
2✔ |
|
/**
|
2✔ |
|
* terra address validation, it verify also the bech32 checksum |
2✔ |
|
* @param {string} address |
2✔ |
|
*/ |
2✔ |
|
export function validateTerraAddress(address: string): boolean { |
2✔ |
NEW
UNCOV
|
try {
|
× |
NEW
|
const { prefix: decodedPrefix } = bech32.decode(address); // throw error if checksum is invalid |
× |
NEW
|
// verify address prefix
|
× |
NEW
|
|
× |
NEW
|
return decodedPrefix === "terra" |
× |
NEW
|
} catch {
|
× |
NEW
|
// invalid checksum
|
× |
NEW
|
return false |
× |
NEW
|
} |
× |
NEW
|
} |
× |