Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanieliov committed Jan 9, 2025
1 parent d064fbd commit 00ae431
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/test/java/co/rsk/federate/BtcToRskClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import co.rsk.cli.CliArgs;
import co.rsk.config.*;
import co.rsk.federate.adapter.ThinConverter;
import co.rsk.federate.bitcoin.BitcoinTestUtils;
import co.rsk.federate.bitcoin.BitcoinWrapper;
import co.rsk.federate.bitcoin.BitcoinWrapperImpl;
import co.rsk.federate.config.PowpegNodeSystemProperties;
Expand Down Expand Up @@ -2774,16 +2775,16 @@ private Transaction getCoinbaseTransactionWithWrongWitnessCommitment() {
coinbaseTx.verify();

TransactionWitness txWitness = new TransactionWitness(1);
txWitness.setPush(0, BitcoinUtils.WITNESS_RESERVED_VALUE.getBytes());
txWitness.setPush(0, BitcoinTestUtils.WITNESS_RESERVED_VALUE.getBytes());
coinbaseTx.getInput(0).setWitness(txWitness);

Sha256Hash witnessCommitment = Sha256Hash.wrap("0011223344556677889900112233445566778899001122334455667788990011");
String witnessCommitmentHeader = "aa21a9ed";

byte[] wrongWitnessCommitmentWithHeader = ByteUtil.merge(
new byte[]{ScriptOpCodes.OP_RETURN},
new byte[]{ScriptOpCodes.OP_PUSHDATA1},
new byte[]{BitcoinUtils.WITNESS_COMMITMENT_LENGTH},
Hex.decode(witnessCommitmentHeader),
new byte[]{(byte) BitcoinTestUtils.WITNESS_COMMITMENT_LENGTH},
BitcoinTestUtils.WITNESS_COMMITMENT_HEADER,
witnessCommitment.getBytes()
);
Script wrongWitnessCommitmentScript = new Script(wrongWitnessCommitmentWithHeader);
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/co/rsk/federate/bitcoin/BitcoinTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.HashUtil;

public final class BitcoinTestUtils {

public static final byte[] WITNESS_COMMITMENT_HEADER = Hex.decode("aa21a9ed");
public static final Sha256Hash WITNESS_RESERVED_VALUE = Sha256Hash.ZERO_HASH;
public static final int WITNESS_COMMITMENT_LENGTH = WITNESS_COMMITMENT_HEADER.length + Sha256Hash.LENGTH;
public static final int MINIMUM_WITNESS_COMMITMENT_SIZE = WITNESS_COMMITMENT_LENGTH + 2; // 1 extra by for OP_RETURN and another one for data length

private BitcoinTestUtils() { }

public static List<Coin> coinListOf(long... values) {
Expand Down

0 comments on commit 00ae431

Please sign in to comment.