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

Improve parse_and_sign #716

Open
wants to merge 77 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
13e979b
Merge pull request #38 from CityOfZion/development
jseagrave21 Oct 10, 2018
e41e950
Merge pull request #40 from CityOfZion/development
jseagrave21 Oct 11, 2018
7db54f4
Merge pull request #41 from CityOfZion/development
jseagrave21 Oct 11, 2018
54a4f3f
Fix ExtendedJsonRpcApi (#662)
jseagrave21 Oct 11, 2018
0f96dc3
Mute expected test stacktrace and clearly identify why an exception i…
ixje Oct 12, 2018
1e5b4dc
Add guideline for adding tests to the neo-privnet-unittest image (#661)
dauTT Oct 12, 2018
8febcf1
Update CHANGELOG.rst
jseagrave21 Oct 18, 2018
c7a790f
Update CHANGELOG.rst
jseagrave21 Oct 18, 2018
c51390e
Merge CoZ Development into jseagrave21 Development (#49)
jseagrave21 Oct 18, 2018
32a16e3
Merge pull request #50 from CityOfZion/development
jseagrave21 Oct 18, 2018
3c8232d
Merge pull request #53 from CityOfZion/development
jseagrave21 Oct 25, 2018
1b00db8
Merge pull request #54 from CityOfZion/development
jseagrave21 Oct 26, 2018
eb495bf
Merge pull request #58 from CityOfZion/development
jseagrave21 Oct 28, 2018
4df642e
Merge pull request #63 from CityOfZion/development
jseagrave21 Nov 1, 2018
e12e746
Update test_extended_json_rpc_api.py
jseagrave21 Nov 1, 2018
0f55903
Update test_extended_json_rpc_api.py
jseagrave21 Nov 1, 2018
7eb4a1e
Merge pull request #64 from CityOfZion/development
jseagrave21 Nov 8, 2018
1f40685
Merge pull request #66 from CityOfZion/development
jseagrave21 Nov 10, 2018
a046c9a
Update LoadSmartContract.py
jseagrave21 Nov 10, 2018
4ed6d85
Update test_loadsmartcontract.py
jseagrave21 Nov 10, 2018
d799694
Update Send.py
jseagrave21 Nov 10, 2018
dbc4c95
Update test_send_command.py
jseagrave21 Nov 10, 2018
4b1f4d9
Update tests.rst
jseagrave21 Nov 10, 2018
607b952
Update BlockchainFixtureTestCase.py
jseagrave21 Nov 10, 2018
f643281
Update test_rest_api.py
jseagrave21 Nov 10, 2018
ea23070
Update CHANGELOG.rst
jseagrave21 Nov 10, 2018
963aac3
Update Send.py
jseagrave21 Nov 15, 2018
058a7bb
Update LoadSmartContract.py
jseagrave21 Nov 15, 2018
9c8dd0e
Update test_loadsmartcontract.py
jseagrave21 Nov 15, 2018
57964ac
Update CHANGELOG.rst
jseagrave21 Nov 15, 2018
a9b0ddc
Update BlockchainFixtureTestCase.py
jseagrave21 Nov 15, 2018
8f285b7
Update test_rest_api.py
jseagrave21 Nov 15, 2018
4a5cca1
Merge pull request #69 from CityOfZion/development
jseagrave21 Nov 15, 2018
5c86fe5
Update CHANGELOG.rst
jseagrave21 Nov 15, 2018
1f70d67
Update BlockchainFixtureTestCase.py
jseagrave21 Nov 15, 2018
fce2390
Update tests.rst
jseagrave21 Nov 15, 2018
9a6271d
Add files via upload
jseagrave21 Nov 15, 2018
96d6897
Update Contract.py
jseagrave21 Nov 15, 2018
3d378b3
Update LoadSmartContract.py
jseagrave21 Nov 15, 2018
5e768d5
Update test_loadsmartcontract.py
jseagrave21 Nov 15, 2018
52591b2
Merge branch 'development' into parse_and_sign
ixje Nov 15, 2018
1d4fd4f
Add files via upload
jseagrave21 Nov 17, 2018
fa40a6e
Update test_send_command.py
jseagrave21 Nov 17, 2018
0413ef9
Update test_LevelDBBlockchain.py
jseagrave21 Nov 17, 2018
0d6b541
Update test_leveldb.py
jseagrave21 Nov 17, 2018
81f30b2
Update test_claim_command.py
jseagrave21 Nov 17, 2018
8902f52
Update test_smart_contract.py
jseagrave21 Nov 17, 2018
c23c5e9
Update test_json_rpc_api.py
jseagrave21 Nov 17, 2018
3ff848b
Update tests.rst
jseagrave21 Nov 17, 2018
64fc047
Update tests.rst
jseagrave21 Nov 17, 2018
0e18adc
Update tests.rst
jseagrave21 Nov 17, 2018
533cbb0
Add files via upload
jseagrave21 Nov 17, 2018
7f1d0bf
Update test_user_wallet.py
jseagrave21 Nov 17, 2018
96a1e8b
Update tests.rst
jseagrave21 Nov 17, 2018
ec26999
Update CHANGELOG.rst
jseagrave21 Nov 19, 2018
85062ad
Merge pull request #70 from CityOfZion/development
jseagrave21 Nov 19, 2018
afd65c7
Update CHANGELOG.rst
jseagrave21 Nov 19, 2018
ed4357a
Update .travis.yml
jseagrave21 Nov 20, 2018
e847e15
Update .travis.yml
jseagrave21 Nov 20, 2018
26638f9
Update BuildNRun.py
jseagrave21 Nov 20, 2018
2259778
Update CHANGELOG.rst
jseagrave21 Nov 20, 2018
f31f5ad
Merge pull request #72 from CityOfZion/development
jseagrave21 Nov 20, 2018
b1775ab
Update CHANGELOG.rst
jseagrave21 Nov 20, 2018
16f5163
Merge pull request #74 from CityOfZion/development
jseagrave21 Nov 20, 2018
babc950
Update Send.py
jseagrave21 Nov 28, 2018
9d93d2c
Update CHANGELOG.rst
jseagrave21 Nov 28, 2018
f4c526d
Merge pull request #77 from CityOfZion/development
jseagrave21 Nov 28, 2018
4426962
Update CHANGELOG.rst
jseagrave21 Nov 28, 2018
9c9ca9f
Update Send.py
jseagrave21 Nov 28, 2018
478a60f
Update Send.py
jseagrave21 Nov 28, 2018
ff49beb
Merge pull request #81 from CityOfZion/development
jseagrave21 Dec 8, 2018
05ce2e7
Merge pull request #82 from CityOfZion/development
jseagrave21 Dec 11, 2018
19dce4f
Merge pull request #92 from CityOfZion/development
jseagrave21 Jan 10, 2019
08cd57f
Merge pull request #95 from CityOfZion/development
jseagrave21 Jan 11, 2019
928892c
Merge branch 'development' of https://github.com/CityOfZion/neo-pytho…
Jan 19, 2019
54a5200
Merge branch 'CityOfZion-development' into parse_and_sign
Jan 19, 2019
da8cf8d
Add updated test coverage for parse_and_sign
Jan 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:
- pip install -e .
- pip install coveralls
- yes | pip uninstall neo-boa neocore
- pip install -e git+https://github.com/CityOfZion/neo-boa@development#egg=neo-boa
- pip install -e git+https://github.com/jseagrave21/neo-boa@patch-1#egg=neo-boa
- pip install -e git+https://github.com/CityOfZion/neo-python-core@master#egg=neocore

env:
Expand Down
46 changes: 37 additions & 9 deletions docs/source/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ e) Create new wallets only if absolutely necessary.

.. code-block:: sh

docker run --rm -d --name neo-privnet-unittest -p 20333-20336:20333-20336/tcp -p 30333-30336:30333-30336/tcp dautt/neo-privnet-unittest:v0.0.xx``
docker run --rm -d --name neo-privnet-unittest -p 20333-20336:20333-20336/tcp -p 30333-30336:30333-30336/tcp cityofzion/neo-python-privnet-unittest:v0.0.xx

3) Clean the current ``unittest`` chain:

Expand All @@ -97,7 +97,7 @@ e) Create new wallets only if absolutely necessary.

