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);
}
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;
}
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);
}
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));
}
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]);
}
Aggregations