From 1f2cebce2db5189fdcfbd1d4c6d6c9defa948832 Mon Sep 17 00:00:00 2001 From: davvd Date: Mon, 15 Jul 2024 15:56:35 +0300 Subject: [PATCH] #835 test_log renamed to fake_log --- Gemfile | 2 +- fixtures/scripts/_head.sh | 2 +- test/commands/routines/test_audit.rb | 4 +- test/commands/routines/test_gc.rb | 12 ++--- test/commands/routines/test_reconcile.rb | 4 +- test/commands/routines/test_reconnect.rb | 2 +- test/commands/routines/test_retire.rb | 2 +- test/commands/test_alias.rb | 12 ++--- test/commands/test_calculate.rb | 2 +- test/commands/test_clean.rb | 16 +++---- test/commands/test_create.rb | 2 +- test/commands/test_diff.rb | 6 +-- test/commands/test_fetch.rb | 14 +++--- test/commands/test_invoice.rb | 2 +- test/commands/test_list.rb | 2 +- test/commands/test_merge.rb | 20 ++++---- test/commands/test_node.rb | 8 ++-- test/commands/test_pay.rb | 34 +++++++------- test/commands/test_propagate.rb | 6 +-- test/commands/test_pull.rb | 8 ++-- test/commands/test_push.rb | 14 +++--- test/commands/test_remote.rb | 18 +++---- test/commands/test_remove.rb | 16 +++---- test/commands/test_show.rb | 2 +- test/commands/test_taxes.rb | 4 +- test/node/fake_node.rb | 19 ++++++-- test/node/test_async_entrance.rb | 16 +++---- test/node/test_entrance.rb | 12 ++--- test/node/test_farm.rb | 20 ++++---- test/node/test_farmers.rb | 8 ++-- test/node/test_front.rb | 52 ++++++++++----------- test/node/test_nodup_entrance.rb | 4 +- test/node/test_nospam_entrance.rb | 2 +- test/node/test_safe_entrance.rb | 4 +- test/node/test_spread_entrance.rb | 12 ++--- test/node/test_sync_entrance.rb | 4 +- test/node/test_trace.rb | 2 +- test/test__helper.rb | 6 +-- test/test_copies.rb | 20 ++++---- test/test_dir_items.rb | 4 +- test/test_http.rb | 12 ++--- test/test_hungry_wallets.rb | 18 +++---- test/test_log.rb | 6 +-- test/test_metronome.rb | 8 ++-- test/test_patch.rb | 24 +++++----- test/test_prefixes.rb | 2 +- test/test_remotes.rb | 14 +++--- test/test_sync_wallets.rb | 2 +- test/test_tax.rb | 14 +++--- test/test_thread_pool.rb | 12 ++--- test/test_wallet.rb | 40 ++++++++-------- test/test_wallets.rb | 6 +-- test/test_zold.rb | 6 +-- test/upgrades/test_delete_banned_wallets.rb | 4 +- test/upgrades/test_protocol_up.rb | 4 +- 55 files changed, 291 insertions(+), 280 deletions(-) diff --git a/Gemfile b/Gemfile index f4ce2b74c..0dc82c558 100755 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'minitest-fail-fast', '0.1.0', require: false gem 'minitest-hooks', '1.5.1', require: false gem 'minitest-reporters', '1.6.1', require: false gem 'rake', '13.1.0', require: false -gem 'random-port', '0.6.0', require: false +gem 'random-port', '~>0', require: false gem 'rdoc', '6.6.0', require: false gem 'rspec-rails', '6.1.0', require: false gem 'rubocop', '1.57.2', require: false diff --git a/fixtures/scripts/_head.sh b/fixtures/scripts/_head.sh index aa426669c..f85127db6 100644 --- a/fixtures/scripts/_head.sh +++ b/fixtures/scripts/_head.sh @@ -8,7 +8,7 @@ export RUBYOPT="-W0" alias zold="$1 --ignore-this-stupid-option --halt-code=test --ignore-global-config --trace --network=test --no-colors --dump-errors" function reserve_port { - python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()' + python -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1]); s.close()' } function wait_for_url { diff --git a/test/commands/routines/test_audit.rb b/test/commands/routines/test_audit.rb index f693711f8..4f82ec053 100644 --- a/test/commands/routines/test_audit.rb +++ b/test/commands/routines/test_audit.rb @@ -32,9 +32,9 @@ # License:: MIT class TestAudit < Zold::Test def test_audits - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| opts = { 'routine-immediately' => true } - routine = Zold::Routines::Audit.new(opts, home.wallets, log: test_log) + routine = Zold::Routines::Audit.new(opts, home.wallets, log: fake_log) routine.exec end end diff --git a/test/commands/routines/test_gc.rb b/test/commands/routines/test_gc.rb index 0ef4553b5..2b73243b4 100644 --- a/test/commands/routines/test_gc.rb +++ b/test/commands/routines/test_gc.rb @@ -32,37 +32,37 @@ # License:: MIT class TestGc < Zold::Test def test_collects_garbage - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets home.create_wallet opts = { 'routine-immediately' => true, 'gc-age' => 0 } assert_equal(1, wallets.count) - routine = Zold::Routines::Gc.new(opts, wallets, log: test_log) + routine = Zold::Routines::Gc.new(opts, wallets, log: fake_log) routine.exec assert_equal(0, wallets.count) end end def test_doesnt_touch_non_empty_wallets - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key) opts = { 'routine-immediately' => true, 'gc-age' => 0 } - routine = Zold::Routines::Gc.new(opts, wallets, log: test_log) + routine = Zold::Routines::Gc.new(opts, wallets, log: fake_log) routine.exec assert_equal(1, wallets.count) end end def test_doesnt_touch_fresh_wallets - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets home.create_wallet opts = { 'routine-immediately' => true, 'gc-age' => 60 * 60 } - routine = Zold::Routines::Gc.new(opts, wallets, log: test_log) + routine = Zold::Routines::Gc.new(opts, wallets, log: fake_log) routine.exec assert_equal(1, wallets.count) end diff --git a/test/commands/routines/test_reconcile.rb b/test/commands/routines/test_reconcile.rb index 535bd002a..cdff5c527 100644 --- a/test/commands/routines/test_reconcile.rb +++ b/test/commands/routines/test_reconcile.rb @@ -33,7 +33,7 @@ # License:: MIT class TestReconcile < Zold::Test def test_reconciles - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| remotes = home.remotes remotes.clean remotes.masters @@ -43,7 +43,7 @@ def test_reconciles stub_request(:get, "http://#{m[:host]}:#{m[:port]}/wallet/#{Zold::Id::ROOT}").to_return(status: 404) opts = { 'never-reboot' => true, 'routine-immediately' => true } routine = Zold::Routines::Reconcile.new( - opts, home.wallets, remotes, home.copies.root, 'some-fake-host:2096', log: test_log + opts, home.wallets, remotes, home.copies.root, 'some-fake-host:2096', log: fake_log ) routine.exec end diff --git a/test/commands/routines/test_reconnect.rb b/test/commands/routines/test_reconnect.rb index 9b2ed3f35..8345aad4e 100755 --- a/test/commands/routines/test_reconnect.rb +++ b/test/commands/routines/test_reconnect.rb @@ -39,7 +39,7 @@ def test_reconnects remotes.add('localhost', 4096) stub_request(:get, 'http://localhost:4096/remotes').to_return(status: 404) opts = { 'never-reboot' => true, 'routine-immediately' => true } - routine = Zold::Routines::Reconnect.new(opts, remotes, log: test_log) + routine = Zold::Routines::Reconnect.new(opts, remotes, log: fake_log) routine.exec end end diff --git a/test/commands/routines/test_retire.rb b/test/commands/routines/test_retire.rb index 97372507b..776d1e895 100644 --- a/test/commands/routines/test_retire.rb +++ b/test/commands/routines/test_retire.rb @@ -34,7 +34,7 @@ class TestRetire < Zold::Test def test_retires opts = { 'never-reboot' => false, 'routine-immediately' => true } - routine = Zold::Routines::Retire.new(opts, log: test_log) + routine = Zold::Routines::Retire.new(opts, log: fake_log) routine.exec(10 * 24 * 60) end end diff --git a/test/commands/test_alias.rb b/test/commands/test_alias.rb index 60a5af83a..000b0fbec 100644 --- a/test/commands/test_alias.rb +++ b/test/commands/test_alias.rb @@ -11,9 +11,9 @@ class TestAlias < Zold::Test # The syntax is already documented in the alias command in the help. def test_set_writes_alias_to_the_alias_file skip - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet - Zold::Alias.new(wallets: home.wallets, log: test_log).run(%W[set #{wallet.id} my-alias]) + Zold::Alias.new(wallets: home.wallets, log: fake_log).run(%W[set #{wallet.id} my-alias]) assert_equal read_alias_file(home), %W[my-alias #{wallet.id}] end end @@ -23,9 +23,9 @@ def test_set_writes_alias_to_the_alias_file # The syntax is already documented in the alias command in the help. def test_remove_removes_the_alias_from_the_alias_file skip - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet - cmd = Zold::Alias.new(wallets: home.wallets, log: test_log) + cmd = Zold::Alias.new(wallets: home.wallets, log: fake_log) cmd.run(%W[set #{wallet.id} my-alias]) assert_equal read_alias_file(home), %W[my-alias #{wallet.id}] cmd.run(%w[remove my-alias]) @@ -38,9 +38,9 @@ def test_remove_removes_the_alias_from_the_alias_file # The syntax is already documented in the alias command in the help. def test_show_prints_out_the_aliased_wallet_id skip - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet - cmd = Zold::Alias.new(wallets: home.wallets, log: test_log) + cmd = Zold::Alias.new(wallets: home.wallets, log: fake_log) cmd.run(%W[set #{wallet.id} my-alias]) assert_equal read_alias_file(home), %W[my-alias #{wallet.id}] stdout, = capture_io { cmd.run(%w[show my-alias]) } diff --git a/test/commands/test_calculate.rb b/test/commands/test_calculate.rb index b074a3cab..188859305 100644 --- a/test/commands/test_calculate.rb +++ b/test/commands/test_calculate.rb @@ -31,7 +31,7 @@ # License:: MIT class TestCalculate < Zold::Test def test_calculates_score - score = Zold::Calculate.new(log: test_log).run( + score = Zold::Calculate.new(log: fake_log).run( ['score', '--strength=2', '--max=8', '--invoice=NOSUFFIX@ffffffffffffffff'] ) assert(score.valid?) diff --git a/test/commands/test_clean.rb b/test/commands/test_clean.rb index a627ba7d3..0d5e1561e 100644 --- a/test/commands/test_clean.rb +++ b/test/commands/test_clean.rb @@ -34,38 +34,38 @@ # License:: MIT class TestClean < Zold::Test def test_cleans_copies - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet copies = home.copies(wallet) copies.add('a1', 'host-1', 80, 1, time: Time.now - (26 * 60 * 60)) copies.add('a2', 'host-2', 80, 2, time: Time.now - (26 * 60 * 60)) - Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean', wallet.id.to_s]) + Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(['clean', wallet.id.to_s]) assert(copies.all.empty?) end end def test_clean_no_copies - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet copies = home.copies(wallet) - Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean']) + Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(['clean']) assert(copies.all.empty?) end end def test_cleans_empty_wallets - FakeHome.new(log: test_log).run do |home| - Zold::Clean.new(wallets: home.wallets, copies: File.join(home.dir, 'c'), log: test_log).run(['clean']) + FakeHome.new(log: fake_log).run do |home| + Zold::Clean.new(wallets: home.wallets, copies: File.join(home.dir, 'c'), log: fake_log).run(['clean']) end end def test_cleans_copies_in_threads - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet copies = home.copies(wallet) copies.add(File.read(wallet.path), 'host-2', 80, 2, time: Time.now) Threads.new(20).assert do - Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean']) + Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(['clean']) end assert_equal(1, copies.all.count) end diff --git a/test/commands/test_create.rb b/test/commands/test_create.rb index fca92680c..eba02fe79 100644 --- a/test/commands/test_create.rb +++ b/test/commands/test_create.rb @@ -35,7 +35,7 @@ class TestCreate < Zold::Test def test_creates_wallet Dir.mktmpdir do |dir| wallets = Zold::Wallets.new(dir) - id = Zold::Create.new(wallets: wallets, remotes: nil, log: test_log).run( + id = Zold::Create.new(wallets: wallets, remotes: nil, log: fake_log).run( ['create', '--public-key=fixtures/id_rsa.pub', '--skip-test'] ) wallets.acq(id) do |wallet| diff --git a/test/commands/test_diff.rb b/test/commands/test_diff.rb index 41493731c..50364c9f1 100644 --- a/test/commands/test_diff.rb +++ b/test/commands/test_diff.rb @@ -40,19 +40,19 @@ # License:: MIT class TestDiff < Zold::Test def test_diff_with_copies - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet first = home.create_wallet File.write(first.path, File.read(wallet.path)) second = home.create_wallet File.write(second.path, File.read(wallet.path)) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( ['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa'] ) copies = home.copies(wallet) copies.add(File.read(first.path), 'host-1', 80, 5) copies.add(File.read(second.path), 'host-2', 80, 5) - diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: test_log).run( + diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: fake_log).run( ['diff', wallet.id.to_s] ) assert(diff.include?('-0001;'), diff) diff --git a/test/commands/test_fetch.rb b/test/commands/test_fetch.rb index 43fb533ff..ee1a58d31 100755 --- a/test/commands/test_fetch.rb +++ b/test/commands/test_fetch.rb @@ -42,7 +42,7 @@ # License:: MIT class TestFetch < Zold::Test def test_fetches_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return( status: 200, @@ -59,7 +59,7 @@ def test_fetches_wallet remotes.add('localhost', 4096) remotes.add('localhost', 81) copies = home.copies(wallet) - Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: test_log).run( + Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: fake_log).run( ['fetch', '--tolerate-edges', '--tolerate-quorum=1', '--ignore-score-weakness', wallet.id.to_s] ) assert_equal(1, copies.all.count) @@ -69,7 +69,7 @@ def test_fetches_wallet end def test_fetches_multiple_wallets - log = TestLogger.new(test_log) + log = TestLogger.new(fake_log) FakeHome.new(log: log).run do |home| wallet_a = home.create_wallet stub_request(:get, "http://localhost:4096/wallet/#{wallet_a.id}").to_return( @@ -113,7 +113,7 @@ def test_fetches_multiple_wallets end def test_fails_when_only_edge_nodes - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return( status: 200, @@ -129,7 +129,7 @@ def test_fails_when_only_edge_nodes remotes.add('localhost', 4096) copies = home.copies(wallet) assert_raises Zold::Fetch::EdgesOnly do - Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: test_log).run( + Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: fake_log).run( ['fetch', '--ignore-score-weakness', wallet.id.to_s] ) end @@ -137,7 +137,7 @@ def test_fails_when_only_edge_nodes end def test_fails_when_only_one_node - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return( status: 200, @@ -153,7 +153,7 @@ def test_fails_when_only_one_node remotes.add('localhost', 4096) copies = home.copies(wallet) assert_raises Zold::Fetch::NoQuorum do - Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: test_log).run( + Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: fake_log).run( ['fetch', '--tolerate-edges', '--ignore-score-weakness', wallet.id.to_s] ) end diff --git a/test/commands/test_invoice.rb b/test/commands/test_invoice.rb index dc49c8a1a..41f81c892 100644 --- a/test/commands/test_invoice.rb +++ b/test/commands/test_invoice.rb @@ -40,7 +40,7 @@ def test_generates_invoice wallets = Zold::Wallets.new(dir) wallets.acq(id) do |source| source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub')) - invoice = Zold::Invoice.new(wallets: wallets, remotes: nil, copies: nil, log: test_log).run( + invoice = Zold::Invoice.new(wallets: wallets, remotes: nil, copies: nil, log: fake_log).run( ['invoice', id.to_s, '--length=16'] ) assert_equal(33, invoice.length) diff --git a/test/commands/test_list.rb b/test/commands/test_list.rb index 56adda304..6c84c0930 100644 --- a/test/commands/test_list.rb +++ b/test/commands/test_list.rb @@ -40,7 +40,7 @@ def test_lists_wallets_with_balances wallets = Zold::Wallets.new(dir) wallets.acq(id) do |wallet| wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub')) - Zold::List.new(wallets: wallets, copies: File.join(dir, 'copies'), log: test_log).run + Zold::List.new(wallets: wallets, copies: File.join(dir, 'copies'), log: fake_log).run end end end diff --git a/test/commands/test_merge.rb b/test/commands/test_merge.rb index 93a6ef629..e83186dc7 100644 --- a/test/commands/test_merge.rb +++ b/test/commands/test_merge.rb @@ -43,19 +43,19 @@ # License:: MIT class TestMerge < Zold::Test def test_merges_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet first = home.create_wallet File.write(first.path, File.read(wallet.path)) second = home.create_wallet File.write(second.path, File.read(wallet.path)) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( ['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa'] ) copies = home.copies(wallet) copies.add(File.read(first.path), 'host-1', 80, 5) copies.add(File.read(second.path), 'host-2', 80, 5) - modified = Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: test_log).run( + modified = Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run( ['merge', wallet.id.to_s] ) assert(1, modified.count) @@ -64,12 +64,12 @@ def test_merges_wallet end def test_merges_with_a_broken_copy - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet copies = home.copies(wallet) copies.add(File.read(wallet.path), 'good-host', 80, 5) copies.add('some garbage', 'bad-host', 80, 5) - modified = Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: test_log).run( + modified = Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run( ['merge', wallet.id.to_s] ) assert(modified.empty?) @@ -77,13 +77,13 @@ def test_merges_with_a_broken_copy end def test_merges_a_copy_on_top - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet(Zold::Id::ROOT) copies = home.copies(wallet) copies.add(File.read(wallet.path), 'good-host', 80, 5) key = Zold::Key.new(file: 'fixtures/id_rsa') wallet.sub(Zold::Amount.new(zld: 9.99), "NOPREFIX@#{Zold::Id.new}", key) - Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: test_log).run( + Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run( ['merge', wallet.id.to_s] ) assert(!wallet.balance.zero?) @@ -91,14 +91,14 @@ def test_merges_a_copy_on_top end def test_rejects_fake_positives_in_new_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| main = home.create_wallet remote = home.create_wallet File.write(remote.path, File.read(main.path)) remote.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake')) copies = home.copies(main) copies.add(File.read(remote.path), 'fake-host', 80, 0) - Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: test_log).run( + Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run( ['merge', main.id.to_s, '--no-baseline'] ) assert_equal(Zold::Amount::ZERO, main.balance) @@ -117,7 +117,7 @@ def test_rejects_fake_positives_in_new_wallet wallets = Zold::Wallets.new(dir) copies = File.join(dir, 'copies') remotes = Zold::Remotes.new(file: File.join(dir, 'remotes')) - Zold::Merge.new(wallets: wallets, remotes: remotes, copies: copies, log: test_log).run( + Zold::Merge.new(wallets: wallets, remotes: remotes, copies: copies, log: fake_log).run( %w[merge 0123456789abcdef] + File.read(File.join(dir, 'opts')).split("\n") ) Dir.chdir(dir) do diff --git a/test/commands/test_node.rb b/test/commands/test_node.rb index 2eccfe86b..89a3bab0f 100755 --- a/test/commands/test_node.rb +++ b/test/commands/test_node.rb @@ -40,13 +40,13 @@ # License:: MIT class TestNode < Zold::Test def test_push_and_fetch - FakeHome.new(log: test_log).run do |home| - FakeNode.new(log: test_log).run do |port| + FakeHome.new(log: fake_log).run do |home| + FakeNode.new(log: fake_log).run do |port| wallets = home.wallets wallet = home.create_wallet remotes = home.remotes remotes.add('localhost', port) - Zold::Push.new(wallets: wallets, remotes: remotes, log: test_log).run( + Zold::Push.new(wallets: wallets, remotes: remotes, log: fake_log).run( ['push', '--ignore-score-weakness', '--tolerate-edges', '--tolerate-quorum=1'] ) copies = home.copies(wallet) @@ -54,7 +54,7 @@ def test_push_and_fetch retries ||= 0 Zold::Fetch.new( wallets: wallets, copies: copies.root, - remotes: remotes, log: test_log + remotes: remotes, log: fake_log ).run(['fetch', '--ignore-score-weakness', '--tolerate-edges', '--tolerate-quorum=1']) rescue StandardError => _e sleep 1 diff --git a/test/commands/test_pay.rb b/test/commands/test_pay.rb index 393002478..deebb6570 100644 --- a/test/commands/test_pay.rb +++ b/test/commands/test_pay.rb @@ -39,18 +39,18 @@ # License:: MIT class TestPay < Zold::Test def test_sends_from_wallet_to_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| source = home.create_wallet target = home.create_wallet amount = Zold::Amount.new(zld: 14.95) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--force', '--private-key=fixtures/id_rsa', source.id.to_s, target.id.to_s, amount.to_zld, 'For the car' ] ) assert_equal(amount * -1, source.balance) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--private-key=fixtures/id_rsa', target.id.to_s, source.id.to_s, amount.to_zld, 'Refund' @@ -62,7 +62,7 @@ def test_sends_from_wallet_to_wallet end def test_pay_without_invoice - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| remotes = home.remotes remotes.add('localhost', 4096) json = home.create_wallet_json @@ -73,7 +73,7 @@ def test_pay_without_invoice home.wallets.acq(Zold::Id.new(id)) { |w| File.delete(w.path) } source = home.create_wallet amount = Zold::Amount.new(zld: 14.95) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: remotes, log: fake_log).run( [ 'pay', '--force', '--private-key=fixtures/id_rsa', '--tolerate-edges', '--tolerate-quorum=1', source.id.to_s, id, amount.to_zld, 'For the car' @@ -84,14 +84,14 @@ def test_pay_without_invoice end def test_pay_with_keygap - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 2.0) Tempfile.open do |f| pem = File.read('fixtures/id_rsa') keygap = pem[100..120] File.write(f, pem.gsub(keygap, '*' * keygap.length)) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--force', "--private-key=#{Shellwords.escape(f.path)}", "--keygap=#{Shellwords.escape(keygap)}", @@ -104,12 +104,12 @@ def test_pay_with_keygap end def test_pay_in_many_threads - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 2.0) wallets = home.wallets Threads.new(10).assert do - Zold::Pay.new(wallets: wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--force', '--private-key=fixtures/id_rsa', wallet.id.to_s, 'NOPREFIX@dddd0000dddd0000', amount.to_zld, '-' @@ -121,11 +121,11 @@ def test_pay_in_many_threads end def test_sends_from_root_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| source = home.create_wallet(Zold::Id::ROOT) target = home.create_wallet amount = Zold::Amount.new(zld: 14.95) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--private-key=fixtures/id_rsa', source.id.to_s, target.id.to_s, amount.to_zld, 'For the car' @@ -136,7 +136,7 @@ def test_sends_from_root_wallet end def test_sends_from_normal_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| source = home.create_wallet target = home.create_wallet amount = Zold::Amount.new(zld: 14.95) @@ -146,7 +146,7 @@ def test_sends_from_normal_wallet 'NOPREFIX', Zold::Id.new, '-' ) ) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--private-key=fixtures/id_rsa', source.id.to_s, target.id.to_s, amount.to_zld, 'here is the refund' @@ -157,11 +157,11 @@ def test_sends_from_normal_wallet end def test_notifies_about_tax_status - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| source = home.create_wallet target = home.create_wallet amount = Zold::Amount.new(zld: 14.95) - accumulating_log = test_log.dup + accumulating_log = fake_log.dup class << accumulating_log attr_accessor :info_messages @@ -182,7 +182,7 @@ def info(message) end def test_pays_and_taxes - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet fund = Zold::Amount.new(zld: 19.99) 10.times do |i| @@ -207,7 +207,7 @@ def test_pays_and_taxes ) before = wallet.balance target = home.create_wallet - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: remotes, log: fake_log).run( [ 'pay', '--force', '--private-key=fixtures/id_rsa', '--ignore-score-weakness', diff --git a/test/commands/test_propagate.rb b/test/commands/test_propagate.rb index 8a06f0b8e..16478d912 100644 --- a/test/commands/test_propagate.rb +++ b/test/commands/test_propagate.rb @@ -33,14 +33,14 @@ # License:: MIT class TestPropagate < Zold::Test def test_propagates_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet friend = home.create_wallet amount = Zold::Amount.new(zld: 14.95) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( ['pay', wallet.id.to_s, friend.id.to_s, amount.to_zld, '--force', '--private-key=fixtures/id_rsa'] ) - Zold::Propagate.new(wallets: home.wallets, log: test_log).run( + Zold::Propagate.new(wallets: home.wallets, log: fake_log).run( ['merge', wallet.id.to_s] ) assert(amount, friend.balance) diff --git a/test/commands/test_pull.rb b/test/commands/test_pull.rb index 5d0bbb222..ac24750aa 100755 --- a/test/commands/test_pull.rb +++ b/test/commands/test_pull.rb @@ -34,7 +34,7 @@ # License:: MIT class TestPull < Zold::Test def test_pull_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| remotes = home.remotes remotes.add('localhost', 4096) json = home.create_wallet_json @@ -42,7 +42,7 @@ def test_pull_wallet id = hash['id'] stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 200, body: json) stub_request(:get, "http://localhost:4096/wallet/#{id}.bin").to_return(status: 200, body: hash['body']) - Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: test_log).run( + Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: fake_log).run( ['--ignore-this-stupid-option', 'pull', id.to_s, '--tolerate-edges', '--tolerate-quorum=1'] ) home.wallets.acq(Zold::Id.new(id)) do |wallet| @@ -52,7 +52,7 @@ def test_pull_wallet end def test_fails_when_only_edge_nodes - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| remotes = home.remotes remotes.add('localhost', 4096) json = home.create_wallet_json @@ -61,7 +61,7 @@ def test_fails_when_only_edge_nodes stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 200, body: json) stub_request(:get, "http://localhost:4096/wallet/#{id}.bin").to_return(status: 200, body: hash['body']) assert_raises Zold::Fetch::EdgesOnly do - Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: test_log).run( + Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: fake_log).run( ['--ignore-this-stupid-option', 'pull', id.to_s] ) end diff --git a/test/commands/test_push.rb b/test/commands/test_push.rb index 8c987f5f4..2f907b023 100755 --- a/test/commands/test_push.rb +++ b/test/commands/test_push.rb @@ -37,19 +37,19 @@ # License:: MIT class TestPush < Zold::Test def test_pushes_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet remotes = home.remotes remotes.add('localhost', 80) stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304) - Zold::Push.new(wallets: home.wallets, remotes: remotes, log: test_log).run( + Zold::Push.new(wallets: home.wallets, remotes: remotes, log: fake_log).run( ['--ignore-this-stupid-option', 'push', wallet.id.to_s, '--tolerate-edges', '--tolerate-quorum=1'] ) end end def test_pushes_multiple_wallets - log = TestLogger.new(test_log) + log = TestLogger.new(fake_log) FakeHome.new(log: log).run do |home| wallet_a = home.create_wallet wallet_b = home.create_wallet @@ -64,13 +64,13 @@ def test_pushes_multiple_wallets end def test_fails_when_only_edge_nodes - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet remotes = home.remotes remotes.add('localhost', 80) stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304) assert_raises Zold::Push::EdgesOnly do - Zold::Push.new(wallets: home.wallets, remotes: remotes, log: test_log).run( + Zold::Push.new(wallets: home.wallets, remotes: remotes, log: fake_log).run( ['push', wallet.id.to_s] ) end @@ -78,13 +78,13 @@ def test_fails_when_only_edge_nodes end def test_fails_when_only_one_node - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet remotes = home.remotes remotes.add('localhost', 80) stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304) assert_raises Zold::Push::NoQuorum do - Zold::Push.new(wallets: home.wallets, remotes: remotes, log: test_log).run( + Zold::Push.new(wallets: home.wallets, remotes: remotes, log: fake_log).run( ['push', wallet.id.to_s, '--tolerate-edges'] ) end diff --git a/test/commands/test_remote.rb b/test/commands/test_remote.rb index 45712a406..9510cd677 100755 --- a/test/commands/test_remote.rb +++ b/test/commands/test_remote.rb @@ -67,7 +67,7 @@ def test_updates_remote headers: {}, body: '{"version": "0.0.0"}' ) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) cmd.run(%w[remote clean]) assert(remotes.all.empty?) cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping']) @@ -126,7 +126,7 @@ def test_elects_a_remote score: zero.to_h }.to_json ) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) winners = cmd.run(%w[remote elect --ignore-score-value]) assert_equal(1, winners.count) end @@ -135,7 +135,7 @@ def test_elects_a_remote def test_resets_remotes Dir.mktmpdir do |dir| remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt')) - Zold::Remote.new(remotes: remotes, log: test_log).run(%w[remote reset]) + Zold::Remote.new(remotes: remotes, log: fake_log).run(%w[remote reset]) end end @@ -164,7 +164,7 @@ def test_remote_trim_with_tolerate body: '{"version": "0.0.0"}' ) stub_request(:get, 'http://localhost:8883/remotes').to_return(status: 404) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) cmd.run(%w[remote clean]) assert(remotes.all.empty?) cmd.run(['remote', 'add', score.host, score.port.to_s, '--skip-ping']) @@ -179,7 +179,7 @@ def test_remote_trim_with_tolerate def test_select_selects_the_strongest_nodes Dir.mktmpdir do |dir| remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt')) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) (1..11).each do |i| cmd.run(%W[remote add localhost #{i} --skip-ping]) remotes.rescore('localhost', i, i) @@ -197,7 +197,7 @@ def test_select_respects_max_nodes_option remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt')) remotes.masters zero = Zold::Score::ZERO - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) (5000..5010).each do |port| stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return( status: 200, @@ -226,7 +226,7 @@ def test_select_respects_max_nodes_option def test_sets_masters Dir.mktmpdir do |dir| remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt')) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) cmd.run(%w[remote masters]) assert(!remotes.all.empty?) end @@ -235,7 +235,7 @@ def test_sets_masters def test_select_doesnt_touch_masters Dir.mktmpdir do |dir| remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt')) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) cmd.run(%w[remote masters]) cmd.run(%w[remote select --max-nodes=0]) assert(!remotes.all.empty?) @@ -255,7 +255,7 @@ def test_updates_just_once all: [] }.to_json ) - cmd = Zold::Remote.new(remotes: remotes, log: test_log) + cmd = Zold::Remote.new(remotes: remotes, log: fake_log) cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping']) cmd.run(['remote', 'update', '--ignore-score-weakness', '--depth=10']) assert_equal(1, remotes.all.count) diff --git a/test/commands/test_remove.rb b/test/commands/test_remove.rb index 22a3b9f77..0db75bee9 100644 --- a/test/commands/test_remove.rb +++ b/test/commands/test_remove.rb @@ -31,33 +31,33 @@ # License:: MIT class TestRemove < Zold::Test def test_removes_one_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet assert_equal(1, home.wallets.all.count) - Zold::Remove.new(wallets: home.wallets, log: test_log).run(['remove', wallet.id.to_s]) + Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove', wallet.id.to_s]) assert(home.wallets.all.empty?) end end def test_removes_wallets - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| home.create_wallet home.create_wallet - Zold::Remove.new(wallets: home.wallets, log: test_log).run(['remove']) + Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove']) assert(home.wallets.all.empty?) end end def test_removes_no_wallets - FakeHome.new(log: test_log).run do |home| - Zold::Remove.new(wallets: home.wallets, log: test_log).run(['remove']) + FakeHome.new(log: fake_log).run do |home| + Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove']) assert(home.wallets.all.empty?) end end def test_removes_absent_wallets - FakeHome.new(log: test_log).run do |home| - Zold::Remove.new(wallets: home.wallets, log: test_log).run( + FakeHome.new(log: fake_log).run do |home| + Zold::Remove.new(wallets: home.wallets, log: fake_log).run( ['remove', '7654321076543210', '--force'] ) assert(home.wallets.all.empty?) diff --git a/test/commands/test_show.rb b/test/commands/test_show.rb index 22b3bc5ca..521c4ec5b 100644 --- a/test/commands/test_show.rb +++ b/test/commands/test_show.rb @@ -40,7 +40,7 @@ def test_checks_wallet_balance wallets = Zold::Wallets.new(dir) wallets.acq(id) do |wallet| wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub')) - balance = Zold::Show.new(wallets: wallets, copies: File.join(dir, 'c'), log: test_log).run(['show', id.to_s]) + balance = Zold::Show.new(wallets: wallets, copies: File.join(dir, 'c'), log: fake_log).run(['show', id.to_s]) assert_equal(Zold::Amount::ZERO, balance) end end diff --git a/test/commands/test_taxes.rb b/test/commands/test_taxes.rb index 6198d6386..16ff7e2e7 100644 --- a/test/commands/test_taxes.rb +++ b/test/commands/test_taxes.rb @@ -38,7 +38,7 @@ # License:: MIT class TestTaxes < Zold::Test def test_pays_taxes - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets wallet = home.create_wallet fund = Zold::Amount.new(zld: 19.99) @@ -65,7 +65,7 @@ def test_pays_taxes before = wallet.balance tax = Zold::Tax.new(wallet, ignore_score_weakness: true) debt = tax.debt - Zold::Taxes.new(wallets: wallets, remotes: remotes, log: test_log).run( + Zold::Taxes.new(wallets: wallets, remotes: remotes, log: fake_log).run( ['taxes', '--private-key=fixtures/id_rsa', '--ignore-score-weakness', 'pay', wallet.id.to_s] ) wallet.flush diff --git a/test/node/fake_node.rb b/test/node/fake_node.rb index fd6244f6f..ad6c474dd 100755 --- a/test/node/fake_node.rb +++ b/test/node/fake_node.rb @@ -44,7 +44,7 @@ def run(args = ['--standalone', '--no-metronome']) RandomPort::Pool::SINGLETON.acquire do |port| node = Thread.new do Thread.current.name = 'fake_node' - Thread.current.abort_on_exception = true + Thread.current.abort_on_exception = false Zold::VerboseThread.new(@log).run do require_relative '../../lib/zold/commands/node' Zold::Node.new(wallets: home.wallets, remotes: home.remotes, copies: home.copies.root, log: @log).run( @@ -68,11 +68,21 @@ def run(args = ['--standalone', '--no-metronome']) attempt = 0 loop do ping = Zold::Http.new(uri: uri).get - break unless ping.status == 599 && node.alive? - @log.info("Waiting for #{uri} (attempt no.#{attempt}): ##{ping.status}...") + unless ping.status == 599 && node.alive? + @log.debug("The URL #{uri} is probably alive, after #{attempt} attempts") + break + end + unless node.alive? + @log.debug("The URL #{uri} is dead, after #{attempt} attempts") + break + end + @log.debug("Waiting for #{uri} (attempt no.#{attempt}): ##{ping.status}...") sleep 0.5 attempt += 1 - break if attempt > 10 + if attempt > 10 + @log.error("Waiting for too long for #{uri} (#{attempt} attempts)") + break + end end raise "The node is dead at #{uri}" unless node.alive? begin @@ -82,6 +92,7 @@ def run(args = ['--standalone', '--no-metronome']) node.join sleep 0.1 # stupid sleep to make sure all threads are terminated end + @log.debug("Thread with fake node stopped: #{node.alive?}") end end end diff --git a/test/node/test_async_entrance.rb b/test/node/test_async_entrance.rb index f990857aa..9dc6439a8 100644 --- a/test/node/test_async_entrance.rb +++ b/test/node/test_async_entrance.rb @@ -34,21 +34,21 @@ # License:: MIT class TestAsyncEntrance < Zold::Test def test_renders_json - FakeHome.new(log: test_log).run do |home| - Zold::AsyncEntrance.new(FakeEntrance.new, home.dir, log: test_log).start do |e| + FakeHome.new(log: fake_log).run do |home| + Zold::AsyncEntrance.new(FakeEntrance.new, home.dir, log: fake_log).start do |e| assert_equal(0, e.to_json[:queue]) end end end def test_sends_through_once - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key) basic = CountingEntrance.new - Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e| + Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: fake_log).start do |e| e.push(wallet.id, File.read(wallet.path)) assert_equal_wait(1) { basic.count } end @@ -56,9 +56,9 @@ def test_sends_through_once end def test_sends_through - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| basic = CountingEntrance.new - Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log, queue_limit: 1000).start do |e| + Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: fake_log, queue_limit: 1000).start do |e| Threads.new(20).assert do wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) @@ -72,11 +72,11 @@ def test_sends_through end def test_handles_broken_entrance_gracefully - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet id = wallet.id body = File.read(wallet.path) - Zold::AsyncEntrance.new(BrokenEntrance.new, home.dir, log: test_log).start do |e| + Zold::AsyncEntrance.new(BrokenEntrance.new, home.dir, log: fake_log).start do |e| e.push(id, body) end end diff --git a/test/node/test_entrance.rb b/test/node/test_entrance.rb index b236d9cbd..0b403dd2e 100755 --- a/test/node/test_entrance.rb +++ b/test/node/test_entrance.rb @@ -40,10 +40,10 @@ class TestEntrance < Zold::Test def test_pushes_wallet sid = Zold::Id::ROOT tid = Zold::Id.new - body = FakeHome.new(log: test_log).run do |home| + body = FakeHome.new(log: fake_log).run do |home| source = home.create_wallet(sid) target = home.create_wallet(tid) - Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run( + Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run( [ 'pay', '--force', '--private-key=fixtures/id_rsa', source.id.to_s, target.id.to_s, '19.99', 'testing' @@ -51,14 +51,14 @@ def test_pushes_wallet ) File.read(source.path) end - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| source = home.create_wallet(sid) target = home.create_wallet(tid) ledger = File.join(home.dir, 'ledger.csv') e = Zold::Entrance.new( home.wallets, Zold::Pipeline.new(home.remotes, home.copies(source).root, 'x', ledger: ledger), - log: test_log + log: fake_log ) modified = e.push(source.id, body) assert_equal(2, modified.count) @@ -71,9 +71,9 @@ def test_pushes_wallet end def test_renders_json - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet - e = Zold::Entrance.new(home.wallets, Zold::Pipeline.new(home.remotes, home.copies.root, 'x'), log: test_log) + e = Zold::Entrance.new(home.wallets, Zold::Pipeline.new(home.remotes, home.copies.root, 'x'), log: fake_log) e.push(wallet.id, File.read(wallet.path)) assert(e.to_json[:history].include?(wallet.id.to_s)) assert(!e.to_json[:speed].negative?) diff --git a/test/node/test_farm.rb b/test/node/test_farm.rb index 93fe98dac..797294c37 100644 --- a/test/node/test_farm.rb +++ b/test/node/test_farm.rb @@ -30,7 +30,7 @@ class FarmTest < Zold::Test def test_renders_in_json Dir.mktmpdir do |dir| - farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 2) + farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: fake_log, strength: 2) farm.start('localhost', 80, threads: 2) do assert_wait { !farm.best.empty? && !farm.best[0].value.zero? } count = 0 @@ -42,7 +42,7 @@ def test_renders_in_json def test_renders_in_text Dir.mktmpdir do |dir| - farm = Zold::Farm.new('NOPREFIX7@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 1) + farm = Zold::Farm.new('NOPREFIX7@ffffffffffffffff', File.join(dir, 'f'), log: fake_log, strength: 1) farm.start('localhost', 80, threads: 2) do assert(!farm.to_text.nil?) end @@ -52,7 +52,7 @@ def test_renders_in_text def test_makes_many_scores Dir.mktmpdir do |dir| farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), - log: test_log, lifetime: 10, farmer: Zold::Farmers::Plain.new, strength: 1) + log: fake_log, lifetime: 10, farmer: Zold::Farmers::Plain.new, strength: 1) farm.start('localhost', 80, threads: 4) do assert_wait { farm.best.length == 4 } end @@ -67,7 +67,7 @@ def test_makes_many_scores # that it's usually a few microseconds, but sometimes over 200ms. def test_reads_scores_at_high_speed Dir.mktmpdir do |dir| - farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 4) + farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: fake_log, strength: 4) farm.start('localhost', 80, threads: 4) do assert_wait { !farm.best.empty? && !farm.best[0].value.zero? } cycles = 100 @@ -76,14 +76,14 @@ def test_reads_scores_at_high_speed farm.best Time.now - start end.inject(&:+) / cycles - test_log.info("Average speed is #{(speed * 1000).round(2)}ms in #{cycles} cycles") + fake_log.info("Average speed is #{(speed * 1000).round(2)}ms in #{cycles} cycles") end end end def test_makes_best_score_in_background Dir.mktmpdir do |dir| - farm = Zold::Farm.new('NOPREFIX1@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 3) + farm = Zold::Farm.new('NOPREFIX1@ffffffffffffffff', File.join(dir, 'f'), log: fake_log, strength: 3) farm.start('localhost', 80, threads: 1) do assert_wait { !farm.best.empty? && farm.best[0].value >= 3 } score = farm.best[0] @@ -95,7 +95,7 @@ def test_makes_best_score_in_background def test_correct_score_from_empty_farm Dir.mktmpdir do |dir| - farm = Zold::Farm.new('NOPREFIX2@cccccccccccccccc', File.join(dir, 'f'), log: test_log, strength: 1) + farm = Zold::Farm.new('NOPREFIX2@cccccccccccccccc', File.join(dir, 'f'), log: fake_log, strength: 1) farm.start('example.com', 8080, threads: 0) do score = farm.best[0] assert(!score.expired?) @@ -109,7 +109,7 @@ def test_correct_score_from_empty_farm def test_pre_loads_history Dir.mktmpdir do |dir| cache = File.join(dir, 'a/b/c/cache') - farm = Zold::Farm.new('NOPREFIX3@cccccccccccccccc', cache, log: test_log, strength: 1) + farm = Zold::Farm.new('NOPREFIX3@cccccccccccccccc', cache, log: fake_log, strength: 1) farm.start('example.com', 8080, threads: 0) do score = farm.best[0] assert(!score.nil?, 'The list of best scores can\'t be empty!') @@ -132,7 +132,7 @@ def test_drops_expired_scores_from_history strength: 6 ) File.write(cache, score.to_s) - farm = Zold::Farm.new('NOPREFIX4@ffffffffffffffff', cache, log: test_log, strength: score.strength) + farm = Zold::Farm.new('NOPREFIX4@ffffffffffffffff', cache, log: fake_log, strength: score.strength) farm.start(score.host, score.port, threads: 1) do 100.times do sleep(0.1) @@ -170,7 +170,7 @@ def test_garbage_farm_file end def test_terminates_farm_entirely - Zold::Farm.new('NOPREFIX4@ffffffffffffffff', log: test_log, strength: 10).start('localhost', 4096, threads: 1) do + Zold::Farm.new('NOPREFIX4@ffffffffffffffff', log: fake_log, strength: 10).start('localhost', 4096, threads: 1) do sleep 1 end end diff --git a/test/node/test_farmers.rb b/test/node/test_farmers.rb index 0a47c41a1..8b1118e27 100755 --- a/test/node/test_farmers.rb +++ b/test/node/test_farmers.rb @@ -38,7 +38,7 @@ class FarmersTest < Zold::Test def test_calculates_next_score before = Zold::Score.new(host: 'some-host', port: 9999, invoice: 'NOPREFIX4@ffffffffffffffff', strength: 3) TYPES.each do |farmer_class| - farmer = farmer_class.new(log: test_log) + farmer = farmer_class.new(log: fake_log) after = farmer.up(before) assert_equal(1, after.value) assert(!after.expired?) @@ -49,7 +49,7 @@ def test_calculates_next_score def test_calculates_large_score TYPES.each do |type| - log = TestLogger.new(test_log) + log = TestLogger.new(fake_log) thread = Thread.start do farmer = type.new(log: log) farmer.up(Zold::Score.new(host: 'a', port: 1, invoice: 'NOPREFIX4@ffffffffffffffff', strength: 20)) @@ -62,9 +62,9 @@ def test_calculates_large_score def test_kills_farmer TYPES.each do |type| - farmer = type.new(log: test_log) + farmer = type.new(log: fake_log) thread = Thread.start do - Zold::VerboseThread.new(test_log).run do + Zold::VerboseThread.new(fake_log).run do farmer.up(Zold::Score.new(host: 'some-host', invoice: 'NOPREFIX4@ffffffffffffffff', strength: 32)) end end diff --git a/test/node/test_front.rb b/test/node/test_front.rb index 0a0140766..3a3274856 100755 --- a/test/node/test_front.rb +++ b/test/node/test_front.rb @@ -45,7 +45,7 @@ def app def test_memory_leakage skip report = MemoryProfiler.report(top: 10) do - FakeNode.new(log: test_log).run(opts('--network=foo')) do |port| + FakeNode.new(log: fake_log).run(opts('--network=foo')) do |port| 100.times do Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get end @@ -55,7 +55,7 @@ def test_memory_leakage end def test_renders_front_json - FakeNode.new(log: test_log).run(opts('--network=foo')) do |port| + FakeNode.new(log: fake_log).run(opts('--network=foo')) do |port| res = Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get json = JSON.parse(res.body) assert_equal(Zold::VERSION, json['version']) @@ -74,7 +74,7 @@ def test_renders_front_json end def test_renders_public_pages - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| { 200 => [ '/robots.txt', @@ -117,7 +117,7 @@ def test_renders_public_pages end def test_updates_list_of_remotes - FakeNode.new(log: test_log).run(['--no-metronome', '--ignore-score-weakness', '--no-cache']) do |port| + FakeNode.new(log: fake_log).run(['--no-metronome', '--ignore-score-weakness', '--no-cache']) do |port| (Zold::Remotes::MAX_NODES + 5).times do |i| score = Zold::Score.new( host: 'localhost', port: i + 1, invoice: 'NOPREFIX@ffffffffffffffff', strength: 1 @@ -138,7 +138,7 @@ def test_updates_list_of_remotes end def test_increments_score - FakeNode.new(log: test_log).run(opts('--threads=1')) do |port| + FakeNode.new(log: fake_log).run(opts('--threads=1')) do |port| 3.times do |i| assert_equal_wait(true, max: 60) do response = Zold::Http.new(uri: "http://localhost:#{port}/").get @@ -159,8 +159,8 @@ def test_increments_score ].each do |p| method = "test_wallet_page_#{p.gsub(/[^a-z]/, '_')}" define_method(method) do - FakeHome.new(log: test_log).run do |home| - FakeNode.new(log: test_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| wallet = home.create_wallet(txns: 2) base = "http://localhost:#{port}" response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) @@ -173,8 +173,8 @@ def test_increments_score end def test_renders_wallets_page - FakeHome.new(log: test_log).run do |home| - FakeNode.new(log: test_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| wallet = home.create_wallet(txns: 2) base = "http://localhost:#{port}" response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) @@ -188,8 +188,8 @@ def test_renders_wallets_page end def test_fetch_in_multiple_threads - FakeNode.new(log: test_log).run(opts) do |port| - FakeHome.new(log: test_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet base = "http://localhost:#{port}" Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) @@ -209,8 +209,8 @@ def test_fetch_in_multiple_threads end def test_pushes_twice - FakeNode.new(log: test_log).run(opts) do |port| - FakeHome.new(log: test_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet base = "http://localhost:#{port}" assert_equal( @@ -227,9 +227,9 @@ def test_pushes_twice end def test_pushes_many_wallets - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| base = "http://localhost:#{port}" - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| Threads.new(5).assert do wallet = home.create_wallet Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) @@ -273,7 +273,7 @@ def test_different_logos end def test_gzip - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| response = Zold::Http.new(uri: URI("http://localhost:#{port}/version")).get assert_equal(200, response.status, response) assert_operator(300, :>, response.body.length.to_i, 'Expected the content to be small') @@ -282,7 +282,7 @@ def test_gzip def test_performance times = Queue.new - FakeNode.new(log: test_log).run(opts('--threads=4', '--strength=6')) do |port| + FakeNode.new(log: fake_log).run(opts('--threads=4', '--strength=6')) do |port| Threads.new(10).assert(100) do start = Time.now Zold::Http.new(uri: URI("http://localhost:#{port}/")).get @@ -291,7 +291,7 @@ def test_performance end all = [] all << times.pop(true) until times.empty? - test_log.info("Average response time is #{all.inject(&:+) / all.count}") + fake_log.info("Average response time is #{all.inject(&:+) / all.count}") end # The score exposed via the HTTP header must be reduced to the value of 16. @@ -299,7 +299,7 @@ def test_performance # HTTP request. This value is enough to identify a valueable node, and filter # out those that are too weak. def test_score_is_reduced - FakeNode.new(log: test_log).run(opts('--threads=1', '--strength=1', '--farmer=plain')) do |port| + FakeNode.new(log: fake_log).run(opts('--threads=1', '--strength=1', '--farmer=plain')) do |port| scores = [] 50.times do res = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get @@ -311,7 +311,7 @@ def test_score_is_reduced end def test_headers_are_being_set_correctly - FakeNode.new(log: test_log).run(opts('--expose-version=9.9.9')) do |port| + FakeNode.new(log: fake_log).run(opts('--expose-version=9.9.9')) do |port| response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get assert_equal('no-cache', response.headers['Cache-Control']) assert_equal('close', response.headers['Connection']) @@ -325,7 +325,7 @@ def test_headers_are_being_set_correctly def test_alias_parameter name = SecureRandom.hex(4) - FakeNode.new(log: test_log).run(opts("--alias=#{name}")) do |port| + FakeNode.new(log: fake_log).run(opts("--alias=#{name}")) do |port| uri = URI("http://localhost:#{port}/") response = Zold::Http.new(uri: uri).get assert_match( @@ -337,7 +337,7 @@ def test_alias_parameter end def test_default_alias_parameter - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| uri = URI("http://localhost:#{port}/") response = Zold::Http.new(uri: uri).get assert_match( @@ -350,7 +350,7 @@ def test_default_alias_parameter def test_invalid_alias exception = assert_raises RuntimeError do - FakeNode.new(log: test_log).run(opts('--alias=invalid-alias')) do |port| + FakeNode.new(log: fake_log).run(opts('--alias=invalid-alias')) do |port| uri = URI("http://localhost:#{port}/") Zold::Http.new(uri: uri).get end @@ -360,8 +360,8 @@ def test_invalid_alias def test_push_fetch_in_multiple_threads key = Zold::Key.new(text: File.read('fixtures/id_rsa')) - FakeNode.new(log: test_log).run(opts) do |port| - FakeHome.new(log: test_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet(Zold::Id::ROOT) base = "http://localhost:#{port}" Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) @@ -380,7 +380,7 @@ def test_push_fetch_in_multiple_threads end def test_checksum_in_json - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| uri = URI("http://localhost:#{port}/") response = Zold::Http.new(uri: uri).get assert( diff --git a/test/node/test_nodup_entrance.rb b/test/node/test_nodup_entrance.rb index b8f82aee0..164d96348 100644 --- a/test/node/test_nodup_entrance.rb +++ b/test/node/test_nodup_entrance.rb @@ -33,9 +33,9 @@ # License:: MIT class TestNoDupEntrance < Zold::Test def test_ignores_dup - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet - Zold::NoDupEntrance.new(RealEntrance.new, home.wallets, log: test_log).start do |e| + Zold::NoDupEntrance.new(RealEntrance.new, home.wallets, log: fake_log).start do |e| assert(e.push(wallet.id, File.read(wallet.path)).empty?) end end diff --git a/test/node/test_nospam_entrance.rb b/test/node/test_nospam_entrance.rb index 9c3fe9185..261127e6e 100644 --- a/test/node/test_nospam_entrance.rb +++ b/test/node/test_nospam_entrance.rb @@ -32,7 +32,7 @@ # License:: MIT class TestNoSpamEntrance < Zold::Test def test_ignores_spam - Zold::NoSpamEntrance.new(RealEntrance.new, log: test_log).start do |e| + Zold::NoSpamEntrance.new(RealEntrance.new, log: fake_log).start do |e| id = Zold::Id.new content = 'hello' assert(!e.push(id, content).empty?) diff --git a/test/node/test_safe_entrance.rb b/test/node/test_safe_entrance.rb index 569de7f19..39c309433 100644 --- a/test/node/test_safe_entrance.rb +++ b/test/node/test_safe_entrance.rb @@ -36,7 +36,7 @@ # License:: MIT class TestSafeEntrance < Zold::Test def test_rejects_wallet_with_negative_balance - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -48,7 +48,7 @@ def test_rejects_wallet_with_negative_balance end def test_rejects_wallet_with_wrong_network - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = Zold::Wallet.new(File.join(home.dir, 'wallet.z')) wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'), network: 'someothernetwork') assert_raises StandardError do diff --git a/test/node/test_spread_entrance.rb b/test/node/test_spread_entrance.rb index eed41e16e..b14f0f12b 100644 --- a/test/node/test_spread_entrance.rb +++ b/test/node/test_spread_entrance.rb @@ -36,15 +36,15 @@ # License:: MIT class TestSpreadEntrance < Zold::Test def test_renders_json - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet(Zold::Id.new) Zold::SpreadEntrance.new( Zold::Entrance.new( home.wallets, Zold::Pipeline.new(home.remotes, home.copies(wallet).root, 'x'), - log: test_log + log: fake_log ), - home.wallets, home.remotes, 'x', log: test_log + home.wallets, home.remotes, 'x', log: fake_log ).start do |e| assert_equal(0, e.to_json[:modified]) end @@ -52,12 +52,12 @@ def test_renders_json end def test_ignores_duplicates - FakeHome.new(log: test_log).run do |home| - FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port| + FakeHome.new(log: fake_log).run do |home| + FakeNode.new(log: fake_log).run(['--ignore-score-weakness']) do |port| wallet = home.create_wallet remotes = home.remotes remotes.add('localhost', port) - Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log: test_log).start do |e| + Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log: fake_log).start do |e| 8.times { e.push(wallet.id, File.read(wallet.path)) } assert(e.to_json[:modified] < 2, "It's too big: #{e.to_json[:modified]}") end diff --git a/test/node/test_sync_entrance.rb b/test/node/test_sync_entrance.rb index 880aebc1b..c33d22c6a 100644 --- a/test/node/test_sync_entrance.rb +++ b/test/node/test_sync_entrance.rb @@ -32,8 +32,8 @@ # License:: MIT class TestSyncEntrance < Zold::Test def test_renders_json - FakeHome.new(log: test_log).run do |home| - Zold::SyncEntrance.new(FakeEntrance.new, File.join(home.dir, 'x'), log: test_log).start do |e| + FakeHome.new(log: fake_log).run do |home| + Zold::SyncEntrance.new(FakeEntrance.new, File.join(home.dir, 'x'), log: fake_log).start do |e| assert(!e.to_json.nil?) end end diff --git a/test/node/test_trace.rb b/test/node/test_trace.rb index af5fd4bdb..bccc22221 100644 --- a/test/node/test_trace.rb +++ b/test/node/test_trace.rb @@ -26,7 +26,7 @@ class TraceTest < Zold::Test def test_records_log_lines - trace = Zold::Trace.new(test_log, 2) + trace = Zold::Trace.new(fake_log, 2) trace.error('This should not be visible') trace.error('How are you, друг?') trace.error('Works?') diff --git a/test/test__helper.rb b/test/test__helper.rb index 83a24de7f..600c8d33a 100755 --- a/test/test__helper.rb +++ b/test/test__helper.rb @@ -71,7 +71,7 @@ def assert_equal_wait(expected, max: 30) break end rescue StandardError => e - test_log.debug(e.message) + fake_log.debug(e.message) end sleep 1 sec = Time.now - start @@ -80,9 +80,9 @@ def assert_equal_wait(expected, max: 30) end end - def test_log + def fake_log require_relative '../lib/zold/log' - @test_log ||= ENV['TEST_QUIET_LOG'] ? Zold::Log::NULL : Zold::Log::VERBOSE + @fake_log ||= ENV['TEST_QUIET_LOG'] ? Zold::Log::NULL : Zold::Log::VERBOSE end class TestLogger diff --git a/test/test_copies.rb b/test/test_copies.rb index 751a2181b..68025ecef 100644 --- a/test/test_copies.rb +++ b/test/test_copies.rb @@ -38,7 +38,7 @@ class TestCopies < Zold::Test def test_adds_and_removes_copies Dir.mktmpdir do |dir| - copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log: test_log) + copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log: fake_log) copies.add(content('alpha'), '192.168.0.1', 80, 1) copies.add(content('beta'), '192.168.0.2', 80, 3) copies.add(content('beta'), '192.168.0.3', 80, 7) @@ -53,14 +53,14 @@ def test_adds_and_removes_copies def test_lists_empty_dir Dir.mktmpdir do |dir| - copies = Zold::Copies.new(File.join(dir, 'xxx'), log: test_log) + copies = Zold::Copies.new(File.join(dir, 'xxx'), log: fake_log) assert(copies.all.empty?, "#{copies.all.count} is not zero") end end def test_overwrites_host Dir.mktmpdir do |dir| - copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: test_log) + copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log) host = 'b1.zold.io' copies.add(content('z1'), host, 80, 5) copies.add(content('z1'), host, 80, 6) @@ -72,7 +72,7 @@ def test_overwrites_host def test_master_first Dir.mktmpdir do |dir| - copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: test_log) + copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log) copies.add(content('z1'), 'edge-1', 80, 100, master: false) copies.add(content('z2'), 'master', 80, 1, master: true) copies.add(content('z1'), 'edge-2', 80, 50, master: false) @@ -83,7 +83,7 @@ def test_master_first def test_cleans_copies Dir.mktmpdir do |dir| - copies = Zold::Copies.new(dir, log: test_log) + copies = Zold::Copies.new(dir, log: fake_log) copies.add(content('h1'), 'zold.io', 4096, 10, time: Time.now - (25 * 60 * 60)) copies.add(content('h1'), 'zold.io', 4097, 20, time: Time.now - (26 * 60 * 60)) assert(File.exist?(File.join(dir, "1#{Zold::Copies::EXT}"))) @@ -95,7 +95,7 @@ def test_cleans_copies def test_cleans_broken_copies Dir.mktmpdir do |dir| - copies = Zold::Copies.new(dir, log: test_log) + copies = Zold::Copies.new(dir, log: fake_log) copies.add('broken wallet content', 'zold.io', 4096, 10, time: Time.now) copies.clean assert(copies.all.empty?, "#{copies.all.count} is not empty") @@ -104,7 +104,7 @@ def test_cleans_broken_copies def test_ignores_garbage Dir.mktmpdir do |dir| - copies = Zold::Copies.new(dir, log: test_log) + copies = Zold::Copies.new(dir, log: fake_log) copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (25 * 60 * 60)) FileUtils.mkdir(File.join(dir, '55')) assert_equal(1, copies.all.count) @@ -113,7 +113,7 @@ def test_ignores_garbage def test_sorts_them_by_score Dir.mktmpdir do |dir| - copies = Zold::Copies.new(dir, log: test_log) + copies = Zold::Copies.new(dir, log: fake_log) copies.add(content('content-1'), '1.zold.io', 80, 1) copies.add(content('content-2'), '2.zold.io', 80, 2) copies.add(content('content-3'), '3.zold.io', 80, 50) @@ -124,7 +124,7 @@ def test_sorts_them_by_score def test_ignores_too_old_scores Dir.mktmpdir do |dir| - copies = Zold::Copies.new(dir, log: test_log) + copies = Zold::Copies.new(dir, log: fake_log) copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (1000 * 60 * 60)) assert_equal(0, copies.all[0][:score]) end @@ -134,7 +134,7 @@ def test_ignores_too_old_scores def content(text) id = Zold::Id.new('aaaabbbbccccdddd') - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet(id) amount = Zold::Amount.new(zld: 1.99) key = Zold::Key.new(file: 'fixtures/id_rsa') diff --git a/test/test_dir_items.rb b/test/test_dir_items.rb index 1b7997547..ffc625734 100644 --- a/test/test_dir_items.rb +++ b/test/test_dir_items.rb @@ -37,14 +37,14 @@ def test_intensive_write_in_threads Dir.mktmpdir do |dir| file = File.join(dir, 'hey.txt') back = Thread.start do - Zold::Endless.new('test-diritems', log: test_log).run do + Zold::Endless.new('test-diritems', log: fake_log).run do Zold::DirItems.new(dir).fetch end end Threads.new(100).assert do start = Time.now File.write(file, 'test') - test_log.info("Saved in #{Zold::Age.new(start)}") + fake_log.info("Saved in #{Zold::Age.new(start)}") sleep 1 end back.kill diff --git a/test/test_http.rb b/test/test_http.rb index 9f59dd01e..2be7aec6f 100755 --- a/test/test_http.rb +++ b/test/test_http.rb @@ -76,7 +76,7 @@ def test_terminates_on_timeout WebMock.allow_net_connect! RandomPort::Pool::SINGLETON.acquire do |port| thread = Thread.start do - Zold::VerboseThread.new(test_log).run do + Zold::VerboseThread.new(fake_log).run do server = TCPServer.new(port) server.accept sleep 400 @@ -95,7 +95,7 @@ def test_doesnt_terminate_on_long_call WebMock.allow_net_connect! RandomPort::Pool::SINGLETON.acquire do |port| thread = Thread.start do - Zold::VerboseThread.new(test_log).run do + Zold::VerboseThread.new(fake_log).run do server = TCPServer.new(port) client = server.accept client.puts("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n") @@ -118,14 +118,14 @@ def test_sends_correct_http_headers RandomPort::Pool::SINGLETON.acquire do |port| latch = Concurrent::CountDownLatch.new(1) thread = Thread.start do - Zold::VerboseThread.new(test_log).run do + Zold::VerboseThread.new(fake_log).run do server = TCPServer.new('127.0.0.1', port) latch.count_down socket = server.accept loop do line = socket.gets break if line.eql?("\r\n") - test_log.info(line.inspect) + fake_log.info(line.inspect) body += line end socket.print("HTTP/1.1 200 OK\r\n") @@ -163,7 +163,7 @@ def test_uploads_file RandomPort::Pool::SINGLETON.acquire do |port| latch = Concurrent::CountDownLatch.new(1) thread = Thread.start do - Zold::VerboseThread.new(test_log).run do + Zold::VerboseThread.new(fake_log).run do server = TCPServer.new(port) latch.count_down socket = server.accept @@ -204,7 +204,7 @@ def test_downloads_file content = "how are you\nmy friend" * 1000 latch = Concurrent::CountDownLatch.new(1) thread = Thread.start do - Zold::VerboseThread.new(test_log).run do + Zold::VerboseThread.new(fake_log).run do server = TCPServer.new(port) latch.count_down socket = server.accept diff --git a/test/test_hungry_wallets.rb b/test/test_hungry_wallets.rb index a4532376d..282511742 100644 --- a/test/test_hungry_wallets.rb +++ b/test/test_hungry_wallets.rb @@ -35,15 +35,15 @@ # License:: MIT class TestHungryWallets < Zold::Test def test_pulls_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| id = Zold::Id.new get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404) remotes = home.remotes remotes.add('localhost', 4096) - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) wallets = Zold::HungryWallets.new( home.wallets, remotes, File.join(home.dir, 'copies'), - pool, log: test_log + pool, log: fake_log ) wallets.acq(id) { |w| assert(!w.exists?) } pool.join(2) @@ -52,15 +52,15 @@ def test_pulls_wallet end def test_doesnt_pull_twice_if_not_found - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| id = Zold::Id.new get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404) remotes = home.remotes remotes.add('localhost', 4096) - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) wallets = Zold::HungryWallets.new( home.wallets, remotes, File.join(home.dir, 'copies'), - pool, log: test_log + pool, log: fake_log ) 3.times do wallets.acq(id) { |w| assert(!w.exists?) } @@ -72,15 +72,15 @@ def test_doesnt_pull_twice_if_not_found end def test_doesnt_pull_wallet_if_exists - FakeHome.new(log: test_log).run do |home| - pool = Zold::ThreadPool.new('test', log: test_log) + FakeHome.new(log: fake_log).run do |home| + pool = Zold::ThreadPool.new('test', log: fake_log) remotes = home.remotes remotes.add('localhost', 4096) wallet = home.create_wallet get = stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(status: 200) wallets = Zold::HungryWallets.new( home.wallets, remotes, File.join(home.dir, 'copies'), - pool, log: test_log + pool, log: fake_log ) wallets.acq(wallet.id) { |w| assert(w.exists?) } pool.join(2) diff --git a/test/test_log.rb b/test/test_log.rb index 5497e5eb7..b3b8a0316 100644 --- a/test/test_log.rb +++ b/test/test_log.rb @@ -32,9 +32,9 @@ class TestLog < Zold::Test def test_prints_from_many_threads Threads.new(20).assert do - test_log.debug("This is debug\nand it is multi\nline") - test_log.info('This is info') - test_log.error('This is error') + fake_log.debug("This is debug\nand it is multi\nline") + fake_log.info('This is info') + fake_log.error('This is error') end end diff --git a/test/test_metronome.rb b/test/test_metronome.rb index d9f5ed2e8..2e6d32b57 100644 --- a/test/test_metronome.rb +++ b/test/test_metronome.rb @@ -30,7 +30,7 @@ # License:: MIT class TestMetronome < Zold::Test def test_start_and_stop - metronome = Zold::Metronome.new(test_log) + metronome = Zold::Metronome.new(fake_log) list = [] metronome.add(FakeRoutine.new(list)) metronome.start do @@ -39,7 +39,7 @@ def test_start_and_stop end def test_prints_to_text - metronome = Zold::Metronome.new(test_log) + metronome = Zold::Metronome.new(fake_log) metronome.add(FakeRoutine.new([])) metronome.start do |m| assert(!m.to_text.nil?) @@ -47,14 +47,14 @@ def test_prints_to_text end def test_prints_empty_to_text - metronome = Zold::Metronome.new(test_log) + metronome = Zold::Metronome.new(fake_log) metronome.start do |m| assert(!m.to_text.nil?) end end def test_continues_even_after_error - metronome = Zold::Metronome.new(test_log) + metronome = Zold::Metronome.new(fake_log) routine = BrokenRoutine.new metronome.add(routine) metronome.start do diff --git a/test/test_patch.rb b/test/test_patch.rb index 3aad92c80..458d69175 100644 --- a/test/test_patch.rb +++ b/test/test_patch.rb @@ -36,7 +36,7 @@ # License:: MIT class TestPatch < Zold::Test def test_builds_patch - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| first = home.create_wallet second = home.create_wallet third = home.create_wallet @@ -49,7 +49,7 @@ def test_builds_patch File.write(third.path, File.read(first.path)) t = third.sub(Zold::Amount.new(zld: 10.0), "NOPREFIX@#{Zold::Id.new}", key) third.add(t.inverse(Zold::Id.new)) - patch = Zold::Patch.new(home.wallets, log: test_log) + patch = Zold::Patch.new(home.wallets, log: fake_log) patch.join(first) { false } patch.join(second) { false } patch.join(third) { false } @@ -59,12 +59,12 @@ def test_builds_patch end def test_rejects_fake_positives - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| first = home.create_wallet second = home.create_wallet File.write(second.path, File.read(first.path)) second.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake')) - patch = Zold::Patch.new(home.wallets, log: test_log) + patch = Zold::Patch.new(home.wallets, log: fake_log) patch.join(first) { false } patch.join(second) { false } assert_equal(false, patch.save(first.path, overwrite: true)) @@ -74,14 +74,14 @@ def test_rejects_fake_positives end def test_accepts_negative_balance_in_root_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| first = home.create_wallet(Zold::Id::ROOT) second = home.create_wallet File.write(second.path, File.read(first.path)) amount = Zold::Amount.new(zld: 333.0) key = Zold::Key.new(file: 'fixtures/id_rsa') second.sub(amount, "NOPREFIX@#{Zold::Id.new}", key) - patch = Zold::Patch.new(home.wallets, log: test_log) + patch = Zold::Patch.new(home.wallets, log: fake_log) patch.join(first) { false } patch.join(second) { false } assert_equal(true, patch.save(first.path, overwrite: true)) @@ -91,7 +91,7 @@ def test_accepts_negative_balance_in_root_wallet end def test_merges_similar_ids_but_different_signs - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| first = home.create_wallet(Zold::Id::ROOT) second = home.create_wallet File.write(second.path, File.read(first.path)) @@ -103,7 +103,7 @@ def test_merges_similar_ids_but_different_signs Zold::Prefixes.new(first).create, Zold::Id.new, 'fake' ) ) - patch = Zold::Patch.new(home.wallets, log: test_log) + patch = Zold::Patch.new(home.wallets, log: fake_log) patch.join(first) { false } patch.join(second) { false } assert_equal(true, patch.save(first.path, overwrite: true)) @@ -113,7 +113,7 @@ def test_merges_similar_ids_but_different_signs end def test_merges_fragmented_parts - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| first = home.create_wallet(Zold::Id::ROOT) second = home.create_wallet File.write(second.path, File.read(first.path)) @@ -137,7 +137,7 @@ def test_merges_fragmented_parts 'NOPREFIX', Zold::Id.new, 'third payment' ).signed(key, first.id) ) - patch = Zold::Patch.new(home.wallets, log: test_log) + patch = Zold::Patch.new(home.wallets, log: fake_log) patch.join(first) { false } patch.join(second) { false } assert_equal(true, patch.save(first.path, overwrite: true)) @@ -148,7 +148,7 @@ def test_merges_fragmented_parts end def test_protocols_new_txns - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| first = home.create_wallet(Zold::Id::ROOT) second = home.create_wallet File.write(second.path, File.read(first.path)) @@ -157,7 +157,7 @@ def test_protocols_new_txns target = Zold::Id.new second.sub(amount, "NOPREFIX@#{target}", key, 'some details') second.sub(amount * 2, "NOPREFIX@#{target}", key) - patch = Zold::Patch.new(home.wallets, log: test_log) + patch = Zold::Patch.new(home.wallets, log: fake_log) patch.legacy(first) Tempfile.open do |f| patch.join(second, ledger: f.path) { false } diff --git a/test/test_prefixes.rb b/test/test_prefixes.rb index e7b0b01d4..e8be96d39 100644 --- a/test/test_prefixes.rb +++ b/test/test_prefixes.rb @@ -34,7 +34,7 @@ # License:: MIT class TestPrefixes < Zold::Test def test_creates_and_validates - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet prefixes = Zold::Prefixes.new(wallet) (8..32).each do |len| diff --git a/test/test_remotes.rb b/test/test_remotes.rb index 7967812db..f2d874b19 100755 --- a/test/test_remotes.rb +++ b/test/test_remotes.rb @@ -118,7 +118,7 @@ def test_iterates_them_all_even_with_delays remotes.clean 5.times { |i| remotes.add("0.0.0.#{i + 1}", 8080) } total = 0 - remotes.iterate(test_log) do + remotes.iterate(fake_log) do sleep 0.25 total += 1 end @@ -126,7 +126,7 @@ def test_iterates_them_all_even_with_delays end end - def test_log_msg_of_iterates_when_fail + def fake_log_msg_of_iterates_when_fail Dir.mktmpdir do |dir| file = File.join(dir, 'remotes') FileUtils.touch(file) @@ -138,7 +138,7 @@ def test_log_msg_of_iterates_when_fail end end - def test_log_msg_of_iterates_when_take_too_long + def fake_log_msg_of_iterates_when_take_too_long Dir.mktmpdir do |dir| file = File.join(dir, 'remotes') FileUtils.touch(file) @@ -254,10 +254,10 @@ def test_quickly_ads_and_reads remotes.add('127.0.0.1', 8080 + t) remotes.error('127.0.0.1', 8080 + t) remotes.all - remotes.iterate(test_log) { remotes.all } + remotes.iterate(fake_log) { remotes.all } remotes.remove('127.0.0.1', 8080 + t) end - test_log.info("Total time: #{Zold::Age.new(start)}") + fake_log.info("Total time: #{Zold::Age.new(start)}") end end @@ -298,7 +298,7 @@ def test_reports_zold_error_header 'X-Zold-Error': 'hey you' } ) - remotes.iterate(test_log) do |r| + remotes.iterate(fake_log) do |r| r.assert_code(200, r.http.get) end end @@ -310,7 +310,7 @@ def test_manifests_correct_network_name remotes.clean remotes.add('r5-example.org', 8080) stub_request(:get, 'http://r5-example.org:8080/').to_return(status: 200) - remotes.iterate(test_log) do |r| + remotes.iterate(fake_log) do |r| r.http.get end assert_requested(:get, 'http://r5-example.org:8080/', headers: { 'X-Zold-Network' => 'x13' }) diff --git a/test/test_sync_wallets.rb b/test/test_sync_wallets.rb index 5ca341094..4bbaa9953 100644 --- a/test/test_sync_wallets.rb +++ b/test/test_sync_wallets.rb @@ -37,7 +37,7 @@ # License:: MIT class TestSyncWallets < Zold::Test def test_adds_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets id = Zold::Id.new home.create_wallet(id) diff --git a/test/test_tax.rb b/test/test_tax.rb index baf410391..1ddf77364 100644 --- a/test/test_tax.rb +++ b/test/test_tax.rb @@ -39,11 +39,11 @@ # License:: MIT class TestTax < Zold::Test def test_print_fee - test_log.info("Fee in zents: #{Zold::Tax::FEE.to_i}") + fake_log.info("Fee in zents: #{Zold::Tax::FEE.to_i}") end def test_calculates_tax_for_one_year - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet a = 10_000 wallet.add( @@ -60,7 +60,7 @@ def test_calculates_tax_for_one_year end def test_calculates_debt - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet (1..30).each do |i| wallet.add( @@ -84,7 +84,7 @@ def test_calculates_debt end def test_prints_tax_formula - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet tax = Zold::Tax.new(wallet) assert(!tax.to_text.nil?) @@ -92,7 +92,7 @@ def test_prints_tax_formula end def test_takes_tax_payment_into_account - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zents: 95_596_800) wallet.add( @@ -112,7 +112,7 @@ def test_takes_tax_payment_into_account end def test_filters_out_incoming_payments - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zents: 95_596_800) prefix = Zold::Prefixes.new(wallet).create(8) @@ -146,7 +146,7 @@ def test_filters_out_incoming_payments end def test_checks_existence_of_duplicates - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet wallet.add( Zold::Txn.new( diff --git a/test/test_thread_pool.rb b/test/test_thread_pool.rb index b7057f00a..1f493c58d 100644 --- a/test/test_thread_pool.rb +++ b/test/test_thread_pool.rb @@ -31,7 +31,7 @@ # License:: MIT class TestThreadPool < Zold::Test def test_closes_all_threads_right - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) idx = Concurrent::AtomicFixnum.new threads = 50 threads.times do @@ -44,7 +44,7 @@ def test_closes_all_threads_right end def test_adds_and_stops - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) pool.add do sleep 60 * 60 end @@ -52,7 +52,7 @@ def test_adds_and_stops end def test_stops_stuck_threads - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) pool.add do loop do # forever @@ -62,12 +62,12 @@ def test_stops_stuck_threads end def test_stops_empty_pool - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) pool.kill end def test_prints_to_json - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) pool.add do Thread.current.thread_variable_set(:foo, 1) loop do @@ -83,7 +83,7 @@ def test_prints_to_json end def test_prints_to_text - pool = Zold::ThreadPool.new('test', log: test_log) + pool = Zold::ThreadPool.new('test', log: fake_log) assert(!pool.to_s.nil?) end end diff --git a/test/test_wallet.rb b/test/test_wallet.rb index a4c66bfd7..d1e10c31b 100644 --- a/test/test_wallet.rb +++ b/test/test_wallet.rb @@ -39,7 +39,7 @@ # License:: MIT class TestWallet < Zold::Test def test_reads_empty_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet assert(wallet.txns.empty?) assert_equal(Zold::Amount::ZERO, wallet.balance) @@ -47,7 +47,7 @@ def test_reads_empty_wallet end def test_generates_memo - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet assert(!wallet.mnemo.nil?) end @@ -55,7 +55,7 @@ def test_generates_memo def test_reads_large_wallet key = Zold::Key.new(file: 'fixtures/id_rsa') - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet(Zold::Id.new('448b451bc62e8e16')) FileUtils.cp('fixtures/448b451bc62e8e16.z', wallet.path) start = Time.now @@ -67,7 +67,7 @@ def test_reads_large_wallet end def test_adds_transaction - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -82,7 +82,7 @@ def test_adds_transaction end def test_adds_similar_transaction - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -100,7 +100,7 @@ def test_adds_similar_transaction end def test_checks_similar_transaction - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -113,7 +113,7 @@ def test_checks_similar_transaction end def test_refurbishes_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 5.99) key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -128,7 +128,7 @@ def test_refurbishes_wallet end def test_refurbishes_empty_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet before = File.read(wallet.path) File.write(wallet.path, "#{File.read(wallet.path)}\n\n\n") @@ -138,7 +138,7 @@ def test_refurbishes_empty_wallet end def test_positive_transactions_go_first - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet time = Time.now key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -151,7 +151,7 @@ def test_positive_transactions_go_first end def test_validate_key_on_payment - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa-2') @@ -162,7 +162,7 @@ def test_validate_key_on_payment end def test_adds_transaction_and_reads_back - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') @@ -173,7 +173,7 @@ def test_adds_transaction_and_reads_back end def test_calculates_wallet_age_in_hours - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet hours = 100 wallet.add( @@ -189,7 +189,7 @@ def test_calculates_wallet_age_in_hours end def test_flushes_and_reads_again - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet wallet.add( Zold::Txn.new( @@ -208,14 +208,14 @@ def test_flushes_and_reads_again end def test_returns_modified_time - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet assert(wallet.mtime > Time.now - (60 * 60)) end end def test_returns_digest - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet assert_equal(64, wallet.digest.length) end @@ -235,14 +235,14 @@ def test_raises_when_broken_format end def test_returns_protocol - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet assert_equal(Zold::PROTOCOL, wallet.protocol) end end def test_iterates_income_transactions - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet wallet.add( Zold::Txn.new( @@ -268,7 +268,7 @@ def test_iterates_income_transactions end def test_sorts_them_always_right - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| time = Time.now txns = [] 50.times do @@ -306,13 +306,13 @@ def test_collects_memory_garbage GC.start wallet.id wallet.txns.count - test_log.debug("Memory: #{GetProcessMem.new.bytes.to_i}") if (i % 5).zero? + fake_log.debug("Memory: #{GetProcessMem.new.bytes.to_i}") if (i % 5).zero? end end GC.stress = true diff = GetProcessMem.new.bytes.to_i - start GC.stress = false - test_log.debug("Memory diff is #{diff}") + fake_log.debug("Memory diff is #{diff}") assert(diff < 20_000_000) end end diff --git a/test/test_wallets.rb b/test/test_wallets.rb index bd52f5564..00602aece 100644 --- a/test/test_wallets.rb +++ b/test/test_wallets.rb @@ -35,7 +35,7 @@ # License:: MIT class TestWallets < Zold::Test def test_adds_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets id = Zold::Id.new wallets.acq(id) do |wallet| @@ -46,7 +46,7 @@ def test_adds_wallet end def test_lists_wallets_and_ignores_garbage - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets FileUtils.touch(File.join(home.dir, '0xaaaaaaaaaaaaaaaaaaahello')) FileUtils.mkdir_p(File.join(home.dir, 'a/b/c')) @@ -76,7 +76,7 @@ def test_count_wallets assert_equal(5, wallets.count) end end - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| wallets = home.wallets home.create_wallet assert_equal(1, wallets.count) diff --git a/test/test_zold.rb b/test/test_zold.rb index 89f4f3008..4882f0407 100755 --- a/test/test_zold.rb +++ b/test/test_zold.rb @@ -37,7 +37,7 @@ class TestZold < Zold::Test method = "test_#{f.gsub(/\.sh$/, '').gsub(/[^a-z]/, '_')}" define_method(method) do start = Time.now - test_log.info("\n\n#{method} running (script at #{f})...") + fake_log.info("\n\n#{method} running (script at #{f})...") Dir.mktmpdir do |dir| FileUtils.cp('fixtures/id_rsa.pub', dir) FileUtils.cp('fixtures/id_rsa', dir) @@ -50,7 +50,7 @@ class TestZold < Zold::Test stdin.close until stdout.eof? line = stdout.gets - test_log.info(line) + fake_log.info(line) out << line end code = thr.value.to_i @@ -59,7 +59,7 @@ class TestZold < Zold::Test end sleep 1 # It's a workaround, I can't fix the bug (tests crash sporadically) end - test_log.info("\n\n#{f} done in #{Zold::Age.new(start)}") + fake_log.info("\n\n#{f} done in #{Zold::Age.new(start)}") end end diff --git a/test/upgrades/test_delete_banned_wallets.rb b/test/upgrades/test_delete_banned_wallets.rb index 1f8d5c566..5876f5242 100644 --- a/test/upgrades/test_delete_banned_wallets.rb +++ b/test/upgrades/test_delete_banned_wallets.rb @@ -33,14 +33,14 @@ class TestDeleteBannedWallets < Zold::Test def test_delete_them id = Zold::Id.new(Zold::Id::BANNED[0]) - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| home.create_wallet(id) FileUtils.mkdir_p(File.join(home.dir, 'a/b/c')) File.rename( File.join(home.dir, "#{id}#{Zold::Wallet::EXT}"), File.join(home.dir, "a/b/c/#{id}#{Zold::Wallet::EXT}") ) - Zold::DeleteBannedWallets.new(home.dir, test_log).exec + Zold::DeleteBannedWallets.new(home.dir, fake_log).exec assert(File.exist?(File.join(home.dir, "a/b/c/#{id}#{Zold::Wallet::EXT}-banned"))) end end diff --git a/test/upgrades/test_protocol_up.rb b/test/upgrades/test_protocol_up.rb index 5e7c67e7e..483032583 100644 --- a/test/upgrades/test_protocol_up.rb +++ b/test/upgrades/test_protocol_up.rb @@ -31,9 +31,9 @@ # License:: MIT class TestProtocolUp < Zold::Test def test_upgrades_protocol_in_wallet - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| id = home.create_wallet.id - Zold::ProtocolUp.new(home.dir, test_log).exec + Zold::ProtocolUp.new(home.dir, fake_log).exec home.wallets.acq(id) do |wallet| assert_equal(Zold::PROTOCOL, wallet.protocol) end