<commit_before>require 'spec_helper'

describe Nis::Util::Serializer do
  subject { described_class }

  let(:private_key) { '<KEY>' }
  let(:mosaic_id) { { namespaceId: 'makoto.metal.silver', name: 'coin' } }
  let(:mosaic) { { mosaicId: mosaic_id, quantity: 123_000 } }
  let(:property) { { name: 'divisibility', value: '3' } }
  let(:properties) do
    [ { name: 'divisibility', value: '3' },
      { name: 'initialSupply', value: '1000' },
      { name: 'supplyMutable', value: 'false' },
      { name: 'transferable', value: 'true' } ]
  end
  let(:levy) do
    { recipient: 'TAH4MBR6MNLZKJAVW5ZJCMFAL7RS5U2YODUQKLCT',
      mosaic_id: mosaic_id,
      fee: 1_000_000 }
  end
  let(:mosaic_definition) do
    { creator: hex_creator,
      id: mosaic_id,
      description: description,
      properties: properties,
      levy: levy }
  end
  let(:hex_creator) { '10cfe522fe23c015b8ab24ef6a0c32c5de78eb55b2152ed07b6a092121187100' }
  let(:description) { 'A healthy drink with lots of vitamins' }

  it { expect(subject.serialize_safe_string('Hello')).to eq [5, 0, 0, 0, 72, 101, 108, 108, 111] }
  it { expect(subject.serialize_safe_string(nil)).to eq [255, 255, 255, 255] }
  it { expect(subject.serialize_safe_string('')).to  eq [0, 0, 0, 0] }

  # it { expect(subject.serialize_ua_string('9876543210')).to eq [10, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] }
  # it { expect(subject.serialize_ua_string(nil)).to eq [255, 255, 255, 255] }
  # it { expect(subject.serialize_ua_string('')).to  eq [0, 0, 0, 0] }

  it { expect(subject.serialize_int(0x0101)).to eq [1,  1, 0, 0] }
  it { expect(subject.serialize_int(0x1001)).to eq [1, 16, 0, 0] }
  it { expect(subject.serialize_int(0x2001)).to eq [1, 32, 0, 0] }
  it { expect(subject.serialize_int(0x4001)).to eq [1, 64, 0, 0] }
  it { expect(subject.serialize_int(0x98000001)).to eq [1,  0, 0, 152] }

  it { expect(subject.serialize_long(3_000_000)).to eq [192, 198, 45, 0, 0, 0, 0, 0] }
  it { expect(subject.serialize_long(12_000_000)).to eq [0, 27, 183, 0, 0, 0, 0, 0] }
  it { expect(subject.serialize_long(1_234_000_000)).to eq [128, 88, 141, 73, 0, 0, 0, 0] }
  it { expect(subject.serialize_long(50_000_000_000)).to eq [0, 116, 59, 164, 11, 0, 0, 0] }
  it { expect(subject.serialize_long(100_000_000_000)).to eq [0, 232, 118, 72, 23, 0, 0, 0] }

  it { expect(subject.serialize_mosaic_id(mosaic_id)).to eq [31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110] }

  xit { expect(subject.serialize_mosaic_and_quantity(mosaic)).to eq [43, 0, 0, 0, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 120, 224, 1, 0, 0, 0, 0, 0] }

  xit { expect(subject.serialize_mosaics([mosaic])).to eq [1, 0, 0, 0, 43, 0, 0, 0, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 120, 224, 1, 0, 0, 0, 0, 0] }

  it { expect(subject.serialize_property(property)).to eq [21, 0, 0, 0, 12, 0, 0, 0, 100, 105, 118, 105, 115, 105, 98, 105, 108, 105, 116, 121, 1, 0, 0, 0, 51] }

  xit { expect(subject.serialize_properties(properties)).to eq [1, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, 100, 105, 118, 105, 115, 105, 98, 105, 108, 105, 116, 121, 1, 0, 0, 0, 51] }

  xit { expect(subject.serialize_levy(levy)).to eq [91, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 84, 65, 72, 52, 77, 66, 82, 54, 77, 78, 76, 90, 75, 74, 65, 86, 87, 53, 90, 74, 67, 77, 70, 65, 76, 55, 82, 83, 53, 85, 50, 89, 79, 68, 85, 81, 75, 76, 67, 84, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 64, 66, 15, 0, 0, 0, 0, 0] }
  it { expect(subject.serialize_levy(nil)).to eq [0, 0, 0, 0] }

  xit { expect(subject.serialize_mosaic_definition(mosaic_definition)).to eq [32, 0, 0, 0, 16, 207, 229, 34, 254, 35, 192, 21, 184, 171, 36, 239, 106, 12, 50, 197, 222, 120, 235, 85, 178, 21, 46, 208, 123, 106, 9, 33, 33, 24, 113, 0, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 37, 0, 0, 0, 65, 32, 104, 101, 97, 108, 116, 104, 121, 32, 100, 114, 105, 110, 107, 32, 119, 105, 116, 104, 32, 108, 111, 116, 115, 32, 111, 102, 32, 118, 105, 116, 97, 109, 105, 110, 115, 1, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, 100, 105, 118, 105, 115, 105, 98, 105, 108, 105, 116, 121, 1, 0, 0, 0, 51, 91, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 84, 65, 72, 52, 77, 66, 82, 54, 77, 78, 76, 90, 75, 74, 65, 86, 87, 53, 90, 74, 67, 77, 70, 65, 76, 55, 82, 83, 53, 85, 50, 89, 79, 68, 85, 81, 75, 76, 67, 84, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 64, 66, 15, 0, 0, 0, 0, 0] }

  describe '.serialize_transaction' do
    subject { described_class.serialize_transaction(entity) }

    context 'when transfer' do
      let(:entity) do
        {
          type: 257,
          version: -1744830463,
          timeStamp: 9111526,
          signer: 'a1aaca6c17a24252e674d155713cdf55996ad00175be4af02a20c67b59f9fe8a',
          fee: 3_000_000,
          deadline: 9154726,
          recipient: 'TAH4MBR6MNLZ<KEY>',
          amount: 1_000_000_000,
          message: {
            payload: 'Hello',
            type: 1
          },
          privateKey: '<KEY>'
        }
      end<commit_msg>fixup serializer<commit_after>require 'spec_helper'

