Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bohendo/connext

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bohendo/connext

Shared code between wallet and hub

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Testing

There are a number of helper functions to make testing easier::

import { assert, getChannelState, updateState, assertStateEqual } from 'client/testing'

describe('confirm deposit', () => { const preDepositState = getChannelState('empty', { balanceWei: [0, 0], pendingDepositWei: [6, 9], })

  it('should add the correct amount', () => {
     let actual = confirmDeposit(preDepositState)
     assertStateEqual(actual, {
        balanceWei: [6, 9],
        pendingDepositWei: [0, 0],
     })
  })

})

Notice that:

  1. The testing library provides four "default" states: "empty" (where all fields are zero, except for the txCount, which is [1, 1] or 1 for channels and threads, respectively), and "full", where each field has a unique value (this is useful for testing, ex, signature functions).

    empty channel state::

    contractAddress: '0xCCC0000000000000000000000000000000000000' user: '0xAAA0000000000000000000000000000000000000' recipient: '0x2220000000000000000000000000000000000000' balanceWei: [ '0', '0' ] balanceToken: [ '0', '0' ] pendingDepositWei: [ '0', '0' ] pendingDepositToken: [ '0', '0' ] pendingWithdrawalWei: [ '0', '0' ] pendingWithdrawalToken: [ '0', '0' ] txCount: [ 1, 1 ], threadRoot: '0x0000000000000000000000000000000000000000000000000000000000000000' threadCount: 0 timeout: 0 sig: [ '', '' ]

    full channel state::

    contractAddress: '0xCCC0000000000000000000000000000000000000' user: '0xAAA0000000000000000000000000000000000000' recipient: '0x2220000000000000000000000000000000000000' balanceWei: [ '1', '2' ] balanceToken: [ '3', '4' ] pendingDepositWei: [ '4', '5' ] pendingDepositToken: [ '6', '7' ] pendingWithdrawalWei: [ '8', '9' ] pendingWithdrawalToken: [ '10', '11' ] txCount: [ 13, 12 ] threadRoot: '0x1414140000000000000000000000000000000000000000000000000000000000' threadCount: 14 timeout: 15 sig: [ 'sighub0000000000000000000000000000000000000000000000000000000000', 'siguser0000000000000000000000000000000000000000000000000000000000' ]

    empty thread state::

    contractAddress: '0xCCC0000000000000000000000000000000000000' user: '0xAAA0000000000000000000000000000000000000' sender: '0x2220000000000000000000000000000000000000' receiver: '0x3330000000000000000000000000000000000000' txCount: 1 balanceWei: [ '0', '0' ] balanceToken: [ '0', '0' ] sigA: ''

    full thread state::

    contractAddress: '0xCCC0000000000000000000000000000000000000' user: '0xAAA0000000000000000000000000000000000000' sender: '0x2220000000000000000000000000000000000000' receiver: '0x3330000000000000000000000000000000000000' balanceWei: [ '1', '2' ] balanceToken: [ '3', '4' ] txCount: 22 sigA: 'sigA0000000000000000000000000000000000000000000000000000000000'

  2. All operations support "shorthands" for values; internally, balanceWei: [5, 10] is expanded to balanceWeiHub: 6, balanceWeiUser: 9. This is done through two functions: expandChannelSuccinct, expandThreadSuccinct, which expands the fields in a "succinct" state to a verbose state, and makeSuccinctChannel and makeSuccinctThread, which do the opposite.

    Note that these functions can accept partial states, and combinations of succinct and verbose states.

    Additionally, they will always normalize numeric values to strings.

    For example::

    verbose = expandSuccinctChannel({ . balanceWei: [6, 9], . balanceTokenUser: 69, . timout: 5, . }) verbose { balanceWeiHub: '6', balanceTokenUser: '9', balanceTokenUser: '69', timeout: 5, } makeSuccinctChannel(verbose) { balanceWei: ['6', '9'], balanceToken: ['0', '69'], timeout: 5, }

Additionally, useful helper functions:

  • mkAddress(prefix): Generates an address by suffixing prefix with zeros::

    mkAddress('0x1234') '0x1234000000000000000000000000000000000000'

  • mkHash(prefix): Generates a hash by suffixing prefix with zeros::

    mkHash('0xab') '0xab00000000000000000000000000000000000000000000000000000000000000'

FAQs

Package last updated on 07 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc