Search in sources :

Example 16 with CoinbaseInformation

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());
}
Also used : CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) Test(org.junit.Test)

Example 17 with CoinbaseInformation

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));
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with 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));
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with 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);
}
Also used : CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) RLPList(org.ethereum.util.RLPList)

Example 20 with CoinbaseInformation

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));
}
Also used : BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) Block(org.ethereum.core.Block) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Aggregations

CoinbaseInformation (co.rsk.peg.bitcoin.CoinbaseInformation)22 Test (org.junit.Test)18 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)17 Repository (org.ethereum.core.Repository)16 MutableRepository (org.ethereum.db.MutableRepository)16 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)11 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)11 Block (org.ethereum.core.Block)11 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)9 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Script (co.rsk.bitcoinj.script.Script)5 BigInteger (java.math.BigInteger)5 MerkleBranch (co.rsk.peg.bitcoin.MerkleBranch)3 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)3 Transaction (org.ethereum.core.Transaction)3 InternalTransaction (org.ethereum.vm.program.InternalTransaction)3 RskAddress (co.rsk.core.RskAddress)2 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)2 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)2