For #3359. RPCs transferring funds return error if Sapling addresses are used before Sapling activation.
This commit is contained in:
parent
527b7feef5
commit
de1b86a429
|
@ -19,17 +19,44 @@ class WalletSaplingTest(BitcoinTestFramework):
|
|||
def setup_nodes(self):
|
||||
return start_nodes(4, self.options.tmpdir, [[
|
||||
'-nuparams=5ba81b19:201', # Overwinter
|
||||
'-nuparams=76b809bb:201', # Sapling
|
||||
'-nuparams=76b809bb:203', # Sapling
|
||||
]] * 4)
|
||||
|
||||
def run_test(self):
|
||||
# Sanity-check the test harness
|
||||
assert_equal(self.nodes[0].getblockcount(), 200)
|
||||
|
||||
# Activate Sapling
|
||||
# Activate Overwinter
|
||||
self.nodes[2].generate(1)
|
||||
self.sync_all()
|
||||
|
||||
# Verify RPCs disallow Sapling value transfer if Sapling is not active
|
||||
tmp_taddr = self.nodes[3].getnewaddress()
|
||||
tmp_zaddr = self.nodes[3].z_getnewaddress('sapling')
|
||||
try:
|
||||
recipients = []
|
||||
recipients.append({"address": tmp_zaddr, "amount": Decimal('20')})
|
||||
self.nodes[3].z_sendmany(tmp_taddr, recipients, 1, 0)
|
||||
raise AssertionError("Should have thrown an exception")
|
||||
except JSONRPCException as e:
|
||||
assert_equal("Invalid parameter, Sapling has not activated", e.error['message'])
|
||||
try:
|
||||
recipients = []
|
||||
recipients.append({"address": tmp_taddr, "amount": Decimal('20')})
|
||||
self.nodes[3].z_sendmany(tmp_zaddr, recipients, 1, 0)
|
||||
raise AssertionError("Should have thrown an exception")
|
||||
except JSONRPCException as e:
|
||||
assert_equal("Invalid parameter, Sapling has not activated", e.error['message'])
|
||||
try:
|
||||
self.nodes[3].z_shieldcoinbase(tmp_taddr, tmp_zaddr)
|
||||
raise AssertionError("Should have thrown an exception")
|
||||
except JSONRPCException as e:
|
||||
assert_equal("Invalid parameter, Sapling has not activated", e.error['message'])
|
||||
|
||||
# Activate Sapling
|
||||
self.nodes[2].generate(2)
|
||||
self.sync_all()
|
||||
|
||||
taddr0 = self.nodes[0].getnewaddress()
|
||||
# Skip over the address containing node 1's coinbase
|
||||
self.nodes[1].getnewaddress()
|
||||
|
|
|
@ -3795,6 +3795,13 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
|
|||
}
|
||||
}
|
||||
|
||||
// If Sapling is not active, do not allow sending from or sending to Sapling addresses.
|
||||
if (!NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||
if (fromSapling || containsSaplingOutput) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated");
|
||||
}
|
||||
}
|
||||
|
||||
// As a sanity check, estimate and verify that the size of the transaction will be valid.
|
||||
// Depending on the input notes, the actual tx size may turn out to be larger and perhaps invalid.
|
||||
size_t txsize = 0;
|
||||
|
@ -3984,6 +3991,19 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
|
|||
max_tx_size = MAX_TX_SIZE_BEFORE_SAPLING;
|
||||
}
|
||||
|
||||
// If Sapling is not active, do not allow sending to a Sapling address.
|
||||
if (!NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||
auto res = DecodePaymentAddress(destaddress);
|
||||
if (IsValidPaymentAddress(res)) {
|
||||
bool toSapling = boost::get<libzcash::SaplingPaymentAddress>(&res) != nullptr;
|
||||
if (toSapling) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated");
|
||||
}
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare to get coinbase utxos
|
||||
std::vector<ShieldCoinbaseUTXO> inputs;
|
||||
CAmount shieldedValue = 0;
|
||||
|
|
Loading…
Reference in New Issue