Search in sources :

Example 6 with WorldDslProcessor

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

the class DslFilesTest method runCreate01Resource.

@Test
public void runCreate01Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/create01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Transaction transaction = world.getTransactionByName("tx01");
    Assert.assertNotNull(transaction);
    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash().getBytes());
    Assert.assertNotNull(txinfo);
    BigInteger gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed());
    Assert.assertNotEquals(BigInteger.ZERO, gasUsed);
    // According to TestRPC and geth, the gas used is 0x010c2d
    Assert.assertEquals(BigIntegers.fromUnsignedByteArray(Hex.decode("010c2d")), gasUsed);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) TransactionInfo(org.ethereum.db.TransactionInfo) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 7 with WorldDslProcessor

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

the class DslFilesTest method runContracts06Resource.

@Test
public void runContracts06Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/contracts06.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Test(org.junit.Test)

Example 8 with WorldDslProcessor

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

the class DslFilesTest method runLogs01Resource.

@Test
public void runLogs01Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/logs01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    // the transaction receipt should have three logs
    BlockChainStatus status = world.getBlockChain().getStatus();
    Assert.assertEquals(1, status.getBestBlockNumber());
    Block block = status.getBestBlock();
    Assert.assertEquals(1, block.getTransactionsList().size());
    byte[] txhash = block.getTransactionsList().get(0).getHash().getBytes();
    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(txhash);
    // only three events, raised by
    // Counter constructor
    // Counter getValue
    // Creator constructor
    Assert.assertEquals(3, txinfo.getReceipt().getLogInfoList().size());
    // only one topic in each event
    Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(0).getTopics().size());
    Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(1).getTopics().size());
    Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(2).getTopics().size());
    // the topics are different
    DataWord topic1 = txinfo.getReceipt().getLogInfoList().get(0).getTopics().get(0);
    DataWord topic2 = txinfo.getReceipt().getLogInfoList().get(1).getTopics().get(0);
    DataWord topic3 = txinfo.getReceipt().getLogInfoList().get(2).getTopics().get(0);
    Assert.assertNotEquals(topic1, topic2);
    Assert.assertNotEquals(topic1, topic3);
    Assert.assertNotEquals(topic2, topic3);
    // only the third log was directly produced by the created contract
    byte[] contractAddress = txinfo.getReceipt().getTransaction().getContractAddress().getBytes();
    Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(0).getAddress()));
    Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(1).getAddress()));
    Assert.assertTrue(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(2).getAddress()));
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 9 with WorldDslProcessor

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

the class DslFilesTest method runBlocks02Resource.

@Test
public void runBlocks02Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/blocks02.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Assert.assertNotNull(world.getBlockByName("b01"));
    Assert.assertNotNull(world.getBlockByName("c01"));
    Assert.assertEquals(1, world.getBlockChain().getStatus().getBestBlock().getNumber());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Test(org.junit.Test)

Example 10 with WorldDslProcessor

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

the class DslFilesTest method runContracts07Resource.

@Test
public void runContracts07Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/contracts07.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) 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