.. code-block:: sh

python prompt.py -u
np-prompt -u

6) Use the following wallets for generating transactions:

Expand Down Expand Up @@ -131,23 +131,51 @@ In that way we can easily find out all the contracts deploy on the image by runn

.. code-block:: sh

docker commit neo-privnet-unittest dautt/neo-privnet-unittest:v0.0.xx+1
docker commit neo-privnet-unittest cityofzion/neo-python-privnet-unittest:v0.0.xx+1

The reason for this is that we need to keep the image as small as possible. It can inadvertently happen that your image has been accumulating new blocks for days or weeks e.g. while working on implementing the new tests in phases, which unnecessarily increases the image size.
Our test fixtures are reset and extracted 20+ times in our build system so any size increase will add a delay * 20 or more.

10) Create the fixtures by incrementing the suffix number (x+1):
10) Stop your current docker container before creating the new fixtures:

.. code-block:: sh

notif_fixtures_vx+1.tar.gz
fixtures_vx+1.tar.gz
docker stop neo-privnet-unittest

11) Update the fixture name in the static class variables in the following files
11) Create the fixtures by incrementing the suffix number (x+1):

**WARNING:** Ensure your fixtures include the following file structure:

- For fixtures_vx+1.tar.gz: ``fixtures/test_chain``

