#!/usr/bin/env python3
# Copyright (c) 2018-2019 The Syscoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from test_framework.test_framework import SyscoinTestFramework
from test_framework.util import (
    assert_equal,
)
from test_framework.blocktools import (
    TIME_GENESIS_BLOCK,
)


class CreateTxWalletTest(SyscoinTestFramework):
    def set_test_params(self):
        self.setup_clean_chain = True
        self.num_nodes = 1

    def skip_test_if_missing_module(self):
        self.skip_if_no_wallet()

    def run_test(self):
        self.log.info('Create some old blocks')
        self.nodes[0].setmocktime(TIME_GENESIS_BLOCK)
        self.nodes[0].generate(200)
        self.nodes[0].setmocktime(0)

        self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
        assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
        txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
        tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
        assert_equal(tx['locktime'], 0)

        self.log.info('Check that anti-fee-sniping is enabled when we mine a recent block')
        self.nodes[0].generate(1)
        txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
        tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
        assert 0 < tx['locktime'] <= 201


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

@@ -323,16 +323,45 @@
 _equal,%0A
+    assert_raises_rpc_error,%0A
 )%0Afrom t
@@ -840,24 +840,137 @@
 ocktime(0)%0A%0A
+        self.test_anti_fee_sniping()%0A        self.test_tx_size_too_large()%0A%0A    def test_anti_fee_sniping(self):%0A
         self
@@ -1623,32 +1623,32 @@
 n(txid)%5B'hex'%5D)%0A
-
         assert 0
@@ -1673,16 +1673,1521 @@
 %3C= 201%0A%0A
+    def test_tx_size_too_large(self):%0A        # More than 10kB of outputs, so that we hit -maxtxfee with a high feerate%0A        outputs = %7Bself.nodes%5B0%5D.getnewaddress(address_type='bech32'): 0.000025 for i in range(400)%7D%0A        raw_tx = self.nodes%5B0%5D.createrawtransaction(inputs=%5B%5D, outputs=outputs)%0A%0A        for fee_setting in %5B'-minrelaytxfee=0.01', '-mintxfee=0.01', '-paytxfee=0.01'%5D:%0A            self.log.info('Check maxtxfee in combination with %7B%7D'.format(fee_setting))%0A            self.restart_node(0, extra_args=%5Bfee_setting%5D)%0A            assert_raises_rpc_error(%0A                -6,%0A                %22Fee exceeds maximum configured by -maxtxfee%22,%0A                lambda: self.nodes%5B0%5D.sendmany(dummy=%22%22, amounts=outputs),%0A            )%0A            assert_raises_rpc_error(%0A                -4,%0A                %22Fee exceeds maximum configured by -maxtxfee%22,%0A                lambda: self.nodes%5B0%5D.fundrawtransaction(hexstring=raw_tx),%0A            )%0A%0A        self.log.info('Check maxtxfee in combination with settxfee')%0A        self.restart_node(0)%0A        self.nodes%5B0%5D.settxfee(0.01)%0A        assert_raises_rpc_error(%0A            -6,%0A            %22Fee exceeds maximum configured by -maxtxfee%22,%0A            lambda: self.nodes%5B0%5D.sendmany(dummy=%22%22, amounts=outputs),%0A        )%0A        assert_raises_rpc_error(%0A            -4,%0A            %22Fee exceeds maximum configured by -maxtxfee%22,%0A            lambda: self.nodes%5B0%5D.fundrawtransaction(hexstring=raw_tx),%0A        )%0A        self.nodes%5B0%5D.settxfee(0)%0A%0A
 %0Aif __na

Add test for maxtxfee option