From 332d6a91bda2986c5d58e71accb797f958a63995 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 7 Dec 2023 12:14:50 +0100 Subject: [PATCH] Add tests for address helper --- core/test/helpers.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 core/test/helpers.test.ts diff --git a/core/test/helpers.test.ts b/core/test/helpers.test.ts new file mode 100644 index 000000000..bb5641643 --- /dev/null +++ b/core/test/helpers.test.ts @@ -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") + }) + }) + }) +})