mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
test: extend CoinJoin RPC tests to include more cases, add logging
This commit is contained in:
parent
c6dd3dd567
commit
a1b256b06f
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user