<commit_before>require_relative "setup"

include BitVault::Bitcoin

describe "Transaction" do
  include BitVaultTests::Bitcoin

  describe "created with no arguments" do

    def transaction
      @transaction ||= Transaction.new()
    end

    it "has a native Tx" do
      assert_kind_of Bitcoin::Protocol::Tx, transaction.native
    end

    it "has no inputs" do
      assert_empty transaction.inputs
    end

    it "has no outputs" do
      assert_empty transaction.outputs
    end

    it "has binary and base58 hash values" do
      refute_empty transaction.binary_hash
      assert_kind_of String, transaction.binary_hash
      refute_empty transaction.base58_hash
      assert_kind_of String, transaction.base58_hash
    end

    it "fails validation" do
      report = transaction.validate_syntax
      assert_equal false, report[:valid]
      assert_equal :lists, report[:error].first
    end

  end

  describe "created from a full Hash representation" do

    def transaction
      @transaction ||= begin
        keypair = ::Bitcoin::Key.new
        address = keypair.addr
        Transaction.data(
          :inputs => [],
          :outputs => [
            :value => 1000,
            :script => {
              :address => address
            }
          ]
        )
      end
    end

    it "works" do
      # TODO:  add real tests, obviously.
      assert_equal 0, transaction.inputs.size
    end

  end


  describe "created from a valid Bitcoin::Protocol::Tx" do

    def transaction
      @transaction ||= Transaction.native(disbursal_tx)
    end

    it "has binary and base58 hash values" do
      assert_equal disbursal_tx.binary_hash, transaction.binary_hash
      refute_empty transaction.base58_hash
      assert_kind_of String, transaction.base58_hash
    end

    describe "inputs" do<commit_msg>bug in the Transaction.data test<commit_after>require_relative "setup"

include BitVault::Bitcoin

describe "Transaction" do
  include BitVaultTests::Bitcoin

  describe "created with no arguments" do

    def transaction
      @transaction ||= Transaction.new()
    end

    it "has a native Tx" do
      assert_kind_of Bitcoin::Protocol::Tx, transaction.native
    end

    it "has no inputs" do
      assert_empty transaction.inputs
    end

    it "has no outputs" do
      assert_empty transaction.outputs
    end

    it "has binary and base58 hash values" do
      refute_empty transaction.binary_hash
      assert_kind_of String, transaction.binary_hash
      refute_empty transaction.base58_hash
      assert_kind_of String, transaction.base58_hash
    end

    it "fails validation" do
      report = transaction.validate_syntax
      assert_equal false, report[:valid]
      assert_equal :lists, report[:error].first
    end

  end

  describe "created from a full Hash representation" do

    def transaction
      @transaction ||= begin
        keypair = ::Bitcoin::Key.new
        address = keypair.addr
        Transaction.data(
          :inputs => [],
          :outputs => [
            {
              :value => 1000,
              :script => {
                :address => address
              }
            },
            {
              :value => 2000,
              :script => {
                :address => address
              }
            }
          ]
        )
      end
    end

    it "works" do
      # TODO:  add real tests, obviously.
      assert_equal 0, transaction.inputs.size
      assert_equal 2, transaction.outputs.size
    end

  end


  describe "created from a valid Bitcoin::Protocol::Tx" do

    def transaction
      @transaction ||= Transaction.native(disbursal_tx)
    end

    it "has binary and base58 hash values" do
      assert_equal disbursal_tx.binary_hash, transaction.binary_hash
      refute_empty transaction.base58_hash
      assert_kind_of String, transaction.base58_hash
    end

    describe "inputs" do
{'fraction_non_alphanumeric': 0.07109856262833676, 'fraction_numerical': 0.010010266940451745, 'mean_word_length': 2.2340248962655602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5303341', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1042, 'n_words': 311}