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

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Feb 1, 2023
1 parent 636c806 commit 3123c1e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions util/ss58.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertEquals, assertInstanceOf } from "../deps/std/testing/asserts.ts"
import { returnThrows } from "./error.ts"
import * as ss58 from "./ss58.ts"
import { alice } from "./test_pairs.ts"

Expand Down Expand Up @@ -33,26 +34,37 @@ for (

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

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

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

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

Deno.test("ss58.decodeRaw invalid checksum", () => {
assertInstanceOf(
ss58.decodeRaw(Uint8Array.of(0, ...alice.publicKey, 255, 255)),
returnThrows<ss58.DecodeError>()(() =>
ss58.decodeRaw(Uint8Array.of(0, ...alice.publicKey, 255, 255))
),
ss58.InvalidAddressChecksumError,
)
})

0 comments on commit 3123c1e

Please sign in to comment.