예제 #1
0
    def run_test(self):
        # Temporary workaround for the may15th hardfork. These tests will not work if the fork is enabled
        # because we are forcing an EB of 32MB after each block is mined which invalidates many of these tests.
        # So we set the mocktime to sometime far in advance of the fork.
        MAY152018_START_TIME = 1526400000
        self.nodes[0].setmocktime(MAY152018_START_TIME - 10000)
        self.nodes[1].setmocktime(MAY152018_START_TIME - 10000)
        self.nodes[2].setmocktime(MAY152018_START_TIME - 10000)
        self.nodes[3].setmocktime(MAY152018_START_TIME - 10000)

        BitcoinTestFramework.run_test(self)
        self.testCli()
        self.testExcessiveSigops()

        # clear out the mempool
        mostly_sync_mempools(self.nodes)
        for n in self.nodes:
            n.generate(2)
            sync_blocks(self.nodes)
        for n in self.nodes:
            while len(n.getrawmempool()):
                n.generate(1)
                sync_blocks(self.nodes)
        logging.info(
            "cleared mempool: %s" %
            str([len(x) for x in [y.getrawmempool() for y in self.nodes]]))
        self.testExcessiveBlockSize()
        self.testExcessiveTx()
    def __init__(self, test_assertion='success'):
        self.rep = False
        BitcoinTestFramework.__init__(self)

        if test_assertion == 'success':
            self.test_assertion = self.assert_success
        else:
            self.test_assertion = self.assert_failure
    def __init__(self, block_type, n_txs, n_nodes=NUM_PROCS + 1):
        self.block_type = block_type
        self.n_txs = n_txs
        self.n_nodes = n_nodes
        self.rep = False
        self.stats = {}

        BitcoinTestFramework.__init__(self)
예제 #4
0
 def __init__(self, build_variant, client_dirs, extended=False):
     BitcoinTestFramework.__init__(self)
     self.buildVariant = build_variant
     self.clientDirs = client_dirs
     self.extended = extended
     self.unspendableTx = 0
     self.bins = [ os.path.join(base_dir, x, self.buildVariant, "src","bitcoind") for x in clientDirs]
     logging.info(self.bins)
예제 #5
0
 def __init__(self, build_variant, client_dirs):
     BitcoinTestFramework.__init__(self)
     self.buildVariant = build_variant
     self.clientDirs = client_dirs
     self.bins = [ os.path.join(base_dir, x, self.buildVariant, "src","bitcoind") for x in clientDirs]
     self.forkTime = int(time.time())
     self.conf = { "forkMay2018time": self.forkTime, "acceptnonstdtxn": 0 }
     logging.info(self.bins)
예제 #6
0
 def __init__(self, build_variant, client_dirs):
     BitcoinTestFramework.__init__(self)
     self.buildVariant = build_variant
     self.clientDirs = client_dirs
     self.bins = [
         os.path.join(base_dir, x, self.buildVariant, "src", "bitcoind")
         for x in clientDirs
     ]
     logging.info(self.bins)
예제 #7
0
    def run_test (self):
        BitcoinTestFramework.run_test (self)

        tips = self.nodes[0].getchaintips ()
        assert_equal (len (tips), 1)
        assert_equal (tips[0]['branchlen'], 0)
        assert_equal (tips[0]['height'], 200)
        assert_equal (tips[0]['status'], 'active')

        # Split the network and build two chains of different lengths.
        self.split_network ()
예제 #8
0
    def run_test (self):
        BitcoinTestFramework.run_test (self)

        tips = self.nodes[0].getchaintips ()
        assert_equal (len (tips), 1)
        assert_equal (tips[0]['branchlen'], 0)
        assert_equal (tips[0]['height'], 200)
        assert_equal (tips[0]['status'], 'active')

        # Split the network and build two chains of different lengths.
        self.split_network ()
        self.nodes[0].generate(10)
        self.sync_all ()
        self.nodes[2].generate(20)
        self.sync_all ()

        tips = self.nodes[1].getchaintips ()
        assert_equal (len (tips), 1)
        shortTip = tips[0]
        assert_equal (shortTip['branchlen'], 0)
        assert_equal (shortTip['height'], 210)
        assert_equal (tips[0]['status'], 'active')

        tips = self.nodes[3].getchaintips ()
        assert_equal (len (tips), 1)
        longTip = tips[0]
        assert_equal (longTip['branchlen'], 0)
        assert_equal (longTip['height'], 220)
        assert_equal (tips[0]['status'], 'active')

        stop_nodes(self.nodes)
        wait_bitcoinds()
        self.is_network_split = False
        self.nodes = self.setup_nodes()
        connect_nodes_bi(self.nodes, 0, 1)
        connect_nodes_bi(self.nodes, 0, 2)
        connect_nodes_bi(self.nodes, 0, 3)
        connect_nodes_bi(self.nodes, 1, 2)
        connect_nodes_bi(self.nodes, 1, 3)
        connect_nodes_bi(self.nodes, 2, 3)
        self.sync_blocks()
        self.sync_all()

        tips = self.nodes[0].getchaintips ()
        assert_equal (len (tips), 2)
        assert_equal (tips[0], longTip)

        assert_equal (tips[1]['branchlen'], 10)
        assert_equal (tips[1]['status'], 'valid-fork')
        tips[1]['branchlen'] = 0
        tips[1]['status'] = 'active'
        assert_equal (tips[1], shortTip)
