Skip to content

Commit

Permalink
add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Jul 5, 2018
1 parent 8d7b9bc commit 7d45f93
Show file tree
Hide file tree
Showing 25 changed files with 1,412 additions and 32 deletions.
20 changes: 19 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions hdwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/tyler-smith/go-bip32"
"github.com/tyler-smith/go-bip39"
)

Expand Down Expand Up @@ -101,12 +102,22 @@ func (s Wallet) Derive(index interface{}) (*Wallet, error) {
idx = uint32(v)
case int16:
idx = uint32(v)
case int32:
idx = uint32(v)
case int64:
idx = uint32(v)
case uint:
idx = uint32(v)
case uint8:
idx = uint32(v)
case uint16:
idx = uint32(v)
case uint32:
idx = v
case uint64:
idx = uint32(v)
default:
return nil, errors.New("unsupported index type")
}

address, err := s.extendedKey.Child(idx)
Expand Down Expand Up @@ -209,3 +220,8 @@ func NewMnemonic() (string, error) {
}
return bip39.NewMnemonic(entropy)
}

// NewSeed ...
func NewSeed() ([]byte, error) {
return bip32.NewSeed()
}
69 changes: 38 additions & 31 deletions hdwallet_test.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
package hdwallet

import (
"fmt"
"log"
"testing"
)

// TODO: tests
// TODO: table test

func TestNew(t *testing.T) {
mnemonic := "tag volcano eight thank tide danger coast health above argue embrace heavy"
/*
seed, err := bip32.NewSeed()
if err != nil {
log.Fatalln("Error generating seed:", err)
}
*/
//seed := bip39.NewSeed(mnemonic, "")

wallet, err := New(Config{
root, err := New(Config{
Mnemonic: mnemonic,
Path: "",
Path: "m/44'/60'/0'/0",
})
if err != nil {
log.Fatal(err)
t.Error(err)
}

fmt.Println(wallet.PrivateKeyHex())
fmt.Println("")
fmt.Println(wallet.PublicKeyHex())
fmt.Println("")
fmt.Println(wallet.AddressHex())
fmt.Println("")
fmt.Println(wallet.Path())
if root.PrivateKeyHex() != "7657783b9ba4d4b16062337235432bbc5c80e3dce39fdc91e62d744fdb665cad" {
t.Error("wrong private key")
}

if root.PublicKeyHex() != "177c0776ca4c9e160822a1006eb6d236039eb882da8d7687ba20049d73e6230cae699eb8037aeeee2098d433d4210401a0cc1bf635c3fee2a40933d22c1206e7" {
t.Error("wrong public key")
}

if root.AddressHex() != "0xAF1c991f6068Ac832eC60A8557eF1C7D8B9BcCD6" {
t.Error("wrong address")
}

if root.Path() != `m/44'/60'/0'/0` {
t.Error("wrong hdpath")
}

wal, err := wallet.Derive(0)
wallet, err := root.Derive(0)
if err != nil {
log.Fatal(err)
}
fmt.Println(wal.PrivateKeyHex())
fmt.Println("")
fmt.Println(wal.PublicKeyHex())
fmt.Println("")
fmt.Println(wal.AddressHex())
fmt.Println("")
fmt.Println(wal.Path())
t.Error(err)
}

if wallet.PrivateKeyHex() != "63e21d10fd50155dbba0e7d3f7431a400b84b4c2ac1ee38872f82448fe3ecfb9" {
t.Error("wrong private key")
}

if wallet.PublicKeyHex() != "6005c86a6718f66221713a77073c41291cc3abbfcd03aa4955e9b2b50dbf7f9b6672dad0d46ade61e382f79888a73ea7899d9419becf1d6c9ec2087c1188fa18" {
t.Error("wrong public key")
}

if wallet.AddressHex() != "0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947" {
t.Error("wrong address")
}

if wallet.Path() != `m/44'/60'/0'/0/0` {
t.Error("wrong hdpath")
}
}
1 change: 1 addition & 0 deletions vendor/github.com/FactomProject/basen/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/FactomProject/basen/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/FactomProject/basen/README

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions vendor/github.com/FactomProject/basen/basen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/FactomProject/btcutilecc/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/FactomProject/btcutilecc/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions vendor/github.com/FactomProject/btcutilecc/arith.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d45f93

Please sign in to comment.