package
1.8.0-rc1
Repository: https://github.com/hermeznetwork/hermez-node.git
Documentation: pkg.go.dev

# README

Til (Test instructions language)

Language to define sets of instructions to simulate Hermez transactions (L1 & L2) with real data.

Syntax

Global

  • Set type definition
    • Blockchain: generate the transactions that would come from the Hermez smart contract on the blockchain.
    Type: Blockchain
    
    • PoolL2: generate the transactions that would come from the Pool of L2Txs
    Type: PoolL2
    

Blockchain set of instructions

Available instructions:

Type: Blockchain

// add the TokenID:
AddToken(1)

// deposit of TokenID=1, on the account of tokenID=1 for the user A, of an
// amount of 50 units
CreateAccountDeposit(1) A: 50

// create the account of TokenID=1 for the user B, deposit of TokenID=1, on the
// account of tokenID=1 for the user B, of an amount of 40 units and atomically
// transfer 10 units to account of tokenID=1 for the user A
CreateAccountDepositTransfer(1) B-A: 40, 10

// transaction generated by the Coordinator, create account for user User0 for
// the TokenID=2, with a deposit of 0
CreateAccountCoordinator(2) User0


// deposit of TokenID=1, at the account A, of 6 units
Deposit(1) A: 6

// deposit of TokenID=1, on the account of tokenID=1 for the user B, of an
// amount of 6 units and atomically transfer 10 units to account of tokenID=1 for
// the user A
DepositTransfer(1) B-A: 6, 4

// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 3. Transaction will be a L2Tx
Transfer(1) A-B: 6 (3)

// exit of TokenID=1, from the account A (for that token), of 5 units, paying a
// fee of 1. Transaction will be a L2Tx
Exit(1) A: 5 (1)

// force-transfer of TokenID=1, from the account A to B (for that token), of 6
// units. Transaction will be L1UserTx of ForceTransfer type
ForceTransfer(1) A-B: 6

// force-exit of TokenID=1, from the account A (for that token), of 5 units.
// Transaction will be L1UserTx of ForceExit type
ForceExit(1) A: 5

// advance one batch, forging without L1UserTxs, only can contain L2Txs and
// L1CoordinatorTxs
> batch

// advance one batch, forging with L1UserTxs (and L2Txs and L1CoordinatorTxs)
> batchL1

// advance an ethereum block
> block

PoolL2 set of instructions

Available instructions:

Type: PoolL2

// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 4
PoolTransfer(1) A-B: 6 (4)

// exit of TokenID=1, from the account A (for that token), of 3 units, paying a
// fee of 1
PoolExit(1) A: 3 (1)

Usage

// create a new til.Context
tc := til.NewContext(eth.RollupConstMaxL1UserTx)

// generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
blocks, err = tc.GenerateBlocks(common.SetBlockchainMinimumFlow0)
assert.Nil(t, err)

// generate PoolL2 transactions data from the common.SetPool0 instructions set
poolL2Txs, err = tc.GeneratePoolL2Txs(common.SetPoolL2MinimumFlow0)
assert.Nil(t, err)

Where blocks will contain:

// BatchData contains the information of a Batch
type BatchData struct {
    L1CoordinatorTxs     []common.L1Tx
    L2Txs                []common.L2Tx
    CreatedAccounts []common.Account
}

// BlockData contains the information of a Block
type BlockData struct {
    L1UserTxs        []common.L1Tx
    Batches          []BatchData
    RegisteredTokens []common.Token
}

# Functions

L1TxsToCommonL1Txs converts an array of []til.L1Tx to []common.L1Tx.
NewContext returns a new Context.
NewUser creates a User deriving its keys at the path keyDerivationIndex.

# Constants

nolint.
val.
nolint.
nolint.

# Variables

SetTypeBlockchain defines the type 'Blockchain' of the set.
SetTypePoolL2 defines the type 'PoolL2' of the set.
TxTypeCreateAccountDepositCoordinator is used for testing purposes only, and represents the common.TxType of a create acount deposit made by the coordinator.
nolint:gosec.
TypeNewBatch is used for testing purposes only, and represents the common.TxType of a new batch.
TypeNewBatchL1 is used for testing purposes only, and represents the common.TxType of a new batch.
TypeNewBlock is used for testing purposes only, and represents the common.TxType of a new ethereum block.

# Structs

Account contains the data related to the account for a specific TokenID of a User.
ConfigExtra is the configuration used in FillBlocksExtra to extend the blocks returned by til.
Context contains the data of the test.
Instruction is the data structure that represents one line of code.
L1Tx is the data structure used internally for transaction test generation, which contains a common.L1Tx data plus some intermediate data for the transaction generation.
L2Tx is the data structure used internally for transaction test generation, which contains a common.L2Tx data plus some intermediate data for the transaction generation.
User contains the data related to a testing user.