Search in sources :

Example 1 with MerkleTreeUtils

use of co.rsk.peg.utils.MerkleTreeUtils 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 MerkleTreeUtils

use of co.rsk.peg.utils.MerkleTreeUtils 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)

Aggregations

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