#!/usr/bin/env python3
# Copyright (c) 2015-2016 The Bitcoin Core developers
# Copyright (c) 2017 The Bitcoin developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
Test that the blockmaxsize and excessiveblocksize parameters are also
settable via the bitcoin.conf file.
"""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error
from test_framework.cdefs import (ONE_MEGABYTE)

import os

class BSVBlockSizeParams(BitcoinTestFramework):

    def set_test_params(self):
        self.num_nodes = 1
        self.maxminedblocksize = 4 * ONE_MEGABYTE
        self.maxblocksize = 16 * ONE_MEGABYTE

    def setup_chain(self):
        super().setup_chain()
        with open(os.path.join(self.options.tmpdir + "/node0", "bitcoin.conf"), 'a', encoding='utf8') as f:
            f.write("blockmaxsize=" + str(self.maxminedblocksize) + "\n")
            f.write("excessiveblocksize=" + str(self.maxblocksize) + "\n")

    def add_options(self, parser):
        super().add_options(parser)

    def run_test(self):
        gires = self.nodes[0].getinfo()
        assert_equal(gires["maxblocksize"], self.maxblocksize)
        assert_equal(gires["maxminedblocksize"], self.maxminedblocksize)


if __name__ == '__main__':
    BSVBlockSizeParams().main()

[((35, 8, 35, 62), 'test_framework.util.assert_equal', 'assert_equal', ({(35, 21, 35, 42): "gires['maxblocksize']", (35, 44, 35, 61): 'self.maxblocksize'}, {}), "(gires['maxblocksize'], self.maxblocksize)", False, 'from test_framework.util import assert_equal, assert_raises_rpc_error\n'), ((36, 8, 36, 72), 'test_framework.util.assert_equal', 'assert_equal', ({(36, 21, 36, 47): "gires['maxminedblocksize']", (36, 49, 36, 71): 'self.maxminedblocksize'}, {}), "(gires['maxminedblocksize'], self.maxminedblocksize)", False, 'from test_framework.util import assert_equal, assert_raises_rpc_error\n'), ((26, 18, 26, 78), 'os.path.join', 'os.path.join', ({(26, 31, 26, 61): "(self.options.tmpdir + '/node0')", (26, 63, 26, 77): '"""bitcoin.conf"""'}, {}), "(self.options.tmpdir + '/node0', 'bitcoin.conf')", False, 'import os\n')]