From a1b256b06f2bc30c6a3686f11a1849e0dbdb92be Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:33:22 +0000 Subject: [PATCH] test: extend CoinJoin RPC tests to include more cases, add logging --- test/functional/rpc_coinjoin.py | 54 ++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/test/functional/rpc_coinjoin.py b/test/functional/rpc_coinjoin.py index 935d2817f6..8ca9c865fa 100755 --- a/test/functional/rpc_coinjoin.py +++ b/test/functional/rpc_coinjoin.py @@ -4,13 +4,21 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.messages import ( + COIN, + MAX_MONEY, +) +from test_framework.util import ( + assert_equal, + assert_raises_rpc_error, +) -''' -rpc_coinjoin.py - -Tests CoinJoin basic RPC -''' +# See coinjoin/options.h +COINJOIN_ROUNDS_DEFAULT = 4 +COINJOIN_ROUNDS_MAX = 16 +COINJOIN_ROUNDS_MIN = 2 +COINJOIN_TARGET_MAX = int(MAX_MONEY / COIN) +COINJOIN_TARGET_MIN = 2 class CoinJoinTest(BitcoinTestFramework): def set_test_params(self): @@ -33,33 +41,45 @@ class CoinJoinTest(BitcoinTestFramework): self.test_setcoinjoinrounds(w1) def test_coinjoin_start_stop(self, node): - # Start Mixing + self.log.info('"coinjoin" subcommands should update mixing status') + # Start mix session and ensure it's reported node.coinjoin('start') - # Get CoinJoin info cj_info = node.getcoinjoininfo() - # Ensure that it started properly assert_equal(cj_info['enabled'], True) assert_equal(cj_info['running'], True) + # Repeated start should yield error + assert_raises_rpc_error(-32603, 'Mixing has been started already.', node.coinjoin, 'start') - # Stop mixing + # Stop mix session and ensure it's reported node.coinjoin('stop') - # Get CoinJoin info cj_info = node.getcoinjoininfo() - # Ensure that it stopped properly assert_equal(cj_info['enabled'], True) assert_equal(cj_info['running'], False) + # Repeated stop should yield error + assert_raises_rpc_error(-32603, 'No mix session to stop', node.coinjoin, 'stop') + + # Reset mix session + assert_equal(node.coinjoin('reset'), "Mixing was reset") def test_setcoinjoinamount(self, node): + self.log.info('"setcoinjoinamount" should update mixing target') # Test normal and large values - for value in [50, 1200000]: + for value in [COINJOIN_TARGET_MIN, 50, 1200000, COINJOIN_TARGET_MAX]: node.setcoinjoinamount(value) assert_equal(node.getcoinjoininfo()['max_amount'], value) + # Test values below minimum and above maximum + for value in [COINJOIN_TARGET_MIN - 1, COINJOIN_TARGET_MAX + 1]: + assert_raises_rpc_error(-8, "Invalid amount of DASH as mixing goal amount", node.setcoinjoinamount, value) def test_setcoinjoinrounds(self, node): - # Test normal values - node.setcoinjoinrounds(5) - assert_equal(node.getcoinjoininfo()['max_rounds'], 5) - + self.log.info('"setcoinjoinrounds" should update mixing rounds') + # Test acceptable values + for value in [COINJOIN_ROUNDS_MIN, COINJOIN_ROUNDS_DEFAULT, COINJOIN_ROUNDS_MAX]: + node.setcoinjoinrounds(value) + assert_equal(node.getcoinjoininfo()['max_rounds'], value) + # Test values below minimum and above maximum + for value in [COINJOIN_ROUNDS_MIN - 1, COINJOIN_ROUNDS_MAX + 1]: + assert_raises_rpc_error(-8, "Invalid number of rounds", node.setcoinjoinrounds, value) if __name__ == '__main__': CoinJoinTest().main()