예제 #9
0
    def run_test(self):
        BitcoinTestFramework.run_test(self)
        self.testCli()

        # clear out the mempool
        for n in self.nodes:
            while len(n.getrawmempool()):
                n.generate(1)
                sync_blocks(self.nodes)
        logging.info(
            "cleared mempool: %s" %
            str([len(x) for x in [y.getrawmempool() for y in self.nodes]]))
        self.testExcessiveBlockSize()
        self.testExcessiveTx()
예제 #10
0
 def __init__(self, build_variant, client_dirs, bitcoinConfDict):
     BitcoinTestFramework.__init__(self)
     self.buildVariant = build_variant
     self.clientDirs = client_dirs
     self.bins = [
         os.path.join(base_dir, x, self.buildVariant, "src", "bitcoind")
         for x in clientDirs
     ]
     self.forkTime = int(time.time())
     self.conf = {
         "forkMay2018time": self.forkTime,
         "acceptnonstdtxn": 0,
         "relaypriority": 0
     }
     self.conf.update(bitcoinConfDict)
     # config required for running hub
     self.conf = remove_hubclient_parameters(self.bins, self.conf)
     logging.info(self.bins)
예제 #11
0
    def run_test(self):
        # self.nodes[0].generate(200)
        # self.sync_all ()

        BitcoinTestFramework.run_test(self)
        tips = self.nodes[0].getchaintips()
        assert_equal(len(tips), 1)
        assert_equal(tips[0]['branchlen'], 0)
        assert_equal(tips[0]['height'], 200)
        assert_equal(tips[0]['status'], 'active')

        # Split the network and build two chains of different lengths.
        self.split_network()
        self.nodes[0].generate(10)
        self.nodes[2].generate(20)
        self.sync_all()

        tips = self.nodes[1].getchaintips()
        assert_equal(len(tips), 1)
        shortTip = tips[0]
        assert_equal(shortTip['branchlen'], 0)
        assert_equal(shortTip['height'], 210)
        assert_equal(tips[0]['status'], 'active')

        tips = self.nodes[3].getchaintips()
        assert_equal(len(tips), 1)
        longTip = tips[0]
        assert_equal(longTip['branchlen'], 0)
        assert_equal(longTip['height'], 220)
        assert_equal(tips[0]['status'], 'active')

        # Join the network halves and check that we now have two tips
        # (at least at the nodes that previously had the short chain).
        self.join_network()

        tips = self.nodes[0].getchaintips()
        assert_equal(len(tips), 2)
        assert_equal(tips[0], longTip)

        assert_equal(tips[1]['branchlen'], 10)
        assert_equal(tips[1]['status'], 'valid-fork')
        tips[1]['branchlen'] = 0
        tips[1]['status'] = 'active'
        assert_equal(tips[1], shortTip)
예제 #12
0
    def run_test (self):
        BitcoinTestFramework.run_test (self)

        tips = self.nodes[0].getchaintips ()
        assert_equal (len (tips), 1)
        assert_equal (tips[0]['branchlen'], 0)
        assert_equal (tips[0]['height'], 120)
        assert_equal (tips[0]['status'], 'active')

        # Split the network and build two chains of different lengths.
        self.split_network ()
        self.nodes[0].generate(10);
        self.nodes[2].generate(20);
        self.sync_all ()

        tips = self.nodes[1].getchaintips ()
        assert_equal (len (tips), 1)
        shortTip = tips[0]
        assert_equal (shortTip['branchlen'], 0)
        assert_equal (shortTip['height'], 130)
        assert_equal (tips[0]['status'], 'active')

        tips = self.nodes[3].getchaintips ()
        assert_equal (len (tips), 1)
        longTip = tips[0]
        assert_equal (longTip['branchlen'], 0)
        assert_equal (longTip['height'], 140)
        assert_equal (tips[0]['status'], 'active')

        # Join the network halves and check that we now have two tips
        # (at least at the nodes that previously had the short chain).
        self.join_network ()

        tips = self.nodes[0].getchaintips ()
        assert_equal (len (tips), 2)
        assert_equal (tips[0], longTip)

        assert_equal (tips[1]['branchlen'], 10)
        assert_equal (tips[1]['status'], 'valid-fork')
        tips[1]['branchlen'] = 0
        tips[1]['status'] = 'active'
        assert_equal (tips[1], shortTip)
