Skip to content

Commit

Permalink
Add tests for address helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba committed Dec 7, 2023
1 parent 0c44856 commit 332d6a9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions core/test/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import { expect } from "chai"
import { ZeroAddress } from "ethers"

import { isNonZeroAddress } from "../helpers/address"

const ADDRESS_1: string = "0xb894c3967CFb58A5c55f1de4131d126B1eFA1EE0"
const ADDRESS_1_LOWERCASE: string = ADDRESS_1.toLowerCase()
const ADDRESS_1_NO_PREFIX: string = ADDRESS_1.substring(2)
const ADDRESS_INVALID: string = "0xXYZ4c3967CFb58A5c55f1de4131d126B1eFA1EE0"
const ADDRESS_ZERO: string = ZeroAddress

describe("Helpers", () => {
describe("address", () => {
describe("isNonZeroAddress", () => {
it("should return true for valid checksumed address", () => {
expect(isNonZeroAddress(ADDRESS_1)).to.be.true
})

it("should return true for lowercase address", () => {
expect(isNonZeroAddress(ADDRESS_1_LOWERCASE)).to.be.true
})

it("should return true for address without 0x prefix", () => {
expect(isNonZeroAddress(ADDRESS_1_NO_PREFIX)).to.be.true
})

it("should return false for zero address", () => {
expect(isNonZeroAddress(ADDRESS_ZERO)).to.be.false
})

it("should throw an error for address containing invalid character", () => {
expect(() => {
isNonZeroAddress(ADDRESS_INVALID)
}).to.throw("invalid address")
})
})
})
})

0 comments on commit 332d6a9

Please sign in to comment.