Search in sources :

Example 36 with WorldDslProcessor

use of co.rsk.test.dsl.WorldDslProcessor in project rskj by rsksmart.

the class WorldDslProcessorTest method processBlockChainCommandWithOneChildBlock.

@Test
public void processBlockChainCommandWithOneChildBlock() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("block_chain g00 b01");
    processor.processCommands(parser);
    Block genesis = world.getBlockByName("g00");
    Block block = world.getBlockByName("b01");
    Assert.assertNotNull(block);
    Assert.assertEquals(1, block.getNumber());
    Assert.assertEquals(genesis.getHash(), block.getParentHash());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) World(co.rsk.test.World) Test(org.junit.Test)

Example 37 with WorldDslProcessor

use of co.rsk.test.dsl.WorldDslProcessor in project rskj by rsksmart.

the class WorldDslProcessorTest method processTransactionWithDataBuildCommand.

@Test
public void processTransactionWithDataBuildCommand() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1\naccount_new acc2\ntransaction_build tx01\nsender acc1\nreceiver acc2\nvalue 1000\ndata 01020304\nbuild");
    processor.processCommands(parser);
    Account acc1 = world.getAccountByName("acc1");
    Account acc2 = world.getAccountByName("acc2");
    Assert.assertNotNull(acc1);
    Assert.assertNotNull(acc2);
    Transaction tx01 = world.getTransactionByName("tx01");
    Assert.assertNotNull(tx01);
    Assert.assertArrayEquals(acc1.getAddress().getBytes(), tx01.getSender().getBytes());
    Assert.assertArrayEquals(acc2.getAddress().getBytes(), tx01.getReceiveAddress().getBytes());
    Assert.assertEquals(new BigInteger("1000"), tx01.getValue().asBigInteger());
    Assert.assertNotNull(tx01.getData());
    Assert.assertArrayEquals(new byte[] { 0x01, 0x02, 0x03, 0x04 }, tx01.getData());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Example 38 with WorldDslProcessor

use of co.rsk.test.dsl.WorldDslProcessor in project rskj by rsksmart.

the class WorldDslProcessorTest method processAssertBestCommand.

@Test
public void processAssertBestCommand() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("block_chain g00 b01 b02\nblock_connect b01 b02\nassert_best b02");
    processor.processCommands(parser);
    Block parent = world.getBlockByName("b01");
    Block block = world.getBlockChain().getStatus().getBestBlock();
    Assert.assertNotNull(parent);
    Assert.assertNotNull(block);
    Assert.assertEquals(2, block.getNumber());
    Assert.assertEquals(parent.getHash(), block.getParentHash());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) World(co.rsk.test.World) Test(org.junit.Test)

Example 39 with WorldDslProcessor

use of co.rsk.test.dsl.WorldDslProcessor in project rskj by rsksmart.

the class WorldDslProcessorTest method processBlockConnectCommand.

@Test
public void processBlockConnectCommand() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("block_chain g00 b01\nblock_connect b01");
    processor.processCommands(parser);
    Block genesis = world.getBlockByName("g00");
    Block block = world.getBlockChain().getStatus().getBestBlock();
    Assert.assertNotNull(block);
    Assert.assertEquals(1, block.getNumber());
    Assert.assertEquals(genesis.getHash(), block.getParentHash());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) World(co.rsk.test.World) Test(org.junit.Test)

Example 40 with WorldDslProcessor

use of co.rsk.test.dsl.WorldDslProcessor in project rskj by rsksmart.

the class WorldDslProcessorTest method processBlockBuildCommandWithTransactions.

@Test
public void processBlockBuildCommandWithTransactions() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1\naccount_new acc2\n" + "transaction_build tx01\nsender acc1\nreceiver acc2\nvalue 1000\nbuild\n" + "transaction_build tx02\nsender acc1\nreceiver acc2\nvalue 1000\nbuild\n" + "block_build b01\nparent g00\ntransactions tx01 tx02\nbuild\n");
    processor.processCommands(parser);
    Block block = world.getBlockByName("b01");
    Assert.assertNotNull(block);
    Assert.assertEquals(1, block.getNumber());
    Assert.assertNotNull(block.getTransactionsList());
    Assert.assertFalse(block.getTransactionsList().isEmpty());
    Assert.assertEquals(2, block.getTransactionsList().size());
    Transaction tx01 = world.getTransactionByName("tx01");
    Transaction tx02 = world.getTransactionByName("tx02");
    Assert.assertNotNull(tx01);
    Assert.assertNotNull(tx02);
    Assert.assertEquals(tx01.getHash(), block.getTransactionsList().get(0).getHash());
    Assert.assertEquals(tx02.getHash(), block.getTransactionsList().get(1).getHash());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)43 Test (org.junit.Test)43 DslParser (co.rsk.test.dsl.DslParser)42 World (co.rsk.test.World)24 Block (org.ethereum.core.Block)13 Account (org.ethereum.core.Account)7 BigInteger (java.math.BigInteger)6 Transaction (org.ethereum.core.Transaction)6 DslProcessorException (co.rsk.test.dsl.DslProcessorException)2 TransactionInfo (org.ethereum.db.TransactionInfo)2 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)1 DataWord (org.ethereum.vm.DataWord)1