def run(self): dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks) dbloop.start(.1) Blockchain.Default().PersistBlocks() while Blockchain.Default().Height < 2: print("Waiting for chain to sync...") time.sleep(1) # Claim initial NEO address = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y" self.claim_initial_neo(address) # Open wallet again print("Opening wallet %s" % self.wallet_fn) self.wallet = UserWallet.Open(self.wallet_fn, to_aes_key("coz")) self.wallet.ProcessBlocks() self._walletdb_loop = task.LoopingCall(self.wallet.ProcessBlocks) self._walletdb_loop.start(1) # self.wallet.Rebuild() # print("\nOpened wallet. Rebuilding...") # time.sleep(10) print("\nWait %s min before claiming GAS." % self.min_wait) time.sleep(60 * self.min_wait) print("\nSending NEO to own wallet...") with patch('neo.Prompt.Commands.Send.prompt', side_effect=["coz"]): framework = construct_send_basic(self.wallet, ["neo", address, "100000000"]) tx = process_transaction(self.wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) if not tx: print("Something went wrong, no tx.") return # Wait until transaction is on blockchain self.wait_for_tx(tx) print("Claiming the GAS...") claim_tx, relayed = ClaimGas(self.wallet, require_password=False) self.wait_for_tx(claim_tx) # Finally, need to rebuild the wallet self.wallet.Rebuild() print("\nAll done!") print("- Wallet file: %s" % self.wallet_fn) print("- Wallet pwd: %s" % self.wallet_pwd) if self.wif_fn: with open(self.wif_fn, "w") as f: f.write("KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr") self.quit()
def test_send_with_fee_and_from_addr(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): wallet = self.GetWallet1(recreate=True) args = [ 'neo', self.watch_addr_str, '1', '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3', '--fee=0.005' ] framework = construct_send_basic(wallet, args) res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertTrue(res) # verify successful tx json_res = res.ToJson() self.assertEqual( self.watch_addr_str, json_res['vout'][0]['address']) # verify correct address_to self.assertEqual( self.wallet_1_addr, json_res['vout'][1]['address']) # verify correct address_from self.assertEqual(json_res['net_fee'], "0.005") # verify correct fee
def test_send_bad_args(self): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str] # too few args framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_weird_fee(self): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str, '12', '--fee=0.0abc'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_bad_precision_amount(self): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str, '12.01'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_negative_amount(self): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str, '-12'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_bad_assetid(self): wallet = self.GetWallet1(recreate=True) args = ['blah', self.watch_addr_str, '12'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_no_wallet(self): wallet = None args = ['neo', self.watch_addr_str, '50'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_bad_address_from(self): wallet = self.GetWallet1(recreate=True) address_from = '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc' # address_from is too short causing ToScriptHash to fail args = ['neo', self.watch_addr_str, '12', address_from] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_bad_address_to(self): wallet = self.GetWallet1(recreate=True) address_to = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkE' # address_to is too short causing ToScriptHash to fail args = ['neo', address_to, '12'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_send_token_bad(self): wallet = self.GetWallet1(recreate=True) token_hash = 'f8d448b227991cf07cb96a6f9c0322437f1599b9' ImportToken(wallet, token_hash) args = ['NEP5', self.watch_addr_str, '32'] framework = construct_send_basic(wallet, args) self.assertFalse(framework)
def test_bad_password(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=['blah']): wallet = self.GetWallet1(recreate=True) args = ['neo', self.watch_addr_str, '50'] framework = construct_send_basic(wallet, args) res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertFalse(res)
def test_insufficient_funds(self): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '72620'] framework = construct_send_basic(wallet, args) res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertFalse(res)
def run(self): dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks) dbloop.start(.1) Blockchain.Default().PersistBlocks() while Blockchain.Default().Height < 2: print("Waiting for chain to sync...") time.sleep(1) # Open wallet again print("Opening wallet %s" % self.wallet_fn) self.wallet = UserWallet.Open(self.wallet_fn, to_aes_key("coz")) self.wallet.ProcessBlocks() self._walletdb_loop = task.LoopingCall(self.wallet.ProcessBlocks) self._walletdb_loop.start(1) print("\nWait %s min before claiming GAS." % self.min_wait) time.sleep(60 * self.min_wait) self.wallet.Rebuild() print("\nRebuilding wallet...") time.sleep(20) print("\nSending NEO to own wallet...") address = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y" with patch('neo.Prompt.Commands.Send.prompt', side_effect=["coz"]): framework = construct_send_basic(self.wallet, ["neo", address, "100000000"]) tx = process_transaction(self.wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) if not tx: print("Something went wrong, no tx.") return # Wait until transaction is on blockchain self.wait_for_tx(tx) print("Claiming the GAS...") claim_tx, relayed = ClaimGas(self.wallet, require_password=False) self.wait_for_tx(claim_tx) # Finally, need to rebuild the wallet # self.wallet.Rebuild() self.quit()
def test_fails_to_sign_tx(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): with patch('neo.Wallets.Wallet.Wallet.Sign', return_value=False): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '2'] framework = construct_send_basic(wallet, args) res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertFalse(res)
def test_send_token_ok(self): with patch('neo.Prompt.Commands.Tokens.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): wallet = self.GetWallet1(recreate=True) token_hash = '31730cc9a1844891a3bafd1aa929a4142860d8d3' ImportToken(wallet, token_hash) args = [ 'NXT4', self.watch_addr_str, '30', '--from-addr=%s' % self.wallet_1_addr ] framework = construct_send_basic(wallet, args) self.assertTrue(framework)
def test_send_gas_mimic_prompt(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '5'] res = False framework = construct_send_basic(wallet, args) if type(framework) is list: res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertTrue(res)
def test_could_not_send(self, mocked_tracback_module): # mocking traceback module to avoid stacktrace printing during test run wallet = self.GetWallet1(recreate=True) args = ['gas', self.watch_addr_str, '2'] contract_tx, scripthash_from, fee, owners, user_tx_attributes = construct_send_basic( wallet, args) scripthash_change = scripthash_from # mocking wallet to trigger the exception wallet = MagicMock() wallet.MakeTransaction.side_effect = Exception res = process_transaction( wallet, contract_tx, scripthash_from, scripthash_change, fee, owners, user_tx_attributes) # forces the 'try:' to fail self.assertFalse(res)
def test_owners(self, mock): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): wallet = self.GetWallet1(recreate=True) args = [ 'gas', self.wallet_1_addr, '2', "--owners=['AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK','APRgMZHZubii29UXF9uFa6sohrsYupNAvx']" ] framework = construct_send_basic(wallet, args) process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertTrue(mock.called)
def test_bad_attributes(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): wallet = self.GetWallet1(recreate=True) args = [ 'gas', self.watch_addr_str, '2', '--tx-attr=[{"usa:241"data":his is a remark"}]' ] framework = construct_send_basic(wallet, args) res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertTrue(res) self.assertEqual(1, len(res.Attributes))
def test_attributes(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): wallet = self.GetWallet1(recreate=True) args = [ 'gas', self.watch_addr_str, '2', '--tx-attr={"usage":241,"data":"This is a remark"}' ] framework = construct_send_basic(wallet, args) res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) self.assertTrue(res) self.assertEqual( 2, len(res.Attributes) ) # By default the script_hash of the transaction sender is added to the TransactionAttribute list, therefore the Attributes length is `count` + 1