def test_transfer_Ont(self):
        wallet_path = "C:\\Go_WorkSpace\\src\\github.com\\ontio\\ontology\\_Wallet_\\wallet.dat"
        sdk.wallet_manager.open_wallet(wallet_path)
        acct1_addr = "AQf4Mzu1YJrhz9f3aRkkwSm9n3qhXGSh4p"
        acct1_pwd = "xinhao"
        acct1 = sdk.wallet_manager.get_account(acct1_addr, acct1_pwd)
        # export several keys
        wif_key = acct1.export_wif()
        print("wif_key is ", wif_key)
        private_key_bytes = acct1.get_privatekey_from_wif(wif_key)
        print("private_key_bytes is ", private_key_bytes,
              type(private_key_bytes))
        private_key_str = private_key_bytes.hex()
        print("private_key_str is ", private_key_str)

        contract_address_str = "0000000000000000000000000000000000000001"
        contract_address_bytearray = bytearray.fromhex(contract_address_str)
        contract_address = contract_address_bytearray
        # contract_address.reverse()
        print("my converted contract_address is ", contract_address)
        print("the givencontract_address is ", ONT_CONTRACT_ADDRESS)

        print('contract_address is ', contract_address)
        mybalance_1 = sdk.rpc.get_balance(acct1.get_address_base58())
        print("acc wif_key is ", acc.export_wif())

        from_acc = acct1
        to_acc = acc
        asset = "ong"
        balance_1 = sdk.rpc.get_balance(from_acc.get_address_base58())
        print("mybalance_1 is ", mybalance_1)
        print("balance_1 is ", balance_1)
        ass = Asset(sdk)
        from_addr = from_acc.get_address_base58()
        to_addr = to_acc.get_address_base58()
        print("Transfer from " + from_addr + " to " + to_addr)
        amount = int(int(balance_1[asset]) / 2)
        print("amount is ", amount, type(amount))
        payer = acct1.get_address_base58()
        gaslimit = 20000
        gasprice = 500

        # print('ong balance is ', sdk.rpc.get_balance(from_acc.get_address_base58()))
        # # int(ass.unbound_ong(from_addr))
        # ass.send_withdraw_ong_transaction(from_acc, to_addr, 100, to_acc,gaslimit, gasprice)
        #
        # print('ong balance is ', sdk.rpc.get_balance(from_acc.get_address_base58()))

        tx = ass.new_transfer_transaction(asset, from_addr, to_addr, amount,
                                          payer, gaslimit, gasprice)
        sdk.sign_transaction(tx, acct1)
        # sdk.sign_transaction(tx, to_acc)
        res = sdk.rpc.send_raw_transaction(tx)
        print("res in test_transfer_Ont is ", res)
    def test_transferONG(self, fromAcct, toAcct, ongAmount):

        fromAddr = fromAcct.get_address_base58()
        toAddr = toAcct.get_address_base58()
        asset = "ong"
        ass = Asset(sdk)
        payerAddr = fromAddr
        gaslimit = 20000000
        gasprice = 500
        tx = ass.new_transfer_transaction(asset, fromAddr, toAddr, ongAmount, payerAddr, gaslimit, gasprice)
        sdk.sign_transaction(tx, fromAcct)
        hash = sdk.rpc.send_raw_transaction(tx)
 def test_send_raw_transaction(self):
     private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
     acct = Account(a2b_hex(private_key.encode()))
     private_key2 = get_random_bytes(32)
     acct2 = Account(private_key2)
     tx = Asset.new_transfer_transaction("ont", acct.get_address_base58(),
                                         acct2.get_address_base58(), 2,
                                         acct.get_address_base58(), 20000,
                                         500)
     tx = sdk.sign_transaction(tx, acct)
     res = sdk.rpc.send_raw_transaction(tx)
     self.assertEqual(len(res), 64)
Esempio n. 4
0
 def test_send_raw_transaction_pre_exec(self):
     pri_key_1 = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
     acct = Account(pri_key_1)
     pri_key2 = get_random_str(64)
     acct2 = Account(pri_key2)
     b58_address_1 = acct.get_address_base58()
     b58_address_2 = acct2.get_address_base58()
     tx = Asset.new_transfer_transaction("ont", b58_address_1,
                                         b58_address_2, 2, b58_address_1,
                                         20000, 500)
     tx = sdk.sign_transaction(tx, acct)
     result = sdk.rpc.send_raw_transaction_pre_exec(tx)
     self.assertEqual(result, '01')
