Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_write_score_to_score_deploy_path_revision_ge3(
self, mock_engine, context, mocker, revision
):
self.set_test(mocker, self.score_path, self.score_deploy_path, revision)
mock_engine._write_score_to_score_deploy_path(
context, GOVERNANCE_SCORE_ADDRESS, context.tx.hash, None
)
isde.get_score_deploy_path.assert_called_with(
context.score_root_path, GOVERNANCE_SCORE_ADDRESS, context.tx.hash
)
os.path.join.assert_called_with(
context.score_root_path,
GOVERNANCE_SCORE_ADDRESS.to_bytes().hex(),
f"0x{context.tx.hash.hex()}",
)
isde.remove_path.assert_called_with(self.score_path)
IconScoreDeployer.deploy.assert_called_with(
self.score_deploy_path, None, revision
)
mocker.stopall()
def test_prefix_and_int(self):
assert Address.from_prefix_and_int(AddressPrefix.CONTRACT, 0) == ZERO_SCORE_ADDRESS
assert Address.from_prefix_and_int(AddressPrefix.CONTRACT, 1) == GOVERNANCE_SCORE_ADDRESS
assert str(Address.from_prefix_and_int(AddressPrefix.EOA, 10)) == "hx000000000000000000000000000000000000000a"
assert str(Address.from_prefix_and_int(AddressPrefix.CONTRACT, 1024)) == \
"cx0000000000000000000000000000000000000400"
def test_governance_call_about_add_blacklist_already_blacklist(self):
score_addr = create_address(1)
self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name="addToScoreBlackList",
params={"address": str(score_addr)})
self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name="addToScoreBlackList",
params={"address": str(score_addr)})
score_addr = create_address(1)
raise_exception_start_tag("addDeployer")
tx_result = self._external_call(self._admin,
GOVERNANCE_SCORE_ADDRESS,
'addDeployer',
{"address": str(score_addr)})
raise_exception_end_tag("addDeployer")
self.assertEqual(tx_result.status, int(False))
self.assertEqual(tx_result.failure.code, ExceptionCode.SCORE_ERROR)
self.assertEqual(tx_result.failure.message, f"Invalid EOA Address: {str(score_addr)}")
raise_exception_start_tag("removeDeployer")
tx_result = self._external_call(self._admin,
GOVERNANCE_SCORE_ADDRESS,
'removeDeployer',
{"address": str(score_addr)})
raise_exception_end_tag("removeDeployer")
self.assertEqual(tx_result.status, int(False))
self.assertEqual(tx_result.failure.code, ExceptionCode.SCORE_ERROR)
self.assertEqual(tx_result.failure.message, f"Invalid EOA Address: {str(score_addr)}")
def test_score_remove_deployer(self):
score_addr_array = []
addr1 = create_address(AddressPrefix.EOA, b'addr1')
value = 500
is_commit, tx_results = self._run_async(
self._call_method_score(
self._admin_addr, str(GOVERNANCE_SCORE_ADDRESS), 'addDeployer', {"address": str(addr1)}))
self.assertEqual(is_commit, True)
is_commit, tx_results = self._run_async(
self._deploy_zip('install/test_score', ZERO_SCORE_ADDRESS, addr1, {'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": {}
validate_tx_response1, tx1 = self._run_async(
self._make_deploy_tx(self.sample_root, "test_score", ZERO_SCORE_ADDRESS, addr1))
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))
tx_hash1 = tx_result1['txHash']
score_addr1 = tx_result1['scoreAddress']
response = self._run_async(self._write_precommit_state(precommit_req1))
self.assertEqual(response, hex(0))
validate_tx_response2, tx2 = self._run_async(
self._make_score_call_tx(self._admin_addr, GOVERNANCE_SCORE_ADDRESS, 'acceptScore', {"txHash": tx_hash1}))
self.assertEqual(validate_tx_response2, hex(0))
precommit_req2, tx_results2 = self._run_async(self._make_and_req_block([tx2]))
tx_result2 = self._get_tx_result(tx_results2, tx2)
self.assertEqual(tx_result2['status'], hex(True))
response = self._run_async(self._write_precommit_state(precommit_req2))
self.assertEqual(response, hex(0))
validate_tx_response3, tx3 = self._run_async(
self._make_deploy_tx(self.sample_root, "test_link_score", ZERO_SCORE_ADDRESS, addr2,
deploy_params={"score_addr": score_addr1}))
self.assertEqual(validate_tx_response3, hex(0))
precommit_req3, tx_results3 = self._run_async(self._make_and_req_block([tx3]))
tx_result3 = self._get_tx_result(tx_results3, tx3)
def _assert_get_score_status(self, target_addr: 'Address', expect_status: dict):
query_request = {
"version": self._version,
"from": self._accounts[0],
"to": GOVERNANCE_SCORE_ADDRESS,
"dataType": "call",
"data": {
"method": "getScoreStatus",
"params": {"address": str(target_addr)}
}
}
response = self._query(query_request)
self.assertEqual(response, expect_status)
def _assert_get_score_status(self, target_addr: 'Address', expect_status: dict):
query_request = {
"version": self._version,
"from": self._addr_array[0],
"to": GOVERNANCE_SCORE_ADDRESS,
"dataType": "call",
"data": {
"method": "getScoreStatus",
"params": {"address": str(target_addr)}
}
}
response = self._query(query_request)
self.assertEqual(response, expect_status)
def _update_governance(self):
tx = self._make_deploy_tx("sample_builtin",
"latest_version/governance",
self._admin,
GOVERNANCE_SCORE_ADDRESS)
prev_block, tx_results = self._make_and_req_block([tx])
self.assertEqual(int(True), tx_results[0].status)
self._write_precommit_state(prev_block)
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(
self._call_method_score(
self._admin_addr, str(GOVERNANCE_SCORE_ADDRESS), 'acceptScore', {"txHash": tx_hash}))
self.assertEqual(is_commit, True)
request = {
"version": hex(self._version),
"from": str(self._admin_addr),