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 36 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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project are documented in this file.
- Fix RPC's ``getaccountstate`` response schema to match ``neo-cli`` `#714 <https://github.com/CityOfZion/neo-python/issues/714>`
- Add fix to ensure tx is saved to wallet when sent using RPC
- Add bad peers to the ``getpeers`` RPC method `#715 <https://github.com/CityOfZion/neo-python/pull/715>`
- Improve ``parse_and_sign`` and ``ImportMultiSigContractAddr`` and add tests


[0.8.2] 2018-10-31
Expand Down
10 changes: 5 additions & 5 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,7 +131,7 @@ 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.
Expand All @@ -140,8 +140,8 @@ Our test fixtures are reset and extracted 20+ times in our build system so any s

.. code-block:: sh

notif_fixtures_vx+1.tar.gz
fixtures_vx+1.tar.gz
tar -zcvf notif_fixtures_vx+1.tar.gz unittest_notif
tar -zcvf fixtures_vx+1.tar.gz unittest

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

Expand Down
20 changes: 9 additions & 11 deletions neo/Prompt/Commands/LoadSmartContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,14 @@ def ImportMultiSigContractAddr(wallet, args):
m = get_arg(args, 1)
publicKeys = args[2:]

if publicKeys[1]:
pubkey_script_hash = Crypto.ToScriptHash(pubkey, unhex=True)

verification_contract = Contract.CreateMultiSigContract(pubkey_script_hash, int(m), publicKeys)

address = verification_contract.Address

wallet.AddContract(verification_contract)
if int(m) != len(publicKeys):
print("the minimum # of signatures required must equal the number of signing pubkeys")
return

print("Added multi-sig contract address %s to wallet" % address)
return address
pubkey_script_hash = Crypto.ToScriptHash(pubkey, unhex=True)
ixje marked this conversation as resolved.
Show resolved Hide resolved
verification_contract = Contract.CreateMultiSigContract(pubkey_script_hash, int(m), publicKeys)
address = verification_contract.Address
wallet.AddContract(verification_contract)

return 'Hello'
print("Added multi-sig contract address %s to wallet" % address)
return address
5 changes: 4 additions & 1 deletion neo/Prompt/Commands/Send.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,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 @@ -262,3 +263,5 @@ def parse_and_sign(wallet, jsn):
print("could not send: %s " % e)
traceback.print_stack()
traceback.print_exc()

return
77 changes: 74 additions & 3 deletions neo/Prompt/Commands/tests/test_loadsmartcontract.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
from unittest import TestCase
from neo.Prompt.Commands.LoadSmartContract import LoadContract, GatherLoadedContractParams
from neo.Utils.WalletFixtureTestCase import WalletFixtureTestCase
from neo.Wallets.utils import to_aes_key
from neo.Implementations.Wallets.peewee.UserWallet import UserWallet
import shutil
from neo.Prompt.Commands.LoadSmartContract import LoadContract, GatherLoadedContractParams, ImportMultiSigContractAddr
import mock


class LoadSmartContractTestCase(TestCase):
class LoadSmartContractTestCase(WalletFixtureTestCase):

wallet_1_addr = "AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3"
wallet_1_pk = "03cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c6"

_wallet1 = None

wallet_2_pk = "03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034"

@classmethod
def GetWallet1(cls, recreate=False):
if cls._wallet1 is None or recreate:
shutil.copyfile(cls.wallet_1_path(), cls.wallet_1_dest())
cls._wallet1 = UserWallet.Open(LoadSmartContractTestCase.wallet_1_dest(),
to_aes_key(LoadSmartContractTestCase.wallet_1_pass()))
return cls._wallet1

def test_loadcontract(self):

Expand Down Expand Up @@ -97,3 +115,56 @@ def test_gatherloadedcontractparams(self):
res = GatherLoadedContractParams(args, script)

self.assertTrue(res)

def test_importmultisigcontractaddr(self):

