def test_get_total_supply(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '6fe70af535887a820a13cfbaff6b0b505f855e5c' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) self.assertEqual(10000000000000, oep4.get_total_supply())
def withdraw_ong(project_dir_path: str, claimer: str, to: str, amount, gas_limit, gas_price, network): if project_dir_path == '': project_dir_path = os.getcwd() if not os.path.isdir(project_dir_path): raise PunicaException(PunicaError.dir_path_error) rpc_address = handle_network_config(project_dir_path, network) sdk = OntologySdk() sdk.rpc.set_address(rpc_address) sdk.wallet_manager = Account.get_wallet_manager(project_dir_path) if len(sdk.wallet_manager.wallet_in_mem.accounts) == 0: print('there is not account in the wallet.json') return has_sender = False for acc in sdk.wallet_manager.wallet_in_mem.accounts: if claimer == acc.address: has_sender = True break if not has_sender: print('there is not sender in the wallet.json') return claimer_pwd = getpass.getpass('Please input claimer password: '******'tx_hash: ', tx_hash)
def test_get_total_supply(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) self.assertEqual(1000000000, oep4.get_total_supply())
def test_set_contract_address(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '85848b5ec3b15617e396bdd62cb49575738dd413' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) self.assertEqual(contract_address, oep4.get_contract_address(is_hex=True))
def test_send_transfer_from(self): private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf' sender = Account(private_key, SignatureScheme.SHA256withECDSA) payer = sender rpc_address = 'http://polaris3.ont.io:20336' sdk = OntologySdk() sdk.rpc.set_address(rpc_address) asset = sdk.native_vm().asset() b58_from_address = 'ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6' b58_recv_address = sender.get_address_base58() old_from_balance = sdk.rpc.get_balance(b58_from_address) old_recv_balance = sdk.rpc.get_balance(b58_recv_address) amount = 1 gas_limit = 20000 gas_price = 500 tx_hash = asset.send_transfer_from('ont', sender, b58_from_address, b58_recv_address, amount, payer, gas_limit, gas_price) self.assertEqual(64, len(tx_hash)) time.sleep(6) new_from_balance = sdk.rpc.get_balance(b58_from_address) new_recv_balance = sdk.rpc.get_balance(b58_recv_address) self.assertEqual( int(old_from_balance['ont']) - amount, int(new_from_balance['ont'])) self.assertEqual( int(old_recv_balance['ont']) + amount, int(new_recv_balance['ont']))
def transfer(project_dir_path, asset: str, sender, to, amount, gas_price, gas_limit, network): if asset == '' or asset.lower() != 'ont' and asset.lower() != 'ong': print('asset should be ont or ong') return if project_dir_path == '': project_dir_path = os.getcwd() if not os.path.isdir(project_dir_path): raise PunicaException(PunicaError.dir_path_error) rpc_address = handle_network_config(project_dir_path, network) sdk = OntologySdk() sdk.set_rpc(rpc_address) wallet_manager = Account.get_wallet_manager(project_dir_path) if len(wallet_manager.wallet_in_mem.accounts) == 0: print('there is not account in the wallet.json') return has_sender = False for acc in wallet_manager.wallet_in_mem.accounts: if sender == acc.address: has_sender = True break if not has_sender: print('there is not sender in the wallet.json') return sender_account = Invoke.unlock_account(sender, wallet_manager) if sender_account is None: return tx_hash = sdk.native_vm().asset().send_transfer(asset, sender_account, to, amount, sender_account, gas_limit, gas_price) print('tx_hash: ', tx_hash)
def generate_signed_deploy_transaction(hex_avm_code: str, project_path: str = '', wallet_file_name: str = ''): wallet_dir_path = os.path.join(project_path, 'wallet') wallet_manager = read_wallet(wallet_dir_path, wallet_file_name) deploy_dir_path = os.path.join(project_path, 'contracts') deploy_information = handle_deploy_config(deploy_dir_path) need_storage = deploy_information.get('needStorage', True) name = deploy_information.get('name', os.path.split(project_path)[1]) version = deploy_information.get('version', '0.0.1') author = deploy_information.get('author', '') email = deploy_information.get('email', '') desc = deploy_information.get('desc', '') b58_payer_address = deploy_information.get( 'payer', wallet_manager.get_default_account().get_address()) gas_limit = deploy_information.get('gasLimit', 21000000) gas_price = deploy_information.get('gasPrice', 500) ontology = OntologySdk() tx = ontology.neo_vm().make_deploy_transaction(hex_avm_code, need_storage, name, version, author, email, desc, b58_payer_address, gas_limit, gas_price) password = getpass.getpass('\tPlease input payer account password: ') payer_acct = wallet_manager.get_account(b58_payer_address, password) ontology.sign_transaction(tx, payer_acct) return tx
def test_send_transfer(self): rpc_address = 'http://polaris3.ont.io:20336' sdk = OntologySdk() sdk.rpc.set_address(rpc_address) asset = sdk.native_vm().asset() private_key = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' from_acct = Account(private_key, SignatureScheme.SHA256withECDSA) payer = Account(private_key, SignatureScheme.SHA256withECDSA) b58_from_address = from_acct.get_address_base58() b58_to_address = 'Ad4H6AB3iY7gBGNukgBLgLiB6p3v627gz1' old_from_acct_balance = asset.query_balance('ont', b58_from_address) old_to_acct_balance = asset.query_balance('ont', b58_to_address) amount = 1 gas_price = 500 gas_limit = 20000 tx_hash = asset.send_transfer('ont', from_acct, b58_to_address, amount, payer, gas_limit, gas_price) time.sleep(6) new_from_acct_balance = asset.query_balance('ont', b58_from_address) new_to_acct_balance = asset.query_balance('ont', b58_to_address) self.assertEqual(old_from_acct_balance - amount, new_from_acct_balance) self.assertEqual(old_to_acct_balance + amount, new_to_acct_balance) event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) self.assertEqual('0100000000000000000000000000000000000000', event['Notify'][0]['ContractAddress']) self.assertEqual('0200000000000000000000000000000000000000', event['Notify'][1]['ContractAddress'])
def test_send_approve(self): private_key1 = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' private_key2 = '1383ed1fe570b6673351f1a30a66b21204918ef8f673e864769fa2a653401114' sender = Account(private_key1, SignatureScheme.SHA256withECDSA) payer = Account(private_key2, SignatureScheme.SHA256withECDSA) rpc_address = 'http://polaris3.ont.io:20336' sdk = OntologySdk() sdk.rpc.set_address(rpc_address) asset = sdk.native_vm().asset() b58_recv_address = 'AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve' amount = 1 gas_limit = 20000 gas_price = 500 try: tx_hash = asset.send_approve('ont', sender, b58_recv_address, amount, payer, gas_limit, gas_price) self.assertEqual(len(tx_hash), 64) except SDKException as e: msg = 'has no balance enough to cover gas cost 10000000' self.assertEqual(59000, e.args[0]) self.assertIn(msg, e.args[1]) try: tx_hash = asset.send_approve('ong', sender, b58_recv_address, amount, payer, gas_limit, gas_price) self.assertEqual(len(tx_hash), 64) except SDKException as e: msg = 'has no balance enough to cover gas cost 10000000' self.assertEqual(59000, e.args[0]) self.assertIn(msg, e.args[1])
def test_get_total_supply(self): sdk = OntologySdk() sdk.set_rpc(local_rpc_address) oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) print("oep4.get_total_supply() is ", oep4.get_total_supply()) self.assertEqual(100000000000000000, oep4.get_total_supply())
def test_get_name(self): sdk = OntologySdk() sdk.set_rpc(local_rpc_address) oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) print("oep4.get_name() is ", oep4.get_name()) self.assertEqual('TokenName', oep4.get_name())
def test_get_symbol(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = 'd7b6a47966770c1545bf74c16426b26c0a238b16' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) self.assertEqual('DX', oep4.get_symbol())
def test_set_contract_address(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '6fe70af535887a820a13cfbaff6b0b505f855e5c' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) self.assertEqual(contract_address, oep4.get_contract_address(is_hex=True))
def test_set_contract_address(self): sdk = OntologySdk() sdk.set_rpc(local_rpc_address) oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) # print("ope4 contract address is ", oep4.get_contract_address(is_hex=True), type(oep4.get_contract_address(is_hex=True))) # print("Contract address is ", contract_address, type(contract_address)) self.assertEqual(contract_address, oep4.get_contract_address(is_hex=True))
def test_get_asset_address(self): rpc_address = 'http://polaris3.ont.io:20336' sdk = OntologySdk() sdk.rpc.set_address(rpc_address) asset = sdk.native_vm().asset() ont_address = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' ong_address = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02' self.assertEqual(ont_address, asset.get_asset_address('ont')) self.assertEqual(ong_address, asset.get_asset_address('ong'))
def __init__(self, rpc_addr: str, wallet_file: str, is_maker: bool, pwd, avm_file, abi_file): self.sdk = OntologySdk() self.sdk.rpc.set_address(rpc_addr) self.sdk.open_wallet(wallet_file) self.is_maker = is_maker # 可以查询一个合约存不存在,存在就可以让maker是True,而不必自己指定了 self.__pwd = pwd self.__get_code_from_avm(avm_file) self.__get_abi_from_file(abi_file)
def test_query_decimals(self): rpc_address = 'http://polaris3.ont.io:20336' sdk = OntologySdk() sdk.rpc.set_address(rpc_address) asset = sdk.native_vm().asset() decimals = asset.query_decimals('ong') self.assertEqual(9, decimals) decimals = asset.query_decimals('ont') self.assertEqual(1, decimals)
def test_query_symbol(self): rpc_address = 'http://polaris3.ont.io:20336' sdk = OntologySdk() sdk.rpc.set_address(rpc_address) asset = sdk.native_vm().asset() token_symbol = asset.query_symbol('ont') self.assertEqual('ONT', token_symbol) token_symbol = asset.query_symbol('ong') self.assertEqual('ONG', token_symbol)
def execute(m: [], function_name=None): sdk = OntologySdk() sdk.set_rpc(m["rpc_address"]) if m["func"] is "migrate": deploy(sdk, m) elif m["func"] is "invoke": invoke(sdk, m, function_name) else: print("only support migrate and invoke")
def query_unbound_ong(project_dir_path, address, network): if project_dir_path == '': project_dir_path = os.getcwd() if not os.path.isdir(project_dir_path): raise PunicaException(PunicaError.dir_path_error) rpc_address = handle_network_config(project_dir_path, network) sdk = OntologySdk() sdk.rpc.set_address(rpc_address) balance = sdk.native_vm().asset().query_unbound_ong(address) print(address + ' UnboundOng: ', balance)
def test_approve(self): sdk = OntologySdk() sdk.set_rpc(local_rpc_address) oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key1 = "5f2fe68215476abb9852cfa7da31ef00aa1468782d5ca809da5c4e1390b8ee45" private_key2 = "f00dd7f5356e8aee93a049bdccc44ce91169e07ea3bec9f4e0142e456fd39bae" owner_acct = Account(private_key1, SignatureScheme.SHA256withECDSA) hex_owner_address = owner_acct.get_address_hex() spender = Account(private_key2, SignatureScheme.SHA256withECDSA) b58_spender_address = spender.get_address_base58() hex_spender_address = spender.get_address_hex() amount = 100 gas_limit = 20000000 gas_price = 0 tx_hash = oep4.approve(owner_acct, b58_spender_address, amount, owner_acct, gas_limit, gas_price) self.assertEqual(len(tx_hash), 64) sdk = OntologySdk() sdk.set_rpc(local_rpc_address) time.sleep(6) try: event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) notify = event['Notify'][0] self.assertEqual(hex_owner_address, notify['States'][1]) self.assertEqual(hex_spender_address, notify['States'][2]) self.assertEqual('64', notify['States'][3]) except SDKException as e: raised = False self.assertTrue(raised, e)
def test_approve(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '6fe70af535887a820a13cfbaff6b0b505f855e5c' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key1 = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' private_key2 = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf' owner_acct = Account(private_key1, SignatureScheme.SHA256withECDSA) hex_owner_address = owner_acct.get_address_hex() spender = Account(private_key2, SignatureScheme.SHA256withECDSA) b58_spender_address = spender.get_address_base58() hex_spender_address = spender.get_address_hex() amount = 100 gas_limit = 20000000 gas_price = 500 tx_hash = oep4.approve(owner_acct, b58_spender_address, amount, owner_acct, gas_limit, gas_price) self.assertEqual(len(tx_hash), 64) sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) time.sleep(6) try: event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) notify = event['Notify'][0] self.assertEqual(hex_owner_address, notify['States'][0]) self.assertEqual(hex_spender_address, notify['States'][1]) self.assertEqual('64', notify['States'][2]) except SDKException as e: raised = False self.assertTrue(raised, e)
def test_transfer_multi(self): sdk = OntologySdk() sdk.set_rpc(local_rpc_address) oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key1 = "5f2fe68215476abb9852cfa7da31ef00aa1468782d5ca809da5c4e1390b8ee45" private_key2 = "f00dd7f5356e8aee93a049bdccc44ce91169e07ea3bec9f4e0142e456fd39bae" private_key3 = "da213fb4cb1b12269c20307dadda35a7c89869c0c791b777fd8618d4159db99c" acct1 = Account(private_key1, SignatureScheme.SHA256withECDSA) acct2 = Account(private_key2, SignatureScheme.SHA256withECDSA) acct3 = Account(private_key3, SignatureScheme.SHA256withECDSA) b58_from_address1 = acct1.get_address_base58() hex_from_address1 = acct1.get_address_hex() from_address_list = [hex_from_address1, hex_from_address1] b58_to_address2 = acct2.get_address_base58() b58_to_address3 = acct3.get_address_base58() hex_to_address2 = acct2.get_address_hex() hex_to_address3 = acct3.get_address_hex() to_address_list = [hex_to_address2, hex_to_address3] value_list = [1, 2] # print("b58 addr 1 is ", b58_from_address1) # print("b58 addr 1 is ", b58_to_address2) # print("b58 addr 1 is ", b58_to_address3) transfer1 = [b58_from_address1, b58_to_address2, value_list[0]] transfer2 = [b58_from_address1, b58_to_address3, value_list[1]] signers = [acct1] args = [] args.append(transfer1) args.append(transfer2) gas_limit = 20000000 gas_price = 500 tx_hash = oep4.transfer_multi(args, signers[0], signers, gas_limit, gas_price) self.assertEqual(64, len(tx_hash)) sdk = OntologySdk() sdk.set_rpc(local_rpc_address) time.sleep(10) try: event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) # print("event is ", event) notify = event['Notify'][0:-1] # print("notify is ", notify) self.assertEqual(len(args), len(notify)) for index in range(len(notify)): self.assertEqual(from_address_list[index], notify[index]['States'][1]) self.assertEqual(to_address_list[index], notify[index]['States'][2]) self.assertEqual(value_list[index], int(notify[index]['States'][3])) except SDKException as e: raised = False self.assertTrue(raised, e)
def test_init(self): sdk = OntologySdk() sdk.set_rpc(local_rpc_address) oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key = '5f2fe68215476abb9852cfa7da31ef00aa1468782d5ca809da5c4e1390b8ee45' acct = Account(private_key, SignatureScheme.SHA256withECDSA) gas_limit = 20000000 gas_price = 500 tx_hash = oep4.init(acct, acct, gas_limit, gas_price) self.assertEqual(len(tx_hash), 64)
def test_transfer_multi(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key1 = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' private_key2 = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf' private_key3 = '1383ed1fe570b6673351f1a30a66b21204918ef8f673e864769fa2a653401114' acct1 = Account(private_key1, SignatureScheme.SHA256withECDSA) acct2 = Account(private_key2, SignatureScheme.SHA256withECDSA) acct3 = Account(private_key3, SignatureScheme.SHA256withECDSA) args = list() b58_from_address1 = acct1.get_address_base58() b58_from_address2 = acct2.get_address_base58() hex_from_address1 = acct1.get_address_hex() hex_from_address2 = acct2.get_address_hex() from_address_list = [hex_from_address1, hex_from_address2] b58_to_address1 = acct2.get_address_base58() b58_to_address2 = acct3.get_address_base58() hex_to_address1 = acct2.get_address_hex() hex_to_address2 = acct3.get_address_hex() to_address_list = [hex_to_address1, hex_to_address2] value_list = [1.1, 2.2] transfer1 = [b58_from_address1, b58_to_address1, value_list[0]] transfer2 = [b58_from_address2, b58_to_address2, value_list[1]] signers = [acct1, acct2, acct3] args.append(transfer1) args.append(transfer2) gas_limit = 20000000 gas_price = 500 tx_hash = oep4.transfer_multi(args, signers[0], signers, gas_limit, gas_price) self.assertEqual(64, len(tx_hash)) sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) time.sleep(6) try: decimal = oep4.get_decimal() event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) notify = event['Notify'][:-1] self.assertEqual(len(args), len(notify)) for index in range(len(notify)): self.assertEqual('transfer', bytes.fromhex(notify[index]['States'][0]).decode()) self.assertEqual(from_address_list[index], notify[index]['States'][1]) self.assertEqual(to_address_list[index], notify[index]['States'][2]) array = bytearray(binascii.a2b_hex(notify[index]['States'][3].encode('ascii'))) array.reverse() notify_value = int(binascii.b2a_hex(array).decode('ascii'), 16) self.assertEqual((10 ** decimal) * value_list[index], notify_value) except SDKException as e: raised = False self.assertTrue(raised, e)
def test_transfer_multi(self): sdk = OntologySdk() sdk.rpc.connect_to_test_net() contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9' oep4 = sdk.neo_vm.oep4() oep4.hex_contract_address = contract_address transfer_list = list() b58_from_address1 = acct1.get_address_base58() b58_from_address2 = acct2.get_address_base58() hex_from_address1 = acct1.get_address_hex() hex_from_address2 = acct2.get_address_hex() from_address_list = [hex_from_address1, hex_from_address2] b58_to_address1 = acct2.get_address_base58() b58_to_address2 = acct3.get_address_base58() hex_to_address1 = acct2.get_address_hex() hex_to_address2 = acct3.get_address_hex() to_address_list = [hex_to_address1, hex_to_address2] value_list = [1, 2] transfer1 = [b58_from_address1, b58_to_address1, value_list[0]] transfer2 = [b58_from_address2, b58_to_address2, value_list[1]] signers = [acct1, acct2, acct3] transfer_list.append(transfer1) transfer_list.append(transfer2) gas_limit = 20000000 gas_price = 500 tx_hash = oep4.transfer_multi(transfer_list, signers[0], signers, gas_limit, gas_price) self.assertEqual(64, len(tx_hash)) sdk = OntologySdk() sdk.rpc.connect_to_test_net() time.sleep(randint(6, 10)) try: event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) notify_list = event['Notify'][:-1] self.assertEqual(len(transfer_list), len(notify_list)) for index, notify in enumerate(notify_list): self.assertEqual( 'transfer', ContractDataParser.to_utf8_str(notify['States'][0])) self.assertEqual(from_address_list[index], notify['States'][1]) self.assertEqual(to_address_list[index], notify['States'][2]) notify_value = ContractDataParser.to_int(notify['States'][3]) self.assertEqual(value_list[index], notify_value) except SDKException as e: raised = False self.assertTrue(raised, e)
def test_balance_of(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) b58_address1 = 'ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6' b58_address2 = 'AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve' balance = oep4.balance_of(b58_address1) self.assertGreaterEqual(balance, 10) balance = oep4.balance_of(b58_address2) self.assertGreaterEqual(balance, 1)
def test_init(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '6fe70af535887a820a13cfbaff6b0b505f855e5c' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' acct = Account(private_key, SignatureScheme.SHA256withECDSA) gas_limit = 20000000 gas_price = 500 tx_hash = oep4.init(acct, acct, gas_limit, gas_price) self.assertEqual(len(tx_hash), 64)
def test_transfer_multi(self): sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) contract_address = '6fe70af535887a820a13cfbaff6b0b505f855e5c' oep4 = sdk.neo_vm().oep4() oep4.set_contract_address(contract_address) private_key1 = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' private_key2 = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf' private_key3 = '1383ed1fe570b6673351f1a30a66b21204918ef8f673e864769fa2a653401114' acct1 = Account(private_key1, SignatureScheme.SHA256withECDSA) acct2 = Account(private_key2, SignatureScheme.SHA256withECDSA) acct3 = Account(private_key3, SignatureScheme.SHA256withECDSA) args = list() b58_from_address1 = acct1.get_address_base58() b58_from_address2 = acct2.get_address_base58() hex_from_address1 = acct1.get_address_hex() hex_from_address2 = acct2.get_address_hex() from_address_list = [hex_from_address1, hex_from_address2] b58_to_address1 = acct2.get_address_base58() b58_to_address2 = acct3.get_address_base58() hex_to_address1 = acct2.get_address_hex() hex_to_address2 = acct3.get_address_hex() to_address_list = [hex_to_address1, hex_to_address2] value_list = [1, 2] transfer1 = [b58_from_address1, b58_to_address1, value_list[0]] transfer2 = [b58_from_address2, b58_to_address2, value_list[1]] signers = [acct1, acct2, acct3] args.append(transfer1) args.append(transfer2) gas_limit = 20000000 gas_price = 500 tx_hash = oep4.transfer_multi(args, signers[0], signers, gas_limit, gas_price) self.assertEqual(64, len(tx_hash)) sdk = OntologySdk() sdk.set_rpc(remote_rpc_address) time.sleep(6) try: event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) notify = event['Notify'][:-1] self.assertEqual(len(args), len(notify)) for index in range(len(notify)): self.assertEqual(from_address_list[index], notify[index]['States'][0]) self.assertEqual(to_address_list[index], notify[index]['States'][1]) self.assertEqual(value_list[index], int(notify[index]['States'][2])) except SDKException as e: raised = False self.assertTrue(raised, e)
def balance_of(project_dir_path: str, asset: str, address: str, network: str): if asset == '' or asset.lower() != 'ont' and asset.lower() != 'ong': print(asset, ' asset should be ont or ong') return if project_dir_path == '': project_dir_path = os.getcwd() if not os.path.isdir(project_dir_path): raise PunicaException(PunicaError.dir_path_error) rpc_address = handle_network_config(project_dir_path, network) sdk = OntologySdk() sdk.rpc.set_address(rpc_address) balance = sdk.native_vm().asset().query_balance(asset, address) print(address + ' Balance: ', balance)