Search in sources :

Example 41 with WorldDslProcessor

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

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

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

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