use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryTest method test16_4.
@Test
public void test16_4() {
Repository repository = new RepositoryImpl(config);
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
Repository track = repository.startTracking();
track.addStorageBytes(COW, new DataWord(cowKey1), cowValue1);
track.commit();
// changes level_1
Repository track1 = repository.startTracking();
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageBytes(COW, new DataWord(cowKey2), cowValue2);
track2.commit();
// leaving level_2
track1.commit();
// leaving level_1
assertArrayEquals(cowValue1, track1.getStorageBytes(COW, new DataWord(cowKey1)));
assertArrayEquals(cowValue2, track1.getStorageBytes(COW, new DataWord(cowKey2)));
repository.close();
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RepositoryTest method test19.
@Test
public void test19() {
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
DataWord cowKey1 = new DataWord("c1");
byte[] cowVal1 = Hex.decode("c0a1");
byte[] cowVal0 = Hex.decode("c0a0");
DataWord horseKey1 = new DataWord("e1");
byte[] horseVal1 = Hex.decode("c0a1");
byte[] horseVal0 = Hex.decode("c0a0");
track.addStorageBytes(COW, cowKey1, cowVal0);
track.addStorageBytes(HORSE, horseKey1, horseVal0);
track.commit();
// track
Repository track2 = repository.startTracking();
track2.addStorageBytes(HORSE, horseKey1, horseVal0);
Repository track3 = track2.startTracking();
ContractDetails cowDetails = track3.getContractDetails(COW);
cowDetails.putBytes(cowKey1, cowVal1);
ContractDetails horseDetails = track3.getContractDetails(HORSE);
horseDetails.putBytes(horseKey1, horseVal1);
track3.commit();
track2.rollback();
ContractDetails cowDetailsOrigin = repository.getContractDetails(COW);
byte[] cowValOrin = cowDetailsOrigin.getBytes(cowKey1);
ContractDetails horseDetailsOrigin = repository.getContractDetails(HORSE);
byte[] horseValOrin = horseDetailsOrigin.getBytes(horseKey1);
assertArrayEquals(cowVal0, cowValOrin);
assertArrayEquals(horseVal0, horseValOrin);
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class LockTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minHashes = 100;
final int maxHashes = 10000;
final int minHeight = 1000;
final int maxHeight = 2000;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
int hashesToGenerate = Helper.randomInRange(minHashes, maxHashes);
int randomHashIndex = Helper.randomInRange(0, hashesToGenerate - 1);
Random rnd = new Random();
Map<Sha256Hash, Long> hashesAlreadyProcessed;
try {
hashesAlreadyProcessed = provider.getBtcTxHashesAlreadyProcessed();
} catch (IOException e) {
throw new RuntimeException("Exception trying to gather hashes already processed for benchmarking");
}
for (int i = 0; i < hashesToGenerate; i++) {
Sha256Hash hash = Sha256Hash.of(BigInteger.valueOf(rnd.nextLong()).toByteArray());
long height = Helper.randomInRange(minHeight, maxHeight);
hashesAlreadyProcessed.put(hash, height);
if (i == randomHashIndex) {
randomHashInMap = hash;
}
}
};
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class LockWhitelistTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minSize = 10;
final int maxSize = 100;
final int minBtcBlocks = 500;
final int maxBtcBlocks = 1000;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
lockWhitelist = provider.getLockWhitelist();
int size = Helper.randomInRange(minSize, maxSize);
for (int i = 0; i < size; i++) {
Address address = new BtcECKey().toAddress(networkParameters);
Coin value = Helper.randomCoin(Coin.COIN, 1, 30);
lockWhitelist.put(address, value);
}
};
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class StateForBtcReleaseClientTest method getInitializer.
private BridgeStorageProviderInitializer getInitializer() {
final int minNumTxs = 1;
final int maxNumTxs = 100;
final int minNumInputs = 1;
final int maxNumInputs = 10;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Map<Keccak256, BtcTransaction> txsWaitingForSignatures;
try {
txsWaitingForSignatures = provider.getRskTxsWaitingForSignatures();
} catch (IOException e) {
throw new RuntimeException("Exception while trying to gather txs waiting for signatures for storage initialization");
}
int numTxs = Helper.randomInRange(minNumTxs, maxNumTxs);
for (int i = 0; i < numTxs; i++) {
BtcTransaction releaseTx = new BtcTransaction(networkParameters);
Federation federation = bridgeConstants.getGenesisFederation();
// Receiver and amounts
Address toAddress = new BtcECKey().toAddress(networkParameters);
Coin releaseAmount = Coin.CENT.multiply(Helper.randomInRange(10, 100));
releaseTx.addOutput(releaseAmount, toAddress);
// Input generation
int numInputs = Helper.randomInRange(minNumInputs, maxNumInputs);
for (int j = 0; j < numInputs; j++) {
Coin inputAmount = releaseAmount.divide(numInputs);
BtcTransaction inputTx = new BtcTransaction(networkParameters);
inputTx.addOutput(inputAmount, federation.getAddress());
releaseTx.addInput(inputTx.getOutput(0)).setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation));
}
Keccak256 rskTxHash = new Keccak256(HashUtil.keccak256(BigInteger.valueOf(new Random().nextLong()).toByteArray()));
txsWaitingForSignatures.put(rskTxHash, releaseTx);
}
};
}
Aggregations