Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -8,6 +8,7 @@ All notable changes to this project are documented in this file.
- Allow override of test invocation return type
- Add current wallet height to bottom toolbar
- Change class attributes of ``Transaction`` into instance attributes and fix constructor
- Fix sys_fee calculation in block persist.
- Improve testing of "getbalance" RPC method
- Support cancelling actions with ``KeyboardInterrupt``
- Enhance output of `wallet` cli command
Expand Down
6 changes: 3 additions & 3 deletions neo/Core/State/StateDescriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class StateDescriptor(SerializableMixin):

@property
def SystemFee(self):
if self.Type == StateType.Account:
return Fixed8.Zero()
elif self.Type == StateType.Validator:
if self.Type == StateType.Validator:
return self.GetSystemFee_Validator()
else:
return Fixed8.Zero()

def Size(self):
"""
Expand Down
9 changes: 0 additions & 9 deletions neo/Core/TX/StateTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ def __init__(self, *args, **kwargs):

self.Type = TransactionType.StateTransaction

def NetworkFee(self):
"""
Get the network fee for a claim transaction.

Returns:
Fixed8: currently fixed to 0.
"""
return Fixed8(0)

def SystemFee(self):
amount = Fixed8.Zero()
for d in self.Descriptors:
Expand Down
10 changes: 5 additions & 5 deletions neo/Core/TX/Transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __init__(self, inputs=None, outputs=None, attributes=None, scripts=None):
self.Attributes = [] if attributes is None else attributes
self.scripts = [] if scripts is None else scripts
self.InventoryType = 0x01 # InventoryType TX 0x01
self.__references = None
self._references = None
self.Type = None
self.raw_tx = False
self.withdraw_hold = None
Expand Down Expand Up @@ -297,7 +297,7 @@ def getAllInputs(self):

def ResetReferences(self):
"""Reset local stored references."""
self.__references = None
self._references = None

def ResetHashData(self):
"""Reset local stored hash data."""
Expand All @@ -323,7 +323,7 @@ def References(self):
Key (UInt256): input PrevHash
Value (TransactionOutput): object.
"""
if self.__references is None:
if self._references is None:

refs = {}

Expand All @@ -335,9 +335,9 @@ def References(self):
for input in group:
refs[input] = tx.outputs[input.PrevIndex]

self.__references = refs
self._references = refs

return self.__references
return self._references

