Skip to content

Commit

Permalink
fix(resharding): fixed the resharding_rpc_tx nayduck test (near#10700)
Browse files Browse the repository at this point in the history
Something's changed and now when submitting the transaction the result
has status "EXECUTED" and when getting the status later via RPC the
result has status "FINAL". Previously the test was asserting equality of
those, now adjusted to accomodate the different statuses.

First commit is just a minor refactor and the second one is the actual
fix. Best reviewed separately.
  • Loading branch information
wacban authored Mar 5, 2024
1 parent 5048119 commit ac5cba2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pytest/lib/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def start(self,
self.wait_for_rpc(10)
except:
logger.error(
'=== failed to start node, rpc does not ready in 10 seconds')
'=== failed to start node, rpc is not ready in 10 seconds')

def run_cmd(self, *, cmd: tuple, extra_env: typing.Dict[str, str] = dict()):

Expand Down
53 changes: 32 additions & 21 deletions pytest/tests/sanity/resharding_rpc_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,24 @@
import sys
import unittest
import pathlib
import copy

sys.path.append(str(pathlib.Path(__file__).resolve().parents[2] / 'lib'))

from configured_logger import logger
import cluster
from resharding_lib import get_target_shard_layout_version, get_target_num_shards, get_genesis_config_changes, get_client_config_changes
from resharding_lib import ReshardingTestBase, get_genesis_config_changes, get_client_config_changes
import transaction
from utils import MetricsTracker, poll_blocks
import key

STARTING_AMOUNT = 123 * (10**24)


class ReshardingRpcTx(unittest.TestCase):
class ReshardingRpcTx(ReshardingTestBase):

def setUp(self) -> None:
self.epoch_length = 5
self.config = cluster.load_config()
self.binary_protocol_version = cluster.get_binary_protocol_version(
self.config)
assert self.binary_protocol_version is not None

self.target_shard_layout_version = get_target_shard_layout_version(
self.binary_protocol_version)
self.target_num_shards = get_target_num_shards(
self.binary_protocol_version)
super().setUp(epoch_length=5)

def __setup_account(self, account_id, nonce):
""" Create an account with full access key and balance. """
Expand All @@ -60,6 +52,20 @@ def __submit_transfer_tx(self, from_key, to_account_id, nonce):
def __verify_tx_status(self, transfer_response, sender_account_id):
tx_hash = transfer_response['result']['transaction']['hash']
response = self.node.get_tx(tx_hash, sender_account_id)

self.assertEqual(
transfer_response['result']['final_execution_status'],
'EXECUTED',
)
self.assertEqual(
response['result']['final_execution_status'],
'FINAL',
)

transfer_response = copy.deepcopy(transfer_response)
transfer_response['result']['final_execution_status'] = "IGNORE_ME"
response['result']['final_execution_status'] = "IGNORE_ME"

assert response == transfer_response, response
pass

Expand All @@ -74,7 +80,8 @@ def test_resharding_rpc_tx(self):
num_shards=1,
config=self.config,
genesis_config_changes=genesis_config_changes,
client_config_changes=client_config_changes)
client_config_changes=client_config_changes,
)
self.node = nodes[0]

# The shard boundaries are at "kkuuue2akv_1630967379.near" and "tge-lockup.sweat" for shard 3 and 4
Expand All @@ -88,10 +95,16 @@ def test_resharding_rpc_tx(self):
poll_blocks(self.node)

# Submit a transfer transaction between the accounts, we would verify the transaction status later
response0 = self.__submit_transfer_tx(account0, account1.account_id,
6000001)
response1 = self.__submit_transfer_tx(account1, account0.account_id,
12000001)
response0 = self.__submit_transfer_tx(
account0,
account1.account_id,
6000001,
)
response1 = self.__submit_transfer_tx(
account1,
account0.account_id,
12000001,
)

metrics_tracker = MetricsTracker(self.node)
for height, _ in poll_blocks(self.node):
Expand All @@ -100,10 +113,8 @@ def test_resharding_rpc_tx(self):
continue

# Quick check whether resharding is completed
version = metrics_tracker.get_int_metric_value(
"near_shard_layout_version")
num_shards = metrics_tracker.get_int_metric_value(
"near_shard_layout_num_shards")
version = self.get_version(metrics_tracker)
num_shards = self.get_num_shards(metrics_tracker)
self.assertEqual(version, self.target_shard_layout_version)
self.assertEqual(num_shards, self.target_num_shards)

Expand Down

0 comments on commit ac5cba2

Please sign in to comment.