describe Nis::Util::Serializer do
  subject { described_class }

  let(:private_key) { '<KEY>' }
  let(:mosaic_id) { { namespaceId: 'makoto.metal.silver', name: 'coin' } }
  let(:mosaic) { { mosaicId: mosaic_id, quantity: 123_000 } }
  let(:property) { { name: 'divisibility', value: '3' } }
  let(:properties) do
    [ { name: 'divisibility', value: '3' },
      { name: 'initialSupply', value: '1000' },
      { name: 'supplyMutable', value: 'false' },
      { name: 'transferable', value: 'true' } ]
  end
  let(:levy) do
    { recipient: 'TAH4MBR6MNLZKJAVW5ZJCMFAL7RS5U2YODUQKLCT',
      mosaic_id: mosaic_id,
      fee: 1_000_000 }
  end
  let(:mosaic_definition) do
    { creator: hex_creator,
      id: mosaic_id,
      description: description,
      properties: properties,
      levy: levy }
  end
  let(:hex_creator) { '10cfe522fe23c015b8ab24ef6a0c32c5de78eb55b2152ed07b6a092121187100' }
  let(:description) { 'A healthy drink with lots of vitamins' }

  it { expect(subject.serialize_safe_string('Hello')).to eq [5, 0, 0, 0, 72, 101, 108, 108, 111] }
  it { expect(subject.serialize_safe_string(nil)).to eq [255, 255, 255, 255] }
  it { expect(subject.serialize_safe_string('')).to  eq [0, 0, 0, 0] }

  # it { expect(subject.serialize_ua_string('9876543210')).to eq [10, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] }
  # it { expect(subject.serialize_ua_string(nil)).to eq [255, 255, 255, 255] }
  # it { expect(subject.serialize_ua_string('')).to  eq [0, 0, 0, 0] }

  it { expect(subject.serialize_int(0x0101)).to eq [1,  1, 0, 0] }
  it { expect(subject.serialize_int(0x1001)).to eq [1, 16, 0, 0] }
  it { expect(subject.serialize_int(0x2001)).to eq [1, 32, 0, 0] }
  it { expect(subject.serialize_int(0x4001)).to eq [1, 64, 0, 0] }
  it { expect(subject.serialize_int(0x98000001)).to eq [1,  0, 0, 152] }

  it { expect(subject.serialize_long(3_000_000)).to eq [192, 198, 45, 0, 0, 0, 0, 0] }
  it { expect(subject.serialize_long(12_000_000)).to eq [0, 27, 183, 0, 0, 0, 0, 0] }
  it { expect(subject.serialize_long(1_234_000_000)).to eq [128, 88, 141, 73, 0, 0, 0, 0] }
  it { expect(subject.serialize_long(50_000_000_000)).to eq [0, 116, 59, 164, 11, 0, 0, 0] }
  it { expect(subject.serialize_long(100_000_000_000)).to eq [0, 232, 118, 72, 23, 0, 0, 0] }

  it { expect(subject.serialize_mosaic_id(mosaic_id)).to eq [31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110] }

  it { expect(subject.serialize_mosaic_and_quantity(mosaic)).to eq [31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 120, 224, 1, 0, 0, 0, 0, 0] }

  it { expect(subject.serialize_mosaics([mosaic])).to eq [1, 0, 0, 0, 43, 0, 0, 0, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 120, 224, 1, 0, 0, 0, 0, 0] }

  it { expect(subject.serialize_property(property)).to eq [21, 0, 0, 0, 12, 0, 0, 0, 100, 105, 118, 105, 115, 105, 98, 105, 108, 105, 116, 121, 1, 0, 0, 0, 51] }

  it { expect(subject.serialize_properties(properties)).to eq [4, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, 100, 105, 118, 105, 115, 105, 98, 105, 108, 105, 116, 121, 1, 0, 0, 0, 51, 25, 0, 0, 0, 13, 0, 0, 0, 105, 110, 105, 116, 105, 97, 108, 83, 117, 112, 112, 108, 121, 4, 0, 0, 0, 49, 48, 48, 48, 26, 0, 0, 0, 13, 0, 0, 0, 115, 117, 112, 112, 108, 121, 77, 117, 116, 97, 98, 108, 101, 5, 0, 0, 0, 102, 97, 108, 115, 101, 24, 0, 0, 0, 12, 0, 0, 0, 116, 114, 97, 110, 115, 102, 101, 114, 97, 98, 108, 101, 4, 0, 0, 0, 116, 114, 117, 101] }

  xit { expect(subject.serialize_levy(levy)).to eq [91, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 84, 65, 72, 52, 77, 66, 82, 54, 77, 78, 76, 90, 75, 74, 65, 86, 87, 53, 90, 74, 67, 77, 70, 65, 76, 55, 82, 83, 53, 85, 50, 89, 79, 68, 85, 81, 75, 76, 67, 84, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 64, 66, 15, 0, 0, 0, 0, 0] }
  it { expect(subject.serialize_levy(nil)).to eq [0, 0, 0, 0] }

  xit { expect(subject.serialize_mosaic_definition(mosaic_definition)).to eq [32, 0, 0, 0, 16, 207, 229, 34, 254, 35, 192, 21, 184, 171, 36, 239, 106, 12, 50, 197, 222, 120, 235, 85, 178, 21, 46, 208, 123, 106, 9, 33, 33, 24, 113, 0, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 37, 0, 0, 0, 65, 32, 104, 101, 97, 108, 116, 104, 121, 32, 100, 114, 105, 110, 107, 32, 119, 105, 116, 104, 32, 108, 111, 116, 115, 32, 111, 102, 32, 118, 105, 116, 97, 109, 105, 110, 115, 1, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, 100, 105, 118, 105, 115, 105, 98, 105, 108, 105, 116, 121, 1, 0, 0, 0, 51, 91, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 84, 65, 72, 52, 77, 66, 82, 54, 77, 78, 76, 90, 75, 74, 65, 86, 87, 53, 90, 74, 67, 77, 70, 65, 76, 55, 82, 83, 53, 85, 50, 89, 79, 68, 85, 81, 75, 76, 67, 84, 31, 0, 0, 0, 19, 0, 0, 0, 109, 97, 107, 111, 116, 111, 46, 109, 101, 116, 97, 108, 46, 115, 105, 108, 118, 101, 114, 4, 0, 0, 0, 99, 111, 105, 110, 64, 66, 15, 0, 0, 0, 0, 0] }

  describe '.serialize_transaction' do
    subject { described_class.serialize_transaction(entity) }

    context 'when transfer' do
      let(:entity) do
        {
          type: 257,
          version: -1744830463,
          timeStamp: 9111526,
          signer: 'a1aaca6c17a24252e674d155713cdf55996ad00175be4af02a20c67b59f9fe8a',
          fee: 3_000_000,
          deadline: 9154726,
          recipient: 'TAH4MBR6MNLZKJAVW5ZJCMFAL7RS5U2YODUQKLCT',
          amount: 1_000_000_000,
          message: {
            payload: 'Hello',
            type: 1
          },
          privateKey: '<KEY>'
        }
      end
{'fraction_non_alphanumeric': 0.18954989532449407, 'fraction_numerical': 0.2717201674808095, 'mean_word_length': 3.3444486547934824, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 49, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428144', 'n_tokens_mistral': 7800, 'n_tokens_neox': 4866, 'n_words': 1689}