Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_rpc_buildavalancheproof.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2021 The Bitcoin developers | # Copyright (c) 2021 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the buildavalancheproof RPC""" | """Test the buildavalancheproof RPC""" | ||||
from test_framework.avatools import create_coinbase_stakes | from test_framework.avatools import create_coinbase_stakes | ||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
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 = [['-enableavalanche=1', '-avacooldown=0']] | self.extra_args = [['-enableavalanche=1', '-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 = node.generatetoaddress(2, addrkey0.address) | blockhashes = node.generatetoaddress(2, addrkey0.address) | ||||
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()) | |||||
proof_master = privkey.get_pubkey().get_bytes().hex() | |||||
def check_buildavalancheproof_error( | def check_buildavalancheproof_error( | ||||
error_code, error_message, stakes): | 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 | master_key, | ||||
proof_master, | |||||
stakes, | stakes, | ||||
) | ) | ||||
good_stake = stakes[0] | good_stake = stakes[0] | ||||
self.log.info("Error cases") | self.log.info("Error cases") | ||||
check_buildavalancheproof_error(-8, | |||||
"Invalid master key", | |||||
[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 must be positive", | "vout must be positive", | ||||
[negative_vout], | [negative_vout], | ||||
) | ) | ||||
zero_height = good_stake.copy() | zero_height = good_stake.copy() | ||||
Show All 25 Lines | def run_test(self): | ||||
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, proof_master, [good_stake]) | assert node.buildavalancheproof(0, 0, wif_privkey, [good_stake]) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
BuildAvalancheProofTest().main() | BuildAvalancheProofTest().main() |