예제 #13
0
    def run_test(self):
        BitcoinTestFramework.run_test(self)

        test_default_values(self)

        test_setting_values(self, nodeId=0)
        test_setting_values(self, nodeId=1)
        test_setting_values(self, nodeId=2)
        test_setting_values(self, nodeId=3)

        test_sync_clear_mempool(self)

        # Fixed-6: Insufficient funds
        self.nodes[0].generate(101)
        sync_blocks(self.nodes)
        test_accept_depth(self, nodeOneId=0, nodeTwoId=1)

        test_excessive_Sigops(self)

        reporter.display_report()
예제 #14
0
  def run_test (self):
    BitcoinTestFramework.run_test (self)

    # Generate a block so that we are not "downloading blocks".
    self.nodes[0].generate (1)

    # Register a player.
    self.nodes[0].name_register ("foo", '{"color": 0}')
    self.nodes[0].generate (1)
    self.sync_all ('blocks')

    # Perform some transactions.
    addr = self.nodes[3].getnewaddress ()
    self.nodes[2].sendtoaddress (addr, Decimal ('1'))
    self.nodes[0].name_update ("foo", '{"0": {"destruct": true}}')
    self.nodes[1].name_register ("bar", '{"color": 1}')

    # Mine a block and get its stats.
    self.sync_all ('mempool')
    blkhash = self.nodes[3].generate (1)
    self.sync_all ('blocks')
    assert_equal (1, len (blkhash))
    blkhash = blkhash[0]
    cnt = self.nodes[0].getblockcount ()
    stats = self.nodes[0].getstatsforheight (cnt)

    # Verify stats against expectations.
    assert_equal (blkhash, stats['blockhash'])
    assert_equal (cnt, stats['height'])
    assert 'time' in stats
    assert 'size' in stats
    assert_equal (2, stats['transactions']['currency'])
    assert_equal (2, stats['transactions']['name'])
    assert_equal (1, stats['transactions']['game'])
    assert_equal (1, stats['game']['players'])
    assert_equal (3, stats['game']['hunters'])
예제 #15
0
 def __init__(self):
     self.nodes = []
     BitcoinTestFramework.__init__(self)
