use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class UpdateCollectionsTest method updateCollections_confirmTxs.
private void updateCollections_confirmTxs(ExecutionStats stats, int numCases) throws IOException {
final int minTxsWaitingForSigs = 0;
final int maxTxsWaitingForSigs = 10;
final int minReleaseTxs = 1;
final int maxReleaseTxs = 100;
final int minBlockNumber = 10;
final int maxBlockNumber = 100;
final int minHeight = 50;
final int maxHeight = 150;
final int minCentOutput = 1;
final int maxCentOutput = 100;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Random rnd = new Random();
SortedMap<Keccak256, BtcTransaction> txsWaitingForSignatures;
ReleaseTransactionSet txSet;
try {
txsWaitingForSignatures = provider.getRskTxsWaitingForSignatures();
} catch (Exception e) {
throw new RuntimeException("Unable to gather txs waiting for signatures");
}
try {
txSet = provider.getReleaseTransactionSet();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release tx set");
}
// Generate some txs waiting for signatures
Script genesisFederationScript = bridgeConstants.getGenesisFederation().getP2SHScript();
for (int i = 0; i < Helper.randomInRange(minTxsWaitingForSigs, maxTxsWaitingForSigs); i++) {
Keccak256 rskHash = new Keccak256(HashUtil.keccak256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
BtcTransaction btcTx = new BtcTransaction(networkParameters);
Sha256Hash inputHash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
btcTx.addInput(inputHash, 0, genesisFederationScript);
btcTx.addOutput(Helper.randomCoin(Coin.CENT, minCentOutput, maxCentOutput), new BtcECKey());
txsWaitingForSignatures.put(rskHash, btcTx);
}
// Generate some txs waiting for confirmations
for (int i = 0; i < Helper.randomInRange(minReleaseTxs, maxReleaseTxs); i++) {
BtcTransaction btcTx = new BtcTransaction(networkParameters);
Sha256Hash inputHash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
btcTx.addInput(inputHash, 0, genesisFederationScript);
btcTx.addOutput(Helper.randomCoin(Coin.CENT, minCentOutput, maxCentOutput), new BtcECKey());
long blockNumber = Helper.randomInRange(minBlockNumber, maxBlockNumber);
txSet.add(btcTx, blockNumber);
}
};
final byte[] updateCollectionsEncoded = Bridge.UPDATE_COLLECTIONS.encode();
ABIEncoder abiEncoder = (int executionIndex) -> updateCollectionsEncoded;
HeightProvider heightProvider = (int executionIndex) -> Helper.randomInRange(minHeight, maxHeight);
executeAndAverage("updateCollections-releaseTxs", numCases, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), heightProvider, stats);
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class Web3RskImplTest method web3_LogFilterElement_toString.
@Test
public void web3_LogFilterElement_toString() {
LogInfo logInfo = Mockito.mock(LogInfo.class);
byte[] valueToTest = HashUtil.keccak256(new byte[] { 1 });
Mockito.when(logInfo.getData()).thenReturn(valueToTest);
List<DataWord> topics = new ArrayList<>();
topics.add(new DataWord("c1"));
topics.add(new DataWord("c2"));
Mockito.when(logInfo.getTopics()).thenReturn(topics);
Block block = Mockito.mock(Block.class);
Mockito.when(block.getHash()).thenReturn(new Keccak256(valueToTest));
Mockito.when(block.getNumber()).thenReturn(1L);
int txIndex = 1;
Transaction tx = Mockito.mock(Transaction.class);
byte[] bytes = new byte[32];
bytes[0] = 2;
Mockito.when(tx.getHash()).thenReturn(new Keccak256(bytes));
int logIdx = 5;
LogFilterElement logFilterElement = new LogFilterElement(logInfo, block, txIndex, tx, logIdx);
Assert.assertEquals(logFilterElement.toString(), "LogFilterElement{logIndex='0x5', blockNumber='0x1', blockHash='0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2', transactionHash='0x0200000000000000000000000000000000000000000000000000000000000000', transactionIndex='0x1', address='0x00', data='0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2', topics=[0x00000000000000000000000000000000000000000000000000000000000000c1, 0x00000000000000000000000000000000000000000000000000000000000000c2]}");
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class TransactionNodeInformationTest method transactionEvictionPolicy.
@Test
public void transactionEvictionPolicy() {
final TransactionNodeInformation nodeInformation = new TransactionNodeInformation();
final NodeID nodeID1 = new NodeID(new byte[] { 2 });
// Add a few blocks, without exceeding the block limit. NodeID1 should contain them all.
for (int i = 0; i < 500; i++) {
final Keccak256 hash1 = createBlockHash(i);
nodeInformation.addTransactionToNode(hash1, nodeID1);
}
Assert.assertTrue(nodeInformation.getNodesByTransaction(createBlockHash(15)).contains(nodeID1));
Assert.assertTrue(nodeInformation.getNodesByTransaction(createBlockHash(200)).contains(nodeID1));
// Except from block 10, which is being constantly accessed.
for (int i = 500; i < 2000; i++) {
final Keccak256 hash1 = createBlockHash(i);
nodeInformation.addTransactionToNode(hash1, nodeID1);
nodeInformation.getNodesByTransaction(createBlockHash(10));
}
Assert.assertFalse(nodeInformation.getNodesByTransaction(createBlockHash(1)).contains(nodeID1));
Assert.assertFalse(nodeInformation.getNodesByTransaction(createBlockHash(700)).contains(nodeID1));
Assert.assertFalse(nodeInformation.getNodesByTransaction(createBlockHash(200)).contains(nodeID1));
Assert.assertTrue(nodeInformation.getNodesByTransaction(createBlockHash(1900)).contains(nodeID1));
Assert.assertTrue(nodeInformation.getNodesByTransaction(createBlockHash(10)).contains(nodeID1));
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class TransactionNodeInformationTest method getIsNotEmptyIfPresent.
@Test
public void getIsNotEmptyIfPresent() {
final TransactionNodeInformation nodeInformation = new TransactionNodeInformation();
final Keccak256 hash1 = createBlockHash(1);
final NodeID nodeID1 = new NodeID(new byte[] { 2 });
final Keccak256 badHash = createBlockHash(3);
final NodeID badNode = new NodeID(new byte[] { 4 });
nodeInformation.addTransactionToNode(hash1, nodeID1);
Set<NodeID> nodes = nodeInformation.getNodesByTransaction(hash1);
Assert.assertTrue(nodes.size() == 1);
Assert.assertTrue(nodes.contains(nodeID1));
Assert.assertFalse(nodes.contains(badNode));
nodes = nodeInformation.getNodesByTransaction(badHash);
Assert.assertTrue(nodes.size() == 0);
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class TransactionResultDTOTest method remascAddressSerialization.
@Test
public void remascAddressSerialization() {
Block b = mock(Block.class);
Integer index = 42;
Transaction tx = mock(Transaction.class);
when(tx.getHash()).thenReturn(new Keccak256(TestUtils.randomBytes(32)));
when(tx.getSender()).thenReturn(RemascTransaction.REMASC_ADDRESS);
when(tx.getReceiveAddress()).thenReturn(TestUtils.randomAddress());
when(tx.getGasPrice()).thenReturn(Coin.valueOf(42));
when(tx.getValue()).thenReturn(Coin.ZERO);
when(tx.getData()).thenReturn(TestUtils.randomBytes(2));
TransactionResultDTO dto = new TransactionResultDTO(b, index, tx);
assertThat(dto.from, is("0x0000000000000000000000000000000000000000"));
}
Aggregations