Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
t6 feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Feb 1, 2023
1 parent 34a4068 commit efb94cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
35 changes: 16 additions & 19 deletions util/ss58.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assertEquals, assertInstanceOf } from "../deps/std/testing/asserts.ts"
import { returnThrows } from "./error.ts"
import { assertEquals, assertThrows } from "../deps/std/testing/asserts.ts"
import * as ss58 from "./ss58.ts"
import { alice } from "./test_pairs.ts"

Expand Down Expand Up @@ -33,38 +32,36 @@ for (
}

Deno.test("ss58.encode invalid public key length", () => {
assertInstanceOf(
returnThrows<ss58.EncodeError>()(() => ss58.encode(0, alice.publicKey.slice(0, 30))),
ss58.InvalidPublicKeyLengthError,
assertThrows(
() => ss58.encode(0, alice.publicKey.slice(0, 30)),
ss58.InvalidPublicKeyLengthError.prototype.message,
)
})

Deno.test("ss58.encode invalid network prefix", () => {
assertInstanceOf(
returnThrows<ss58.EncodeError>()(() => ss58.encode(46, alice.publicKey, [0])),
ss58.InvalidNetworkPrefixError,
assertThrows(
() => ss58.encode(46, alice.publicKey, [0]),
ss58.InvalidNetworkPrefixError.prototype.message,
)
})

Deno.test("ss58.decodeRaw long address", () => {
assertInstanceOf(
returnThrows<ss58.DecodeError>()(() => ss58.decodeRaw(new Uint8Array(40))),
ss58.InvalidAddressLengthError,
assertThrows(
() => ss58.decodeRaw(new Uint8Array(40)),
ss58.InvalidAddressLengthError.prototype.message,
)
})

Deno.test("ss58.decodeRaw short address", () => {
assertInstanceOf(
returnThrows<ss58.DecodeError>()(() => ss58.decodeRaw(new Uint8Array(30))),
ss58.InvalidAddressLengthError,
assertThrows(
() => ss58.decodeRaw(new Uint8Array(30)),
ss58.InvalidAddressLengthError.prototype.message,
)
})

Deno.test("ss58.decodeRaw invalid checksum", () => {
assertInstanceOf(
returnThrows<ss58.DecodeError>()(() =>
ss58.decodeRaw(Uint8Array.of(0, ...alice.publicKey, 255, 255))
),
ss58.InvalidAddressChecksumError,
assertThrows(
() => ss58.decodeRaw(Uint8Array.of(0, ...alice.publicKey, 255, 255)),
ss58.InvalidAddressChecksumError.prototype.message,
)
})
4 changes: 2 additions & 2 deletions util/ss58.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export function encode(
return base58.encode(encodeRaw(prefix, pubKey, validNetworkPrefixes))
}

export const encodeRaw = (
export function encodeRaw(
prefix: number,
pubKey: Uint8Array,
validNetworkPrefixes?: readonly number[],
): Uint8Array => {
): Uint8Array {
const isValidPublicKeyLength = !!VALID_PUBLIC_KEY_LENGTHS[pubKey.length]

if (!isValidPublicKeyLength) {
Expand Down

0 comments on commit efb94cb

Please sign in to comment.