def test_unbound_ong(self): b58_address1 = acct1.get_address_base58() b58_address2 = acct2.get_address_base58() b58_address3 = acct3.get_address_base58() b58_address4 = acct4.get_address_base58() try: acct1_unbound_ong = sdk.native_vm.asset().query_unbound_ong( b58_address1) self.assertGreaterEqual(acct1_unbound_ong, 0) except SDKException as e: self.assertIn('ConnectTimeout', e.args[1]) try: acct2_unbound_ong = sdk.native_vm.asset().query_unbound_ong( b58_address2) self.assertGreaterEqual(acct2_unbound_ong, 0) except SDKException as e: self.assertIn('ConnectTimeout', e.args[1]) try: acct3_unbound_ong = sdk.native_vm.asset().query_unbound_ong( b58_address3) self.assertGreaterEqual(acct3_unbound_ong, 0) except SDKException as e: self.assertIn('ConnectTimeout', e.args[1]) try: acct4_unbound_ong = sdk.native_vm.asset().query_unbound_ong( b58_address4) self.assertGreaterEqual(acct4_unbound_ong, 0) except SDKException as e: self.assertIn('ConnectTimeout', e.args[1])
def test_transfer_multi_args(self): transfer_1 = [ acct1.get_address().to_bytes(), acct2.get_address().to_bytes(), 10 ] transfer_2 = [ acct2.get_address().to_bytes(), acct3.get_address().to_bytes(), 100 ] hex_contract_address = 'ca91a73433c016fbcbcf98051d385785a6a5d9be' func = InvokeFunction('transfer_multi_args') func.set_params_value(transfer_1, transfer_2) tx_hash = self.send_tx(hex_contract_address, acct1, acct2, func) if len(tx_hash) == 0: return time.sleep(randint(7, 12)) event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) states = ContractEventParser.get_states_by_contract_address( event, hex_contract_address) states[0] = ContractDataParser.to_utf8_str(states[0]) self.assertEqual('transfer_multi_args', states[0]) states[1][0][0] = ContractDataParser.to_b58_address(states[1][0][0]) self.assertEqual(acct1.get_address_base58(), states[1][0][0]) states[1][0][1] = ContractDataParser.to_b58_address(states[1][0][1]) self.assertEqual(acct2.get_address_base58(), states[1][0][1]) states[1][0][2] = ContractDataParser.to_int(states[1][0][2]) self.assertEqual(10, states[1][0][2]) states[1][1][0] = ContractDataParser.to_b58_address(states[1][1][0]) self.assertEqual(acct2.get_address_base58(), states[1][1][0]) states[1][1][1] = ContractDataParser.to_b58_address(states[1][1][1]) self.assertEqual(acct3.get_address_base58(), states[1][1][1]) states[1][1][2] = ContractDataParser.to_int(states[1][1][2]) self.assertEqual(100, states[1][1][2])
def test_get_memory_poll_tx_state(self): tx_hash = '0000000000000000000000000000000000000000000000000000000000000000' try: restful_client.get_memory_pool_tx_state(tx_hash) except SDKException as e: self.assertIn('UNKNOWN TRANSACTION', e.args[1]) contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9' sdk = OntologySdk() rpc_address = choice(TEST_RPC_ADDRESS) sdk.rpc.set_address(rpc_address) oep4 = sdk.neo_vm.oep4() oep4.hex_contract_address = contract_address from_acct = acct4 gas_limit = 20000000 gas_price = 500 b58_to_address = acct3.get_address_base58() value = 10 tx_hash = oep4.transfer(from_acct, b58_to_address, value, from_acct, gas_limit, gas_price) self.assertEqual(64, len(tx_hash)) try: tx_state = restful_client.get_memory_pool_tx_state(tx_hash) self.assertGreaterEqual(tx_state[0]['Height'], 0) self.assertGreaterEqual(tx_state[1]['Height'], 0) except SDKException: pass
def test_balance_of(self): contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9' oep4 = sdk.neo_vm.oep4() oep4.hex_contract_address = contract_address b58_address1 = acct3.get_address_base58() b58_address2 = acct4.get_address_base58() balance = oep4.balance_of(b58_address1) self.assertGreaterEqual(balance, 10) balance = oep4.balance_of(b58_address2) self.assertGreaterEqual(balance, 1)
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_transfer_multi(self): 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() from_address_list = [b58_from_address1, b58_from_address2] b58_to_address1 = acct2.get_address_base58() b58_to_address2 = acct3.get_address_base58() to_address_list = [b58_to_address1, b58_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)) time.sleep(randint(6, 10)) notify_list = oep4.query_multi_transfer_event(tx_hash) try: self.assertEqual(len(transfer_list), len(notify_list)) for index, notify in enumerate(notify_list): self.assertEqual('transfer', notify['States'][0]) self.assertEqual(from_address_list[index], notify['States'][1]) self.assertEqual(to_address_list[index], notify['States'][2]) self.assertEqual(value_list[index], notify['States'][3]) except SDKException as e: raised = False self.assertTrue(raised, e)
def test_transfer_multi_args(self): transfer_1 = [ acct1.get_address().to_bytes(), acct2.get_address().to_bytes(), 10 ] transfer_2 = [ acct2.get_address().to_bytes(), acct3.get_address().to_bytes(), 100 ] hex_contract_address = 'ca91a73433c016fbcbcf98051d385785a6a5d9be' func = InvokeFunction('transfer_multi_args') func.set_params_value(transfer_1, transfer_2) try: tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, acct1, acct2, gas_limit, gas_price, func, False) self.assertEqual(64, len(tx_hash)) except SDKException as e: self.assertIn('already in the tx pool', e.args[1]) return time.sleep(randint(6, 10)) event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash) states = ContractEventParser.get_states_by_contract_address( event, hex_contract_address) states[0] = ContractDataParser.to_utf8_str(states[0]) self.assertEqual('transfer_multi_args', states[0]) states[1][0][0] = ContractDataParser.to_b58_address(states[1][0][0]) self.assertEqual(acct1.get_address_base58(), states[1][0][0]) states[1][0][1] = ContractDataParser.to_b58_address(states[1][0][1]) self.assertEqual(acct2.get_address_base58(), states[1][0][1]) states[1][0][2] = ContractDataParser.to_int(states[1][0][2]) self.assertEqual(10, states[1][0][2]) states[1][1][0] = ContractDataParser.to_b58_address(states[1][1][0]) self.assertEqual(acct2.get_address_base58(), states[1][1][0]) states[1][1][1] = ContractDataParser.to_b58_address(states[1][1][1]) self.assertEqual(acct3.get_address_base58(), states[1][1][1]) states[1][1][2] = ContractDataParser.to_int(states[1][1][2]) self.assertEqual(100, states[1][1][2])