spec/bitcoin/storage/reorg_spec.rb in bitcoin-ruby-0.0.3 vs spec/bitcoin/storage/reorg_spec.rb in bitcoin-ruby-0.0.4
- old
+ new
@@ -2,27 +2,34 @@
require_relative '../spec_helper'
include Bitcoin::Builder
+Bitcoin.network = :testnet
+Bitcoin::Validation::Block::RETARGET = 10
-[ { :name => :utxo, :db => 'sqlite:/', :index_all_addrs => true },
- { :name => :sequel, :db => 'sqlite:/' } ] .each do |configuration|
+[
+ [:utxo, :sqlite, index_all_addrs: true],
+ [:sequel, :sqlite], # [:sequel, :postgres],
+ [:utxo, :postgres, index_all_addrs: true],
+ [:sequel, :mysql],
+ [:utxo, :mysql, index_all_addrs: true],
+].compact.each do |options|
- describe "reorg (#{configuration[:name].capitalize}Store)" do
+ next unless storage = setup_db(*options)
+ describe "reorg (#{options[0]} - #{options[1]})" do
+
def balance addr
@store.get_balance(Bitcoin.hash160_from_address(addr))
end
before do
- Bitcoin.network = :testnet
- @store = Bitcoin::Storage.send(configuration[:name], configuration)
+ @store = storage
@store.reset
def @store.in_sync?; true; end
- @store.log.level = :warn
Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("ff"*32)
@key = Bitcoin::Key.generate
@block0 = create_block "00"*32, false, [], @key
Bitcoin.network[:genesis_hash] = @block0.hash
@store.store_block(@block0)
@@ -31,12 +38,10 @@
it "should retarget" do
@store.reset
time = Time.now.to_i - 3000*600
- Bitcoin::Validation::Block::RETARGET = 10
-
# create genesis block
block = create_block "00"*32, false, [], @key, 50e8, {time: time}
Bitcoin.network[:genesis_hash] = block.hash
@store.store_block(block)
time += 600
@@ -185,9 +190,10 @@
@store.get_head.hash.should =~ /00000000195f85184e7/
balance("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa").should == 15000000000
balance("1NiEGXeURREqqMjCvjCeZn6SwEBZ9AdVet").should == 1000000000
balance("1KXFNhNtrRMfgbdiQeuJqnfD7dR4PhniyJ").should == 0
balance("1JyMKvPHkrCQd8jQrqTR1rBsAd1VpRhTiE").should == 14000000000
+ Bitcoin.network = :testnet
class Bitcoin::Validation::Block
def difficulty
return true if Bitcoin.network_name == :testnet3
block.bits == next_bits_required || [block.bits, next_bits_required]
end