Search in sources :

Example 21 with DslParser

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

the class WorldDslProcessorTest method processTransactionBuildCommand.

@Test
public void processTransactionBuildCommand() 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\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.assertEquals(0, tx01.getData().length);
}
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 22 with DslParser

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

the class WorldDslProcessorTest method processAssertBalance.

@Test
public void processAssertBalance() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1 1000\nassert_balance acc1 1000\n");
    processor.processCommands(parser);
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) DslParser(co.rsk.test.dsl.DslParser) World(co.rsk.test.World) Test(org.junit.Test)

Example 23 with DslParser

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

the class WorldDslProcessorTest method processAssertConnectWithBlockWithoutParent.

@Test
public void processAssertConnectWithBlockWithoutParent() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("block_chain g00 b01 b02\nblock_connect b02\nassert_connect no_parent");
    processor.processCommands(parser);
    Block block = world.getBlockChain().getStatus().getBestBlock();
    Assert.assertNotNull(block);
    Assert.assertEquals(0, block.getNumber());
}
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 24 with DslParser

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

the class WorldDslProcessorTest method processTransactionWithGasAndGasPriceBuildCommand.

@Test
public void processTransactionWithGasAndGasPriceBuildCommand() 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\ngas 1200000\ngasPrice 2\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.assertEquals(0, tx01.getData().length);
    Assert.assertEquals(new BigInteger("2"), tx01.getGasPrice().asBigInteger());
    Assert.assertEquals(new BigInteger("1200000"), tx01.getGasLimitAsInteger());
}
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 25 with DslParser

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

the class WorldDslProcessorTest method processBlockBuildCommandWithUncles.

@Test
public void processBlockBuildCommandWithUncles() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("block_chain g00 b01\nblock_chain g00 u01\nblock_chain g00 u02\nblock_build b02\nparent b01\nuncles u01 u02\nbuild");
    processor.processCommands(parser);
    Block block = world.getBlockByName("b02");
    Assert.assertNotNull(block);
    Assert.assertEquals(2, block.getNumber());
    Assert.assertNotNull(block.getUncleList());
    Assert.assertFalse(block.getUncleList().isEmpty());
    Assert.assertEquals(2, block.getUncleList().size());
    Assert.assertEquals(world.getBlockByName("u01").getHash(), block.getUncleList().get(0).getHash());
    Assert.assertEquals(world.getBlockByName("u02").getHash(), block.getUncleList().get(1).getHash());
}
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)

Aggregations

DslParser (co.rsk.test.dsl.DslParser)50 Test (org.junit.Test)50 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)42 World (co.rsk.test.World)23 Block (org.ethereum.core.Block)13 DslCommand (co.rsk.test.dsl.DslCommand)7 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