Created
December 20, 2014 07:49
-
-
Save dexX7/06df91d1a7f99190d8d6 to your computer and use it in GitHub Desktop.
bitcoin/qa/rpc-tests/walletreaccept.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# Copyright (c) 2014 The Bitcoin Core developers | |
# Distributed under the MIT software license, see the accompanying | |
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
""" | |
Tests whether a client is able to add | |
unconfirmed wallet transactions back to | |
the memory pool after restart | |
""" | |
from test_framework import BitcoinTestFramework | |
from util import * | |
from random import randint | |
import logging | |
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO) | |
class WalletReacceptTest(BitcoinTestFramework): | |
def setup_chain(self): | |
logging.info("Initializing test directory "+self.options.tmpdir) | |
initialize_chain_clean(self.options.tmpdir, 1) | |
def setup_network(self, split=False): | |
self.nodes = start_nodes(1, self.options.tmpdir) | |
self.is_network_split=False | |
def random_send(self, node): | |
amount = Decimal(randint(1,10)) / Decimal(10) | |
node.sendtoaddress(node.getnewaddress(), amount) | |
def run_test(self): | |
logging.info("Generate 101 blocks") | |
self.nodes[0].setgenerate(True, 101) | |
logging.info("Node should have 50.0 spendable bitcoin") | |
assert_equal(self.nodes[0].getbalance(), 50) | |
logging.info("Send 20 random transactions") | |
for i in range(20): | |
self.random_send(self.nodes[0]) | |
logging.info("Node should have 20 transactions in mempool") | |
assert_equal(len(self.nodes[0].getrawmempool()), 20) | |
logging.info("Shutdown and restart client") | |
stop_nodes(self.nodes) | |
wait_bitcoinds() | |
self.setup_network() | |
logging.info("Node should reaccept all transactions and have 20 transactions in mempool") | |
assert_equal(len(self.nodes[0].getrawmempool()), 20) | |
logging.info("Generate 1 block") | |
self.nodes[0].setgenerate(True, 1) | |
logging.info("Node should have 0 transactions in mempool") | |
assert_equal(len(self.nodes[0].getrawmempool()), 0) | |
if __name__ == '__main__': | |
WalletReacceptTest().main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment