def test_get_rpc_creds():
    trivechain_config = trivechain_conf()
    creds = TrivechainConfig.get_rpc_creds(trivechain_config, 'testnet')

    for key in ('user', 'password', 'port'):
        assert key in creds
    assert creds.get('user') == 'trivechainrpc'
    assert creds.get(
        'password') == 'EwJeV3fZTyTVozdECF627BkBMnNDwQaVLakG3A4wXYyk'
    assert creds.get('port') == 29241

    trivechain_config = trivechain_conf(rpcpassword='******',
                                        rpcport=8000)
    creds = TrivechainConfig.get_rpc_creds(trivechain_config, 'testnet')

    for key in ('user', 'password', 'port'):
        assert key in creds
    assert creds.get('user') == 'trivechainrpc'
    assert creds.get('password') == 's00pers33kr1t'
    assert creds.get('port') == 8000

    no_port_specified = re.sub('\nrpcport=.*?\n', '\n', trivechain_conf(),
                               re.M)
    creds = TrivechainConfig.get_rpc_creds(no_port_specified, 'testnet')

    for key in ('user', 'password', 'port'):
        assert key in creds
    assert creds.get('user') == 'trivechainrpc'
    assert creds.get(
        'password') == 'EwJeV3fZTyTVozdECF627BkBMnNDwQaVLakG3A4wXYyk'
    assert creds.get('port') == 19998
Example #2
0
    def from_trivechain_conf(self, trivechain_dot_conf):
        from trivechain_config import TrivechainConfig
        config_text = TrivechainConfig.slurp_config_file(trivechain_dot_conf)
        creds = TrivechainConfig.get_rpc_creds(config_text, config.network)

        creds[u'host'] = config.rpc_host

        return self(**creds)
Example #3
0
def test_trivechaind():
    config_text = TrivechainConfig.slurp_config_file(config.trivechain_conf)
    network = 'mainnet'
    is_testnet = False
    genesis_hash = u'000008ad295e16d2a5456aef65cb1c28139835aba6a340d0be0fb8ca2b2e9e26'
    for line in config_text.split("\n"):
        if line.startswith('testnet=1'):
            network = 'testnet'
            is_testnet = True
            genesis_hash = u'00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c'

    creds = TrivechainConfig.get_rpc_creds(config_text, network)
    trivechaind = TrivechainDaemon(**creds)
    assert trivechaind.rpc_command is not None

    assert hasattr(trivechaind, 'rpc_connection')

    # Trivechain testnet block 0 hash == 00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c
    # test commands without arguments
    info = trivechaind.rpc_command('getinfo')
    info_keys = [
        'blocks',
        'connections',
        'difficulty',
        'errors',
        'protocolversion',
        'proxy',
        'testnet',
        'timeoffset',
        'version',
    ]
    for key in info_keys:
        assert key in info
    assert info['testnet'] is is_testnet

    # test commands with args
    assert trivechaind.rpc_command('getblockhash', 0) == genesis_hash
Example #4
0
def test_trivechaind():
    config_text = TrivechainConfig.slurp_config_file(config.trivechain_conf)
    network = 'mainnet'
    is_testnet = False
    genesis_hash = u'000008ad295e16d2a5456aef65cb1c28139835aba6a340d0be0fb8ca2b2e9e26'
    for line in config_text.split("\n"):
        if line.startswith('testnet=1'):
            network = 'testnet'
            is_testnet = True
            genesis_hash = u'00000288fe5535c740c1418c70a6da3affa7c858ea6de8852a568ed24d5328d5'

    creds = TrivechainConfig.get_rpc_creds(config_text, network)
    trivechaind = TrivechainDaemon(**creds)
    assert trivechaind.rpc_command is not None

    assert hasattr(trivechaind, 'rpc_connection')

    # Trivechain testnet block 0 hash == 00000288fe5535c740c1418c70a6da3affa7c858ea6de8852a568ed24d5328d5
    # test commands without arguments
    info = trivechaind.rpc_command('getinfo')
    info_keys = [
        'blocks',
        'connections',
        'difficulty',
        'errors',
        'protocolversion',
        'proxy',
        'testnet',
        'timeoffset',
        'version',
    ]
    for key in info_keys:
        assert key in info
    assert info['testnet'] is is_testnet

    # test commands with args
    assert trivechaind.rpc_command('getblockhash', 0) == genesis_hash
def test_slurp_config_file():
    import tempfile

    trivechain_config = """# basic settings
#testnet=1 # TESTNET
server=1
printtoconsole=1
txindex=1 # enable transaction index
"""

    expected_stripped_config = """server=1
printtoconsole=1
txindex=1 # enable transaction index
"""

    with tempfile.NamedTemporaryFile(mode='w') as temp:
        temp.write(trivechain_config)
        temp.flush()
        conf = TrivechainConfig.slurp_config_file(temp.name)
        assert conf == expected_stripped_config
Example #6
0
"""
    Set up defaults and read sentinel.conf
"""
import sys
import os
from trivechain_config import TrivechainConfig

default_sentinel_config = os.path.normpath(
    os.path.join(os.path.dirname(__file__), '../sentinel.conf'))
sentinel_config_file = os.environ.get('SENTINEL_CONFIG',
                                      default_sentinel_config)
sentinel_cfg = TrivechainConfig.tokenize(sentinel_config_file)
sentinel_version = "1.2.0"
min_trivechaind_proto_version_with_sentinel_ping = 70207


def get_trivechain_conf():
    if sys.platform == 'win32':
        trivechain_conf = os.path.join(os.getenv('APPDATA'),
                                       "TrivechainCore/trivechain.conf")
    else:
        home = os.environ.get('HOME')

        trivechain_conf = os.path.join(home, ".trivechaincore/trivechain.conf")
        if sys.platform == 'darwin':
            trivechain_conf = os.path.join(
                home,
                "Library/Application Support/TrivechainCore/trivechain.conf")

    trivechain_conf = sentinel_cfg.get('trivechain_conf', trivechain_conf)