Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ndev 2981 trace call overrides params #327

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e941a0e
add case to check stateOverrides nonce
romanova-natasha May 6, 2024
1ddb225
add dbg prints and run only one test
romanova-natasha May 6, 2024
d65c8e0
Merge branch 'develop' into NDEV-2981-traceCall-overrides-param
romanova-natasha May 7, 2024
fa8edd6
mv tests to new file, add cases for stateOverride check
romanova-natasha May 8, 2024
0ba594b
add cases for stateOverride check
romanova-natasha May 8, 2024
77f12c9
rm dbg
romanova-natasha May 8, 2024
ff3e9e1
link bugs to tests and skip these cases
romanova-natasha May 8, 2024
ade1a82
add blockOverride case using debug_traceCall request
romanova-natasha May 9, 2024
df78a65
Merge branch 'run-specific-test' into NDEV-2981-traceCall-overrides-p…
romanova-natasha May 10, 2024
00b1140
Merge branch 'run-specific-test' into NDEV-2981-traceCall-overrides-p…
romanova-natasha May 10, 2024
defad66
add case with blockOverrides for debug_traceCall method
romanova-natasha May 10, 2024
e24d8eb
add comment to test_stateOverrides_eth_call_override_code case
romanova-natasha May 10, 2024
796d273
minor refactoring
romanova-natasha May 10, 2024
787e74c
add negative cases to override params suite, minor refactoring, add c…
romanova-natasha May 10, 2024
e5df8b6
add cases for blockOverrides with time parameter
romanova-natasha May 10, 2024
bf757c4
add negative cases for stateDiff param
romanova-natasha May 10, 2024
9721b9e
add cases for stateOverride nonce, balance
romanova-natasha May 10, 2024
5d887bb
add cases for stateOverride code parameter
romanova-natasha May 10, 2024
17321d9
enable stateDiff cases which were fixed
romanova-natasha May 10, 2024
23f2e86
fix stateOverride balance tests, add a negative case: insufficient ba…
romanova-natasha May 11, 2024
8212775
add blockOverrides time and number case, minor refactoring, add case …
romanova-natasha May 13, 2024
e6be41d
add case: stateOverrides and blockOverrides in one requests, add case…
romanova-natasha May 13, 2024
403113e
refactoring of debug_methods suite according to the recent changes
romanova-natasha May 13, 2024
6ffeb7e
add stateOverride cases for state param
romanova-natasha May 14, 2024
e3c30a4
fix tests stateOverrides with code param: add check of trace with ove…
romanova-natasha May 14, 2024
a9c1620
add contract function with retrieving sender balance, check balance i…
romanova-natasha May 14, 2024
0172479
fix: add make_raw_tx where it is nedeed
romanova-natasha May 14, 2024
355a9f5
add function: fill params for prestateTracer call
romanova-natasha May 14, 2024
8d8ba5a
mv storage contract to separate class
romanova-natasha May 14, 2024
8958546
fix review
romanova-natasha May 14, 2024
18f5763
fix review: do not wait transaction
romanova-natasha May 14, 2024
73a41c8
add case for stateDiff: check storage with 2 indixes
romanova-natasha May 15, 2024
26f4869
rm code field from state and stateDiff requests
romanova-natasha May 15, 2024
2db27a7
fix state/stateDiff param format: should be hex string 32 bytes
romanova-natasha May 15, 2024
2cd746a
fix state/stateDiff param format: should be hex string 32 bytes
romanova-natasha May 15, 2024
6fba2c5
fix blockOverrides: add is_tx_block flag to control block number in r…
romanova-natasha May 15, 2024
37aca39
fix stateDiff cases
romanova-natasha May 17, 2024
ecc79a1
rm dbg info
romanova-natasha May 17, 2024
25b3ca6
fix state cases
romanova-natasha May 17, 2024
edf0c62
Merge remote-tracking branch 'origin/develop' into NDEV-2981-traceCal…
romanova-natasha May 17, 2024
bcd368c
rm wait for get transaction method
romanova-natasha May 22, 2024
3380e11
Merge remote-tracking branch 'origin/develop' into NDEV-2981-traceCal…
romanova-natasha May 23, 2024
6a2e627
rm wait transaction method
romanova-natasha May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions contracts/common/StorageSoliditySource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ pragma solidity >=0.4.0;
*/
contract Storage {
uint256 number;
uint256 time;
uint256[] public values;

/**
* @dev Stores value in variable
* @param num value to store
*/
function store(uint256 num) public {
number = num;
values = [number];
}

/**
Expand All @@ -30,14 +33,31 @@ contract Storage {
function at(address _addr) public view returns (bytes memory) {
return _addr.code;
}

function storeBlock() public {
number = block.number;
values = [number];
}

function storeBlockTimestamp() public returns (uint256) {
number = block.timestamp;
values = [number];
return block.timestamp;
}

function storeBlockInfo() public {
number = block.number;
time = block.timestamp;
values = [number, time];
}
}

contract StorageMultipleVars {
string public data = "test";
uint256 constant public number = 1;
uint256 public constant number = 1;
uint256 public notSet;

function setData(string memory _data) public {
function setData(string memory _data) public {
data = _data;
}
}
}
800 changes: 800 additions & 0 deletions integration/tests/tracer/test_override_params.py

Large diffs are not rendered by default.

60 changes: 24 additions & 36 deletions integration/tests/tracer/test_tracer_debug_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from utils.web3client import NeonChainWeb3Client
from utils.accounts import EthAccounts
from utils.tracer_client import TracerClient
from utils.helpers import padhex
from integration.tests.tracer.test_tracer_historical_methods import call_storage

SCHEMAS = "./integration/tests/tracer/schemas/"
Expand All @@ -37,43 +38,33 @@ def validate_response_result(self, response):
validator = Draft4Validator(schema)
assert validator.is_valid(response["result"])

# NDEV-3009
def test_debug_trace_call_invalid_params(self):
response = self.tracer_api.send_rpc(method="debug_traceCall", params=[{}, "0x0"])
assert "error" in response, "No errors in response"
assert response["error"]["code"] == -32603, "Invalid error code"
assert response["error"]["message"] == "neon_api::trace failed"

def test_debug_trace_call_empty_params_valid_block(self):
@pytest.mark.skip("NDEV-2998")
def test_debug_trace_call_empty_params_valid_block(self, storage_contract):
sender_account = self.accounts[0]
recipient_account = self.accounts[1]
receipt = self.web3_client.send_neon(sender_account, recipient_account, 0.1)
assert receipt["status"] == 1
tx_hash = receipt["transactionHash"].hex()

wait_condition(
lambda: self.web3_client.get_transaction_by_hash(tx_hash) is not None,
timeout_sec=10,
)
tx_info = self.web3_client.get_transaction_by_hash(tx_hash)
store_value = random.randint(1, 100)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", self.web3_client)
tx_info = self.web3_client.wait_get_transaction_by_hash(receipt["transactionHash"].hex())

response = self.tracer_api.send_rpc(method="debug_traceCall", params=[{}, hex(tx_info["blockNumber"])])

assert "error" in response, "No errors in response"
assert response["error"]["code"] == -32603, "Invalid error code"
assert response["error"]["message"] == "neon_api::trace failed"
assert "error" not in response, "Error in response"
assert response["result"]["returnValue"] == ""
self.validate_response_result(response)

def test_debug_trace_call_zero_eth_call(self):
sender_account = self.accounts[0]
recipient_account = self.accounts[1]
receipt = self.web3_client.send_neon(sender_account, recipient_account, 0.1)
assert receipt["status"] == 1
tx_hash = receipt["transactionHash"].hex()

wait_condition(
lambda: self.web3_client.get_transaction_by_hash(tx_hash) is not None,
timeout_sec=10,
)
tx_info = self.web3_client.get_transaction_by_hash(tx_hash)
tx_info = self.web3_client.wait_get_transaction_by_hash(receipt["transactionHash"].hex())
kristinaNikolaevaa marked this conversation as resolved.
Show resolved Hide resolved

params = [
{
Expand All @@ -93,17 +84,12 @@ def test_debug_trace_call_zero_eth_call(self):
assert response["result"]["returnValue"] == ""
self.validate_response_result(response)

def test_debug_trace_call_non_zero_eth_call(self, storage_contract, web3_client):
def test_debug_trace_call_non_zero_eth_call(self, storage_contract):
sender_account = self.accounts[0]
store_value = random.randint(1, 100)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", web3_client)
tx_hash = receipt["transactionHash"].hex()

wait_condition(
lambda: self.web3_client.get_transaction_by_hash(tx_hash) is not None,
timeout_sec=10,
)
tx_info = self.web3_client.get_transaction_by_hash(tx_hash)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", self.web3_client)

tx_info = self.web3_client.wait_get_transaction_by_hash(receipt["transactionHash"].hex())
kristinaNikolaevaa marked this conversation as resolved.
Show resolved Hide resolved

params = [
{
Expand All @@ -119,7 +105,7 @@ def test_debug_trace_call_non_zero_eth_call(self, storage_contract, web3_client)
response = self.tracer_api.send_rpc_and_wait_response("debug_traceCall", params)

assert "error" not in response, "Error in response"
assert 1 <= int(response["result"]["returnValue"], 16) <= 100
assert response["result"]["returnValue"] == padhex(hex(store_value), 64)[2:]
self.validate_response_result(response)

def test_debug_trace_transaction(self):
Expand All @@ -132,24 +118,26 @@ def test_debug_trace_transaction(self):
assert "error" not in response, "Error in response"
self.validate_response_result(response)

def test_debug_trace_transaction_non_zero_trace(self, web3_client, storage_contract):
def test_debug_trace_transaction_non_zero_trace(self, storage_contract):
sender_account = self.accounts[0]
store_value = random.randint(1, 100)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", web3_client)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", self.web3_client)

response = self.tracer_api.send_rpc_and_wait_response("debug_traceTransaction", [receipt["transactionHash"].hex()])

assert "error" not in response, "Error in response"
assert 1 <= int(response["result"]["returnValue"], 16) <= 100
assert response["result"]["returnValue"] == padhex(hex(store_value), 64)[2:]
self.validate_response_result(response)

def test_debug_trace_transaction_hash_without_prefix(self, storage_contract, web3_client):
def test_debug_trace_transaction_hash_without_prefix(self, storage_contract):
sender_account = self.accounts[0]
store_value = random.randint(1, 100)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", web3_client)
_, _, receipt = call_storage(sender_account, storage_contract, store_value, "blockNumber", self.web3_client)

response = self.tracer_api.send_rpc_and_wait_response("debug_traceTransaction", [receipt["transactionHash"].hex()[2:]])

assert "error" not in response, "Error in response"
assert 1 <= int(response["result"]["returnValue"], 16) <= 100
assert response["result"]["returnValue"] == padhex(hex(store_value), 64)[2:]
self.validate_response_result(response)

@pytest.mark.parametrize("hash", [6, "0x0", "", "f23e554"])
Expand Down
1 change: 1 addition & 0 deletions integration/tests/tracer/test_tracer_historical_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def store_value(sender_account, value, storage_contract, web3_client):
)
receipt = web3_client.send_transaction(sender_account, instruction_tx)
assert receipt["status"] == 1
return receipt


def retrieve_value(sender_account, storage_contract, web3_client):
Expand Down
5 changes: 4 additions & 1 deletion utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,7 @@ def serialize_instruction(program_id, instruction) -> bytes:
serialized += key.is_writable.to_bytes(1, "little")

serialized += len(instruction.data).to_bytes(8, "little") + instruction.data
return serialized
return serialized

def padhex(s, size):
return '0x' + s[2:].zfill(size)
4 changes: 2 additions & 2 deletions utils/tracer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def __init__(self, url):
self.url = url
self.tracer_api = JsonRPCSession(url)

def send_rpc_and_wait_response(self, method_name, params):
def send_rpc_and_wait_response(self, method_name, params, req_type=None):
wait_condition(
lambda: self.tracer_api.send_rpc(method=method_name, params=params)["result"]
lambda: self.tracer_api.send_rpc(method=method_name, params=params, req_type=req_type)["result"]
is not None,
timeout_sec=120,
)
Expand Down
12 changes: 12 additions & 0 deletions utils/web3client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from utils import helpers
from utils.consts import InputTestConstants, Unit
from utils.helpers import decode_function_signature
from utils.helpers import wait_condition

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -109,6 +110,17 @@ def get_transaction_by_hash(self, transaction_hash):
return self._web3.eth.get_transaction(transaction_hash)
except TransactionNotFound:
return None

@allure.step("Get transaction by hash with wait for result is available")
def wait_get_transaction_by_hash(self, transaction_hash, timeout=10):
kristinaNikolaevaa marked this conversation as resolved.
Show resolved Hide resolved
try:
wait_condition(
lambda: self._web3.eth.get_transaction(transaction_hash) is not None,
timeout_sec=timeout,
)
return self._web3.eth.get_transaction(transaction_hash)
except TransactionNotFound:
return None

@allure.step("Get gas price")
def gas_price(self):
Expand Down