Add tests for contract counter

pull/6324/head
sl1depengwyn 2 years ago
parent ce10763e2e
commit b6b60f5fc8
  1. 1
      apps/explorer/config/runtime/test.exs
  2. 65
      apps/explorer/test/explorer/counters/contracts_counter_test.exs

@ -18,6 +18,7 @@ config :explorer, Explorer.Chain.Transaction.History.Historian, enabled: false
config :explorer, Explorer.Market.History.Historian, enabled: false config :explorer, Explorer.Market.History.Historian, enabled: false
config :explorer, Explorer.Counters.AddressesCounter, enabled: false, enable_consolidation: false config :explorer, Explorer.Counters.AddressesCounter, enabled: false, enable_consolidation: false
config :explorer, Explorer.Counters.ContractsCounter, enabled: false, enable_consolidation: false
config :explorer, Explorer.Market.History.Cataloger, enabled: false config :explorer, Explorer.Market.History.Cataloger, enabled: false

@ -0,0 +1,65 @@
defmodule Explorer.Counters.ContractsCounterTest do
use Explorer.DataCase
alias Explorer.Counters.ContractsCounter
alias Explorer.Chain
alias Explorer.Chain.Transaction
test "populates the cache with the number of all contracts" do
insert(:address, contract_code: "0x608060")
insert(:address, contract_code: "0x608060")
insert(:address, contract_code: "0x608060", inserted_at: Timex.shift(Timex.now(), days: -2))
insert(:smart_contract)
start_supervised!(ContractsCounter)
ContractsCounter.consolidate()
assert Chain.count_contracts_from_cache() == 4
end
test "populates the cache with the number of new contracts (last 24h)" do
:transaction
|> insert(created_contract_code_indexed_at: Timex.shift(Timex.now(), hours: -1))
|> with_block(status: :ok)
:transaction
|> insert(created_contract_code_indexed_at: Timex.shift(Timex.now(), hours: -25))
|> with_block(status: :ok)
:transaction
|> insert(created_contract_code_indexed_at: Timex.shift(Timex.now(), hours: -23))
|> with_block(status: :ok)
:transaction
|> insert(created_contract_code_indexed_at: Timex.shift(Timex.now(), hours: -30))
|> with_block(status: :ok)
start_supervised!(ContractsCounter)
ContractsCounter.consolidate()
assert Chain.count_new_contracts_from_cache() == 2
end
test "populates the cache with the number of verified contracts" do
insert(:smart_contract)
insert(:smart_contract)
insert(:smart_contract, inserted_at: Timex.shift(Timex.now(), days: -2))
start_supervised!(ContractsCounter)
ContractsCounter.consolidate()
assert Chain.count_verified_contracts_from_cache() == 3
end
test "populates the cache with the number of new verified contracts (last 24h)" do
insert(:smart_contract, inserted_at: Timex.shift(Timex.now(), hours: -25))
insert(:smart_contract, inserted_at: Timex.shift(Timex.now(), hours: -1))
insert(:smart_contract, inserted_at: Timex.shift(Timex.now(), hours: -23))
insert(:smart_contract, inserted_at: Timex.shift(Timex.now(), hours: -30))
start_supervised!(ContractsCounter)
ContractsCounter.consolidate()
assert Chain.count_new_verified_contracts_from_cache() == 2
end
end
Loading…
Cancel
Save