Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_rpc_buildavalancheproof.py
Show All 9 Lines | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_raises_rpc_error | from test_framework.util import assert_raises_rpc_error | ||||
from test_framework.wallet_util import bytes_to_wif | from test_framework.wallet_util import bytes_to_wif | ||||
class BuildAvalancheProofTest(BitcoinTestFramework): | class BuildAvalancheProofTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [['-avaproofstakeutxoconfirmations=1', | self.extra_args = [["-avaproofstakeutxoconfirmations=1", "-avacooldown=0"]] | ||||
'-avacooldown=0']] | |||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
addrkey0 = node.get_deterministic_priv_key() | addrkey0 = node.get_deterministic_priv_key() | ||||
blockhashes = self.generatetoaddress( | blockhashes = self.generatetoaddress( | ||||
node, 2, addrkey0.address, sync_fun=self.no_op) | node, 2, addrkey0.address, sync_fun=self.no_op | ||||
) | |||||
stakes = create_coinbase_stakes(node, [blockhashes[0]], addrkey0.key) | stakes = create_coinbase_stakes(node, [blockhashes[0]], addrkey0.key) | ||||
privkey = ECKey() | privkey = ECKey() | ||||
privkey.generate() | privkey.generate() | ||||
wif_privkey = bytes_to_wif(privkey.get_bytes()) | wif_privkey = bytes_to_wif(privkey.get_bytes()) | ||||
def check_buildavalancheproof_error( | def check_buildavalancheproof_error( | ||||
error_code, error_message, stakes, master_key=wif_privkey): | error_code, error_message, stakes, master_key=wif_privkey | ||||
): | |||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
error_code, | error_code, | ||||
error_message, | error_message, | ||||
node.buildavalancheproof, | node.buildavalancheproof, | ||||
# Sequence | # Sequence | ||||
0, | 0, | ||||
# Expiration | # Expiration | ||||
0, | 0, | ||||
master_key, | master_key, | ||||
stakes, | stakes, | ||||
) | ) | ||||
good_stake = stakes[0] | good_stake = stakes[0] | ||||
self.log.info("Error cases") | self.log.info("Error cases") | ||||
check_buildavalancheproof_error(-8, | check_buildavalancheproof_error( | ||||
"Invalid master key", | -8, "Invalid master key", [good_stake], master_key=bytes_to_wif(b"f00") | ||||
[good_stake], | |||||
master_key=bytes_to_wif(b'f00') | |||||
) | ) | ||||
negative_vout = good_stake.copy() | negative_vout = good_stake.copy() | ||||
negative_vout['vout'] = -1 | negative_vout["vout"] = -1 | ||||
check_buildavalancheproof_error(-22, | check_buildavalancheproof_error( | ||||
-22, | |||||
"vout cannot be negative", | "vout cannot be negative", | ||||
[negative_vout], | [negative_vout], | ||||
) | ) | ||||
zero_height = good_stake.copy() | zero_height = good_stake.copy() | ||||
zero_height['height'] = 0 | zero_height["height"] = 0 | ||||
check_buildavalancheproof_error(-22, | check_buildavalancheproof_error( | ||||
-22, | |||||
"height must be positive", | "height must be positive", | ||||
[zero_height], | [zero_height], | ||||
) | ) | ||||
negative_height = good_stake.copy() | negative_height = good_stake.copy() | ||||
negative_height['height'] = -1 | negative_height["height"] = -1 | ||||
check_buildavalancheproof_error(-22, | check_buildavalancheproof_error( | ||||
-22, | |||||
"height must be positive", | "height must be positive", | ||||
[negative_height], | [negative_height], | ||||
) | ) | ||||
missing_amount = good_stake.copy() | missing_amount = good_stake.copy() | ||||
del missing_amount['amount'] | del missing_amount["amount"] | ||||
check_buildavalancheproof_error(-8, | check_buildavalancheproof_error( | ||||
-8, | |||||
"Missing amount", | "Missing amount", | ||||
[missing_amount], | [missing_amount], | ||||
) | ) | ||||
invalid_privkey = good_stake.copy() | invalid_privkey = good_stake.copy() | ||||
invalid_privkey['privatekey'] = 'foobar' | invalid_privkey["privatekey"] = "foobar" | ||||
check_buildavalancheproof_error(-8, | check_buildavalancheproof_error( | ||||
-8, | |||||
"Invalid private key", | "Invalid private key", | ||||
[invalid_privkey], | [invalid_privkey], | ||||
) | ) | ||||
duplicate_stake = [good_stake] * 2 | duplicate_stake = [good_stake] * 2 | ||||
check_buildavalancheproof_error(-8, | check_buildavalancheproof_error( | ||||
-8, | |||||
"Duplicated stake", | "Duplicated stake", | ||||
duplicate_stake, | duplicate_stake, | ||||
) | ) | ||||
self.log.info("Happy path") | self.log.info("Happy path") | ||||
assert node.buildavalancheproof(0, 0, wif_privkey, [good_stake]) | assert node.buildavalancheproof(0, 0, wif_privkey, [good_stake]) | ||||
self.log.info("Check the payout address") | self.log.info("Check the payout address") | ||||
assert_raises_rpc_error(-8, | assert_raises_rpc_error( | ||||
-8, | |||||
"Invalid payout address", | "Invalid payout address", | ||||
node.buildavalancheproof, | node.buildavalancheproof, | ||||
0, | 0, | ||||
0, | 0, | ||||
wif_privkey, | wif_privkey, | ||||
[good_stake], | [good_stake], | ||||
"ecregtest:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcrl5mqkq", | "ecregtest:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcrl5mqkq", | ||||
) | ) | ||||
# Happy path | # Happy path | ||||
node.buildavalancheproof( | node.buildavalancheproof( | ||||
0, | 0, 0, wif_privkey, [good_stake], ADDRESS_ECREG_UNSPENDABLE | ||||
0, | ) | ||||
wif_privkey, | |||||
[good_stake], | |||||
ADDRESS_ECREG_UNSPENDABLE) | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
BuildAvalancheProofTest().main() | BuildAvalancheProofTest().main() |