Commit adfa5f56 authored by Kelvin Fichter's avatar Kelvin Fichter

maint(core): clean up test folder structure

Small PR to clean up the folder structure for the tests for core-utils
so that the folders follow the source folders and file names. Planning
to make some improvements to these tests, this is a first simple PR that
will help me do that.
parent f77b7a9b
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
"lint:check": "eslint . --max-warnings=0", "lint:check": "eslint . --max-warnings=0",
"lint:fix": "yarn lint:check --fix", "lint:fix": "yarn lint:check --fix",
"pre-commit": "lint-staged", "pre-commit": "lint-staged",
"test": "ts-mocha test/*.spec.ts", "test": "ts-mocha test/**/*.spec.ts",
"test:coverage": "nyc ts-mocha test/*.spec.ts && nyc merge .nyc_output coverage.json" "test:coverage": "nyc ts-mocha test/**/*.spec.ts && nyc merge .nyc_output coverage.json"
}, },
"keywords": [ "keywords": [
"optimism", "optimism",
......
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
/* Imports: Internal */ /* Imports: Internal */
import { expect } from './setup' import { expect } from '../setup'
import { import {
toRpcHexString, toRpcHexString,
remove0x, remove0x,
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
encodeHex, encodeHex,
hexStringEquals, hexStringEquals,
bytes32ify, bytes32ify,
} from '../src' } from '../../src'
describe('remove0x', () => { describe('remove0x', () => {
it('should return undefined', () => { it('should return undefined', () => {
...@@ -62,6 +62,7 @@ describe('toHexString', () => { ...@@ -62,6 +62,7 @@ describe('toHexString', () => {
'The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null' 'The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null'
) )
}) })
it('should return with a hex string', () => { it('should return with a hex string', () => {
const cases = [ const cases = [
{ input: 0, output: '0x00' }, { input: 0, output: '0x00' },
...@@ -104,6 +105,7 @@ describe('padHexString', () => { ...@@ -104,6 +105,7 @@ describe('padHexString', () => {
expect(padHexString('abcd', 1)).to.deep.equal('abcd') expect(padHexString('abcd', 1)).to.deep.equal('abcd')
expect(padHexString('abcdefgh', 3).length).to.deep.equal(8) expect(padHexString('abcdefgh', 3).length).to.deep.equal(8)
}) })
it('should return a string padded with 0x and zeros', () => { it('should return a string padded with 0x and zeros', () => {
expect(padHexString('0xabcd', 3)).to.deep.equal('0x00abcd') expect(padHexString('0xabcd', 3)).to.deep.equal('0x00abcd')
}) })
......
/* Imports: Internal */ /* Imports: Internal */
import { expect } from './setup' import { expect } from '../setup'
import { sleep, clone, reqenv, getenv } from '../src' import { sleep, clone, reqenv, getenv } from '../../src'
describe('sleep', async () => { describe('sleep', async () => {
it('should return wait input amount of ms', async () => { it('should return wait input amount of ms', async () => {
...@@ -21,7 +21,7 @@ describe('clone', async () => { ...@@ -21,7 +21,7 @@ describe('clone', async () => {
}) })
describe('reqenv', async () => { describe('reqenv', async () => {
let cachedEnvironment let cachedEnvironment: NodeJS.ProcessEnv
const temporaryEnvironmentKey = 'testVariable' const temporaryEnvironmentKey = 'testVariable'
const temporaryEnvironment = { const temporaryEnvironment = {
[temporaryEnvironmentKey]: 'This is an environment variable', [temporaryEnvironmentKey]: 'This is an environment variable',
...@@ -51,7 +51,7 @@ describe('reqenv', async () => { ...@@ -51,7 +51,7 @@ describe('reqenv', async () => {
}) })
describe('getenv', async () => { describe('getenv', async () => {
let cachedEnvironment let cachedEnvironment: NodeJS.ProcessEnv
const temporaryEnvironmentKey = 'testVariable' const temporaryEnvironmentKey = 'testVariable'
const temporaryEnvironment = { const temporaryEnvironment = {
[temporaryEnvironmentKey]: 'This is an environment variable', [temporaryEnvironmentKey]: 'This is an environment variable',
......
import { assert } from 'chai' import { assert } from 'chai'
/* Imports: Internal */ /* Imports: Internal */
import { expect } from './setup' import { expect } from '../setup'
import { expectApprox, awaitCondition } from '../src' import { expectApprox, awaitCondition } from '../../src'
describe('awaitCondition', () => { describe('awaitCondition', () => {
it('should try the condition fn until it returns true', async () => { it('should try the condition fn until it returns true', async () => {
...@@ -42,6 +42,7 @@ describe('expectApprox', () => { ...@@ -42,6 +42,7 @@ describe('expectApprox', () => {
absoluteLowerDeviation: 20, absoluteLowerDeviation: 20,
}) })
}) })
it('should pass when the actual number is lower, but within the expected range of the target', async () => { it('should pass when the actual number is lower, but within the expected range of the target', async () => {
expectApprox(81, 100, { expectApprox(81, 100, {
percentUpperDeviation: 20, percentUpperDeviation: 20,
...@@ -50,6 +51,7 @@ describe('expectApprox', () => { ...@@ -50,6 +51,7 @@ describe('expectApprox', () => {
absoluteLowerDeviation: 20, absoluteLowerDeviation: 20,
}) })
}) })
it('should throw an error when no deviation values are given', async () => { it('should throw an error when no deviation values are given', async () => {
try { try {
expectApprox(101, 100, {}) expectApprox(101, 100, {})
...@@ -75,6 +77,7 @@ describe('expectApprox', () => { ...@@ -75,6 +77,7 @@ describe('expectApprox', () => {
) )
} }
}) })
it('... and absoluteUpperDeviation sets the upper bound', async () => { it('... and absoluteUpperDeviation sets the upper bound', async () => {
try { try {
expectApprox(121, 100, { expectApprox(121, 100, {
...@@ -88,6 +91,7 @@ describe('expectApprox', () => { ...@@ -88,6 +91,7 @@ describe('expectApprox', () => {
} }
}) })
}) })
describe('... when both values are defined', () => { describe('... when both values are defined', () => {
it('... and percentUpperDeviation sets the upper bound', async () => { it('... and percentUpperDeviation sets the upper bound', async () => {
try { try {
...@@ -102,6 +106,7 @@ describe('expectApprox', () => { ...@@ -102,6 +106,7 @@ describe('expectApprox', () => {
) )
} }
}) })
it('... and absoluteUpperDeviation sets the upper bound', async () => { it('... and absoluteUpperDeviation sets the upper bound', async () => {
try { try {
expectApprox(121, 100, { expectApprox(121, 100, {
......
import { expect } from './setup' import { expect } from '../setup'
import { applyL1ToL2Alias, undoL1ToL2Alias } from '../src' import { applyL1ToL2Alias, undoL1ToL2Alias } from '../../src'
describe('address aliasing utils', () => { describe('address aliasing utils', () => {
describe('applyL1ToL2Alias', () => { describe('applyL1ToL2Alias', () => {
......
import './setup' import '../setup'
/* Internal Imports */ /* Internal Imports */
import { expect } from 'chai' import { expect } from 'chai'
...@@ -9,13 +9,13 @@ import { ...@@ -9,13 +9,13 @@ import {
sequencerBatch, sequencerBatch,
BatchType, BatchType,
SequencerBatch, SequencerBatch,
} from '../src' } from '../../src'
describe('BatchEncoder', function () { describe('BatchEncoder', function () {
this.timeout(10_000) this.timeout(10_000)
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const data = require('./fixtures/calldata.json') const data = require('../fixtures/calldata.json')
describe('appendSequencerBatch', () => { describe('appendSequencerBatch', () => {
it('legacy: should work with the simple case', () => { it('legacy: should work with the simple case', () => {
...@@ -112,6 +112,7 @@ describe('BatchEncoder', function () { ...@@ -112,6 +112,7 @@ describe('BatchEncoder', function () {
], ],
transactions: ['0x454234000000112', '0x45423400000012'], transactions: ['0x454234000000112', '0x45423400000012'],
} }
expect(() => encodeAppendSequencerBatch(batch)).to.throw( expect(() => encodeAppendSequencerBatch(batch)).to.throw(
'Unexpected uneven hex string value!' 'Unexpected uneven hex string value!'
) )
......
import './setup' import '../setup'
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { zeroesAndOnes, calldataCost } from '../src' import { zeroesAndOnes, calldataCost } from '../../src'
describe('Fees', () => { describe('Fees', () => {
it('should count zeros and ones', () => { it('should count zeros and ones', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment