dogecoin/qa/rpc-tests/auxpow.py
Patrick Lodder 4dce3af38e Add AUXPoW rpc tests
- Tests the auxpow rpc interface `getauxblock`
- Tests consensus constraints for auxpow:
  - Minimum block height
  - Valid scrypt proof of work
  - Foreign chain ID

This test requires the python package ltc_scrypt. Installation of
this module is scripted in qa/pull-tester/install-deps.sh and has
been integrated for travis CI.
2015-08-26 22:14:51 +02:00

81 lines
2.7 KiB
Python
Executable file

#!/usr/bin/env python2
# Copyright (c) 2015 The Dogecoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Test AuxPOW RPC interface and constraints
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from struct import *
import binascii
import json
import StringIO
from test_framework import scrypt_auxpow
class AuxPOWTest (BitcoinTestFramework):
REWARD = 500000 # reward per block
CHAIN_ID = "62"
DIGISHIELD_START = 10 # nHeight when digishield starts
AUXPOW_START = 20 # nHeight when auxpow starts
MATURITY_HEIGHT = 60 # number of blocks for mined transactions to mature
def setup_chain(self):
print("Initializing test directory " + self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 2)
def setup_network(self, split=False):
self.nodes = start_nodes(2, self.options.tmpdir)
connect_nodes_bi(self.nodes,0,1)
self.is_network_split=False
self.sync_all()
def run_test(self):
print "Mining blocks..."
# 1. mine an auxpow block before auxpow is allowed, expect: fail
scrypt_auxpow.mineScryptAux(self.nodes[0], "00", True)
self.sync_all()
# 2. mine a non-auxpow block, just to ensure that this node
# can mine at all, expect: success
self.nodes[0].generate(1)
self.sync_all()
# 3. mine blocks until we're in digishield era
self.nodes[1].generate(self.DIGISHIELD_START - 1 - 1)
self.sync_all()
# 4. mine an auxpow block before auxpow is allowed, attempt 2
# expect: fail
scrypt_auxpow.mineScryptAux(self.nodes[0], "00", True)
self.sync_all()
# 5. mine blocks until we're in in auxpow era
self.nodes[1].generate(self.AUXPOW_START - self.DIGISHIELD_START)
self.sync_all()
# 6. mine a valid auxpow block, expect: success
scrypt_auxpow.mineScryptAux(self.nodes[0], "00", True)
# 7. mine an auxpow block with high pow, expect: fail
scrypt_auxpow.mineScryptAux(self.nodes[0], "00", False)
# 8. mine a valid auxpow block with the parent chain being us
# expect: fail
scrypt_auxpow.mineScryptAux(self.nodes[0], self.CHAIN_ID, True)
self.sync_all()
# 9. mine enough blocks to mature all node 0 rewards
self.nodes[1].generate(self.MATURITY_HEIGHT)
self.sync_all()
# node 0 should have block rewards for 2 blocks,
# One from step 2 and one from step 6.
assert_equal(self.nodes[0].getbalance(), self.REWARD * 2)
if __name__ == '__main__':
AuxPOWTest ().main ()