- For notif_fixtures_vx+1.tar.gz: ``fixtures/test_notifications``

.. code-block:: sh

tar -zcvf notif_fixtures_vx+1.tar.gz fixtures
tar -zcvf fixtures_vx+1.tar.gz fixtures

12) Update the fixture name in the static class variables in the following files

.. code-block:: sh

neo.Utils.BlockchainFixtureTestCase.py
neo.api.REST.test_rest_api.py

12) Create a new PR with the link to the new image and the newly created fixtures.
13) Create a new PR with the link to the new image and the newly created fixtures.

14) If you edited any of the fixture wallets, make sure you fully sync your wallet before uploading it to your PR's branch:

- While the neo-privnet-unittest container is stopped, run ``np-prompt -u`` and open all affected fixture wallets

- Check to ensure each wallet is 100% synced before closing

- Update any affected tests

**NOTE:** During ``make test`` or ``python -m unittest discover neo`` you should not see this warning, which indicates one or more fixture wallets is not fully synced:

.. code-block:: sh

[W 181116 16:13:07 Wallet:1063] Wait for your wallet to be synced before doing transactions.
To check enter 'wallet' and look at 'percent_synced', it should be 100.
Also the blockchain should be up to the latest blocks (see Progress).
Issuing 'wallet rebuild' restarts the syncing process.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def leveldb_testpath(cls):

# test need to be updated whenever we change the fixtures
def test_initial_setup(self):
self.assertEqual(self._blockchain.Height, 12349)
self.assertEqual(self._blockchain.Height, 12362)

def test_GetBlockHash(self):
# test requested block height exceeding blockchain current_height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def leveldb_testpath(cls):

# test need to be updated whenever we change the fixtures
def test_a_initial_setup(self):
self.assertEqual(self._blockchain.Height, 12349)
self.assertEqual(self._blockchain.Height, 12362)
2 changes: 1 addition & 1 deletion neo/Implementations/Wallets/peewee/test_user_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_1_initial_setup(self):

self.assertEqual(neo_balance_should_be, neo_balance)

self.assertEqual(wallet.WalletHeight, 12351)
self.assertEqual(wallet.WalletHeight, 12363)

def test_2_transactions(self):

