Skip to content

Commit

Permalink
test: add consensus related types
Browse files Browse the repository at this point in the history
Consensus, ProposalWindow and RationalU256
  • Loading branch information
shaojunda committed Jan 11, 2021
1 parent d29fe4a commit 4c5b90b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
61 changes: 61 additions & 0 deletions spec/ckb/types/consensus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
RSpec.describe CKB::Types::Consensus do
let(:consensus_h) do
{
:block_version=>"0x0",
:cellbase_maturity=>"0x10000000000",
:dao_type_hash=>"0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
:epoch_duration_target=>"0x3840",
:genesis_hash=>"0x823b2ff5785b12da8b1363cac9a5cbe566d8b715a4311441b119c39a0367488c",
:id=>"ckb_dev",
:initial_primary_epoch_reward=>"0xae6c73c3e070",
:max_block_bytes=>"0x91c08",
:max_block_cycles=>"0x2540be400",
:max_block_proposals_limit=>"0x5dc",
:max_uncles_num=>"0x2",
:median_time_block_count=>"0x25",
:orphan_rate_target=>{:denom=>"0x28", :numer=>"0x1"},
:permanent_difficulty_in_dummy=>false,
:primary_epoch_reward_halving_interval=>"0x2238",
:proposer_reward_ratio=>{:denom=>"0xa", :numer=>"0x4"},
:secondary_epoch_reward=>"0x37d0c8e28542",
:secp256k1_blake160_multisig_all_type_hash=>"0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8",
:secp256k1_blake160_sighash_all_type_hash=>"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
:tx_proposal_window=>{:closest=>"0x2", :farthest=>"0xa"},
:tx_version=>"0x0",
:type_id_code_hash=>"0x00000000000000000000000000000000000000000000000000545950455f4944"
}
end

let(:consensus) { CKB::Types::Consensus.from_h(consensus_h) }

it "from h" do
expect(consensus).to be_a(CKB::Types::Consensus)
expect(consensus.id).to eq consensus_h[:id]
expect(consensus.genesis_hash).to eq consensus_h[:genesis_hash]
expect(consensus.dao_type_hash).to eq consensus_h[:dao_type_hash]
expect(consensus.secp256k1_blake160_sighash_all_type_hash).to eq consensus_h[:secp256k1_blake160_sighash_all_type_hash]
expect(consensus.secp256k1_blake160_multisig_all_type_hash).to eq consensus_h[:secp256k1_blake160_multisig_all_type_hash]
expect(CKB::Utils.to_hex(consensus.initial_primary_epoch_reward)).to eq consensus_h[:initial_primary_epoch_reward]
expect(CKB::Utils.to_hex(consensus.secondary_epoch_reward)).to eq consensus_h[:secondary_epoch_reward]
expect(CKB::Utils.to_hex(consensus.max_uncles_num)).to eq consensus_h[:max_uncles_num]
expect(consensus.orphan_rate_target.to_h).to eq consensus_h[:orphan_rate_target]
expect(CKB::Utils.to_hex(consensus.epoch_duration_target)).to eq consensus_h[:epoch_duration_target]
expect(consensus.tx_proposal_window.to_h).to eq consensus_h[:tx_proposal_window]
expect(consensus.proposer_reward_ratio.to_h).to eq consensus_h[:proposer_reward_ratio]
expect(consensus.cellbase_maturity).to eq consensus_h[:cellbase_maturity]
expect(CKB::Utils.to_hex(consensus.max_block_cycles)).to eq consensus_h[:max_block_cycles]
expect(CKB::Utils.to_hex(consensus.max_block_bytes)).to eq consensus_h[:max_block_bytes]
expect(CKB::Utils.to_hex(consensus.block_version)).to eq consensus_h[:block_version]
expect(CKB::Utils.to_hex(consensus.tx_version)).to eq consensus_h[:tx_version]
expect(consensus.type_id_code_hash).to eq consensus_h[:type_id_code_hash]
expect(CKB::Utils.to_hex(consensus.max_block_proposals_limit)).to eq consensus_h[:max_block_proposals_limit]
expect(CKB::Utils.to_hex(consensus.primary_epoch_reward_halving_interval)).to eq consensus_h[:primary_epoch_reward_halving_interval]
expect(consensus.permanent_difficulty_in_dummy).to eq consensus_h[:permanent_difficulty_in_dummy]
end

it "to_h" do
expect(
consensus.to_h
).to eq consensus_h
end
end
23 changes: 23 additions & 0 deletions spec/ckb/types/proposal_window_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.describe CKB::Types::ProposalWindow do
let(:proposal_window_h) do
{
:closest=>"0x2",
:farthest=>"0xa"
}
end

let(:proposal_window) { CKB::Types::ProposalWindow.from_h(proposal_window_h) }

it "from h" do
expect(proposal_window).to be_a(CKB::Types::ProposalWindow)
proposal_window_h.each do |key, value|
expect(proposal_window.public_send(key)).to eq value.hex
end
end

it "to_h" do
expect(
proposal_window.to_h
).to eq proposal_window_h
end
end
23 changes: 23 additions & 0 deletions spec/ckb/types/rational_u256_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.describe CKB::Types::RationalU256 do
let(:rationalu256_h) do
{
:denom=>"0x28",
:numer=>"0x1"
}
end

let(:rationalu256) { CKB::Types::RationalU256.from_h(rationalu256_h) }

it "from h" do
expect(rationalu256).to be_a(CKB::Types::RationalU256)
rationalu256_h.each do |key, value|
expect(rationalu256.public_send(key)).to eq value
end
end

it "to_h" do
expect(
rationalu256.to_h
).to eq rationalu256_h
end
end

0 comments on commit 4c5b90b

Please sign in to comment.