Commit c93ea307898a165f9e9cd44f9d63ada9d05ec124

Authored by Marius Hanne
1 parent a3558c2f76

add test double-spending output from same block

Showing 1 changed file with 14 additions and 3 deletions Side-by-side Diff

spec/bitcoin/storage/validation_spec.rb
... ... @@ -273,12 +273,23 @@
273 273 end
274 274  
275 275  
276   - it "should not allow double spend within a block" do
  276 + it "should not allow double spend within the same block" do
  277 + # double-spend output from previous block
277 278 prev_tx = @block1.tx[0]
278 279 block = create_block @block1.hash, false, [
279   - ->(t) { create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, Bitcoin::Key.generate]], @key) },
280   - ->(t) { create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, Bitcoin::Key.generate]], @key) }
  280 + ->(t) { create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, @key]]) },
  281 + ->(t) { create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, @key]]) }
281 282 ]
  283 + -> { @store.store_block(block) }.should.raise(Bitcoin::Validation::ValidationError)
  284 +
  285 + # double-spend output from current block
  286 + block = create_block @block1.hash, false, [
  287 + ->(t) { create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, @key]]) }
  288 + ]
  289 + prev_tx = block.tx[1]
  290 + block.tx << build_tx {|t| create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, @key]]) }
  291 + block.tx << build_tx {|t| create_tx(t, prev_tx, 0, [[prev_tx.out[0].value, @key]]) }
  292 + block.recalc_mrkl_root; block.recalc_block_hash
282 293 -> { @store.store_block(block) }.should.raise(Bitcoin::Validation::ValidationError)
283 294 end
284 295