-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_debug.py
105 lines (93 loc) · 6.03 KB
/
test_debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This test is not guaranteed to run smoothly,
# because the assembly instructions can differ from compilers and optimizers
from neo_fairy_client.rpc import FairyClient
from neo_fairy_client.utils.types import Hash160Str, Signer, WitnessScope
from neo_fairy_client import VMState
target_url = 'http://127.0.0.1:16868'
wallet_address = 'Nb2CHYY5wTh2ac58mTue5S3wpG6bQv5hSY'
wallet_scripthash = Hash160Str.from_address(wallet_address)
borrower_address = 'NaainHz563mJLsHRsPD4NrKjMEQGBXXJY9'
borrower_scripthash = Hash160Str.from_address(borrower_address)
lender = Signer(wallet_scripthash, scopes=WitnessScope.Global)
borrower = Signer(borrower_scripthash, scopes=WitnessScope.Global)
fairy_session = 'debug'
client = FairyClient(target_url, wallet_address, with_print=True, fairy_session=fairy_session, signers=lender)
client.new_snapshots_from_current_system()
client.set_gas_balance(100_0000_0000)
test_nopht_d_hash = Hash160Str('0x9ffb143877c7a0776f3b0dc88f55c4ad16c689c6')
client.delete_debug_info(test_nopht_d_hash)
# test_nopht_d_hash = client.virutal_deploy_from_path('../NFTLoan/NophtD/bin/sc/TestNophtD.nef')
client.contract_scripthash = client.virutal_deploy_from_path('../NFTLoan/NFTLoan/bin/sc/NFTFlashLoan.nef')
print(client.contract_scripthash)
print(client.list_filenames_of_contract())
assert client.list_debug_info() == [client.contract_scripthash]
client.delete_source_code_breakpoints()
print(client.set_assembly_breakpoints(0))
print(client.set_assembly_breakpoints(3))
try:
client.set_assembly_breakpoints(1)
except ValueError as e:
print(e)
pass
assert client.list_assembly_breakpoints() == [0, 3]
assert client.set_source_code_breakpoint('NFTLoan.cs', 88) == [{'filename': 'NFTLoan.cs', 'line': 88}] # get => "NEPHRENT";
assert client.set_source_code_breakpoints(['NFTLoan.cs', 253]) == [{'filename': 'NFTLoan.cs', 'line': 253}] # ExecutionEngine.Assert(externalTokenId.Length <= 64, "tokenId.Length > 64");
assert client.list_source_code_breakpoints() == [{'filename': 'NFTLoan.cs', 'line': 88}, {'filename': 'NFTLoan.cs', 'line': 253}]
print(method_info := client.get_method_by_instruction_pointer(3309)) # ExecutionEngine.Assert(externalTokenContract != Runtime.ExecutingScriptHash, "Cannot register rental for tokens issued by this contract");
assert 'RegisterRental' in method_info['id']
print(rpc_breakpoint := client.debug_function_with_session('registerRental', [wallet_scripthash, test_nopht_d_hash, 68, '\x01', 5, 7, True]))
assert rpc_breakpoint.break_reason == 'SourceCodeBreakpoint' and rpc_breakpoint.source_line_num == 253
print(rpc_breakpoint := client.debug_step_over_assembly())
assert rpc_breakpoint.break_reason == 'None' and rpc_breakpoint.source_filename == 'ByteString.cs' and rpc_breakpoint.source_line_num == 31
print(rpc_breakpoint := client.debug_step_over_assembly())
assert rpc_breakpoint.break_reason == 'None' and rpc_breakpoint.source_line_num == 253
print(rpc_breakpoint := client.debug_step_into()) # Nothing to step into; same as step over
assert rpc_breakpoint.break_reason == 'SourceCode' and rpc_breakpoint.source_line_num == 254
print(rpc_breakpoint := client.debug_step_over())
assert rpc_breakpoint.break_reason == 'SourceCode' and rpc_breakpoint.source_line_num == 257
print(rpc_breakpoint := client.debug_step_over_source_code())
assert rpc_breakpoint.break_reason == 'SourceCode' and rpc_breakpoint.source_line_num == 258
# print(rpc_breakpoint := client.debug_step_out())
print(client.get_local_variables())
print(client.get_arguments())
print(client.get_static_fields())
print(client.get_evaluation_stack())
print(client.get_instruction_pointer())
print(client.get_variable_value_by_name("flashLoanPrice"))
print(client.get_variable_names_and_values())
assert rpc_breakpoint.state == VMState.BREAK
print(rpc_breakpoint := client.debug_step_into())
assert rpc_breakpoint.break_reason == 'None' and rpc_breakpoint.state == VMState.FAULT
assert rpc_breakpoint.state == VMState.FAULT # we did not deploy NophtD here
assert client.previous_raw_result['result']['sourcefilename'] == 'Contract.cs'
assert client.previous_raw_result['result']['sourcelinenum'] == 42
assert 'Called Contract Does Not Exist' in client.previous_raw_result['result']['exception']
print(client.get_contract_opcode_coverage())
print(client.clear_contract_opcode_coverage())
for k, v in client.get_contract_opcode_coverage().items():
assert v is False
# deploy NophtD
test_nopht_d_hash = client.virutal_deploy_from_path('../NFTLoan/NophtD/bin/sc/TestNophtD.nef', auto_set_client_contract_scripthash=False)
print(rpc_breakpoint := client.debug_function_with_session('registerRental', [wallet_scripthash, test_nopht_d_hash, 68, '\x01', 5, 7, True]))
assert rpc_breakpoint.break_reason == 'SourceCodeBreakpoint' and rpc_breakpoint.source_line_num == 253
client.set_source_code_breakpoints(['NFTLoan.cs', 258])
client.set_source_code_breakpoints(['NFTLoan.cs', 269])
print(rpc_breakpoint := client.debug_continue())
assert rpc_breakpoint.break_reason == 'SourceCodeBreakpoint' and rpc_breakpoint.source_line_num == 258
print(rpc_breakpoint := client.debug_step_into())
assert rpc_breakpoint.break_reason == 'Call' and rpc_breakpoint.source_line_num == 96
print(rpc_breakpoint := client.debug_step_out())
assert rpc_breakpoint.break_reason == 'Return' and rpc_breakpoint.source_line_num == 258
print(rpc_breakpoint := client.debug_step_into())
assert rpc_breakpoint.break_reason == 'SourceCode' and rpc_breakpoint.source_line_num == 257
print(rpc_breakpoint := client.debug_step_out())
assert rpc_breakpoint.break_reason == 'SourceCodeBreakpoint' and rpc_breakpoint.source_line_num == 269
print(rpc_breakpoint := client.debug_step_over())
assert rpc_breakpoint.break_reason == 'SourceCode' and rpc_breakpoint.source_line_num == 270
print(client.delete_assembly_breakpoints(0))
print(client.delete_assembly_breakpoints())
print(client.delete_source_code_breakpoints(['NFTLoan.cs', 253]))
print(client.delete_source_code_breakpoints(['NFTLoan.cs', 269]))
print(client.delete_source_code_breakpoints([]))
print(client.delete_debug_info(client.contract_scripthash))
print(client.delete_snapshots(fairy_session))