Expand Down
5 changes: 3 additions & 2 deletions neo/Prompt/Commands/BuildNRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def DoRun(contract_script, arguments, wallet, path, verbose=True,
return tx, result, None, None


def TestBuild(script, invoke_args, wallet, plist='05', ret='05', dynamic=False, invoke_attrs=None, owners=None):
def TestBuild(script, invoke_args, wallet, plist='05', ret='05', arguments=[], dynamic=False, invoke_attrs=None, owners=None):
arguments, from_addr = get_from_addr(arguments)
properties = ContractPropertyState.HasStorage

if dynamic:
Expand All @@ -133,4 +134,4 @@ def TestBuild(script, invoke_args, wallet, plist='05', ret='05', dynamic=False,

script = generate_deploy_script(script, contract_properties=int(properties), parameter_list=plist, return_type=BigInteger.FromBytes(ret))

return test_deploy_and_invoke(script, invoke_args, wallet, invoke_attrs=invoke_attrs, owners=owners)
return test_deploy_and_invoke(script, invoke_args, wallet, from_addr=from_addr, invoke_attrs=invoke_attrs, owners=owners)
5 changes: 4 additions & 1 deletion neo/Prompt/Commands/Send.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@ def parse_and_sign(wallet, jsn):

if relayed:
print("Relayed Tx: %s " % tx.Hash.ToString())
return tx
else:
print("Could not relay tx %s " % tx.Hash.ToString())
return
return
else:
print("Transaction initiated, but the signature is incomplete")
print(json.dumps(context.ToJson(), separators=(',', ':')))
Expand All @@ -374,3 +375,5 @@ def parse_and_sign(wallet, jsn):
print("Could not send: %s " % e)
traceback.print_stack()
traceback.print_exc()

return
11 changes: 8 additions & 3 deletions neo/Prompt/Commands/tests/test_claim_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ def test_1_no_available_claim(self):

wallet = self.GetWallet3()

# claim gas
claim_tx, relayed = ClaimGas(wallet, require_password=False)

self.assertTrue(relayed)

unspents = wallet.FindUnspentCoinsByAsset(self.NEO)

self.assertEqual(1, len(unspents))
self.assertEqual(2, len(unspents))

unavailable_bonus = wallet.GetUnavailableBonus()

self.assertEqual(Fixed8.FromDecimal(0.0002685), unavailable_bonus)
self.assertEqual(Fixed8.FromDecimal(0.000008), unavailable_bonus)

unclaimed_coins = wallet.GetUnclaimedCoins()

Expand All @@ -91,7 +96,7 @@ def test_2_wallet_with_claimable_gas(self):

unavailable_bonus = wallet.GetUnavailableBonus()

self.assertEqual(Fixed8.FromDecimal(0.000601), unavailable_bonus)
self.assertEqual(Fixed8.FromDecimal(0.000653), unavailable_bonus)

unclaimed_coins = wallet.GetUnclaimedCoins()

Expand Down
139 changes: 136 additions & 3 deletions neo/Prompt/Commands/tests/test_send_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from neo.Prompt.Commands import Send, Wallet
from neo.Prompt.PromptData import PromptData
import shutil
from mock import patch
from mock import patch, MagicMock
import json
from io import StringIO
from neo.Prompt.PromptPrinter import pp
Expand All @@ -23,6 +23,14 @@ class UserWalletTestCase(WalletFixtureTestCase):
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet1 = None

wallet_2_addr = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet2 = None

wallet_3_addr = 'AZiE7xfyJALW7KmADWtCJXGGcnduYhGiCX'
_wallet3 = None

wallet_2_and_3_multisig_addr = "Aau2M4UdXxwxLLizDw11eDZRDs5jpXduh8"

@classmethod
def GetWallet1(cls, recreate=False):
if cls._wallet1 is None or recreate:
Expand All @@ -31,6 +39,22 @@ def GetWallet1(cls, recreate=False):
to_aes_key(UserWalletTestCase.wallet_1_pass()))
return cls._wallet1

@classmethod
def GetWallet2(cls, recreate=False):
if cls._wallet2 is None or recreate:
shutil.copyfile(cls.wallet_2_path(), cls.wallet_2_dest())
cls._wallet2 = UserWallet.Open(UserWalletTestCase.wallet_2_dest(),
to_aes_key(UserWalletTestCase.wallet_2_pass()))
return cls._wallet2

@classmethod
def GetWallet3(cls, recreate=False):
if cls._wallet3 is None or recreate:
shutil.copyfile(cls.wallet_3_path(), cls.wallet_3_dest())
cls._wallet3 = UserWallet.Open(UserWalletTestCase.wallet_3_dest(),
to_aes_key(UserWalletTestCase.wallet_3_pass()))
return cls._wallet3

@classmethod
def tearDown(cls):
PromptData.Wallet = None
Expand All @@ -39,7 +63,7 @@ def test_send_neo(self):
with patch('sys.stdout', new=StringIO()) as mock_print:
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]):
PromptData.Wallet = self.GetWallet1(recreate=True)
args = ['send', 'neo', self.watch_addr_str, '50']
args = ['send', 'neo', self.watch_addr_str, '1']

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

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

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

Expand Down Expand Up @@ -546,3 +570,112 @@ def test_sendmany_keyboard_interrupt(self):

self.assertFalse(res)
self.assertIn("Transaction cancelled", mock_print.getvalue())

def test_parse_and_sign_good(self):
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
# start the tx from wallet2
PromptData.Wallet = self.GetWallet2(recreate=True)
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]

