Skip to content

Commit

Permalink
Merge pull request #2766 from rsksmart/deterministic-test
Browse files Browse the repository at this point in the history
Update test in BitcoinUtilsTest to use deterministic keys
  • Loading branch information
Vovchyk authored Sep 30, 2024
2 parents 2c00b2f + bb5fb5c commit 0f5e2ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
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

0 comments on commit 0f5e2ed

Please sign in to comment.