use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeSupportTest method testInitialChainHeadWithBtcCheckpoints.
@Test
public void testInitialChainHeadWithBtcCheckpoints() throws Exception {
config = new RskSystemProperties();
config.setBlockchainConfig(new TestNetConfig());
bridgeConstants = config.getBlockchainConfig().getCommonConstants().getBridgeConstants();
btcParams = bridgeConstants.getBtcParams();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
BridgeSupport bridgeSupport = new BridgeSupport(config, track, mock(BridgeEventLogger.class), provider, null);
Assert.assertEquals(1229760, bridgeSupport.getBtcBlockStore().getChainHead().getHeight());
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeSupportTest method addSignatureCreateEventLog.
@Test
public void addSignatureCreateEventLog() throws Exception {
// Setup
Federation federation = bridgeConstants.getGenesisFederation();
Repository track = new RepositoryImpl(config).startTracking();
BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants);
// Build prev btc tx
BtcTransaction prevTx = new BtcTransaction(btcParams);
TransactionOutput prevOut = new TransactionOutput(btcParams, prevTx, Coin.FIFTY_COINS, federation.getAddress());
prevTx.addOutput(prevOut);
// Build btc tx to be signed
BtcTransaction btcTx = new BtcTransaction(btcParams);
btcTx.addInput(prevOut).setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation));
TransactionOutput output = new TransactionOutput(btcParams, btcTx, Coin.COIN, new BtcECKey().toAddress(btcParams));
btcTx.addOutput(output);
// Save btc tx to be signed
final Keccak256 rskTxHash = PegTestUtils.createHash3();
provider.getRskTxsWaitingForSignatures().put(rskTxHash, btcTx);
provider.save();
track.commit();
// Setup BridgeSupport
List<LogInfo> eventLogs = new ArrayList<>();
BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(bridgeConstants, eventLogs);
BridgeSupport bridgeSupport = new BridgeSupport(config, track, eventLogger, contractAddress, null);
// Create signed hash of Btc tx
Script inputScript = btcTx.getInputs().get(0).getScriptSig();
List<ScriptChunk> chunks = inputScript.getChunks();
byte[] program = chunks.get(chunks.size() - 1).data;
Script redeemScript = new Script(program);
Sha256Hash sigHash = btcTx.hashForSignature(0, redeemScript, BtcTransaction.SigHash.ALL, false);
BtcECKey privateKeyToSignWith = ((BridgeRegTestConstants) bridgeConstants).getFederatorPrivateKeys().get(0);
BtcECKey.ECDSASignature sig = privateKeyToSignWith.sign(sigHash);
List derEncodedSigs = Collections.singletonList(sig.encodeToDER());
BtcECKey federatorPubKey = findPublicKeySignedBy(federation.getPublicKeys(), privateKeyToSignWith);
bridgeSupport.addSignature(1, federatorPubKey, derEncodedSigs, rskTxHash.getBytes());
Assert.assertEquals(1, eventLogs.size());
// Assert address that made the log
LogInfo result = eventLogs.get(0);
Assert.assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), result.getAddress());
// Assert log topics
Assert.assertEquals(1, result.getTopics().size());
Assert.assertEquals(Bridge.ADD_SIGNATURE_TOPIC, result.getTopics().get(0));
// Assert log data
Assert.assertNotNull(result.getData());
List<RLPElement> rlpData = RLP.decode2(result.getData());
Assert.assertEquals(1, rlpData.size());
RLPList dataList = (RLPList) rlpData.get(0);
Assert.assertEquals(3, dataList.size());
Assert.assertArrayEquals(btcTx.getHashAsString().getBytes(), dataList.get(0).getRLPData());
Assert.assertArrayEquals(federatorPubKey.getPubKeyHash(), dataList.get(1).getRLPData());
Assert.assertArrayEquals(rskTxHash.getBytes(), dataList.get(2).getRLPData());
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeTest method registerBtcTransactionWithNonParseableMerkleeProof2.
@Test
public void registerBtcTransactionWithNonParseableMerkleeProof2() throws Exception {
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
bridge.init(null, null, track, null, null, null);
NetworkParameters btcParams = RegTestParams.get();
BtcTransaction tx = new BtcTransaction(btcParams);
tx.addOutput(Coin.COIN, new BtcECKey().toAddress(btcParams));
tx.addInput(PegTestUtils.createHash(), 0, ScriptBuilder.createInputScript(null, new BtcECKey()));
byte[] data = Bridge.REGISTER_BTC_TRANSACTION.encode(tx.bitcoinSerialize(), 1, new byte[30]);
Assert.assertNull(bridge.execute(data));
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeTest method registerBtcTransactionWithNonParseableMerkleeProof1.
@Test
public void registerBtcTransactionWithNonParseableMerkleeProof1() throws Exception {
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
bridge.init(null, null, track, null, null, null);
NetworkParameters btcParams = RegTestParams.get();
BtcTransaction tx = new BtcTransaction(btcParams);
tx.addOutput(Coin.COIN, new BtcECKey().toAddress(btcParams));
tx.addInput(PegTestUtils.createHash(), 0, ScriptBuilder.createInputScript(null, new BtcECKey()));
byte[] data = Bridge.REGISTER_BTC_TRANSACTION.encode(tx.bitcoinSerialize(), 1, new byte[3]);
Assert.assertNull(bridge.execute(data));
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeTest method callUpdateCollectionsWithTransactionsWaitingForConfirmation.
@Test
public void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOException {
BtcTransaction tx1 = createTransaction();
BtcTransaction tx2 = createTransaction();
BtcTransaction tx3 = createTransaction();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
provider0.getReleaseTransactionSet().add(tx1, 1L);
provider0.getReleaseTransactionSet().add(tx2, 2L);
provider0.getReleaseTransactionSet().add(tx3, 3L);
provider0.save();
track.commit();
track = repository.startTracking();
Transaction rskTx = Transaction.create(config, PrecompiledContracts.BRIDGE_ADDR_STR, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
rskTx.sign(new ECKey().getPrivKeyBytes());
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
World world = new World();
bridge.init(rskTx, world.getBlockChain().getBestBlock(), track, world.getBlockChain().getBlockStore(), null, new LinkedList<>());
bridge.execute(Bridge.UPDATE_COLLECTIONS.encode());
track.commit();
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
Assert.assertEquals(3, provider.getReleaseTransactionSet().getEntries().size());
Assert.assertEquals(0, provider.getRskTxsWaitingForSignatures().size());
}
Aggregations