aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/usbwallet/ledger_test.go
blob: 16a1e0b3fd416875525147df68192783ffc2e57a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// +build !ios

package usbwallet

/*
func TestLedgerHub(t *testing.T) {
    glog.SetV(6)
    glog.SetToStderr(true)

    // Create a USB hub watching for Ledger devices
    hub, err := NewLedgerHub()
    if err != nil {
        t.Fatalf("Failed to create Ledger hub: %v", err)
    }
    defer hub.Close()

    // Wait for events :P
    time.Sleep(time.Minute)
}
*/
/*
func TestLedger(t *testing.T) {
    // Create a USB context to access devices through
    ctx, err := usb.NewContext()
    defer ctx.Close()
    ctx.Debug(6)

    // List all of the Ledger wallets
    wallets, err := findLedgerWallets(ctx)
    if err != nil {
        t.Fatalf("Failed to list Ledger wallets: %v", err)
    }
    // Retrieve the address from every one of them
    for _, wallet := range wallets {
        // Retrieve the version of the wallet app
        ver, err := wallet.Version()
        if err != nil {
            t.Fatalf("Failed to retrieve wallet version: %v", err)
        }
        fmt.Printf("Ledger version: %s\n", ver)

        // Retrieve the address of the wallet
        addr, err := wallet.Address()
        if err != nil {
            t.Fatalf("Failed to retrieve wallet address: %v", err)
        }
        fmt.Printf("Ledger address: %x\n", addr)

        // Try to sign a transaction with the wallet
        unsigned := types.NewTransaction(1, common.HexToAddress("0xbabababababababababababababababababababa"), common.Ether, big.NewInt(20000), common.Shannon, nil)
        signed, err := wallet.Sign(unsigned)
        if err != nil {
            t.Fatalf("Failed to sign transactions: %v", err)
        }
        signer, err := types.Sender(types.NewEIP155Signer(big.NewInt(1)), signed)
        if err != nil {
            t.Fatalf("Failed to recover signer: %v", err)
        }
        fmt.Printf("Ledger signature by: %x\n", signer)
    }
}*/