Search in sources :

Example 86 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class SimpleNode method createNode.

public static SimpleNode createNode() {
    final World world = new World();
    BlockChainImpl blockChain = world.getBlockChain();
    NodeMessageHandler handler = NodeMessageHandlerUtil.createHandler(blockChain);
    return new SimpleNode(handler, blockChain);
}
Also used : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) World(co.rsk.test.World)

Example 87 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class RskForksBridgeTest method before.

@Before
public void before() {
    world = new World();
    blockChain = world.getBlockChain();
    blockStore = world.getBlockStore();
    repositoryLocator = world.getRepositoryLocator();
    trieStore = world.getTrieStore();
    repository = world.getRepository();
    bridgeSupportFactory = world.getBridgeSupportFactory();
    whitelistManipulationKey = ECKey.fromPrivate(Hex.decode("3890187a3071327cee08467ba1b44ed4c13adb2da0d5ffcc0563c371fa88259c"));
    genesis = (Genesis) blockChain.getBestBlock();
    // keyHoldingRSKs = new ECKey();
    co.rsk.core.Coin balance = new co.rsk.core.Coin(new BigInteger("10000000000000000000"));
    repository.addBalance(new RskAddress(fedECPrivateKey.getAddress()), balance);
    co.rsk.core.Coin bridgeBalance = co.rsk.core.Coin.fromBitcoin(BridgeRegTestConstants.getInstance().getMaxRbtc());
    repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, bridgeBalance);
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    Transaction whitelistAddressTx = buildWhitelistTx();
    Transaction receiveHeadersTx = buildReceiveHeadersTx();
    Transaction registerBtctransactionTx = buildRegisterBtcTransactionTx();
    blockBase = buildBlock(genesis, whitelistAddressTx, receiveHeadersTx, registerBtctransactionTx);
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(blockBase));
}
Also used : co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) org.ethereum.core(org.ethereum.core) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Before(org.junit.Before)

Example 88 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class RevertOpCodeTest method runAndRevertThenRunFullContract.

@Test
public void runAndRevertThenRunFullContract() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/opcode_revert2.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Assert.assertNotNull(world.getAccountByName("acc1"));
    Assert.assertTrue(world.getTransactionByName("contract_with_revert").isContractCreation());
    Assert.assertTrue(!world.getTransactionByName("tx02").isContractCreation());
    Assert.assertTrue(!world.getTransactionByName("tx03").isContractCreation());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) World(co.rsk.test.World) Test(org.junit.Test)

Example 89 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class BridgeTest method callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations.

@Test
public void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations() 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();
    World world = new World();
    List<Block> blocks = new BlockGenerator().getSimpleBlockChain(world.getBlockChain().getBestBlock(), 10);
    Transaction rskTx = Transaction.create(config, PrecompiledContracts.BRIDGE_ADDR_STR, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
    rskTx.sign(new ECKey().getPrivKeyBytes());
    world.getBlockChain().getBlockStore().saveBlock(blocks.get(1), new BlockDifficulty(BigInteger.ONE), true);
    Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(rskTx, blocks.get(9), 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(2, provider.getReleaseTransactionSet().getEntries().size());
    Assert.assertEquals(1, provider.getRskTxsWaitingForSignatures().size());
}
Also used : SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) ECKey(org.ethereum.crypto.ECKey) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockDifficulty(co.rsk.core.BlockDifficulty) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) Test(org.junit.Test)

Example 90 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class RskForksBridgeTest method buildBlock.

private Block buildBlock(Block parent, long difficulty) {
    World world = new World(blockChain, genesis);
    BlockBuilder blockBuilder = new BlockBuilder(world).difficulty(difficulty).parent(parent);
    return blockBuilder.build();
}
Also used : World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Aggregations

World (co.rsk.test.World)198 Test (org.junit.Test)169 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)55 DslParser (co.rsk.test.dsl.DslParser)52 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)46 HashMapDB (org.ethereum.datasource.HashMapDB)45 AccountBuilder (co.rsk.test.builders.AccountBuilder)36 Block (org.ethereum.core.Block)36 ReceiptStore (org.ethereum.db.ReceiptStore)34 BlockBuilder (co.rsk.test.builders.BlockBuilder)31 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)31 Blockchain (org.ethereum.core.Blockchain)30 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)24 Transaction (org.ethereum.core.Transaction)23 BigInteger (java.math.BigInteger)17 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Account (org.ethereum.core.Account)15 TestSystemProperties (co.rsk.config.TestSystemProperties)14