Search in sources :

Example 11 with NetworkParameters

use of co.rsk.bitcoinj.core.NetworkParameters in project rskj by rsksmart.

the class LockWhitelistTest method createWhitelist.

@Before
public void createWhitelist() {
    NetworkParameters params = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
    int existingPrivate = 300;
    addresses = Arrays.stream(new Integer[] { 100, 200, existingPrivate, 400 }).map(i -> {
        Address address = BtcECKey.fromPrivate(BigInteger.valueOf(i)).toAddress(params);
        if (i == existingPrivate) {
            existingAddress = address;
        }
        return address;
    }).collect(Collectors.toMap(Function.identity(), i -> new OneOffWhiteListEntry(i, Coin.CENT)));
    whitelist = new LockWhitelist(addresses, 0);
}
Also used : BigInteger(java.math.BigInteger) Address(co.rsk.bitcoinj.core.Address) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) Before(org.junit.Before)

Example 12 with NetworkParameters

use of co.rsk.bitcoinj.core.NetworkParameters in project rskj by rsksmart.

the class RskContext method getBtcBlockStoreFactory.

public synchronized BtcBlockStoreWithCache.Factory getBtcBlockStoreFactory() {
    checkIfNotClosed();
    if (btcBlockStoreFactory == null) {
        NetworkParameters btcParams = getRskSystemProperties().getNetworkConstants().getBridgeConstants().getBtcParams();
        btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(btcParams, getRskSystemProperties().getBtcBlockStoreCacheDepth(), getRskSystemProperties().getBtcBlockStoreCacheSize());
    }
    return btcBlockStoreFactory;
}
Also used : RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters)

Example 13 with NetworkParameters

use of co.rsk.bitcoinj.core.NetworkParameters in project rskj by rsksmart.

the class BlockValidatorTest method blockInTheFuture.

@Test
public void blockInTheFuture() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    byte[] bitcoinMergedMiningHeader = new byte[0];
    int validPeriod = 6000;
    // some random timestamp (taken from Sys.currentTimeMills())
    long baseTimeStamp = 1627932722L;
    BlockHeader header = mock(BlockHeader.class);
    when(header.getBitcoinMergedMiningHeader()).thenReturn(bitcoinMergedMiningHeader);
    when(header.getTimestamp()).thenReturn(baseTimeStamp + 2 * validPeriod);
    when(header.getParentHash()).thenReturn(genesis.getHash());
    Block block = mock(Block.class);
    when(block.getHeader()).thenReturn(header);
    BtcBlock btcBlock = mock(BtcBlock.class);
    // a close enough block
    when(btcBlock.getTimeSeconds()).thenReturn(baseTimeStamp + validPeriod - 100);
    MessageSerializer messageSerializer = mock(BitcoinSerializer.class);
    when(messageSerializer.makeBlock(bitcoinMergedMiningHeader)).thenReturn(btcBlock);
    NetworkParameters bitcoinNetworkParameters = mock(NetworkParameters.class);
    when(bitcoinNetworkParameters.getDefaultSerializer()).thenReturn(messageSerializer);
    // Before Iris
    blockTimeStampValidation(validPeriod, baseTimeStamp, header, block, bitcoinNetworkParameters, false);
    // After Iris
    blockTimeStampValidation(validPeriod, baseTimeStamp, header, block, bitcoinNetworkParameters, true);
}
Also used : MessageSerializer(co.rsk.bitcoinj.core.MessageSerializer) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 14 with NetworkParameters

use of co.rsk.bitcoinj.core.NetworkParameters in project rskj by rsksmart.

the class BridgeTest method registerFastBridgeBtcTransaction_after_RSKIP176_activation_p2sh_refund_address_after_RSKIP284_activation_ok.

