Skip to content

Commit ed9aa39

Browse files
committed
Fixing derivation path issue + adding tests
Fixing CircleCI
1 parent 394d5af commit ed9aa39

File tree

5 files changed

+107
-5
lines changed

5 files changed

+107
-5
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ jobs:
33
build:
44
docker:
55
- image: golang:1.10
6-
working_directory: /go/src/zondax/ledger-goclient
6+
working_directory: /go/src/zondax/ledger-cosmos-go
77
steps:
88
- checkout
99
- run: go get -v -u github.com/golang/dep/cmd/dep
1010
- run: dep ensure -v
11-
- run: go build ledger.go apduWrapper.go
11+
- run: go build *.go
1212
- run: go test
1313
workflows:
1414
version: 2

common.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ func getBip32bytes(bip32Path []uint32, hardenCount int) ([]byte, error) {
3737
for index, element := range bip32Path {
3838
pos := 1 + index*4
3939
value := element
40-
// Harden 0, 1, 2
41-
if index <= hardenCount {
40+
if index < hardenCount {
4241
value = 0x80000000 | element
4342
}
4443
binary.LittleEndian.PutUint32(message[pos:], value)

common_test.go

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*******************************************************************************
2+
* (c) 2018 ZondaX GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
16+
17+
package ledger_cosmos_go
18+
19+
import (
20+
"fmt"
21+
"github.com/stretchr/testify/assert"
22+
"testing"
23+
)
24+
25+
func Test_PathGeneration0(t *testing.T) {
26+
bip32Path := []uint32{44, 100, 0, 0, 0}
27+
28+
pathBytes, err := getBip32bytes(bip32Path, 0)
29+
30+
if err != nil {
31+
assert.FailNow(t, "Detected error, err: %s\n", err.Error())
32+
}
33+
34+
fmt.Printf("Path: %x\n", pathBytes)
35+
36+
assert.Equal(
37+
t,
38+
41,
39+
len(pathBytes),
40+
"PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41)
41+
42+
assert.Equal(
43+
t,
44+
"052c000000640000000000000000000000000000000000000000000000000000000000000000000000",
45+
fmt.Sprintf("%x", pathBytes),
46+
"Unexpected PathBytes\n")
47+
}
48+
49+
func Test_PathGeneration2(t *testing.T) {
50+
bip32Path := []uint32{44, 118, 0, 0, 0}
51+
52+
pathBytes, err := getBip32bytes(bip32Path, 2)
53+
54+
if err != nil {
55+
assert.FailNow(t, "Detected error, err: %s\n", err.Error())
56+
}
57+
58+
fmt.Printf("Path: %x\n", pathBytes)
59+
60+
assert.Equal(
61+
t,
62+
41,
63+
len(pathBytes),
64+
"PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41)
65+
66+
assert.Equal(
67+
t,
68+
"052c000080760000800000000000000000000000000000000000000000000000000000000000000000",
69+
fmt.Sprintf("%x", pathBytes),
70+
"Unexpected PathBytes\n")
71+
}
72+
73+
func Test_PathGeneration3(t *testing.T) {
74+
bip32Path := []uint32{44, 118, 0, 0, 0}
75+
76+
pathBytes, err := getBip32bytes(bip32Path, 3)
77+
78+
if err != nil {
79+
assert.FailNow(t, "Detected error, err: %s\n", err.Error())
80+
}
81+
82+
fmt.Printf("Path: %x\n", pathBytes)
83+
84+
assert.Equal(
85+
t,
86+
41,
87+
len(pathBytes),
88+
"PathBytes has wrong length: %x, expected length: %x\n", pathBytes, 41)
89+
90+
assert.Equal(
91+
t,
92+
"052c000080760000800000008000000000000000000000000000000000000000000000000000000000",
93+
fmt.Sprintf("%x", pathBytes),
94+
"Unexpected PathBytes\n")
95+
}

user_app_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build ledger_device
2+
13
/*******************************************************************************
24
* (c) 2018 ZondaX GmbH
35
*
@@ -41,7 +43,7 @@ func Test_UserGetVersion(t *testing.T) {
4143
assert.Equal(t, uint8(0x0), version.AppMode, "TESTING MODE ENABLED!!")
4244
assert.Equal(t, uint8(0x1), version.Major, "Wrong Major version")
4345
assert.Equal(t, uint8(0x0), version.Minor, "Wrong Minor version")
44-
assert.Equal(t, uint8(0x0), version.Patch, "Wrong Patch version")
46+
assert.Equal(t, uint8(0x1), version.Patch, "Wrong Patch version")
4547
}
4648

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

70+
fmt.Printf("PUBLIC KEY: %x\n", pubKey)
71+
6872
_, err = secp256k1.ParsePubKey(pubKey[:], secp256k1.S256())
6973
require.Nil(t, err, "Error parsing public key err: %s\n", err)
7074
}
7175

76+
// Ledger Test Mnemonic: equip will roof matter pink blind book anxiety banner elbow sun young
77+
7278
func getDummyTx() []byte {
7379
dummyTx := `{
7480
"account_number": 1,

validator_app_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build ledger_device
2+
13
/*******************************************************************************
24
* (c) 2018 ZondaX GmbH
35
*

0 commit comments

Comments
 (0)