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.

116 lines
3.3 KiB

Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
  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. // add the TokenID:
  19. AddToken(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
  26. CreateAccountDepositTransfer(1) B-A: 40, 10
  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
  35. DepositTransfer(1) B-A: 6, 4
  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, paying a
  40. // fee of 1. Transaction will be a L2Tx
  41. Exit(1) A: 5 (1)
  42. // force-transfer of TokenID=1, from the account A to B (for that token), of 6
  43. // units. Transaction will be L1UserTx of ForceTransfer type
  44. ForceTransfer(1) A-B: 6
  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, paying a
  64. // fee of 1
  65. PoolExit(1) A: 3 (1)
  66. ```
  67. ## Usage
  68. ```go
  69. // create a new til.Context
  70. tc := til.NewContext(eth.RollupConstMaxL1UserTx)
  71. // generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
  72. blocks, err = tc.GenerateBlocks(common.SetBlockchain0)
  73. assert.Nil(t, err)
  74. // generate PoolL2 transactions data from the common.SetPool0 instructions set
  75. poolL2Txs, err = tc.GenerateBlocks(common.SetPool0)
  76. assert.Nil(t, err)
  77. ```
  78. Where `blocks` will contain:
  79. ```go
  80. // BatchData contains the information of a Batch
  81. type BatchData struct {
  82. L1CoordinatorTxs []common.L1Tx
  83. L2Txs []common.L2Tx
  84. CreatedAccounts []common.Account
  85. }
  86. // BlockData contains the information of a Block
  87. type BlockData struct {
  88. L1UserTxs []common.L1Tx
  89. Batches []BatchData
  90. RegisteredTokens []common.Token
  91. }
  92. ```