Commit bfb350bbd35186b5ccb49a148306dda497ba7978

Authored by Marius Hanne
1 parent 78ad135bb0

fix wallet spec

Showing 2 changed files with 22 additions and 21 deletions Side-by-side Diff

lib/bitcoin/wallet/wallet.rb
... ... @@ -20,7 +20,7 @@
20 20 end
21 21  
22 22 def addrs
23   - @keystore.keys.map{|k| k.addr}
  23 + @keystore.keys.map{|k| k[:key].addr}
24 24 end
25 25  
26 26 def list
spec/bitcoin/wallet/wallet_spec.rb
1 1 require_relative '../spec_helper'
2   -
  2 +require 'json'
3 3 include MiniTest
4 4 include Bitcoin
5 5 include Bitcoin::Wallet
6 6  
  7 +def txout_mock(value, next_in)
  8 + txout = Mock.new
  9 + txout.expect(:value, value)
  10 + txout.expect(:get_next_in, next_in)
  11 + txout.expect(:hash, [value, next_in].hash)
  12 + txout.expect(:eql?, false, [1])
  13 + txout.expect(:==, false, [1])
  14 +end
  15 +
7 16 describe Bitcoin::Wallet::Wallet do
8 17  
9 18 class DummyKeyStore
10 19  
11 20 def initialize keys
12   - @keys =keys
  21 + @keys = keys.map{|k|{:key => k}}
13 22 end
14 23  
15 24 def key(addr)
16   - @keys.select{|k|k.addr==addr}.first
  25 + @keys.select{|k|k[:key].addr==addr}.first
17 26 end
18 27  
19 28 def keys
20 29  
21 30  
... ... @@ -21,17 +30,14 @@
21 30 end
22 31  
23 32 def new_key
24   - @keys << Bitcoin::Key.generate
  33 + k=Bitcoin::Key.generate
  34 + @keys << {:key => k}
25 35 @keys[-1]
26 36 end
27 37 end
28 38  
29   - def txout_mock(value, next_in)
30   - txout = Mock.new
31   - txout.expect(:value, value)
32   - txout.expect(:get_next_in, next_in)
33   - end
34 39  
  40 +
35 41 before do
36 42 @storage = Mock.new
37 43 @key = Key.from_base58('5J2hn1E8KEXmQn5gqykzKotyCcHbKrVbe8fjegsfVXRdv6wwon8')
... ... @@ -40,7 +46,12 @@
40 46 @addr2 = '134A4Bi8jN5V2KjkwmXUHjokDqdyqZ778J'
41 47 @key3 = Key.from_base58('5JFcJByQvwYnWjQ2RHTTu6LLGiBj9oPQYsHqKWuKLDVAvv4cQ7E')
42 48 @addr3 = '1EnrPVaRiRgrs1D7pujYZNN1N6iD9unZV6'
43   - @keystore = DummyKeyStore.new([@key])
  49 + keystore_data = [{:addr => @key.addr, :priv => @key.priv, :pub => @key.pub}]
  50 + spec_dir = File.join(File.dirname(__FILE__), '../fixtures/wallet')
  51 + FileUtils.mkdir_p(spec_dir)
  52 + @filename = File.join(spec_dir, 'test1.json')
  53 + File.open(@filename, 'w') {|f| f.write(keystore_data.to_json) }
  54 + @keystore = SimpleKeyStore.new(file: @filename)
44 55 @selector = MiniTest::Mock.new
45 56 @wallet = Wallet.new(@storage, @keystore, @selector)
46 57 end
... ... @@ -82,11 +93,6 @@
82 93 end
83 94  
84 95 describe "Bitcoin::Wallet::Wallet#tx" do
85   - def txout_mock(value, next_in)
86   - txout = Mock.new
87   - txout.expect(:value, value)
88   - txout.expect(:get_next_in, next_in)
89   - end
90 96  
91 97 before do
92 98 txout = txout_mock(5000, nil)
... ... @@ -155,11 +161,6 @@
155 161  
156 162 describe "Bitcoin::Wallet::Wallet#tx (multisig)" do
157 163  
158   - def txout_mock(value, next_in)
159   - txout = Mock.new
160   - txout.expect(:value, value)
161   - txout.expect(:get_next_in, next_in)
162   - end
163 164  
164 165 before do
165 166 txout = txout_mock(5000, nil)