Search in sources :

Example 46 with DslParser

use of co.rsk.test.dsl.DslParser 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 47 with DslParser

use of co.rsk.test.dsl.DslParser 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)

Example 48 with DslParser

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

the class WorldDslProcessorTest method processTransactionWithNonceBuildCommand.

@Test
public void processTransactionWithNonceBuildCommand() 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\nnonce 10\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("10"), tx01.getNonceAsInteger());
}
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 49 with DslParser

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

the class WorldDslProcessorTest method processBlockConnectCommandWithTwoBlocksInFork.

@Test
public void processBlockConnectCommandWithTwoBlocksInFork() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("block_chain g00 b01 b02\nblock_chain b01 c02 c03\nblock_connect b01 b02\n" + "block_connect c02 c03");
    processor.processCommands(parser);
    Block parent = world.getBlockByName("c02");
    Block block = world.getBlockChain().getStatus().getBestBlock();
    Assert.assertNotNull(parent);
    Assert.assertNotNull(block);
    Assert.assertEquals(3, 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 50 with DslParser

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

the class RevertOpCodeTest method runFullContractThenRunAndRevert.

/*
    The following sample contract was used for the following tests.
    The require function will invoke the REVERT opcode when the condition isn't met,
    and return all remaining gas.

    pragma solidity ^0.4.0;

    contract Sharer {
        uint8[10] integers;

        function sendHalf() payable returns (uint8 sum) {
            require(msg.value % 2 == 0); // Only allow even numbers

            address creator = msg.sender;         // set the creator address
            uint8 x = 0;                  // initialize an 8-bit, unsigned integer to zero
            while(x < integers.length)    // the variable integers was initialized to length 10
            {
                integers[x] = x;      // set integers to [0,1,2,3,4,5,6,7,8,9] over ten iterations
                x++;
            }

            x = 0;
            while(x < integers.length)
            {
                sum = sum + integers[x];      // sum all integers
                x++;
            }
            return sum;
        }
    }
    */
@Test
public void runFullContractThenRunAndRevert() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/opcode_revert1.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)

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