Commit 32314aa0a1cc3ecb7069a764e95d1b33f2de2e60

Authored by comboy
1 parent 624abdbcd5
Exists in master and in 1 other branch benchmark

network :no_difficulty option to avoid monkey patching

Showing 8 changed files with 11 additions and 28 deletions Side-by-side Diff

... ... @@ -552,6 +552,7 @@
552 552 :target_spacing => 600, # block interval
553 553 :max_money => 21_000_000 * COIN,
554 554 :min_tx_fee => 10_000,
  555 + :no_difficulty => true,
555 556 :min_relay_tx_fee => 10_000,
556 557 :dns_seeds => [
557 558 "testnet-seed.bitcoin.petertodd.org",
lib/bitcoin/validation.rb
... ... @@ -109,7 +109,7 @@
109 109  
110 110 # check that bits satisfy required difficulty
111 111 def difficulty
112   - return true if Bitcoin.network_name == :testnet3
  112 + return true if Bitcoin.network[:no_difficulty] == true
113 113 block.bits == next_bits_required || [block.bits, next_bits_required]
114 114 end
115 115  
spec/bitcoin/helpers/fake_blockchain.rb
... ... @@ -3,6 +3,7 @@
3 3  
4 4 Bitcoin::NETWORKS[:fake] = {
5 5 :project => :bitcoin,
  6 + :no_difficulty => true,
6 7 :magic_head => "fake",
7 8 :address_version => "00",
8 9 :p2sh_version => "05",
... ... @@ -21,7 +22,6 @@
21 22 :min_relay_tx_fee => 10_000,
22 23 }
23 24  
24   -class Bitcoin::Validation::Block; def difficulty; true; end; end
25 25  
26 26  
27 27 # Small utility to generate fake blocks mostly to be able to test performance
spec/bitcoin/namecoin_spec.rb
... ... @@ -89,7 +89,7 @@
89 89  
90 90 before do
91 91 Bitcoin.network = :namecoin
92   - class Bitcoin::Validation::Block; def difficulty; true; end; end
  92 + Bitcoin.network[:no_difficulty] = true
93 93 class Bitcoin::Validation::Block; def min_timestamp; true; end; end
94 94 Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("ff"*32)
95 95 [:name_new, :name_firstupdate, :name_update].each {|type|
spec/bitcoin/performance/storage_spec.rb
... ... @@ -16,8 +16,6 @@
16 16 @store = storage
17 17 @store.reset
18 18 @store.log.level = :error
19   - class Bitcoin::Validation::Block; def difficulty; true; end; end
20   -
21 19 FakeBlockchain.prepare
22 20 end
23 21  
spec/bitcoin/storage/models_spec.rb
... ... @@ -22,7 +22,7 @@
22 22 describe "Storage::Models (#{options[0].to_s.capitalize}Store, #{options[1]})" do
23 23  
24 24 before do
25   - class Bitcoin::Validation::Block; def difficulty; true; end; end
  25 + Bitcoin.network[:no_difficulty] = true
26 26 Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("ff"*32)
27 27  
28 28 @store = storage
... ... @@ -44,12 +44,7 @@
44 44 end
45 45  
46 46 after do
47   - class Bitcoin::Validation::Block
48   - def difficulty
49   - return true if Bitcoin.network_name == :testnet3
50   - block.bits == next_bits_required || [block.bits, next_bits_required]
51   - end
52   - end
  47 + Bitcoin.network.delete :no_difficulty
53 48 end
54 49  
55 50 describe "Block" do
spec/bitcoin/storage/reorg_spec.rb
... ... @@ -208,9 +208,9 @@
208 208  
209 209 # see https://bitcointalk.org/index.php?topic=46370.0
210 210 it "should pass reorg unit tests" do
211   - # Disable difficulty checks. Hackish, should be replaced with some sane API.**
212   - class Bitcoin::Validation::Block; def difficulty; true; end; end
213 211 Bitcoin.network = :bitcoin
  212 + # Disable difficulty check
  213 + Bitcoin.network[:no_difficulty] = true
214 214 @store.import "./spec/bitcoin/fixtures/reorg/blk_0_to_4.dat"
215 215 @store.get_depth.should == 4
216 216 @store.get_head.hash.should =~ /000000002f264d65040/
217 217  
... ... @@ -228,14 +228,8 @@
228 228 balance("1NiEGXeURREqqMjCvjCeZn6SwEBZ9AdVet").should == 1000000000
229 229 balance("1KXFNhNtrRMfgbdiQeuJqnfD7dR4PhniyJ").should == 0
230 230 balance("1JyMKvPHkrCQd8jQrqTR1rBsAd1VpRhTiE").should == 14000000000
  231 + Bitcoin.network.delete :no_difficulty
231 232 Bitcoin.network = :testnet
232   - # Re-enable difficulty checks. Hackish, should be replaced with some sane API.
233   - class Bitcoin::Validation::Block
234   - def difficulty
235   - return true if Bitcoin.network_name == :testnet3
236   - block.bits == next_bits_required || [block.bits, next_bits_required]
237   - end
238   - end
239 233 end
240 234  
241 235 end
spec/bitcoin/storage/storage_spec.rb
... ... @@ -24,7 +24,7 @@
24 24 describe "Storage::Backends::#{options[0].to_s.capitalize}Store (#{options[1]})" do
25 25  
26 26 before do
27   - class Bitcoin::Validation::Block; def difficulty; true; end; end
  27 + Bitcoin.network[:no_difficulty] = true
28 28 Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("ff"*32)
29 29  
30 30 @store = storage
... ... @@ -46,12 +46,7 @@
46 46 end
47 47  
48 48 after do
49   - class Bitcoin::Validation::Block
50   - def difficulty
51   - return true if Bitcoin.network_name == :testnet3
52   - block.bits == next_bits_required || [block.bits, next_bits_required]
53   - end
54   - end
  49 + Bitcoin.network.delete :no_difficulty
55 50 end
56 51  
57 52 it "should get backend name" do