diff --git a/test/functional/feature_b4os.py b/test/functional/feature_b4os.py new file mode 100755 index 0000000000..ef0e137abf --- /dev/null +++ b/test/functional/feature_b4os.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +"""b4os functional test.""" + +from test_framework.test_framework import BitcoinTestFramework + + +class B4osTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 1 + + def run_test(self): + self.log.info("b4os") + + +if __name__ == '__main__': + B4osTest(__file__).main() \ No newline at end of file diff --git a/test/functional/feature_miniwallet.py b/test/functional/feature_miniwallet.py new file mode 100644 index 0000000000..6cd0cb6546 --- /dev/null +++ b/test/functional/feature_miniwallet.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Test MiniWallet as a test helper.""" + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_greater_than +from test_framework.wallet import MiniWallet + + +class MiniWalletTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 1 + + def run_test(self): + wallet = MiniWallet(self.nodes[0]) + + assert_greater_than(wallet.get_balance(), 0) + + tx = wallet.send_self_transfer(from_node=self.nodes[0]) + txid = tx["txid"] + + assert txid in self.nodes[0].getrawmempool() + + self.generate(self.nodes[0], 1) + + assert txid not in self.nodes[0].getrawmempool() + + +if __name__ == '__main__': + MiniWalletTest(__file__).main() diff --git a/test/functional/feature_prune_debug_log.py b/test/functional/feature_prune_debug_log.py new file mode 100644 index 0000000000..61e85d88d5 --- /dev/null +++ b/test/functional/feature_prune_debug_log.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Test prune mode debug log messages.""" + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal + + +class PruneDebugLogTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 1 + + def run_test(self): + self.log.info("Restart without prune - check no prune log message") + with self.nodes[0].assert_debug_log([], unexpected_msgs=["Prune configured to target"]): + self.restart_node(0, extra_args=[]) + + info = self.nodes[0].getblockchaininfo() + assert_equal(info["pruned"], False) + + self.log.info("Restart with prune=550 - check prune log message") + with self.nodes[0].assert_debug_log(["Prune configured to target"]): + self.restart_node(0, extra_args=["-prune=550"]) + + info = self.nodes[0].getblockchaininfo() + assert_equal(info["pruned"], True) + + +if __name__ == '__main__': + PruneDebugLogTest(__file__).main() diff --git a/test/functional/p2p_invalid_submission.py b/test/functional/p2p_invalid_submission.py new file mode 100755 index 0000000000..7752f86f5d --- /dev/null +++ b/test/functional/p2p_invalid_submission.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +"""Test that an invalid transaction is rejected over P2P.""" + +from test_framework.messages import CInv, MSG_TX, msg_getdata, msg_tx +from test_framework.p2p import P2PInterface +from test_framework.test_framework import BitcoinTestFramework +from test_framework.wallet import MiniWallet + + +class P2PInvalidSubmissionTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 1 + + def run_test(self): + wallet = MiniWallet(self.nodes[0]) + peer = self.nodes[0].add_p2p_connection(P2PInterface()) + + tx = wallet.create_self_transfer()["tx"] + tx.vin[0].prevout.n = 15 + + with self.nodes[0].assert_debug_log(["bad-txns"]): + peer.send_and_ping(msg_tx(tx)) + + assert tx.txid_hex not in self.nodes[0].getrawmempool() + + getdata = msg_getdata() + getdata.inv.append(CInv(MSG_TX, tx.txid_int)) + peer.send_without_ping(getdata) + + peer.wait_until(lambda: "notfound" in peer.last_message) + self.log.info("Node correctly rejected invalid transaction") + + +if __name__ == '__main__': + P2PInvalidSubmissionTest(__file__).main() \ No newline at end of file diff --git a/test/functional/p2p_ping_pong.py b/test/functional/p2p_ping_pong.py new file mode 100755 index 0000000000..6e9fe540b1 --- /dev/null +++ b/test/functional/p2p_ping_pong.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +"""Test P2P ping/pong message exchange.""" + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.p2p import P2PInterface +from test_framework.messages import msg_ping + + +class P2PPingPongTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 1 + + def run_test(self): + peer = self.nodes[0].add_p2p_connection(P2PInterface()) + + nonce = 12345 + peer.send_without_ping(msg_ping(nonce=nonce)) + + peer.wait_until(lambda: "pong" in peer.last_message and peer.last_message["pong"].nonce == + nonce) + + self.log.info("Pong received with matching nonce") + + +if __name__ == '__main__': + P2PPingPongTest(__file__).main() \ No newline at end of file diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index a4052f9102..b1adb6e386 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -379,8 +379,14 @@ 'tool_rpcauth.py', 'p2p_handshake.py', 'p2p_handshake.py --v2transport', + 'p2p_invalid_submission.py', 'feature_dirsymlinks.py', + 'feature_b4os.py', 'feature_help.py', + 'feature_miniwallet.py', + 'p2p_ping_pong.py', + 'feature_prune_debug_log.py', + 'wallet_rpc_basics.py', 'feature_framework_startup_failures.py', 'feature_shutdown.py', 'wallet_migration.py', diff --git a/test/functional/wallet_rpc_basics.py b/test/functional/wallet_rpc_basics.py new file mode 100755 index 0000000000..8f17e1d71c --- /dev/null +++ b/test/functional/wallet_rpc_basics.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Basic wallet RPC flow test.""" + +from decimal import Decimal + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, assert_greater_than + + +class WalletRPCBasicsTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 2 + self.setup_clean_chain = True + + def skip_test_if_missing_module(self): + self.skip_if_no_wallet() + + def run_test(self): + + self.nodes[0].createwallet("node0_wallet") + node0_wallet = self.nodes[0].get_wallet_rpc("node0_wallet") + + self.nodes[1].createwallet("node1_wallet") + node1_wallet = self.nodes[1].get_wallet_rpc("node1_wallet") + + + addr0 = node0_wallet.getnewaddress() + self.generatetoaddress(self.nodes[0], 101, addr0) + + assert_equal(node0_wallet.getbalance(), Decimal("50.00000000")) + + + addr = node1_wallet.getnewaddress() + txid = node0_wallet.sendtoaddress(addr, 1) + + + self.sync_mempools() + assert txid in self.nodes[0].getrawmempool() + assert txid in self.nodes[1].getrawmempool() + + + assert_greater_than(Decimal("49"), node0_wallet.getbalance()) + + + self.generate(self.nodes[0], 1) + + + assert txid not in self.nodes[0].getrawmempool() + assert txid not in self.nodes[1].getrawmempool() + + + assert_equal(node1_wallet.getbalance(), Decimal("1.00000000")) + + +if __name__ == '__main__': + WalletRPCBasicsTest(__file__).main() \ No newline at end of file