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, paying a fee of 2
 31CreateAccountDepositTransfer(1) B-A: 40, 10 (2)
 32
 33// transaction generated by the Coordinator, create account for user User0 for
 34// the TokenID=2, with a deposit of 0
 35CreateAccountDepositCoordinator(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, paying a fee of 2
 44DepositTransfer(1) B-A: 6, 4 (2)
 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.
 51// Transaction will be a L2Tx
 52Exit(1) A: 5
 53
 54// force-transfer of TokenID=1, from the account A to B (for that token), of 6
 55// units, paying a fee of 3. Transaction will be L1UserTx of ForceTransfer type
 56ForceTransfer(1) A-B: 6 (3)
 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
 83PoolExit(1) A: 3
 84```
 85
 86## Usage
 87```go
 88// create a new til.Context
 89tc := til.NewContext(eth.RollupConstMaxL1UserTx)
 90
 91// generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
 92blocks, err = tc.GenerateBlocks(common.SetBlockchain0)
 93assert.Nil(t, err)
 94
 95// generate PoolL2 transactions data from the common.SetPool0 instructions set
 96poolL2Txs, err = tc.GenerateBlocks(common.SetPool0)
 97assert.Nil(t, err)
 98```
 99
100Where `blocks` will contain:
101```go
102// BatchData contains the information of a Batch
103type BatchData struct {
104    L1CoordinatorTxs     []common.L1Tx
105    L2Txs                []common.L2Tx
106    CreatedAccounts []common.Account
107}
108
109// BlockData contains the information of a Block
110type BlockData struct {
111    L1UserTxs        []common.L1Tx
112    Batches          []BatchData
113    RegisteredTokens []common.Token
114}
115```