Esempio n. 5
0
 def test_send_raw_transaction(self):
     pri_key_1 = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
     acct = Account(pri_key_1)
     length = 64
     pri_key_2 = get_random_str(length)
     acct2 = Account(pri_key_2)
     b58_address_1 = acct.get_address_base58()
     b58_address_2 = acct2.get_address_base58()
     tx = Asset.new_transfer_transaction("ont", b58_address_1,
                                         b58_address_2, 2, b58_address_1,
                                         20000, 500)
     tx = sdk.sign_transaction(tx, acct)
     tx_hash = sdk.rpc.send_raw_transaction(tx)
     self.assertEqual(tx_hash, tx.hash256_explorer())
 def test_send_raw_transaction(self):
     private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
     acct = Account(private_key, SignatureScheme.SHA256withECDSA)
     b58_from_address = acct.get_address_base58()
     b58_to_address = 'AW352JufVwuZReSt7SCQpbYqrWeuERUNJr'
     amount = 1
     gas_price = 500
     gas_limit = 20000
     tx = Asset.new_transfer_transaction('ont', b58_from_address,
                                         b58_to_address, amount,
                                         b58_from_address, gas_limit,
                                         gas_price)
     tx = sdk.sign_transaction(tx, acct)
     tx_hash = sdk.rpc.send_raw_transaction(tx)
     self.assertEqual(tx_hash, tx.hash256_explorer())
 def test_new_approve_transaction(self):
     private_key = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f'
     sender = Account(private_key, SignatureScheme.SHA256withECDSA)
     b58_send_address = sender.get_address_base58()
     b58_payer_address = sender.get_address_base58()
     b58_recv_address = 'AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve'
     amount = 5
     gas_price = 500
     gas_limit = 20000
     tx = Asset.new_approve_transaction('ont', b58_send_address,
                                        b58_recv_address, amount,
                                        b58_payer_address, gas_limit,
                                        gas_price)
     tx = sdk.sign_transaction(tx, sender)
     tx_hash = sdk.rpc.send_raw_transaction(tx)
     self.assertEqual(64, len(tx_hash))
 def test_new_withdraw_ong_transaction(self):
     private_key = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f'
     claimer = Account(private_key, SignatureScheme.SHA256withECDSA)
     b58_claimer_address = claimer.get_address_base58()
     b58_recv_address = claimer.get_address_base58()
     b58_payer_address = claimer.get_address_base58()
     amount = 1
     gas_price = 500
     gas_limit = 20000
     tx = Asset.new_withdraw_ong_transaction(b58_claimer_address,
                                             b58_recv_address, amount,
                                             b58_payer_address, gas_limit,
                                             gas_price)
     sdk.add_sign_transaction(tx, claimer)
     tx_hash = sdk.rpc.send_raw_transaction(tx)
     self.assertEqual(64, len(tx_hash))
Esempio n. 9
0
 def test_new_transfer_from_transaction(self):
     rpc_address = 'http://polaris3.ont.io:20336'
     sdk = OntologySdk()
     sdk.rpc.set_address(rpc_address)
     private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
     sender = Account(private_key, SignatureScheme.SHA256withECDSA)
     b58_sender_address = sender.get_address_base58()
     b58_payer_address = sender.get_address_base58()
     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 = Asset.new_transfer_from_transaction('ont', b58_sender_address,
                                              b58_from_address,
                                              b58_recv_address, amount,
                                              b58_payer_address, gas_limit,
                                              gas_price)
     sdk.add_sign_transaction(tx, sender)
     try:
         tx_hash = sdk.rpc.send_raw_transaction(tx)
         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']))
         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'])
     except SDKException as e:
         msg = '[TransferFrom] approve balance insufficient!'
         self.assertEqual(59000, e.args[0])
         self.assertIn(msg, e.args[1])
Esempio n. 10
0
 def test_query_allowance(self):
     a = Asset(sdk)
     res = a.query_allowance("ont",
                             acc.get_address().b58encode(),
                             acc2.get_address().b58encode())
     self.assertEqual(res, '01')
Esempio n. 11
0
 def test_query_balance(self):
     a = Asset(sdk)
     res = a.query_balance("ont", acc.get_address_base58())
     print(res)
     self.assertTrue(isinstance(res, int))
Esempio n. 12
0
 def test_send_approve2(self):
     a = Asset(sdk)
     res = a.send_approve("ont", acc, acc2.get_address_base58(), 1, acc3,
                          20000, 500)
     self.assertEqual(len(res), 64)
Esempio n. 13
0
 def test_send_withdraw_ong_transaction(self):
     a = Asset(sdk)
     res = a.send_withdraw_ong_transaction(acc, acc2.get_address_base58(),
                                           1, acc3, 20000, 500)
     self.assertEqual(res, '01')
 def test_query_name(self):
     a = Asset(sdk)
     res = a.query_name("ont")
     print(res)
 def test_send_approve2(self):
     a = Asset(sdk)
     res = a.send_approve("ont", acc, acc2.get_address_base58(), 1, acc3,
                          20000, 500)
     print(res)
 def test_send_withdraw_ong_transaction(self):
     a = Asset(sdk)
     res = a.send_withdraw_ong_transaction(acc, acc2.get_address_base58(),
                                           1, acc3, 20000, 500)
     print(res)
 def test_query_decimals(self):
     a = Asset(sdk)
     res = a.query_decimals("ong")
     print(res)
 def test_query_symbol(self):
     a = Asset(sdk)
     res = a.query_symbol("ont")
     print(res)
Esempio n. 19
0
 def asset(self):
     return Asset(self.__sdk)
Esempio n. 20
0
 def test_query_decimals(self):
     a = Asset(sdk)
     res = a.query_decimals("ong")
     self.assertEqual(res, '09')
     res = a.query_decimals("ont")
     self.assertEqual(res, '01')
Esempio n. 21
0
 def test_query_name(self):
     a = Asset(sdk)
     res = a.query_name('ont')
     self.assertEqual(res, 'ONT Token')
 def test_query_allowance(self):
     a = Asset(sdk)
     res = a.query_allowance("ont",
                             acc.get_address().to_base58(),
                             acc2.get_address().to_base58())
     print(res)
Esempio n. 23
0
 def test_query_symbol(self):
     a = Asset(sdk)
     res = a.query_symbol('ont')
     self.assertEqual(res, 'ONT')
Esempio n. 24
0
 def test_query_balance(self):
     a = Asset(sdk)
     res = a.query_balance("ont", acc.get_address().b58encode())
     self.assertTrue(isinstance(res, int))