UNPKG

ox

Version:

Ethereum Standard Library

136 lines (132 loc) 2.93 kB
import { Solidity } from 'ox' import { describe, expect, test } from 'vp/test' test('exports', () => { expect(Object.keys(Solidity)).toMatchInlineSnapshot(` [ "arrayRegex", "bytesRegex", "integerRegex", "maxInt8", "maxInt16", "maxInt24", "maxInt32", "maxInt40", "maxInt48", "maxInt56", "maxInt64", "maxInt72", "maxInt80", "maxInt88", "maxInt96", "maxInt104", "maxInt112", "maxInt120", "maxInt128", "maxInt136", "maxInt144", "maxInt152", "maxInt160", "maxInt168", "maxInt176", "maxInt184", "maxInt192", "maxInt200", "maxInt208", "maxInt216", "maxInt224", "maxInt232", "maxInt240", "maxInt248", "maxInt256", "minInt8", "minInt16", "minInt24", "minInt32", "minInt40", "minInt48", "minInt56", "minInt64", "minInt72", "minInt80", "minInt88", "minInt96", "minInt104", "minInt112", "minInt120", "minInt128", "minInt136", "minInt144", "minInt152", "minInt160", "minInt168", "minInt176", "minInt184", "minInt192", "minInt200", "minInt208", "minInt216", "minInt224", "minInt232", "minInt240", "minInt248", "minInt256", "maxUint8", "maxUint16", "maxUint24", "maxUint32", "maxUint40", "maxUint48", "maxUint56", "maxUint64", "maxUint72", "maxUint80", "maxUint88", "maxUint96", "maxUint104", "maxUint112", "maxUint120", "maxUint128", "maxUint136", "maxUint144", "maxUint152", "maxUint160", "maxUint168", "maxUint176", "maxUint184", "maxUint192", "maxUint200", "maxUint208", "maxUint216", "maxUint224", "maxUint232", "maxUint240", "maxUint248", "maxUint256", "intRange", "maxUint", ] `) }) describe('intRange', () => { test('unsigned 8-bit', () => { expect(Solidity.intRange(8, false)).toEqual({ min: 0n, max: 255n }) }) test('signed 8-bit', () => { expect(Solidity.intRange(8, true)).toEqual({ min: -128n, max: 127n }) }) test('matches existing constants', () => { expect(Solidity.intRange(256, false).max).toBe(Solidity.maxUint256) expect(Solidity.intRange(8, true).max).toBe(Solidity.maxInt8) }) test('rejects non-multiple-of-8 widths', () => { expect(() => Solidity.intRange(7, false)).toThrowError( '`bits` must be a positive multiple of 8 in [8, 256]. Got `7`.', ) }) }) describe('maxUint', () => { test('matches existing constants', () => { expect(Solidity.maxUint(8)).toBe(Solidity.maxUint8) expect(Solidity.maxUint(256)).toBe(Solidity.maxUint256) }) })