mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
Merge bitcoin/bitcoin#33920: Export embedded ASMap RPC
2a90b6132aAdd release notes for exportasmap (Fabian Jahr)8cb2d926b4rpc: Add exportasmap RPC (Fabian Jahr) Pull request description: This depends on the embedded data PR itself (#28792), until merge this will remain in draft status. All commit but the last one are from there. There has been interest in exporting the embedded data back into a file. This is implemented here with a simple `exportasmap` RPC which provides this functionality. The exported file can be used to verify the data integrity or statistical analysis using e.g. `contrib/asmap-tool.py`. ACKs for top commit: achow101: ACK2a90b6132asedited: ACK2a90b6132aseduless: Tested ACK2a90b6132aTree-SHA512: c8453078efe916ed95bff0695aabd9123d805970e037fad5e9317f4d43e2a4b21970030265bc82b00f3a222ee3db11346eef1fb6fc9393429b9bc6449f1830f1
This commit is contained in:
@@ -11,11 +11,15 @@ with missing and unparseable files.
|
||||
The tests are order-independent.
|
||||
|
||||
"""
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
)
|
||||
|
||||
ASMAP = 'src/test/data/asmap.raw' # path to unit test skeleton asmap
|
||||
VERSION = 'bafc9da308f45179443bd1d22325400ac9104f741522d003e3fac86700f68895'
|
||||
@@ -124,6 +128,29 @@ class AsmapTest(BitcoinTestFramework):
|
||||
asns.append(asn)
|
||||
assert_equal(len(asns), 3)
|
||||
|
||||
def test_export_embedded_asmap(self):
|
||||
self.log.info('Test exportasmap RPC')
|
||||
export_path = os.path.join(self.datadir, "asmap.dat")
|
||||
|
||||
if not self.is_embedded_asmap_compiled():
|
||||
assert_raises_rpc_error(-1, "No embedded ASMap data available", self.node.exportasmap, export_path)
|
||||
return
|
||||
|
||||
# Relative paths are resolved against the datadir.
|
||||
result = self.node.exportasmap("asmap.dat")
|
||||
assert_equal(result["path"], export_path)
|
||||
|
||||
with open(export_path, 'rb') as f:
|
||||
data = f.read()
|
||||
assert_equal(result["bytes_written"], len(data))
|
||||
|
||||
# Added in https://github.com/bitcoin/bitcoin/pull/34696
|
||||
expected_hash = "478d61986c59365cf86cd244485bbbe76a9ca0c630864717286dd19949879074"
|
||||
assert_equal(hashlib.sha256(data).hexdigest(), expected_hash)
|
||||
assert_equal(result["file_hash"], expected_hash)
|
||||
|
||||
os.remove(export_path)
|
||||
|
||||
def run_test(self):
|
||||
self.node = self.nodes[0]
|
||||
self.datadir = self.node.chain_path
|
||||
@@ -139,6 +166,7 @@ class AsmapTest(BitcoinTestFramework):
|
||||
self.test_asmap_with_missing_file()
|
||||
self.test_empty_asmap()
|
||||
self.test_asmap_health_check()
|
||||
self.test_export_embedded_asmap()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user