From a9391d6d497f1df58e127fbb8eb2d8a8846059ec Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Fri, 25 Jun 2021 19:54:28 +0200 Subject: [PATCH] pytest: convert rpc_state_changes.py to use test-contract-rs To reduce reliance on WASM blobs stored in repository, convert the pytest/tests/sanity/rpc_state_changes.py test to use test-contract-rs, which is built from source, rather than hello.wasm contract. Issue: https://github.com/near/nearcore/issues/4408 --- pytest/tests/sanity/rpc_state_changes.py | 92 ++++++++++++------------ 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/pytest/tests/sanity/rpc_state_changes.py b/pytest/tests/sanity/rpc_state_changes.py index 7088439b96e..2f169f573d4 100644 --- a/pytest/tests/sanity/rpc_state_changes.py +++ b/pytest/tests/sanity/rpc_state_changes.py @@ -2,9 +2,10 @@ # and call various scenarios to trigger store changes. # Check that the key changes are observable via `changes` RPC call. -import sys import base58, base64 import json +import struct +import sys import threading import deepdiff @@ -12,7 +13,7 @@ sys.path.append('lib') from cluster import start_cluster from key import Key -from utils import load_binary_file +from utils import load_test_contract import transaction nodes = start_cluster( @@ -325,18 +326,18 @@ def test_key_value_changes(): 1. Deploy a contract. 2. Observe the code changes in the block where the transaction outcome "lands". 3. Send two transactions to be included into the same block setting and overriding the value of - the same key (`my_key`). + the same key. 4. Observe the changes in the block where the transaction outcome "lands". """ contract_key = nodes[0].signer_key - hello_smart_contract = load_binary_file('testdata/hello.wasm') + contract_blob = load_test_contract() # Step 1 status = nodes[0].get_status() latest_block_hash = status['sync_info']['latest_block_hash'] deploy_contract_tx = transaction.sign_deploy_contract_tx( - contract_key, hello_smart_contract, 10, + contract_key, contract_blob, 10, base58.b58decode(latest_block_hash.encode('utf8'))) deploy_contract_response = nodes[0].send_tx_and_wait(deploy_contract_tx, 10) @@ -401,7 +402,7 @@ def test_key_value_changes(): "account_id": contract_key.account_id, "code_base64": - base64.b64encode(hello_smart_contract).decode('utf-8'), + base64.b64encode(contract_blob).decode('utf-8'), } },] } @@ -429,40 +430,37 @@ def test_key_value_changes(): latest_block_hash = status['sync_info']['latest_block_hash'] function_caller_key = nodes[0].signer_key - def set_value_1(): - function_call_1_tx = transaction.sign_function_call_tx( - function_caller_key, contract_key.account_id, 'setKeyValue', - json.dumps({ - "key": "my_key", - "value": "my_value_1" - }).encode('utf-8'), 300000000000000, 100000000000, 20, - base58.b58decode(latest_block_hash.encode('utf8'))) - nodes[1].send_tx_and_wait(function_call_1_tx, 10) - - function_call_1_thread = threading.Thread(target=set_value_1) - function_call_1_thread.start() - - function_call_2_tx = transaction.sign_function_call_tx( - function_caller_key, contract_key.account_id, 'setKeyValue', - json.dumps({ - "key": "my_key", - "value": "my_value_2" - }).encode('utf-8'), 300000000000000, 100000000000, 30, - base58.b58decode(latest_block_hash.encode('utf8'))) - function_call_2_response = nodes[1].send_tx_and_wait(function_call_2_tx, 10) - assert function_call_2_response['result']['receipts_outcome'][0]['outcome']['status'] == {'SuccessValue': ''}, \ - "Expected successful execution, but the output was: %s" % function_call_2_response - function_call_1_thread.join() + key = struct.pack('