forked from bitcoin-education/bitcoin-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicKeyTest.java
More file actions
40 lines (35 loc) · 1.71 KB
/
PublicKeyTest.java
File metadata and controls
40 lines (35 loc) · 1.71 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
import io.github.bitcoineducation.bitcoinjava.PublicKey;
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 java.math.BigInteger;
import java.util.stream.Stream;
import static io.github.bitcoineducation.bitcoinjava.AddressConstants.MAINNET_P2WPKH_ADDRESS_PREFIX;
import static io.github.bitcoineducation.bitcoinjava.PublicKey.taprootInternalKeyFromX;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PublicKeyTest {
@ParameterizedTest
@MethodSource("taprootAddressParameters")
public void taprootAddress(String internalKeyX, String expectedAddress) {
PublicKey internalKey = taprootInternalKeyFromX(new BigInteger(1, Hex.decode(internalKeyX)));
PublicKey outputKey = internalKey.toTaprootSingleKeyOutputKey();
assertEquals(expectedAddress, outputKey.taprootAddress(MAINNET_P2WPKH_ADDRESS_PREFIX));
}
private static Stream<Arguments> taprootAddressParameters() {
return Stream.of(
Arguments.of(
"cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115",
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr"
),
Arguments.of(
"83dfe85a3151d2517290da461fe2815591ef69f2b18a2ce63f01697a8b313145",
"bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh"
),
Arguments.of(
"399f1b2f4393f29a18c937859c5dd8a77350103157eb880f02e8c08214277cef",
"bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7"
)
);
}
}