Skip to content

Commit

Permalink
Merge refs/heads/staging into enable_floats
Browse files Browse the repository at this point in the history
  • Loading branch information
nearprotocol-bulldozer[bot] authored Jan 11, 2020
2 parents eb8dc45 + ae4852e commit e21c93a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
26 changes: 26 additions & 0 deletions pytest/lib/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ def create_staking_action(amount, pk):
action.stake = stake
return action

def create_deploy_contract_action(code):
deployContract = DeployContract()
deployContract.code = code
action = Action()
action.enum = 'deployContract'
action.deployContract = deployContract
return action

def create_function_call_action(methodName, args, gas, deposit):
functionCall = FunctionCall()
functionCall.methodName = methodName
functionCall.args = args
functionCall.gas = gas
functionCall.deposit = deposit
action = Action()
action.enum = 'functionCall'
action.functionCall = functionCall
return action

def sign_payment_tx(key, to, amount, nonce, blockHash):
action = create_payment_action(amount)
return sign_and_serialize_transaction(to, nonce, [action], blockHash, key.account_id, key.decoded_pk(), key.decoded_sk())
Expand All @@ -178,3 +197,10 @@ def sign_staking_tx(signer_key, validator_key, amount, nonce, blockHash):
action = create_staking_action(amount, validator_key.decoded_pk())
return sign_and_serialize_transaction(signer_key.account_id, nonce, [action], blockHash, signer_key.account_id, signer_key.decoded_pk(), signer_key.decoded_sk())

def sign_deploy_contract_tx(signer_key, code, nonce, blockHash):
action = create_deploy_contract_action(code)
return sign_and_serialize_transaction(signer_key.account_id, nonce, [action], blockHash, signer_key.account_id, signer_key.decoded_pk(), signer_key.decoded_sk())

def sign_function_call_tx(signer_key, methodName, args, gas, deposit, nonce, blockHash):
action = create_function_call_action(methodName, args, gas, deposit)
return sign_and_serialize_transaction(signer_key.account_id, nonce, [action], blockHash, signer_key.account_id, signer_key.decoded_pk(), signer_key.decoded_sk())
4 changes: 4 additions & 0 deletions pytest/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ def count(self, pattern):
return ret
else:
raise NotImplementedError()

def load_binary_file(filepath):
with open(filepath, "rb") as binaryfile:
return bytearray(binaryfile.read())
11 changes: 7 additions & 4 deletions pytest/tests/sanity/block_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# Ensures that the nodes remained in sync throughout the process
# Sets epoch length to 10

# Local:
# python tests/sanity/block_production.py
# Remote:
# NEAR_PYTEST_CONFIG=remote.json python tests/sanity/block_production.py

# Same for all tests that call start_cluster with a None config

import sys, time

sys.path.append('lib')
Expand All @@ -12,12 +19,8 @@
TIMEOUT = 150
BLOCKS = 50

# Local:
nodes = start_cluster(4, 0, 4, None, [["epoch_length", 10], ["block_producer_kickout_threshold", 80]], {})

# Remote:
# NEAR_PYTEST_CONFIG=remote.json python tests/sanity/block_production.py

started = time.time()

max_height = 0
Expand Down
27 changes: 27 additions & 0 deletions pytest/tests/sanity/deploy_call_smart_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Spins up four nodes, deploy an smart contract to one node,
# Call a smart contract method in another node

import sys, time
import base58

sys.path.append('lib')
from cluster import start_cluster
from transaction import sign_deploy_contract_tx, sign_function_call_tx
from utils import load_binary_file

nodes = start_cluster(4, 0, 4, None, [["epoch_length", 10], ["block_producer_kickout_threshold", 80]], {})

status = nodes[0].get_status()
hash_ = status['sync_info']['latest_block_hash']
hash_ = base58.b58decode(hash_.encode('utf8'))
tx = sign_deploy_contract_tx(nodes[0].signer_key, load_binary_file('../runtime/near-vm-runner/tests/res/test_contract_rs.wasm'), 10, hash_)
nodes[0].send_tx(tx)

time.sleep(3)

status2 = nodes[1].get_status()
hash_2 = status2['sync_info']['latest_block_hash']
hash_2 = base58.b58decode(hash_2.encode('utf8'))
tx2 = sign_function_call_tx(nodes[0].signer_key, 'log_something', [], 100000000000, 100000000000, 20, hash_2)
res = nodes[1].send_tx_and_wait(tx2, 10)
assert res['result']['receipts_outcome'][0]['outcome']['logs'][0] == 'hello'

0 comments on commit e21c93a

Please sign in to comment.