@@ -34,6 +34,7 @@ import (
34
34
"path/filepath"
35
35
"regexp"
36
36
"runtime"
37
+ "strings"
37
38
"sync"
38
39
"testing"
39
40
"time"
@@ -44,6 +45,8 @@ import (
44
45
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/maketx"
45
46
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/types"
46
47
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
48
+ "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/eth"
49
+ "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/ltc"
47
50
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/config"
48
51
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/signing"
49
52
"github.com/BitBoxSwiss/bitbox-wallet-app/util/errp"
@@ -61,13 +64,16 @@ import (
61
64
"github.com/btcsuite/btcd/chaincfg"
62
65
"github.com/btcsuite/btcd/chaincfg/chainhash"
63
66
"github.com/btcsuite/btcd/wire"
67
+ "github.com/ethereum/go-ethereum/params"
64
68
"github.com/stretchr/testify/require"
65
69
)
66
70
67
71
var (
68
72
log = logging .Get ().WithGroup ("simulator tx signing test" )
69
73
network = & chaincfg .MainNetParams
70
- coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , coinpkg .BtcUnitDefault , network , "." , []* config.ServerInfo {}, "https://blockstream.info/testnet/tx/" , socksproxy .NewSocksProxy (false , "" ))
74
+ coinBTC = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , coinpkg .BtcUnitDefault , network , "." , []* config.ServerInfo {}, "https://blockstream.info/testnet/tx/" , socksproxy .NewSocksProxy (false , "" ))
75
+ coinLTC = btc .NewCoin (coinpkg .CodeLTC , "Litecoin" , "LTC" , coinpkg .BtcUnitDefault , & ltc .MainNetParams , "." , []* config.ServerInfo {}, "" , socksproxy .NewSocksProxy (false , "" ))
76
+ coinETH = eth .NewCoin (nil , "Etheruem" , "ETH" , "ETH" , "ETH" , params .MainnetChainConfig , "" , nil , nil )
71
77
)
72
78
73
79
func mustKeypath (keypath string ) signing.AbsoluteKeypath {
@@ -309,14 +315,15 @@ func TestSimulatorExtendedPublicKeyBTC(t *testing.T) {
309
315
testInitializedSimulators (t , func (t * testing.T , device * Device , stdOut * bytes.Buffer ) {
310
316
t .Helper ()
311
317
keypath := mustKeypath ("m/84'/1'/0'" )
312
- xpub , err := device .Keystore ().ExtendedPublicKey (coin , keypath )
318
+ xpub , err := device .Keystore ().ExtendedPublicKey (coinBTC , keypath )
313
319
require .NoError (t , err )
314
320
require .Equal (t ,
315
321
"xpub6CAkM5q77qFTdrsoqguwTxAnnPVRd4hyHntZaYr9FTcefWi3AaTevG1YTvWzkNuqtshjQnJxpw1YjKLtuQvfvDiDiLVx2XYKZW5baGsRUuC" ,
316
322
xpub .String (),
317
323
)
318
324
})
319
325
}
326
+
320
327
func makeConfig (t * testing.T , device * Device , scriptType signing.ScriptType , keypath signing.AbsoluteKeypath ) * signing.Configuration {
321
328
t .Helper ()
322
329
xpubStr , err := device .BTCXPub (messages .BTCCoin_BTC , keypath .ToUInt32 (), messages .BTCPubRequest_XPUB , false )
@@ -395,7 +402,7 @@ func makeTx(t *testing.T, device *Device, recipient *maketx.OutputInfo) *btc.Pro
395
402
outputAmount := int64 (250_000_000 )
396
403
feePerKb := btcutil .Amount (1000 )
397
404
txProposal , err := maketx .NewTx (
398
- coin ,
405
+ coinBTC ,
399
406
spendableOutputs ,
400
407
recipient ,
401
408
outputAmount ,
@@ -550,3 +557,122 @@ func TestSimulatorSignBTCTransactionSilentPayment(t *testing.T) {
550
557
require .True (t , found )
551
558
})
552
559
}
560
+
561
+ func TestSimulatorVerifyAddressBTC (t * testing.T ) {
562
+ testInitializedSimulators (t , func (t * testing.T , device * Device , stdOut * bytes.Buffer ) {
563
+ t .Helper ()
564
+
565
+ type test struct {
566
+ coin coinpkg.Coin
567
+ accountConfiguration * signing.Configuration
568
+ derivation types.Derivation
569
+ expectedAddress string
570
+ }
571
+ tests := []test {
572
+ {
573
+ coin : coinBTC ,
574
+ accountConfiguration : makeConfig (t , device , signing .ScriptTypeP2TR , mustKeypath ("m/86'/0'/0'" )),
575
+ derivation : types.Derivation {Change : false , AddressIndex : 0 },
576
+ expectedAddress : "bc1pg848p0rvmj0r3j064prlpw0gecyzkwlpt7ndzdlmh2mvkyu299psetgxhf" ,
577
+ },
578
+ {
579
+ coin : coinBTC ,
580
+ accountConfiguration : makeConfig (t , device , signing .ScriptTypeP2TR , mustKeypath ("m/86'/0'/0'" )),
581
+ derivation : types.Derivation {Change : true , AddressIndex : 10 },
582
+ expectedAddress : "bc1pru6697hz78fxc7dvz36qvgkne59kht86eyk7cefc6hpvgud4z76qxjc8we" ,
583
+ },
584
+ {
585
+ coin : coinBTC ,
586
+ accountConfiguration : makeConfig (t , device , signing .ScriptTypeP2WPKH , mustKeypath ("m/84'/0'/0'" )),
587
+ derivation : types.Derivation {Change : false , AddressIndex : 0 },
588
+ expectedAddress : "bc1qljxfdh29amtq6u2xgltc0e6d9vemtt5m6mc5nd" ,
589
+ },
590
+ {
591
+ coin : coinBTC ,
592
+ accountConfiguration : makeConfig (t , device , signing .ScriptTypeP2WPKHP2SH , mustKeypath ("m/49'/0'/0'" )),
593
+ derivation : types.Derivation {Change : false , AddressIndex : 0 },
594
+ expectedAddress : "3PSdXEXzzmqVXSV6DECyaaaaDYVyaHQ8AD" ,
595
+ },
596
+ }
597
+ if device .Version ().AtLeast (semver .NewSemVer (9 , 23 , 0 )) {
598
+ // Litecoin was not enabled in the simulator before v9.23.0.
599
+ tests = append (tests ,
600
+ test {
601
+ coin : coinLTC ,
602
+ accountConfiguration : makeConfig (t , device , signing .ScriptTypeP2WPKH , mustKeypath ("m/84'/2'/0'" )),
603
+ derivation : types.Derivation {Change : false , AddressIndex : 0 },
604
+ expectedAddress : "ltc1qmgh3jwrt636mya08dytcsm7gxsxva8ckcu93jm" ,
605
+ },
606
+ test {
607
+ coin : coinLTC ,
608
+ accountConfiguration : makeConfig (t , device , signing .ScriptTypeP2WPKHP2SH , mustKeypath ("m/49'/2'/0'" )),
609
+ derivation : types.Derivation {Change : false , AddressIndex : 0 },
610
+ expectedAddress : "MFbeAVCwWdVvi5SeZh4zTpyz2gfPFdhs9c" ,
611
+ },
612
+ )
613
+ }
614
+
615
+ for _ , test := range tests {
616
+ stdOut .Truncate (0 )
617
+
618
+ addressConfiguration , err := test .accountConfiguration .Derive (
619
+ signing .NewEmptyRelativeKeypath ().
620
+ Child (test .derivation .SimpleChainIndex (), signing .NonHardened ).
621
+ Child (test .derivation .AddressIndex , signing .NonHardened ),
622
+ )
623
+ require .NoError (t , err )
624
+ require .NoError (t , device .Keystore ().VerifyAddress (addressConfiguration , test .coin ))
625
+ require .Eventually (t ,
626
+ func () bool {
627
+ return strings .Contains (
628
+ stdOut .String (),
629
+ fmt .Sprintf (
630
+ "CONFIRM SCREEN START\n TITLE: %s\n BODY: %s\n CONFIRM SCREEN END\n " ,
631
+ test .coin .Name (), test .expectedAddress ))
632
+ },
633
+ time .Second , 10 * time .Millisecond )
634
+ }
635
+ })
636
+ }
637
+
638
+ func TestSimulatorVerifyAddressETH (t * testing.T ) {
639
+ testInitializedSimulators (t , func (t * testing.T , device * Device , stdOut * bytes.Buffer ) {
640
+ t .Helper ()
641
+
642
+ type test struct {
643
+ keypath signing.AbsoluteKeypath
644
+ expectedAddress string
645
+ }
646
+
647
+ tests := []test {
648
+ {
649
+ keypath : mustKeypath ("m/44'/60'/0'/0/0" ),
650
+ expectedAddress : "0x416E88840Eb6353E49252Da2a2c140eA1f969D1a" ,
651
+ },
652
+ {
653
+ keypath : mustKeypath ("m/44'/60'/0'/0/1" ),
654
+ expectedAddress : "0x6A2A567cB891DeF8eA8C215C85f93d2f0F844ceB" ,
655
+ },
656
+ }
657
+
658
+ for _ , test := range tests {
659
+ xpub , err := device .Keystore ().ExtendedPublicKey (coinETH , test .keypath )
660
+ require .NoError (t , err )
661
+ stdOut .Truncate (0 )
662
+
663
+ addressConfiguration := signing .NewEthereumConfiguration (
664
+ []byte {1 , 2 , 3 , 4 }, test .keypath , xpub )
665
+
666
+ require .NoError (t , device .Keystore ().VerifyAddress (addressConfiguration , coinETH ))
667
+ require .Eventually (t ,
668
+ func () bool {
669
+ return strings .Contains (
670
+ stdOut .String (),
671
+ fmt .Sprintf (
672
+ "CONFIRM SCREEN START\n TITLE: Ethereum\n BODY: %s\n CONFIRM SCREEN END\n " ,
673
+ test .expectedAddress ))
674
+ },
675
+ time .Second , 10 * time .Millisecond )
676
+ }
677
+ })
678
+ }
0 commit comments