use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.
the class BridgeSerializationUtilsTest method deserializeCoinbaseInformation_dataIsValid_returnsValidCoinbaseInformation.
@Test
public void deserializeCoinbaseInformation_dataIsValid_returnsValidCoinbaseInformation() {
Sha256Hash secondHashTx = Sha256Hash.wrap(Hex.decode("e3d0840a0825fb7d880e5cb8306745352920a8c7e8a30fac882b275e26c6bb65"));
Sha256Hash witnessRoot = MerkleTreeUtils.combineLeftRight(Sha256Hash.ZERO_HASH, secondHashTx);
CoinbaseInformation coinbaseInformation = new CoinbaseInformation(witnessRoot);
byte[] serializedCoinbaseInformation = BridgeSerializationUtils.serializeCoinbaseInformation(coinbaseInformation);
Assert.assertEquals(witnessRoot, BridgeSerializationUtils.deserializeCoinbaseInformation(serializedCoinbaseInformation).getWitnessMerkleRoot());
}
use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.
the class BridgeStorageProviderTest method saveCoinBaseInformation_after_RSKIP143.
@Test
public void saveCoinBaseInformation_after_RSKIP143() throws IOException {
Repository repository = mock(Repository.class);
Sha256Hash hash = Sha256Hash.ZERO_HASH;
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks);
assertNull(provider.getCoinbaseInformation(hash));
CoinbaseInformation coinbaseInformation = new CoinbaseInformation(Sha256Hash.ZERO_HASH);
provider.setCoinbaseInformation(hash, coinbaseInformation);
assertEquals(coinbaseInformation, provider.getCoinbaseInformation(hash));
provider.save();
verify(repository, times(1)).addStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("coinbaseInformation-" + hash.toString()), BridgeSerializationUtils.serializeCoinbaseInformation(coinbaseInformation));
}
use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.
the class BridgeStorageProviderTest method saveCoinBaseInformation_before_RSKIP143.
@Test
public void saveCoinBaseInformation_before_RSKIP143() throws IOException {
Repository repository = mock(Repository.class);
Sha256Hash hash = Sha256Hash.ZERO_HASH;
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork);
assertNull(provider.getCoinbaseInformation(hash));
CoinbaseInformation coinbaseInformation = new CoinbaseInformation(Sha256Hash.ZERO_HASH);
provider.setCoinbaseInformation(hash, coinbaseInformation);
assertNull(provider.getCoinbaseInformation(hash));
provider.save();
verify(repository, never()).addStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("coinbaseInformation" + hash.toString()), BridgeSerializationUtils.serializeCoinbaseInformation(coinbaseInformation));
}
use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.
the class BridgeSerializationUtils method deserializeCoinbaseInformation.
public static CoinbaseInformation deserializeCoinbaseInformation(byte[] data) {
if (data == null) {
return null;
}
RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
if (rlpList.size() != 1) {
throw new RuntimeException(String.format("Invalid serialized coinbase information, expected 1 value but got %d", rlpList.size()));
}
Sha256Hash witnessMerkleRoot = Sha256Hash.wrap(rlpList.get(0).getRLPData());
return new CoinbaseInformation(witnessMerkleRoot);
}
use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.
the class BridgeSupportTest method isBlockMerkleRootValid_coinbase_information_not_null_and_equal_mroots_after_rskip_143.
@Test
public void isBlockMerkleRootValid_coinbase_information_not_null_and_equal_mroots_after_rskip_143() {
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
when(activations.isActive(ConsensusRule.RSKIP143)).thenReturn(true);
Sha256Hash merkleRoot = PegTestUtils.createHash(1);
CoinbaseInformation coinbaseInformation = new CoinbaseInformation(merkleRoot);
BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
when(provider.getCoinbaseInformation(Sha256Hash.ZERO_HASH)).thenReturn(coinbaseInformation);
BridgeSupport bridgeSupport = getBridgeSupport(bridgeConstants, provider, mock(Repository.class), mock(BtcLockSenderProvider.class), mock(PeginInstructionsProvider.class), mock(Block.class), mock(BtcBlockStoreWithCache.Factory.class), activations);
BtcBlock btcBlock = mock(BtcBlock.class);
when(btcBlock.getMerkleRoot()).thenReturn(Sha256Hash.ZERO_HASH);
when(btcBlock.getHash()).thenReturn(Sha256Hash.ZERO_HASH);
Assert.assertTrue(bridgeSupport.isBlockMerkleRootValid(merkleRoot, btcBlock));
}
Aggregations