MultiBit HD / Technical library
INDEPENDENT KEYCHAINX RESOURCE
WalletId tests: formatting and round trips
Tests provide concrete expectations around identifiers and their representation. They are useful for following the implementation without using private wallet data. They are not evidence that a particular user-owned wallet has been recovered.
Source inspection only. Historical Java code; not executed or security-audited for this publication.
mbhd-core/src/test/java/org/multibit/hd/core/dto/WalletIdTest.java
View the exact upstream file · Read raw source · License notices
SHA-256: 546925b888282fb4da01cdf1576f77c197b6a33577ff329efe0dda5c3527a6ca
1package org.multibit.hd.core.dto;23/**4 * Copyright 2014 multibit.org5 *6 * Licensed under the MIT license (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://opensource.org/licenses/mit-license.php11 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819import org.bitcoinj.core.Utils;20import org.junit.Before;21import org.junit.Test;22import org.multibit.hd.brit.core.seed_phrase.Bip39SeedPhraseGenerator;23import org.multibit.hd.brit.core.seed_phrase.SeedPhraseGenerator;2425import java.io.File;26import java.util.Arrays;2728import static org.fest.assertions.Assertions.assertThat;2930public class WalletIdTest {31 public static final String SEED_PHRASE_1 = "letter advice cage absurd amount doctor acoustic avoid letter advice cage above";32 public static final String WALLET_ID_1 = "5c81964a030c3b659dc56fe63dbe27aef3370750";33 private static final String WALLET_ID_FORMATTED_1 = "5c81964a-030c3b65-9dc56fe6-3dbe27ae-f3370750";3435 public static final String SEED_PHRASE_2 = "require want tube elegant juice cool cup noble town poem plate harsh";36 private static final String WALLET_ID_2 = "a0bf136f8ce97d0358b4b29a87f6662cf14e594f";37 private static final String WALLET_ID_FORMATTED_2 = "a0bf136f-8ce97d03-58b4b29a-87f6662c-f14e594f";3839 public static final String SEED_PHRASE_3 = "morning truly witness grass pill typical blur then notable session exact coyote word noodle dentist hurry ability dignity";40 private static final String WALLET_ID_3 = "621a029836c3d152ae62134fb8ff7618900c5f9a";41 private static final String WALLET_ID_FORMATTED_3 = "621a0298-36c3d152-ae62134f-b8ff7618-900c5f9a";4243 @Before44 public void setUp() throws Exception {45 }4647 @Test48 public void testCreateWalletId1() throws Exception {49 SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator();50 byte[] seed = seedGenerator.convertToSeed(Bip39SeedPhraseGenerator.split(SEED_PHRASE_1));5152 WalletId walletId = new WalletId(seed);5354 assertThat(walletId).isNotNull();55 assertThat(walletId.getBytes()).isNotNull();56 String walletIdString = Utils.HEX.encode(walletId.getBytes());57 assertThat(walletIdString).isEqualTo(WALLET_ID_1);58 assertThat(walletId.toFormattedString()).isEqualTo(WALLET_ID_FORMATTED_1);5960 WalletId walletIdPhoenix = WalletId.parseWalletFilename(File.separator + "herp" + File.separator + "derp" +61 File.separator + "mbhd-" + walletId.toFormattedString() + File.separator + "mbhd.wallet");62 assertThat(walletId.equals(walletIdPhoenix)).isTrue();6364 // Generate the wallet Id again - it should get the same result.65 WalletId walletId2 = new WalletId(seed);66 assertThat(walletId2).isNotNull();67 assertThat(walletId2.getBytes()).isNotNull();6869 assertThat(Arrays.equals(walletId.getBytes(), walletId2.getBytes())).isTrue();70 }7172 @Test73 public void testCreateWalletId2() throws Exception {74 SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator();75 byte[] seed = seedGenerator.convertToSeed(Bip39SeedPhraseGenerator.split(SEED_PHRASE_2));7677 WalletId walletId = new WalletId(seed);7879 assertThat(walletId).isNotNull();80 assertThat(walletId.getBytes()).isNotNull();81 String walletIdString = Utils.HEX.encode(walletId.getBytes());82 assertThat(walletIdString).isEqualTo(WALLET_ID_2);83 assertThat(walletId.toFormattedString()).isEqualTo(WALLET_ID_FORMATTED_2);8485 }8687 @Test88 public void testCreateWalletId3() throws Exception {89 SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator();90 byte[] seed = seedGenerator.convertToSeed(Bip39SeedPhraseGenerator.split(SEED_PHRASE_3));9192 WalletId walletId = new WalletId(seed);9394 assertThat(walletId).isNotNull();95 assertThat(walletId.getBytes()).isNotNull();96 String walletIdString = Utils.HEX.encode(walletId.getBytes());97 assertThat(walletIdString).isEqualTo(WALLET_ID_3);98 assertThat(walletId.toFormattedString()).isEqualTo(WALLET_ID_FORMATTED_3);99100 }101}102Read in context
Tests provide concrete expectations around identifiers and their representation. They are useful for following the implementation without using private wallet data. They are not evidence that a particular user-owned wallet has been recovered.
Compare the callers, dependency versions and corresponding tests. The pinned file is one part of a larger application. Do not execute write, prune or migration routines against your only copy of a wallet.