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

Commit

Permalink
Merge pull request #22 from CityOfZion/development
Browse files Browse the repository at this point in the history
Merge CoZ Development into jseagrave21 development
  • Loading branch information
jseagrave21 committed Sep 22, 2018
2 parents 0de31ac + ccf789d commit 59599b8
Show file tree
Hide file tree
Showing 35 changed files with 342 additions and 463 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project are documented in this file.
- Update seed list to include NGD nodes
- Fix unhandled deferred errors
- Fix ``Blockchain.DeregisterBlockchain`` not clearing all static variables
- Migrate the existing test cases, which depend on BlockchainFixtureTestCase and WalletFixtureTestCase, to a privnet. Reduction of the fixtures' size to about 7MB. `#478 <https://github.com/CityOfZion/neo-python/issues/478>`_

[0.7.8] 2018-09-06
------------------
Expand Down
Binary file added fixtures/neo-test-coz.wallet
Binary file not shown.
Binary file added fixtures/neo-test1-bc.wallet
Binary file not shown.
Binary file added fixtures/neo-test1-w.wallet
Binary file not shown.
Binary file added fixtures/neo-test2-bc.wallet
Binary file not shown.
Binary file added fixtures/neo-test2-w.wallet
Binary file not shown.
Binary file added fixtures/neo-test3-w.wallet
Binary file not shown.
Binary file modified fixtures/testwallet.db3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class LevelDBBlockchainTest(BlockchainFixtureTestCase):
def leveldb_testpath(self):
return os.path.join(settings.DATA_DIR_PATH, 'fixtures/test_chain')

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

def test_02_GetBlockHash(self):
# test requested block height exceeding blockchain current_height
result = self._blockchain.GetBlockHash(800000)
invalid_bc_height = self._blockchain.Height + 1
result = self._blockchain.GetBlockHash(invalid_bc_height)
self.assertEqual(result, None)

# test header index length mismatch
Expand All @@ -34,5 +36,6 @@ def test_03_GetBlockByHeight(self):
self.assertEqual(block.GetHashCode().ToString(), self._blockchain.GetBlockHash(100).decode('utf-8'))

# and also a invalid retrieval
block = self._blockchain.GetBlockByHeight(800000)
invalid_bc_height = self._blockchain.Height + 1
block = self._blockchain.GetBlockByHeight(invalid_bc_height)
self.assertEqual(block, None)
19 changes: 11 additions & 8 deletions neo/Implementations/Blockchains/LevelDB/tests/test_initial_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class LevelDBTest(NeoTestCase):

@classmethod
def setUpClass(self):
settings.setup_unittest_net()
Blockchain.DeregisterBlockchain()
self._blockchain = LevelDBBlockchain(path=self.LEVELDB_TESTPATH, skip_version_check=True)
Blockchain.RegisterBlockchain(self._blockchain)
self._genesis = Blockchain.GenesisBlock()
Expand All @@ -43,17 +45,18 @@ def test__initial_state(self):
self.assertEqual(self._blockchain.Height, 0)

def test_add_header(self):
hexdata = binascii.unhexlify(self.block_one_raw)
block_one = Helper.AsSerializableWithType(hexdata, 'neo.Core.Block.Block')

hexdata = binascii.unhexlify(self.block_one_raw)
if settings.MAGIC == 56753:
self.assertEqual(self._blockchain.CurrentHeaderHash, b'996e37358dc369912041f966f8c5d8d3a8255ba5dcbd3447f8a82b55db869099')
else:
self.assertEqual(self._blockchain.CurrentHeaderHash, b'd42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf')

block_one = Helper.AsSerializableWithType(hexdata, 'neo.Core.Block.Block')
self.assertEqual(self._blockchain.HeaderHeight, 0)

if settings.MAGIC == 1953787457:
self.assertEqual(self._blockchain.CurrentHeaderHash, b'b3181718ef6167105b70920e4a8fbbd0a0a56aacf460d70e10ba6fa1668f1fef')
else:
self.assertEqual(self._blockchain.CurrentHeaderHash, b'd42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf')