def Size(self):
"""
Expand Down
13 changes: 11 additions & 2 deletions neo/Core/TX/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_issue_tx(self):
self.assertEqual(json['sys_fee'], "0")
self.assertEqual(json['net_fee'], "0")
self.assertEqual(json['scripts'][0]['invocation'], "")
self.assertEqual(json['scripts'][0]['verification'], "51")
self.assertEqual(json['scripts'][0]['verification'], "51")

cr = b'800001f012e99481e4bb93e59088e7baa6e6b58be8af9502f8e0bc69b6af579e69a56d3d3d559759cdb848cb55b54531afc6e3322c85badf08002c82c09c5b49d10cd776c8679789ba98d0b0236f0db4dc67695a1eb920a646b9000001cd5e195b9235a31b7423af5e6937a660f7e7e62524710110b847bab41721090c0061c2540cd1220067f97110a66136d38badc7b9f88eab013027ce490241400bd2e921cee90c8de1a192e61e33eb8980a3dc00c388ee9aac0712178cc8fceed8bb59788f7caf3c4dc082abcdaaa49772fda86db4ceea243bda31bcde9b8a0b3c21034b44ed9c8a88fb2497b6b57206cc08edd42c5614bd1fee790e5b795dee0f4e1104182f145967cc4ee2f1c9f4e0782756dabf246d0a4fe60a035441402fe3e20c303e26c3817fed6fc7db8edde4ac62b16eee796c01c2b59e382b7ddfc82f0b36c7f7520821c7b72b9aff50ae27a016961f1ef1dade9cafa85655380f2321034b44ed9c8a88fb2497b6b57206cc08edd42c5614bd1fee790e5b795dee0f4e11ac'
cr2 = b'800001f012e99481e4bb93e59088e7baa6e6b58be8af9502f8e0bc69b6af579e69a56d3d3d559759cdb848cb55b54531afc6e3322c85badf08002c82c09c5b49d10cd776c8679789ba98d0b0236f0db4dc67695a1eb920a646b9000001cd5e195b9235a31b7423af5e6937a660f7e7e62524710110b847bab41721090c0061c2540cd1220067f97110a66136d38badc7b9f88eab013027ce49'
Expand Down Expand Up @@ -275,10 +275,19 @@ def test_state_tx(self):

reader = BinaryReader(ms)
tx = Transaction.DeserializeFrom(reader)

# the net_fee calculation in short is : net_fee = inputs - outputs -system fee.
# For this test to be able to grab the input values we need to make the TX that it references available for this test
ms2 = MemoryStream(binascii.unhexlify(
b'80000001def3ab1c73a13e80fea34ca751c79fe8dcf68d93d91d4956818baf0b99d95818010002e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6000e8764817000000faaa0f339e0fb33f91697cbf5aac41d17921222ae72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60008997b2270000002d9a070d388aa24d9f639bc8ddf985dc473c75d70141401a07d186fdfe3f9862c873d7cd9bdcb9cc8b3f5edcf853af31addcc4476d7d4fe89385cc955a4f604c667110332c14cb2fd8f62a29569b01a572774c7f7136572321026aeca2aed2094e9622a44cf584c694554f10cdb84d4f8eeab3e28ead4e87c168ac'))
reader2 = BinaryReader(ms2)
vout_tx = Transaction.DeserializeFrom(reader2)

self.assertEqual(tx.ToArray(), self.sttx)
self.assertEqual(tx.Hash.ToBytes(), self.sttx_id)

json = tx.ToJson()
with patch('neo.Core.Blockchain.Blockchain.GetTransaction', return_value=(vout_tx, 0)):
json = tx.ToJson()
self.assertEqual(json['size'], 191)
self.assertEqual(json['type'], "StateTransaction")
self.assertEqual(json['version'], 0)
Expand Down
8 changes: 4 additions & 4 deletions neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import plyvel
import binascii
import struct
from neo.Core.Blockchain import Blockchain
from neo.Core.Header import Header
from neo.Core.Block import Block
Expand Down Expand Up @@ -514,7 +515,7 @@ def GetSysFeeAmount(self, hash):
hash = hash.ToBytes()
try:
value = self._db.get(DBPrefix.DATA_Block + hash)[0:8]
amount = int.from_bytes(value, 'little', signed=False)
amount = struct.unpack("<d", value)[0]
return amount
except Exception as e:
logger.debug("Could not get sys fee: %s " % e)
Expand Down Expand Up @@ -666,9 +667,8 @@ def Persist(self, block):
contracts = DBCollection(self._db, DBPrefix.ST_Contract, ContractState)
storages = DBCollection(self._db, DBPrefix.ST_Storage, StorageItem)

amount_sysfee = self.GetSysFeeAmount(block.PrevHash) + block.TotalFees().value
amount_sysfee_bytes = amount_sysfee.to_bytes(8, 'little')

amount_sysfee = self.GetSysFeeAmount(block.PrevHash) + (block.TotalFees().value / Fixed8.D)
amount_sysfee_bytes = struct.pack("<d", amount_sysfee)
to_dispatch = []

with self._db.write_batch() as wb:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from neo.SmartContract.StateMachine import StateMachine
from neo.SmartContract.ApplicationEngine import ApplicationEngine
from neo.SmartContract import TriggerType
import struct


class TestLevelDBBlockchain(LevelDBBlockchain):
Expand All @@ -33,8 +34,8 @@ def Persist(self, block):
contracts = DBCollection(self._db, DBPrefix.ST_Contract, ContractState)
storages = DBCollection(self._db, DBPrefix.ST_Storage, StorageItem)

amount_sysfee = self.GetSysFeeAmount(block.PrevHash) + block.TotalFees().value
amount_sysfee_bytes = amount_sysfee.to_bytes(8, 'little')
amount_sysfee = self.GetSysFeeAmount(block.PrevHash) + (block.TotalFees().value / Fixed8.D)
amount_sysfee_bytes = struct.pack("<d", amount_sysfee)

with self._db.write_batch() as wb:
for tx in block.Transactions:
Expand Down
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, 12356)

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, 12356)
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, 12357)

def test_2_transactions(self):

Expand Down
4 changes: 2 additions & 2 deletions neo/Prompt/Commands/WalletAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def SplitUnspentCoin(wallet, asset_id, from_addr, index, divisions, fee=Fixed8.Z
try:
passwd = prompt("[Password]> ", is_password=True)
except KeyboardInterrupt:
print("Splitting cancelled")
return
print("Splitting cancelled")
return
if not wallet.ValidatePassword(passwd):
print("incorrect password")
return
Expand Down
6 changes: 3 additions & 3 deletions neo/Prompt/Commands/tests/test_claim_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_1_no_available_claim(self):

unavailable_bonus = wallet.GetUnavailableBonus()

self.assertEqual(Fixed8.FromDecimal(0.0002685), unavailable_bonus)
self.assertEqual(Fixed8.FromDecimal(0.00028250).value, unavailable_bonus.value)

unclaimed_coins = wallet.GetUnclaimedCoins()

Expand All @@ -93,15 +93,15 @@ 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.000629).value, unavailable_bonus.value)

unclaimed_coins = wallet.GetUnclaimedCoins()

self.assertEqual(1, len(unclaimed_coins))

available_bonus = wallet.GetAvailableClaimTotal()

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

def test_3_wallet_no_claimable_gas(self):

Expand Down
7 changes: 5 additions & 2 deletions neo/Prompt/Commands/tests/test_send_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def test_send_token_ok(self):
mock_print.getvalue())

def test_insufficient_funds(self):

with patch('sys.stdout', new=StringIO()) as mock_print:
PromptData.Wallet = self.GetWallet1(recreate=True)
args = ['send', 'gas', self.watch_addr_str, '72620']
Expand All @@ -232,7 +233,8 @@ def test_transaction_size_1(self):
res = Wallet.CommandWallet().execute(args)

self.assertFalse(res)
self.assertIn('Transaction cancelled. The tx size (1026) exceeds the max free tx size (1024).\nA network fee of 0.001 GAS is required.', mock_print.getvalue()) # notice the required fee is equal to the low priority threshold
self.assertIn('Transaction cancelled. The tx size (1026) exceeds the max free tx size (1024).\nA network fee of 0.001 GAS is required.',
mock_print.getvalue()) # notice the required fee is equal to the low priority threshold

def test_transaction_size_2(self):
with patch('sys.stdout', new=StringIO()) as mock_print:
Expand All @@ -243,7 +245,8 @@ def test_transaction_size_2(self):
res = Wallet.CommandWallet().execute(args)

self.assertFalse(res)
self.assertIn('Transaction cancelled. The tx size (1411) exceeds the max free tx size (1024).\nA network fee of 0.00387 GAS is required.', mock_print.getvalue()) # the required fee is equal to (1411-1024) * 0.0001 (FEE_PER_EXTRA_BYTE) = 0.00387
self.assertIn('Transaction cancelled. The tx size (1411) exceeds the max free tx size (1024).\nA network fee of 0.00387 GAS is required.',
mock_print.getvalue()) # the required fee is equal to (1411-1024) * 0.0001 (FEE_PER_EXTRA_BYTE) = 0.00387

def test_bad_password(self):
with patch('neo.Prompt.Commands.Send.prompt', side_effect=['blah']):
Expand Down
Loading