@Test
public void registerFastBridgeBtcTransaction_after_RSKIP176_activation_p2sh_refund_address_after_RSKIP284_activation_ok() throws VMException, IOException, BlockStoreException {
    NetworkParameters networkParameters = constants.getBridgeConstants().getBtcParams();
    doReturn(true).when(activationConfig).isActive(eq(RSKIP176), anyLong());
    doReturn(true).when(activationConfig).isActive(eq(RSKIP284), anyLong());
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Bridge bridge = getBridgeInstance(bridgeSupportMock);
    when(bridgeSupportMock.registerFastBridgeBtcTransaction(any(Transaction.class), any(byte[].class), anyInt(), any(byte[].class), any(Keccak256.class), any(Address.class), any(RskAddress.class), any(Address.class), anyBoolean())).thenReturn(BigInteger.valueOf(2));
    byte[] value = Sha256Hash.ZERO_HASH.getBytes();
    Address refundBtcAddress = Address.fromBase58(networkParameters, "2MyEXHyt2fXqdFm3r4xXEkTdbwdZm7qFiDP");
    byte[] refundBtcAddressBytes = BridgeUtils.serializeBtcAddressWithVersion(activationConfig.forBlock(anyLong()), refundBtcAddress);
    BtcECKey btcECKeyLp = new BtcECKey();
    Address lpBtcAddress = btcECKeyLp.toAddress(networkParameters);
    byte[] lpBtcAddressBytes = BridgeUtils.serializeBtcAddressWithVersion(activationConfig.forBlock(anyLong()), lpBtcAddress);
    ECKey ecKey = new ECKey();
    RskAddress rskAddress = new RskAddress(ecKey.getAddress());
    byte[] data = Bridge.REGISTER_FAST_BRIDGE_BTC_TRANSACTION.encode(value, 1, value, value, refundBtcAddressBytes, rskAddress.toHexString(), lpBtcAddressBytes, true);
    byte[] result = bridge.execute(data);
    // Assert
    assertEquals(BigInteger.valueOf(2), Bridge.REGISTER_FAST_BRIDGE_BTC_TRANSACTION.decodeResult(result)[0]);
    verify(bridgeSupportMock, times(1)).registerFastBridgeBtcTransaction(any(Transaction.class), eq(value), eq(1), eq(value), eq(new Keccak256(value)), eq(refundBtcAddress), eq(rskAddress), eq(lpBtcAddress), eq(true));
}
Also used : CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) Address(co.rsk.bitcoinj.core.Address) RskAddress(co.rsk.core.RskAddress) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) RskAddress(co.rsk.core.RskAddress) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ECKey(org.ethereum.crypto.ECKey) Keccak256(co.rsk.crypto.Keccak256) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 15 with NetworkParameters

use of co.rsk.bitcoinj.core.NetworkParameters in project rskj by rsksmart.

the class BridgeTest method receiveHeader_after_RSKIP200_Ok.

@Test
public void receiveHeader_after_RSKIP200_Ok() throws VMException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP200), anyLong());
    Bridge bridge = spy(getBridgeInstance(mock(BridgeSupport.class), activations));
    NetworkParameters networkParameters = constants.bridgeConstants.getBtcParams();
    co.rsk.bitcoinj.core.BtcBlock block = new co.rsk.bitcoinj.core.BtcBlock(networkParameters, 1, PegTestUtils.createHash(1), PegTestUtils.createHash(1), 1, Utils.encodeCompactBits(networkParameters.getMaxTarget()), 1, new ArrayList<>()).cloneAsHeader();
    Object[] parameters = new Object[] { block.bitcoinSerialize() };
    byte[] data = Bridge.RECEIVE_HEADER.encode(parameters);
    byte[] result = bridge.execute(data);
    verify(bridge, times(1)).receiveHeader(eq(parameters));
    assertEquals(BigInteger.valueOf(0), Bridge.RECEIVE_HEADER.decodeResult(result)[0]);
}
Also used : co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) ArrayList(java.util.ArrayList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Aggregations

NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)28 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)11 Test (org.junit.Test)9 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)8 Context (co.rsk.bitcoinj.core.Context)7 BigInteger (java.math.BigInteger)6 Address (co.rsk.bitcoinj.core.Address)5 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)5 ECKey (org.ethereum.crypto.ECKey)5 DeterministicKey (co.rsk.bitcoinj.crypto.DeterministicKey)4 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)3 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 RskAddress (co.rsk.core.RskAddress)3 Keccak256 (co.rsk.crypto.Keccak256)3 SubmitBlockResult (co.rsk.mine.SubmitBlockResult)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)3 CallTransaction (org.ethereum.core.CallTransaction)3