Skip to content

Commit

Permalink
feat: added ticket_sequence to Transaction class common fields (#428)
Browse files Browse the repository at this point in the history
* added ticket_sequence to Transaction class common

* added simple ticket_sequence added test

* unit tested and threw errors on ticket seq

* fixed up name of tests

* made ticket sequence test more readable

* changed to long string

* whitespace

* Updated CHANGELOG.md with ticket_sequence

* Remove empty lines from CHANGELOG

* Removed empty lines from CHANGELOG v2

* Update CHANGELOG.md for clearer common field naming

Co-authored-by: Elliot Lee <github.public@intelliot.com>

* Update Sequence to sequence for readability

Co-authored-by: Elliot Lee <github.public@intelliot.com>

Co-authored-by: Elliot Lee <github.public@intelliot.com>
  • Loading branch information
connorjchen and intelliot committed Sep 1, 2022
1 parent 3511d1c commit 5058b42
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Function to parse the final account balances from a transaction's metadata
- Function to parse order book changes from a transaction's metadata
- Support for Ed25519 seeds that don't use the `sEd` prefix
- Common field `ticket_sequence` to Transaction class

### Fixed:
- Typing for factory classmethods on models
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/models/transactions/test_transaction.py
Expand Up @@ -8,6 +8,8 @@
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
_FEE = "0.00001"
_SEQUENCE = 19048
_TICKET_SEQUENCE = 20510
_ACCOUNT_TXN_ID = "66F3D6158CAB6E53405F8C264DB39F07D8D0454433A63DDFB98218ED1BC99B60"


class TestTransaction(TestCase):
Expand Down Expand Up @@ -79,3 +81,44 @@ def test_to_dict_flag_list(self):
expected_flags = 0b111
value = tx.to_dict()["flags"]
self.assertEqual(value, expected_flags)

def test_to_dict_ticket_sequence(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
value = tx.to_dict()["ticket_sequence"]
self.assertEqual(value, _TICKET_SEQUENCE)

def test_to_dict_ticket_sequence_with_sequence_zero(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=0,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
value = tx.to_dict()["ticket_sequence"]
self.assertEqual(value, _TICKET_SEQUENCE)

def test_throws_when_ticket_sequence_and_sequence_both_nonzero(self):
with self.assertRaises(XRPLModelException):
Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=_SEQUENCE,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)

def test_throws_when_ticket_sequence_and_account_tx_in_both_included(self):
with self.assertRaises(XRPLModelException):
Transaction(
account=_ACCOUNT,
fee=_FEE,
account_txn_id=_ACCOUNT_TXN_ID,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
18 changes: 18 additions & 0 deletions xrpl/models/transactions/transaction.py
Expand Up @@ -243,12 +243,30 @@ class Transaction(BaseModel):
added during signing.
"""

ticket_sequence: Optional[int] = None
"""
The sequence number of the ticket to use in place of a Sequence number. If
this is provided, sequence must be 0. Cannot be used with account_txn_id.
"""

txn_signature: Optional[str] = None
"""
The cryptographic signature from the sender that authorizes this
transaction. Automatically added during signing.
"""

def _get_errors(self: Transaction) -> Dict[str, str]:
errors = super()._get_errors()
if self.ticket_sequence is not None and (
(self.sequence is not None and self.sequence != 0)
or self.account_txn_id is not None
):
errors[
"Transaction"
] = """If ticket_sequence is provided,
account_txn_id must be None and sequence must be None or 0"""
return errors

def to_dict(self: Transaction) -> Dict[str, Any]:
"""
Returns the dictionary representation of a Transaction.
Expand Down

0 comments on commit 5058b42

Please sign in to comment.