Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bitcoin segwit and taproot tests in ragger #184

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/python/apps/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
BTC_CONF = create_currency_config("BTC", "Bitcoin")

BTC_PACKED_DERIVATION_PATH = bitcoin_pack_derivation_path(BtcDerivationPathFormat.BECH32, "m/84'/0'/0'/0/0")
BTC_SEGWIT_PACKED_DERIVATION_PATH = bitcoin_pack_derivation_path(BtcDerivationPathFormat.BECH32, "m/84'/0'/0'/0/10")
BTC_TAPROOT_PACKED_DERIVATION_PATH = bitcoin_pack_derivation_path(BtcDerivationPathFormat.BECH32M, "m/86'/0'/0'/0/6")

CHAIN = Chain.MAIN

Expand Down
4 changes: 3 additions & 1 deletion test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .ethereum import DAI_PACKED_DERIVATION_PATH, DAI_CONF

from .litecoin import LTC_PACKED_DERIVATION_PATH, LTC_CONF
from .bitcoin import BTC_PACKED_DERIVATION_PATH, BTC_CONF
from .bitcoin import BTC_PACKED_DERIVATION_PATH, BTC_CONF, BTC_SEGWIT_PACKED_DERIVATION_PATH, BTC_TAPROOT_PACKED_DERIVATION_PATH
from .stellar import XLM_PACKED_DERIVATION_PATH, XLM_CONF
from .solana_utils import SOL_PACKED_DERIVATION_PATH, SOL_CONF
from .xrp import XRP_PACKED_DERIVATION_PATH, XRP_CONF
Expand All @@ -37,6 +37,8 @@ def get_conf_for_ticker(self, overload_signer: Optional[SigningAuthority]=None)
ETC_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ETC", conf=ETC_CONF, packed_derivation_path=ETC_PACKED_DERIVATION_PATH)
ETH_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ETH", conf=ETH_CONF, packed_derivation_path=ETH_PACKED_DERIVATION_PATH)
BTC_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="BTC", conf=BTC_CONF, packed_derivation_path=BTC_PACKED_DERIVATION_PATH)
BTC_SEGWIT_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="BTC", conf=BTC_CONF, packed_derivation_path=BTC_SEGWIT_PACKED_DERIVATION_PATH)
BTC_TAPROOT_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="BTC", conf=BTC_CONF, packed_derivation_path=BTC_TAPROOT_PACKED_DERIVATION_PATH)
LTC_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="LTC", conf=LTC_CONF, packed_derivation_path=LTC_PACKED_DERIVATION_PATH)
XLM_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="XLM", conf=XLM_CONF, packed_derivation_path=XLM_PACKED_DERIVATION_PATH)
SOL_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="SOL", conf=SOL_CONF, packed_derivation_path=SOL_PACKED_DERIVATION_PATH)
Expand Down
155 changes: 112 additions & 43 deletions test/python/test_bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,10 @@
from .apps import cal as cal
from ledger_bitcoin import WalletPolicy

in_wallet = WalletPolicy(
"",
"wpkh(@0/**)",
[
"[f5acc2fd/84'/0'/0']xpub6DUYn4moKgHkK2d7bXX3mHTPb6XQwRVFRMdZ6ZwLS5u3nonGVpJiFeZiQkHutwdFqxKP75jex8gvVm7ed4euYeDtMnoiF1Cz1z4CeBJYWin"
],
)

out_wallet = WalletPolicy(
"",
"wpkh(@0/**)",
[
"xpub6CatWdiZiodmYVtWLtEQsAg1H9ooS1bmsJUBwQ83FE1Fyk386FWcyicJgEZv3quZSJKA5dh5Lo2PbubMGxCfZtRthV6ST2qquL9w3HSzcUn"
],
)

out_wallet_2 = WalletPolicy(
"",
"wpkh(@0/**)",
[
"xpub6D7atwj3ewAGT347tUzTNzfTGos1rCFVX4v8gViXiM2R1QHvox1LhEf6NtCeNsCwpppFUoQuS6mHUwfTveA5tEEwn2LqZHfVBEz5qvYmYhf"
],
)

