Skip to content

Commit

Permalink
style: format files with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Feb 9, 2024
1 parent b7ae09c commit c50b0ec
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions packages/utils/tests/number-conversions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,53 @@ import { bufferToBigint, bigintToBuffer, leBigintToBuffer, leBufferToBigint } fr
describe("Number Conversions", () => {
describe("Bigint to/from Buffer Conversions", () => {
const tesetBytes1 = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
]
const testNum1LE = BigInt("0x1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100");
const testNum1BE = BigInt("0x000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
const testNum1LE = BigInt("0x1F1E1D1C1B1A191817161514131211100F0E0D0C0B0A09080706050403020100")
const testNum1BE = BigInt("0x000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")

it("Should support little-endian conversions", async () => {
const in1 = Buffer.from(tesetBytes1)
const n1 = leBufferToBigint(in1)
expect(n1).to.be.eq(testNum1LE)
const out1 = leBigintToBuffer(n1)
expect(out1.length).to.eq(32)
expect(out1).to.deep.eq(Buffer.from(tesetBytes1))
const in1 = Buffer.from(tesetBytes1)
const n1 = leBufferToBigint(in1)
expect(n1).to.be.eq(testNum1LE)
const out1 = leBigintToBuffer(n1)
expect(out1.length).to.eq(32)
expect(out1).to.deep.eq(Buffer.from(tesetBytes1))
})

it("Should support big-endian conversions", async () => {
const in1 = Buffer.from(tesetBytes1)
const n1 = bufferToBigint(in1)
expect(n1).to.be.eq(testNum1BE)
const out1 = bigintToBuffer(n1)
expect(out1.length).to.eq(32)
expect(out1).to.deep.eq(Buffer.from(tesetBytes1))
const in1 = Buffer.from(tesetBytes1)
const n1 = bufferToBigint(in1)
expect(n1).to.be.eq(testNum1BE)
const out1 = bigintToBuffer(n1)
expect(out1.length).to.eq(32)
expect(out1).to.deep.eq(Buffer.from(tesetBytes1))
})

it("Should pad small numbers", async () => {
const smallBufLE = leBigintToBuffer(BigInt(0x020100))
expect(smallBufLE).to.have.length(32)
const smallOutLE = leBufferToBigint(smallBufLE)
expect(smallOutLE).to.eq(BigInt(0x020100))

const smallBufBE = bigintToBuffer(BigInt(0x020100))
expect(smallBufBE).to.have.length(32)
const smallOutBE = bufferToBigint(smallBufBE)
expect(smallOutBE).to.eq(BigInt(0x020100))
const smallBufLE = leBigintToBuffer(BigInt(0x020100))
expect(smallBufLE).to.have.length(32)
const smallOutLE = leBufferToBigint(smallBufLE)
expect(smallOutLE).to.eq(BigInt(0x020100))

const smallBufBE = bigintToBuffer(BigInt(0x020100))
expect(smallBufBE).to.have.length(32)
const smallOutBE = bufferToBigint(smallBufBE)
expect(smallOutBE).to.eq(BigInt(0x020100))
})

it("Should not mutate input buffers", async () => {
const in1 = Buffer.from(tesetBytes1)
expect(in1).to.deep.eq(Buffer.from(tesetBytes1))
const in1 = Buffer.from(tesetBytes1)
expect(in1).to.deep.eq(Buffer.from(tesetBytes1))

const n1LE = leBufferToBigint(in1)
expect(n1LE).to.eq(testNum1LE)
expect(in1).to.deep.eq(Buffer.from(tesetBytes1))
const n1LE = leBufferToBigint(in1)
expect(n1LE).to.eq(testNum1LE)
expect(in1).to.deep.eq(Buffer.from(tesetBytes1))

const n1BE = bufferToBigint(in1)
expect(n1BE).to.eq(testNum1BE)
expect(in1).to.deep.eq(Buffer.from(tesetBytes1))
const n1BE = bufferToBigint(in1)
expect(n1BE).to.eq(testNum1BE)
expect(in1).to.deep.eq(Buffer.from(tesetBytes1))
})
})
})
})

0 comments on commit c50b0ec

Please sign in to comment.