예제 #16
0
  def run_test (self):
    BitcoinTestFramework.run_test (self)

    # Check for difficulty reports in various RPC calls.  Where the "current"
    # state is involved, we get two (for each algo).  Where a particular block
    # is involved, we just get that block's difficulty (whatever the algo).
    dual = []
    dual.append (self.nodes[0].getinfo ())
    dual.append (self.nodes[0].getblockchaininfo ())
    dual.append (self.nodes[0].getmininginfo ())
    for data in dual:
      assert 'difficulty_sha256d' in data
      assert 'difficulty_scrypt' in data
      assert 'difficulty' not in data
    bestHash = self.nodes[0].getbestblockhash ()
    data = self.nodes[0].getblock (bestHash)
    assert 'difficulty' in data
    assert 'difficulty_sha256d' not in data
    assert 'difficulty_scrypt' not in data

    # Check getdifficulty RPC call.
    diffSHA = self.nodes[0].getdifficulty (0)
    assert_equal (diffSHA, dual[0]['difficulty_sha256d'])
    diffScrypt = self.nodes[0].getdifficulty (1)
    assert_equal (diffScrypt, dual[0]['difficulty_scrypt'])
    try:
      self.nodes[0].getdifficulty ()
      raise AssertionError ("getdifficulty without arg accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -1)

    # Generate a few blocks with SHA256D.  Ensure that they are, indeed,
    # with the correct algo.
    arr1 = self.nodes[0].generate (5)
    arr2 = self.nodes[0].generate (5, 0)
    for blk in arr1 + arr2:
      data = self.nodes[0].getblock (blk)
      assert_equal (data['algo'], 0)

    # Generate a few blocks with scrypt.  Ensure the algo parameter.
    # Furthermore, at least one of them "should" have an obviously high
    # hash value.  It may, of course, happen that this is not the case,
    # but the probability for that is negligible (about 2^(-20)).
    arr = self.nodes[0].generate (20, 1)
    foundHigh = False
    for blk in arr:
      data = self.nodes[0].getblock (blk)
      assert_equal (data['algo'], 1)
      if blk[0] in '89abcdef':
        foundHigh = True
    assert foundHigh

    # Verify check for algo parameter.
    for p in [-1, 2]:
      try:
        self.nodes[0].generate (1, p)
        raise AssertionError ("invalid algo parameter accepted")
      except JSONRPCException as exc:
        assert_equal (exc.error['code'], -8)

    # Briefly test generatetoaddress as well.
    for algo in [0, 1]:
      addr = self.nodes[0].getnewaddress ()
      blkhash = self.nodes[0].generatetoaddress (1, addr, algo)
      assert_equal (1, len (blkhash))
      data = self.nodes[0].getblock(blkhash[0])
      assert_equal (algo, data['algo'])
      coinbaseTx = data['tx'][0]
      utxo = self.nodes[0].gettxout (coinbaseTx, 0)
      assert_equal ([addr], utxo['scriptPubKey']['addresses'])

    # Check updates of the returned block (or not) with getauxblock.
    # Note that this behaviour needs not necessarily be exactly as tested,
    # but the test ensures that no change is introduced accidentally.
    auxblock1 = self.nodes[0].getauxblock ()
    auxblock2 = self.nodes[0].getauxblock (0)
    assert_equal (auxblock1['hash'], auxblock2['hash'])
    auxblock2 = self.nodes[0].getauxblock (1)
    auxblock3 = self.nodes[0].getauxblock (1)
    assert_equal (auxblock2['hash'], auxblock3['hash'])
    assert auxblock2['hash'] != auxblock1['hash']
    auxblock3 = self.nodes[0].getauxblock ()
    assert auxblock1['hash'] != auxblock3['hash']

    # Use getauxblock with explicit algo to mine a SHA256D block.
    # Assert that this works (the block is saved) even if we request
    # another scrypt block before.
    auxblock = self.nodes[0].getauxblock ()
    assert_equal (auxblock['chainid'], 6)
    assert_equal (auxblock['algo'], 0)
    dummy = self.nodes[0].getauxblock (1)
    assert_equal (dummy['chainid'], 2)
    assert_equal (dummy['algo'], 1)

    # Solve the auxpow requested before.
    curcnt = self.nodes[0].getblockcount ()
    target = auxpow.reverseHex (auxblock['_target'])
    apow = auxpow.computeAuxpow (auxblock['hash'], target, True)
    res = self.nodes[0].getauxblock (auxblock['hash'], apow)
    assert res

    # Check submitted data.
    assert_equal (self.nodes[0].getblockcount (), curcnt + 1)
    data = self.nodes[0].getblock (auxblock['hash'])
    assert_equal (data['algo'], 0)

    # Mine an scrypt auxpow.  Since there is no built-in Python
    # function to scrypt, we do it differently:  Simply try submitting
    # until the block is accepted.  Since we need on average 2 trials,
    # this is no big hit.
    trials = 0
    curcnt = self.nodes[0].getblockcount ()
    ok = False
    while not ok:
      if trials > 100:
        raise AssertionError ("failed to merge-mine scrypt auxpow")
      trials += 1

      # Force an update of the block so we get a new trial.
      self.nodes[0].getauxblock (0)
      auxblock = self.nodes[0].getauxblock (1)

      target = auxpow.reverseHex (auxblock['_target'])
      apow = auxpow.computeAuxpow (auxblock['hash'], target, False)
      ok = self.nodes[0].getauxblock (auxblock['hash'], apow)
    print "Found scrypt block after %d trials." % trials

    # Check submitted auxblock.
    assert_equal (self.nodes[0].getblockcount (), curcnt + 1)
    data = self.nodes[0].getblock (auxblock['hash'])
    assert_equal (data['algo'], 1)
예제 #17
0
  def run_test (self):
    BitcoinTestFramework.run_test (self)

    # Generate a block so that we are not "downloading blocks".
    self.nodes[0].generate (1)

    # Compare basic data of getauxblock to getblocktemplate.
    auxblock = self.nodes[0].getauxblock ()
    blocktemplate = self.nodes[0].getblocktemplate ()
    assert_equal (auxblock['coinbasevalue'], blocktemplate['coinbasevalue'])
    assert_equal (auxblock['bits'], blocktemplate['bits'])
    assert_equal (auxblock['height'], blocktemplate['height'])
    assert_equal (auxblock['previousblockhash'], blocktemplate['previousblockhash'])

    # Compare target and take byte order into account.
    target = auxblock['_target']
    reversedTarget = auxpow.reverseHex (target)
    assert_equal (reversedTarget, blocktemplate['target'])

    # Verify data that can be found in another way.
    assert_equal (auxblock['chainid'], 1)
    assert_equal (auxblock['height'], self.nodes[0].getblockcount () + 1)
    assert_equal (auxblock['previousblockhash'], self.nodes[0].getblockhash (auxblock['height'] - 1))

    # Calling again should give the same block.
    auxblock2 = self.nodes[0].getauxblock ()
    assert_equal (auxblock2, auxblock)

    # If we receive a new block, the old hash will be replaced.
    self.sync_all ()
    self.nodes[1].generate (1)
    self.sync_all ()
    auxblock2 = self.nodes[0].getauxblock ()
    assert auxblock['hash'] != auxblock2['hash']
    try:
      self.nodes[0].getauxblock (auxblock['hash'], "x")
      raise AssertionError ("invalid block hash accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)

    # Invalid format for auxpow.
    try:
      self.nodes[0].getauxblock (auxblock2['hash'], "x")
      raise AssertionError ("malformed auxpow accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -1)

    # Invalidate the block again, send a transaction and query for the
    # auxblock to solve that contains the transaction.
    self.nodes[0].generate (1)
    addr = self.nodes[1].getnewaddress ()
    txid = self.nodes[0].sendtoaddress (addr, 1)
    self.sync_all ()
    assert_equal (self.nodes[1].getrawmempool (), [txid])
    auxblock = self.nodes[0].getauxblock ()
    blocktemplate = self.nodes[0].getblocktemplate ()
    target = blocktemplate['target']

    # Compute invalid auxpow.
    apow = auxpow.computeAuxpow (auxblock['hash'], target, False)
    res = self.nodes[0].getauxblock (auxblock['hash'], apow)
    assert not res

    # Compute and submit valid auxpow.
    apow = auxpow.computeAuxpow (auxblock['hash'], target, True)
    res = self.nodes[0].getauxblock (auxblock['hash'], apow)
    assert res

    # Make sure that the block is indeed accepted.
    self.sync_all ()
    assert_equal (self.nodes[1].getrawmempool (), [])
    height = self.nodes[1].getblockcount ()
    assert_equal (height, auxblock['height'])
    assert_equal (self.nodes[1].getblockhash (height), auxblock['hash'])

    # Call getblock and verify the auxpow field.
    data = self.nodes[1].getblock (auxblock['hash'])
    assert 'auxpow' in data
    auxJson = data['auxpow']
    assert_equal (auxJson['index'], 0)
    assert_equal (auxJson['parentblock'], apow[-160:])

    # Check that previous blocks don't have 'auxpow' in their getblock JSON.
    oldHash = self.nodes[1].getblockhash (100)
    data = self.nodes[1].getblock (oldHash)
    assert 'auxpow' not in data

    # Check that it paid correctly to the first node.
    t = self.nodes[0].listtransactions ("", 1)
    assert_equal (len (t), 1)
    t = t[0]
    assert_equal (t['category'], "immature")
    assert_equal (t['blockhash'], auxblock['hash'])
    assert t['generated']
    assert t['amount'] >= Decimal ("25")
    assert_equal (t['confirmations'], 1)

    # Verify the coinbase script.  Ensure that it includes the block height
    # to make the coinbase tx unique.  The expected block height is around
    # 200, so that the serialisation of the CScriptNum ends in an extra 00.
    # The vector has length 2, which makes up for 02XX00 as the serialised
    # height.  Check this.
    blk = self.nodes[1].getblock (auxblock['hash'])
    tx = self.nodes[1].getrawtransaction (blk['tx'][0], 1)
    coinbase = tx['vin'][0]['coinbase']
    assert_equal ("02%02x00" % auxblock['height'], coinbase[0 : 6])

    # Ensure that the payout address is changed from one block to the next.
    addr1 = self.getCoinbaseAddr (auxblock['hash'])
    newHash = auxpow.mineAuxpowBlock (self.nodes[0])
    self.sync_all ()
    addr2 = self.getCoinbaseAddr (newHash)
    assert addr1 != addr2
    valid = self.nodes[0].validateaddress (addr1)
    assert valid['ismine']
    valid = self.nodes[0].validateaddress (addr2)
    assert valid['ismine']
예제 #18
0
 def __init__(self,extended=False):
   self.extended = extended
   BitcoinTestFramework.__init__(self)
예제 #19
0
 def run_test(self):
     BitcoinTestFramework.run_test(self)
     self.testCli()
     self.testExcessiveSigops()
     self.testExcessiveBlockSize()
     self.testExcessiveTx()
예제 #20
0
 def __init__(self):
     self.rep = False
     BitcoinTestFramework.__init__(self)
예제 #21
0
 def disconnect_nodes(self, a, b):
     BitcoinTestFramework.disconnect_nodes(self, a, b)
예제 #22
0
 def __init__(self, build_variant, client_dirs):
     BitcoinTestFramework.__init__(self)
     self.buildVariant = build_variant
     self.clientDirs = client_dirs
     # override the binaries
     self.bins = [ os.path.join(base_dir, x, self.buildVariant, "src","bitcoind") for x in clientDirs]
예제 #23
0
 def __init__(self, extended=False):
     self.extended = extended
     BitcoinTestFramework.__init__(self)
예제 #24
0
    def run_test(self):
        BitcoinTestFramework.run_test(self)

        # Generate a block so that we are not "downloading blocks".
        self.nodes[0].generate(1)

        # Compare basic data of getauxblock to getblocktemplate.
        auxblock = self.nodes[0].getauxblock()
        blocktemplate = self.nodes[0].getblocktemplate()
        assert_equal(auxblock['coinbasevalue'], blocktemplate['coinbasevalue'])
        assert_equal(auxblock['bits'], blocktemplate['bits'])
        assert_equal(auxblock['height'], blocktemplate['height'])
        assert_equal(auxblock['previousblockhash'],
                     blocktemplate['previousblockhash'])

        # Compare target and take byte order into account.
        target = auxblock['_target']
        reversedTarget = auxpow.reverseHex(target)
        assert_equal(reversedTarget, blocktemplate['target'])

        # Verify data that can be found in another way.
        assert_equal(auxblock['chainid'], 1)
        assert_equal(auxblock['height'], self.nodes[0].getblockcount() + 1)
        assert_equal(auxblock['previousblockhash'],
                     self.nodes[0].getblockhash(auxblock['height'] - 1))

        # Calling again should give the same block.
        auxblock2 = self.nodes[0].getauxblock()
        assert_equal(auxblock2, auxblock)

        # If we receive a new block, the old hash will be replaced.
        self.sync_all()
        self.nodes[1].generate(1)
        self.sync_all()
        auxblock2 = self.nodes[0].getauxblock()
        assert auxblock['hash'] != auxblock2['hash']
        try:
            self.nodes[0].getauxblock(auxblock['hash'], "x")
            raise AssertionError("invalid block hash accepted")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -8)

        # Invalid format for auxpow.
        try:
            self.nodes[0].getauxblock(auxblock2['hash'], "x")
            raise AssertionError("malformed auxpow accepted")
        except JSONRPCException as exc:
            assert_equal(exc.error['code'], -1)

        # Invalidate the block again, send a transaction and query for the
        # auxblock to solve that contains the transaction.
        self.nodes[0].generate(1)
        addr = self.nodes[1].getnewaddress()
        txid = self.nodes[0].sendtoaddress(addr, 1)
        self.sync_all()
        assert_equal(self.nodes[1].getrawmempool(), [txid])
        auxblock = self.nodes[0].getauxblock()
        blocktemplate = self.nodes[0].getblocktemplate()
        target = blocktemplate['target']

        # Compute invalid auxpow.
        apow = auxpow.computeAuxpow(auxblock['hash'], target, False)
        res = self.nodes[0].getauxblock(auxblock['hash'], apow)
        assert not res

        # Compute and submit valid auxpow.
        apow = auxpow.computeAuxpow(auxblock['hash'], target, True)
        res = self.nodes[0].getauxblock(auxblock['hash'], apow)
        assert res

        # Make sure that the block is indeed accepted.
        self.sync_all()
        assert_equal(self.nodes[1].getrawmempool(), [])
        height = self.nodes[1].getblockcount()
        assert_equal(height, auxblock['height'])
        assert_equal(self.nodes[1].getblockhash(height), auxblock['hash'])

        # Call getblock and verify the auxpow field.
        data = self.nodes[1].getblock(auxblock['hash'])
        assert 'auxpow' in data
        auxJson = data['auxpow']
        assert_equal(auxJson['index'], 0)
        assert_equal(auxJson['parentblock'], apow[-160:])

        # Check that previous blocks don't have 'auxpow' in their getblock JSON.
        oldHash = self.nodes[1].getblockhash(100)
        data = self.nodes[1].getblock(oldHash)
        assert 'auxpow' not in data

        # Check that it paid correctly to the first node.
        t = self.nodes[0].listtransactions("", 1)
        assert_equal(len(t), 1)
        t = t[0]
        assert_equal(t['category'], "immature")
        assert_equal(t['blockhash'], auxblock['hash'])
        assert t['generated']
        assert t['amount'] >= Decimal("25")
        assert_equal(t['confirmations'], 1)

        # Verify the coinbase script.  Ensure that it includes the block height
        # to make the coinbase tx unique.  The expected block height is around
        # 200, so that the serialisation of the CScriptNum ends in an extra 00.
        # The vector has length 2, which makes up for 02XX00 as the serialised
        # height.  Check this.
        blk = self.nodes[1].getblock(auxblock['hash'])
        tx = self.nodes[1].getrawtransaction(blk['tx'][0], 1)
        coinbase = tx['vin'][0]['coinbase']
        assert_equal("02%02x00" % auxblock['height'], coinbase[0:6])
예제 #25
0
 def run_test(self):
     BitcoinTestFramework.run_test(self)
     self.testExcessiveSigops()
     self.testExcessiveBlockSize()
     self.testExcessiveTx()
예제 #26
0
 def __init__(self):
     BitcoinTestFramework.__init__(self)
     # TODO When this asserts, you have probably backported bitcoin#11121, so you'll have to remove this constructor
     assert (not callable(
         getattr(BitcoinTestFramework(), "set_test_params", None)))
     self.set_test_params()
예제 #27
0
    def run_test (self):
        BitcoinTestFramework.run_test (self)
        tips = self.nodes[0].getchaintips ()
        assert_equal (len (tips), 1)
        assert_equal (tips[0]['branchlen'], 0)
        assert_equal (tips[0]['height'], 200)
        assert_equal (tips[0]['status'], 'active')
        # get spendable coins
        if 0:
          for n in self.nodes:
            n.generate(1)
            self.sync_all()
          self.nodes[0].generate(100)
	  self.sync_all()
        
 	# Set the accept depth at 1, 2, and 3 and watch each nodes resist the chain for that long
        self.nodes[1].setminingmaxblock(1000, 1)
        self.nodes[2].setminingmaxblock(1000, 2)
        self.nodes[3].setminingmaxblock(1000, 3)

        self.nodes[1].setexcessiveblock(1000, 1)
        self.nodes[2].setexcessiveblock(1000, 2)
        self.nodes[3].setexcessiveblock(1000, 3)

        addr = self.nodes[3].getnewaddress()
        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [201,200,200,200])  

        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        sync_blocks(self.nodes[0:2])
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [202,202,200,200])  

        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        sync_blocks(self.nodes[0:3])
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [203,203,203,200])  

        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        self.sync_all()
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [204,204,204,204])  

        # Now generate another excessive block, but all nodes should snap right to it because they have an older excessive block
        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        self.sync_all()
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [205,205,205,205])  
      
        self.nodes[0].generate(6*24)  # Now generate a day's worth of small blocks which should re-enable the node's reluctance to accept a large block
        self.sync_all()
        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [350,349,349,349])  

        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        sync_blocks(self.nodes[0:2])
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [351,351,350,350])  

        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        sync_blocks(self.nodes[0:3])
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [352,352,352,351])  

        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        self.sync_all()
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [353,353,353,353])  

        for i in range(0,20):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.nodes[0].generate(1)
        self.sync_all()
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [354,354,354,354])  

        self.nodes[0].generate(6*24 + 10)  # Now generate a day's worth of small blocks which should re-enable the node's reluctance to accept a large block + 10 because we have to get beyond all the node's accept depths
        self.sync_all()

        counts = [ x.getblockcount() for x in self.nodes ]
        self.nodes[1].setminingmaxblock(100000)  # not sure how big the txns will be but smaller than this 
        self.nodes[1].setexcessiveblock(100000, 1)  # not sure how big the txns will be but smaller than this 
        for i in range(0,40):
          self.nodes[0].sendtoaddress(addr, 1.0)
        self.sync_all()
        self.nodes[0].generate(1)
        time.sleep(2) #give blocks a chance to fully propagate
        sync_blocks(self.nodes[0:2])
        counts = [ x.getblockcount() for x in self.nodes ]
        assert_equal(counts, [509,509,508,508])  
      

        print "Random test"
        random.seed(1)
        for i in range(0,2):
          print "round ", i,
          for n in self.nodes:
            size = random.randint(1,1000)*1000
            n.setminingmaxblock(size)
            n.setexcessiveblock(size, random.randint(0,10))
          addrs = [x.getnewaddress() for x in self.nodes]
          ntxs=0
          for i in range(0,random.randint(1,1000)):
            try:
              self.nodes[random.randint(0,3)].sendtoaddress(addrs[random.randint(0,3)], .1)
              ntxs += 1
            except JSONRPCException: # could be spent all the txouts
              pass
          print ntxs, " transactions"
          time.sleep(1)
          self.nodes[random.randint(0,3)].generate(1)
          time.sleep(1)