# good test
wallet = self.GetWallet1(recreate=True)
args = [self.wallet_1_pk, 2, self.wallet_1_pk, self.wallet_2_pk]

address = ImportMultiSigContractAddr(wallet, args)

self.assertEqual(address[0], "A")
self.assertEqual(len(address), 34)

# test too few args
wallet = self.GetWallet1()
args = [self.wallet_1_pk, 2, self.wallet_1_pk] # need at least four args

res = ImportMultiSigContractAddr(wallet, args)

self.assertFalse(res)

# test no wallet
wallet = None
args = [self.wallet_1_pk, 2, self.wallet_1_pk, self.wallet_2_pk]

res = ImportMultiSigContractAddr(wallet, args)

self.assertFalse(res)

# test bad first pk
with self.assertRaises(Exception) as e:
wallet = self.GetWallet1(recreate=True)
args = [self.wallet_2_pk, 2, self.wallet_1_pk, self.wallet_2_pk] # first pk needs to be from wallet

ImportMultiSigContractAddr(wallet, args)

self.assertTrue("Invalid operation - public key mismatch" in str(e.exception))

# test bad second pk
with self.assertRaises(Exception) as e:
wallet = self.GetWallet1(recreate=True)
args = [self.wallet_1_pk, 2, "03cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c", self.wallet_2_pk] # pk is too short

ImportMultiSigContractAddr(wallet, args)

self.assertTrue("Odd-length string" in str(e.exception))

# test minimum # of signatures required != len(publicKeys)
wallet = self.GetWallet1(recreate=True)
args = [self.wallet_1_pk, 2, self.wallet_1_pk, self.wallet_2_pk, self.wallet_2_pk]

res = ImportMultiSigContractAddr(wallet, args)

self.assertFalse(res)
105 changes: 104 additions & 1 deletion neo/Prompt/Commands/tests/test_send_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from neo.Implementations.Wallets.peewee.UserWallet import UserWallet
from neo.Core.Blockchain import Blockchain
from neocore.UInt160 import UInt160
from neo.Prompt.Commands.Send import construct_send_basic, construct_send_many, process_transaction
from neo.Prompt.Commands.Send import construct_send_basic, construct_send_many, process_transaction, parse_and_sign
from neo.Prompt.Commands.Wallet import ImportToken
from neo.Prompt.Utils import get_tx_attr_from_args
from neo.Prompt.Commands import Send
Expand All @@ -23,6 +23,10 @@ class UserWalletTestCase(WalletFixtureTestCase):
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet1 = None

_wallet2 = None

wallet_1_and_2_multisig_addr = "AY7cn9RRanTWtDTZ5AgcxoYMGBMcuqFZw5"

@property
def GAS(self):
return Blockchain.Default().SystemCoin().Hash
Expand All @@ -39,6 +43,14 @@ 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

def test_send_neo(self):
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]):
wallet = self.GetWallet1(recreate=True)
Expand Down Expand Up @@ -501,3 +513,94 @@ def test_sendmany_negative_fee(self):
framework = construct_send_many(wallet, args)

self.assertFalse(framework)

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
wallet2 = self.GetWallet2(recreate=True)
args = ['neo', self.wallet_1_addr, '1', '--from-addr=AY7cn9RRanTWtDTZ5AgcxoYMGBMcuqFZw5']

framework = construct_send_basic(wallet2, args)
process_transaction(wallet2, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4])

# now sign the tx with wallet1
wallet1 = self.GetWallet1(recreate=True)
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'

res = parse_and_sign(wallet1, jsn)

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

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

framework = construct_send_basic(wallet2, args)
process_transaction(wallet2, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4])

# now sign the tx with wallet1
wallet1 = self.GetWallet1(recreate=True)
jsn = 'blah'

res = parse_and_sign(wallet1, jsn)

self.assertFalse(res)

def test_parse_and_sign_fails_to_relay(self):
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
wallet2 = self.GetWallet2(recreate=True)
args = ['neo', self.wallet_1_addr, '1', '--from-addr=AY7cn9RRanTWtDTZ5AgcxoYMGBMcuqFZw5']

