mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Issue a warning when filtering by height but also asking for mempool transactions, fix #37
This commit is contained in:
parent
e3dcc96a60
commit
000a1d5cff
4 changed files with 60 additions and 41 deletions
|
@ -55,9 +55,9 @@ author = 'Michal Salaban'
|
||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = '0.4.3'
|
version = '0.4.4'
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = '0.4.3'
|
release = '0.4.4'
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
|
|
@ -177,6 +177,10 @@ and ``unconfirmed`` query parameters that accept boolean values:
|
||||||
You may as well query for both confirmed and unconfirmed transactions using
|
You may as well query for both confirmed and unconfirmed transactions using
|
||||||
``wallet.incoming(unconfirmed=True)`` (the default value for ``confirmed`` is ``True``).
|
``wallet.incoming(unconfirmed=True)`` (the default value for ``confirmed`` is ``True``).
|
||||||
|
|
||||||
|
.. note:: Mempool transactions don't belong to the blockchain (yet), therefore they have no height.
|
||||||
|
Setting ``min_height`` or ``max_height`` arguments will **always exclude mempool
|
||||||
|
transactions**. If ``unconfirmed`` is also set to ``True``, a warning will be issued.
|
||||||
|
|
||||||
.. _sending-payments:
|
.. _sending-payments:
|
||||||
|
|
||||||
Sending payments
|
Sending payments
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
from .address import address
|
from .address import address
|
||||||
from .numbers import PaymentID
|
from .numbers import PaymentID
|
||||||
|
|
||||||
|
@ -160,7 +161,12 @@ class PaymentFilter(object):
|
||||||
_payment_id = filterparams.pop('payment_id', None)
|
_payment_id = filterparams.pop('payment_id', None)
|
||||||
if len(filterparams) > 0:
|
if len(filterparams) > 0:
|
||||||
raise ValueError("Excessive arguments for payment query: {}".format(filterparams))
|
raise ValueError("Excessive arguments for payment query: {}".format(filterparams))
|
||||||
|
if self.unconfirmed and (self.min_height is not None or self.max_height is not None):
|
||||||
|
warnings.warn("Height filtering (min_height/max_height) has been requested while "
|
||||||
|
"also asking for unconfirmed transactions. These are mutually exclusive. "
|
||||||
|
"As mempool transactions have no height at all, they will be excluded "
|
||||||
|
"from the result.",
|
||||||
|
RuntimeWarning)
|
||||||
if _local_address is None:
|
if _local_address is None:
|
||||||
self.local_addresses = []
|
self.local_addresses = []
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import unittest
|
import unittest
|
||||||
|
import warnings
|
||||||
|
|
||||||
from monero.wallet import Wallet
|
from monero.wallet import Wallet
|
||||||
from monero.account import Account
|
from monero.account import Account
|
||||||
from monero.address import address
|
from monero.address import address
|
||||||
from monero.numbers import PaymentID
|
from monero.numbers import PaymentID
|
||||||
from monero.transaction import IncomingPayment, OutgoingPayment, Transaction
|
from monero.transaction import IncomingPayment, Transaction
|
||||||
|
|
||||||
class FiltersTestCase(unittest.TestCase):
|
class FiltersTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -146,6 +147,8 @@ class FiltersTestCase(unittest.TestCase):
|
||||||
self.assertEqual(len(pmts), 3)
|
self.assertEqual(len(pmts), 3)
|
||||||
|
|
||||||
def test_filter_mempool(self):
|
def test_filter_mempool(self):
|
||||||
|
with warnings.catch_warnings(record=True) as w:
|
||||||
|
warnings.simplefilter('always')
|
||||||
pmts = self.wallet.incoming()
|
pmts = self.wallet.incoming()
|
||||||
self.assertEqual(len(pmts), 7)
|
self.assertEqual(len(pmts), 7)
|
||||||
for p in pmts:
|
for p in pmts:
|
||||||
|
@ -159,10 +162,15 @@ class FiltersTestCase(unittest.TestCase):
|
||||||
'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c')
|
'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c')
|
||||||
self.assertEqual(self.wallet.confirmations(pmts[0]), 0)
|
self.assertEqual(self.wallet.confirmations(pmts[0]), 0)
|
||||||
self.assertEqual(self.wallet.confirmations(pmts[0].transaction), 0)
|
self.assertEqual(self.wallet.confirmations(pmts[0].transaction), 0)
|
||||||
|
self.assertEqual(len(w), 0)
|
||||||
pmts = self.wallet.incoming(unconfirmed=True, confirmed=False, min_height=1)
|
pmts = self.wallet.incoming(unconfirmed=True, confirmed=False, min_height=1)
|
||||||
self.assertEqual(len(pmts), 0)
|
self.assertEqual(len(pmts), 0)
|
||||||
|
self.assertEqual(len(w), 1)
|
||||||
|
self.assertIs(w[0].category, RuntimeWarning)
|
||||||
pmts = self.wallet.incoming(unconfirmed=True, confirmed=False, max_height=99999999999999)
|
pmts = self.wallet.incoming(unconfirmed=True, confirmed=False, max_height=99999999999999)
|
||||||
self.assertEqual(len(pmts), 0)
|
self.assertEqual(len(pmts), 0)
|
||||||
|
self.assertEqual(len(w), 2)
|
||||||
|
self.assertIs(w[1].category, RuntimeWarning)
|
||||||
pmts = self.wallet.incoming(payment_id='03f6649304ea4cb2')
|
pmts = self.wallet.incoming(payment_id='03f6649304ea4cb2')
|
||||||
self.assertEqual(len(pmts), 0)
|
self.assertEqual(len(pmts), 0)
|
||||||
pmts = self.wallet.incoming(unconfirmed=True, payment_id='03f6649304ea4cb2')
|
pmts = self.wallet.incoming(unconfirmed=True, payment_id='03f6649304ea4cb2')
|
||||||
|
@ -183,6 +191,7 @@ class FiltersTestCase(unittest.TestCase):
|
||||||
local_address='9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC',
|
local_address='9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC',
|
||||||
payment_id='03f6649304ea4cb2')
|
payment_id='03f6649304ea4cb2')
|
||||||
self.assertEqual(len(pmts), 1)
|
self.assertEqual(len(pmts), 1)
|
||||||
|
self.assertEqual(len(w), 2)
|
||||||
|
|
||||||
def test_filter_excessive(self):
|
def test_filter_excessive(self):
|
||||||
self.assertRaises(ValueError, self.wallet.incoming, excessive_argument='foo')
|
self.assertRaises(ValueError, self.wallet.incoming, excessive_argument='foo')
|
||||||
|
|
Loading…
Reference in a new issue