-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultBip39ServiceTest.java
More file actions
82 lines (67 loc) · 2.9 KB
/
Copy pathDefaultBip39ServiceTest.java
File metadata and controls
82 lines (67 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.example.bip39.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.example.bip39.error.Bip39ErrorCode;
import com.example.bip39.error.Bip39Exception;
import com.example.bip39.model.ValidationResult;
import com.example.bip39.wordlist.EnglishWordList;
import java.util.List;
import org.junit.jupiter.api.Test;
class DefaultBip39ServiceTest {
@Test
void defaultServiceLoadsValidatedEnglishWordList() {
DefaultBip39Service service = new DefaultBip39Service();
assertSame(EnglishWordList.getInstance(), service.wordList());
}
@Test
void servicesShareSingleLoadedWordListInstance() {
DefaultBip39Service first = new DefaultBip39Service();
DefaultBip39Service second = new DefaultBip39Service();
assertSame(first.wordList(), second.wordList());
}
@Test
void methodsBeyondParsingRemainExplicitlyUnimplementedForNormalizedInputs() {
DefaultBip39Service service = new DefaultBip39Service();
assertThrows(
UnsupportedOperationException.class, () -> service.entropyToMnemonic(new byte[16]));
assertThrows(
UnsupportedOperationException.class,
() -> service.mnemonicToEntropy("abandon ability able"));
assertThrows(
UnsupportedOperationException.class,
() -> service.mnemonicToEntropy(List.of("abandon", "ability", "able")));
assertThrows(
UnsupportedOperationException.class,
() -> service.validateMnemonic("abandon ability able"));
assertThrows(
UnsupportedOperationException.class,
() -> service.validateMnemonic(List.of("abandon", "ability", "able")));
assertThrows(
UnsupportedOperationException.class,
() -> service.mnemonicToSeed("abandon ability", "TREZOR"));
assertThrows(
UnsupportedOperationException.class,
() -> service.mnemonicToSeed(List.of("abandon", "ability"), "TREZOR"));
}
@Test
void mnemonicToEntropyRejectsInvalidFormatBeforeCoreLogic() {
DefaultBip39Service service = new DefaultBip39Service();
Bip39Exception exception =
assertThrows(
Bip39Exception.class, () -> service.mnemonicToEntropy(" abandon ability able"));
assertEquals(Bip39ErrorCode.ERR_INVALID_MNEMONIC_FORMAT, exception.getErrorCode());
}
@Test
void validateMnemonicReturnsFormatFailureBeforeValidationLogic() {
DefaultBip39Service service = new DefaultBip39Service();
ValidationResult result = service.validateMnemonic("abandon ability able");
assertFalse(result.ok());
assertEquals(Bip39ErrorCode.ERR_INVALID_MNEMONIC_FORMAT, result.errorCode());
assertNull(result.normalizedMnemonic());
assertNull(result.wordCount());
assertNull(result.invalidWord());
}
}