github.com/ethereum-optimism/optimism@v1.7.2/packages/core-utils/test/optimism/fees.spec.ts (about)

     1  import '../setup'
     2  
     3  import { BigNumber } from '@ethersproject/bignumber'
     4  
     5  import { zeroesAndOnes, calldataCost } from '../../src'
     6  
     7  describe('Fees', () => {
     8    it('should count zeros and ones', () => {
     9      const cases = [
    10        { input: Buffer.from('0001', 'hex'), zeros: 1, ones: 1 },
    11        { input: '0x0001', zeros: 1, ones: 1 },
    12        { input: '0x', zeros: 0, ones: 0 },
    13        { input: '0x1111', zeros: 0, ones: 2 },
    14      ]
    15  
    16      for (const test of cases) {
    17        const [zeros, ones] = zeroesAndOnes(test.input)
    18        zeros.should.eq(test.zeros)
    19        ones.should.eq(test.ones)
    20      }
    21    })
    22  
    23    it('should compute calldata costs', () => {
    24      const cases = [
    25        { input: '0x', output: BigNumber.from(0) },
    26        { input: '0x00', output: BigNumber.from(4) },
    27        { input: '0xff', output: BigNumber.from(16) },
    28        { input: Buffer.alloc(32), output: BigNumber.from(4 * 32) },
    29        { input: Buffer.alloc(32, 0xff), output: BigNumber.from(16 * 32) },
    30      ]
    31  
    32      for (const test of cases) {
    33        const cost = calldataCost(test.input)
    34        cost.should.deep.eq(test.output)
    35      }
    36    })
    37  })