ledger_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package usbwallet
  17. /*
  18. func TestLedgerHub(t *testing.T) {
  19. glog.SetV(6)
  20. glog.SetToStderr(true)
  21. // Create a USB hub watching for Ledger devices
  22. hub, err := NewLedgerHub()
  23. if err != nil {
  24. t.Fatalf("Failed to create Ledger hub: %v", err)
  25. }
  26. defer hub.Close()
  27. // Wait for events :P
  28. time.Sleep(time.Minute)
  29. }
  30. */
  31. /*
  32. func TestLedger(t *testing.T) {
  33. // Create a USB context to access devices through
  34. ctx, err := usb.NewContext()
  35. defer ctx.Close()
  36. ctx.Debug(6)
  37. // List all of the Ledger wallets
  38. wallets, err := findLedgerWallets(ctx)
  39. if err != nil {
  40. t.Fatalf("Failed to list Ledger wallets: %v", err)
  41. }
  42. // Retrieve the address from every one of them
  43. for _, wallet := range wallets {
  44. // Retrieve the version of the wallet app
  45. ver, err := wallet.Version()
  46. if err != nil {
  47. t.Fatalf("Failed to retrieve wallet version: %v", err)
  48. }
  49. fmt.Printf("Ledger version: %s\n", ver)
  50. // Retrieve the address of the wallet
  51. addr, err := wallet.Address()
  52. if err != nil {
  53. t.Fatalf("Failed to retrieve wallet address: %v", err)
  54. }
  55. fmt.Printf("Ledger address: %x\n", addr)
  56. // Try to sign a transaction with the wallet
  57. unsigned := types.NewTransaction(1, common.HexToAddress("0xbabababababababababababababababababababa"), common.Ether, big.NewInt(20000), common.Shannon, nil)
  58. signed, err := wallet.Sign(unsigned)
  59. if err != nil {
  60. t.Fatalf("Failed to sign transactions: %v", err)
  61. }
  62. signer, err := types.Sender(types.NewEIP155Signer(big.NewInt(1)), signed)
  63. if err != nil {
  64. t.Fatalf("Failed to recover signer: %v", err)
  65. }
  66. fmt.Printf("Ledger signature by: %x\n", signer)
  67. }
  68. }*/