Commit 69e38b5f1ee1a25e88128590ba982858181a2a52

Authored by comboy
Committed by Julian Langschaedel
1 parent f006d5e109

add test for get_txout_for_txin and dummy store implementation

Showing 2 changed files with 11 additions and 0 deletions Side-by-side Diff

lib/bitcoin/storage/dummy/dummy_store.rb
... ... @@ -94,6 +94,11 @@
94 94 wrap_txin(txin)
95 95 end
96 96  
  97 + def get_txout_for_txin(txin)
  98 + return nil unless tx = @tx[txin.prev_out.reverse_hth]
  99 + wrap_tx(tx).out[txin.prev_out_index]
  100 + end
  101 +
97 102 def get_txouts_for_pk_script(script)
98 103 txouts = @tx.values.map(&:out).flatten.select {|o| o.pk_script == script}
99 104 txouts.map {|o| wrap_txout(o) }
spec/bitcoin/storage/storage_spec.rb
... ... @@ -273,6 +273,12 @@
273 273 .should == [@block.tx[1].out[0]]
274 274 end
275 275  
  276 + it "should get txouts for txin" do
  277 + prev_tx = @block.tx[0]
  278 + tx = build_tx { |t| create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, Bitcoin::Key.generate]], @key) }
  279 + @store.get_txout_for_txin(tx.in[0]).should == prev_tx.out[0]
  280 + end
  281 +
276 282 it "should get unspent txouts for address" do
277 283 @store.get_unspent_txouts_for_address(@key2.addr, true)
278 284 .should == [@block.tx[1].out[0]]