# ExchangeTestRunner implementation for Bitcoin
class BitcoinTests(ExchangeTestRunner):

currency_configuration = cal.BTC_CURRENCY_CONFIGURATION
valid_destination_1 = BitcoinClient.get_address_from_wallet(out_wallet)
class BitcoinTestsCommon(ExchangeTestRunner):
valid_destination_memo_1 = ""
valid_destination_2 = BitcoinClient.get_address_from_wallet(out_wallet_2)
valid_destination_memo_2 = "0"
valid_refund = BitcoinClient.get_address_from_wallet(in_wallet)
valid_refund_memo = ""
valid_send_amount_1 = 20900000
valid_send_amount_2 = 446739662
Expand All @@ -50,25 +21,123 @@ class BitcoinTests(ExchangeTestRunner):
signature_refusal_error_code = BitcoinErrors.SW_SWAP_CHECKING_FAIL

def perform_final_tx(self, destination, send_amount, fees, memo):
if destination == BitcoinClient.get_address_from_wallet(out_wallet):
BitcoinClient(self.backend).send_simple_sign_tx(in_wallet=in_wallet,
fees=fees,
destination=out_wallet,
send_amount=send_amount)

elif destination == BitcoinClient.get_address_from_wallet(out_wallet_2):
BitcoinClient(self.backend).send_simple_sign_tx(in_wallet=in_wallet,
fees=fees,
destination=out_wallet_2,
send_amount=send_amount)
if destination == BitcoinClient.get_address_from_wallet(self.out_wallet):
BitcoinClient(self.backend).send_simple_sign_tx(in_wallet=self.in_wallet,
fees=fees,
destination=self.out_wallet,
send_amount=send_amount)

elif destination == BitcoinClient.get_address_from_wallet(self.out_wallet_2):
BitcoinClient(self.backend).send_simple_sign_tx(in_wallet=self.in_wallet,
fees=fees,
destination=self.out_wallet_2,
send_amount=send_amount)

# TODO : assert signature validity


# Use a class to reuse the same Speculos instance
class TestsBitcoin:
class BitcoinTests(BitcoinTestsCommon):
currency_configuration = cal.BTC_CURRENCY_CONFIGURATION
in_wallet = WalletPolicy(
"",
"wpkh(@0/**)",
[
"[f5acc2fd/84'/0'/0']xpub6DUYn4moKgHkK2d7bXX3mHTPb6XQwRVFRMdZ6ZwLS5u3nonGVpJiFeZiQkHutwdFqxKP75jex8gvVm7ed4euYeDtMnoiF1Cz1z4CeBJYWin"
],
)

out_wallet = WalletPolicy(
"",
"wpkh(@0/**)",
[
"xpub6CatWdiZiodmYVtWLtEQsAg1H9ooS1bmsJUBwQ83FE1Fyk386FWcyicJgEZv3quZSJKA5dh5Lo2PbubMGxCfZtRthV6ST2qquL9w3HSzcUn"
],
)

out_wallet_2 = WalletPolicy(
"",
"wpkh(@0/**)",
[
"xpub6D7atwj3ewAGT347tUzTNzfTGos1rCFVX4v8gViXiM2R1QHvox1LhEf6NtCeNsCwpppFUoQuS6mHUwfTveA5tEEwn2LqZHfVBEz5qvYmYhf"
],
)
valid_refund = BitcoinClient.get_address_from_wallet(in_wallet)
valid_destination_1 = BitcoinClient.get_address_from_wallet(out_wallet)
valid_destination_2 = BitcoinClient.get_address_from_wallet(out_wallet_2)

class TestsBitcoin:
@pytest.mark.parametrize('test_to_run', ALL_TESTS_EXCEPT_MEMO)
def test_bitcoin(self, backend, exchange_navigation_helper, test_to_run):
BitcoinTests(backend, exchange_navigation_helper).run_test(test_to_run)


