|
5 | 5 |
|
6 | 6 | using Autarkysoft.Bitcoin.ImprovementProposals; |
7 | 7 | using FinderOuter.Models; |
| 8 | +using FinderOuter.Services.Comparers; |
8 | 9 | using FinderOuter.Services.SearchSpaces; |
9 | 10 | using System; |
10 | 11 | using System.Collections.Generic; |
@@ -176,16 +177,105 @@ public void ProcessTest(string mnemonic, char missChar, MnemonicTypes mnType, BI |
176 | 177 | } |
177 | 178 |
|
178 | 179 |
|
179 | | - private static MnemonicSearchSpace BuildSS(string s, int expMissCount, bool processResult) |
| 180 | + private static MnemonicSearchSpace BuildSS(string s, int expMissCount, bool processResult, |
| 181 | + MnemonicTypes mnType = MnemonicTypes.BIP39) |
180 | 182 | { |
181 | 183 | MnemonicSearchSpace ss = new(); |
182 | | - bool b = ss.Process(s, '*', MnemonicTypes.BIP39, BIP0039.WordLists.English, ElectrumMnemonic.MnemonicType.Standard, out _); |
| 184 | + bool b = ss.Process(s, '*', mnType, BIP0039.WordLists.English, ElectrumMnemonic.MnemonicType.Standard, out _); |
183 | 185 | Assert.Equal(expMissCount, ss.MissCount); |
184 | 186 | Assert.Equal(processResult, b); |
185 | 187 |
|
186 | 188 | return ss; |
187 | 189 | } |
188 | 190 |
|
| 191 | + |
| 192 | + public static IEnumerable<object[]> GetProcessNoMissingCases() |
| 193 | + { |
| 194 | + ICompareService comp_noInit = new PrvToAddrCompComparer(); |
| 195 | + |
| 196 | + ICompareService comp_wrongAddr = new PrvToAddrCompComparer(); |
| 197 | + Assert.True(comp_wrongAddr.Init(KeyHelper.Pub2CompAddr)); |
| 198 | + |
| 199 | + BIP0032Path path = new("m/84'/0'/0'/0/5"); |
| 200 | + ICompareService comp_noPass = new PrvToAddrCompComparer(); |
| 201 | + Assert.True(comp_noPass.Init("bc1qddpga3fkdgcc0wv64azacykr9vyrvqsahu0eeu")); |
| 202 | + |
| 203 | + ICompareService comp_withPass = new PrvToAddrCompComparer(); |
| 204 | + Assert.True(comp_withPass.Init("bc1qt5e7ynnrazrvcn64dwcwhjyu2wdjzygumtv8jj")); |
| 205 | + string pass = "foobar"; |
| 206 | + |
| 207 | + yield return new object[] |
| 208 | + { |
| 209 | + BuildSS(OneMiss, 1, true), new PrvToPubComparer(), null, null, false, |
| 210 | + "This method should not be called with missing characters (this is a bug)." |
| 211 | + }; |
| 212 | + yield return new object[] |
| 213 | + { |
| 214 | + BuildSS("shed slide night best wave buddy honey salmon fresh bitter seek seek", 0, true), comp_noInit, |
| 215 | + null, null, false, |
| 216 | + "Mnemonic is not missing any characters but is invalid. Error: Wrong checksum." |
| 217 | + }; |
| 218 | + yield return new object[] |
| 219 | + { |
| 220 | + BuildSS(NoMiss, 0, true, MnemonicTypes.Electrum), comp_noInit, |
| 221 | + null, null, false, |
| 222 | + "Mnemonic is not missing any characters but is invalid. Error: Invalid mnemonic (undefined version)." |
| 223 | + }; |
| 224 | + yield return new object[] |
| 225 | + { |
| 226 | + BuildSS(NoMiss, 0, true), comp_noInit, |
| 227 | + null, null, true, |
| 228 | + $"Given input is a valid BIP39 mnemonic.{Environment.NewLine}" + |
| 229 | + $"Set the derivation path correctly to verify the derived key/address." |
| 230 | + }; |
| 231 | + yield return new object[] |
| 232 | + { |
| 233 | + BuildSS(NoMiss, 0, true), null, |
| 234 | + null, path, true, |
| 235 | + $"Given input is a valid BIP39 mnemonic.{Environment.NewLine}" + |
| 236 | + $"Set the compare value correctly to verify the derived key/address." |
| 237 | + }; |
| 238 | + yield return new object[] |
| 239 | + { |
| 240 | + BuildSS(NoMiss, 0, true), comp_noInit, |
| 241 | + null, path, true, |
| 242 | + $"Given input is a valid BIP39 mnemonic.{Environment.NewLine}" + |
| 243 | + $"Set the compare value correctly to verify the derived key/address." |
| 244 | + }; |
| 245 | + yield return new object[] |
| 246 | + { |
| 247 | + BuildSS(NoMiss, 0, true), comp_wrongAddr, |
| 248 | + null, path, false, |
| 249 | + $"Given input is a valid BIP39 mnemonic.{Environment.NewLine}" + |
| 250 | + $"The given child key is not derived from this mnemonic or not at m/84'/0'/0'/0/5{Environment.NewLine}" + |
| 251 | + $"List of all address types that can be derived from this mnemonic at the given path:{Environment.NewLine}" |
| 252 | + }; |
| 253 | + yield return new object[] |
| 254 | + { |
| 255 | + BuildSS(NoMiss, 0, true), comp_noPass, |
| 256 | + null, path, true, |
| 257 | + $"Given input is a valid BIP39 mnemonic.{Environment.NewLine}" + |
| 258 | + $"The given child key is correctly derived from this mnemonic at m/84'/0'/0'/0/5" |
| 259 | + }; |
| 260 | + yield return new object[] |
| 261 | + { |
| 262 | + BuildSS(NoMiss, 0, true), comp_withPass, |
| 263 | + pass, path, true, |
| 264 | + $"Given input is a valid BIP39 mnemonic.{Environment.NewLine}" + |
| 265 | + $"The given child key is correctly derived from this mnemonic at m/84'/0'/0'/0/5" |
| 266 | + }; |
| 267 | + } |
| 268 | + [Theory] |
| 269 | + [MemberData(nameof(GetProcessNoMissingCases))] |
| 270 | + public void ProcessNoMissingTest(MnemonicSearchSpace ss, ICompareService comparer, string pass, BIP0032Path path, |
| 271 | + bool expected, string expMsg) |
| 272 | + { |
| 273 | + bool actual = ss.ProcessNoMissing(comparer, pass, path, out string message); |
| 274 | + Assert.Equal(expected, actual); |
| 275 | + Assert.Contains(expMsg, message); |
| 276 | + } |
| 277 | + |
| 278 | + |
189 | 279 | public static IEnumerable<object[]> GetSetValuesCases() |
190 | 280 | { |
191 | 281 | // The following cases test SearchSpaceBase.ProcessValues() method that is thoroughly tested elsewhere |
|
0 commit comments