ledger_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // +build !ios
  17. package usbwallet
  18. /*
  19. func TestLedgerHub(t *testing.T) {
  20. glog.SetV(6)
  21. glog.SetToStderr(true)
  22. // Create a USB hub watching for Ledger devices
  23. hub, err := NewLedgerHub()
  24. if err != nil {
  25. t.Fatalf("Failed to create Ledger hub: %v", err)
  26. }
  27. defer hub.Close()
  28. // Wait for events :P
  29. time.Sleep(time.Minute)
  30. }
  31. */
  32. /*
  33. func TestLedger(t *testing.T) {
  34. // Create a USB context to access devices through
  35. ctx, err := usb.NewContext()
  36. defer ctx.Close()
  37. ctx.Debug(6)
  38. // List all of the Ledger wallets
  39. wallets, err := findLedgerWallets(ctx)
  40. if err != nil {
  41. t.Fatalf("Failed to list Ledger wallets: %v", err)
  42. }
  43. // Retrieve the address from every one of them
  44. for _, wallet := range wallets {
  45. // Retrieve the version of the wallet app
  46. ver, err := wallet.Version()
  47. if err != nil {
  48. t.Fatalf("Failed to retrieve wallet version: %v", err)
  49. }
  50. fmt.Printf("Ledger version: %s\n", ver)
  51. // Retrieve the address of the wallet
  52. addr, err := wallet.Address()
  53. if err != nil {
  54. t.Fatalf("Failed to retrieve wallet address: %v", err)
  55. }
  56. fmt.Printf("Ledger address: %x\n", addr)
  57. // Try to sign a transaction with the wallet
  58. unsigned := types.NewTransaction(1, common.HexToAddress("0xbabababababababababababababababababababa"), common.Ether, big.NewInt(20000), common.Shannon, nil)
  59. signed, err := wallet.Sign(unsigned)
  60. if err != nil {
  61. t.Fatalf("Failed to sign transactions: %v", err)
  62. }
  63. signer, err := types.Sender(types.NewEIP155Signer(big.NewInt(1)), signed)
  64. if err != nil {
  65. t.Fatalf("Failed to recover signer: %v", err)
  66. }
  67. fmt.Printf("Ledger signature by: %x\n", signer)
  68. }
  69. }*/