Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add utils test case #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { validateAndParseAddress, parseBigintIsh, isEqualAddress, sortsBefore } from '../src/utils'
import JSBI from "jsbi";
import { BigintIsh } from "../src/constants";

describe('validateAndParseAddress', () => {

it('should return checksummed address if valid', () => {
const address = '0xAbCdEf0123456789aBcdef0123456789ABCDEF01'
const checksummedAddress = '0x000000000000000000000000abcdef0123456789abcdef0123456789abcdef01'

const result = validateAndParseAddress(address)
expect(result).toBe(checksummedAddress)
})

it('should throw error if address is not valid', () => {
const address = 'invalid_address'
expect(() => validateAndParseAddress(address)).toThrowError(`${address} is not a valid address.`)
})
})


describe('parseBigintIsh', () => {

it('should return the same JSBI instance if input is already JSBI', () => {
const jsbiValue = JSBI.BigInt('123')
const result = parseBigintIsh(jsbiValue)
expect(result).toBe(jsbiValue)
})

it('should convert bigint to JSBI', () => {
const bigintValue: BigintIsh = BigInt(123)
const result = parseBigintIsh(bigintValue)
expect(result).toEqual(JSBI.BigInt('123'))
})

it('should convert string to JSBI', () => {
const stringValue: BigintIsh = '123'
const result = parseBigintIsh(stringValue)
expect(result).toEqual(JSBI.BigInt('123'))
})

it('should handle large bigint values', () => {
const bigintValue: BigintIsh = BigInt('12345678901234567890')
const result = parseBigintIsh(bigintValue)
expect(result).toEqual(JSBI.BigInt('12345678901234567890'))
})

it('should handle large string values', () => {
const stringValue: BigintIsh = '12345678901234567890'
const result = parseBigintIsh(stringValue)
expect(result).toEqual(JSBI.BigInt('12345678901234567890'))
})
})


describe('isEqualAddress', () => {
it('should return true if two addresses are equal', () => {
const addressA = '0x123'
const addressB = '0x123'

const result = isEqualAddress(addressA, addressB)

expect(result).toBe(true)
})

it('should return false if two addresses are not equal', () => {
const addressA = '0x123'
const addressB = '0x456'

const result = isEqualAddress(addressA, addressB)

expect(result).toBe(false)
})
})


describe('sortsBefore', () => {
it('should return true if addressA is less than addressB', () => {
const addressA = '0x123'
const addressB = '0x456'

const result = sortsBefore(addressA, addressB)

expect(result).toBe(true)
})

it('should return false if addressA is greater than or equal to addressB', () => {
const addressA = '0x456'
const addressB = '0x123'

const result = sortsBefore(addressA, addressB)

expect(result).toBe(false)
})
})