Skip to content

Commit e5ff4e4

Browse files
committed
qa: use a clearer and documented amount error in malleated snapshot
In the assumeutxo functional tests, the final test case with alternated UTxO data tests the error raised when deserializing a snapshot that contains a coin with an amount not in range (<0 or >MAX_MONEY). The current malleation uses an undocumented byte string and offset which makes it hard to maintain. In addition, the undocumented offset is set surprisingly high (39 bytes is well into the serialization of the amount which starts at offset 36). Similarly the value is surprisingly small, presumably one was adjusted for the other. But there is no comment explaining how they were chosen, why not in a clearer manner and what they are supposed to represent. Instead replace this seemingly magic value with a clear one, MAX_MONEY + 1, serialize the whole value for the amount field at the correct offset, and document the whole thing for the next person around.
1 parent b34fdb5 commit e5ff4e4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
create_block,
1717
create_coinbase
1818
)
19+
from test_framework.compressor import (
20+
compress_amount,
21+
)
1922
from test_framework.messages import (
2023
CBlockHeader,
2124
from_hex,
2225
msg_headers,
23-
tx_from_hex
26+
tx_from_hex,
27+
ser_varint,
28+
MAX_MONEY,
2429
)
2530
from test_framework.p2p import (
2631
P2PInterface,
@@ -139,7 +144,14 @@ def expected_error(msg):
139144
[b"\x81", 34, "3da966ba9826fb6d2604260e01607b55ba44e1a5de298606b08704bc62570ea8", None], # wrong coin code VARINT
140145
[b"\x80", 34, "091e893b3ccb4334378709578025356c8bcb0a623f37c7c4e493133c988648e5", None], # another wrong coin code
141146
[b"\x84\x58", 34, None, "Bad snapshot data after deserializing 0 coins"], # wrong coin case with height 364 and coinbase 0
142-
[b"\xCA\xD2\x8F\x5A", 39, None, "Bad snapshot data after deserializing 0 coins - bad tx out value"], # Amount exceeds MAX_MONEY
147+
[
148+
# compressed txout value + scriptpubkey
149+
ser_varint(compress_amount(MAX_MONEY + 1)) + ser_varint(0),
150+
# txid + coins per txid + vout + coin height
151+
32 + 1 + 1 + 2,
152+
None,
153+
"Bad snapshot data after deserializing 0 coins - bad tx out value"
154+
], # Amount exceeds MAX_MONEY
143155
]
144156

145157
for content, offset, wrong_hash, custom_message in cases:

0 commit comments

Comments
 (0)