<commit_before>/* global describe, it */

var assert = require('assert')
var base58 = require('bs58')

var Bitcoin = require('../')
var Address = Bitcoin.Address
var Block = Bitcoin.Block
var ECPair = Bitcoin.ECPair
var ECSignature = Bitcoin.ECSignature
var Transaction = Bitcoin.Transaction
var Script = Bitcoin.Script

var bufferutils = Bitcoin.bufferutils
var networks = Bitcoin.networks

var base58_encode_decode = require('./fixtures/core/base58_encode_decode.json')
var base58_keys_invalid = require('./fixtures/core/base58_keys_invalid.json')
var base58_keys_valid = require('./fixtures/core/base58_keys_valid.json')
var blocks_valid = require('./fixtures/core/blocks.json')
var sig_canonical = require('./fixtures/core/sig_canonical.json')
var sig_noncanonical = require('./fixtures/core/sig_noncanonical.json')
var sighash = require('./fixtures/core/sighash.json')
var tx_valid = require('./fixtures/core/tx_valid.json')

describe('Bitcoin-core', function () {
  // base58_encode_decode
  describe('base58', function () {
    base58_encode_decode.forEach(function (f) {
      var fhex = f[0]
      var fb58 = f[1]

      it('can decode ' + fb58, function () {
        var buffer = base58.decode(fb58)
        var actual = new Buffer(buffer).toString('hex')

        assert.strictEqual(actual, fhex)
      })

      it('can encode ' + fhex, function () {
        var buffer = new Buffer(fhex, 'hex')
        var actual = base58.encode(buffer)

        assert.strictEqual(actual, fb58)
      })
    })
  })

  // base58_keys_valid
  describe('Address.formBase58Check', function () {
    var typeMap = {
      'pubkey': 'pubKeyHash',
      'script': 'scriptHash'
    }

    base58_keys_valid.forEach(function (f) {
      var string = f[0]
      var hex = f[1]
      var params = f[2]
      var network = networks.bitcoin

      if (params.isPrivkey) return
      if (params.isTestnet) {
        network = networks.testnet
      }

      it('can import ' + string, function () {
        var address = Address.fromBase58Check(string)

        assert.strictEqual(address.hash.toString('hex'), hex)
        assert.strictEqual(address.version, network[typeMap[params.addrType]])
      })
    })
  })

  // base58_keys_invalid<commit_msg>tests: fix spelling error<commit_after>/* global describe, it */

var assert = require('assert')
var base58 = require('bs58')

var Bitcoin = require('../')
var Address = Bitcoin.Address
var Block = Bitcoin.Block
var ECPair = Bitcoin.ECPair
var ECSignature = Bitcoin.ECSignature
var Transaction = Bitcoin.Transaction
var Script = Bitcoin.Script

var bufferutils = Bitcoin.bufferutils
var networks = Bitcoin.networks

var base58_encode_decode = require('./fixtures/core/base58_encode_decode.json')
var base58_keys_invalid = require('./fixtures/core/base58_keys_invalid.json')
var base58_keys_valid = require('./fixtures/core/base58_keys_valid.json')
var blocks_valid = require('./fixtures/core/blocks.json')
var sig_canonical = require('./fixtures/core/sig_canonical.json')
var sig_noncanonical = require('./fixtures/core/sig_noncanonical.json')
var sighash = require('./fixtures/core/sighash.json')
var tx_valid = require('./fixtures/core/tx_valid.json')

describe('Bitcoin-core', function () {
  // base58_encode_decode
  describe('base58', function () {
    base58_encode_decode.forEach(function (f) {
      var fhex = f[0]
      var fb58 = f[1]

      it('can decode ' + fb58, function () {
        var buffer = base58.decode(fb58)
        var actual = new Buffer(buffer).toString('hex')

        assert.strictEqual(actual, fhex)
      })

      it('can encode ' + fhex, function () {
        var buffer = new Buffer(fhex, 'hex')
        var actual = base58.encode(buffer)

        assert.strictEqual(actual, fb58)
      })
    })
  })

  // base58_keys_valid
  describe('Address.fromBase58Check', function () {
    var typeMap = {
      'pubkey': 'pubKeyHash',
      'script': 'scriptHash'
    }

    base58_keys_valid.forEach(function (f) {
      var string = f[0]
      var hex = f[1]
      var params = f[2]
      var network = networks.bitcoin

      if (params.isPrivkey) return
      if (params.isTestnet) {
        network = networks.testnet
      }

      it('can import ' + string, function () {
        var address = Address.fromBase58Check(string)

        assert.strictEqual(address.hash.toString('hex'), hex)
        assert.strictEqual(address.version, network[typeMap[params.addrType]])
      })
    })
  })

  // base58_keys_invalid
{'fraction_non_alphanumeric': 0.13123885918003564, 'fraction_numerical': 0.021836007130124777, 'mean_word_length': 3.275238095238095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7351279', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1374, 'n_words': 288}