test.py: add test for halving calculator
This commit is contained in:
parent
5f22ded095
commit
2f6e5f1fc2
2 changed files with 25 additions and 5 deletions
|
|
@ -2,15 +2,28 @@
|
|||
|
||||
# Demonstrates use of the MMGen asyncio/aiohttp JSON-RPC interface
|
||||
# https://github.com/mmgen/mmgen
|
||||
# Requires a running Bitcoin Core node
|
||||
# If necessary, invoke with --rpc-host/--rpc-port/--rpc-user/--rpc-password
|
||||
# Specify aiohttp backend with --rpc-backend=aiohttp (Linux only)
|
||||
|
||||
import time
|
||||
from decimal import Decimal
|
||||
from mmgen.common import *
|
||||
|
||||
opts.init()
|
||||
opts.init({
|
||||
'text': {
|
||||
'desc': 'Estimate date of next Bitcoin halving',
|
||||
'usage':'[opts]',
|
||||
'options': """
|
||||
-h, --help Print this help message
|
||||
--, --longhelp Print help message for long options (common options)
|
||||
-s, --sample-size=N Specify sample block range for block discovery time
|
||||
estimate
|
||||
""",
|
||||
'notes': """
|
||||
Requires a running Bitcoin Core node
|
||||
If necessary, invoke with --rpc-host/--rpc-port/--rpc-user/--rpc-password
|
||||
Specify aiohttp backend with --rpc-backend=aiohttp (Linux only)
|
||||
"""
|
||||
}
|
||||
})
|
||||
|
||||
HalvingInterval = 210000 # src/chainparams.cpp
|
||||
|
||||
|
|
@ -36,7 +49,7 @@ async def main():
|
|||
|
||||
tip = await c.call('getblockcount')
|
||||
remaining = HalvingInterval - tip % HalvingInterval
|
||||
sample_size = max(remaining,144)
|
||||
sample_size = int(opt.sample_size) if opt.sample_size else max(remaining,144)
|
||||
|
||||
# aiohttp backend will perform these two calls concurrently:
|
||||
cur,old = await c.gathered_call('getblockstats',((tip,),(tip - sample_size,)))
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
|
|||
cmd_group = (
|
||||
('setup', 'regtest (Bob and Alice) mode setup'),
|
||||
('current_user', 'current user'),
|
||||
('halving_calculator_bob', 'halving calculator (Bob)'),
|
||||
('walletgen_bob', 'wallet generation (Bob)'),
|
||||
('walletgen_alice', 'wallet generation (Alice)'),
|
||||
('addrgen_bob', 'address generation (Bob)'),
|
||||
|
|
@ -283,6 +284,12 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
|
|||
t.expect('Bob')
|
||||
return t
|
||||
|
||||
def halving_calculator_bob(self):
|
||||
t = self.spawn('halving-calculator.py',['--bob','--sample-size=144'],cmd_dir='examples')
|
||||
t.expect('time until halving')
|
||||
t.read()
|
||||
return t
|
||||
|
||||
def walletgen(self,user):
|
||||
t = self.spawn('mmgen-walletgen',['-q','-r0','-p1','--'+user])
|
||||
t.passphrase_new('new '+dfl_wcls.desc,rt_pw)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue