All files / js-dfinity-message/tests index.js

92.86% Statements 13/14
100% Branches 0/0
100% Functions 1/1
92.86% Lines 13/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 332x 2x 2x   2x 2x                     2x   2x 2x 2x     2x 2x 2x         2x    
const crypto = require('crypto')
const tape = require('tape')
const DfinityTx = require('../')
 
tape('tests', async t => {
  const tx = new DfinityTx({
    version: 0,
    to: new Uint8Array(20),
    caps: 0,
    ticks: 0,
    ticksPrice: 0,
    nonce: 0,
    height: 0,
    data: new Uint8Array([])
  })
 
  const sk = crypto.randomBytes(32)
 
  const signedTx = await tx.sign(sk)
  const result = await DfinityTx.validateSignature(signedTx)
  t.equals(result !== false, true, 'should validate message')
 
  // console.log(tx2)
  try {
    const tx2 = await DfinityTx.deserialize(signedTx)
    t.deepEquals(tx2.serialize(), signedTx)
  } catch (e) {
    console.log(e)
  }
 
  t.end()
})