Skip to content

Commit

Permalink
add doctests for logging operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed May 1, 2018
1 parent 2bb268b commit 6522865
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/evm/log_entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ defmodule EVM.LogEntry do
## Examples
iex> log = EVM.LogEntry.new(0, [0, 0, 0, 0], <<1>>)
iex> EVM.LogEntry.new(0, [0, 0, 0, 0], <<1>>)
%EVM.LogEntry{
address: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>,
data: <<1>>,
topics: [0, 0, 0, 0]
}
iex> log = EVM.LogEntry.new( <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47, 109, 45, 108, 123, 94, 198>>, [0, 0, 0, 0], <<1>>)
iex> EVM.LogEntry.new( <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47, 109, 45, 108, 123, 94, 198>>, [0, 0, 0, 0], <<1>>)
%EVM.LogEntry{
address: <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47, 109,
45, 108, 123, 94, 198>>,
Expand Down
189 changes: 177 additions & 12 deletions lib/evm/operation/logging.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,42 @@ defmodule EVM.Operation.Logging do
@doc """
Append log record with no topics.
TODO: Implement opcode
## Examples
iex> env = %EVM.ExecEnv{
...> account_interface: %EVM.Interface.Mock.MockAccountInterface{},
...> address: 87579061662017136990230301793909925042452127430,
...> block_interface: %EVM.Interface.Mock.MockBlockInterface{}
...> }
iex> machine_state = %EVM.MachineState{
...> active_words: 1,
...> gas: 99351,
...> memory: <<255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255>>,
...> previously_active_words: 0,
...> program_counter: 40,
...> stack: []
...> }
iex> sub_state = %EVM.SubState{logs: [], refund: 0, suicide_list: []}
iex> vm_map = %{sub_state: sub_state, exec_env: env, machine_state: machine_state}
iex> EVM.Operation.Logging.log0([0, 32], vm_map)
%{
sub_state: %EVM.SubState{
logs: [
%EVM.LogEntry{
address: <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47,
109, 45, 108, 123, 94, 198>>,
data: <<255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255>>,
topics: []
}
],
refund: 0,
suicide_list: []
}
}
"""
@spec log0(Operation.stack_args(), Operation.vm_map()) :: Operation.op_result()
def log0(args, vm_map) do
Expand All @@ -17,10 +49,43 @@ defmodule EVM.Operation.Logging do
@doc """
Append log record with one topic.
TODO: Implement opcode
## Examples
iex> env = %EVM.ExecEnv{
...> account_interface: %EVM.Interface.Mock.MockAccountInterface{},
...> address: 87579061662017136990230301793909925042452127430,
...> block_interface: %EVM.Interface.Mock.MockBlockInterface{}
...> }
iex> machine_state = %EVM.MachineState{
...> active_words: 1,
...> gas: 99351,
...> memory: <<170, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 204, 221>>,
...> previously_active_words: 0,
...> program_counter: 40,
...> stack: []
...> }
iex> sub_state = %EVM.SubState{logs: [], refund: 0, suicide_list: []}
iex> vm_map = %{sub_state: sub_state, exec_env: env, machine_state: machine_state}
iex> args = [0, 32, 115792089237316195423570985008687907853269984665640564039457584007913129639935]
iex> EVM.Operation.Logging.log1(args, vm_map)
%{
sub_state: %EVM.SubState{
logs: [
%EVM.LogEntry{
address: <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47,
109, 45, 108, 123, 94, 198>>,
data: <<170, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 204, 221>>,
topics: [115792089237316195423570985008687907853269984665640564039457584007913129639935]
}
],
refund: 0,
suicide_list: []
}
}
"""
@spec log1(Operation.stack_args(), Operation.vm_map()) :: Operation.op_result()
def log1(args, vm_map) do
Expand All @@ -30,11 +95,46 @@ defmodule EVM.Operation.Logging do
@doc """
Append log record with two topics.
TODO: Implement opcode
## Examples
iex> env = %EVM.ExecEnv{
...> account_interface: %EVM.Interface.Mock.MockAccountInterface{},
...> address: 87579061662017136990230301793909925042452127430,
...> block_interface: %EVM.Interface.Mock.MockBlockInterface{}
...> }
iex> machine_state = %EVM.MachineState{
...> active_words: 1,
...> gas: 99351,
...> memory: <<170, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 204, 221>>,
...> previously_active_words: 0,
...> program_counter: 40,
...> stack: []
...> }
iex> sub_state = %EVM.SubState{logs: [], refund: 0, suicide_list: []}
iex> vm_map = %{sub_state: sub_state, exec_env: env, machine_state: machine_state}
iex> args = [0, 32,
...> 115792089237316195423570985008687907853269984665640564039457584007913129639935,
...> 115792089237316195423570985008687907853269984665640564039457584007913129639935]
iex> EVM.Operation.Logging.log1(args, vm_map)
%{
sub_state: %EVM.SubState{
logs: [
%EVM.LogEntry{
address: <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47,
109, 45, 108, 123, 94, 198>>,
data: <<170, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 204, 221>>,
topics: [115792089237316195423570985008687907853269984665640564039457584007913129639935,
115792089237316195423570985008687907853269984665640564039457584007913129639935]
}
],
refund: 0,
suicide_list: []
}
}
"""
@spec log2(Operation.stack_args(), Operation.vm_map()) :: Operation.op_result()
def log2(args, vm_map) do
Expand All @@ -44,11 +144,41 @@ defmodule EVM.Operation.Logging do
@doc """
Append log record with three topics.
TODO: Implement opcode
## Examples
iex> env = %EVM.ExecEnv{
...> account_interface: %EVM.Interface.Mock.MockAccountInterface{},
...> address: 87579061662017136990230301793909925042452127430,
...> block_interface: %EVM.Interface.Mock.MockBlockInterface{}
...> }
iex> machine_state = %EVM.MachineState{
...> active_words: 1,
...> gas: 99351,
...> memory: <<170, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 204, 221>>,
...> previously_active_words: 0,
...> program_counter: 40,
...> stack: []
...> }
iex> sub_state = %EVM.SubState{logs: [], refund: 0, suicide_list: []}
iex> vm_map = %{sub_state: sub_state, exec_env: env, machine_state: machine_state}
iex> args = [1, 0, 0, 0, 0]
iex> EVM.Operation.Logging.log1(args, vm_map)
%{
sub_state: %EVM.SubState{
logs: [
%EVM.LogEntry{
address: <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47,
109, 45, 108, 123, 94, 198>>,
data: "",
topics: [0, 0, 0]
}
],
refund: 0,
suicide_list: []
}
}
"""
@spec log3(Operation.stack_args(), Operation.vm_map()) :: Operation.op_result()
def log3(args, vm_map) do
Expand All @@ -58,10 +188,45 @@ defmodule EVM.Operation.Logging do
@doc """
Append log record with four topics.
TODO: Implement opcode
## Examples
iex> env = %EVM.ExecEnv{
...> account_interface: %EVM.Interface.Mock.MockAccountInterface{},
...> address: 87579061662017136990230301793909925042452127430,
...> block_interface: %EVM.Interface.Mock.MockBlockInterface{}
...> }
iex> machine_state = %EVM.MachineState{
...> active_words: 1,
...> gas: 99351,
...> memory: <<127, 170, 187, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 204, 221, 96, 0, 82, 96, 0, 96, 0, 96, 0, 96, 0, 96,
...> 1, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
...> 255, 255, 255, 255, 164>>,
...> previously_active_words: 0,
...> program_counter: 40,
...> stack: []
...> }
iex> sub_state = %EVM.SubState{logs: [], refund: 0, suicide_list: []}
iex> vm_map = %{sub_state: sub_state, exec_env: env, machine_state: machine_state}
iex> args = [115792089237316195423570985008687907853269984665640564039457584007913129639935,
...> 1, 0, 0, 0, 0]
iex> EVM.Operation.Logging.log1(args, vm_map)
%{
sub_state: %EVM.SubState{
logs: [
%EVM.LogEntry{
address: <<15, 87, 46, 82, 149, 197, 127, 21, 136, 111, 155, 38, 62, 47,
109, 45, 108, 123, 94, 198>>,
data: <<0>>,
topics: [0, 0, 0, 0]
}
],
refund: 0,
suicide_list: []
}
}
"""
@spec log4(Operation.stack_args(), Operation.vm_map()) :: Operation.op_result()
def log4(args, vm_map) do
Expand Down

0 comments on commit 6522865

Please sign in to comment.