mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-31 00:05:13 +02:00
rpc: Add exportasmap RPC
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