From bb5fb5c86f1b9db3c42fdb30cc55a2c3e6b80dc8 Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 27 Sep 2024 11:19:16 -0300 Subject: [PATCH] Update test in BitcoinUtilsTest to use deterministic keys --- .../co/rsk/peg/bitcoin/BitcoinTestUtils.java | 23 +++++++++---------- .../co/rsk/peg/bitcoin/BitcoinUtilsTest.java | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinTestUtils.java b/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinTestUtils.java index 4ba69f1fc7c..146d389f73f 100644 --- a/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinTestUtils.java +++ b/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinTestUtils.java @@ -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 getBtcEcKeysFromSeeds(String[] seeds, boolean sorted) { - List keys = Arrays - .stream(seeds) - .map(seed -> BtcECKey.fromPrivate( - HashUtil.keccak256(seed.getBytes(StandardCharsets.UTF_8)))) + List keys = Arrays.stream(seeds) + .map(BitcoinTestUtils::getBtcEcKeyFromSeed) .collect(Collectors.toList()); if (sorted) { diff --git a/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java index 5740f641af0..4d908493635 100644 --- a/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java @@ -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);