Search in sources :

Example 1 with Rskip92MerkleProofValidator

use of co.rsk.validators.Rskip92MerkleProofValidator in project rskj by rsksmart.

the class Rskip92MerkleProofValidatorTests method isValid_PassValidHashes_ShouldReturnTrue.

@Test
public void isValid_PassValidHashes_ShouldReturnTrue() {
    List<byte[]> hashList = makeHashList();
    byte[] pmtSerialized = join(hashList);
    Sha256Hash coinbaseHash = Sha256Hash.wrap(hashList.get(0));
    Rskip92MerkleProofValidator rskip92MerkleProofValidator = new Rskip92MerkleProofValidator(pmtSerialized, true);
    Sha256Hash rootHash = hashList.stream().map(Sha256Hash::wrap).reduce(coinbaseHash, MerkleTreeUtils::combineLeftRight);
    boolean actualResult = rskip92MerkleProofValidator.isValid(rootHash, coinbaseHash);
    assertTrue(actualResult);
}
Also used : Rskip92MerkleProofValidator(co.rsk.validators.Rskip92MerkleProofValidator) MerkleTreeUtils(co.rsk.peg.utils.MerkleTreeUtils) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash) Test(org.junit.Test)

Example 2 with Rskip92MerkleProofValidator

use of co.rsk.validators.Rskip92MerkleProofValidator in project rskj by rsksmart.

the class Rskip92MerkleProofValidatorTests method isValid_PassInvalidCoinbaseHash_ShouldReturnFalse.

@Test
public void isValid_PassInvalidCoinbaseHash_ShouldReturnFalse() {
    List<byte[]> hashList = makeHashList();
    byte[] pmtSerialized = join(hashList);
    Sha256Hash coinbaseHash = Sha256Hash.wrap(hashList.get(0));
    Rskip92MerkleProofValidator rskip92MerkleProofValidator = new Rskip92MerkleProofValidator(pmtSerialized, true);
    Sha256Hash rootHash = hashList.stream().map(Sha256Hash::wrap).reduce(coinbaseHash, MerkleTreeUtils::combineLeftRight);
    boolean actualResult = rskip92MerkleProofValidator.isValid(rootHash, Sha256Hash.wrap(new byte[Sha256Hash.LENGTH]));
    assertFalse(actualResult);
}
Also used : Rskip92MerkleProofValidator(co.rsk.validators.Rskip92MerkleProofValidator) MerkleTreeUtils(co.rsk.peg.utils.MerkleTreeUtils) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash) Test(org.junit.Test)

Example 3 with Rskip92MerkleProofValidator

use of co.rsk.validators.Rskip92MerkleProofValidator in project rskj by rsksmart.

the class Rskip92MerkleProofValidatorTests method createInstance_PassLargeProofAndRskip180Disabled_ShouldNotThrowError.

@Test
public void createInstance_PassLargeProofAndRskip180Disabled_ShouldNotThrowError() {
    byte[] pmtSerialized = new byte[MAX_MERKLE_PROOF_SIZE + Sha256Hash.LENGTH];
    Rskip92MerkleProofValidator instance = new Rskip92MerkleProofValidator(pmtSerialized, false);
    assertNotNull(instance);
}
Also used : Rskip92MerkleProofValidator(co.rsk.validators.Rskip92MerkleProofValidator) Test(org.junit.Test)

Example 4 with Rskip92MerkleProofValidator

use of co.rsk.validators.Rskip92MerkleProofValidator in project rskj by rsksmart.

the class Rskip92MerkleProofValidatorTests method isValid_PassInvalidRootHash_ShouldReturnFalse.

@Test
public void isValid_PassInvalidRootHash_ShouldReturnFalse() {
    List<byte[]> hashList = makeHashList();
    byte[] pmtSerialized = join(hashList);
    Sha256Hash coinbaseHash = Sha256Hash.wrap(hashList.get(0));
    Rskip92MerkleProofValidator rskip92MerkleProofValidator = new Rskip92MerkleProofValidator(pmtSerialized, true);
    Sha256Hash rootHash = Sha256Hash.wrap(new byte[Sha256Hash.LENGTH]);
    boolean actualResult = rskip92MerkleProofValidator.isValid(rootHash, coinbaseHash);
    assertFalse(actualResult);
}
Also used : Rskip92MerkleProofValidator(co.rsk.validators.Rskip92MerkleProofValidator) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash) Test(org.junit.Test)

Aggregations

Rskip92MerkleProofValidator (co.rsk.validators.Rskip92MerkleProofValidator)4 Test (org.junit.Test)4 Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)3 MerkleTreeUtils (co.rsk.peg.utils.MerkleTreeUtils)2