Using a DSL (Domain Specific Language) for RSK Java implementation tests

Some examples

Partial list of DSL files with actions to be executed and tested
# create account with initial balance
account_new acc1 10000000

# check account balance
assert_balance acc1 10000000
# Create two blocks, starting from genesis block
block_chain g00 b01 b02

# Add the two blocks, in order, to current block chain
block_connect b01 b02

# Assert best block
assert_best b02

# Assert latest connect result
assert_connect best
# Create one block and two uncles
block_chain g00 b01
block_chain g00 u01
block_chain g00 u02

# Create second block with uncles

block_build b02
parent b01
uncles u01 u02
build

# Add the two blocks
block_connect b01 u01 u02 b02

# Assert best block
assert_best b02

# Assert latest connect result
assert_connect best
account_new acc1 10000000
account_new acc2 0

transaction_build tx01
sender acc1
receiver acc2
value 1000
build

block_build b01
parent g00
transactions tx01
build

block_connect b01

# Assert best block
assert_best b01

assert_balance acc2 1000
account_new acc1 10000000

# Create empty.sol contract

transaction_build tx01
sender acc1
receiverAddress 00
value 0
data 60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a72305820b25edb28bec763685838b8044760e105b5385638276b4768c8045237b8fc6bf10029
gas 1200000
build

block_build b01
parent g00
transactions tx01
build

block_connect b01

# Assert best block
assert_best b01

# The code test checks the gas used
comment

// Contracts compiled using
// Truffle v5.1.14 (core: 5.1.14)
// Solidity v0.5.16 (solc-js)
// the contract to be deployed is RecursiveParent

// the contracts source code

// RecursiveInterface.sol

pragma solidity >=0.5.0 <0.6.0;

interface RecursiveInterface {
function increment(uint level) external;
}

// RecursiveParent.sol

pragma solidity >=0.5.0 <0.6.0;

import "./RecursiveInterface.sol";
import "./RecursiveChild.sol";

contract RecursiveParent is RecursiveInterface {
// ....// end of comment
end

Usage

@Test
public void runTransfers01Resource() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/transfers01.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

Assert.assertNotNull(world.getAccountByName("acc1"));
Assert.assertNotNull(world.getAccountByName("acc2"));
Assert.assertNotNull(world.getTransactionByName("tx01"));
Assert.assertNotNull(world.getBlockByName("b01"));
}

The package

DSL Parser, Commands, Processors and World builder

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store