spec/bitcoin/storage/validation_spec.rb in bitcoin-ruby-0.0.3 vs spec/bitcoin/storage/validation_spec.rb in bitcoin-ruby-0.0.4
- old
+ new
@@ -4,22 +4,31 @@
include Bitcoin::Builder
include Bitcoin::Storage
include Bitcoin::Validation
-[ { :name => :utxo, :db => 'sqlite:/', :index_all_addrs => true },
- { :name => :sequel, :db => 'sqlite:/' } ].each do |configuration|
+Bitcoin.network = :spec
- describe "block rules (#{configuration[:name].capitalize}Store)" do
+[
+ [:sequel, :sqlite],
+ [:utxo, :sqlite, index_all_addrs: true],
+ [:sequel, :postgres],
+ [:utxo, :postgres, index_all_addrs: true],
+ [:sequel, :mysql],
+ [:utxo, :mysql, index_all_addrs: true],
+].compact.each do |options|
+ next unless storage = setup_db(*options)
+
+ describe "block rules (#{options[0]} - #{options[1]})" do
+
def balance addr
@store.get_balance(Bitcoin.hash160_from_address(addr))
end
before do
- Bitcoin.network = :spec
- @store = Bitcoin::Storage.send(configuration[:name], configuration)
+ @store = storage
@store.reset
@store.log.level = :warn
Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("f"*64)
@key = Bitcoin::Key.generate
@block0 = create_block "00"*32, false, [], @key
@@ -145,15 +154,15 @@
Bitcoin::Validation::REWARD_DROP = 210_000
end
end
-describe "transaction rules (#{configuration[:name].capitalize}Store)" do
+describe "transaction rules (#{options[0]} - #{options[1]})" do
before do
Bitcoin.network = :spec
- @store = Bitcoin::Storage.send(configuration[:name], configuration)
+ @store = storage
@store.reset
@store.log.level = :warn
Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("f"*64)
@key = Bitcoin::Key.generate
@@ -245,10 +254,10 @@
check_tx(@tx, [:spent, [0]])
end
end
it "15. Using the referenced output transactions to get input values, check that each input value, as well as the sum, are in legal money range" do
- @store.db[@store.class.name =~ /Utxo/ ? :utxo : :txout].where(id: 2).update(value: 22e14)
+ @store.db[@store.class.name =~ /Utxo/ ? :utxo : :txout].order(:id).reverse.limit(1).update(value: 22e14)
check_tx(@tx, [:input_values, [22e14, 21e14]])
end
it "16. Reject if the sum of input values < sum of output values" do
tx = build_tx {|t| create_tx(t, @block1.tx.first, 0, [[100e8, @key]]) }