arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/test/til/README.md
test/til/README.mdRaw
  1# Til (Test instructions language)
  2Language to define sets of instructions to simulate Hermez transactions (L1 & L2) with real data.
  3
  4## Syntax
  5### Global
  6- Set type definition
  7    - Blockchain: generate the transactions that would come from the Hermez smart contract on the blockchain.
  8	```
  9	Type: Blockchain
 10	```
 11    - PoolL2: generate the transactions that would come from the Pool of L2Txs
 12	```
 13	Type: PoolL2
 14	```
 15
 16### Blockchain set of instructions
 17Available instructions:
 18```go
 19Type: Blockchain
 20
 21// add the TokenID:
 22AddToken(1)
 23
 24// deposit of TokenID=1, on the account of tokenID=1 for the user A, of an
 25// amount of 50 units
 26CreateAccountDeposit(1) A: 50
 27
 28// create the account of TokenID=1 for the user B, deposit of TokenID=1, on the
 29// account of tokenID=1 for the user B, of an amount of 40 units and atomically
 30// transfer 10 units to account of tokenID=1 for the user A
 31CreateAccountDepositTransfer(1) B-A: 40, 10
 32
 33// transaction generated by the Coordinator, create account for user User0 for
 34// the TokenID=2, with a deposit of 0
 35CreateAccountCoordinator(2) User0
 36
 37
 38// deposit of TokenID=1, at the account A, of 6 units
 39Deposit(1) A: 6
 40
 41// deposit of TokenID=1, on the account of tokenID=1 for the user B, of an
 42// amount of 6 units and atomically transfer 10 units to account of tokenID=1 for
 43// the user A
 44DepositTransfer(1) B-A: 6, 4
 45
 46// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
 47// paying a fee of 3. Transaction will be a L2Tx
 48Transfer(1) A-B: 6 (3)
 49
 50// exit of TokenID=1, from the account A (for that token), of 5 units, paying a
 51// fee of 1. Transaction will be a L2Tx
 52Exit(1) A: 5 (1)
 53
 54// force-transfer of TokenID=1, from the account A to B (for that token), of 6
 55// units. Transaction will be L1UserTx of ForceTransfer type
 56ForceTransfer(1) A-B: 6
 57
 58// force-exit of TokenID=1, from the account A (for that token), of 5 units.
 59// Transaction will be L1UserTx of ForceExit type
 60ForceExit(1) A: 5
 61
 62// advance one batch, forging without L1UserTxs, only can contain L2Txs and
 63// L1CoordinatorTxs
 64> batch
 65
 66// advance one batch, forging with L1UserTxs (and L2Txs and L1CoordinatorTxs)
 67> batchL1
 68
 69// advance an ethereum block
 70> block
 71```
 72
 73### PoolL2 set of instructions
 74Available instructions:
 75```go
 76Type: PoolL2
 77
 78// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
 79// paying a fee of 4
 80PoolTransfer(1) A-B: 6 (4)
 81
 82// exit of TokenID=1, from the account A (for that token), of 3 units, paying a
 83// fee of 1
 84PoolExit(1) A: 3 (1)
 85```
 86
 87## Usage
 88```go
 89// create a new til.Context
 90tc := til.NewContext(eth.RollupConstMaxL1UserTx)
 91
 92// generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
 93blocks, err = tc.GenerateBlocks(common.SetBlockchain0)
 94assert.Nil(t, err)
 95
 96// generate PoolL2 transactions data from the common.SetPool0 instructions set
 97poolL2Txs, err = tc.GenerateBlocks(common.SetPool0)
 98assert.Nil(t, err)
 99```
100
101Where `blocks` will contain:
102```go
103// BatchData contains the information of a Batch
104type BatchData struct {
105    L1CoordinatorTxs     []common.L1Tx
106    L2Txs                []common.L2Tx
107    CreatedAccounts []common.Account
108}
109
110// BlockData contains the information of a Block
111type BlockData struct {
112    L1UserTxs        []common.L1Tx
113    Batches          []BatchData
114    RegisteredTokens []common.Token
115}
116```