From eaf2d0c89c12abe0acdd7516475478f0f6022652 Mon Sep 17 00:00:00 2001 From: YoshihitoAso Date: Wed, 11 Jan 2023 19:12:59 +0900 Subject: [PATCH 1/2] feat: Make contract class object-oriented --- app/model/blockchain/token.py | 650 +++++++--------- app/routers/bond.py | 33 +- app/routers/ledger.py | 4 +- app/routers/position.py | 19 +- app/routers/share.py | 33 +- app/utils/ledger_utils.py | 4 +- batch/processor_batch_issue_redeem.py | 12 +- .../processor_batch_register_personal_info.py | 4 +- batch/processor_bulk_transfer.py | 6 +- batch/processor_modify_personal_info.py | 4 +- batch/processor_scheduled_events.py | 6 +- batch/processor_update_token.py | 6 +- .../test_exchange_IbetExchangeInterface.py | 2 +- .../test_exchange_IbetSecurityTokenEscrow.py | 2 +- .../model/blockchain/test_token_IbetShare.py | 714 +++++++----------- .../blockchain/test_token_IbetStraightBond.py | 687 +++++++---------- tests/model/blockchain/test_token_list.py | 5 +- ...unts_{issuer_address}_eoa_password_POST.py | 2 +- tests/test_app_routers_bond_tokens_GET.py | 27 +- ...routers_bond_tokens_{token_address}_GET.py | 4 - ...outers_bond_tokens_{token_address}_POST.py | 2 - ...s_{token_address}_additional_issue_POST.py | 2 - ...rs_{account_address}_personal_info_POST.py | 3 - ...kens_{token_address}_personal_info_POST.py | 3 - ...bond_tokens_{token_address}_redeem_POST.py | 2 - ...fer_approvals_{token_Address}_{id}_POST.py | 3 - tests/test_app_routers_bond_transfers_POST.py | 2 - ...nts_{account_address}_eoa_password_POST.py | 2 +- ...{token_address}_history_{ledger_id}_GET.py | 2 - ...ions_{account_address}_forceunlock_POST.py | 2 - tests/test_app_routers_share_tokens_GET.py | 18 - ...outers_share_tokens_{token_address}_GET.py | 4 - ...uters_share_tokens_{token_address}_POST.py | 4 - ...s_{token_address}_additional_issue_POST.py | 2 - ...rs_{account_address}_personal_info_POST.py | 3 - ...kens_{token_address}_personal_info_POST.py | 3 - ...hare_tokens_{token_address}_redeem_POST.py | 2 - ...fer_approvals_{token_Address}_{id}_POST.py | 3 - .../test_app_routers_share_transfers_POST.py | 2 - tests/test_batch_indexer_issue_redeem.py | 37 +- tests/test_batch_indexer_personal_info.py | 40 +- tests/test_batch_indexer_position_bond.py | 19 +- tests/test_batch_indexer_position_share.py | 19 +- tests/test_batch_indexer_token_holders.py | 21 +- tests/test_batch_indexer_transfer.py | 29 +- tests/test_batch_indexer_transfer_approval.py | 41 +- ...test_batch_processor_batch_issue_redeem.py | 4 - tests/test_batch_processor_create_utxo.py | 61 +- ...st_batch_processor_modify_personal_info.py | 20 +- ..._batch_processor_register_personal_info.py | 29 +- tests/test_batch_processor_update_token.py | 4 - tests/test_utils_ledger_utils.py | 22 +- 52 files changed, 1068 insertions(+), 1566 deletions(-) diff --git a/app/model/blockchain/token.py b/app/model/blockchain/token.py index 6f44914a..b0c92837 100644 --- a/app/model/blockchain/token.py +++ b/app/model/blockchain/token.py @@ -27,6 +27,7 @@ from sqlalchemy import desc from sqlalchemy.exc import IntegrityError as SAIntegrityError from sqlalchemy.orm import Session +from web3.datastructures import AttributeDict from web3.exceptions import TimeExhausted from config import ( @@ -81,72 +82,69 @@ class IbetStandardTokenInterface: tradable_exchange_contract_address: str status: bool - @staticmethod - def get_account_balance(contract_address: str, account_address: str): - """Get account balance + def __init__(self, + contract_address: str = ZERO_ADDRESS, + contract_name: str = "IbetStandardTokenInterface"): + self.contract_name = contract_name + self.token_address = contract_address - :param contract_address: contract address - :param account_address: account address - :return: account balance - """ - token_contract = ContractUtils.get_contract( - contract_name="IbetStandardTokenInterface", - contract_address=contract_address - ) - balance = ContractUtils.call_function( - contract=token_contract, - function_name="balanceOf", - args=(account_address,), - default_returns=0 - ) - tradable_exchange_address = ContractUtils.call_function( - contract=token_contract, - function_name="tradableExchange", - args=(), - default_returns=ZERO_ADDRESS - ) - if tradable_exchange_address != ZERO_ADDRESS: - exchange_contract = IbetExchangeInterface(tradable_exchange_address) - exchange_balance = exchange_contract.get_account_balance( - account_address=account_address, - token_address=contract_address - ) - balance = balance + exchange_balance["balance"] + exchange_balance["commitment"] - - return balance - - @staticmethod - def check_attr_update(db_session: Session, contract_address: str, base_datetime: datetime): + def check_attr_update(self, db_session: Session, base_datetime: datetime): is_updated = False _token_attr_update = db_session.query(TokenAttrUpdate). \ - filter(TokenAttrUpdate.token_address == contract_address). \ + filter(TokenAttrUpdate.token_address == self.token_address). \ order_by(desc(TokenAttrUpdate.id)). \ first() if _token_attr_update is not None and _token_attr_update.updated_datetime > base_datetime: is_updated = True return is_updated - @staticmethod - def record_attr_update(db_session: Session, contract_address: str): + def record_attr_update(self, db_session: Session): _token_attr_update = TokenAttrUpdate() - _token_attr_update.token_address = contract_address + _token_attr_update.token_address = self.token_address _token_attr_update.updated_datetime = datetime.utcnow() db_session.add(_token_attr_update) - def create_cache(self, db_session: Session, contract_address: str): + def create_cache(self, db_session: Session): token_cache = TokenCache() - token_cache.token_address = contract_address + token_cache.token_address = self.token_address token_cache.attributes = self.__dict__ token_cache.cached_datetime = datetime.utcnow() token_cache.expiration_datetime = datetime.utcnow() + timedelta(seconds=TOKEN_CACHE_TTL) db_session.merge(token_cache) - @staticmethod - def delete_cache(db_session: Session, contract_address: str): + def delete_cache(self, db_session: Session): db_session.query(TokenCache). \ - filter(TokenCache.token_address == contract_address). \ + filter(TokenCache.token_address == self.token_address). \ delete() + def get_account_balance(self, account_address: str): + """Get account balance""" + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address + ) + balance = ContractUtils.call_function( + contract=contract, + function_name="balanceOf", + args=(account_address,), + default_returns=0 + ) + tradable_exchange_address = ContractUtils.call_function( + contract=contract, + function_name="tradableExchange", + args=(), + default_returns=ZERO_ADDRESS + ) + if tradable_exchange_address != ZERO_ADDRESS: + exchange_contract = IbetExchangeInterface(tradable_exchange_address) + exchange_balance = exchange_contract.get_account_balance( + account_address=account_address, + token_address=self.token_address + ) + balance = balance + exchange_balance["balance"] + exchange_balance["commitment"] + + return balance + class IbetSecurityTokenInterface(IbetStandardTokenInterface): personal_info_contract_address: str @@ -154,22 +152,27 @@ class IbetSecurityTokenInterface(IbetStandardTokenInterface): is_offering: bool transfer_approval_required: bool - @staticmethod - def transfer(contract_address: str, + def __init__(self, + contract_address: str = ZERO_ADDRESS, + contract_name: str = "IbetSecurityTokenInterface"): + super().__init__(contract_address, contract_name) + + def transfer(self, data: IbetSecurityTokenTransferParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Transfer ownership""" try: - security_contract = ContractUtils.get_contract( - contract_name="IbetSecurityTokenInterface", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) _from = data.from_address _to = data.to_address _amount = data.amount - tx = security_contract.functions.transferFrom( - _from, _to, _amount + tx = contract.functions.transferFrom( + _from, + _to, + _amount ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, @@ -189,21 +192,21 @@ def transfer(contract_address: str, return tx_hash - @staticmethod - def additional_issue(contract_address: str, + def additional_issue(self, data: IbetSecurityTokenAdditionalIssueParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Additional issue""" try: - share_contract = ContractUtils.get_contract( - contract_name="IbetShare", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) _target_address = data.account_address _amount = data.amount - tx = share_contract.functions.issueFrom( - _target_address, ZERO_ADDRESS, _amount + tx = contract.functions.issueFrom( + _target_address, + ZERO_ADDRESS, + _amount ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, @@ -224,14 +227,8 @@ def additional_issue(contract_address: str, # Delete Cache db_session = Session(autocommit=False, autoflush=True, bind=engine) try: - IbetShareContract.record_attr_update( - db_session=db_session, - contract_address=contract_address - ) - IbetShareContract.delete_cache( - db_session=db_session, - contract_address=contract_address - ) + self.record_attr_update(db_session) + self.delete_cache(db_session) db_session.commit() except Exception as err: raise SendTransactionError(err) @@ -240,21 +237,21 @@ def additional_issue(contract_address: str, return tx_hash - @staticmethod - def redeem(contract_address: str, + def redeem(self, data: IbetSecurityTokenRedeemParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Redeem a token""" try: - share_contract = ContractUtils.get_contract( - contract_name="IbetShare", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) _target_address = data.account_address _amount = data.amount - tx = share_contract.functions.redeemFrom( - _target_address, ZERO_ADDRESS, _amount + tx = contract.functions.redeemFrom( + _target_address, + ZERO_ADDRESS, + _amount ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, @@ -275,14 +272,8 @@ def redeem(contract_address: str, # Delete Cache db_session = Session(autocommit=False, autoflush=True, bind=engine) try: - IbetShareContract.record_attr_update( - db_session=db_session, - contract_address=contract_address - ) - IbetShareContract.delete_cache( - db_session=db_session, - contract_address=contract_address - ) + self.record_attr_update(db_session) + self.delete_cache(db_session) db_session.commit() except Exception as err: raise SendTransactionError(err) @@ -291,26 +282,28 @@ def redeem(contract_address: str, return tx_hash - @staticmethod - def approve_transfer(contract_address: str, + def approve_transfer(self, data: IbetSecurityTokenApproveTransfer, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Approve Transfer""" try: - security_contract = ContractUtils.get_contract( - contract_name="IbetSecurityTokenInterface", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) - tx = security_contract.functions.approveTransfer( - data.application_id, data.data + tx = contract.functions.approveTransfer( + data.application_id, + data.data ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, "gas": TX_GAS_LIMIT, "gasPrice": 0 }) - tx_hash, tx_receipt = ContractUtils.send_transaction(transaction=tx, private_key=private_key) + tx_hash, tx_receipt = ContractUtils.send_transaction( + transaction=tx, + private_key=private_key + ) return tx_hash, tx_receipt except ContractRevertError: raise @@ -319,26 +312,28 @@ def approve_transfer(contract_address: str, except Exception as err: raise SendTransactionError(err) - @staticmethod - def cancel_transfer(contract_address: str, + def cancel_transfer(self, data: IbetSecurityTokenCancelTransfer, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Cancel Transfer""" try: - security_contract = ContractUtils.get_contract( - contract_name="IbetSecurityTokenInterface", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) - tx = security_contract.functions.cancelTransfer( - data.application_id, data.data + tx = contract.functions.cancelTransfer( + data.application_id, + data.data ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, "gas": TX_GAS_LIMIT, "gasPrice": 0 }) - tx_hash, tx_receipt = ContractUtils.send_transaction(transaction=tx, private_key=private_key) + tx_hash, tx_receipt = ContractUtils.send_transaction( + transaction=tx, + private_key=private_key + ) return tx_hash, tx_receipt except ContractRevertError: raise @@ -347,18 +342,16 @@ def cancel_transfer(contract_address: str, except Exception as err: raise SendTransactionError(err) - @staticmethod - def lock(contract_address: str, + def lock(self, data: IbetSecurityTokenLockParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Lock""" try: - security_contract = ContractUtils.get_contract( - contract_name="IbetSecurityTokenInterface", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) - tx = security_contract.functions.lock( + tx = contract.functions.lock( data.lock_address, data.value, data.data @@ -368,7 +361,10 @@ def lock(contract_address: str, "gas": TX_GAS_LIMIT, "gasPrice": 0 }) - tx_hash, tx_receipt = ContractUtils.send_transaction(transaction=tx, private_key=private_key) + tx_hash, tx_receipt = ContractUtils.send_transaction( + transaction=tx, + private_key=private_key + ) return tx_hash, tx_receipt except ContractRevertError: raise @@ -377,18 +373,16 @@ def lock(contract_address: str, except Exception as err: raise SendTransactionError(err) - @staticmethod - def force_unlock(contract_address: str, + def force_unlock(self, data: IbetSecurityTokenForceUnlockParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Force Unlock""" try: - security_contract = ContractUtils.get_contract( - contract_name="IbetSecurityTokenInterface", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) - tx = security_contract.functions.forceUnlock( + tx = contract.functions.forceUnlock( data.lock_address, data.account_address, data.recipient_address, @@ -400,7 +394,10 @@ def force_unlock(contract_address: str, "gas": TX_GAS_LIMIT, "gasPrice": 0 }) - tx_hash, tx_receipt = ContractUtils.send_transaction(transaction=tx, private_key=private_key) + tx_hash, tx_receipt = ContractUtils.send_transaction( + transaction=tx, + private_key=private_key + ) return tx_hash, tx_receipt except ContractRevertError: raise @@ -422,8 +419,11 @@ class IbetStraightBondContract(IbetSecurityTokenInterface): memo: str is_redeemed: bool - @staticmethod - def create(args: list, tx_from: str, private_key: str): + def __init__(self, contract_address: str = ZERO_ADDRESS): + super().__init__(contract_address, "IbetStraightBond") + + def create(self, args: list, + tx_from: str, private_key: str): """Deploy token :param args: deploy arguments @@ -431,130 +431,82 @@ def create(args: list, tx_from: str, private_key: str): :param private_key: deployer's private key :return: contract address, ABI, transaction hash """ - contract_address, abi, tx_hash = ContractUtils.deploy_contract( - contract_name="IbetStraightBond", - args=args, - deployer=tx_from, - private_key=private_key - ) - return contract_address, abi, tx_hash - - @staticmethod - def get(contract_address: str): - """Get token data - - :param contract_address: contract address - :return: IbetStraightBond - """ + if self.token_address == ZERO_ADDRESS: + contract_address, abi, tx_hash = ContractUtils.deploy_contract( + contract_name="IbetStraightBond", + args=args, + deployer=tx_from, + private_key=private_key + ) + self.contract_name = "IbetStraightBond" + self.token_address = contract_address + return contract_address, abi, tx_hash + else: + raise SendTransactionError("contract is already deployed") + + def get(self): + """Get token attributes""" db_session = Session(autocommit=False, autoflush=True, bind=engine) - bond_contract = ContractUtils.get_contract( - contract_name="IbetStraightBond", - contract_address=contract_address - ) # When using the cache if TOKEN_CACHE: token_cache: TokenCache = db_session.query(TokenCache). \ - filter(TokenCache.token_address == contract_address). \ + filter(TokenCache.token_address == self.token_address). \ first() if token_cache is not None: - is_updated = IbetStraightBondContract.check_attr_update( + is_updated = self.check_attr_update( db_session=db_session, - contract_address=contract_address, base_datetime=token_cache.cached_datetime ) if is_updated is False and token_cache.expiration_datetime > datetime.utcnow(): # Get data from cache - bond_token = IbetStraightBondContract() for k, v in token_cache.attributes.items(): - setattr(bond_token, k, v) + setattr(self, k, v) db_session.close() - return bond_token + return AttributeDict(self.__dict__) # When cache is not used # Or, if there is no data in the cache # Or, if the cache has expired - # Get data from contract - bond_token = IbetStraightBondContract() - - bond_token.issuer_address = ContractUtils.call_function( - bond_contract, "owner", (), ZERO_ADDRESS + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) - bond_token.token_address = contract_address # Set IbetStandardTokenInterface attribute - bond_token.name = ContractUtils.call_function( - bond_contract, "name", (), "" - ) - bond_token.symbol = ContractUtils.call_function( - bond_contract, "symbol", (), "" - ) - bond_token.total_supply = ContractUtils.call_function( - bond_contract, "totalSupply", (), 0 - ) - bond_token.tradable_exchange_contract_address = ContractUtils.call_function( - bond_contract, "tradableExchange", (), ZERO_ADDRESS - ) - bond_token.contact_information = ContractUtils.call_function( - bond_contract, "contactInformation", (), "" - ) - bond_token.privacy_policy = ContractUtils.call_function( - bond_contract, "privacyPolicy", (), "" - ) - bond_token.status = ContractUtils.call_function( - bond_contract, "status", (), True - ) + self.issuer_address = ContractUtils.call_function(contract, "owner", (), ZERO_ADDRESS) + self.name = ContractUtils.call_function(contract, "name", (), "") + self.symbol = ContractUtils.call_function(contract, "symbol", (), "") + self.total_supply = ContractUtils.call_function(contract, "totalSupply", (), 0) + self.tradable_exchange_contract_address = ContractUtils.call_function(contract, "tradableExchange", (), ZERO_ADDRESS) + self.contact_information = ContractUtils.call_function(contract, "contactInformation", (), "") + self.privacy_policy = ContractUtils.call_function(contract, "privacyPolicy", (), "") + self.status = ContractUtils.call_function(contract, "status", (), True) # Set IbetSecurityTokenInterface attribute - bond_token.personal_info_contract_address = ContractUtils.call_function( - bond_contract, "personalInfoAddress", (), ZERO_ADDRESS - ) - bond_token.transferable = ContractUtils.call_function( - bond_contract, "transferable", (), False - ) - bond_token.is_offering = ContractUtils.call_function( - bond_contract, "isOffering", (), False - ) - bond_token.transfer_approval_required = ContractUtils.call_function( - bond_contract, "transferApprovalRequired", (), False - ) + self.personal_info_contract_address = ContractUtils.call_function(contract, "personalInfoAddress", (), ZERO_ADDRESS) + self.transferable = ContractUtils.call_function(contract, "transferable", (), False) + self.is_offering = ContractUtils.call_function(contract, "isOffering", (), False) + self.transfer_approval_required = ContractUtils.call_function(contract, "transferApprovalRequired", (), False) # Set IbetStraightBondToken attribute - bond_token.face_value = ContractUtils.call_function( - bond_contract, "faceValue", (), 0 - ) - bond_token.interest_rate = float( + self.face_value = ContractUtils.call_function(contract, "faceValue", (), 0) + self.interest_rate = float( Decimal(str( - ContractUtils.call_function(bond_contract, "interestRate", (), 0) + ContractUtils.call_function(contract, "interestRate", (), 0) )) * Decimal("0.0001") ) - bond_token.redemption_date = ContractUtils.call_function( - bond_contract, "redemptionDate", (), "" - ) - bond_token.redemption_value = ContractUtils.call_function( - bond_contract, "redemptionValue", (), 0 - ) - bond_token.return_date = ContractUtils.call_function( - bond_contract, "returnDate", (), "" - ) - bond_token.return_amount = ContractUtils.call_function( - bond_contract, "returnAmount", (), "" - ) - bond_token.purpose = ContractUtils.call_function( - bond_contract, "purpose", (), "" - ) - bond_token.memo = ContractUtils.call_function( - bond_contract, "memo", (), "" - ) - bond_token.is_redeemed = ContractUtils.call_function( - bond_contract, "isRedeemed", (), False - ) + self.redemption_date = ContractUtils.call_function(contract, "redemptionDate", (), "") + self.redemption_value = ContractUtils.call_function(contract, "redemptionValue", (), 0) + self.return_date = ContractUtils.call_function(contract, "returnDate", (), "") + self.return_amount = ContractUtils.call_function(contract, "returnAmount", (), "") + self.purpose = ContractUtils.call_function(contract, "purpose", (), "") + self.memo = ContractUtils.call_function(contract, "memo", (), "") + self.is_redeemed = ContractUtils.call_function(contract, "isRedeemed", (), False) interest_payment_date_list = [] - interest_payment_date_string = ContractUtils.call_function( - bond_contract, "interestPaymentDate", (), "" - ).replace("'", '"') + interest_payment_date_string = ContractUtils.call_function(contract, "interestPaymentDate", (), "").replace("'", '"') interest_payment_date = {} try: if interest_payment_date_string != "": @@ -565,38 +517,31 @@ def get(contract_address: str): interest_payment_date_list.append( interest_payment_date.get(f"interestPaymentDate{str(i)}", "") ) - bond_token.interest_payment_date = interest_payment_date_list + self.interest_payment_date = interest_payment_date_list if TOKEN_CACHE: # Create token cache try: - token_cache = TokenCache() - token_cache.token_address = contract_address - token_cache.attributes = bond_token.__dict__ - token_cache.cached_datetime = datetime.utcnow() - token_cache.expiration_datetime = datetime.utcnow() + timedelta(seconds=TOKEN_CACHE_TTL) - db_session.merge(token_cache) + self.create_cache(db_session) db_session.commit() except SAIntegrityError: db_session.rollback() - pass + db_session.close() - return bond_token + return AttributeDict(self.__dict__) - @staticmethod - def update(contract_address: str, + def update(self, data: IbetStraightBondUpdateParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Update token""" - bond_contract = ContractUtils.get_contract( - contract_name="IbetStraightBond", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) if data.face_value is not None: - tx = bond_contract.functions.setFaceValue( + tx = contract.functions.setFaceValue( data.face_value ).build_transaction({ "chainId": CHAIN_ID, @@ -615,7 +560,7 @@ def update(contract_address: str, if data.interest_rate is not None: _interest_rate = int(Decimal(str(data.interest_rate)) * Decimal("10000")) - tx = bond_contract.functions.setInterestRate( + tx = contract.functions.setInterestRate( _interest_rate ).build_transaction({ "chainId": CHAIN_ID, @@ -637,7 +582,7 @@ def update(contract_address: str, for i, item in enumerate(data.interest_payment_date): _interest_payment_date[f"interestPaymentDate{i + 1}"] = item _interest_payment_date_string = json.dumps(_interest_payment_date) - tx = bond_contract.functions.setInterestPaymentDate( + tx = contract.functions.setInterestPaymentDate( _interest_payment_date_string ).build_transaction({ "chainId": CHAIN_ID, @@ -655,7 +600,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.redemption_value is not None: - tx = bond_contract.functions.setRedemptionValue( + tx = contract.functions.setRedemptionValue( data.redemption_value ).build_transaction({ "chainId": CHAIN_ID, @@ -671,7 +616,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.transferable is not None: - tx = bond_contract.functions.setTransferable( + tx = contract.functions.setTransferable( data.transferable ).build_transaction({ "chainId": CHAIN_ID, @@ -689,7 +634,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.status is not None: - tx = bond_contract.functions.setStatus( + tx = contract.functions.setStatus( data.status ).build_transaction({ "chainId": CHAIN_ID, @@ -707,7 +652,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.is_offering is not None: - tx = bond_contract.functions.changeOfferingStatus( + tx = contract.functions.changeOfferingStatus( data.is_offering ).build_transaction({ "chainId": CHAIN_ID, @@ -725,7 +670,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.is_redeemed is not None and data.is_redeemed: - tx = bond_contract.functions.changeToRedeemed().build_transaction({ + tx = contract.functions.changeToRedeemed().build_transaction({ "chainId": CHAIN_ID, "from": tx_from, "gas": TX_GAS_LIMIT, @@ -741,7 +686,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.tradable_exchange_contract_address is not None: - tx = bond_contract.functions.setTradableExchange( + tx = contract.functions.setTradableExchange( data.tradable_exchange_contract_address ).build_transaction({ "chainId": CHAIN_ID, @@ -759,7 +704,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.personal_info_contract_address is not None: - tx = bond_contract.functions.setPersonalInfoAddress( + tx = contract.functions.setPersonalInfoAddress( data.personal_info_contract_address ).build_transaction({ "chainId": CHAIN_ID, @@ -777,7 +722,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.contact_information is not None: - tx = bond_contract.functions.setContactInformation( + tx = contract.functions.setContactInformation( data.contact_information ).build_transaction({ "chainId": CHAIN_ID, @@ -795,7 +740,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.privacy_policy is not None: - tx = bond_contract.functions.setPrivacyPolicy( + tx = contract.functions.setPrivacyPolicy( data.privacy_policy ).build_transaction({ "chainId": CHAIN_ID, @@ -813,7 +758,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.transfer_approval_required is not None: - tx = bond_contract.functions.setTransferApprovalRequired( + tx = contract.functions.setTransferApprovalRequired( data.transfer_approval_required ).build_transaction({ "chainId": CHAIN_ID, @@ -831,7 +776,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.memo is not None: - tx = bond_contract.functions.setMemo( + tx = contract.functions.setMemo( data.memo ).build_transaction({ "chainId": CHAIN_ID, @@ -851,14 +796,8 @@ def update(contract_address: str, # Delete Cache db_session = Session(autocommit=False, autoflush=True, bind=engine) try: - IbetStraightBondContract.record_attr_update( - db_session=db_session, - contract_address=contract_address - ) - IbetStraightBondContract.delete_cache( - db_session=db_session, - contract_address=contract_address - ) + self.record_attr_update(db_session) + self.delete_cache(db_session) db_session.commit() except Exception as err: raise SendTransactionError(err) @@ -876,8 +815,11 @@ class IbetShareContract(IbetSecurityTokenInterface): dividend_record_date: str dividend_payment_date: str - @staticmethod - def create(args: list, tx_from: str, private_key: str): + def __init__(self, contract_address: str = ZERO_ADDRESS): + super().__init__(contract_address, "IbetShare") + + def create(self, args: list, + tx_from: str, private_key: str): """Deploy token :param args: deploy arguments @@ -885,148 +827,99 @@ def create(args: list, tx_from: str, private_key: str): :param private_key: deployer's private key :return: contract address, ABI, transaction hash """ - contract_address, abi, tx_hash = ContractUtils.deploy_contract( - contract_name="IbetShare", - args=args, - deployer=tx_from, - private_key=private_key - ) - return contract_address, abi, tx_hash - - @staticmethod - def get(contract_address: str): - """Get token data - - :param contract_address: contract address - :return: IbetShare - """ + if self.token_address == ZERO_ADDRESS: + contract_address, abi, tx_hash = ContractUtils.deploy_contract( + contract_name="IbetShare", + args=args, + deployer=tx_from, + private_key=private_key + ) + self.contract_name = "IbetShare" + self.token_address = contract_address + return contract_address, abi, tx_hash + else: + raise SendTransactionError("contract is already deployed") + + def get(self): + """Get token attributes""" db_session = Session(autocommit=False, autoflush=True, bind=engine) - share_contract = ContractUtils.get_contract( - contract_name="IbetShare", - contract_address=contract_address - ) # When using the cache if TOKEN_CACHE: token_cache: TokenCache = db_session.query(TokenCache). \ - filter(TokenCache.token_address == contract_address). \ + filter(TokenCache.token_address == self.token_address). \ first() if token_cache is not None: - is_updated = IbetStraightBondContract.check_attr_update( + is_updated = self.check_attr_update( db_session=db_session, - contract_address=contract_address, base_datetime=token_cache.cached_datetime ) if is_updated is False and token_cache.expiration_datetime > datetime.utcnow(): # Get data from cache - share_token = IbetShareContract() for k, v in token_cache.attributes.items(): - setattr(share_token, k, v) + setattr(self, k, v) db_session.close() - return share_token + return AttributeDict(self.__dict__) # When cache is not used # Or, if there is no data in the cache # Or, if the cache has expired - # Get data from contract - share_token = IbetShareContract() - - share_token.issuer_address = ContractUtils.call_function( - share_contract, "owner", (), ZERO_ADDRESS + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) - share_token.token_address = contract_address # Set IbetStandardTokenInterface attribute - share_token.name = ContractUtils.call_function( - share_contract, "name", (), "" - ) - share_token.symbol = ContractUtils.call_function( - share_contract, "symbol", (), "" - ) - share_token.total_supply = ContractUtils.call_function( - share_contract, "totalSupply", (), 0 - ) - share_token.tradable_exchange_contract_address = ContractUtils.call_function( - share_contract, "tradableExchange", (), ZERO_ADDRESS - ) - share_token.contact_information = ContractUtils.call_function( - share_contract, "contactInformation", (), "" - ) - share_token.privacy_policy = ContractUtils.call_function( - share_contract, "privacyPolicy", (), "" - ) - share_token.status = ContractUtils.call_function( - share_contract, "status", (), True - ) + self.issuer_address = ContractUtils.call_function(contract, "owner", (), ZERO_ADDRESS) + self.name = ContractUtils.call_function(contract, "name", (), "") + self.symbol = ContractUtils.call_function(contract, "symbol", (), "") + self.total_supply = ContractUtils.call_function(contract, "totalSupply", (), 0) + self.tradable_exchange_contract_address = ContractUtils.call_function(contract, "tradableExchange", (), ZERO_ADDRESS) + self.contact_information = ContractUtils.call_function(contract, "contactInformation", (), "") + self.privacy_policy = ContractUtils.call_function(contract, "privacyPolicy", (), "") + self.status = ContractUtils.call_function(contract, "status", (), True) # Set IbetSecurityTokenInterface attribute - share_token.personal_info_contract_address = ContractUtils.call_function( - share_contract, "personalInfoAddress", (), ZERO_ADDRESS - ) - share_token.transferable = ContractUtils.call_function( - share_contract, "transferable", (), False - ) - share_token.is_offering = ContractUtils.call_function( - share_contract, "isOffering", (), False - ) - share_token.transfer_approval_required = ContractUtils.call_function( - share_contract, "transferApprovalRequired", (), False - ) + self.personal_info_contract_address = ContractUtils.call_function(contract, "personalInfoAddress", (), ZERO_ADDRESS) + self.transferable = ContractUtils.call_function(contract, "transferable", (), False) + self.is_offering = ContractUtils.call_function(contract, "isOffering", (), False) + self.transfer_approval_required = ContractUtils.call_function(contract, "transferApprovalRequired", (), False) # Set IbetShareToken attribute - share_token.issue_price = ContractUtils.call_function( - share_contract, "issuePrice", (), 0 - ) - share_token.cancellation_date = ContractUtils.call_function( - share_contract, "cancellationDate", (), "" - ) - share_token.memo = ContractUtils.call_function( - share_contract, "memo", (), "" - ) - share_token.principal_value = ContractUtils.call_function( - share_contract, "principalValue", (), 0 - ) - share_token.is_canceled = ContractUtils.call_function( - share_contract, "isCanceled", (), False - ) - _dividend_info = ContractUtils.call_function( - share_contract, "dividendInformation", (), (0, "", "") - ) - share_token.dividends = float(Decimal(str(_dividend_info[0])) * Decimal("0.0000000000001")) - share_token.dividend_record_date = _dividend_info[1] - share_token.dividend_payment_date = _dividend_info[2] + self.issue_price = ContractUtils.call_function(contract, "issuePrice", (), 0) + self.cancellation_date = ContractUtils.call_function(contract, "cancellationDate", (), "") + self.memo = ContractUtils.call_function(contract, "memo", (), "") + self.principal_value = ContractUtils.call_function(contract, "principalValue", (), 0) + self.is_canceled = ContractUtils.call_function(contract, "isCanceled", (), False) + _dividend_info = ContractUtils.call_function(contract, "dividendInformation", (), (0, "", "")) + self.dividends = float(Decimal(str(_dividend_info[0])) * Decimal("0.0000000000001")) + self.dividend_record_date = _dividend_info[1] + self.dividend_payment_date = _dividend_info[2] if TOKEN_CACHE: # Create token cache try: - token_cache = TokenCache() - token_cache.token_address = contract_address - token_cache.attributes = share_token.__dict__ - token_cache.cached_datetime = datetime.utcnow() - token_cache.expiration_datetime = datetime.utcnow() + timedelta(seconds=TOKEN_CACHE_TTL) - db_session.merge(token_cache) + self.create_cache(db_session) db_session.commit() except SAIntegrityError: db_session.rollback() - pass + db_session.close() - return share_token + return AttributeDict(self.__dict__) - @staticmethod - def update(contract_address: str, + def update(self, data: IbetShareUpdateParams, - tx_from: str, - private_key: str): + tx_from: str, private_key: str): """Update token""" - share_contract = ContractUtils.get_contract( - contract_name="IbetShare", - contract_address=contract_address + contract = ContractUtils.get_contract( + contract_name=self.contract_name, + contract_address=self.token_address ) if data.tradable_exchange_contract_address is not None: - tx = share_contract.functions.setTradableExchange( + tx = contract.functions.setTradableExchange( data.tradable_exchange_contract_address ).build_transaction({ "chainId": CHAIN_ID, @@ -1044,7 +937,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.personal_info_contract_address is not None: - tx = share_contract.functions.setPersonalInfoAddress( + tx = contract.functions.setPersonalInfoAddress( data.personal_info_contract_address ).build_transaction({ "chainId": CHAIN_ID, @@ -1063,7 +956,7 @@ def update(contract_address: str, if data.dividends is not None: _dividends = int(Decimal(str(data.dividends)) * Decimal("10000000000000")) - tx = share_contract.functions.setDividendInformation( + tx = contract.functions.setDividendInformation( _dividends, data.dividend_record_date, data.dividend_payment_date @@ -1083,7 +976,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.cancellation_date is not None: - tx = share_contract.functions.setCancellationDate( + tx = contract.functions.setCancellationDate( data.cancellation_date ).build_transaction({ "chainId": CHAIN_ID, @@ -1101,7 +994,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.contact_information is not None: - tx = share_contract.functions.setContactInformation( + tx = contract.functions.setContactInformation( data.contact_information ).build_transaction({ "chainId": CHAIN_ID, @@ -1119,7 +1012,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.privacy_policy is not None: - tx = share_contract.functions.setPrivacyPolicy( + tx = contract.functions.setPrivacyPolicy( data.privacy_policy ).build_transaction({ "chainId": CHAIN_ID, @@ -1137,7 +1030,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.status is not None: - tx = share_contract.functions.setStatus( + tx = contract.functions.setStatus( data.status ).build_transaction({ "chainId": CHAIN_ID, @@ -1155,7 +1048,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.transferable is not None: - tx = share_contract.functions.setTransferable( + tx = contract.functions.setTransferable( data.transferable ).build_transaction({ "chainId": CHAIN_ID, @@ -1173,7 +1066,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.is_offering is not None: - tx = share_contract.functions.changeOfferingStatus( + tx = contract.functions.changeOfferingStatus( data.is_offering ).build_transaction({ "chainId": CHAIN_ID, @@ -1191,7 +1084,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.transfer_approval_required is not None: - tx = share_contract.functions.setTransferApprovalRequired( + tx = contract.functions.setTransferApprovalRequired( data.transfer_approval_required ).build_transaction({ "chainId": CHAIN_ID, @@ -1209,7 +1102,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.principal_value is not None: - tx = share_contract.functions.setPrincipalValue( + tx = contract.functions.setPrincipalValue( data.principal_value ).build_transaction({ "chainId": CHAIN_ID, @@ -1227,7 +1120,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.is_canceled is not None and data.is_canceled: - tx = share_contract.functions.changeToCanceled().build_transaction({ + tx = contract.functions.changeToCanceled().build_transaction({ "chainId": CHAIN_ID, "from": tx_from, "gas": TX_GAS_LIMIT, @@ -1243,7 +1136,7 @@ def update(contract_address: str, raise SendTransactionError(err) if data.memo is not None: - tx = share_contract.functions.setMemo( + tx = contract.functions.setMemo( data.memo ).build_transaction({ "chainId": CHAIN_ID, @@ -1263,17 +1156,10 @@ def update(contract_address: str, # Delete Cache db_session = Session(autocommit=False, autoflush=True, bind=engine) try: - IbetShareContract.record_attr_update( - db_session=db_session, - contract_address=contract_address - ) - IbetShareContract.delete_cache( - db_session=db_session, - contract_address=contract_address - ) + self.record_attr_update(db_session) + self.delete_cache(db_session) db_session.commit() except Exception as err: raise SendTransactionError(err) finally: db_session.close() - diff --git a/app/routers/bond.py b/app/routers/bond.py index 77085b04..5c323b99 100644 --- a/app/routers/bond.py +++ b/app/routers/bond.py @@ -207,7 +207,7 @@ def issue_token( token.purpose ] try: - contract_address, abi, tx_hash = IbetStraightBondContract.create( + contract_address, abi, tx_hash = IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -333,10 +333,11 @@ def list_all_tokens( bond_tokens = [] for token in tokens: # Get contract data - bond_token = IbetStraightBondContract.get(contract_address=token.token_address).__dict__ + bond_token = IbetStraightBondContract(token.token_address).get().__dict__ issue_datetime_utc = timezone("UTC").localize(token.created) bond_token["issue_datetime"] = issue_datetime_utc.astimezone(local_tz).isoformat() bond_token["token_status"] = token.token_status + bond_token.pop("contract_name") bond_tokens.append(bond_token) return json_response(bond_tokens) @@ -364,10 +365,11 @@ def retrieve_token( raise InvalidParameterError("this token is temporarily unavailable") # Get contract data - bond_token = IbetStraightBondContract.get(contract_address=token_address).__dict__ + bond_token = IbetStraightBondContract(token_address).get().__dict__ issue_datetime_utc = timezone("UTC").localize(_token.created) bond_token["issue_datetime"] = issue_datetime_utc.astimezone(local_tz).isoformat() bond_token["token_status"] = _token.token_status + bond_token.pop("contract_name") return json_response(bond_token) @@ -424,8 +426,7 @@ def update_token( # Send transaction try: - IbetStraightBondContract.update( - contract_address=token_address, + IbetStraightBondContract(token_address).update( data=UpdateParams(**token.dict()), tx_from=issuer_address, private_key=private_key @@ -562,8 +563,7 @@ def additional_issue( # Send transaction try: - IbetStraightBondContract.additional_issue( - contract_address=token_address, + IbetStraightBondContract(token_address).additional_issue( data=AdditionalIssueParams(**data.dict()), tx_from=issuer_address, private_key=private_key @@ -889,8 +889,7 @@ def redeem_token( # Send transaction try: - IbetStraightBondContract.redeem( - contract_address=token_address, + IbetStraightBondContract(token_address).redeem( data=RedeemParams(**data.dict()), tx_from=issuer_address, private_key=private_key @@ -1590,7 +1589,7 @@ def modify_holder_personal_info( raise InvalidParameterError("this token is temporarily unavailable") # Modify Personal Info - token_contract = IbetStraightBondContract.get(token_address) + token_contract = IbetStraightBondContract(token_address).get() try: personal_info_contract = PersonalInfoContract( db=db, @@ -1652,7 +1651,7 @@ def register_holder_personal_info( raise InvalidParameterError("this token is temporarily unavailable") # Register Personal Info - token_contract = IbetStraightBondContract.get(token_address) + token_contract = IbetStraightBondContract(token_address).get() try: personal_info_contract = PersonalInfoContract( db=db, @@ -1915,8 +1914,7 @@ def transfer_ownership( raise InvalidParameterError("this token is temporarily unavailable") try: - IbetStraightBondContract.transfer( - contract_address=token.token_address, + IbetStraightBondContract(token.token_address).transfer( data=TransferParams(**token.dict()), tx_from=issuer_address, private_key=private_key @@ -2383,8 +2381,7 @@ def update_transfer_approval( "data": now } try: - _, tx_receipt = IbetStraightBondContract.approve_transfer( - contract_address=token_address, + _, tx_receipt = IbetStraightBondContract(token_address).approve_transfer( data=ApproveTransferParams(**_data), tx_from=issuer_address, private_key=private_key, @@ -2394,8 +2391,7 @@ def update_transfer_approval( # cancelTransfer should be performed immediately. # After cancelTransfer, ContractRevertError is returned. try: - IbetStraightBondContract.cancel_transfer( - contract_address=token_address, + IbetStraightBondContract(token_address).cancel_transfer( data=CancelTransferParams(**_data), tx_from=issuer_address, private_key=private_key, @@ -2429,8 +2425,7 @@ def update_transfer_approval( "data": now } try: - _, tx_receipt = IbetStraightBondContract.cancel_transfer( - contract_address=token_address, + _, tx_receipt = IbetStraightBondContract(token_address).cancel_transfer( data=CancelTransferParams(**_data), tx_from=issuer_address, private_key=private_key, diff --git a/app/routers/ledger.py b/app/routers/ledger.py index 32deab3d..abb26a12 100644 --- a/app/routers/ledger.py +++ b/app/routers/ledger.py @@ -715,9 +715,9 @@ def __get_personal_info(token_address: str, token_type: str, account_address: st # Get personal info from contract token_contract = None if token_type == TokenType.IBET_SHARE.value: - token_contract = IbetShareContract.get(token_address) + token_contract = IbetShareContract(token_address).get() elif token_type == TokenType.IBET_STRAIGHT_BOND.value: - token_contract = IbetStraightBondContract.get(token_address) + token_contract = IbetStraightBondContract(token_address).get() personal_info_contract = PersonalInfoContract( db=db, issuer_address=issuer_address, diff --git a/app/routers/position.py b/app/routers/position.py index 61b53b9f..4bdfcba7 100644 --- a/app/routers/position.py +++ b/app/routers/position.py @@ -155,10 +155,10 @@ def list_all_position( # Get Token Name token_name = None if _token.type == TokenType.IBET_STRAIGHT_BOND.value: - _bond = IbetStraightBondContract.get(contract_address=_token.token_address) + _bond = IbetStraightBondContract(_token.token_address).get() token_name = _bond.name elif _token.type == TokenType.IBET_SHARE.value: - _share = IbetShareContract.get(contract_address=_token.token_address) + _share = IbetShareContract(_token.token_address).get() token_name = _share.name positions.append({ "issuer_address": _token.issuer_address, @@ -237,10 +237,10 @@ def list_all_locked_position( # Get Token Name token_name = None if _token.type == TokenType.IBET_STRAIGHT_BOND.value: - _bond = IbetStraightBondContract.get(contract_address=_token.token_address) + _bond = IbetStraightBondContract(_token.token_address).get() token_name = _bond.name elif _token.type == TokenType.IBET_SHARE.value: - _share = IbetShareContract.get(contract_address=_token.token_address) + _share = IbetShareContract(_token.token_address).get() token_name = _share.name positions.append({ "issuer_address": _token.issuer_address, @@ -371,10 +371,10 @@ def list_all_lock_events( token_name = None _token = lock_event[9] if _token.type == TokenType.IBET_STRAIGHT_BOND.value: - _bond = IbetStraightBondContract.get(contract_address=_token.token_address) + _bond = IbetStraightBondContract(_token.token_address).get() token_name = _bond.name elif _token.type == TokenType.IBET_SHARE.value: - _share = IbetShareContract.get(contract_address=_token.token_address) + _share = IbetShareContract(_token.token_address).get() token_name = _share.name block_timestamp_utc = timezone("UTC").localize(lock_event[8]) @@ -465,8 +465,7 @@ def force_unlock( "data": "" } try: - IbetSecurityTokenInterface.force_unlock( - contract_address=data.token_address, + IbetSecurityTokenInterface(data.token_address).force_unlock( data=ForceUnlockParams(**unlock_data), tx_from=issuer_address, private_key=private_key @@ -540,10 +539,10 @@ def retrieve_position( # Get Token Name token_name = None if _token.type == TokenType.IBET_STRAIGHT_BOND.value: - _bond = IbetStraightBondContract.get(contract_address=_token.token_address) + _bond = IbetStraightBondContract(_token.token_address).get() token_name = _bond.name elif _token.type == TokenType.IBET_SHARE.value: - _share = IbetShareContract.get(contract_address=_token.token_address) + _share = IbetShareContract(_token.token_address).get() token_name = _share.name resp = { diff --git a/app/routers/share.py b/app/routers/share.py index c799194a..92567f4b 100644 --- a/app/routers/share.py +++ b/app/routers/share.py @@ -207,7 +207,7 @@ def issue_token( token.principal_value ] try: - contract_address, abi, tx_hash = IbetShareContract.create( + contract_address, abi, tx_hash = IbetShareContract().create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -320,10 +320,11 @@ def list_all_tokens( share_tokens = [] for token in tokens: # Get contract data - share_token = IbetShareContract.get(contract_address=token.token_address).__dict__ + share_token = IbetShareContract(token.token_address).get().__dict__ issue_datetime_utc = timezone("UTC").localize(token.created) share_token["issue_datetime"] = issue_datetime_utc.astimezone(local_tz).isoformat() share_token["token_status"] = token.token_status + share_token.pop("contract_name") share_tokens.append(share_token) return json_response(share_tokens) @@ -351,10 +352,11 @@ def retrieve_token( raise InvalidParameterError("this token is temporarily unavailable") # Get contract data - share_token = IbetShareContract.get(contract_address=token_address).__dict__ + share_token = IbetShareContract(token_address).get().__dict__ issue_datetime_utc = timezone("UTC").localize(_token.created) share_token["issue_datetime"] = issue_datetime_utc.astimezone(local_tz).isoformat() share_token["token_status"] = _token.token_status + share_token.pop("contract_name") return json_response(share_token) @@ -411,8 +413,7 @@ def update_token( # Send transaction try: - IbetShareContract.update( - contract_address=token_address, + IbetShareContract(token_address).update( data=UpdateParams(**token.dict()), tx_from=issuer_address, private_key=private_key @@ -550,8 +551,7 @@ def additional_issue( # Send transaction try: - IbetShareContract.additional_issue( - contract_address=token_address, + IbetShareContract(token_address).additional_issue( data=AdditionalIssueParams(**data.dict()), tx_from=issuer_address, private_key=private_key @@ -877,8 +877,7 @@ def redeem_token( # Send transaction try: - IbetShareContract.redeem( - contract_address=token_address, + IbetShareContract(token_address).redeem( data=RedeemParams(**data.dict()), tx_from=issuer_address, private_key=private_key @@ -1577,7 +1576,7 @@ def modify_holder_personal_info( raise InvalidParameterError("this token is temporarily unavailable") # Modify Personal Info - token_contract = IbetShareContract.get(token_address) + token_contract = IbetShareContract(token_address).get() try: personal_info_contract = PersonalInfoContract( db=db, @@ -1713,7 +1712,7 @@ def register_holder_personal_info( raise InvalidParameterError("this token is temporarily unavailable") # Register Personal Info - token_contract = IbetShareContract.get(token_address) + token_contract = IbetShareContract(token_address).get() try: personal_info_contract = PersonalInfoContract( db=db, @@ -1902,8 +1901,7 @@ def transfer_ownership( raise InvalidParameterError("this token is temporarily unavailable") try: - IbetShareContract.transfer( - contract_address=token.token_address, + IbetShareContract(token.token_address).transfer( data=TransferParams(**token.dict()), tx_from=issuer_address, private_key=private_key @@ -2370,8 +2368,7 @@ def update_transfer_approval( "data": now } try: - _, tx_receipt = IbetShareContract.approve_transfer( - contract_address=token_address, + _, tx_receipt = IbetShareContract(token_address).approve_transfer( data=ApproveTransferParams(**_data), tx_from=issuer_address, private_key=private_key, @@ -2381,8 +2378,7 @@ def update_transfer_approval( # cancelTransfer should be performed immediately. # After cancelTransfer, ContractRevertError is returned. try: - IbetShareContract.cancel_transfer( - contract_address=token_address, + IbetShareContract(token_address).cancel_transfer( data=CancelTransferParams(**_data), tx_from=issuer_address, private_key=private_key, @@ -2416,8 +2412,7 @@ def update_transfer_approval( "data": now } try: - _, tx_receipt = IbetShareContract.cancel_transfer( - contract_address=token_address, + _, tx_receipt = IbetShareContract(token_address).cancel_transfer( data=CancelTransferParams(**_data), tx_from=issuer_address, private_key=private_key, diff --git a/app/utils/ledger_utils.py b/app/utils/ledger_utils.py index f9a1c161..d111ef2d 100644 --- a/app/utils/ledger_utils.py +++ b/app/utils/ledger_utils.py @@ -147,10 +147,10 @@ def __get_details_data_list(token_address: str, token_type: str, data_type: str, def __get_details_data_list_from_ibetfin(token_address: str, token_type: str, db: Session): if token_type == TokenType.IBET_SHARE.value: - token_contract = IbetShareContract.get(token_address) + token_contract = IbetShareContract(token_address).get() price = token_contract.principal_value elif token_type == TokenType.IBET_STRAIGHT_BOND.value: - token_contract = IbetStraightBondContract.get(token_address) + token_contract = IbetStraightBondContract(token_address).get() price = token_contract.face_value issuer_address = token_contract.issuer_address diff --git a/batch/processor_batch_issue_redeem.py b/batch/processor_batch_issue_redeem.py index 12f3d70f..ad12baea 100644 --- a/batch/processor_batch_issue_redeem.py +++ b/batch/processor_batch_issue_redeem.py @@ -133,8 +133,7 @@ def process(self): try: if upload.token_type == TokenType.IBET_STRAIGHT_BOND.value: if upload.category == BatchIssueRedeemProcessingCategory.ISSUE.value: - tx_hash = IbetStraightBondContract.additional_issue( - contract_address=upload.token_address, + tx_hash = IbetStraightBondContract(upload.token_address).additional_issue( data=IbetStraightBondAdditionalIssueParams( account_address=batch_data.account_address, amount=batch_data.amount @@ -143,8 +142,7 @@ def process(self): private_key=issuer_pk ) elif upload.category == BatchIssueRedeemProcessingCategory.REDEEM.value: - tx_hash = IbetStraightBondContract.redeem( - contract_address=upload.token_address, + tx_hash = IbetStraightBondContract(upload.token_address).redeem( data=IbetStraightBondRedeemParams( account_address=batch_data.account_address, amount=batch_data.amount @@ -154,8 +152,7 @@ def process(self): ) elif upload.token_type == TokenType.IBET_SHARE.value: if upload.category == BatchIssueRedeemProcessingCategory.ISSUE.value: - tx_hash = IbetShareContract.additional_issue( - contract_address=upload.token_address, + tx_hash = IbetShareContract(upload.token_address).additional_issue( data=IbetShareAdditionalIssueParams( account_address=batch_data.account_address, amount=batch_data.amount @@ -164,8 +161,7 @@ def process(self): private_key=issuer_pk ) elif upload.category == BatchIssueRedeemProcessingCategory.REDEEM.value: - tx_hash = IbetShareContract.redeem( - contract_address=upload.token_address, + tx_hash = IbetShareContract(upload.token_address).redeem( data=IbetShareRedeemParams( account_address=batch_data.account_address, amount=batch_data.amount diff --git a/batch/processor_batch_register_personal_info.py b/batch/processor_batch_register_personal_info.py index f6d88f36..e6779fe9 100644 --- a/batch/processor_batch_register_personal_info.py +++ b/batch/processor_batch_register_personal_info.py @@ -213,9 +213,9 @@ def __load_personal_info_contract_accessor(self, db_session: Session, issuer_add all() for token in token_list: if token.type == TokenType.IBET_SHARE.value: - token_contract = IbetShareContract.get(token.token_address) + token_contract = IbetShareContract(token.token_address).get() elif token.type == TokenType.IBET_STRAIGHT_BOND.value: - token_contract = IbetStraightBondContract.get(token.token_address) + token_contract = IbetStraightBondContract(token.token_address).get() else: continue diff --git a/batch/processor_bulk_transfer.py b/batch/processor_bulk_transfer.py index 8cc2d21e..94f6b7de 100644 --- a/batch/processor_bulk_transfer.py +++ b/batch/processor_bulk_transfer.py @@ -157,16 +157,14 @@ def process(self): try: if _transfer.token_type == TokenType.IBET_SHARE.value: _transfer_data = IbetShareTransferParams(**token) - IbetShareContract.transfer( - contract_address=_transfer.token_address, + IbetShareContract(_transfer.token_address).transfer( data=_transfer_data, tx_from=_transfer.issuer_address, private_key=private_key ) elif _transfer.token_type == TokenType.IBET_STRAIGHT_BOND.value: _transfer_data = IbetStraightBondTransferParams(**token) - IbetStraightBondContract.transfer( - contract_address=_transfer.token_address, + IbetStraightBondContract(_transfer.token_address).transfer( data=_transfer_data, tx_from=_transfer.issuer_address, private_key=private_key diff --git a/batch/processor_modify_personal_info.py b/batch/processor_modify_personal_info.py index 7a8d4db1..85669f91 100644 --- a/batch/processor_modify_personal_info.py +++ b/batch/processor_modify_personal_info.py @@ -142,9 +142,9 @@ def __get_personal_info_contract_accessor_list(self, personal_info_contract_list = set() for token in token_list: if token.type == TokenType.IBET_SHARE.value: - token_contract = IbetShareContract.get(token.token_address) + token_contract = IbetShareContract(token.token_address).get() elif token.type == TokenType.IBET_STRAIGHT_BOND.value: - token_contract = IbetStraightBondContract.get(token.token_address) + token_contract = IbetStraightBondContract(token.token_address).get() else: continue diff --git a/batch/processor_scheduled_events.py b/batch/processor_scheduled_events.py index cbdf97e4..4043e438 100644 --- a/batch/processor_scheduled_events.py +++ b/batch/processor_scheduled_events.py @@ -191,8 +191,7 @@ def __process(self, db_session: Session, events_list: List[ScheduledEvents]): # Update if _event.event_type == ScheduledEventType.UPDATE.value: _update_data = IbetShareUpdateParams(**_event.data) - IbetShareContract.update( - contract_address=_event.token_address, + IbetShareContract(_event.token_address).update( data=_update_data, tx_from=_event.issuer_address, private_key=private_key @@ -201,8 +200,7 @@ def __process(self, db_session: Session, events_list: List[ScheduledEvents]): # Update if _event.event_type == ScheduledEventType.UPDATE.value: _update_data = IbetStraightBondUpdateParams(**_event.data) - IbetStraightBondContract.update( - contract_address=_event.token_address, + IbetStraightBondContract(_event.token_address).update( data=_update_data, tx_from=_event.issuer_address, private_key=private_key diff --git a/batch/processor_update_token.py b/batch/processor_update_token.py index 6a5aaf11..b2e12e3a 100644 --- a/batch/processor_update_token.py +++ b/batch/processor_update_token.py @@ -147,8 +147,7 @@ def process(self): token_type=TokenType.IBET_SHARE.value, arguments=_update_token.arguments ) - IbetShareContract.update( - contract_address=_update_token.token_address, + IbetShareContract(_update_token.token_address).update( data=_update_data, tx_from=_update_token.issuer_address, private_key=private_key @@ -161,8 +160,7 @@ def process(self): token_type=TokenType.IBET_STRAIGHT_BOND.value, arguments=_update_token.arguments ) - IbetStraightBondContract.update( - contract_address=_update_token.token_address, + IbetStraightBondContract(_update_token.token_address).update( data=_update_data, tx_from=_update_token.issuer_address, private_key=private_key diff --git a/tests/model/blockchain/test_exchange_IbetExchangeInterface.py b/tests/model/blockchain/test_exchange_IbetExchangeInterface.py index d7cf19ca..9a4eb4e6 100644 --- a/tests/model/blockchain/test_exchange_IbetExchangeInterface.py +++ b/tests/model/blockchain/test_exchange_IbetExchangeInterface.py @@ -104,7 +104,7 @@ def issue_bond_token(issuer: dict, exchange_address: str): "リターン内容", "発行目的" ] - token_contract_address, abi, tx_hash = IbetStraightBondContract.create( + token_contract_address, abi, tx_hash = IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=issuer_pk diff --git a/tests/model/blockchain/test_exchange_IbetSecurityTokenEscrow.py b/tests/model/blockchain/test_exchange_IbetSecurityTokenEscrow.py index f66417d8..b44d704b 100644 --- a/tests/model/blockchain/test_exchange_IbetSecurityTokenEscrow.py +++ b/tests/model/blockchain/test_exchange_IbetSecurityTokenEscrow.py @@ -112,7 +112,7 @@ def issue_bond_token(issuer: dict, exchange_address: str): "リターン内容", "発行目的" ] - token_contract_address, abi, tx_hash = IbetStraightBondContract.create( + token_contract_address, abi, tx_hash = IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=issuer_pk diff --git a/tests/model/blockchain/test_token_IbetShare.py b/tests/model/blockchain/test_token_IbetShare.py index e9cccd9b..6b6dcb06 100644 --- a/tests/model/blockchain/test_token_IbetShare.py +++ b/tests/model/blockchain/test_token_IbetShare.py @@ -86,7 +86,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -125,8 +126,9 @@ def test_error_1(self, db): # execute the function arguments = [] + share_contract = IbetShareContract() with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.create( + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -158,8 +160,9 @@ def test_error_2(self, db): 0, "string" ] # invalid types + share_contract = IbetShareContract() with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.create( + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -191,8 +194,9 @@ def test_error_3(self, db): "20221231", 10000 ] + share_contract = IbetShareContract() with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.create( + share_contract.create( args=arguments, tx_from=issuer_address[:-1], # short address private_key=private_key @@ -220,8 +224,9 @@ def test_error_4(self, db): "20221231", 10000 ] + share_contract = IbetShareContract() with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.create( + share_contract.create( args=arguments, tx_from=issuer_address, private_key="some_private_key" @@ -231,6 +236,44 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") + # + # Already deployed + def test_error_5(self, db): + test_account = config_eth_account("user1") + issuer_address = test_account.get("address") + private_key = decode_keyfile_json( + raw_keyfile_json=test_account.get("keyfile_json"), + password=test_account.get("password").encode("utf-8") + ) + + # execute the function + arguments = [ + "テスト株式", + "TEST", + 10000, + 20000, + 1, + "20211231", + "20211231", + "20221231", + 10000 + ] + contract_address, abi, tx_hash = IbetShareContract().create( + args=arguments, + tx_from=issuer_address, + private_key=private_key + ) + + with pytest.raises(SendTransactionError) as exc_info: + IbetShareContract(contract_address).create( + args=arguments, + tx_from=issuer_address, + private_key=private_key + ) + + # assertion + assert exc_info.match("contract is already deployed") + class TestGet: @@ -262,14 +305,15 @@ def test_normal_1(self, db): "20221231", 10001 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key ) # execute the function - share_contract = IbetShareContract.get(contract_address=contract_address) + share_contract = share_contract.get() # assertion assert share_contract.issuer_address == issuer_address @@ -319,7 +363,8 @@ def test_normal_2(self, db): "20221231", 10001 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -358,7 +403,7 @@ def test_normal_2(self, db): db.commit() # execute the function - share_contract = IbetShareContract.get(contract_address=contract_address) + share_contract = share_contract.get() # assertion assert share_contract.issuer_address == issuer_address @@ -408,7 +453,8 @@ def test_normal_3(self, db): "20221231", 10001 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -454,7 +500,7 @@ def test_normal_3(self, db): db.commit() # execute the function - share_contract = IbetShareContract.get(contract_address=contract_address) + share_contract = share_contract.get() # assertion assert share_contract.issuer_address == issuer_address @@ -482,8 +528,9 @@ def test_normal_3(self, db): # # contract not deployed def test_normal_4(self, db): + share_contract = IbetShareContract() # execute the function - share_contract = IbetShareContract.get(contract_address=ZERO_ADDRESS) + share_contract = share_contract.get() # assertion assert share_contract.issuer_address == ZERO_ADDRESS @@ -512,15 +559,6 @@ def test_normal_4(self, db): # Error Case ########################################################################### - # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - # execute the function - with pytest.raises(ValueError) as exc_info: - IbetShareContract.get(contract_address=ZERO_ADDRESS[:-1]) - # assertion - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - class TestUpdate: @@ -550,7 +588,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -560,15 +599,14 @@ def test_normal_1(self, db): _data = {} _add_data = UpdateParams(**_data) pre_datetime = datetime.utcnow() - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - share_contract = IbetShareContract.get(contract_address=contract_address) + share_contract = share_contract.get() assert share_contract.cancellation_date == "20221231" assert share_contract.dividend_record_date == "20211231" assert share_contract.dividend_payment_date == "20211231" @@ -584,6 +622,7 @@ def test_normal_1(self, db): assert share_contract.principal_value == 10000 assert share_contract.is_canceled is False assert share_contract.memo == "" + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -611,7 +650,8 @@ def test_normal_2(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -637,15 +677,14 @@ def test_normal_2(self, db): } _add_data = UpdateParams(**_data) pre_datetime = datetime.utcnow() - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - share_contract = IbetShareContract.get(contract_address=contract_address) + share_contract = share_contract.get() assert share_contract.cancellation_date == "20211231" assert share_contract.dividend_record_date == "20210930" assert share_contract.dividend_payment_date == "20211001" @@ -671,53 +710,9 @@ def test_normal_2(self, db): ########################################################################### # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - - # deploy token - arguments = [ - "テスト株式", - "TEST", - 10000, - 20000, - 1, - "20211231", - "20211231", - "20221231", - 10000 - ] - contract_address, abi, tx_hash = IbetShareContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # update - _data = { - "interest_rate": 0.0001, - } - _add_data = UpdateParams(**_data) - with pytest.raises(ValueError) as exc_info: - IbetShareContract.update( - contract_address=contract_address[:-1], # short - data=_add_data, - tx_from=issuer_address, - private_key=private_key - ) - - # assertion - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - - # # Validation (UpdateParams) # invalid parameter - def test_error_2(self, db): + def test_error_1(self, db): # update _data = { "dividends": 0.00000000000001, @@ -742,9 +737,9 @@ def test_error_2(self, db): } ] - # + # # invalid tx_from - def test_error_3(self, db): + def test_error_2(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -764,7 +759,8 @@ def test_error_3(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -776,8 +772,7 @@ def test_error_3(self, db): } _add_data = UpdateParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from="invalid_tx_from", private_key="invalid private key" @@ -785,9 +780,9 @@ def test_error_3(self, db): assert isinstance(exc_info.value.args[0], InvalidAddress) assert exc_info.match("ENS name: \'invalid_tx_from\' is invalid.") - # + # # invalid private key - def test_error_4(self, db): + def test_error_3(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -807,7 +802,8 @@ def test_error_4(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -819,16 +815,15 @@ def test_error_4(self, db): } _add_data = UpdateParams(**_data) with pytest.raises(SendTransactionError): - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from=issuer_address, private_key="invalid private key" ) - # + # # TimeExhausted - def test_error_5(self, db): + def test_error_4(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -848,7 +843,8 @@ def test_error_5(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -867,8 +863,7 @@ def test_error_5(self, db): _add_data = UpdateParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key @@ -877,9 +872,9 @@ def test_error_5(self, db): # assertion assert isinstance(exc_info.value.args[0], TimeExhausted) - # + # # Transaction Error - def test_error_6(self, db): + def test_error_5(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -899,7 +894,8 @@ def test_error_6(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -918,8 +914,7 @@ def test_error_6(self, db): _add_data = UpdateParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key @@ -928,9 +923,9 @@ def test_error_6(self, db): # assertion assert isinstance(exc_info.value.args[0], TransactionNotFound) - # + # # Transaction REVERT(not owner) - def test_error_7(self, db): + def test_error_6(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") user_account = config_eth_account("user2") @@ -956,7 +951,8 @@ def test_error_7(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -977,8 +973,7 @@ def test_error_7(self, db): } _add_data = UpdateParams(**_data) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.update( - contract_address=contract_address, + share_contract.update( data=_add_data, tx_from=user_address, private_key=user_private_key @@ -1018,7 +1013,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - token_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=from_address, private_key=from_private_key @@ -1031,22 +1027,15 @@ def test_normal_1(self, db): "amount": 10 } _transfer_data = TransferParams(**_data) - IbetShareContract.transfer( - contract_address=token_address, + share_contract.transfer( data=_transfer_data, tx_from=from_address, private_key=from_private_key ) # assertion - from_balance = IbetShareContract.get_account_balance( - contract_address=token_address, - account_address=from_address - ) - to_balance = IbetShareContract.get_account_balance( - contract_address=token_address, - account_address=to_address - ) + from_balance = share_contract.get_account_balance(from_address) + to_balance = share_contract.get_account_balance(to_address) assert from_balance == arguments[3] - 10 assert to_balance == 10 @@ -1132,7 +1121,8 @@ def test_error_3(self, db): "20221231", 10000 ] - token_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=from_address, private_key=from_private_key @@ -1146,8 +1136,7 @@ def test_error_3(self, db): } _transfer_data = TransferParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.transfer( - contract_address=token_address, + share_contract.transfer( data=_transfer_data, tx_from="invalid_tx_from", private_key=from_private_key @@ -1180,7 +1169,8 @@ def test_error_4(self, db): "20221231", 10000 ] - token_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=from_address, private_key=from_private_key @@ -1194,8 +1184,7 @@ def test_error_4(self, db): } _transfer_data = TransferParams(**_data) with pytest.raises(SendTransactionError): - IbetShareContract.transfer( - contract_address=token_address, + share_contract.transfer( data=_transfer_data, tx_from=from_address, private_key="invalid_private_key" @@ -1226,7 +1215,8 @@ def test_error_5(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1247,8 +1237,7 @@ def test_error_5(self, db): _transfer_data = TransferParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.transfer( - contract_address=contract_address, + share_contract.transfer( data=_transfer_data, tx_from=issuer_address, private_key=private_key @@ -1280,7 +1269,8 @@ def test_error_6(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1301,8 +1291,7 @@ def test_error_6(self, db): _transfer_data = TransferParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.transfer( - contract_address=contract_address, + share_contract.transfer( data=_transfer_data, tx_from=issuer_address, private_key=private_key @@ -1334,7 +1323,8 @@ def test_error_7(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1358,8 +1348,7 @@ def test_error_7(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.transfer( - contract_address=contract_address, + share_contract.transfer( data=_transfer_data, tx_from=issuer_address, private_key=private_key @@ -1396,7 +1385,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1409,21 +1399,19 @@ def test_normal_1(self, db): } _add_data = AdditionalIssueParams(**_data) pre_datetime = datetime.utcnow() - IbetShareContract.additional_issue( - contract_address=contract_address, + share_contract.additional_issue( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - share_contract = IbetShareContract.get(contract_address=contract_address) - assert share_contract.total_supply == arguments[3] + 10 - balance = IbetShareContract.get_account_balance( - contract_address=contract_address, - account_address=issuer_address - ) + share_contract_attr = share_contract.get() + assert share_contract_attr.total_supply == arguments[3] + 10 + + balance = share_contract.get_account_balance(issuer_address) assert balance == arguments[3] + 10 + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -1434,51 +1422,8 @@ def test_normal_1(self, db): ########################################################################### # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - # deploy token - arguments = [ - "テスト株式", - "TEST", - 10000, - 20000, - 1, - "20211231", - "20211231", - "20221231", - 10000 - ] - contract_address, abi, tx_hash = IbetShareContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # additional issue - _data = { - "account_address": issuer_address, - "amount": 10 - } - _add_data = AdditionalIssueParams(**_data) - with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.additional_issue( - contract_address=contract_address[:-1], # short - data=_add_data, - tx_from=issuer_address, - private_key=private_key - ) - assert isinstance(exc_info.value.args[0], ValueError) - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - - # # invalid parameter (AdditionalIssueParams) - def test_error_2(self, db): + def test_error_1(self, db): _data = {} with pytest.raises(ValidationError) as exc_info: AdditionalIssueParams(**_data) @@ -1494,9 +1439,9 @@ def test_error_2(self, db): } ] - # + # # invalid parameter (AdditionalIssueParams) - def test_error_3(self, db): + def test_error_2(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") @@ -1521,9 +1466,9 @@ def test_error_3(self, db): } ] - # + # # invalid tx_from - def test_error_4(self, db): + def test_error_3(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1543,7 +1488,8 @@ def test_error_4(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1556,8 +1502,7 @@ def test_error_4(self, db): } _add_data = AdditionalIssueParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.additional_issue( - contract_address=contract_address, + share_contract.additional_issue( data=_add_data, tx_from="invalid_tx_from", private_key=private_key @@ -1565,9 +1510,9 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], InvalidAddress) assert exc_info.match("ENS name: \'invalid_tx_from\' is invalid.") - # + # # invalid private key - def test_error_5(self, db): + def test_error_4(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1587,7 +1532,8 @@ def test_error_5(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1600,8 +1546,7 @@ def test_error_5(self, db): } _add_data = AdditionalIssueParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.additional_issue( - contract_address=contract_address, + share_contract.additional_issue( data=_add_data, tx_from=test_account.get("address"), private_key="invalid_private_key" @@ -1609,9 +1554,9 @@ def test_error_5(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") - # + # # TimeExhausted - def test_error_6(self, db): + def test_error_5(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1631,7 +1576,8 @@ def test_error_6(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1651,17 +1597,16 @@ def test_error_6(self, db): _add_data = AdditionalIssueParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.additional_issue( - contract_address=contract_address, + share_contract.additional_issue( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert exc_info.type(SendTransactionError(TimeExhausted)) - # + # # Error - def test_error_7(self, db): + def test_error_6(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1681,7 +1626,8 @@ def test_error_7(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1701,17 +1647,16 @@ def test_error_7(self, db): _add_data = AdditionalIssueParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.additional_issue( - contract_address=contract_address, + share_contract.additional_issue( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], TransactionNotFound) - # + # # Transaction REVERT(not owner) - def test_error_8(self, db): + def test_error_7(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") user_account = config_eth_account("user2") @@ -1737,7 +1682,8 @@ def test_error_8(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_private_key @@ -1761,8 +1707,7 @@ def test_error_8(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.additional_issue( - contract_address=contract_address, + share_contract.additional_issue( data=_add_data, tx_from=user_address, private_key=user_private_key @@ -1799,7 +1744,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1812,21 +1758,19 @@ def test_normal_1(self, db): } _add_data = RedeemParams(**_data) pre_datetime = datetime.utcnow() - IbetShareContract.redeem( - contract_address=contract_address, + share_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - share_contract = IbetShareContract.get(contract_address=contract_address) - assert share_contract.total_supply == arguments[3] - 10 - balance = IbetShareContract.get_account_balance( - contract_address=contract_address, - account_address=issuer_address - ) + share_contract_attr = share_contract.get() + assert share_contract_attr.total_supply == arguments[3] - 10 + + balance = share_contract.get_account_balance(issuer_address) assert balance == arguments[3] - 10 + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -1837,51 +1781,8 @@ def test_normal_1(self, db): ########################################################################### # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - # deploy token - arguments = [ - "テスト株式", - "TEST", - 10000, - 20000, - 1, - "20211231", - "20211231", - "20221231", - 10000 - ] - contract_address, abi, tx_hash = IbetShareContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # redeem - _data = { - "account_address": issuer_address, - "amount": 10 - } - _add_data = RedeemParams(**_data) - with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.redeem( - contract_address=contract_address[:-1], # short - data=_add_data, - tx_from=issuer_address, - private_key=private_key - ) - assert isinstance(exc_info.value.args[0], ValueError) - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - - # # invalid parameter (RedeemParams) - def test_error_2(self, db): + def test_error_1(self, db): _data = {} with pytest.raises(ValidationError) as exc_info: RedeemParams(**_data) @@ -1897,9 +1798,9 @@ def test_error_2(self, db): } ] - # + # # invalid parameter (RedeemParams) - def test_error_3(self, db): + def test_error_2(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") @@ -1924,9 +1825,9 @@ def test_error_3(self, db): } ] - # + # # invalid tx_from - def test_error_4(self, db): + def test_error_3(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1946,7 +1847,8 @@ def test_error_4(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1959,8 +1861,7 @@ def test_error_4(self, db): } _add_data = RedeemParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.redeem( - contract_address=contract_address, + share_contract.redeem( data=_add_data, tx_from="invalid_tx_from", private_key=private_key @@ -1968,9 +1869,9 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], InvalidAddress) assert exc_info.match("ENS name: \'invalid_tx_from\' is invalid.") - # + # # invalid private key - def test_error_5(self, db): + def test_error_4(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1990,7 +1891,8 @@ def test_error_5(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2003,8 +1905,7 @@ def test_error_5(self, db): } _add_data = RedeemParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.redeem( - contract_address=contract_address, + share_contract.redeem( data=_add_data, tx_from=test_account.get("address"), private_key="invalid_private_key" @@ -2012,9 +1913,9 @@ def test_error_5(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") - # + # # TimeExhausted - def test_error_6(self, db): + def test_error_5(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -2034,7 +1935,8 @@ def test_error_6(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2054,17 +1956,16 @@ def test_error_6(self, db): _add_data = RedeemParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.redeem( - contract_address=contract_address, + share_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert exc_info.type(SendTransactionError(TimeExhausted)) - # + # # Error - def test_error_7(self, db): + def test_error_6(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -2084,7 +1985,8 @@ def test_error_7(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2104,17 +2006,16 @@ def test_error_7(self, db): _add_data = RedeemParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.redeem( - contract_address=contract_address, + share_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], TransactionNotFound) - # + # # Transaction REVERT(lack balance) - def test_error_8(self, db): + def test_error_7(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -2134,7 +2035,8 @@ def test_error_8(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2158,8 +2060,7 @@ def test_error_8(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.redeem( - contract_address=contract_address, + share_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key @@ -2196,17 +2097,15 @@ def test_normal_1(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key ) # assertion - balance = IbetShareContract.get_account_balance( - contract_address=contract_address, - account_address=issuer_address - ) + balance = share_contract.get_account_balance(issuer_address) assert balance == arguments[3] # @@ -2216,10 +2115,8 @@ def test_normal_2(self, db): issuer_address = test_account.get("address") # execute the function - balance = IbetShareContract.get_account_balance( - ZERO_ADDRESS, - issuer_address - ) + share_contract = IbetShareContract(ZERO_ADDRESS) + balance = share_contract.get_account_balance(issuer_address) # assertion assert balance == 0 @@ -2229,45 +2126,8 @@ def test_normal_2(self, db): ########################################################################### # - # invalid contract_address - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - # deploy token - arguments = [ - "テスト株式", - "TEST", - 10000, - 20000, - 1, - "20211231", - "20211231", - "20221231", - 10000 - ] - contract_address, abi, tx_hash = IbetShareContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # execute the function - with pytest.raises(ValueError) as exc_info: - IbetShareContract.get_account_balance( - contract_address[:-1], # short - issuer_address - ) - - # assertion - assert exc_info.match(f"Unknown format {contract_address[:-1]}, attempted to normalize to ") - - # # invalid account_address - def test_error_2(self, db): + def test_error_1(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -2287,7 +2147,8 @@ def test_error_2(self, db): "20221231", 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2295,8 +2156,7 @@ def test_error_2(self, db): # execute the function with pytest.raises(Web3ValidationError): - IbetShareContract.get_account_balance( - contract_address, + share_contract.get_account_balance( issuer_address[:-1] # short ) @@ -2314,7 +2174,8 @@ def test_normal_1(self, db): before_datetime = datetime.utcnow() # Test - result = IbetShareContract.check_attr_update(db, self.token_address, before_datetime) + share_contract = IbetShareContract(self.token_address) + result = share_contract.check_attr_update(db, before_datetime) # assertion assert result is False @@ -2334,7 +2195,8 @@ def test_normal_2(self, db): db.commit() # Test - result = IbetShareContract.check_attr_update(db, self.token_address, after_datetime) + share_contract = IbetShareContract(self.token_address) + result = share_contract.check_attr_update(db, after_datetime) # assertion assert result is False @@ -2354,7 +2216,8 @@ def test_normal_3(self, db): db.commit() # Test - result = IbetShareContract.check_attr_update(db, self.token_address, before_datetime) + share_contract = IbetShareContract(self.token_address) + result = share_contract.check_attr_update(db, before_datetime) # assertion assert result is True @@ -2376,7 +2239,8 @@ class TestRecordAttrUpdate: @pytest.mark.freeze_time('2021-04-27 12:34:56') def test_normal_1(self, db): # Test - IbetShareContract.record_attr_update(db, self.token_address) + share_contract = IbetShareContract(self.token_address) + share_contract.record_attr_update(db) # assertion _update = db.query(TokenAttrUpdate).first() @@ -2399,7 +2263,8 @@ def test_normal_2(self, db, freezer): freezer.move_to('2021-04-27 12:34:56') # Test - IbetShareContract.record_attr_update(db, self.token_address) + share_contract = IbetShareContract(self.token_address) + share_contract.record_attr_update(db) # assertion _update = db.query(TokenAttrUpdate).filter(TokenAttrUpdate.id == 2).first() @@ -2461,7 +2326,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2473,8 +2339,7 @@ def test_normal_1(self, db): "transfer_approval_required": True, "transferable": True } - IbetShareContract.update( - contract_address=token_address, + share_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2501,8 +2366,7 @@ def test_normal_1(self, db): "application_id": 0, "data": "approve transfer test" } - tx_hash, tx_receipt = IbetShareContract.approve_transfer( - contract_address=token_address, + tx_hash, tx_receipt = share_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -2511,6 +2375,7 @@ def test_normal_1(self, db): # assertion assert isinstance(tx_hash, str) and int(tx_hash, 16) > 0 assert tx_receipt["status"] == 1 + share_token = ContractUtils.get_contract( contract_name="IbetShare", contract_address=token_address @@ -2520,6 +2385,7 @@ def test_normal_1(self, db): assert applications[1] == to_address assert applications[2] == 10 assert applications[3] is False + pendingTransfer = share_token.functions.pendingTransfer(issuer_address).call() issuer_value = share_token.functions.balanceOf(issuer_address).call() to_value = share_token.functions.balanceOf(to_address).call() @@ -2569,9 +2435,9 @@ def test_error_2(self, db): "data": "test_data" } _approve_transfer_data = ApproveTransferParams(**approve_data) + share_contract = IbetShareContract("not address") with pytest.raises(SendTransactionError) as ex_info: - IbetShareContract.approve_transfer( - contract_address="not address", + share_contract.approve_transfer( data=_approve_transfer_data, tx_from=issuer_address, private_key=private_key @@ -2600,8 +2466,8 @@ def test_error_3(self, db): "20221231", 10000 ] - - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2614,8 +2480,7 @@ def test_error_3(self, db): } _approve_transfer_data = ApproveTransferParams(**approve_data) with pytest.raises(SendTransactionError) as ex_info: - IbetShareContract.approve_transfer( - contract_address=contract_address, + share_contract.approve_transfer( data=_approve_transfer_data, tx_from=issuer_address[:-1], private_key=private_key @@ -2645,7 +2510,8 @@ def test_error_4(self, db): 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2658,8 +2524,7 @@ def test_error_4(self, db): } _approve_transfer_data = ApproveTransferParams(**approve_data) with pytest.raises(SendTransactionError) as ex_info: - IbetShareContract.approve_transfer( - contract_address=contract_address, + share_contract.approve_transfer( data=_approve_transfer_data, tx_from=issuer_address, private_key="dummy-private" @@ -2710,8 +2575,8 @@ def test_error_5(self, db): "20221231", 10000 ] - - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2723,8 +2588,7 @@ def test_error_5(self, db): "transfer_approval_required": True, "transferable": True } - IbetShareContract.update( - contract_address=token_address, + share_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2751,8 +2615,7 @@ def test_error_5(self, db): "application_id": 0, "data": "approve transfer test" } - IbetShareContract.approve_transfer( - contract_address=token_address, + share_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -2771,8 +2634,7 @@ def test_error_5(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.approve_transfer( - contract_address=token_address, + share_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -2831,7 +2693,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2843,8 +2706,7 @@ def test_normal_1(self, db): "transfer_approval_required": True, "transferable": True } - IbetShareContract.update( - contract_address=token_address, + share_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2873,8 +2735,7 @@ def test_normal_1(self, db): } _approve_transfer_data = CancelTransferParams(**cancel_data) - tx_hash, tx_receipt = IbetShareContract.cancel_transfer( - contract_address=token_address, + tx_hash, tx_receipt = share_contract.cancel_transfer( data=_approve_transfer_data, tx_from=issuer_address, private_key=issuer_pk @@ -2941,9 +2802,9 @@ def test_error_2(self, db): "data": "test_data" } _cancel_transfer_data = CancelTransferParams(**cancel_data) + share_contract = IbetShareContract("not address") with pytest.raises(SendTransactionError) as ex_info: - IbetShareContract.cancel_transfer( - contract_address="not address", + share_contract.cancel_transfer( data=_cancel_transfer_data, tx_from=issuer_address, private_key=private_key @@ -2973,7 +2834,8 @@ def test_error_3(self, db): 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2986,8 +2848,7 @@ def test_error_3(self, db): } _cancel_transfer_data = CancelTransferParams(**cancel_data) with pytest.raises(SendTransactionError) as ex_info: - IbetShareContract.cancel_transfer( - contract_address=contract_address, + share_contract.cancel_transfer( data=_cancel_transfer_data, tx_from=issuer_address[:-1], private_key=private_key @@ -3017,7 +2878,8 @@ def test_error_4(self, db): 10000 ] - contract_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + contract_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -3030,8 +2892,7 @@ def test_error_4(self, db): } _cancel_transfer_data = CancelTransferParams(**cancel_data) with pytest.raises(SendTransactionError) as ex_info: - IbetShareContract.cancel_transfer( - contract_address=contract_address, + share_contract.cancel_transfer( data=_cancel_transfer_data, tx_from=issuer_address, private_key="dummy-private" @@ -3082,8 +2943,8 @@ def test_error_5(self, db): "20221231", 10000 ] - - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3095,8 +2956,7 @@ def test_error_5(self, db): "transfer_approval_required": True, "transferable": True } - IbetShareContract.update( - contract_address=token_address, + share_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -3123,8 +2983,7 @@ def test_error_5(self, db): "application_id": 0, "data": "approve transfer test" } - IbetShareContract.approve_transfer( - contract_address=token_address, + share_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -3143,8 +3002,7 @@ def test_error_5(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.cancel_transfer( - contract_address=token_address, + share_contract.cancel_transfer( data=CancelTransferParams(**cancel_data), tx_from=issuer_address, private_key=issuer_pk @@ -3184,7 +3042,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3196,8 +3055,7 @@ def test_normal_1(self, db): "value": 10, "data": "" } - tx_hash, tx_receipt = IbetShareContract.lock( - contract_address=token_address, + tx_hash, tx_receipt = share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3296,7 +3154,8 @@ def test_error_2_1(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3309,8 +3168,7 @@ def test_error_2_1(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from="invalid_tx_from", # invalid tx from private_key="", @@ -3345,7 +3203,8 @@ def test_error_2_2(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3358,8 +3217,7 @@ def test_error_2_2(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key="invalid_pk", # invalid pk @@ -3394,7 +3252,8 @@ def test_error_3(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3414,8 +3273,7 @@ def test_error_3(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3449,7 +3307,8 @@ def test_error_4(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3469,8 +3328,7 @@ def test_error_4(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3503,7 +3361,8 @@ def test_error_5(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3525,8 +3384,7 @@ def test_error_5(self, db): "data": "" } with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3567,7 +3425,8 @@ def test_normal_1(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3579,8 +3438,7 @@ def test_normal_1(self, db): "value": 10, "data": "" } - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3594,8 +3452,7 @@ def test_normal_1(self, db): "value": 5, "data": "" } - tx_hash, tx_receipt = IbetShareContract.force_unlock( - contract_address=token_address, + tx_hash, tx_receipt = share_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3717,7 +3574,8 @@ def test_error_2_1(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3729,8 +3587,7 @@ def test_error_2_1(self, db): "value": 10, "data": "" } - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3745,8 +3602,7 @@ def test_error_2_1(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.force_unlock( - contract_address=token_address, + share_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from="invalid_tx_from", # invalid tx from private_key="", @@ -3781,7 +3637,8 @@ def test_error_2_2(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3793,8 +3650,7 @@ def test_error_2_2(self, db): "value": 10, "data": "" } - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3809,8 +3665,7 @@ def test_error_2_2(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.force_unlock( - contract_address=token_address, + share_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key="invalid_pk", # invalid pk @@ -3845,7 +3700,8 @@ def test_error_3(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3857,8 +3713,7 @@ def test_error_3(self, db): "value": 10, "data": "" } - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3880,8 +3735,7 @@ def test_error_3(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.force_unlock( - contract_address=token_address, + share_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3915,7 +3769,8 @@ def test_error_4(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3927,8 +3782,7 @@ def test_error_4(self, db): "value": 10, "data": "" } - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3950,8 +3804,7 @@ def test_error_4(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetShareContract.force_unlock( - contract_address=token_address, + share_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3984,7 +3837,8 @@ def test_error_5(self, db): "20221231", 10000 ] - token_address, _, _ = IbetShareContract.create( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3996,8 +3850,7 @@ def test_error_5(self, db): "value": 10, "data": "" } - IbetShareContract.lock( - contract_address=token_address, + share_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -4021,8 +3874,7 @@ def test_error_5(self, db): "data": "" } with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetShareContract.force_unlock( - contract_address=token_address, + share_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk diff --git a/tests/model/blockchain/test_token_IbetStraightBond.py b/tests/model/blockchain/test_token_IbetStraightBond.py index 8fd517f3..fc4d5f84 100644 --- a/tests/model/blockchain/test_token_IbetStraightBond.py +++ b/tests/model/blockchain/test_token_IbetStraightBond.py @@ -86,7 +86,7 @@ def test_normal_1(self, db): "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + contract_address, abi, tx_hash = IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -125,7 +125,7 @@ def test_error_1(self, db): # execute the function arguments = [] with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.create( + IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -158,7 +158,7 @@ def test_error_2(self, db): 0 ] # invalid types with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.create( + IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -191,7 +191,7 @@ def test_error_3(self, db): "発行目的" ] with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.create( + IbetStraightBondContract().create( args=arguments, tx_from=issuer_address[:-1], # short address private_key=private_key @@ -220,7 +220,7 @@ def test_error_4(self, db): "発行目的" ] with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.create( + IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key="some_private_key" @@ -230,6 +230,43 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") + # + # Already deployed + def test_error_5(self, db): + test_account = config_eth_account("user1") + issuer_address = test_account.get("address") + private_key = decode_keyfile_json( + raw_keyfile_json=test_account.get("keyfile_json"), + password=test_account.get("password").encode("utf-8") + ) + + # execute the function + arguments = [ + "テスト債券", + "TEST", + 10000, + 20000, + "20211231", + 30000, + "20211231", + "リターン内容", + "発行目的" + ] + contract_address, abi, tx_hash = IbetStraightBondContract().create( + args=arguments, + tx_from=issuer_address, + private_key=private_key + ) + + with pytest.raises(SendTransactionError) as exc_info: + IbetStraightBondContract(contract_address).create( + args=arguments, + tx_from=issuer_address, + private_key=private_key + ) + # assertion + assert exc_info.match("contract is already deployed") + class TestGet: @@ -255,7 +292,7 @@ def test_normal_1(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + contract_address, abi, tx_hash = IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -263,7 +300,7 @@ def test_normal_1(self, db): # get token data pre_datetime = datetime.utcnow() - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) + bond_contract = IbetStraightBondContract(contract_address).get() # assertion assert bond_contract.issuer_address == test_account["address"] @@ -309,7 +346,7 @@ def test_normal_2(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + contract_address, abi, tx_hash = IbetStraightBondContract(ZERO_ADDRESS).create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -353,7 +390,7 @@ def test_normal_2(self, db): db.commit() # get token data - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) + bond_contract = IbetStraightBondContract(contract_address).get() # assertion assert bond_contract.issuer_address == test_account["address"] @@ -401,7 +438,7 @@ def test_normal_3(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + contract_address, abi, tx_hash = IbetStraightBondContract(ZERO_ADDRESS).create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -451,7 +488,7 @@ def test_normal_3(self, db): db.commit() # get token data - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) + bond_contract = IbetStraightBondContract(contract_address).get() # assertion assert bond_contract.issuer_address == test_account["address"] @@ -482,7 +519,7 @@ def test_normal_3(self, db): # contract_address not deployed def test_normal_4(self, db): # get token data - bond_contract = IbetStraightBondContract.get(contract_address=ZERO_ADDRESS) + bond_contract = IbetStraightBondContract(ZERO_ADDRESS).get() # assertion assert bond_contract.issuer_address == ZERO_ADDRESS @@ -513,15 +550,6 @@ def test_normal_4(self, db): # Error Case ########################################################################### - # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - # get token data - with pytest.raises(ValueError) as exc_info: - IbetStraightBondContract.get(contract_address=ZERO_ADDRESS[:-1]) - # assertion - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - class TestUpdate: @@ -546,7 +574,8 @@ def test_normal_1(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + contract_address, abi, tx_hash = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -556,15 +585,14 @@ def test_normal_1(self, db): _data = {} _add_data = UpdateParams(**_data) pre_datetime = datetime.utcnow() - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) + bond_contract = bond_contract.get() assert bond_contract.face_value == 20000 assert bond_contract.interest_rate == 0 assert bond_contract.interest_payment_date == ["", "", "", "", "", "", "", "", "", "", "", ""] @@ -579,6 +607,7 @@ def test_normal_1(self, db): assert bond_contract.privacy_policy == "" assert bond_contract.transfer_approval_required is False assert bond_contract.memo == "" + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -601,7 +630,8 @@ def test_normal_2(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + contract_address, abi, tx_hash = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -626,15 +656,14 @@ def test_normal_2(self, db): } _add_data = UpdateParams(**_data) pre_datetime = datetime.utcnow() - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) + bond_contract = bond_contract.get() assert bond_contract.face_value == 20001 assert bond_contract.interest_rate == 0.0001 assert bond_contract.interest_payment_date == ["0331", "0930", "", "", "", "", "", "", "", "", "", ""] @@ -649,6 +678,7 @@ def test_normal_2(self, db): assert bond_contract.privacy_policy == "privacy policy test" assert bond_contract.transfer_approval_required is True assert bond_contract.memo == "memo test" + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -659,45 +689,9 @@ def test_normal_2(self, db): ########################################################################### # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - # deploy token - arguments = [ - "テスト債券", "TEST", 10000, 20000, - "20211231", 30000, - "20211231", "リターン内容", - "発行目的" - ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # update - _data = { - "interest_rate": 0.0001, - } - _add_data = UpdateParams(**_data) - with pytest.raises(ValueError) as exc_info: - IbetStraightBondContract.update( - contract_address=contract_address[:-1], # short - data=_add_data, - tx_from=issuer_address, - private_key=private_key - ) - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - - # # Validation (UpdateParams) # invalid parameter - def test_error_2(self, db): + def test_error_1(self, db): # update _data = { "interest_rate": 0.00001, @@ -741,9 +735,9 @@ def test_error_2(self, db): } ] - # + # # invalid tx_from - def test_error_3(self, db): + def test_error_2(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -758,7 +752,8 @@ def test_error_3(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -770,8 +765,7 @@ def test_error_3(self, db): } _add_data = UpdateParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from="DUMMY", private_key=private_key @@ -779,9 +773,9 @@ def test_error_3(self, db): assert isinstance(exc_info.value.args[0], InvalidAddress) assert exc_info.match("ENS name: \'DUMMY\' is invalid.") - # + # # invalid private key - def test_error_4(self, db): + def test_error_3(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -796,7 +790,8 @@ def test_error_4(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -808,8 +803,7 @@ def test_error_4(self, db): } _add_data = UpdateParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from=issuer_address, private_key="invalid private key" @@ -817,9 +811,9 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") - # + # # TimeExhausted - def test_error_5(self, db): + def test_error_4(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -834,7 +828,8 @@ def test_error_5(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -853,17 +848,16 @@ def test_error_5(self, db): _add_data = UpdateParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], TimeExhausted) - # + # # Error - def test_error_6(self, db): + def test_error_5(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -878,7 +872,8 @@ def test_error_6(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -897,17 +892,16 @@ def test_error_6(self, db): _add_data = UpdateParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], TransactionNotFound) - # + # # Transaction REVERT(not owner) - def test_error_7(self, db): + def test_error_6(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") user_account = config_eth_account("user2") @@ -928,7 +922,8 @@ def test_error_7(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_private_key @@ -950,8 +945,7 @@ def test_error_7(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.update( - contract_address=contract_address, + bond_contract.update( data=_add_data, tx_from=user_address, private_key=user_private_key @@ -986,7 +980,8 @@ def test_normal_1(self, db): "20211231", "リターン内容", "発行目的" ] - token_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=from_address, private_key=from_private_key @@ -999,22 +994,15 @@ def test_normal_1(self, db): "amount": 10 } _transfer_data = TransferParams(**_data) - IbetStraightBondContract.transfer( - contract_address=token_address, + bond_contract.transfer( data=_transfer_data, tx_from=from_address, private_key=from_private_key ) # assertion - from_balance = IbetStraightBondContract.get_account_balance( - contract_address=token_address, - account_address=from_address - ) - to_balance = IbetStraightBondContract.get_account_balance( - contract_address=token_address, - account_address=to_address - ) + from_balance = bond_contract.get_account_balance(from_address) + to_balance = bond_contract.get_account_balance(to_address) assert from_balance == arguments[2] - 10 assert to_balance == 10 @@ -1096,7 +1084,8 @@ def test_error_3(self, db): "20211231", "リターン内容", "発行目的" ] - token_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=from_address, private_key=from_private_key @@ -1110,8 +1099,7 @@ def test_error_3(self, db): } _transfer_data = TransferParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.transfer( - contract_address=token_address, + bond_contract.transfer( data=_transfer_data, tx_from="invalid_tx_from", private_key=from_private_key @@ -1139,7 +1127,8 @@ def test_error_4(self, db): "20211231", "リターン内容", "発行目的" ] - token_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=from_address, private_key=from_private_key @@ -1153,8 +1142,7 @@ def test_error_4(self, db): } _transfer_data = TransferParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.transfer( - contract_address=token_address, + bond_contract.transfer( data=_transfer_data, tx_from=from_address, private_key="invalid_private_key" @@ -1182,7 +1170,8 @@ def test_error_5(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1203,8 +1192,7 @@ def test_error_5(self, db): _transfer_data = TransferParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.transfer( - contract_address=contract_address, + bond_contract.transfer( data=_transfer_data, tx_from=issuer_address, private_key=private_key @@ -1231,7 +1219,8 @@ def test_error_6(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1252,8 +1241,7 @@ def test_error_6(self, db): _transfer_data = TransferParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.transfer( - contract_address=contract_address, + bond_contract.transfer( data=_transfer_data, tx_from=issuer_address, private_key=private_key @@ -1280,7 +1268,8 @@ def test_error_7(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1304,8 +1293,7 @@ def test_error_7(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.transfer( - contract_address=contract_address, + bond_contract.transfer( data=_transfer_data, tx_from=issuer_address, private_key=private_key @@ -1337,7 +1325,8 @@ def test_normal_1(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + contract_address, abi, tx_hash = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1350,21 +1339,19 @@ def test_normal_1(self, db): } _add_data = AdditionalIssueParams(**_data) pre_datetime = datetime.utcnow() - IbetStraightBondContract.additional_issue( - contract_address=contract_address, + bond_contract.additional_issue( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) - assert bond_contract.total_supply == arguments[2] + 10 - balance = IbetStraightBondContract.get_account_balance( - contract_address=contract_address, - account_address=issuer_address - ) + bond_contract_attr = bond_contract.get() + assert bond_contract_attr.total_supply == arguments[2] + 10 + + balance = bond_contract.get_account_balance(issuer_address) assert balance == arguments[2] + 10 + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -1375,47 +1362,9 @@ def test_normal_1(self, db): ########################################################################### # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - # deploy token - arguments = [ - "テスト債券", "TEST", 10000, 20000, - "20211231", 30000, - "20211231", "リターン内容", - "発行目的" - ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # additional issue - _data = { - "account_address": issuer_address, - "amount": 10 - } - _add_data = AdditionalIssueParams(**_data) - with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.additional_issue( - contract_address=contract_address[:-1], # short - data=_add_data, - tx_from=issuer_address, - private_key=private_key - ) - assert isinstance(exc_info.value.args[0], ValueError) - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - - # # validation (AdditionalIssueParams) # required field - def test_error_2(self, db): + def test_error_1(self, db): _data = {} with pytest.raises(ValidationError) as exc_info: AdditionalIssueParams(**_data) @@ -1431,10 +1380,10 @@ def test_error_2(self, db): } ] - # + # # validation (AdditionalIssueParams) # invalid parameter - def test_error_3(self, db): + def test_error_2(self, db): _data = { "account_address": "invalid account address", "amount": 0 @@ -1455,9 +1404,9 @@ def test_error_3(self, db): } ] - # + # # invalid tx_from - def test_error_4(self, db): + def test_error_3(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1472,7 +1421,8 @@ def test_error_4(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1485,8 +1435,7 @@ def test_error_4(self, db): } _add_data = AdditionalIssueParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.additional_issue( - contract_address=contract_address, + bond_contract.additional_issue( data=_add_data, tx_from="invalid_tx_from", private_key=private_key @@ -1494,9 +1443,9 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], InvalidAddress) assert exc_info.match("ENS name: \'invalid_tx_from\' is invalid.") - # + # # invalid private key - def test_error_5(self, db): + def test_error_4(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1511,7 +1460,8 @@ def test_error_5(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1524,8 +1474,7 @@ def test_error_5(self, db): } _add_data = AdditionalIssueParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.additional_issue( - contract_address=contract_address, + bond_contract.additional_issue( data=_add_data, tx_from=test_account.get("address"), private_key="invalid_private_key" @@ -1533,9 +1482,9 @@ def test_error_5(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") - # + # # TimeExhausted - def test_error_6(self, db): + def test_error_5(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1550,7 +1499,8 @@ def test_error_6(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1570,17 +1520,16 @@ def test_error_6(self, db): _add_data = AdditionalIssueParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.additional_issue( - contract_address=contract_address, + bond_contract.additional_issue( data=_add_data, tx_from=test_account.get("address"), private_key=private_key ) assert exc_info.type(SendTransactionError(TimeExhausted)) - # + # # Error - def test_error_7(self, db): + def test_error_6(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1595,7 +1544,8 @@ def test_error_7(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1615,17 +1565,16 @@ def test_error_7(self, db): _add_data = AdditionalIssueParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.additional_issue( - contract_address=contract_address, + bond_contract.additional_issue( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], TransactionNotFound) - # + # # Transaction REVERT(not owner) - def test_error_8(self, db): + def test_error_7(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") user_account = config_eth_account("user2") @@ -1646,7 +1595,8 @@ def test_error_8(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_private_key @@ -1670,8 +1620,7 @@ def test_error_8(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.additional_issue( - contract_address=contract_address, + bond_contract.additional_issue( data=_add_data, tx_from=user_address, private_key=user_private_key @@ -1703,7 +1652,8 @@ def test_normal_1(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + contract_address, abi, tx_hash = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1716,21 +1666,19 @@ def test_normal_1(self, db): } _add_data = RedeemParams(**_data) pre_datetime = datetime.utcnow() - IbetStraightBondContract.redeem( - contract_address=contract_address, + bond_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key ) # assertion - bond_contract = IbetStraightBondContract.get(contract_address=contract_address) - assert bond_contract.total_supply == arguments[2] - 10 - balance = IbetStraightBondContract.get_account_balance( - contract_address=contract_address, - account_address=issuer_address - ) + bond_contract_attr = bond_contract.get() + assert bond_contract_attr.total_supply == arguments[2] - 10 + + balance = bond_contract.get_account_balance(issuer_address) assert balance == arguments[2] - 10 + _token_attr_update = db.query(TokenAttrUpdate).first() assert _token_attr_update.id == 1 assert _token_attr_update.token_address == contract_address @@ -1741,47 +1689,9 @@ def test_normal_1(self, db): ########################################################################### # - # Invalid argument type (contract_address is not address) - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - # deploy token - arguments = [ - "テスト債券", "TEST", 10000, 20000, - "20211231", 30000, - "20211231", "リターン内容", - "発行目的" - ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # redeem - _data = { - "account_address": issuer_address, - "amount": 10 - } - _add_data = RedeemParams(**_data) - with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.redeem( - contract_address=contract_address[:-1], # short - data=_add_data, - tx_from=issuer_address, - private_key=private_key - ) - assert isinstance(exc_info.value.args[0], ValueError) - assert exc_info.match("Unknown format.*, attempted to normalize to.*") - - # # validation (RedeemParams) # required field - def test_error_2(self, db): + def test_error_1(self, db): _data = {} with pytest.raises(ValidationError) as exc_info: RedeemParams(**_data) @@ -1797,10 +1707,10 @@ def test_error_2(self, db): } ] - # + # # validation (RedeemParams) # invalid parameter - def test_error_3(self, db): + def test_error_2(self, db): _data = { "account_address": "invalid account address", "amount": 0 @@ -1821,9 +1731,9 @@ def test_error_3(self, db): } ] - # + # # invalid tx_from - def test_error_4(self, db): + def test_error_3(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1838,7 +1748,8 @@ def test_error_4(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1851,8 +1762,7 @@ def test_error_4(self, db): } _add_data = RedeemParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.redeem( - contract_address=contract_address, + bond_contract.redeem( data=_add_data, tx_from="invalid_tx_from", private_key=private_key @@ -1860,9 +1770,9 @@ def test_error_4(self, db): assert isinstance(exc_info.value.args[0], InvalidAddress) assert exc_info.match("ENS name: \'invalid_tx_from\' is invalid.") - # + # # invalid private key - def test_error_5(self, db): + def test_error_4(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1877,7 +1787,8 @@ def test_error_5(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1890,8 +1801,7 @@ def test_error_5(self, db): } _add_data = RedeemParams(**_data) with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.redeem( - contract_address=contract_address, + bond_contract.redeem( data=_add_data, tx_from=test_account.get("address"), private_key="invalid_private_key" @@ -1899,9 +1809,9 @@ def test_error_5(self, db): assert isinstance(exc_info.value.args[0], Error) assert exc_info.match("Non-hexadecimal digit found") - # + # # TimeExhausted - def test_error_6(self, db): + def test_error_5(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1916,7 +1826,8 @@ def test_error_6(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1936,17 +1847,16 @@ def test_error_6(self, db): _add_data = RedeemParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.redeem( - contract_address=contract_address, + bond_contract.redeem( data=_add_data, tx_from=test_account.get("address"), private_key=private_key ) assert exc_info.type(SendTransactionError(TimeExhausted)) - # + # # Error - def test_error_7(self, db): + def test_error_6(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -1961,7 +1871,8 @@ def test_error_7(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -1981,17 +1892,16 @@ def test_error_7(self, db): _add_data = RedeemParams(**_data) with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.redeem( - contract_address=contract_address, + bond_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], TransactionNotFound) - # + # # Transaction REVERT(lack balance) - def test_error_8(self, db): + def test_error_7(self, db): test_account = config_eth_account("user1") issuer_address = test_account.get("address") private_key = decode_keyfile_json( @@ -2006,7 +1916,8 @@ def test_error_8(self, db): "20211231", "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2030,8 +1941,7 @@ def test_error_8(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.redeem( - contract_address=contract_address, + bond_contract.redeem( data=_add_data, tx_from=issuer_address, private_key=private_key @@ -2068,17 +1978,15 @@ def test_normal_1(self, db): "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key ) # assertion - balance = IbetStraightBondContract.get_account_balance( - contract_address=contract_address, - account_address=issuer_address - ) + balance = bond_contract.get_account_balance(issuer_address) assert balance == arguments[2] # @@ -2088,10 +1996,8 @@ def test_normal_2(self, db): issuer_address = test_account.get("address") # execute the function - balance = IbetStraightBondContract.get_account_balance( - ZERO_ADDRESS, - issuer_address - ) + bond_contract = IbetStraightBondContract() + balance = bond_contract.get_account_balance(issuer_address) # assertion assert balance == 0 @@ -2100,44 +2006,6 @@ def test_normal_2(self, db): # Error Case ########################################################################### - # - # invalid contract_address - def test_error_1(self, db): - test_account = config_eth_account("user1") - issuer_address = test_account.get("address") - private_key = decode_keyfile_json( - raw_keyfile_json=test_account.get("keyfile_json"), - password=test_account.get("password").encode("utf-8") - ) - - # deploy token - arguments = [ - "テスト債券", - "TEST", - 10000, - 20000, - "20211231", - 30000, - "20211231", - "リターン内容", - "発行目的" - ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( - args=arguments, - tx_from=issuer_address, - private_key=private_key - ) - - # execute the function - with pytest.raises(ValueError) as exc_info: - IbetStraightBondContract.get_account_balance( - contract_address[:-1], # short - issuer_address - ) - - # assertion - assert exc_info.match(f"Unknown format {contract_address[:-1]}, attempted to normalize to ") - # # invalid account_address def test_error_2(self, db): @@ -2160,7 +2028,8 @@ def test_error_2(self, db): "リターン内容", "発行目的" ] - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2168,8 +2037,7 @@ def test_error_2(self, db): # execute the function with pytest.raises(Web3ValidationError): - IbetStraightBondContract.get_account_balance( - contract_address, + bond_contract.get_account_balance( issuer_address[:-1] # short ) @@ -2187,7 +2055,8 @@ def test_normal_1(self, db): before_datetime = datetime.utcnow() # Test - result = IbetStraightBondContract.check_attr_update(db, self.token_address, before_datetime) + bond_contract = IbetStraightBondContract(self.token_address) + result = bond_contract.check_attr_update(db, before_datetime) # assertion assert result is False @@ -2207,7 +2076,8 @@ def test_normal_2(self, db): db.commit() # Test - result = IbetStraightBondContract.check_attr_update(db, self.token_address, after_datetime) + bond_contract = IbetStraightBondContract(self.token_address) + result = bond_contract.check_attr_update(db, after_datetime) # assertion assert result is False @@ -2227,7 +2097,8 @@ def test_normal_3(self, db): db.commit() # Test - result = IbetStraightBondContract.check_attr_update(db, self.token_address, before_datetime) + bond_contract = IbetStraightBondContract(self.token_address) + result = bond_contract.check_attr_update(db, before_datetime) # assertion assert result is True @@ -2249,7 +2120,8 @@ class TestRecordAttrUpdate: @pytest.mark.freeze_time('2021-04-27 12:34:56') def test_normal_1(self, db): # Test - IbetStraightBondContract.record_attr_update(db, self.token_address) + bond_contract = IbetStraightBondContract(self.token_address) + bond_contract.record_attr_update(db) # assertion _update = db.query(TokenAttrUpdate).first() @@ -2272,7 +2144,8 @@ def test_normal_2(self, db, freezer): freezer.move_to('2021-04-27 12:34:56') # Test - IbetStraightBondContract.record_attr_update(db, self.token_address) + bond_contract = IbetStraightBondContract(self.token_address) + bond_contract.record_attr_update(db) # assertion _update = db.query(TokenAttrUpdate).filter(TokenAttrUpdate.id == 2).first() @@ -2334,7 +2207,8 @@ def test_normal_1(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2346,8 +2220,7 @@ def test_normal_1(self, db): "transfer_approval_required": True, "transferable": True } - IbetStraightBondContract.update( - contract_address=token_address, + bond_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2374,8 +2247,7 @@ def test_normal_1(self, db): "application_id": 0, "data": "approve transfer test" } - tx_hash, tx_receipt = IbetStraightBondContract.approve_transfer( - contract_address=token_address, + tx_hash, tx_receipt = bond_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -2384,6 +2256,7 @@ def test_normal_1(self, db): # assertion assert isinstance(tx_hash, str) and int(tx_hash, 16) > 0 assert tx_receipt["status"] == 1 + bond_token = ContractUtils.get_contract( contract_name="IbetShare", contract_address=token_address @@ -2393,6 +2266,7 @@ def test_normal_1(self, db): assert applications[1] == to_address assert applications[2] == 10 assert applications[3] is False + pendingTransfer = bond_token.functions.pendingTransfer(issuer_address).call() issuer_value = bond_token.functions.balanceOf(issuer_address).call() to_value = bond_token.functions.balanceOf(to_address).call() @@ -2442,9 +2316,9 @@ def test_error_2(self, db): "data": "test_data" } _approve_transfer_data = ApproveTransferParams(**approve_data) + bond_contract = IbetStraightBondContract("not address") with pytest.raises(SendTransactionError) as ex_info: - IbetStraightBondContract.approve_transfer( - contract_address="not address", + bond_contract.approve_transfer( data=_approve_transfer_data, tx_from=issuer_address, private_key=private_key @@ -2473,8 +2347,8 @@ def test_error_3(self, db): "リターン内容", "発行目的" ] - - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2487,8 +2361,7 @@ def test_error_3(self, db): } _approve_transfer_data = ApproveTransferParams(**approve_data) with pytest.raises(SendTransactionError) as ex_info: - IbetStraightBondContract.approve_transfer( - contract_address=contract_address, + bond_contract.approve_transfer( data=_approve_transfer_data, tx_from=issuer_address[:-1], private_key=private_key @@ -2517,8 +2390,8 @@ def test_error_4(self, db): "リターン内容", "発行目的" ] - - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2531,8 +2404,7 @@ def test_error_4(self, db): } _approve_transfer_data = ApproveTransferParams(**approve_data) with pytest.raises(SendTransactionError) as ex_info: - IbetStraightBondContract.approve_transfer( - contract_address=contract_address, + bond_contract.approve_transfer( data=_approve_transfer_data, tx_from=issuer_address, private_key="dummy-private" @@ -2583,7 +2455,8 @@ def test_error_5(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2595,8 +2468,7 @@ def test_error_5(self, db): "transfer_approval_required": True, "transferable": True } - IbetStraightBondContract.update( - contract_address=token_address, + bond_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2623,8 +2495,7 @@ def test_error_5(self, db): "application_id": 0, "data": "approve transfer test" } - IbetStraightBondContract.approve_transfer( - contract_address=token_address, + bond_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -2643,8 +2514,7 @@ def test_error_5(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.approve_transfer( - contract_address=token_address, + bond_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -2703,7 +2573,8 @@ def test_normal_1(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2715,8 +2586,7 @@ def test_normal_1(self, db): "transfer_approval_required": True, "transferable": True } - IbetStraightBondContract.update( - contract_address=token_address, + bond_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2745,8 +2615,7 @@ def test_normal_1(self, db): } _approve_transfer_data = CancelTransferParams(**cancel_data) - tx_hash, tx_receipt = IbetStraightBondContract.cancel_transfer( - contract_address=token_address, + tx_hash, tx_receipt = bond_contract.cancel_transfer( data=_approve_transfer_data, tx_from=issuer_address, private_key=issuer_pk @@ -2813,9 +2682,9 @@ def test_error_2(self, db): "data": "test_data" } _cancel_transfer_data = CancelTransferParams(**cancel_data) + bond_contract = IbetStraightBondContract("not address") with pytest.raises(SendTransactionError) as ex_info: - IbetStraightBondContract.cancel_transfer( - contract_address="not address", + bond_contract.cancel_transfer( data=_cancel_transfer_data, tx_from=issuer_address, private_key=private_key @@ -2844,8 +2713,8 @@ def test_error_3(self, db): "リターン内容", "発行目的" ] - - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + contract_address, abi, tx_hash = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2858,8 +2727,7 @@ def test_error_3(self, db): } _cancel_transfer_data = CancelTransferParams(**cancel_data) with pytest.raises(SendTransactionError) as ex_info: - IbetStraightBondContract.cancel_transfer( - contract_address=contract_address, + bond_contract.cancel_transfer( data=_cancel_transfer_data, tx_from=issuer_address[:-1], private_key=private_key @@ -2888,8 +2756,8 @@ def test_error_4(self, db): "リターン内容", "発行目的" ] - - contract_address, abi, tx_hash = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + contract_address, abi, tx_hash = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -2902,8 +2770,7 @@ def test_error_4(self, db): } _cancel_transfer_data = CancelTransferParams(**cancel_data) with pytest.raises(SendTransactionError) as ex_info: - IbetStraightBondContract.cancel_transfer( - contract_address=contract_address, + bond_contract.cancel_transfer( data=_cancel_transfer_data, tx_from=issuer_address, private_key="dummy-private" @@ -2954,7 +2821,8 @@ def test_error_5(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -2966,8 +2834,7 @@ def test_error_5(self, db): "transfer_approval_required": True, "transferable": True } - IbetStraightBondContract.update( - contract_address=token_address, + bond_contract.update( data=UpdateParams(**update_data), tx_from=issuer_address, private_key=issuer_pk @@ -2994,8 +2861,7 @@ def test_error_5(self, db): "application_id": 0, "data": "approve transfer test" } - IbetStraightBondContract.approve_transfer( - contract_address=token_address, + bond_contract.approve_transfer( data=ApproveTransferParams(**approve_data), tx_from=issuer_address, private_key=issuer_pk @@ -3015,8 +2881,7 @@ def test_error_5(self, db): ) with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.cancel_transfer( - contract_address=token_address, + bond_contract.cancel_transfer( data=CancelTransferParams(**cancel_data), tx_from=issuer_address, private_key=issuer_pk @@ -3056,7 +2921,8 @@ def test_normal_1(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3068,8 +2934,7 @@ def test_normal_1(self, db): "value": 10, "data": "" } - tx_hash, tx_receipt = IbetStraightBondContract.lock( - contract_address=token_address, + tx_hash, tx_receipt = bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3168,7 +3033,8 @@ def test_error_2_1(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3181,8 +3047,7 @@ def test_error_2_1(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from="invalid_tx_from", # invalid tx from private_key="", @@ -3217,7 +3082,8 @@ def test_error_2_2(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3230,8 +3096,7 @@ def test_error_2_2(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key="invalid_pk", # invalid pk @@ -3266,7 +3131,8 @@ def test_error_3(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3286,8 +3152,7 @@ def test_error_3(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3321,7 +3186,8 @@ def test_error_4(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3341,8 +3207,7 @@ def test_error_4(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3375,7 +3240,8 @@ def test_error_5(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3397,8 +3263,7 @@ def test_error_5(self, db): "data": "" } with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3439,7 +3304,8 @@ def test_normal_1(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3451,8 +3317,7 @@ def test_normal_1(self, db): "value": 10, "data": "" } - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3466,8 +3331,7 @@ def test_normal_1(self, db): "value": 5, "data": "" } - tx_hash, tx_receipt = IbetStraightBondContract.force_unlock( - contract_address=token_address, + tx_hash, tx_receipt = bond_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3589,7 +3453,8 @@ def test_error_2_1(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3601,8 +3466,7 @@ def test_error_2_1(self, db): "value": 10, "data": "" } - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3617,8 +3481,7 @@ def test_error_2_1(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.force_unlock( - contract_address=token_address, + bond_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from="invalid_tx_from", # invalid tx from private_key="", @@ -3653,7 +3516,8 @@ def test_error_2_2(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3665,8 +3529,7 @@ def test_error_2_2(self, db): "value": 10, "data": "" } - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3681,8 +3544,7 @@ def test_error_2_2(self, db): "data": "" } with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.force_unlock( - contract_address=token_address, + bond_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key="invalid_pk", # invalid pk @@ -3717,7 +3579,8 @@ def test_error_3(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3729,8 +3592,7 @@ def test_error_3(self, db): "value": 10, "data": "" } - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3752,8 +3614,7 @@ def test_error_3(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.force_unlock( - contract_address=token_address, + bond_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3787,7 +3648,8 @@ def test_error_4(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3799,8 +3661,7 @@ def test_error_4(self, db): "value": 10, "data": "" } - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3822,8 +3683,7 @@ def test_error_4(self, db): } with Web3_send_raw_transaction: with pytest.raises(SendTransactionError) as exc_info: - IbetStraightBondContract.force_unlock( - contract_address=token_address, + bond_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk @@ -3856,7 +3716,8 @@ def test_error_5(self, db): "リターン内容", "発行目的" ] - token_address, _, _ = IbetStraightBondContract.create( + bond_contract = IbetStraightBondContract() + token_address, _, _ = bond_contract.create( args=arguments, tx_from=issuer_address, private_key=issuer_pk @@ -3868,8 +3729,7 @@ def test_error_5(self, db): "value": 10, "data": "" } - IbetStraightBondContract.lock( - contract_address=token_address, + bond_contract.lock( data=LockParams(**lock_data), tx_from=issuer_address, private_key=issuer_pk, @@ -3893,8 +3753,7 @@ def test_error_5(self, db): "data": "" } with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - IbetStraightBondContract.force_unlock( - contract_address=token_address, + bond_contract.force_unlock( data=ForceUnlockPrams(**lock_data), tx_from=issuer_address, private_key=issuer_pk diff --git a/tests/model/blockchain/test_token_list.py b/tests/model/blockchain/test_token_list.py index a97dd2a0..c625142a 100755 --- a/tests/model/blockchain/test_token_list.py +++ b/tests/model/blockchain/test_token_list.py @@ -85,7 +85,8 @@ def test_normal_1(self, db, contract_list): "20221231", 10000 ] - share_token_address, abi, tx_hash = IbetShareContract.create( + share_contract = IbetShareContract() + share_token_address, abi, tx_hash = share_contract.create( args=arguments, tx_from=issuer_address, private_key=private_key @@ -118,7 +119,7 @@ def test_normal_1(self, db, contract_list): "リターン内容", "発行目的" ] - bond_token_address, abi, tx_hash = IbetStraightBondContract.create( + bond_token_address, abi, tx_hash = IbetStraightBondContract().create( args=arguments, tx_from=issuer_address, private_key=private_key diff --git a/tests/test_app_routers_accounts_{issuer_address}_eoa_password_POST.py b/tests/test_app_routers_accounts_{issuer_address}_eoa_password_POST.py index eb13c1be..fac4581d 100644 --- a/tests/test_app_routers_accounts_{issuer_address}_eoa_password_POST.py +++ b/tests/test_app_routers_accounts_{issuer_address}_eoa_password_POST.py @@ -87,7 +87,7 @@ def test_normal_1(self, client, db): "return_amount_test", "purpose_test" ] - IbetStraightBondContract.create( + IbetStraightBondContract().create( args=arguments, tx_from=_issuer_address, private_key=private_key diff --git a/tests/test_app_routers_bond_tokens_GET.py b/tests/test_app_routers_bond_tokens_GET.py index a0c20d81..abc20dbb 100644 --- a/tests/test_app_routers_bond_tokens_GET.py +++ b/tests/test_app_routers_bond_tokens_GET.py @@ -18,7 +18,8 @@ """ import pytz from unittest import mock -from unittest.mock import call + +from web3.datastructures import AttributeDict from app.model.blockchain import IbetStraightBondContract from app.model.db import ( @@ -96,14 +97,11 @@ def test_normal_2(self, mock_get, client, db): mock_token.memo = "memo_test1" mock_get.side_effect = [ - mock_token + AttributeDict(mock_token.__dict__) ] resp = client.get(self.apiurl) - # assertion mock call arguments - mock_get.assert_any_call(contract_address=token.token_address) - assumed_response = [ { "issuer_address": token.issuer_address, @@ -241,15 +239,12 @@ def test_normal_3(self, mock_get, client, db): mock_token_2.memo = "memo_test2" mock_get.side_effect = [ - mock_token_1, mock_token_2 + AttributeDict(mock_token_1.__dict__), + AttributeDict(mock_token_2.__dict__) ] resp = client.get(self.apiurl) - # assertion mock call arguments - mock_get.assert_has_calls( - [call(contract_address=token_1.token_address), call(contract_address=token_2.token_address)]) - assumed_response = [ { "issuer_address": token_1.issuer_address, @@ -398,7 +393,7 @@ def test_normal_5(self, mock_get, client, db): mock_token.memo = "memo_test1" mock_get.side_effect = [ - mock_token + AttributeDict(mock_token.__dict__) ] # No Target Data @@ -412,9 +407,6 @@ def test_normal_5(self, mock_get, client, db): resp = client.get(self.apiurl, headers={"issuer-address": issuer_address_1}) - # assertion mock call arguments - mock_get.assert_any_call(contract_address=token_1.token_address) - assumed_response = [ { "issuer_address": token_1.issuer_address, @@ -552,7 +544,8 @@ def test_normal_6(self, mock_get, client, db): mock_token_2.memo = "memo_test2" mock_get.side_effect = [ - mock_token_1, mock_token_2 + AttributeDict(mock_token_1.__dict__), + AttributeDict(mock_token_2.__dict__) ] # No Target Data @@ -566,10 +559,6 @@ def test_normal_6(self, mock_get, client, db): resp = client.get(self.apiurl, headers={"issuer-address": issuer_address_1}) - # assertion mock call arguments - mock_get.assert_has_calls( - [call(contract_address=token_1.token_address), call(contract_address=token_2.token_address)]) - assumed_response = [ { "issuer_address": issuer_address_1, diff --git a/tests/test_app_routers_bond_tokens_{token_address}_GET.py b/tests/test_app_routers_bond_tokens_{token_address}_GET.py index 49cd885c..31390c0c 100644 --- a/tests/test_app_routers_bond_tokens_{token_address}_GET.py +++ b/tests/test_app_routers_bond_tokens_{token_address}_GET.py @@ -89,8 +89,6 @@ def test_normal_1(self, mock_get, client, db): resp = client.get(self.base_apiurl + "token_address_test1") # assertion - mock_get.assert_any_call(contract_address="token_address_test1") - assumed_response = { "issuer_address": "issuer_address_test1", "token_address": "token_address_test1", @@ -182,8 +180,6 @@ def test_normal_2(self, mock_get, client, db): resp = client.get(self.base_apiurl + "token_address_test1") # assertion - mock_get.assert_any_call(contract_address="token_address_test1") - assumed_response = { "issuer_address": "issuer_address_test1", "token_address": "token_address_test1", diff --git a/tests/test_app_routers_bond_tokens_{token_address}_POST.py b/tests/test_app_routers_bond_tokens_{token_address}_POST.py index 516dab50..46c33c41 100644 --- a/tests/test_app_routers_bond_tokens_{token_address}_POST.py +++ b/tests/test_app_routers_bond_tokens_{token_address}_POST.py @@ -103,7 +103,6 @@ def test_normal_1(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -214,7 +213,6 @@ def test_normal_3(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY diff --git a/tests/test_app_routers_bond_tokens_{token_address}_additional_issue_POST.py b/tests/test_app_routers_bond_tokens_{token_address}_additional_issue_POST.py index ae9d7f61..28f75929 100644 --- a/tests/test_app_routers_bond_tokens_{token_address}_additional_issue_POST.py +++ b/tests/test_app_routers_bond_tokens_{token_address}_additional_issue_POST.py @@ -82,7 +82,6 @@ def test_normal_1(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -140,7 +139,6 @@ def test_normal_2(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY diff --git a/tests/test_app_routers_bond_tokens_{token_address}_holders_{account_address}_personal_info_POST.py b/tests/test_app_routers_bond_tokens_{token_address}_holders_{account_address}_personal_info_POST.py index 23b58e32..c5f0574f 100644 --- a/tests/test_app_routers_bond_tokens_{token_address}_holders_{account_address}_personal_info_POST.py +++ b/tests/test_app_routers_bond_tokens_{token_address}_holders_{account_address}_personal_info_POST.py @@ -108,7 +108,6 @@ def test_normal_1(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetStraightBondContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -187,7 +186,6 @@ def test_normal_2(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetStraightBondContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -272,7 +270,6 @@ def test_normal_3(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetStraightBondContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, diff --git a/tests/test_app_routers_bond_tokens_{token_address}_personal_info_POST.py b/tests/test_app_routers_bond_tokens_{token_address}_personal_info_POST.py index 1f779e88..a9c9448c 100644 --- a/tests/test_app_routers_bond_tokens_{token_address}_personal_info_POST.py +++ b/tests/test_app_routers_bond_tokens_{token_address}_personal_info_POST.py @@ -109,7 +109,6 @@ def test_normal_1(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetStraightBondContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -189,7 +188,6 @@ def test_normal_2(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetStraightBondContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -275,7 +273,6 @@ def test_normal_3(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetStraightBondContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, diff --git a/tests/test_app_routers_bond_tokens_{token_address}_redeem_POST.py b/tests/test_app_routers_bond_tokens_{token_address}_redeem_POST.py index b20f7368..7912f798 100644 --- a/tests/test_app_routers_bond_tokens_{token_address}_redeem_POST.py +++ b/tests/test_app_routers_bond_tokens_{token_address}_redeem_POST.py @@ -82,7 +82,6 @@ def test_normal_1(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -140,7 +139,6 @@ def test_normal_2(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY diff --git a/tests/test_app_routers_bond_transfer_approvals_{token_Address}_{id}_POST.py b/tests/test_app_routers_bond_transfer_approvals_{token_Address}_{id}_POST.py index 6ba84799..d2a6b8c7 100644 --- a/tests/test_app_routers_bond_transfer_approvals_{token_Address}_{id}_POST.py +++ b/tests/test_app_routers_bond_transfer_approvals_{token_Address}_{id}_POST.py @@ -142,7 +142,6 @@ def test_normal_1_1(self, client, db): } mock_transfer.assert_called_once_with( - contract_address=self.test_token_address, data=ApproveTransferParams(**_expected), tx_from=issuer_address, private_key=ANY @@ -306,7 +305,6 @@ def test_normal_2_1(self, client, db): } mock_transfer.assert_called_once_with( - contract_address=self.test_token_address, data=ApproveTransferParams(**_expected), tx_from=issuer_address, private_key=ANY @@ -393,7 +391,6 @@ def test_normal_3(self, client, db): } mock_transfer.assert_called_once_with( - contract_address=self.test_token_address, data=ApproveTransferParams(**_expected), tx_from=issuer_address, private_key=ANY diff --git a/tests/test_app_routers_bond_transfers_POST.py b/tests/test_app_routers_bond_transfers_POST.py index 7a96a371..000aad6b 100644 --- a/tests/test_app_routers_bond_transfers_POST.py +++ b/tests/test_app_routers_bond_transfers_POST.py @@ -91,7 +91,6 @@ def test_normal_1(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data={ "from_address": _from_address, "to_address": _to_address, @@ -162,7 +161,6 @@ def test_normal_2(self, IbetStraightBondContract_mock, client, db): # assertion IbetStraightBondContract_mock.assert_any_call( - contract_address=_token_address, data={ "from_address": _from_address, "to_address": _to_address, diff --git a/tests/test_app_routers_e2e_messaging_accounts_{account_address}_eoa_password_POST.py b/tests/test_app_routers_e2e_messaging_accounts_{account_address}_eoa_password_POST.py index 8dc43f98..e918daa6 100644 --- a/tests/test_app_routers_e2e_messaging_accounts_{account_address}_eoa_password_POST.py +++ b/tests/test_app_routers_e2e_messaging_accounts_{account_address}_eoa_password_POST.py @@ -80,7 +80,7 @@ def test_normal_1(self, client, db, e2e_messaging_contract): "return_amount_test", "purpose_test" ] - IbetStraightBondContract.create( + IbetStraightBondContract().create( args=arguments, tx_from=user_address_1, private_key=private_key diff --git a/tests/test_app_routers_ledger_{token_address}_history_{ledger_id}_GET.py b/tests/test_app_routers_ledger_{token_address}_history_{ledger_id}_GET.py index b847deda..db529dd1 100644 --- a/tests/test_app_routers_ledger_{token_address}_history_{ledger_id}_GET.py +++ b/tests/test_app_routers_ledger_{token_address}_history_{ledger_id}_GET.py @@ -763,7 +763,6 @@ def test_normal_2_1(self, client, db): } ) # assertion - token_get_mock_patch.assert_any_call(token_address) personal_get_info_mock_patch.assert_has_calls([ call(account_address=account_address_2, default_value=None) ]) @@ -1085,7 +1084,6 @@ def test_normal_2_2(self, client, db): } ) # assertion - token_get_mock_patch.assert_any_call(token_address) personal_get_info_mock_patch.assert_has_calls([ call(account_address=account_address_2, default_value=None) ]) diff --git a/tests/test_app_routers_positions_{account_address}_forceunlock_POST.py b/tests/test_app_routers_positions_{account_address}_forceunlock_POST.py index 9279633d..f83d8322 100644 --- a/tests/test_app_routers_positions_{account_address}_forceunlock_POST.py +++ b/tests/test_app_routers_positions_{account_address}_forceunlock_POST.py @@ -93,7 +93,6 @@ def test_normal_1(self, IbetSecurityTokenInterface_mock, client, db): # assertion IbetSecurityTokenInterface_mock.assert_any_call( - contract_address=_token_address, data={ "lock_address": _lock_address, "account_address": _admin_address, @@ -164,7 +163,6 @@ def test_normal_2(self, IbetSecurityTokenInterface_mock, client, db): # assertion IbetSecurityTokenInterface_mock.assert_any_call( - contract_address=_token_address, data={ "lock_address": _lock_address, "account_address": _admin_address, diff --git a/tests/test_app_routers_share_tokens_GET.py b/tests/test_app_routers_share_tokens_GET.py index 038dfa1b..e739ac2a 100644 --- a/tests/test_app_routers_share_tokens_GET.py +++ b/tests/test_app_routers_share_tokens_GET.py @@ -90,9 +90,6 @@ def test_normal_2(self, mock_get, client, db): resp = client.get(self.apiurl) - # assertion mock call arguments - mock_get.assert_any_call(contract_address=token.token_address) - assumed_response = [ { "issuer_address": issuer_address_1, @@ -207,12 +204,6 @@ def test_normal_3(self, mock_get, client, db): resp = client.get(self.apiurl) - # assertion mock call arguments - mock_get.assert_has_calls([ - call(contract_address=token_1.token_address), - call(contract_address=token_2.token_address) - ]) - assumed_response = [ { "issuer_address": issuer_address_1, @@ -342,9 +333,6 @@ def test_normal_5(self, mock_get, client, db): resp = client.get(self.apiurl, headers={"issuer-address": issuer_address_1}) - # assertion mock call arguments - mock_get.assert_any_call(contract_address=token_1.token_address) - assumed_response = [ { "issuer_address": issuer_address_1, @@ -468,12 +456,6 @@ def test_normal_6(self, mock_get, client, db): resp = client.get(self.apiurl, headers={"issuer-address": issuer_address_1}) - # assertion mock call arguments - mock_get.assert_has_calls([ - call(contract_address=token_1.token_address), - call(contract_address=token_2.token_address) - ]) - assumed_response = [ { "issuer_address": issuer_address_1, diff --git a/tests/test_app_routers_share_tokens_{token_address}_GET.py b/tests/test_app_routers_share_tokens_{token_address}_GET.py index c477cbcf..add693c0 100644 --- a/tests/test_app_routers_share_tokens_{token_address}_GET.py +++ b/tests/test_app_routers_share_tokens_{token_address}_GET.py @@ -79,8 +79,6 @@ def test_normal_1(self, mock_get, client, db): resp = client.get(self.base_apiurl + "token_address_test1") # assertion - mock_get.assert_any_call(contract_address="token_address_test1") - assumed_response = { "issuer_address": "issuer_address_test1", "token_address": "token_address_test1", @@ -153,8 +151,6 @@ def test_normal_2(self, mock_get, client, db): resp = client.get(self.base_apiurl + "token_address_test1") # assertion - mock_get.assert_any_call(contract_address="token_address_test1") - assumed_response = { "issuer_address": "issuer_address_test1", "token_address": "token_address_test1", diff --git a/tests/test_app_routers_share_tokens_{token_address}_POST.py b/tests/test_app_routers_share_tokens_{token_address}_POST.py index abfd139a..0ba1aea7 100644 --- a/tests/test_app_routers_share_tokens_{token_address}_POST.py +++ b/tests/test_app_routers_share_tokens_{token_address}_POST.py @@ -104,7 +104,6 @@ def test_normal_1(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -216,7 +215,6 @@ def test_normal_3(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -269,7 +267,6 @@ def test_normal_4_1(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data={ "cancellation_date": "20221231", "dividends": 345.67, @@ -338,7 +335,6 @@ def test_normal_4_2(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data={ "cancellation_date": "", "dividends": 345.67, diff --git a/tests/test_app_routers_share_tokens_{token_address}_additional_issue_POST.py b/tests/test_app_routers_share_tokens_{token_address}_additional_issue_POST.py index 06f797d8..18f8c793 100644 --- a/tests/test_app_routers_share_tokens_{token_address}_additional_issue_POST.py +++ b/tests/test_app_routers_share_tokens_{token_address}_additional_issue_POST.py @@ -82,7 +82,6 @@ def test_normal_1(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -140,7 +139,6 @@ def test_normal_2(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY diff --git a/tests/test_app_routers_share_tokens_{token_address}_holders_{account_address}_personal_info_POST.py b/tests/test_app_routers_share_tokens_{token_address}_holders_{account_address}_personal_info_POST.py index 051b49fd..f6445b16 100644 --- a/tests/test_app_routers_share_tokens_{token_address}_holders_{account_address}_personal_info_POST.py +++ b/tests/test_app_routers_share_tokens_{token_address}_holders_{account_address}_personal_info_POST.py @@ -108,7 +108,6 @@ def test_normal_1(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetShareContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -187,7 +186,6 @@ def test_normal_2(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetShareContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -272,7 +270,6 @@ def test_normal_3(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetShareContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, diff --git a/tests/test_app_routers_share_tokens_{token_address}_personal_info_POST.py b/tests/test_app_routers_share_tokens_{token_address}_personal_info_POST.py index 5b97fb5b..bed11827 100644 --- a/tests/test_app_routers_share_tokens_{token_address}_personal_info_POST.py +++ b/tests/test_app_routers_share_tokens_{token_address}_personal_info_POST.py @@ -109,7 +109,6 @@ def test_normal_1(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetShareContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -189,7 +188,6 @@ def test_normal_2(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetShareContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, @@ -275,7 +273,6 @@ def test_normal_3(self, client, db): # assertion assert resp.status_code == 200 assert resp.json() is None - IbetShareContract.get.assert_called_with(_token_address) PersonalInfoContract.__init__.assert_called_with( db=db, issuer_address=_issuer_address, diff --git a/tests/test_app_routers_share_tokens_{token_address}_redeem_POST.py b/tests/test_app_routers_share_tokens_{token_address}_redeem_POST.py index ddd9c070..f6f278b5 100644 --- a/tests/test_app_routers_share_tokens_{token_address}_redeem_POST.py +++ b/tests/test_app_routers_share_tokens_{token_address}_redeem_POST.py @@ -82,7 +82,6 @@ def test_normal_1(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY @@ -140,7 +139,6 @@ def test_normal_2(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data=req_param, tx_from=_issuer_address, private_key=ANY diff --git a/tests/test_app_routers_share_transfer_approvals_{token_Address}_{id}_POST.py b/tests/test_app_routers_share_transfer_approvals_{token_Address}_{id}_POST.py index 7458c8d9..b6f7c4e2 100644 --- a/tests/test_app_routers_share_transfer_approvals_{token_Address}_{id}_POST.py +++ b/tests/test_app_routers_share_transfer_approvals_{token_Address}_{id}_POST.py @@ -142,7 +142,6 @@ def test_normal_1_1(self, client, db): } mock_transfer.assert_called_once_with( - contract_address=self.test_token_address, data=ApproveTransferParams(**_expected), tx_from=issuer_address, private_key=ANY @@ -306,7 +305,6 @@ def test_normal_2_1(self, client, db): } mock_transfer.assert_called_once_with( - contract_address=self.test_token_address, data=ApproveTransferParams(**_expected), tx_from=issuer_address, private_key=ANY @@ -393,7 +391,6 @@ def test_normal_3(self, client, db): } mock_transfer.assert_called_once_with( - contract_address=self.test_token_address, data=ApproveTransferParams(**_expected), tx_from=issuer_address, private_key=ANY diff --git a/tests/test_app_routers_share_transfers_POST.py b/tests/test_app_routers_share_transfers_POST.py index c09a1a3e..9325c329 100644 --- a/tests/test_app_routers_share_transfers_POST.py +++ b/tests/test_app_routers_share_transfers_POST.py @@ -91,7 +91,6 @@ def test_normal_1(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data={ "from_address": _from_address, "to_address": _to_address, @@ -162,7 +161,6 @@ def test_normal_2(self, IbetShareContract_mock, client, db): # assertion IbetShareContract_mock.assert_any_call( - contract_address=_token_address, data={ "from_address": _from_address, "to_address": _to_address, diff --git a/tests/test_batch_indexer_issue_redeem.py b/tests/test_batch_indexer_issue_redeem.py index 78634c0f..3b5e507a 100644 --- a/tests/test_batch_indexer_issue_redeem.py +++ b/tests/test_batch_indexer_issue_redeem.py @@ -35,7 +35,8 @@ IDXIssueRedeemBlockNumber ) from app.model.blockchain import IbetStraightBondContract, IbetShareContract -from app.model.schema import IbetStraightBondUpdate, IbetShareUpdate +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from batch.indexer_issue_redeem import Processor, LOG, main @@ -84,14 +85,15 @@ def deploy_bond_token_contract(address, "token.return_amount", "token.purpose" ] - - token_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address=token_address, - data=IbetStraightBondUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + bond_contrat = IbetStraightBondContract() + token_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( + data=IbetStraightBondUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) @@ -115,14 +117,15 @@ def deploy_share_token_contract(address, "token.cancellation_date", 30 ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_indexer_personal_info.py b/tests/test_batch_indexer_personal_info.py index 2ec6fa26..90f2e252 100644 --- a/tests/test_batch_indexer_personal_info.py +++ b/tests/test_batch_indexer_personal_info.py @@ -45,10 +45,8 @@ IbetStraightBondContract, IbetShareContract ) -from app.model.schema import ( - IbetStraightBondUpdate, - IbetShareUpdate -) +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from app.utils.e2ee_utils import E2EEUtils @@ -96,14 +94,15 @@ def deploy_bond_token_contract(address, "token.return_amount", "token.purpose" ] - - token_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address=token_address, - data=IbetStraightBondUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + bond_contrat = IbetStraightBondContract() + token_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( + data=IbetStraightBondUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) @@ -127,14 +126,15 @@ def deploy_share_token_contract(address, "token.cancellation_date", 30 ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_indexer_position_bond.py b/tests/test_batch_indexer_position_bond.py index 0448dd2f..28edc0d8 100644 --- a/tests/test_batch_indexer_position_bond.py +++ b/tests/test_batch_indexer_position_bond.py @@ -35,7 +35,7 @@ IDXUnlock ) from app.model.blockchain import IbetStraightBondContract -from app.model.schema import IbetStraightBondUpdate +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from batch.indexer_position_bond import Processor, LOG, main @@ -89,14 +89,15 @@ def deploy_bond_token_contract(address, "token.return_amount", "token.purpose" ] - - token_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address=token_address, - data=IbetStraightBondUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + bond_contrat = IbetStraightBondContract() + token_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( + data=IbetStraightBondUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_indexer_position_share.py b/tests/test_batch_indexer_position_share.py index b6088b05..38d9a958 100644 --- a/tests/test_batch_indexer_position_share.py +++ b/tests/test_batch_indexer_position_share.py @@ -35,7 +35,7 @@ IDXUnlock ) from app.model.blockchain import IbetShareContract -from app.model.schema import IbetShareUpdate +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from batch.indexer_position_share import Processor, LOG, main @@ -89,14 +89,15 @@ def deploy_share_token_contract(address, "token.cancellation_date", 30 ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_indexer_token_holders.py b/tests/test_batch_indexer_token_holders.py index e1d91809..521f1c3b 100644 --- a/tests/test_batch_indexer_token_holders.py +++ b/tests/test_batch_indexer_token_holders.py @@ -30,7 +30,8 @@ IbetStraightBondContract, IbetShareContract, ) -from app.model.schema import IbetStraightBondUpdate, IbetShareUpdate +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from batch.indexer_token_holders import Processor, LOG, main @@ -96,11 +97,10 @@ def deploy_bond_token_contract( "token.return_amount", "token.purpose", ] - - token_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address=token_address, - data=IbetStraightBondUpdate( + bond_contrat = IbetStraightBondContract() + token_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( + data=IbetStraightBondUpdateParams( transferable=True, personal_info_contract_address=personal_info_contract_address, tradable_exchange_contract_address=tradable_exchange_contract_address, @@ -131,11 +131,10 @@ def deploy_share_token_contract( "token.cancellation_date", 30, ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate( + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( transferable=True, personal_info_contract_address=personal_info_contract_address, tradable_exchange_contract_address=tradable_exchange_contract_address, diff --git a/tests/test_batch_indexer_transfer.py b/tests/test_batch_indexer_transfer.py index dcb08bf4..e7548910 100644 --- a/tests/test_batch_indexer_transfer.py +++ b/tests/test_batch_indexer_transfer.py @@ -28,7 +28,8 @@ from app.exceptions import ServiceUnavailableError from app.model.db import Token, TokenType, IDXTransfer, IDXTransferBlockNumber from app.model.blockchain import IbetStraightBondContract, IbetShareContract -from app.model.schema import IbetStraightBondUpdate, IbetShareUpdate +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from batch.indexer_transfer import Processor, LOG, main @@ -78,11 +79,10 @@ def deploy_bond_token_contract(address, "token.return_amount", "token.purpose" ] - - token_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address=token_address, - data=IbetStraightBondUpdate(transferable=True, + bond_contrat = IbetStraightBondContract() + token_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( + data=IbetStraightBondUpdateParams( personal_info_contract_address=personal_info_contract_address, tradable_exchange_contract_address=tradable_exchange_contract_address, transfer_approval_required=transfer_approval_required), @@ -109,14 +109,15 @@ def deploy_share_token_contract(address, "token.cancellation_date", 30 ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required, + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_indexer_transfer_approval.py b/tests/test_batch_indexer_transfer_approval.py index 13c0c319..b908e9a6 100644 --- a/tests/test_batch_indexer_transfer_approval.py +++ b/tests/test_batch_indexer_transfer_approval.py @@ -37,7 +37,8 @@ NotificationType ) from app.model.blockchain import IbetStraightBondContract, IbetShareContract -from app.model.schema import IbetStraightBondUpdate, IbetShareUpdate +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.web3_utils import Web3Wrapper from app.utils.contract_utils import ContractUtils from batch.indexer_transfer_approval import Processor, LOG, main @@ -90,16 +91,17 @@ def deploy_bond_token_contract(address, "token.return_amount", "token.purpose" ] - - token_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address=token_address, - data=IbetStraightBondUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + bond_contrat = IbetStraightBondContract() + token_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( + data=IbetStraightBondUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required, + ), tx_from=address, - private_key=private_key + private_key=private_key, ) return ContractUtils.get_contract("IbetStraightBond", token_address) @@ -121,16 +123,17 @@ def deploy_share_token_contract(address, "token.cancellation_date", 30 ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required, + ), tx_from=address, - private_key=private_key + private_key=private_key, ) return ContractUtils.get_contract("IbetShare", token_address) diff --git a/tests/test_batch_processor_batch_issue_redeem.py b/tests/test_batch_processor_batch_issue_redeem.py index 7e7e5f30..0e22159a 100644 --- a/tests/test_batch_processor_batch_issue_redeem.py +++ b/tests/test_batch_processor_batch_issue_redeem.py @@ -120,7 +120,6 @@ def test_normal_1(self, processor, db, caplog): # Assertion: contract IbetStraightBondContract_additional_issue.assert_called_with( - contract_address=token_address, data=IbetStraightBondAdditionalIssue( account_address=target_address, amount=target_amount @@ -219,7 +218,6 @@ def test_normal_2(self, processor, db, caplog): # Assertion: contract IbetStraightBondContract_redeem.assert_called_with( - contract_address=token_address, data=IbetStraightBondRedeem( account_address=target_address, amount=target_amount @@ -318,7 +316,6 @@ def test_normal_3(self, processor, db, caplog): # Assertion: contract IbetShareContract_additional_issue.assert_called_with( - contract_address=token_address, data=IbetShareAdditionalIssue( account_address=target_address, amount=target_amount @@ -417,7 +414,6 @@ def test_normal_4(self, processor, db, caplog): # Assertion: contract IbetShareContract_redeem.assert_called_with( - contract_address=token_address, data=IbetShareRedeem( account_address=target_address, amount=target_amount diff --git a/tests/test_batch_processor_create_utxo.py b/tests/test_batch_processor_create_utxo.py index 26559fc6..f5bc8438 100644 --- a/tests/test_batch_processor_create_utxo.py +++ b/tests/test_batch_processor_create_utxo.py @@ -81,10 +81,9 @@ def deploy_bond_token_contract(address, private_key): "token.return_amount", "token.purpose" ] - - contract_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - IbetStraightBondContract.update( - contract_address, + bond_contrat = IbetStraightBondContract() + contract_address, _, _ = bond_contrat.create(arguments, address, private_key) + bond_contrat.update( IbetStraightBondUpdateParams(transferable=True), address, private_key @@ -105,10 +104,9 @@ def deploy_share_token_contract(address, private_key): "token.cancellation_date", 30 ] - - contract_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address, + share_contract = IbetShareContract() + contract_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( IbetShareUpdateParams(transferable=True), address, private_key @@ -178,7 +176,7 @@ def test_normal_1(self, mock_func, processor, db): to_address=user_address_1, amount=70 ) - IbetShareContract.transfer(token_address_2, _transfer_1, issuer_address, issuer_private_key) + IbetShareContract(token_address_2).transfer(_transfer_1, issuer_address, issuer_private_key) time.sleep(1) # Bond:issuer -> user1 @@ -187,7 +185,7 @@ def test_normal_1(self, mock_func, processor, db): to_address=user_address_1, amount=40 ) - IbetStraightBondContract.transfer(token_address_1, _transfer_2, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer_2, issuer_address, issuer_private_key) time.sleep(1) # Bond:issuer -> user2 @@ -196,7 +194,7 @@ def test_normal_1(self, mock_func, processor, db): to_address=user_address_2, amount=20 ) - IbetStraightBondContract.transfer(token_address_1, _transfer_3, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer_3, issuer_address, issuer_private_key) time.sleep(1) # Share:user1 -> user2 @@ -205,7 +203,7 @@ def test_normal_1(self, mock_func, processor, db): to_address=user_address_2, amount=10 ) - IbetShareContract.transfer(token_address_2, _transfer_4, issuer_address, issuer_private_key) + IbetShareContract(token_address_2).transfer(_transfer_4, issuer_address, issuer_private_key) time.sleep(1) # Execute batch(Run 2nd) @@ -295,22 +293,22 @@ def test_normal_2(self, mock_func, processor, db): to_address=user_address_1, amount=60 ) - IbetStraightBondContract.transfer(token_address_1, _transfer, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer, issuer_address, issuer_private_key) time.sleep(1) _transfer = IbetStraightBondTransferParams( from_address=user_address_1, to_address=user_address_2, amount=10 ) - IbetStraightBondContract.transfer(token_address_1, _transfer, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer, issuer_address, issuer_private_key) time.sleep(1) - IbetStraightBondContract.transfer(token_address_1, _transfer, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer, issuer_address, issuer_private_key) time.sleep(1) - IbetStraightBondContract.transfer(token_address_1, _transfer, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer, issuer_address, issuer_private_key) time.sleep(1) - IbetStraightBondContract.transfer(token_address_1, _transfer, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer, issuer_address, issuer_private_key) time.sleep(1) - IbetStraightBondContract.transfer(token_address_1, _transfer, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer, issuer_address, issuer_private_key) time.sleep(1) # Execute batch @@ -392,8 +390,11 @@ def test_normal_3(self, mock_func, processor, db): # set personal info personal_contract_address, _, _ = ContractUtils.deploy_contract( "PersonalInfo", [], issuer_address, issuer_private_key) - IbetStraightBondContract.update(token_address_1, IbetStraightBondUpdateParams( - personal_info_contract_address=personal_contract_address), issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).update( + IbetStraightBondUpdateParams(personal_info_contract_address=personal_contract_address), + issuer_address, + issuer_private_key + ) personal_contract = ContractUtils.get_contract("PersonalInfo", personal_contract_address) tx = personal_contract.functions.register(issuer_address, "").build_transaction( { @@ -482,7 +483,7 @@ def test_normal_4(self, mock_func, processor, db): }) ContractUtils.send_transaction(tx, issuer_private_key) update_data = IbetStraightBondUpdateParams(tradable_exchange_contract_address=exchange_address) - IbetStraightBondContract.update(token_address_1, update_data, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).update(update_data, issuer_address, issuer_private_key) # Execute Transfer Event # Bond:issuer -> Exchange @@ -491,7 +492,7 @@ def test_normal_4(self, mock_func, processor, db): to_address=exchange_address, amount=100 ) - IbetStraightBondContract.transfer(token_address_1, _transfer_1, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_1).transfer(_transfer_1, issuer_address, issuer_private_key) # Execute batch # Assume: Not Create UTXO and Ledger @@ -544,7 +545,7 @@ def test_normal_5(self, mock_func, processor, db): account_address=user_address_1, amount=70 ) - IbetShareContract.additional_issue(token_address_1, _additional_issue_1, issuer_address, issuer_private_key) + IbetShareContract(token_address_1).additional_issue(_additional_issue_1, issuer_address, issuer_private_key) time.sleep(1) # Bond @@ -552,7 +553,7 @@ def test_normal_5(self, mock_func, processor, db): account_address=user_address_2, amount=80 ) - IbetStraightBondContract.additional_issue(token_address_2, _additional_issue_2, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_2).additional_issue(_additional_issue_2, issuer_address, issuer_private_key) time.sleep(1) # Execute batch @@ -618,13 +619,13 @@ def test_normal_6(self, mock_func, processor, db): account_address=user_address_1, amount=10 ) - IbetShareContract.additional_issue(token_address_1, _additional_issue_1, issuer_address, issuer_private_key) + IbetShareContract(token_address_1).additional_issue(_additional_issue_1, issuer_address, issuer_private_key) time.sleep(1) _additional_issue_2 = IbetShareAdditionalIssueParams( account_address=user_address_1, amount=20 ) - IbetShareContract.additional_issue(token_address_1, _additional_issue_2, issuer_address, issuer_private_key) + IbetShareContract(token_address_1).additional_issue(_additional_issue_2, issuer_address, issuer_private_key) time.sleep(1) # Bond @@ -632,13 +633,13 @@ def test_normal_6(self, mock_func, processor, db): account_address=user_address_2, amount=30 ) - IbetStraightBondContract.additional_issue(token_address_2, _additional_issue_3, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_2).additional_issue(_additional_issue_3, issuer_address, issuer_private_key) time.sleep(1) _additional_issue_4 = IbetStraightBondAdditionalIssueParams( account_address=user_address_2, amount=40 ) - IbetStraightBondContract.additional_issue(token_address_2, _additional_issue_4, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_2).additional_issue(_additional_issue_4, issuer_address, issuer_private_key) time.sleep(1) # Before execute @@ -672,7 +673,7 @@ def test_normal_6(self, mock_func, processor, db): account_address=user_address_1, amount=20 ) - IbetShareContract.redeem(token_address_1, _redeem_1, issuer_address, issuer_private_key) + IbetShareContract(token_address_1).redeem(_redeem_1, issuer_address, issuer_private_key) time.sleep(1) # Bond @@ -680,7 +681,7 @@ def test_normal_6(self, mock_func, processor, db): account_address=user_address_2, amount=40 ) - IbetStraightBondContract.redeem(token_address_2, _redeem_2, issuer_address, issuer_private_key) + IbetStraightBondContract(token_address_2).redeem(_redeem_2, issuer_address, issuer_private_key) time.sleep(1) # Execute batch diff --git a/tests/test_batch_processor_modify_personal_info.py b/tests/test_batch_processor_modify_personal_info.py index bca3ec6b..58cb59e5 100644 --- a/tests/test_batch_processor_modify_personal_info.py +++ b/tests/test_batch_processor_modify_personal_info.py @@ -32,6 +32,8 @@ IbetShareContract, PersonalInfoContract ) +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.contract_utils import ContractUtils from app.model.db import ( Account, @@ -42,10 +44,6 @@ IDXPersonalInfo ) from app.utils.e2ee_utils import E2EEUtils -from app.model.schema import ( - IbetStraightBondUpdate, - IbetShareUpdate -) from batch.processor_modify_personal_info import Processor from tests.account_config import config_eth_account @@ -115,12 +113,13 @@ def deploy_bond_token_contract(issuer_user, personal_info_contract_address): password=eoa_password.encode("utf-8") ) - contract_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) + bond_contract = IbetStraightBondContract() + contract_address, _, _ = bond_contract.create(arguments, address, private_key) if personal_info_contract_address: - data = IbetStraightBondUpdate() + data = IbetStraightBondUpdateParams() data.personal_info_contract_address = personal_info_contract_address - IbetStraightBondContract.update(contract_address, data, address, private_key) + bond_contract.update(data, address, private_key) return contract_address @@ -147,12 +146,13 @@ def deploy_share_token_contract(issuer_user, personal_info_contract_address): password=eoa_password.encode("utf-8") ) - contract_address, _, _ = IbetShareContract.create(arguments, address, private_key) + share_contract = IbetShareContract() + contract_address, _, _ = share_contract.create(arguments, address, private_key) if personal_info_contract_address: - data = IbetShareUpdate() + data = IbetShareUpdateParams() data.personal_info_contract_address = personal_info_contract_address - IbetShareContract.update(contract_address, data, address, private_key) + share_contract.update(data, address, private_key) return contract_address diff --git a/tests/test_batch_processor_register_personal_info.py b/tests/test_batch_processor_register_personal_info.py index af9d9b9c..5e259eed 100644 --- a/tests/test_batch_processor_register_personal_info.py +++ b/tests/test_batch_processor_register_personal_info.py @@ -22,17 +22,19 @@ from eth_keyfile import decode_keyfile_json from sqlalchemy.orm import Session from unittest.mock import patch -from app.model.blockchain import IbetShareContract +from app.model.blockchain import IbetShareContract +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.model.db import ( Account, - BulkTransfer, - BulkTransferUpload, TokenType, Notification, - NotificationType, BatchRegisterPersonalInfoUpload, BatchRegisterPersonalInfo, BatchRegisterPersonalInfoUploadStatus, Token + NotificationType, + BatchRegisterPersonalInfoUpload, + BatchRegisterPersonalInfo, + BatchRegisterPersonalInfoUploadStatus, + Token ) -from app.model.schema import IbetShareUpdate from app.utils.contract_utils import ContractUtils from app.utils.e2ee_utils import E2EEUtils from app.exceptions import SendTransactionError, ContractRevertError @@ -107,14 +109,15 @@ def deploy_share_token_contract(address, "token.cancellation_date", 30 ] - - token_address, _, _ = IbetShareContract.create(arguments, address, private_key) - IbetShareContract.update( - contract_address=token_address, - data=IbetShareUpdate(transferable=True, - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + share_contract = IbetShareContract() + token_address, _, _ = share_contract.create(arguments, address, private_key) + share_contract.update( + data=IbetShareUpdateParams( + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_processor_update_token.py b/tests/test_batch_processor_update_token.py index 09499f43..d9b56320 100644 --- a/tests/test_batch_processor_update_token.py +++ b/tests/test_batch_processor_update_token.py @@ -192,7 +192,6 @@ def test_normal_1(self, processor, db): # assertion(contract) IbetShareContract_update.assert_called_with( - contract_address=_token_address_1, data=IbetShareUpdate( cancellation_date=None, dividend_record_date=None, @@ -213,7 +212,6 @@ def test_normal_1(self, processor, db): ) IbetStraightBondContract_update.assert_called_with( - contract_address=_token_address_2, data=IbetStraightBondUpdate( interest_rate=0.0001, interest_payment_date=["0331", "0930"], @@ -1061,7 +1059,6 @@ def test_error_4(self, processor, db): # assertion(contract) IbetShareContract_update.assert_called_with( - contract_address=_token_address_1, data=IbetShareUpdate( cancellation_date=None, dividend_record_date=None, @@ -1082,7 +1079,6 @@ def test_error_4(self, processor, db): ) IbetStraightBondContract_update.assert_called_with( - contract_address=_token_address_2, data=IbetStraightBondUpdate( interest_rate=0.0001, interest_payment_date=["0331", "0930"], diff --git a/tests/test_utils_ledger_utils.py b/tests/test_utils_ledger_utils.py index b9b28700..7aa92f00 100644 --- a/tests/test_utils_ledger_utils.py +++ b/tests/test_utils_ledger_utils.py @@ -36,11 +36,9 @@ IbetStraightBondContract, PersonalInfoContract, ) +from app.model.blockchain.tx_params.ibet_straight_bond import UpdateParams as IbetStraightBondUpdateParams +from app.model.blockchain.tx_params.ibet_share import UpdateParams as IbetShareUpdateParams from app.utils.contract_utils import ContractUtils -from app.model.schema import ( - IbetShareUpdate, - IbetStraightBondUpdate -) from app.model.db import ( Account, AccountRsaStatus, @@ -75,12 +73,12 @@ def deploy_bond_token_contract(address, private_key, personal_info_contract_addr "token.return_amount", "token.purpose" ] + bond_contrat = IbetStraightBondContract() + contract_address, _, _ = bond_contrat.create(arguments, address, private_key) - contract_address, _, _ = IbetStraightBondContract.create(arguments, address, private_key) - - data = IbetStraightBondUpdate() + data = IbetStraightBondUpdateParams() data.personal_info_contract_address = personal_info_contract_address - IbetStraightBondContract.update(contract_address, data, address, private_key) + bond_contrat.update(data, address, private_key) return contract_address @@ -97,12 +95,12 @@ def deploy_share_token_contract(address, private_key, personal_info_contract_add "token.cancellation_date", 200 ] + share_contract = IbetShareContract() + contract_address, _, _ = share_contract.create(arguments, address, private_key) - contract_address, _, _ = IbetShareContract.create(arguments, address, private_key) - - data = IbetShareUpdate() + data = IbetShareUpdateParams() data.personal_info_contract_address = personal_info_contract_address - IbetShareContract.update(contract_address, data, address, private_key) + share_contract.update(data, address, private_key) return contract_address From d4d0faa07107743b46afc200328e0586bc2d8746 Mon Sep 17 00:00:00 2001 From: YoshihitoAso Date: Wed, 11 Jan 2023 21:24:32 +0900 Subject: [PATCH 2/2] feat: Make contract class object-oriented --- app/model/blockchain/e2e_messaging.py | 45 +++----- app/model/blockchain/token_list.py | 45 ++++---- app/routers/bond.py | 5 +- app/routers/e2e_messaging.py | 3 +- app/routers/share.py | 5 +- .../processor_rotate_e2e_messaging_rsa_key.py | 3 +- batch/processor_update_token.py | 5 +- tests/model/blockchain/test_E2EMessaging.py | 30 ++--- tests/model/blockchain/test_token_list.py | 40 +++---- tests/test_app_routers_bond_tokens_POST.py | 6 +- ...app_routers_e2e_messaging_accounts_POST.py | 2 - tests/test_app_routers_share_tokens_POST.py | 9 +- tests/test_batch_indexer_e2e_messaging.py | 108 ++++++------------ tests/test_batch_indexer_transfer.py | 8 +- ..._processor_rotate_e2e_messaging_rsa_key.py | 10 +- tests/test_batch_processor_update_token.py | 10 +- 16 files changed, 125 insertions(+), 209 deletions(-) diff --git a/app/model/blockchain/e2e_messaging.py b/app/model/blockchain/e2e_messaging.py index f93af0ae..ee4ddf8e 100644 --- a/app/model/blockchain/e2e_messaging.py +++ b/app/model/blockchain/e2e_messaging.py @@ -42,20 +42,21 @@ class E2EMessaging: """E2EMessaging model""" - @staticmethod - def send_message(contract_address: str, - to_address: str, - message: str, - tx_from: str, - private_key: str): + def __init__(self, contract_address: str): + self.contract_address = contract_address + + def send_message(self, + to_address: str, message: str, + tx_from: str, private_key: str): """Send Message""" contract = ContractUtils.get_contract( contract_name="E2EMessaging", - contract_address=contract_address + contract_address=self.contract_address ) try: tx = contract.functions.sendMessage( - to_address, message + to_address, + message ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, @@ -71,14 +72,9 @@ def send_message(contract_address: str, except Exception as err: raise SendTransactionError(err) - @staticmethod - def send_message_external(contract_address: str, - to_address: str, - _type: str, - message_org: str, - to_rsa_public_key: str, - tx_from: str, - private_key: str): + def send_message_external(self, + to_address: str, _type: str, message_org: str, to_rsa_public_key: str, + tx_from: str, private_key: str): """Send Message(Format message for external system)""" # Encrypt message with AES-256-CBC @@ -111,8 +107,7 @@ def send_message_external(contract_address: str, message = json.dumps(message_dict) # Send message - tx_hash, tx_receipt = E2EMessaging.send_message( - contract_address=contract_address, + tx_hash, tx_receipt = E2EMessaging(self.contract_address).send_message( to_address=to_address, message=message, tx_from=tx_from, @@ -120,20 +115,18 @@ def send_message_external(contract_address: str, ) return tx_hash, tx_receipt - @staticmethod - def set_public_key(contract_address: str, - public_key: str, - key_type: str, - tx_from: str, - private_key: str): + def set_public_key(self, + public_key: str, key_type: str, + tx_from: str, private_key: str): """Set Public Key""" contract = ContractUtils.get_contract( contract_name="E2EMessaging", - contract_address=contract_address + contract_address=self.contract_address ) try: tx = contract.functions.setPublicKey( - public_key, key_type + public_key, + key_type ).build_transaction({ "chainId": CHAIN_ID, "from": tx_from, diff --git a/app/model/blockchain/token_list.py b/app/model/blockchain/token_list.py index 4f7052bc..9f4d0eab 100644 --- a/app/model/blockchain/token_list.py +++ b/app/model/blockchain/token_list.py @@ -31,37 +31,38 @@ class TokenListContract: - @staticmethod - def register( - token_list_address: str, - token_address: str, - token_template: str, - account_address: str, - private_key: str - ) -> None: + def __init__(self, contract_address: str): + self.contract_address = contract_address + + def register(self, + token_address: str, token_template: str, + tx_from: str, private_key: str) -> None: """Register TokenList - :param token_list_address: token list contract address - :param token_address: token_address - :param token_template: TokenType - :param account_address: token owner account address + :param token_address: token address + :param token_template: token type + :param tx_from: transaction from :param private_key: private_key :return: None """ try: contract = ContractUtils.get_contract( contract_name="TokenList", - contract_address=token_list_address, + contract_address=self.contract_address, + ) + tx = contract.functions.register( + token_address, + token_template + ).build_transaction({ + "chainId": CHAIN_ID, + "from": tx_from, + "gas": TX_GAS_LIMIT, + "gasPrice": 0 + }) + ContractUtils.send_transaction( + transaction=tx, + private_key=private_key ) - tx = contract.functions.register(token_address, token_template). \ - build_transaction({ - "chainId": CHAIN_ID, - "from": account_address, - "gas": TX_GAS_LIMIT, - "gasPrice": 0 - }) - ContractUtils.send_transaction(transaction=tx, private_key=private_key) - except ContractRevertError: raise except TimeExhausted as timeout_error: diff --git a/app/routers/bond.py b/app/routers/bond.py index 5c323b99..c9ff0fa9 100644 --- a/app/routers/bond.py +++ b/app/routers/bond.py @@ -252,11 +252,10 @@ def issue_token( else: # Register token_address token list try: - TokenListContract.register( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=contract_address, token_template=TokenType.IBET_STRAIGHT_BOND.value, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) except SendTransactionError: diff --git a/app/routers/e2e_messaging.py b/app/routers/e2e_messaging.py index 4b8c6025..a0e133c5 100644 --- a/app/routers/e2e_messaging.py +++ b/app/routers/e2e_messaging.py @@ -143,8 +143,7 @@ def create_account( # Send transaction try: - tx_hash, _ = E2EMessaging.set_public_key( - contract_address=E2E_MESSAGING_CONTRACT_ADDRESS, + tx_hash, _ = E2EMessaging(E2E_MESSAGING_CONTRACT_ADDRESS).set_public_key( public_key=rsa_public_key, key_type="RSA4096", tx_from=addr, diff --git a/app/routers/share.py b/app/routers/share.py index 92567f4b..c9eafae2 100644 --- a/app/routers/share.py +++ b/app/routers/share.py @@ -242,11 +242,10 @@ def issue_token( else: # Register token_address token list try: - TokenListContract.register( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=contract_address, token_template=TokenType.IBET_SHARE.value, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) except SendTransactionError: diff --git a/batch/processor_rotate_e2e_messaging_rsa_key.py b/batch/processor_rotate_e2e_messaging_rsa_key.py index 2b38e9d0..24f92160 100644 --- a/batch/processor_rotate_e2e_messaging_rsa_key.py +++ b/batch/processor_rotate_e2e_messaging_rsa_key.py @@ -134,8 +134,7 @@ def __auto_generate_rsa_key(self, db_session: Session, base_time: int, e2e_messa f"account_address={e2e_messaging_account.account_address}") return try: - tx_hash, _ = E2EMessaging.set_public_key( - contract_address=E2E_MESSAGING_CONTRACT_ADDRESS, + tx_hash, _ = E2EMessaging(E2E_MESSAGING_CONTRACT_ADDRESS).set_public_key( public_key=rsa_public_key, key_type="RSA4096", tx_from=e2e_messaging_account.account_address, diff --git a/batch/processor_update_token.py b/batch/processor_update_token.py index b2e12e3a..623b80da 100644 --- a/batch/processor_update_token.py +++ b/batch/processor_update_token.py @@ -170,11 +170,10 @@ def process(self): if _update_token.trigger == "Issue": # Register token_address token list - TokenListContract.register( - token_list_address=TOKEN_LIST_CONTRACT_ADDRESS, + TokenListContract(TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=_update_token.token_address, token_template=token_template, - account_address=_update_token.issuer_address, + tx_from=_update_token.issuer_address, private_key=private_key ) diff --git a/tests/model/blockchain/test_E2EMessaging.py b/tests/model/blockchain/test_E2EMessaging.py index f990a401..05cb66e1 100644 --- a/tests/model/blockchain/test_E2EMessaging.py +++ b/tests/model/blockchain/test_E2EMessaging.py @@ -64,8 +64,7 @@ def test_normal_1(self, db, e2e_messaging_contract): message = "test message" # Run Test - tx_hash, tx_receipt = E2EMessaging.send_message( - contract_address=e2e_messaging_contract.address, + tx_hash, tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message( to_address=user_address_2, message=message, tx_from=user_address_1, @@ -102,8 +101,7 @@ def test_error_1(self, db, e2e_messaging_contract): with mock.patch("app.utils.contract_utils.ContractUtils.send_transaction", MagicMock(side_effect=Exception("tx error"))): # Run Test - E2EMessaging.send_message( - contract_address=e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).send_message( to_address=user_address_2, message=message, tx_from=user_address_1, @@ -132,8 +130,7 @@ def test_error_2(self, db, e2e_messaging_contract): with mock.patch("app.utils.contract_utils.ContractUtils.send_transaction", MagicMock(side_effect=TimeExhausted("Timeout Error test"))): # Run Test - E2EMessaging.send_message( - contract_address=e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).send_message( to_address=user_address_2, message=message, tx_from=user_address_1, @@ -235,8 +232,7 @@ def test_normal_1(self, db, e2e_messaging_contract): _type = "test_type" # Run Test - tx_hash, tx_receipt = E2EMessaging.send_message_external( - contract_address=e2e_messaging_contract.address, + tx_hash, tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( to_address=user_address_2, _type=_type, message_org=message_org, @@ -303,8 +299,7 @@ def generate_random(self, NumberOfBytes): ] # Run Test - tx_hash, tx_receipt = E2EMessaging.send_message_external( - contract_address=e2e_messaging_contract.address, + tx_hash, tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( to_address=user_address_2, _type=_type, message_org=message_org, @@ -357,8 +352,7 @@ def test_error_1(self, db, e2e_messaging_contract): with mock.patch("app.utils.contract_utils.ContractUtils.send_transaction", MagicMock(side_effect=Exception("tx error"))): # Run Test - E2EMessaging.send_message_external( - contract_address=e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).send_message_external( to_address=user_address_2, _type=_type, message_org=message_org, @@ -390,8 +384,7 @@ def test_error_2(self, db, e2e_messaging_contract): with mock.patch("app.utils.contract_utils.ContractUtils.send_transaction", MagicMock(side_effect=TimeExhausted("Timeout Error test"))): # Run Test - E2EMessaging.send_message_external( - contract_address=e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).send_message_external( to_address=user_address_2, _type=_type, message_org=message_org, @@ -438,8 +431,7 @@ def test_normal_1(self, db, e2e_messaging_contract): key_type = "RSA4098" # Run Test - tx_hash, tx_receipt = E2EMessaging.set_public_key( - contract_address=e2e_messaging_contract.address, + tx_hash, tx_receipt = E2EMessaging(e2e_messaging_contract.address).set_public_key( public_key=self.rsa_public_key, key_type=key_type, tx_from=user_address_1, @@ -473,8 +465,7 @@ def test_error_1(self, db, e2e_messaging_contract): with mock.patch("app.utils.contract_utils.ContractUtils.send_transaction", MagicMock(side_effect=Exception("tx error"))): # Run Test - E2EMessaging.set_public_key( - contract_address=e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).set_public_key( public_key=self.rsa_public_key, key_type=key_type, tx_from=user_address_1, @@ -501,8 +492,7 @@ def test_error_2(self, db, e2e_messaging_contract): with mock.patch("app.utils.contract_utils.ContractUtils.send_transaction", MagicMock(side_effect=TimeExhausted("Timeout Error test"))): # Run Test - E2EMessaging.set_public_key( - contract_address=e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).set_public_key( public_key=self.rsa_public_key, key_type=key_type, tx_from=user_address_1, diff --git a/tests/model/blockchain/test_token_list.py b/tests/model/blockchain/test_token_list.py index c625142a..65396a87 100755 --- a/tests/model/blockchain/test_token_list.py +++ b/tests/model/blockchain/test_token_list.py @@ -92,11 +92,10 @@ def test_normal_1(self, db, contract_list): private_key=private_key ) - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=share_token_address, token_template=TokenType.IBET_SHARE.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) @@ -125,11 +124,10 @@ def test_normal_1(self, db, contract_list): private_key=private_key ) - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=bond_token_address, token_template=TokenType.IBET_STRAIGHT_BOND.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) @@ -161,11 +159,10 @@ def test_error_1(self, db, contract_list): ) with pytest.raises(SendTransactionError) as exc_info: - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address="dummy_token_address", token_template=TokenType.IBET_SHARE.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], ValidationError) @@ -180,11 +177,10 @@ def test_error_2(self, db, contract_list): ) with pytest.raises(SendTransactionError) as exc_info: - TokenListContract.register( + TokenListContract("dummy_token_list_address").register( token_address=ZERO_ADDRESS, token_template=TokenType.IBET_STRAIGHT_BOND.value, - token_list_address="dummy_token_list_address", - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) assert isinstance(exc_info.value.args[0], ValueError) @@ -199,11 +195,10 @@ def test_error_3(self, db, contract_list): ) with pytest.raises(SendTransactionError) as exc_info: - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=ZERO_ADDRESS, token_template=TokenType.IBET_SHARE.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address[:-1], + tx_from=issuer_address[:-1], private_key=private_key ) assert isinstance(exc_info.value.args[0], InvalidAddress) @@ -214,11 +209,10 @@ def test_error_4(self, db, contract_list): issuer_address = test_account.get("address") with pytest.raises(SendTransactionError) as exc_info: - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=ZERO_ADDRESS, token_template=TokenType.IBET_SHARE.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address, + tx_from=issuer_address, private_key="not private key" ) assert isinstance(exc_info.value.args[0], Error) @@ -241,11 +235,10 @@ def test_error_5(self, db, contract_list): # execute the function with ContractUtils_send_transaction: with pytest.raises(SendTransactionError): - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=ZERO_ADDRESS, token_template=TokenType.IBET_SHARE.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) @@ -269,11 +262,10 @@ def test_error_6(self, db, contract_list): # execute the function with InspectionMock, pytest.raises(ContractRevertError) as exc_info: - TokenListContract.register( + TokenListContract(config.TOKEN_LIST_CONTRACT_ADDRESS).register( token_address=ZERO_ADDRESS, token_template=TokenType.IBET_SHARE.value, - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, - account_address=issuer_address, + tx_from=issuer_address, private_key=private_key ) diff --git a/tests/test_app_routers_bond_tokens_POST.py b/tests/test_app_routers_bond_tokens_POST.py index 769e858e..04eca939 100644 --- a/tests/test_app_routers_bond_tokens_POST.py +++ b/tests/test_app_routers_bond_tokens_POST.py @@ -120,10 +120,9 @@ def test_normal_1(self, client, db): private_key=ANY ) TokenListContract.register.assert_called_with( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, token_address="contract_address_test1", token_template=TokenType.IBET_STRAIGHT_BOND.value, - account_address=test_account["address"], + tx_from=test_account["address"], private_key=ANY ) ContractUtils.get_block_by_transaction_hash( @@ -349,10 +348,9 @@ def test_normal_3(self, client, db): private_key=ANY ) TokenListContract.register.assert_called_with( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, token_address="contract_address_test1", token_template=TokenType.IBET_STRAIGHT_BOND.value, - account_address=test_account["address"], + tx_from=test_account["address"], private_key=ANY ) ContractUtils.get_block_by_transaction_hash( diff --git a/tests/test_app_routers_e2e_messaging_accounts_POST.py b/tests/test_app_routers_e2e_messaging_accounts_POST.py index 17631f45..47ea92f8 100644 --- a/tests/test_app_routers_e2e_messaging_accounts_POST.py +++ b/tests/test_app_routers_e2e_messaging_accounts_POST.py @@ -85,7 +85,6 @@ def test_normal_1(self, client, db, e2e_messaging_contract): # assertion E2EMessaging.set_public_key.assert_called_with( - contract_address=e2e_messaging_contract.address, public_key=ANY, key_type="RSA4096", tx_from=resp.json()["account_address"], @@ -181,7 +180,6 @@ def generate_random(self, NumberOfBytes): # assertion E2EMessaging.set_public_key.assert_called_with( - contract_address=e2e_messaging_contract.address, public_key=ANY, key_type="RSA4096", tx_from=resp.json()["account_address"], diff --git a/tests/test_app_routers_share_tokens_POST.py b/tests/test_app_routers_share_tokens_POST.py index 7e4d40af..0e37c42c 100644 --- a/tests/test_app_routers_share_tokens_POST.py +++ b/tests/test_app_routers_share_tokens_POST.py @@ -125,10 +125,9 @@ def test_normal_1_1(self, client, db): private_key=ANY ) TokenListContract.register.assert_called_with( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, token_address="contract_address_test1", token_template=TokenType.IBET_SHARE.value, - account_address=test_account["address"], + tx_from=test_account["address"], private_key=ANY ) ContractUtils.get_block_by_transaction_hash( @@ -231,10 +230,9 @@ def test_normal_1_2(self, client, db): private_key=ANY ) TokenListContract.register.assert_called_with( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, token_address="contract_address_test1", token_template=TokenType.IBET_SHARE.value, - account_address=test_account["address"], + tx_from=test_account["address"], private_key=ANY ) ContractUtils.get_block_by_transaction_hash( @@ -454,10 +452,9 @@ def test_normal_3(self, client, db): private_key=ANY ) TokenListContract.register.assert_called_with( - token_list_address=config.TOKEN_LIST_CONTRACT_ADDRESS, token_address="contract_address_test1", token_template=TokenType.IBET_SHARE.value, - account_address=test_account["address"], + tx_from=test_account["address"], private_key=ANY ) ContractUtils.get_block_by_transaction_hash( diff --git a/tests/test_batch_indexer_e2e_messaging.py b/tests/test_batch_indexer_e2e_messaging.py index 22012a3d..e5bd7066 100644 --- a/tests/test_batch_indexer_e2e_messaging.py +++ b/tests/test_batch_indexer_e2e_messaging.py @@ -188,8 +188,7 @@ def test_normal_2_1(self, processor, db, e2e_messaging_contract): "address": "東京都1", } message_message_str = json.dumps(message) - sending_tx_hash, sending_tx_receipt = E2EMessaging.send_message_external( - e2e_messaging_contract.address, + sending_tx_hash, sending_tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_1, _type, message_message_str, @@ -276,8 +275,7 @@ def test_normal_2_2(self, processor, db, e2e_messaging_contract): "address": "東京都1", } message_message_str = json.dumps(message) - sending_tx_hash, sending_tx_receipt = E2EMessaging.send_message_external( - e2e_messaging_contract.address, + sending_tx_hash, sending_tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_1, _type, message_message_str, @@ -385,8 +383,7 @@ def test_normal_3(self, processor, db, e2e_messaging_contract): "address": "東京都1", } message_message_str_1 = json.dumps(message) - sending_tx_hash_1, sending_tx_receipt = E2EMessaging.send_message_external( - e2e_messaging_contract.address, + sending_tx_hash_1, sending_tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_1, _type_1, message_message_str_1, @@ -401,8 +398,7 @@ def test_normal_3(self, processor, db, e2e_messaging_contract): _type_2 = "test_type2" message = ["テスト太郎2", "東京都2"] message_message_str_2 = json.dumps(message) - sending_tx_hash_2, sending_tx_receipt = E2EMessaging.send_message_external( - e2e_messaging_contract.address, + sending_tx_hash_2, sending_tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_2, _type_2, message_message_str_2, @@ -416,8 +412,7 @@ def test_normal_3(self, processor, db, e2e_messaging_contract): # Send Message(user3 -> user1) _type_3 = "test_type3" message_message_str_3 = "テスト太郎1,東京都1" - sending_tx_hash_3, sending_tx_receipt = E2EMessaging.send_message_external( - e2e_messaging_contract.address, + sending_tx_hash_3, sending_tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_1, _type_3, message_message_str_3, @@ -431,8 +426,7 @@ def test_normal_3(self, processor, db, e2e_messaging_contract): # Send Message(user3 -> user2) _type_4 = "a" * 50 message_message_str_4 = "a" * 5000 - sending_tx_hash_4, sending_tx_receipt = E2EMessaging.send_message_external( - e2e_messaging_contract.address, + sending_tx_hash_4, sending_tx_receipt = E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_2, _type_4, message_message_str_4, @@ -529,8 +523,7 @@ def test_normal_4(self, processor, db, e2e_messaging_contract): "address": "東京都1", } message_message_str = json.dumps(message) - E2EMessaging.send_message_external( - e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_3, # not target _type, message_message_str, @@ -587,11 +580,8 @@ def test_error_1_1(self, processor, db, e2e_messaging_contract): # Send Message message = "test" - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address).\ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -650,11 +640,8 @@ def test_error_1_2(self, processor, db, e2e_messaging_contract): "message": encrypted_message, } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address).\ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -702,11 +689,8 @@ def test_error_1_3(self, processor, db, e2e_messaging_contract): message = json.dumps({ "type": "test_type", }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address).\ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -766,11 +750,8 @@ def test_error_1_4(self, processor, db, e2e_messaging_contract): "message": encrypted_message } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address).\ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -826,11 +807,8 @@ def test_error_1_5(self, processor, db, e2e_messaging_contract): "message": encrypted_message, } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address).\ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -885,11 +863,8 @@ def test_error_1_6(self, processor, db, e2e_messaging_contract): "cipher_key": cipher_key, } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address).\ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -949,11 +924,8 @@ def test_error_1_7(self, processor, db, e2e_messaging_contract): "message": encrypted_message } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address). \ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -991,8 +963,7 @@ def test_error_2(self, processor, db, e2e_messaging_contract): "address": "東京都1", } message_message_str = json.dumps(message) - E2EMessaging.send_message_external( - e2e_messaging_contract.address, + E2EMessaging(e2e_messaging_contract.address).send_message_external( user_address_1, _type, message_message_str, @@ -1068,11 +1039,8 @@ def test_error_3_1(self, processor, db, e2e_messaging_contract): "message": encrypted_message } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address). \ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -1130,11 +1098,8 @@ def test_error_3_2(self, processor, db, e2e_messaging_contract): "message": encrypted_message } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address). \ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -1197,11 +1162,8 @@ def test_error_3_3(self, processor, db, e2e_messaging_contract): "message": encrypted_message } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address). \ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -1257,11 +1219,8 @@ def test_error_3_4(self, processor, db, e2e_messaging_contract): "message": "test_message" } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address). \ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number @@ -1322,11 +1281,8 @@ def test_error_3_5(self, processor, db, e2e_messaging_contract): "message": encrypted_message } }) - E2EMessaging.send_message(e2e_messaging_contract.address, - user_address_1, - message, - user_address_2, - user_private_key_2) + E2EMessaging(e2e_messaging_contract.address). \ + send_message(user_address_1, message, user_address_2, user_private_key_2) # Run target process block_number = web3.eth.block_number diff --git a/tests/test_batch_indexer_transfer.py b/tests/test_batch_indexer_transfer.py index e7548910..e7f0b8d3 100644 --- a/tests/test_batch_indexer_transfer.py +++ b/tests/test_batch_indexer_transfer.py @@ -83,9 +83,11 @@ def deploy_bond_token_contract(address, token_address, _, _ = bond_contrat.create(arguments, address, private_key) bond_contrat.update( data=IbetStraightBondUpdateParams( - personal_info_contract_address=personal_info_contract_address, - tradable_exchange_contract_address=tradable_exchange_contract_address, - transfer_approval_required=transfer_approval_required), + transferable=True, + personal_info_contract_address=personal_info_contract_address, + tradable_exchange_contract_address=tradable_exchange_contract_address, + transfer_approval_required=transfer_approval_required + ), tx_from=address, private_key=private_key ) diff --git a/tests/test_batch_processor_rotate_e2e_messaging_rsa_key.py b/tests/test_batch_processor_rotate_e2e_messaging_rsa_key.py index ba5a4757..8cae9b5e 100644 --- a/tests/test_batch_processor_rotate_e2e_messaging_rsa_key.py +++ b/tests/test_batch_processor_rotate_e2e_messaging_rsa_key.py @@ -275,13 +275,11 @@ def test_normal_2(self, processor, db, e2e_messaging_contract): # # Assertion assert user_address_2 < user_address_1 E2EMessaging.set_public_key.assert_has_calls([ - call(contract_address=e2e_messaging_contract.address, - public_key=ANY, + call(public_key=ANY, key_type="RSA4096", tx_from=user_address_2, private_key=user_private_key_2), - call(contract_address=e2e_messaging_contract.address, - public_key=ANY, + call(public_key=ANY, key_type="RSA4096", tx_from=user_address_1, private_key=user_private_key_1), @@ -425,7 +423,6 @@ def test_error_2(self, processor, db, e2e_messaging_contract): # Assertion E2EMessaging.set_public_key.assert_called_with( - contract_address=e2e_messaging_contract.address, public_key=ANY, key_type="RSA4096", tx_from=user_address_1, @@ -482,7 +479,6 @@ def test_error_3(self, processor: Processor, db: Session, e2e_messaging_contract # Assertion E2EMessaging.set_public_key.assert_called_with( - contract_address=e2e_messaging_contract.address, public_key=ANY, key_type="RSA4096", tx_from=user_address_1, @@ -495,4 +491,4 @@ def test_error_3(self, processor: Processor, db: Session, e2e_messaging_contract LOG.name, logging.WARNING, f"Transaction reverted: account_address=<{user_address_1}> error_code:<999999> error_msg:<>" - )) == 1 \ No newline at end of file + )) == 1 diff --git a/tests/test_batch_processor_update_token.py b/tests/test_batch_processor_update_token.py index d9b56320..828be571 100644 --- a/tests/test_batch_processor_update_token.py +++ b/tests/test_batch_processor_update_token.py @@ -230,15 +230,13 @@ def test_normal_1(self, processor, db): ) TokenListContract_register.assert_has_calls([ - call(token_list_address=TOKEN_LIST_CONTRACT_ADDRESS, - token_address=_token_address_1, + call(token_address=_token_address_1, token_template=TokenType.IBET_SHARE.value, - account_address=_issuer_address, + tx_from=_issuer_address, private_key=ANY), - call(token_list_address=TOKEN_LIST_CONTRACT_ADDRESS, - token_address=_token_address_2, + call(token_address=_token_address_2, token_template=TokenType.IBET_STRAIGHT_BOND.value, - account_address=_issuer_address, + tx_from=_issuer_address, private_key=ANY), ])