Skip to content

Commit

Permalink
feat: update calculate min capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Aug 7, 2019
1 parent 01b02aa commit 1945c43
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/ckb/types/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def initialize(code_hash:, args:, hash_type: "Data")

# @return [Integer] Byte
def calculate_bytesize
bytesize = 0
bytesize = Utils.hex_to_bin(@code_hash).bytesize if @code_hash
bytesize = 1
bytesize += Utils.hex_to_bin(@code_hash).bytesize if @code_hash
(@args || []).map { |arg| Utils.hex_to_bin(arg).bytesize }.reduce(bytesize, &:+)
end

Expand Down
8 changes: 4 additions & 4 deletions spec/ckb/types/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
it "default" do
expect(
output.calculate_bytesize
).to eq 60
).to eq 93
end

it "with data" do
output.instance_variable_set(:@data, "0x1234")
expect(
output.calculate_bytesize
).to eq 62
).to eq 93
end

it "with type script" do
Expand All @@ -32,13 +32,13 @@

expect(
output.calculate_bytesize
).to eq 92
).to eq (93 + 33)
end
end

it "calculate min capacity" do
expect(
output.calculate_min_capacity
).to eq CKB::Utils.byte_to_shannon(60)
).to eq CKB::Utils.byte_to_shannon(93)
end
end
4 changes: 2 additions & 2 deletions spec/ckb/types/script_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.describe CKB::Types::Script do
let(:script) do
code_hash = CKB::Blake2b.hexdigest(
Utils.hex_to_bin(
CKB::Utils.hex_to_bin(
"0x1400000000000e00100000000c000800000004000e0000000c00000014000000740100000000000000000600080004000600000004000000580100007f454c460201010000000000000000000200f3000100000078000100000000004000000000000000980000000000000005000000400038000100400003000200010000000500000000000000000000000000010000000000000001000000000082000000000000008200000000000000001000000000000001459308d00573000000002e7368737472746162002e74657874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000780001000000000078000000000000000a000000000000000000000000000000020000000000000000000000000000000100000003000000000000000000000000000000000000008200000000000000110000000000000000000000000000000100000000000000000000000000000000000000"
)
)
Expand Down Expand Up @@ -29,7 +29,7 @@
args: args
)
end
let(:min_capacity) { 52 }
let(:min_capacity) { 53 }

it "success" do
expect(
Expand Down

0 comments on commit 1945c43

Please sign in to comment.