Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.

Commit 4448f76

Browse files
author
jseagrave21
committed
update test_send_commands.py
1 parent 1be1212 commit 4448f76

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

neo/Prompt/Commands/tests/test_send_commands.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ class UserWalletTestCase(WalletFixtureTestCase):
2323
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
2424
_wallet1 = None
2525

26+
wallet_2_addr = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
2627
_wallet2 = None
2728

28-
wallet_1_and_2_multisig_addr = "AY7cn9RRanTWtDTZ5AgcxoYMGBMcuqFZw5"
29+
wallet_3_addr = 'AZiE7xfyJALW7KmADWtCJXGGcnduYhGiCX'
30+
_wallet3 = None
31+
32+
wallet_2_and_3_multisig_addr = "Aau2M4UdXxwxLLizDw11eDZRDs5jpXduh8"
2933

3034
@classmethod
3135
def GetWallet1(cls, recreate=False):
@@ -43,6 +47,14 @@ def GetWallet2(cls, recreate=False):
4347
to_aes_key(UserWalletTestCase.wallet_2_pass()))
4448
return cls._wallet2
4549

50+
@classmethod
51+
def GetWallet3(cls, recreate=False):
52+
if cls._wallet3 is None or recreate:
53+
shutil.copyfile(cls.wallet_3_path(), cls.wallet_3_dest())
54+
cls._wallet3 = UserWallet.Open(UserWalletTestCase.wallet_3_dest(),
55+
to_aes_key(UserWalletTestCase.wallet_3_pass()))
56+
return cls._wallet3
57+
4658
@classmethod
4759
def tearDown(cls):
4860
PromptData.Wallet = None
@@ -51,7 +63,7 @@ def test_send_neo(self):
5163
with patch('sys.stdout', new=StringIO()) as mock_print:
5264
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]):
5365
PromptData.Wallet = self.GetWallet1(recreate=True)
54-
args = ['send', 'neo', self.watch_addr_str, '50']
66+
args = ['send', 'neo', self.watch_addr_str, '1']
5567

5668
res = Wallet.CommandWallet().execute(args)
5769

@@ -62,7 +74,7 @@ def test_send_gas(self):
6274
with patch('sys.stdout', new=StringIO()) as mock_print:
6375
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]):
6476
PromptData.Wallet = self.GetWallet1(recreate=True)
65-
args = ['send', 'gas', self.watch_addr_str, '5']
77+
args = ['send', 'gas', self.watch_addr_str, '1']
6678

6779
res = Wallet.CommandWallet().execute(args)
6880

@@ -563,13 +575,13 @@ def test_parse_and_sign_good(self):
563575
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
564576
# start the tx from wallet2
565577
PromptData.Wallet = self.GetWallet2(recreate=True)
566-
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_1_and_2_multisig_addr]
578+
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]
567579

568580
Wallet.CommandWallet().execute(args)
569581

570-
# now sign the tx with wallet1
571-
PromptData.Wallet = self.GetWallet1(recreate=True)
572-
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'
582+
# now sign the tx with wallet3
583+
PromptData.Wallet = self.GetWallet3(recreate=True)
584+
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
573585
args = ['sign', jsn]
574586

575587
res = Wallet.CommandWallet().execute(args)
@@ -578,22 +590,23 @@ def test_parse_and_sign_good(self):
578590
self.assertTrue(res)
579591
self.assertEqual(res['vout'][0]['value'], "1") # verify the amount
580592
self.assertEqual(res['vout'][0]['address'], self.wallet_1_addr) # verify to_address
581-
self.assertEqual(res['vout'][1]['address'], self.wallet_1_and_2_multisig_addr) # verify from_address
593+
self.assertEqual(res['vout'][1]['address'], self.wallet_2_and_3_multisig_addr) # verify from_address
582594

583595
def test_parse_and_sign_bad_jsn(self):
584596
with patch('sys.stdout', new=StringIO()) as mock_print:
585597
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
586598
# start the tx from wallet2
587599
PromptData.Wallet = self.GetWallet2(recreate=True)
588-
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_1_and_2_multisig_addr]
600+
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]
589601

590602
Wallet.CommandWallet().execute(args)
591603

592-
# now sign the tx with wallet1
593-
PromptData.Wallet = self.GetWallet1(recreate=True)
604+
# now sign the tx with wallet3
605+
PromptData.Wallet = self.GetWallet3(recreate=True)
594606
jsn = 'blah'
607+
args = ['sign', jsn]
595608

596-
res = Wallet.CommandWallet().execute(jsn)
609+
res = Wallet.CommandWallet().execute(args)
597610

598611
self.assertFalse(res)
599612
self.assertIn("Failed to parse JSON", mock_print.getvalue())
@@ -604,13 +617,13 @@ def test_parse_and_sign_fails_to_relay(self):
604617
with patch('neo.Prompt.Commands.Send.NodeLeader.Relay', return_value=False):
605618
# start the tx from wallet2
606619
PromptData.Wallet = self.GetWallet2(recreate=True)
607-
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_1_and_2_multisig_addr]
620+
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]
608621

609622
Wallet.CommandWallet().execute(args)
610623

611-
# now sign the tx with wallet1
612-
PromptData.Wallet = self.GetWallet1(recreate=True)
613-
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'
624+
# now sign the tx with wallet3
625+
PromptData.Wallet = self.GetWallet3(recreate=True)
626+
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
614627
args = ['sign', jsn]
615628

616629
res = Wallet.CommandWallet().execute(args)
@@ -623,12 +636,12 @@ def test_parse_and_sign_twice(self): # this test implies there are more signatu
623636
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
624637
# start the tx from wallet2
625638
PromptData.Wallet = self.GetWallet2(recreate=True)
626-
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_1_and_2_multisig_addr]
639+
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]
627640

628641
Wallet.CommandWallet().execute(args)
629642

630643
# now sign the tx with wallet2 again
631-
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'
644+
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
632645
args = ['sign', jsn]
633646

634647
res = Wallet.CommandWallet().execute(args)
@@ -642,14 +655,14 @@ def test_parse_and_sign_exception(self):
642655
with patch('neo.Prompt.Commands.Send.traceback'): # mocking traceback module to avoid stacktrace printing during test run
643656
# start the tx from wallet2
644657
PromptData.Wallet = self.GetWallet2(recreate=True)
645-
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_1_and_2_multisig_addr]
658+
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]
646659

647660
Wallet.CommandWallet().execute(args)
648661

649662
# mocking wallet to trigger the exception
650663
PromptData.Wallet = MagicMock()
651664
PromptData.Wallet.Sign.side_effect = Exception
652-
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'
665+
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
653666
args = ['sign', jsn]
654667

655668
res = Wallet.CommandWallet().execute(args)
@@ -659,6 +672,7 @@ def test_parse_and_sign_exception(self):
659672

660673
def test_parse_and_sign_no_args(self):
661674
with patch('sys.stdout', new=StringIO()) as mock_print:
675+
PromptData.Wallet = self.GetWallet2(recreate=True)
662676
args = ['sign']
663677

664678
res = Wallet.CommandWallet().execute(args)

0 commit comments

Comments
 (0)