Sha256: e090d5bbb562c774a07a947f7d6e70ebb1766505484ac337a4f8e3cd76eaf6ae

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

require 'rubygems'
require 'ffi-rzmq'

require_relative 'spec_helper'
require_relative '../lib/txcatcher/models/address'
require_relative '../lib/txcatcher/models/transaction'
require_relative '../lib/txcatcher/cleaner'

RSpec.describe TxCatcher::Cleaner do

  before(:each) do
    allow(TxCatcher.rpc_node).to receive(:decoderawtransaction).and_return({ "vout" => []})
  end

  it "doesn't clean anything if transaction count is below threshold" do
    create_transactions(9)
    clean_transactions
    expect(TxCatcher::Transaction.count).to eq(9)
    expect(TxCatcher::Deposit.count).to     eq(9)
    expect(TxCatcher::Address.count).to     eq(9)
  end

  it "cleans excessive transactions from the DB" do
    create_transactions(15)
    clean_transactions
    expect(TxCatcher::Transaction.count).to eq(9)
    expect(TxCatcher::Deposit.count).to     eq(9)
    expect(TxCatcher::Address.count).to     eq(9)
  end

  it "doesn't delete the address upon cleanup if it has another deposit associated with it" do
    create_transactions(15)

    d = TxCatcher::Deposit.create(address_string: "addr1", amount: 0)
    tx = TxCatcher::Transaction.last
    tx.deposits << d
    tx.save

    clean_transactions
    expect(TxCatcher::Transaction.count).to eq(9)
    expect(TxCatcher::Deposit.count).to     eq(10)
    expect(TxCatcher::Address.count).to     eq(10)
  end


  def create_transactions(n)
    (1..n).to_a.each do |i|
      d  = TxCatcher::Deposit.new(address_string: "addr#{i}", amount: 0)
      tx = TxCatcher::Transaction.new
      tx.deposits << d
      tx.save
    end
  end

  def clean_transactions
    TxCatcher::Cleaner.start(run_once: true)
    sleep 1 until TxCatcher::Cleaner.stopped?
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
txcatcher-0.1.5 spec/cleaner_spec.rb
txcatcher-0.1.4 spec/cleaner_spec.rb
txcatcher-0.1.3 spec/cleaner_spec.rb
txcatcher-0.1.2 spec/cleaner_spec.rb
txcatcher-0.1.1 spec/cleaner_spec.rb
txcatcher-0.1.0 spec/cleaner_spec.rb