|
| 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 | +} |
0 commit comments