Wallet.CommandWallet().execute(args)

# now sign the tx with wallet3
PromptData.Wallet = self.GetWallet3(recreate=True)
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
args = ['sign', jsn]

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

res = res.ToJson()
self.assertTrue(res)
self.assertEqual(res['vout'][0]['value'], "1") # verify the amount
self.assertEqual(res['vout'][0]['address'], self.wallet_1_addr) # verify to_address
self.assertEqual(res['vout'][1]['address'], self.wallet_2_and_3_multisig_addr) # verify from_address

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

Wallet.CommandWallet().execute(args)

# now sign the tx with wallet3
PromptData.Wallet = self.GetWallet3(recreate=True)
jsn = 'blah'
args = ['sign', jsn]

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

self.assertFalse(res)
self.assertIn("Failed to parse JSON", mock_print.getvalue())

def test_parse_and_sign_fails_to_relay(self):
with patch('sys.stdout', new=StringIO()) as mock_print:
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
with patch('neo.Prompt.Commands.Send.NodeLeader.Relay', return_value=False):
# start the tx from wallet2
PromptData.Wallet = self.GetWallet2(recreate=True)
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]

Wallet.CommandWallet().execute(args)

# now sign the tx with wallet3
PromptData.Wallet = self.GetWallet3(recreate=True)
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
args = ['sign', jsn]

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

self.assertFalse(res)
self.assertIn("Could not relay tx", mock_print.getvalue())

def test_parse_and_sign_twice(self): # this test implies there are more signatures needed
with patch('sys.stdout', new=StringIO()) as mock_print:
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
# start the tx from wallet2
PromptData.Wallet = self.GetWallet2(recreate=True)
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]

Wallet.CommandWallet().execute(args)

# now sign the tx with wallet2 again
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
args = ['sign', jsn]

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

self.assertFalse(res)
self.assertIn("Transaction initiated, but the signature is incomplete", mock_print.getvalue())

def test_parse_and_sign_exception(self):
with patch('sys.stdout', new=StringIO()) as mock_print:
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
with patch('neo.Prompt.Commands.Send.traceback'): # mocking traceback module to avoid stacktrace printing during test run
# start the tx from wallet2
PromptData.Wallet = self.GetWallet2(recreate=True)
args = ['send', 'neo', self.wallet_1_addr, '1', '--from-addr=' + self.wallet_2_and_3_multisig_addr]

Wallet.CommandWallet().execute(args)

# mocking wallet to trigger the exception
PromptData.Wallet = MagicMock()
PromptData.Wallet.Sign.side_effect = Exception
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"800000014405fd5ae29ceeb20912776048c544109c8c67c4128c019863eca58cf677ad360000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000d1c4904014bfe7d34e9e97370f2cd3a633377cd6","items":{"0xd67c3733a6d32c0f37979e4ed3e7bf144090c4d1":{"script":"522103989f7417da540a8ce00195738249291cba058102a12d2df1b00e2a826d8bd0612103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e9603452ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"b5b32d6b56f3729747380072c722c50b0ee91e930f58a58d49c98c5543e335b70f6a400c8e1f9fa9653f7605ad229974cacfac3143cd355ca900c328b3db6018"}}}}'
args = ['sign', jsn]

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

self.assertFalse(res)
self.assertIn("Could not send:", mock_print.getvalue())

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

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

self.assertFalse(res)
self.assertIn("Please specify the required parameter", mock_print.getvalue())
6 changes: 3 additions & 3 deletions neo/SmartContract/Contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ def Create(redeemScript, parameterList, publicKeyHash):
def CreateMultiSigRedeemScript(m, publicKeys):

if m < 1:
raise Exception("Minimum required signature count is 1, specified {}.".format(m))
raise ValueError("Minimum required signature count is 1, specified {}.".format(m))

if m > len(publicKeys):
raise Exception("Invalid public key count. Minimum required signatures is bigger than supplied public keys count.")
raise ValueError("Invalid public key count. Minimum required signatures is bigger than supplied public keys count.")

if len(publicKeys) > 1024:
raise Exception("Supplied public key count ({}) exceeds maximum of 1024.".format(len(publicKeys)))
raise ValueError("Supplied public key count ({}) exceeds maximum of 1024.".format(len(publicKeys)))

sb = ScriptBuilder()
sb.push(m)
Expand Down
Loading