framework = construct_send_basic(wallet2, args)
process_transaction(wallet2, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4])

# now sign the tx with wallet1
wallet1 = self.GetWallet1(recreate=True)
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'

res = parse_and_sign(wallet1, jsn)

self.assertFalse(res)

def test_parse_and_sign_twice(self): # this test implies there are more signatures needed
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_2_pass()]):
# start the tx from wallet2
wallet2 = self.GetWallet2(recreate=True)
args = ['neo', self.wallet_1_addr, '1', '--from-addr=AY7cn9RRanTWtDTZ5AgcxoYMGBMcuqFZw5']

framework = construct_send_basic(wallet2, args)
process_transaction(wallet2, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4])

# now sign the tx with wallet2 again
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'

res = parse_and_sign(wallet2, jsn)

self.assertFalse(res)

def test_parse_and_sign_exception(self):
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
wallet2 = self.GetWallet2(recreate=True)
args = ['neo', self.wallet_1_addr, '1', '--from-addr=AY7cn9RRanTWtDTZ5AgcxoYMGBMcuqFZw5']

framework = construct_send_basic(wallet2, args)
process_transaction(wallet2, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4])

# mocking wallet to trigger the exception
wallet1 = MagicMock()
wallet1.Sign.side_effect = Exception
jsn = '{"type":"Neo.Core.ContractTransaction","hex":"8000000172da341d6ad36544d49d3387c5ae4485bc238fe1ee8fb6d0a179be7dfc7105160000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000001cc9c05cefffe6cdd7b182816a9152ec218d2ec09b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50084d71700000000b33deba441ce0ae39338575f6c6f7cb958e14007","items":{"0x0740e158b97c6f6c5f573893e30ace41a4eb3db3":{"script":"522103c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e960342103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c652ae","parameters":[{"type":"Signature"},{"type":"Signature"}],"signatures":{"03c46aec8d1ac8cb58fe74764de223d15e7045de67a51d1a4bcecd396918e96034":"0a377e3a9c302f270f3eaf083119fbc60a17f7858975b6aa2c226be10626c50e47a5705fd079da9cc55c6c467015345c230ca13fed8d93555c7024f8663efe6c"}}}}'

res = parse_and_sign(wallet1, jsn)

self.assertFalse(res)
8 changes: 4 additions & 4 deletions neo/Utils/BlockchainFixtureTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@


class BlockchainFixtureTestCase(NeoTestCase):
FIXTURE_REMOTE_LOC = 'https://s3.us-east-2.amazonaws.com/cityofzion/fixtures/fixtures_v8.tar.gz'
FIXTURE_FILENAME = os.path.join(settings.DATA_DIR_PATH, 'Chains/fixtures_v8.tar.gz')
FIXTURE_REMOTE_LOC = 'https://s3.us-east-2.amazonaws.com/cityofzion/fixtures/fixtures_v9.tar.gz'
FIXTURE_FILENAME = os.path.join(settings.DATA_DIR_PATH, 'Chains/fixtures_v9.tar.gz')

N_FIXTURE_REMOTE_LOC = 'https://s3.us-east-2.amazonaws.com/cityofzion/fixtures/notif_fixtures_v8.tar.gz'
N_FIXTURE_FILENAME = os.path.join(settings.DATA_DIR_PATH, 'Chains/notif_fixtures_v8.tar.gz')
N_FIXTURE_REMOTE_LOC = 'https://s3.us-east-2.amazonaws.com/cityofzion/fixtures/notif_fixtures_v9.tar.gz'
N_FIXTURE_FILENAME = os.path.join(settings.DATA_DIR_PATH, 'Chains/notif_fixtures_v9.tar.gz')
N_NOTIFICATION_DB_NAME = os.path.join(settings.DATA_DIR_PATH, 'fixtures/test_notifications')

_blockchain = None
Expand Down