forked from bitcoin-education/bitcoin-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVarIntTest.java
More file actions
53 lines (47 loc) · 1.58 KB
/
VarIntTest.java
File metadata and controls
53 lines (47 loc) · 1.58 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
import org.bouncycastle.util.encoders.Hex;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import io.github.bitcoineducation.bitcoinjava.VarInt;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class VarIntTest {
@ParameterizedTest
@MethodSource("testStreamParameters")
public void fromByteStream(String hex, BigInteger expectedResult) throws IOException {
assertEquals(
expectedResult,
VarInt.fromByteStream(new ByteArrayInputStream(Hex.decodeStrict(hex)))
);
}
@ParameterizedTest
@MethodSource("testStreamParameters")
public void toByteStream(String expectedResult, BigInteger bigInteger) {
assertEquals(
expectedResult,
VarInt.toHex(bigInteger)
);
}
private static Stream<Arguments> testStreamParameters() {
return Stream.of(
Arguments.of(
"64", BigInteger.valueOf(100)
),
Arguments.of(
"fdff00", BigInteger.valueOf(255)
),
Arguments.of(
"fd2b02", BigInteger.valueOf(555)
),
Arguments.of(
"fe7f110100", BigInteger.valueOf(70015)
),
Arguments.of(
"ff6dc7ed3e60100000", BigInteger.valueOf(18005558675309L)
)
);
}
}