diff --git a/test/functional/rpc_fundrawtransaction.py b/test/functional/rpc_fundrawtransaction.py index 4aa37fac80229..a5ddb09501abb 100755 --- a/test/functional/rpc_fundrawtransaction.py +++ b/test/functional/rpc_fundrawtransaction.py @@ -99,6 +99,9 @@ def run_test(self): self.test_simple_two_outputs() self.test_change() self.test_no_change() + self.test_invalid_option() + self.test_invalid_change_address() + self.test_valid_change_address() self.test_coin_selection() self.test_two_vin() self.test_two_vin_two_vout() @@ -168,6 +171,33 @@ def test_no_change(self): assert_equal(changepos, -1) # check (no) change assert check_outputs(outputs, dec_tx) # check outputs + def test_invalid_option(self): + self.log.info("test with an invalid option") + outputs = {self.nodes[0].getnewaddress(): 1.0} + rawtx = self.nodes[2].createrawtransaction([], outputs) + assert_raises_rpc_error(-3, "Unexpected key foo", + self.nodes[2].fundrawtransaction, rawtx, {'foo': 'bar'}) + + def test_invalid_change_address(self): + self.log.info("test with an invalid change address") + outputs = {self.nodes[0].getnewaddress(): 1.0} + rawtx = self.nodes[2].createrawtransaction([], outputs) + assert_raises_rpc_error(-8, "changeAddress must be a valid PIVX address", + self.nodes[2].fundrawtransaction, rawtx, {'changeAddress': 'foobar'}) + + def test_valid_change_address(self): + self.log.info("test with a provided change address") + outputs = {self.nodes[0].getnewaddress(): 1.0} + rawtx = self.nodes[2].createrawtransaction([], outputs) + change = self.nodes[2].getnewaddress() + assert_raises_rpc_error(-8, "changePosition out of bounds", + self.nodes[2].fundrawtransaction, rawtx, {'changeAddress': change, + 'changePosition': 2}) + rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 0}) + dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex']) + out = dec_tx['vout'][0] + assert_equal(change, out['scriptPubKey']['addresses'][0]) + def test_coin_selection(self): self.log.info("test with a vin < required amount") utx = get_unspent(self.nodes[2].listunspent(), 1)