<commit_before>/* eslint-env mocha */

import chai from 'chai'
import chaiBytes from 'chai-bytes'
import dirtyChai from 'dirty-chai'

import * as crypto from '../src/crypto'
import types from '../src/std'
import { isExonumType } from '../src/lowlevel/common'

import blockData from './data/block.json'

const { PublicKey, Precommit } = types

const expect = chai
  .use(chaiBytes)
  .use(dirtyChai)
  .expect

describe('Message', () => {
  const TxTransfer = types.resolve({
    message: {
      serviceId: 1,
      messageId: 128,
      body: [
        { name: 'from', type: 'PublicKey', author: true },
        { name: 'to', type: 'PublicKey' },
        { name: 'amount', type: 'Uint64' }
      ]
    }
  })

  const TxCreate = types.resolve({
    message: {
      serviceId: 1,
      messageId: 129,
      body: [
        { name: 'from', type: 'PublicKey', author: true },
        { name: 'name', type: 'Str' }
      ]
    }
  })

  const ComplexMessage = types.resolve({
    message: {
      serviceId: 1,
      messageId: 130,
      body: [
        { name: 'from', type: 'PublicKey', author: true },
        { name: 'foo', type: 'Str' },
        {
          name: 'bar',
          type: {
            struct: [
              { name: 'x', type: 'Int32' },
              { name: 'y', type: 'Int32' }
            ]
          }
        }
      ]
    }
  })

  const NonStructMessage = types.resolve({
    message: {
      serviceId: 1,
      messageId: 1001,
      body: { fixedBuffer: 4 }
    }
  })

  const aliceKey = crypto.secret()
  const bobKey = crypto.secret()

  describe('constructor', () => {
    it('should construct a message', () => {
      const msg = new TxTransfer({
        body: {
          from: aliceKey.pub(),
          to: bobKey.pub(),
          amount: 10000
        }
      })
<commit_msg>Use brainwallets in tests for reproducibility<commit_after>/* eslint-env mocha */

import chai from 'chai'
import chaiBytes from 'chai-bytes'
import dirtyChai from 'dirty-chai'

import * as crypto from '../src/crypto'
import types from '../src/std'
import { isExonumType } from '../src/lowlevel/common'

import blockData from './data/block.json'

const { PublicKey, Precommit } = types

const expect = chai
  .use(chaiBytes)
  .use(dirtyChai)
  .expect

function brainwallet (phrase) {
  return crypto.secret.fromSeed(crypto.hash(types.Str.from(phrase)))
}

describe('Message', () => {
  const TxTransfer = types.resolve({
    message: {
      serviceId: 1,
      messageId: 128,
      body: [
        { name: 'from', type: 'PublicKey', author: true },
        { name: 'to', type: 'PublicKey' },
        { name: 'amount', type: 'Uint64' }
      ]
    }
  })

  const TxCreate = types.resolve({
    message: {
      serviceId: 1,
      messageId: 129,
      body: [
        { name: 'from', type: 'PublicKey', author: true },
        { name: 'name', type: 'Str' }
      ]
    }
  })

  const ComplexMessage = types.resolve({
    message: {
      serviceId: 1,
      messageId: 130,
      body: [
        { name: 'from', type: 'PublicKey', author: true },
        { name: 'foo', type: 'Str' },
        {
          name: 'bar',
          type: {
            struct: [
              { name: 'x', type: 'Int32' },
              { name: 'y', type: 'Int32' }
            ]
          }
        }
      ]
    }
  })

  const NonStructMessage = types.resolve({
    message: {
      serviceId: 1,
      messageId: 1001,
      body: { fixedBuffer: 4 }
    }
  })

  const aliceKey = brainwallet('correct horse battery staple')
  const bobKey = brainwallet('Bob!')

  describe('constructor', () => {
    it('should construct a message', () => {
      const msg = new TxTransfer({
        body: {
          from: aliceKey.pub(),
          to: bobKey.pub(),
          amount: 10000
        }
      })

{'fraction_non_alphanumeric': 0.15202524986849028, 'fraction_numerical': 0.015255128879537085, 'mean_word_length': 1.966458658346334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6151705', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1228, 'n_words': 311}