use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.
the class BlockChainImplInvalidTest method setup.
@Before
public void setup() {
objects = new RskTestContext(new String[0]) {
@Override
protected synchronized RskSystemProperties buildRskSystemProperties() {
RskSystemProperties rskSystemProperties = super.buildRskSystemProperties();
ActivationConfig activationConfigSpy = spy(rskSystemProperties.getActivationConfig());
RskSystemProperties rskSystemPropertiesSpy = spy(rskSystemProperties);
doReturn(true).when(activationConfigSpy).isActive(eq(ConsensusRule.RSKIP126), anyLong());
doReturn(activationConfigSpy).when(rskSystemPropertiesSpy).getActivationConfig();
return rskSystemPropertiesSpy;
}
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
}
@Override
public BlockValidator buildBlockValidator() {
return new BlockValidatorImpl(getBlockStore(), getBlockParentDependantValidationRule(), getBlockValidationRule());
}
};
blockChain = objects.getBlockchain();
}
use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.
the class BlockChainImplTest method setup.
@Before
public void setup() {
objects = new RskTestFactory() {
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
}
@Override
protected CompositeEthereumListener buildCompositeEthereumListener() {
return new BlockExecutorTest.SimpleEthereumListener();
}
};
config = objects.getRskSystemProperties();
blockChain = objects.getBlockchain();
blockStore = objects.getBlockStore();
blockExecutor = objects.getBlockExecutor();
listener = (BlockExecutorTest.SimpleEthereumListener) objects.getCompositeEthereumListener();
}
use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.
the class MainNetMinerTest method setup.
@Before
public void setup() {
config = spy(new TestSystemProperties());
when(config.getNetworkConstants()).thenReturn(Constants.mainnet());
when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.all());
RskTestFactory factory = new RskTestFactory(config) {
@Override
public GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true) {
@Override
public Genesis load() {
Genesis genesis = super.load();
genesis.getHeader().setDifficulty(new BlockDifficulty(BigInteger.valueOf(300000)));
return genesis;
}
};
}
};
mainchainView = factory.getMiningMainchainView();
transactionPool = factory.getTransactionPool();
blockStore = factory.getBlockStore();
blockProcessor = factory.getNodeBlockProcessor();
repositoryLocator = factory.getRepositoryLocator();
blockFactory = factory.getBlockFactory();
blockExecutor = factory.getBlockExecutor();
}
use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.
the class TransactionTest method multiSuicideTest.
@Test
public void multiSuicideTest() throws IOException, InterruptedException {
/*
Original contract
pragma solidity ^0.4.3;
contract PsychoKiller {
function () payable {}
function homicide() {
suicide(msg.sender);
}
function multipleHomicide() {
PsychoKiller k = this;
k.homicide();
k.homicide();
k.homicide();
k.homicide();
}
}
*/
BigInteger nonce = config.getNetworkConstants().getInitialNonce();
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
MutableRepository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
Blockchain blockchain = ImportLightTest.createBlockchain(new TestGenesisLoader(trieStore, getClass().getResourceAsStream("/genesis/genesis-light.json"), nonce, false, true, true).load(), config, repository, blockStore, trieStore);
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
System.out.println("address: " + ByteUtil.toHexString(sender.getAddress()));
String code = "6060604052341561000c57fe5b5b6102938061001c6000396000f3006060604052361561004a576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806309e587a514610053578063de990da914610065575b6100515b5b565b005b341561005b57fe5b610063610077565b005b341561006d57fe5b610075610092565b005b3373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60003090508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b15156100fa57fe5b60325a03f1151561010757fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b151561016d57fe5b60325a03f1151561017a57fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b15156101e057fe5b60325a03f115156101ed57fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b151561025357fe5b60325a03f1151561026057fe5b5050505b505600a165627a7a72305820084e74021c556522723b6725354378df2fb4b6732f82dd33f5daa29e2820b37c0029";
String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"homicide\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"multipleHomicide\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"payable\":true,\"type\":\"fallback\"}]";
Transaction tx = createTx(sender, new byte[0], Hex.decode(code), repository);
executeTransaction(blockchain, blockStore, tx, repository, blockTxSignatureCache);
byte[] contractAddress = tx.getContractAddress().getBytes();
CallTransaction.Contract contract1 = new CallTransaction.Contract(abi);
byte[] callData = contract1.getByName("multipleHomicide").encode();
Assert.assertNull(contract1.getConstructor());
Assert.assertNotNull(contract1.parseInvocation(callData));
Assert.assertNotNull(contract1.parseInvocation(callData).toString());
try {
contract1.parseInvocation(new byte[32]);
Assert.fail();
} catch (RuntimeException ex) {
}
try {
contract1.parseInvocation(new byte[2]);
Assert.fail();
} catch (RuntimeException ex) {
}
Transaction tx1 = createTx(sender, contractAddress, callData, repository);
ProgramResult programResult = executeTransaction(blockchain, blockStore, tx1, repository, blockTxSignatureCache).getResult();
// suicide of a single account should be counted only once
Assert.assertEquals(24000, programResult.getFutureRefund());
}
use of co.rsk.core.genesis.TestGenesisLoader in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainWithInconsistentBlock.
@Test
public void testLoadBlockchainWithInconsistentBlock() {
RskTestFactory objects = new RskTestFactory() {
@Override
protected synchronized RepositoryLocator buildRepositoryLocator() {
RepositoryLocator repositoryLocatorSpy = spy(super.buildRepositoryLocator());
doReturn(Optional.empty()).when(repositoryLocatorSpy).findSnapshotAt(any());
return repositoryLocatorSpy;
}
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "blockchain_loader_genesis.json", BigInteger.ZERO, true, true, true);
}
};
try {
// calls loadBlockchain
objects.getBlockchain();
fail();
} catch (RuntimeException e) {
String errorMessage = String.format("Best block is not consistent with the state db. Consider using `%s` cli tool to rewind inconsistent blocks", RewindBlocks.class.getSimpleName());
assertEquals(errorMessage, e.getMessage());
}
}
Aggregations