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());
}
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());
}
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());
}
Aggregations