class BitcoinTestsSegwit(BitcoinTestsCommon):
currency_configuration = cal.BTC_SEGWIT_CURRENCY_CONFIGURATION
in_wallet = WalletPolicy(
"",
"sh(wpkh(@0/**))",
[
"[f5acc2fd/84'/0'/0']xpub6DUYn4moKgHkK2d7bXX3mHTPb6XQwRVFRMdZ6ZwLS5u3nonGVpJiFeZiQkHutwdFqxKP75jex8gvVm7ed4euYeDtMnoiF1Cz1z4CeBJYWin"
],
)

out_wallet = WalletPolicy(
"",
"sh(wpkh(@0/**))",
[
"ypub6Ynvx7RLNYgWzFGM8aeU43hFNjTh7u5Grrup7Ryu2nKZ1Y8FWKaJZXiUrkJSnMmGVNBoVH1DNDtQ32tR4YFDRSpSUXjjvsiMnCvoPHVWXJP"
],
)

out_wallet_2 = WalletPolicy(
"",
"sh(wpkh(@0/**))",
[
"xpub6D7atwj3ewAGT347tUzTNzfTGos1rCFVX4v8gViXiM2R1QHvox1LhEf6NtCeNsCwpppFUoQuS6mHUwfTveA5tEEwn2LqZHfVBEz5qvYmYhf"
],
)
valid_refund = BitcoinClient.get_address_from_wallet(in_wallet)
valid_destination_1 = BitcoinClient.get_address_from_wallet(out_wallet)
valid_destination_2 = BitcoinClient.get_address_from_wallet(out_wallet_2)


class TestsBitcoinSegwit:
@pytest.mark.parametrize('test_to_run', ALL_TESTS_EXCEPT_MEMO)
def test_bitcoin_segwit(self, backend, exchange_navigation_helper, test_to_run):
BitcoinTestsSegwit(backend, exchange_navigation_helper).run_test(test_to_run)


class BitcoinTestsTaproot(BitcoinTestsCommon):
currency_configuration = cal.BTC_TAPROOT_CURRENCY_CONFIGURATION
in_wallet = WalletPolicy(
"",
"tr(@0/**)",
[
"[f5acc2fd/86'/0'/0']xpub6DUYn4moKgHkK2d7bXX3mHTPb6XQwRVFRMdZ6ZwLS5u3nonGVpJiFeZiQkHutwdFqxKP75jex8gvVm7ed4euYeDtMnoiF1Cz1z4CeBJYWin"
],
)

out_wallet = WalletPolicy(
"",
"tr(@0/**)",
[
"[f5acc2fd/86'/1'/0']tpubDDKYE6BREvDsSWMazgHoyQWiJwYaDDYPbCFjYxN3HFXJP5fokeiK4hwK5tTLBNEDBwrDXn8cQ4v9b2xdW62Xr5yxoQdMu1v6c7UDXYVH27U"
],
)

out_wallet_2 = WalletPolicy(
"",
"tr(@0/**)",
[
"xpub6D7atwj3ewAGT347tUzTNzfTGos1rCFVX4v8gViXiM2R1QHvox1LhEf6NtCeNsCwpppFUoQuS6mHUwfTveA5tEEwn2LqZHfVBEz5qvYmYhf"
],
)
valid_refund = BitcoinClient.get_address_from_wallet(in_wallet)
valid_destination_1 = BitcoinClient.get_address_from_wallet(out_wallet)
valid_destination_2 = BitcoinClient.get_address_from_wallet(out_wallet_2)

class TestsBitcoinTaproot:
@pytest.mark.parametrize('test_to_run', ALL_TESTS_EXCEPT_MEMO)
def test_bitcoin_taproot(self, backend, exchange_navigation_helper, test_to_run):
BitcoinTestsTaproot(backend, exchange_navigation_helper).run_test(test_to_run)