from iconsdk.builder.transaction_builder import DeployTransactionBuilder
from iconsdk.builder.call_builder import CallBuilder
from iconsdk.libs.in_memory_zip import gen_deploy_data_content
from iconsdk.signed_transaction import SignedTransaction
from tbears.libs.icon_integrate_test import IconIntegrateTestBase, SCORE_INSTALL_ADDRESS
DIR_PATH = os.path.abspath(os.path.dirname(__file__))
class TestScoreTest(IconIntegrateTestBase):
TEST_HTTP_ENDPOINT_URI_V3 = "http://127.0.0.1:9000/api/v3"
SCORE_PROJECT= os.path.abspath(os.path.join(DIR_PATH, '..'))
# If you want to send request to network, uncomment next line and set self.TEST_HTTP_ENDPOINT_URI_V3
# self.icon_service = IconService(HTTPProvider(self.TEST_HTTP_ENDPOINT_URI_V3))
self._score_address = self._deploy_score()['scoreAddress']
def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict:
# Generates an instance of transaction for deploying SCORE.
transaction = DeployTransactionBuilder() \
.from_(self._test1.get_address()) \
.step_limit(100_000_000_000) \
.content_type("application/zip") \
.content(gen_deploy_data_content(self.SCORE_PROJECT)) \
# Returns the signed transaction object having a signature
signed_transaction = SignedTransaction(transaction, self._test1)
# process the transaction in local
tx_result = self._process_transaction(signed_transaction)
# check transaction result
self.assertTrue('status' in tx_result)
self.assertEqual(1, tx_result['status'])
self.assertTrue('scoreAddress' in tx_result)
def test_score_update(self):
tx_result = self._deploy_score(self._score_address)
self.assertEqual(self._score_address, tx_result['scoreAddress'])
def test_call_hello(self):
# Generates a call instance using the CallBuilder
call = CallBuilder().from_(self._test1.get_address()) \
.to(self._score_address) \
response = self._process_call(call, self.icon_service)
self.assertEqual("Hello", response)