예제 #28
0
 def setup_chain(self):
     if self.start_chain:
         BitcoinTestFramework.setup_chain(self)
예제 #29
0
 def __init__(self, bigTest=0):
     self.bigTest = bigTest
     BitcoinTestFramework.__init__(self)
예제 #30
0
  def run_test (self):
    BitcoinTestFramework.run_test (self)

    # Generate a block so that we are not "downloading blocks".
    self.nodes[0].generate (1)

    # We used to compare to getblocktemplate, but this call is gone
    # now completely for merge-mining.

    # Verify data that can be found in another way.
    auxblock = self.nodes[0].getauxblock ()
    assert_equal (auxblock['chainid'], 1)
    assert_equal (auxblock['height'], self.nodes[0].getblockcount () + 1)
    assert_equal (auxblock['previousblockhash'], self.nodes[0].getblockhash (auxblock['height'] - 1))

    # Calling again should give the same block.
    auxblock2 = self.nodes[0].getauxblock ()
    assert_equal (auxblock2, auxblock)

    # If we receive a new block, the old hash will be replaced.
    self.sync_all ()
    self.nodes[1].generate (1)
    self.sync_all ()
    auxblock2 = self.nodes[0].getauxblock ()
    assert auxblock['hash'] != auxblock2['hash']
    try:
      self.nodes[0].getauxblock (auxblock['hash'], "x")
      raise AssertionError ("invalid block hash accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -8)

    # Invalid format for auxpow.
    try:
      self.nodes[0].getauxblock (auxblock2['hash'], "x")
      raise AssertionError ("malformed auxpow accepted")
    except JSONRPCException as exc:
      assert_equal (exc.error['code'], -1)

    # Invalidate the block again, send a transaction and query for the
    # auxblock to solve that contains the transaction.
    self.nodes[0].generate (1)
    addr = self.nodes[1].getnewaddress ()
    txid = self.nodes[0].sendtoaddress (addr, 1)
    self.sync_all ()
    assert_equal (self.nodes[1].getrawmempool (), [txid])
    auxblock = self.nodes[0].getauxblock ()
    target = auxpow.reverseHex (auxblock['_target'])

    # Compute invalid auxpow.
    apow = auxpow.computeAuxpow (auxblock['hash'], target, False)
    res = self.nodes[0].getauxblock (auxblock['hash'], apow)
    assert not res

    # Compute and submit valid auxpow.
    apow = auxpow.computeAuxpow (auxblock['hash'], target, True)
    res = self.nodes[0].getauxblock (auxblock['hash'], apow)
    assert res

    # Make sure that the block is indeed accepted.
    self.sync_all ()
    assert_equal (self.nodes[1].getrawmempool (), [])
    height = self.nodes[1].getblockcount ()
    assert_equal (height, auxblock['height'])
    assert_equal (self.nodes[1].getblockhash (height), auxblock['hash'])

    # Call getblock and verify the auxpow field.
    data = self.nodes[1].getblock (auxblock['hash'])
    assert 'auxpow' in data
    auxJson = data['auxpow']
    assert_equal (auxJson['index'], 0)
    assert_equal (auxJson['chainindex'], 0)
    assert_equal (auxJson['merklebranch'], [])
    assert_equal (auxJson['chainmerklebranch'], [])
    assert_equal (auxJson['parentblock'], apow[-160:])

    # Also previous blocks should have 'auxpow', since all blocks (also
    # those generated by "generate") are merge-mined.
    oldHash = self.nodes[1].getblockhash (100)
    data = self.nodes[1].getblock (oldHash)
    assert 'auxpow' in data

    # Check that it paid correctly to the first node.
    t = self.nodes[0].listtransactions ("", 1)
    assert_equal (len (t), 1)
    t = t[0]
    assert_equal (t['category'], "immature")
    assert_equal (t['blockhash'], auxblock['hash'])
    assert t['generated']
    assert t['amount'] >= Decimal ("25")
    assert_equal (t['confirmations'], 1)

    # Verify the coinbase script.  Ensure that it includes the block height
    # to make the coinbase tx unique.  The expected block height is around
    # 200, so that the serialisation of the CScriptNum ends in an extra 00.
    # The vector has length 2, which makes up for 02XX00 as the serialised
    # height.  Check this.
    blk = self.nodes[1].getblock (auxblock['hash'])
    tx = self.nodes[1].getrawtransaction (blk['tx'][0], 1)
    coinbase = tx['vin'][0]['coinbase']
    assert_equal ("02%02x00" % auxblock['height'], coinbase[0 : 6])

    # Ensure that the payout address is changed from one block to the next.
    addr1 = self.getCoinbaseAddr (auxblock['hash'])
    newHash = auxpow.mineAuxpowBlock (self.nodes[0])
    self.sync_all ()
    addr2 = self.getCoinbaseAddr (newHash)
    assert addr1 != addr2
    valid = self.nodes[0].validateaddress (addr1)
    assert valid['ismine']
    valid = self.nodes[0].validateaddress (addr2)
    assert valid['ismine']