Skip to content

Commit

Permalink
Fixing derivation path issue + adding tests
Browse files Browse the repository at this point in the history
Fixing CircleCI
  • Loading branch information
jleni committed Jan 28, 2019
1 parent 394d5af commit ed9aa39
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ jobs:
build:
docker:
- image: golang:1.10
working_directory: /go/src/zondax/ledger-goclient
working_directory: /go/src/zondax/ledger-cosmos-go
steps:
- checkout
- run: go get -v -u github.com/golang/dep/cmd/dep
- run: dep ensure -v
- run: go build ledger.go apduWrapper.go
- run: go build *.go
- run: go test
workflows:
version: 2
Expand Down
3 changes: 1 addition & 2 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func getBip32bytes(bip32Path []uint32, hardenCount int) ([]byte, error) {
for index, element := range bip32Path {
pos := 1 + index*4
value := element
// Harden 0, 1, 2
if index <= hardenCount {
if index < hardenCount {
value = 0x80000000 | element
}
binary.LittleEndian.PutUint32(message[pos:], value)
Expand Down
95 changes: 95 additions & 0 deletions common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* (c) 2018 ZondaX GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

package ledger_cosmos_go

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_PathGeneration0(t *testing.T) {
bip32Path := []uint32{44, 100, 0, 0, 0}

pathBytes, err := getBip32bytes(bip32Path, 0)

if err != nil {
assert.FailNow(t, "Detected error, err: %s\n", err.Error())
}

fmt.Printf("Path: %x\n", pathBytes)

assert.Equal(
t,
41,
len(pathBytes),
"PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41)

assert.Equal(
t,
"052c000000640000000000000000000000000000000000000000000000000000000000000000000000",
fmt.Sprintf("%x", pathBytes),
"Unexpected PathBytes\n")
}

func Test_PathGeneration2(t *testing.T) {
bip32Path := []uint32{44, 118, 0, 0, 0}

pathBytes, err := getBip32bytes(bip32Path, 2)

if err != nil {
assert.FailNow(t, "Detected error, err: %s\n", err.Error())
}

fmt.Printf("Path: %x\n", pathBytes)

assert.Equal(
t,
41,
len(pathBytes),
"PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41)

assert.Equal(
t,
"052c000080760000800000000000000000000000000000000000000000000000000000000000000000",
fmt.Sprintf("%x", pathBytes),
"Unexpected PathBytes\n")
}

func Test_PathGeneration3(t *testing.T) {
bip32Path := []uint32{44, 118, 0, 0, 0}

pathBytes, err := getBip32bytes(bip32Path, 3)

if err != nil {
assert.FailNow(t, "Detected error, err: %s\n", err.Error())
}

fmt.Printf("Path: %x\n", pathBytes)

assert.Equal(
t,
41,
len(pathBytes),
"PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41)

assert.Equal(
t,
"052c000080760000800000008000000000000000000000000000000000000000000000000000000000",
fmt.Sprintf("%x", pathBytes),
"Unexpected PathBytes\n")
}
8 changes: 7 additions & 1 deletion user_app_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build ledger_device

/*******************************************************************************
* (c) 2018 ZondaX GmbH
*
Expand Down Expand Up @@ -41,7 +43,7 @@ func Test_UserGetVersion(t *testing.T) {
assert.Equal(t, uint8(0x0), version.AppMode, "TESTING MODE ENABLED!!")
assert.Equal(t, uint8(0x1), version.Major, "Wrong Major version")
assert.Equal(t, uint8(0x0), version.Minor, "Wrong Minor version")
assert.Equal(t, uint8(0x0), version.Patch, "Wrong Patch version")
assert.Equal(t, uint8(0x1), version.Patch, "Wrong Patch version")
}

func Test_UserGetPublicKey(t *testing.T) {
Expand All @@ -65,10 +67,14 @@ func Test_UserGetPublicKey(t *testing.T) {
len(pubKey),
"Public key has wrong length: %x, expected length: %x\n", pubKey, 65)

fmt.Printf("PUBLIC KEY: %x\n", pubKey)

_, err = secp256k1.ParsePubKey(pubKey[:], secp256k1.S256())
require.Nil(t, err, "Error parsing public key err: %s\n", err)
}

// Ledger Test Mnemonic: equip will roof matter pink blind book anxiety banner elbow sun young

func getDummyTx() []byte {
dummyTx := `{
"account_number": 1,
Expand Down
2 changes: 2 additions & 0 deletions validator_app_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build ledger_device

/*******************************************************************************
* (c) 2018 ZondaX GmbH
*
Expand Down

0 comments on commit ed9aa39

Please sign in to comment.