You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.3 KiB

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