Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test in BitcoinUtilsTest to use deterministic keys #2766

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinTestUtils.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package co.rsk.peg.bitcoin;

import static co.rsk.bitcoinj.script.ScriptBuilder.createP2SHOutputScript;
import static co.rsk.peg.bitcoin.BitcoinUtils.extractRedeemScriptFromInput;

import co.rsk.bitcoinj.core.*;
import co.rsk.bitcoinj.crypto.TransactionSignature;
import co.rsk.bitcoinj.script.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

import co.rsk.bitcoinj.script.ScriptChunk;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.HashUtil;

import static co.rsk.bitcoinj.script.ScriptBuilder.createP2SHOutputScript;
import static co.rsk.peg.bitcoin.BitcoinUtils.extractRedeemScriptFromInput;

public class BitcoinTestUtils {

public static BtcECKey getBtcEcKeyFromSeed(String seed) {
byte[] serializedSeed = HashUtil.keccak256(seed.getBytes(StandardCharsets.UTF_8));
return BtcECKey.fromPrivate(serializedSeed);
}

public static List<BtcECKey> getBtcEcKeysFromSeeds(String[] seeds, boolean sorted) {
List<BtcECKey> keys = Arrays
.stream(seeds)
.map(seed -> BtcECKey.fromPrivate(
HashUtil.keccak256(seed.getBytes(StandardCharsets.UTF_8))))
List<BtcECKey> keys = Arrays.stream(seeds)
.map(BitcoinTestUtils::getBtcEcKeyFromSeed)
.collect(Collectors.toList());

if (sorted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void removeSignaturesFromTransaction_whenTransactionIsSegwit_shouldThrowIllegalA
void removeSignaturesFromTransaction_whenTransactionInputsDoNotHaveP2shMultiSigInputScript_shouldThrowIllegalArgumentException() {
// arrange
BtcTransaction transaction = new BtcTransaction(btcMainnetParams);
BtcECKey pubKey = new BtcECKey();
BtcECKey pubKey = BitcoinTestUtils.getBtcEcKeyFromSeed("abc");
Script p2pkhScriptSig = ScriptBuilder.createInputScript(null, pubKey);
transaction.addInput(BitcoinTestUtils.createHash(1), 0, p2pkhScriptSig);

Expand Down
Loading