Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]
prev_block, tx_results = self._make_and_req_block_for_issue_test(tx_list, is_block_editable=False)
self._write_precommit_state(prev_block)
expected_tx_status = 1
expected_failure = None
expected_trace = []
self.assertEqual(expected_tx_status, tx_results[0].status)
self.assertEqual(expected_failure, tx_results[0].failure)
self.assertEqual(expected_step_price, tx_results[0].step_price)
self.assertEqual(expected_step_used, tx_results[0].step_used)
self.assertEqual(expected_trace, tx_results[0].traces)
for index, group_key in enumerate(ISSUE_CALCULATE_ORDER):
if group_key not in self.issue_data:
continue
expected_score_address = ZERO_SCORE_ADDRESS
expected_indexed: list = [ISSUE_EVENT_LOG_MAPPER[group_key]['event_signature']]
expected_data: list = [self.issue_data[group_key][key] for key in ISSUE_EVENT_LOG_MAPPER[group_key]['data']]
self.assertEqual(expected_score_address, tx_results[0].event_logs[index].score_address)
self.assertEqual(expected_indexed, tx_results[0].event_logs[index].indexed)
self.assertEqual(expected_data, tx_results[0].event_logs[index].data)
# event log about correction
self.assertEqual(0, tx_results[0].event_logs[1].data[0])
self.assertEqual(0, tx_results[0].event_logs[1].data[1])
self.assertEqual(self.total_issue_amount, tx_results[0].event_logs[1].data[2])
self.assertEqual(0, tx_results[0].event_logs[1].data[3])
after_total_supply = self._query({}, "icx_getTotalSupply")
after_treasury_icx_amount = self._query({"address": self._fee_treasury}, 'icx_getBalance')
self.assertEqual(before_total_supply + self.total_issue_amount, after_total_supply)
def test_deploy_invalid_content(self):
self.update_governance()
# Update revision
self.set_revision(3)
# 1. deploy with str content
tx = self._create_invalid_deploy_tx(from_=self._accounts[0],
to_=ZERO_SCORE_ADDRESS,
content='invalid')
raise_exception_start_tag("test_score_no_zip")
prev_block, hash_list = self.make_and_req_block([tx])
raise_exception_end_tag("test_score_no_zip")
self._write_precommit_state(prev_block)
tx_results: List['TransactionResult'] = self.get_tx_results(hash_list)
self.assertEqual(tx_results[0].status, int(False))
self.assertEqual(tx_results[0].failure.message, f'Invalid content data')
# 2. deploy with int content
tx = self._create_invalid_deploy_tx(from_=self._accounts[0],
to_=ZERO_SCORE_ADDRESS,
content=1000)
def test_score(self):
score_addr_array = []
value1 = 500
is_commit, tx_results = self._run_async(
self._deploy_zip('install/test_score', ZERO_SCORE_ADDRESS, self._admin_addr, {'value': hex(value1)}))
self.assertEqual(is_commit, True)
score_addr_array.append(tx_results[0]['scoreAddress'])
tx_hash = tx_results[0]['txHash']
is_commit, tx_results = self._run_async(
self._call_method_score(
self._admin_addr, str(GOVERNANCE_SCORE_ADDRESS), 'acceptScore', {"txHash": tx_hash}))
self.assertEqual(is_commit, True)
value2 = 300
is_commit, tx_results = self._run_async(
self._deploy_zip('update/test_score', score_addr_array[0], self._admin_addr, {'value': hex(value2)}))
self.assertEqual(is_commit, True)
tx_hash = tx_results[0]['txHash']
is_commit, tx_results = self._run_async(
def test_score(self):
value1 = 1 * self._icx_factor
validate_tx_response1, tx1 = self._run_async(
self._make_deploy_tx(self.sample_root, "install/test_score", ZERO_SCORE_ADDRESS, self._admin_addr,
deploy_params={'value': hex(value1)}))
self.assertEqual(validate_tx_response1, hex(0))
precommit_req1, tx_results1 = self._run_async(self._make_and_req_block([tx1]))
tx_result1 = self._get_tx_result(tx_results1, tx1)
self.assertEqual(tx_result1['status'], hex(True))
score_addr1 = tx_result1['scoreAddress']
response = self._run_async(self._write_precommit_state(precommit_req1))
self.assertEqual(response, hex(0))
value2 = 2 * self._icx_factor
validate_tx_response2, tx2 = self._run_async(
self._make_deploy_tx(self.sample_root, "update/test_score", score_addr1, self._admin_addr,
deploy_params={'value': hex(value2)}))
def _set_prep(self, address: 'Address', data: dict, _revision: int = REV_IISS):
data = deepcopy(data)
value = data.get(ConstantKeys.IREP)
if value:
data[ConstantKeys.IREP] = hex(value)
tx = self._make_score_call_tx(address, ZERO_SCORE_ADDRESS, 'setPRep', data)
prev_block, tx_results = self._make_and_req_block([tx])
tx_result: 'TransactionResult' = tx_results[0]
self.assertEqual(1, tx_result.status)
self.assertEqual('PRepSet(Address)', tx_result.event_logs[0].indexed[0])
self.assertEqual(address, tx_result.event_logs[0].data[0])
self._write_precommit_state(prev_block)
def test_score(self):
score_addr_array = []
value = 500
is_commit, tx_results = self._run_async(
self._deploy_zip('install/test_score', ZERO_SCORE_ADDRESS, self._admin_addr, {'value': hex(value)}))
self.assertEqual(is_commit, True)
score_addr_array.append(tx_results[0]['scoreAddress'])
request = {
"version": hex(self._version),
"from": str(self._admin_addr),
"to": score_addr_array[0],
"dataType": "call",
"data": {
"method": "get_value",
"params": {}
}
}
response = self._run_async(self._icx_call(request))
self.assertEqual(response, hex(value))
def test_link_score(self):
validate_tx_response1, tx1 = self._run_async(
self._make_deploy_tx(self.sample_root, "test_score", ZERO_SCORE_ADDRESS, self._admin_addr))
self.assertEqual(validate_tx_response1, hex(0))
validate_tx_response2, tx2 = self._run_async(
self._make_deploy_tx(self.sample_root, "test_link_score", ZERO_SCORE_ADDRESS, self._admin_addr))
self.assertEqual(validate_tx_response2, hex(0))
precommit_req1, tx_results1 = self._run_async(self._make_and_req_block([tx1, tx2]))
tx_result1 = self._get_tx_result(tx_results1, tx1)
self.assertEqual(tx_result1['status'], hex(True))
score_addr1 = tx_result1['scoreAddress']
tx_result2 = self._get_tx_result(tx_results1, tx2)
self.assertEqual(tx_result2['status'], hex(True))
score_addr2 = tx_result2['scoreAddress']
response = self._run_async(self._write_precommit_state(precommit_req1))
self.assertEqual(response, hex(0))
def test_score_no_scorebase(self):
score_addr_array = []
value = 500
is_commit, tx_results = self._run_async(
self._deploy_zip('install/test_score', ZERO_SCORE_ADDRESS, self._admin_addr, {'value': hex(value)}))
self.assertEqual(is_commit, True)
score_addr_array.append(tx_results[0]['scoreAddress'])
raise_exception_start_tag()
is_commit, tx_results = self._run_async(
self._deploy_zip('install/test_score_no_scorebase', score_addr_array[0], self._admin_addr))
raise_exception_end_tag()
self.assertEqual(is_commit, False)
request = {
"version": hex(self._version),
"from": str(self._admin_addr),
"to": score_addr_array[0],
"dataType": "call",
"data": {
"method": "get_value",
def test_score_pass(self):
validate_tx_response1, tx1 = self._run_async(
self._make_deploy_tx(self.sample_root, "test_score_pass", ZERO_SCORE_ADDRESS, self._admin_addr))
self.assertEqual(validate_tx_response1, hex(0))
precommit_req1, tx_results1 = self._run_async(self._make_and_req_block([tx1]))
tx_result1 = self._get_tx_result(tx_results1, tx1)
self.assertEqual(tx_result1['status'], hex(True))
score_addr1 = tx_result1['scoreAddress']
response = self._run_async(self._write_precommit_state(precommit_req1))
self.assertEqual(response, hex(0))
value = 1 * self._icx_factor
validate_tx_response2, tx2 = self._run_async(
self._make_icx_send_tx(self._genesis_addr, score_addr1, value))
self.assertEqual(validate_tx_response2, hex(0))
def _create_deploy_score_tx_with_timestamp(self, timestamp: int, value: int) -> dict:
return self.create_deploy_score_tx(score_root="sample_deploy_scores",
score_name="install/sample_score",
from_=self._accounts[0],
to_=ZERO_SCORE_ADDRESS,
timestamp_us=timestamp,
deploy_params={'value': hex(value * ICX_IN_LOOP)})