• Kelvin Fichter's avatar
    refactor: improve core-utils folder structure · 3c2acd91
    Kelvin Fichter authored
    Improves the folder structure within the core-utils to make it more
    intuitive. core-utils is now split into three primary folders, "common",
    "external", and "optimism". "common" includes TypeScript/JavaScript
    utilities not necessarily meant to be used with any particular package
    (like hex string utilities). "external" includes utilities that are
    meant to be used in conjunction with some other particular piece of
    tooling (ethers provider utilities, geth typings). "optimism" includes
    any utilities that are specifically meant to be used in the context of
    Optimism (like address aliasing utils, batch encoding utils).
    3c2acd91
alias.spec.ts 1.48 KB
import { expect } from './setup'
import { applyL1ToL2Alias, undoL1ToL2Alias } from '../src'

describe('address aliasing utils', () => {
  describe('applyL1ToL2Alias', () => {
    it('should be able to apply the alias to a valid address', () => {
      expect(
        applyL1ToL2Alias('0x0000000000000000000000000000000000000000')
      ).to.equal('0x1111000000000000000000000000000000001111')
    })

    it('should be able to apply the alias even if the operation overflows', () => {
      expect(
        applyL1ToL2Alias('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')
      ).to.equal('0x1111000000000000000000000000000000001110')
    })

    it('should throw if the input is not a valid address', () => {
      expect(() => {
        applyL1ToL2Alias('0x1234')
      }).to.throw('not a valid address: 0x1234')
    })
  })

  describe('undoL1ToL2Alias', () => {
    it('should be able to undo the alias from a valid address', () => {
      expect(
        undoL1ToL2Alias('0x1111000000000000000000000000000000001111')
      ).to.equal('0x0000000000000000000000000000000000000000')
    })

    it('should be able to undo the alias even if the operation underflows', () => {
      expect(
        undoL1ToL2Alias('0x1111000000000000000000000000000000001110')
      ).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF')
    })

    it('should throw if the input is not a valid address', () => {
      expect(() => {
        undoL1ToL2Alias('0x1234')
      }).to.throw('not a valid address: 0x1234')
    })
  })
})