self.assertEqual(self._blockchain.HeaderHeight, 0)
self._blockchain.AddBlock(block_one)
self.assertEqual(self._blockchain.HeaderHeight, 1)

def test_sys_block_fees(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class LevelDBTest(BlockchainFixtureTestCase):
def leveldb_testpath(self):
return os.path.join(settings.DATA_DIR_PATH, 'fixtures/test_chain')

# test need to be updated whenever we change the fixtures
def test_a_initial_setup(self):
self.assertEqual(self._blockchain.Height, 758986)
self.assertEqual(self._blockchain.Height, 12349)
8 changes: 4 additions & 4 deletions neo/Implementations/Wallets/peewee/test_create_user_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class UserWalletTestCase(WalletFixtureTestCase):

wallet_1_script_hash = UInt160(data=b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
wallet_1_script_hash = UInt160(data=b'\x1c\xc9\xc0\\\xef\xff\xe6\xcd\xd7\xb1\x82\x81j\x91R\xec!\x8d.\xc0')

wallet_1_addr = 'APRgMZHZubii29UXF9uFa6sohrsYupNAvx'
wallet_1_addr = 'AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3'

import_watch_addr = UInt160(data=b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5')
watch_addr_str = 'AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK'
import_watch_addr = UInt160(data=b'\x08t/\\P5\xac-\x0b\x1c\xb4\x94tIyBu\x7f1*')
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet1 = None

@property
Expand Down
28 changes: 15 additions & 13 deletions neo/Implementations/Wallets/peewee/test_user_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

class UserWalletTestCase(WalletFixtureTestCase):

wallet_1_script_hash = UInt160(data=b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
wallet_1_script_hash = UInt160(data=b'\x1c\xc9\xc0\\\xef\xff\xe6\xcd\xd7\xb1\x82\x81j\x91R\xec!\x8d.\xc0')

wallet_1_addr = 'APRgMZHZubii29UXF9uFa6sohrsYupNAvx'
wallet_1_addr = 'AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3'

import_watch_addr = UInt160(data=b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5')
watch_addr_str = 'AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK'
import_watch_addr = UInt160(data=b'\x08t/\\P5\xac-\x0b\x1c\xb4\x94tIyBu\x7f1*')
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet1 = None

@property
Expand Down Expand Up @@ -52,25 +52,27 @@ def test_1_initial_setup(self):

self.assertEqual(self.wallet_1_addr, addr['script_hash'])

balance_should_be = Fixed8.FromDecimal(100)
gas_balance_should_be = Fixed8.FromDecimal(13.9998)

gas_balance = wallet.GetBalance(self.GAS)

self.assertEqual(balance_should_be, gas_balance)
self.assertEqual(gas_balance_should_be, gas_balance)

neo_balance_should_be = Fixed8.FromDecimal(50)

neo_balance = wallet.GetBalance(self.NEO)

self.assertEqual(balance_should_be, neo_balance)
self.assertEqual(neo_balance_should_be, neo_balance)

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

def test_2_transactions(self):

wallet = self.GetWallet1()

transactions = wallet.GetTransactions()

self.assertEqual(2, len(transactions))
self.assertEqual(9, len(transactions))

def test_3_import_watch_addr(self):

Expand Down Expand Up @@ -118,7 +120,7 @@ def test_5_export_wif(self):

wif = key.Export()

self.assertEqual(wif, 'KzV2riT1Vqoi5th1uiCTN5adEtJwXevFxf7Nygant1sBaRfncmbz')
self.assertEqual(wif, 'Ky94Rq8rb1z8UzTthYmy1ApbZa9xsKTvQCiuGUZJZbaDJZdkvLRV')

def test_6_import_wif(self):

Expand All @@ -137,15 +139,15 @@ def test_7_import_token(self):

wallet = self.GetWallet1()

token_hash = b'f8d448b227991cf07cb96a6f9c0322437f1599b9'
token_hash = b'31730cc9a1844891a3bafd1aa929a4142860d8d3'
contract = Blockchain.Default().GetContract(token_hash)

token = NEP5Token(binascii.hexlify(contract.Code.Script))
token.Query()

self.assertEqual(token.name, 'NEP5 Standard')
self.assertEqual(token.name, 'NEX Template V4')
self.assertEqual(token.decimals, 8)
self.assertEqual(token.symbol, 'NEP5')
self.assertEqual(token.symbol, 'NXT4')

wallet.AddNEP5Token(token)

Expand Down
8 changes: 4 additions & 4 deletions neo/Network/test_node_leader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def __init__(self, host, port):

class LeaderTestCase(WalletFixtureTestCase):

wallet_1_script_hash = UInt160(data=b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
wallet_1_script_hash = UInt160(data=b'\x1c\xc9\xc0\\\xef\xff\xe6\xcd\xd7\xb1\x82\x81j\x91R\xec!\x8d.\xc0')

wallet_1_addr = 'APRgMZHZubii29UXF9uFa6sohrsYupNAvx'
wallet_1_addr = 'AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3'

import_watch_addr = UInt160(data=b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5')
watch_addr_str = 'AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK'
import_watch_addr = UInt160(data=b'\x08t/\\P5\xac-\x0b\x1c\xb4\x94tIyBu\x7f1*')
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet1 = None

@classmethod
Expand Down
60 changes: 37 additions & 23 deletions neo/Prompt/Commands/tests/test_claim_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@


class UserWalletTestCase(WalletFixtureTestCase):
wallet_1_script_hash = UInt160(data=b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
wallet_1_script_hash = UInt160(data=b'\x1c\xc9\xc0\\\xef\xff\xe6\xcd\xd7\xb1\x82\x81j\x91R\xec!\x8d.\xc0')

wallet_1_addr = 'APRgMZHZubii29UXF9uFa6sohrsYupNAvx'
wallet_1_addr = 'AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3'

wallet_3_script_hash = UInt160(data=b'\xa6\xc5\x9d\xeb\xf0\xd7(\xbd\x14\x89\xcd\xb9\xd9{\xd1\x90\xcb\x0b\xdch')
wallet_2_script_hash = UInt160(data=b'\x08t/\\P5\xac-\x0b\x1c\xb4\x94tIyBu\x7f1*')

wallet_3_addr = 'AWygZ1B5c3GDiLL6u5bHSVU45Ya1SVGX9P'
wallet_2_addr = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'

wallet_3_script_hash = UInt160(data=b'\xc4\xc1\xb0\xcf\xa8\x7f\xcb\xacE\x98W0\x16d\x11\x03]\xdf\xed#')

wallet_3_addr = 'AZiE7xfyJALW7KmADWtCJXGGcnduYhGiCX'

_wallet1 = None

_wallet2 = None

_wallet3 = None

@property
Expand All @@ -37,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

@classmethod
def GetWallet3(cls, recreate=False):
if cls._wallet3 is None or recreate:
Expand All @@ -47,15 +61,15 @@ def GetWallet3(cls, recreate=False):

def test_1_no_available_claim(self):

wallet = self.GetWallet1()
wallet = self.GetWallet3()

unspents = wallet.FindUnspentCoinsByAsset(self.NEO)

self.assertEqual(1, len(unspents))

unavailable_bonus = wallet.GetUnavailableBonus()

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

unclaimed_coins = wallet.GetUnclaimedCoins()

Expand All @@ -67,62 +81,62 @@ def test_1_no_available_claim(self):

def test_2_wallet_with_claimable_gas(self):

wallet = self.GetWallet3()
wallet = self.GetWallet1()

unspents = wallet.FindUnspentCoinsByAsset(self.NEO)

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

unavailable_bonus = wallet.GetUnavailableBonus()

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

unclaimed_coins = wallet.GetUnclaimedCoins()

self.assertEqual(4, len(unclaimed_coins))
self.assertEqual(1, len(unclaimed_coins))

available_bonus = wallet.GetAvailableClaimTotal()

self.assertEqual(Fixed8.FromDecimal(0.0048411), available_bonus)
self.assertEqual(Fixed8.FromDecimal(0.000288), available_bonus)

def test_3_wallet_no_claimable_gas(self):

wallet = self.GetWallet1()
wallet = self.GetWallet3()

result = ClaimGas(wallet, require_password=False)

self.assertFalse(result)

def test_4_wallet_claim_ok(self):

wallet = self.GetWallet3()
wallet = self.GetWallet1()

claim = ClaimGas(wallet, require_password=False, args=['1'])

self.assertTrue(claim)

def test_5_wallet_claim_ok(self):

wallet = self.GetWallet3()
wallet = self.GetWallet2()

claim = ClaimGas(wallet, require_password=False)

self.assertTrue(claim)

def test_block_150000_sysfee(self):
def test_block_12248_sysfee(self):

fee = Blockchain.Default().GetSysFeeAmountByHeight(150000)
fee = Blockchain.Default().GetSysFeeAmountByHeight(12248)

self.assertEqual(fee, 1230)
self.assertEqual(fee, 2050)

def test_block_347809_sysfee(self):
def test_block_12323_sysfee(self):

fee = Blockchain.Default().GetSysFeeAmountByHeight(347809)
fee = Blockchain.Default().GetSysFeeAmountByHeight(12323)

self.assertEqual(fee, 39134)
self.assertEqual(fee, 2540)

def test_block_747809_sysfee(self):
def test_block_11351_sysfee(self):

fee = Blockchain.Default().GetSysFeeAmountByHeight(747809)
fee = Blockchain.Default().GetSysFeeAmountByHeight(11351)

self.assertEqual(fee, 472954)
self.assertEqual(fee, 1560)
16 changes: 8 additions & 8 deletions neo/Prompt/Commands/tests/test_send_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

class UserWalletTestCase(WalletFixtureTestCase):

wallet_1_script_hash = UInt160(data=b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
wallet_1_script_hash = UInt160(data=b'\x1c\xc9\xc0\\\xef\xff\xe6\xcd\xd7\xb1\x82\x81j\x91R\xec!\x8d.\xc0')

wallet_1_addr = 'APRgMZHZubii29UXF9uFa6sohrsYupNAvx'
wallet_1_addr = 'AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3'

import_watch_addr = UInt160(data=b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5')
watch_addr_str = 'AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK'
import_watch_addr = UInt160(data=b'\x08t/\\P5\xac-\x0b\x1c\xb4\x94tIyBu\x7f1*')
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
_wallet1 = None

@property
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_2_send_gas(self):

wallet = self.GetWallet1(recreate=True)

args = ['gas', self.watch_addr_str, '50']
args = ['gas', self.watch_addr_str, '5']

res = construct_and_send(None, wallet, args, prompt_password=False)

Expand All @@ -62,7 +62,7 @@ def test_3_insufficient_funds(self):

wallet = self.GetWallet1(recreate=True)

args = ['gas', self.watch_addr_str, '101']
args = ['gas', self.watch_addr_str, '72620']

res = construct_and_send(None, wallet, args, prompt_password=False)

Expand Down Expand Up @@ -116,11 +116,11 @@ def test_8_send_token_ok(self):

wallet = self.GetWallet1(recreate=True)

token_hash = 'f8d448b227991cf07cb96a6f9c0322437f1599b9'
token_hash = '31730cc9a1844891a3bafd1aa929a4142860d8d3'

ImportToken(wallet, token_hash)

args = ['NEP5', self.watch_addr_str, '32', '--from-addr=%s' % self.wallet_1_addr]
args = ['NXT4', self.watch_addr_str, '32', '--from-addr=%s' % self.wallet_1_addr]

res = construct_and_send(None, wallet, args, prompt_password=False)

Expand Down
Loading

0 comments on commit 59599b8

Please sign in to comment.