Skip to content

Commit

Permalink
chore: adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jan 21, 2020
1 parent 268858d commit e00ca49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
8 changes: 4 additions & 4 deletions test/models/ckb_sync/node_data_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
tx = fake_dao_withdraw_transaction(node_block)
withdraw_amount = tx.cell_outputs.nervos_dao_withdrawing.first.capacity

assert_difference -> { DaoContract.default_contract.reload.interest_granted }, "0x174876ebe8".hex - withdraw_amount do
assert_difference -> { DaoContract.default_contract.reload.claimed_compensation }, "0x174876ebe8".hex - withdraw_amount do
node_data_processor.process_block(node_block)
end

Expand Down Expand Up @@ -835,7 +835,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
init_deposit_transactions_count = 2
init_withdraw_transactions_count = 1
init_total_depositors_count = 2
dao_contract.update(total_deposit: init_total_deposit, depositors_count: init_depositors_count, interest_granted: init_interest_granted, deposit_transactions_count: init_deposit_transactions_count, withdraw_transactions_count: init_withdraw_transactions_count, total_depositors_count: init_total_depositors_count)
dao_contract.update(total_deposit: init_total_deposit, depositors_count: init_depositors_count, claimed_compensation: init_interest_granted, deposit_transactions_count: init_deposit_transactions_count, withdraw_transactions_count: init_withdraw_transactions_count, total_depositors_count: init_total_depositors_count)
prepare_node_data(HAS_UNCLES_BLOCK_NUMBER)
local_block = Block.find_by(number: HAS_UNCLES_BLOCK_NUMBER)
local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx")
Expand All @@ -845,7 +845,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
dao_contract.reload
assert_equal init_total_deposit, dao_contract.total_deposit
assert_equal init_depositors_count, dao_contract.depositors_count
assert_equal init_interest_granted, dao_contract.interest_granted
assert_equal init_interest_granted, dao_contract.claimed_compensation
assert_equal init_deposit_transactions_count, dao_contract.deposit_transactions_count
assert_equal init_withdraw_transactions_count, dao_contract.withdraw_transactions_count
assert_equal init_total_depositors_count, dao_contract.total_depositors_count
Expand Down Expand Up @@ -1086,7 +1086,7 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
local_block.update(block_hash: "0x419c632366c8eb9635acbb39ea085f7552ae62e1fdd480893375334a0f37d1bx")

VCR.use_cassette("blocks/#{DEFAULT_NODE_BLOCK_NUMBER}", record: :new_episodes) do
assert_difference -> { DaoContract.default_contract.reload.interest_granted }, -1000 do
assert_difference -> { DaoContract.default_contract.reload.claimed_compensation }, -1000 do
node_data_processor.call
end

Expand Down
16 changes: 4 additions & 12 deletions test/models/dao_contract_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class DaoContractTest < ActiveSupport::TestCase
should validate_presence_of(:total_deposit)
should validate_numericality_of(:total_deposit).
is_greater_than_or_equal_to(0)
should validate_presence_of(:interest_granted)
should validate_numericality_of(:interest_granted).
should validate_presence_of(:claimed_compensation)
should validate_numericality_of(:claimed_compensation).
is_greater_than_or_equal_to(0)
should validate_presence_of(:deposit_transactions_count)
should validate_numericality_of(:deposit_transactions_count).
Expand All @@ -24,8 +24,8 @@ class DaoContractTest < ActiveSupport::TestCase

test "should have correct columns" do
dao_contract = create(:dao_contract)
expected_attributes = %w(created_at deposit_transactions_count depositors_count id interest_granted total_deposit total_depositors_count updated_at withdraw_transactions_count)
assert_equal expected_attributes, dao_contract.attributes.keys.sort
expected_attributes = %w(created_at deposit_transactions_count depositors_count id claimed_compensation total_deposit total_depositors_count updated_at withdraw_transactions_count unclaimed_compensation)
assert_equal expected_attributes.sort, dao_contract.attributes.keys.sort
end

test "estimated apc when deposit period is less than one year" do
Expand Down Expand Up @@ -99,14 +99,6 @@ class DaoContractTest < ActiveSupport::TestCase
assert_equal latest_daily_statistic.unclaimed_compensation, dao_contract.unclaimed_compensation
end

test "claimed_compensation should return beginning of today value" do
dao_contract = create(:dao_contract, total_deposit: 10**21 * 100)
create(:daily_statistic)
latest_daily_statistic = DailyStatistic.order(id: :desc).first

assert_equal latest_daily_statistic.claimed_compensation, dao_contract.claimed_compensation
end

test "average_deposit_time should return beginning of today value" do
dao_contract = create(:dao_contract, total_deposit: 10**21 * 100)
create(:daily_statistic)
Expand Down

0 comments on commit e00ca49

Please sign in to comment.