use of org.ethereum.config.blockchain.upgrades.ConsensusRule in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.
@Test
public void testLoadBlockchainEmptyBlockchain() {
RskTestFactory objects = new RskTestFactory() {
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "blockchain_loader_genesis.json", BigInteger.ZERO, true, true, true);
}
};
// calls loadBlockchain
Blockchain blockchain = objects.getBlockchain();
RepositorySnapshot repository = objects.getRepositoryLocator().snapshotAt(blockchain.getBestBlock().getHeader());
TestSystemProperties testSystemProperties = new TestSystemProperties();
ActivationConfig.ForBlock activations = testSystemProperties.getActivationConfig().forBlock(0);
int enabledPCCs = PrecompiledContracts.GENESIS_ADDRESSES.size();
for (ConsensusRule consensusRule : PrecompiledContracts.CONSENSUS_ENABLED_ADDRESSES.values()) {
if (activations.isActive(consensusRule)) {
enabledPCCs++;
}
}
int testAccountsSize = 3;
// PCCs + test accounts in blockchain_loader_genesis.json
int genesisAccountKeysSize = enabledPCCs + testAccountsSize;
Assert.assertEquals(genesisAccountKeysSize, repository.getAccountsKeys().size());
RskAddress daba01 = new RskAddress("dabadabadabadabadabadabadabadabadaba0001");
Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(daba01));
Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(daba01));
RskAddress daba02 = new RskAddress("dabadabadabadabadabadabadabadabadaba0002");
Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(daba02));
Assert.assertEquals(BigInteger.ZERO, repository.getNonce(daba02));
RskAddress address = new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051");
Assert.assertEquals(Coin.valueOf(10), repository.getBalance(address));
Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(address));
Assert.assertEquals(DataWord.ONE, repository.getStorageValue(address, DataWord.ZERO));
Assert.assertEquals(DataWord.valueOf(3), repository.getStorageValue(address, DataWord.ONE));
Assert.assertEquals(274, Objects.requireNonNull(repository.getCode(address)).length);
}
use of org.ethereum.config.blockchain.upgrades.ConsensusRule in project rskj by rsksmart.
the class BridgeSupportTest method assertRefundInProcessPegInVersion1.
private void assertRefundInProcessPegInVersion1(TxSenderAddressType lockSenderAddressType, Optional<Address> btcRefundAddress, List<ConsensusRule> consensusRules) throws IOException, RegisterBtcTransactionException, PeginInstructionsException {
// Arrange
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
for (ConsensusRule consensusRule : consensusRules) {
when(activations.isActive(consensusRule)).thenReturn(true);
}
Repository repository = createRepository();
BtcECKey srcKey1 = new BtcECKey();
ECKey key = ECKey.fromPublicOnly(srcKey1.getPubKey());
RskAddress rskAddress = new RskAddress(key.getAddress());
Address btcSenderAddress = null;
if (lockSenderAddressType != TxSenderAddressType.UNKNOWN) {
btcSenderAddress = srcKey1.toAddress(btcParams);
}
BtcTransaction btcTx = new BtcTransaction(btcParams);
btcTx.addOutput(Coin.COIN.multiply(10), bridgeConstants.getGenesisFederation().getAddress());
btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[] {}));
BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
ReleaseTransactionSet releaseTransactionSet = new ReleaseTransactionSet(new HashSet<>());
when(provider.getReleaseTransactionSet()).thenReturn(releaseTransactionSet);
when(provider.getLockingCap()).thenReturn(Coin.COIN.multiply(1));
BtcLockSenderProvider btcLockSenderProvider = getBtcLockSenderProvider(lockSenderAddressType, btcSenderAddress, rskAddress);
if (!btcRefundAddress.isPresent() && btcSenderAddress != null) {
btcRefundAddress = Optional.of(btcSenderAddress);
}
PeginInstructionsProvider peginInstructionsProvider = getPeginInstructionsProviderForVersion1(rskAddress, btcRefundAddress);
BridgeSupport bridgeSupport = getBridgeSupport(bridgeConstants, provider, repository, btcLockSenderProvider, peginInstructionsProvider, mock(Block.class), mock(BtcBlockStoreWithCache.Factory.class), activations);
// Act
bridgeSupport.processPegIn(btcTx, mock(Transaction.class), 0, mock(Sha256Hash.class));
// Assert
if (lockSenderAddressType == TxSenderAddressType.UNKNOWN && !btcRefundAddress.isPresent()) {
// Unknown sender and no refund address. Can't refund
Assert.assertEquals(0, releaseTransactionSet.getEntries().size());
} else {
Assert.assertEquals(1, releaseTransactionSet.getEntries().size());
// Check rejection tx input was created from btc tx and sent to the btc refund address indicated by the user
boolean successfulRejection = false;
for (ReleaseTransactionSet.Entry e : releaseTransactionSet.getEntries()) {
BtcTransaction refundTx = e.getTransaction();
if (refundTx.getInput(0).getOutpoint().getHash() == btcTx.getHash() && refundTx.getOutput(0).getScriptPubKey().getToAddress(btcParams).equals(btcRefundAddress.get())) {
successfulRejection = true;
break;
}
}
Assert.assertTrue(successfulRejection);
}
}
use of org.ethereum.config.blockchain.upgrades.ConsensusRule in project rskj by rsksmart.
the class BlockExecutor method maintainPrecompiledContractStorageRoots.
/**
* Precompiled contracts storage is setup like any other contract for consistency. Here, we apply this logic on the
* exact activation block.
* This method is called automatically for every block except for the Genesis (which makes an explicit call).
*/
public static void maintainPrecompiledContractStorageRoots(Repository track, ActivationConfig.ForBlock activations) {
if (activations.isActivating(RSKIP126)) {
for (RskAddress addr : PrecompiledContracts.GENESIS_ADDRESSES) {
if (!track.isExist(addr)) {
track.createAccount(addr);
}
track.setupContract(addr);
}
}
for (Map.Entry<RskAddress, ConsensusRule> e : PrecompiledContracts.CONSENSUS_ENABLED_ADDRESSES.entrySet()) {
ConsensusRule contractActivationRule = e.getValue();
if (activations.isActivating(contractActivationRule)) {
RskAddress addr = e.getKey();
track.createAccount(addr);
track.setupContract(addr);
}
}
}
Aggregations