-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorPriorityTest.java
More file actions
62 lines (48 loc) · 2.14 KB
/
Copy pathErrorPriorityTest.java
File metadata and controls
62 lines (48 loc) · 2.14 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
package com.example.bip39.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.example.bip39.error.Bip39ErrorCode;
import com.example.bip39.error.Bip39Exception;
import org.junit.jupiter.api.Test;
class ErrorPriorityTest {
private static final String INVALID_WORD_COUNT_WITH_UNKNOWN_WORD =
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon" + " typo";
private static final String WORD_NOT_IN_LIST_WITH_VALID_WORD_COUNT =
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"
+ " abandon typo";
@Test
void validateMnemonicPrioritizesFormatBeforeAnyDeeperChecks() {
DefaultBip39Service service = new DefaultBip39Service();
assertEquals(
Bip39ErrorCode.ERR_INVALID_MNEMONIC_FORMAT,
service.validateMnemonic("abandon abandon typo").errorCode());
}
@Test
void validateMnemonicPrioritizesWordCountBeforeWordListChecks() {
DefaultBip39Service service = new DefaultBip39Service();
assertEquals(
Bip39ErrorCode.ERR_INVALID_WORD_COUNT,
service.validateMnemonic(INVALID_WORD_COUNT_WITH_UNKNOWN_WORD).errorCode());
}
@Test
void validateMnemonicPrioritizesWordListBeforeChecksumMismatch() {
DefaultBip39Service service = new DefaultBip39Service();
assertEquals(
Bip39ErrorCode.ERR_WORD_NOT_IN_LIST,
service.validateMnemonic(WORD_NOT_IN_LIST_WITH_VALID_WORD_COUNT).errorCode());
}
@Test
void mnemonicToEntropyUsesSamePriorityOrder() {
DefaultBip39Service service = new DefaultBip39Service();
Bip39Exception invalidWordCount =
assertThrows(
Bip39Exception.class,
() -> service.mnemonicToEntropy(INVALID_WORD_COUNT_WITH_UNKNOWN_WORD));
assertEquals(Bip39ErrorCode.ERR_INVALID_WORD_COUNT, invalidWordCount.getErrorCode());
Bip39Exception wordNotInList =
assertThrows(
Bip39Exception.class,
() -> service.mnemonicToEntropy(WORD_NOT_IN_LIST_WITH_VALID_WORD_COUNT));
assertEquals(Bip39ErrorCode.ERR_WORD_NOT_IN_LIST, wordNotInList.getErrorCode());
}
}