Sha256: 63c8f52a4743a19150756362d508af88b55e2369ab6b47568412aedb47845d0c

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require_relative '../spec_helper'

RSpec.describe TxCatcher::Transaction do

  before(:each) do
    @hextx = File.read(File.dirname(__FILE__) + "/../fixtures/transaction.txt").strip
    @transaction = TxCatcher::Transaction.create(hex: @hextx)
  end

  it "parses rawtx using bitcoind" do
    expect(@transaction.txid).to eq("faf8368fec418a971e8fa94943e951490759498e0b2d3c4d5b9b12212c4f2e5a")
  end

  it "creates addresses and deposits" do
    expect(TxCatcher::Address.where(address: "323LGzCm43NgbtoYJhT6oKSwmKFTQ7AHzH").first.received).to eq(466700000)
    expect(TxCatcher::Address.where(address: "36u6xv2TvZqPPYdogzfLZpMAXrYdW4Vwjp").first.received).to eq(1332776478)
  end

  it "doesn't create duplicate deposits if valid? called manually before save" do
    TxCatcher::Transaction.select_all.delete
    transaction = TxCatcher::Transaction.new(hex: @hextx)
    transaction.valid?
    transaction.save
    expect(transaction.deposits.size).to eq(2)
    transaction.update(block_height: 1)
    expect(TxCatcher::Transaction.where(txid: transaction.txid).count).to eq(1)
  end

  it "updates block height by making manual requests to RPC and searching if tx is included in one of the previous blocks" do
    expect(TxCatcher.rpc_node).to receive(:getblockhash).exactly(10).times.and_return("blockhash123")
    expect(TxCatcher.rpc_node).to receive(:getblock).exactly(10).times.and_return({ "height" => "123", "tx" => [@transaction.txid], "hash" => "blockhash123"})
    @transaction.update_block_height!
    expect(@transaction.block_height).to eq(123)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
txcatcher-0.2.3 spec/models/transaction_spec.rb
txcatcher-0.2.2 spec/models/transaction_spec.rb
txcatcher-0.2.1 spec/models/transaction_spec.rb
txcatcher-0.2.0 spec/models/transaction_spec.rb