-
Notifications
You must be signed in to change notification settings - Fork 81
/
test_transaction.py
124 lines (111 loc) · 4.26 KB
/
test_transaction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from unittest import TestCase
from xrpl.models.exceptions import XRPLModelException
from xrpl.models.transactions import OfferCreate
from xrpl.models.transactions.transaction import Transaction
from xrpl.models.transactions.types.transaction_type import TransactionType
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
_FEE = "0.00001"
_SEQUENCE = 19048
_TICKET_SEQUENCE = 20510
_ACCOUNT_TXN_ID = "66F3D6158CAB6E53405F8C264DB39F07D8D0454433A63DDFB98218ED1BC99B60"
class TestTransaction(TestCase):
def test_missing_required_field(self):
with self.assertRaises(XRPLModelException):
# missing account
Transaction(
fee=_FEE,
sequence=_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
def test_initializes_if_all_required_fields_present(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
self.assertTrue(tx.is_valid())
def test_to_dict_includes_type_as_string(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
value = tx.to_dict()["transaction_type"]
self.assertEqual(type(value), str)
def test_get_hash(self):
offer_create_dict = {
"Account": "rLyttXLh7Ttca9CMUaD3exVoXY2fn2zwj3",
"Fee": "10",
"Flags": 0,
"LastLedgerSequence": 16409087,
"Sequence": 16409064,
"SigningPubKey": (
"ED93BFA583E83331E9DC498DE4558CE4861ACFAB9385EBBC43BC56A0D9845A1DF2"
),
"TakerGets": "13100000",
"TakerPays": {
"currency": "USD",
"issuer": "rLyttXLh7Ttca9CMUaD3exVoXY2fn2zwj3",
"value": "10",
},
"TransactionType": "OfferCreate",
"TxnSignature": (
"71135999783658A0CB4EBCF02E59ACD94C4D06D5BF909E05E6B97588155482BBA5985"
"35AD4728ACA1F90C4DE73FFC741B0A6AB87141BDA8BCC2F2DF9CD8C3703"
),
}
offer_create = OfferCreate.from_xrpl(offer_create_dict)
expected_hash = (
"66F3D6158CAB6E53405F8C264DB39F07D8D0454433A63DDFB98218ED1BC99B60"
)
self.assertEqual(offer_create.get_hash(), expected_hash)
def test_to_dict_flag_list(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
flags=[0b1, 0b10, 0b100],
)
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,
)