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.

364 lines
8.1 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`.
3 years ago
  1. package txsets
  2. // sets of instructions to be used in tests of other packages
  3. // NOTE: FeeSelector(126) ~ 10%
  4. // NOTE: FeeSelector(100) ~ 4%
  5. // SetBlockchain0 contains a set of transactions simulated to be from the smart contract
  6. var SetBlockchain0 = `
  7. // Set containing Blockchain transactions
  8. Type: Blockchain
  9. AddToken(1)
  10. AddToken(2)
  11. AddToken(3)
  12. // block:0 batch:1
  13. // Coordinator accounts, Idxs: 256, 257, 258, 259
  14. CreateAccountCoordinator(0) Coord
  15. CreateAccountCoordinator(1) Coord
  16. CreateAccountCoordinator(2) Coord
  17. CreateAccountCoordinator(3) Coord
  18. > batch
  19. // block:0 batch:2
  20. // deposits TokenID: 1
  21. CreateAccountDeposit(1) A: 50
  22. CreateAccountDeposit(1) B: 5
  23. CreateAccountDeposit(1) C: 200
  24. CreateAccountDeposit(1) D: 25
  25. CreateAccountDeposit(1) E: 25
  26. CreateAccountDeposit(1) F: 25
  27. CreateAccountDeposit(1) G: 25
  28. CreateAccountDeposit(1) H: 25
  29. CreateAccountDeposit(1) I: 25
  30. CreateAccountDeposit(1) J: 25
  31. CreateAccountDeposit(1) K: 25
  32. CreateAccountDeposit(1) L: 25
  33. CreateAccountDeposit(1) M: 25
  34. CreateAccountDeposit(1) N: 25
  35. CreateAccountDeposit(1) O: 25
  36. CreateAccountDeposit(1) P: 25
  37. CreateAccountDeposit(1) Q: 25
  38. CreateAccountDeposit(1) R: 25
  39. CreateAccountDeposit(1) S: 25
  40. CreateAccountDeposit(1) T: 25
  41. CreateAccountDeposit(1) U: 25
  42. CreateAccountDeposit(1) V: 25
  43. CreateAccountDeposit(1) W: 25
  44. CreateAccountDeposit(1) X: 25
  45. CreateAccountDeposit(1) Y: 25
  46. CreateAccountDeposit(1) Z: 25
  47. // deposits TokenID: 2
  48. CreateAccountDeposit(2) B: 5
  49. CreateAccountDeposit(2) A: 20
  50. // deposits TokenID: 3
  51. CreateAccountDeposit(3) B: 100
  52. // deposits TokenID: 0
  53. CreateAccountDeposit(0) B: 10000
  54. CreateAccountDeposit(0) C: 1
  55. > batchL1
  56. // block:0 batch:3
  57. // transactions TokenID: 1
  58. Transfer(1) A-B: 5 (1)
  59. Transfer(1) A-L: 10 (1)
  60. Transfer(1) A-M: 5 (1)
  61. Transfer(1) A-N: 5 (1)
  62. Transfer(1) A-O: 5 (1)
  63. Transfer(1) B-C: 3 (1)
  64. Transfer(1) C-A: 10 (126)
  65. Transfer(1) D-A: 5 (1)
  66. Transfer(1) D-Z: 5 (1)
  67. Transfer(1) D-Y: 5 (1)
  68. Transfer(1) D-X: 5 (1)
  69. Transfer(1) E-Z: 5 (2)
  70. Transfer(1) E-Y: 5 (1)
  71. Transfer(1) E-X: 5 (1)
  72. Transfer(1) F-Z: 5 (1)
  73. Transfer(1) G-K: 3 (1)
  74. Transfer(1) G-K: 3 (1)
  75. Transfer(1) G-K: 3 (1)
  76. Transfer(1) H-K: 3 (2)
  77. Transfer(1) H-K: 3 (1)
  78. Transfer(1) H-K: 3 (1)
  79. Transfer(0) B-C: 50 (100)
  80. > batchL1
  81. > block
  82. // block:1 batch:1
  83. // A (3) still does not exist, coordinator should create new L1Tx to create the account
  84. CreateAccountCoordinator(3) A
  85. Transfer(1) A-B: 1 (1)
  86. Transfer(1) A-B: 1 (1)
  87. Transfer(1) A-B: 1 (1)
  88. Transfer(3) B-A: 5 (1)
  89. Transfer(2) A-B: 5 (1)
  90. Transfer(1) I-K: 3 (1)
  91. Transfer(1) I-K: 3 (1)
  92. Transfer(1) I-K: 3 (1)
  93. Transfer(1) J-K: 3 (1)
  94. Transfer(1) J-K: 3 (1)
  95. Transfer(1) J-K: 3 (1)
  96. Transfer(1) K-J: 3 (1)
  97. Transfer(1) L-A: 5 (1)
  98. Transfer(1) L-Z: 5 (1)
  99. Transfer(1) L-Y: 5 (1)
  100. Transfer(1) L-X: 5 (1)
  101. Transfer(1) M-A: 5 (1)
  102. Transfer(1) M-Z: 5 (1)
  103. Transfer(1) M-Y: 5 (1)
  104. Transfer(1) N-A: 5 (1)
  105. Transfer(1) N-Z: 5 (2)
  106. Transfer(1) N-Y: 5 (1)
  107. Transfer(1) O-T: 3 (1)
  108. Transfer(1) O-U: 3 (1)
  109. Transfer(1) O-V: 3 (1)
  110. Transfer(1) P-T: 3 (1)
  111. Transfer(1) P-U: 3 (1)
  112. Transfer(1) P-V: 3 (5)
  113. Transfer(1) Q-O: 3 (1)
  114. Transfer(1) Q-P: 3 (1)
  115. Transfer(1) R-O: 3 (1)
  116. Transfer(1) R-P: 3 (1)
  117. Transfer(1) R-Q: 3 (1)
  118. Transfer(1) S-O: 3 (1)
  119. Transfer(1) S-P: 3 (1)
  120. Transfer(1) S-Q: 3 (1)
  121. Transfer(1) T-O: 3 (1)
  122. Transfer(1) T-P: 3 (1)
  123. Transfer(1) T-Q: 3 (1)
  124. Transfer(1) U-Z: 5 (3)
  125. Transfer(1) U-Y: 5 (1)
  126. Transfer(1) U-T: 3 (1)
  127. Transfer(1) V-Z: 5 (0)
  128. Transfer(1) V-Y: 6 (1)
  129. Transfer(1) V-T: 3 (1)
  130. Transfer(1) W-K: 3 (1)
  131. Transfer(1) W-J: 3 (1)
  132. Transfer(1) W-A: 5 (1)
  133. Transfer(1) W-Z: 5 (1)
  134. Transfer(1) X-B: 5 (1)
  135. Transfer(1) X-C: 10 (126)
  136. Transfer(1) X-D: 5 (1)
  137. Transfer(1) X-E: 5 (1)
  138. Transfer(1) Y-B: 5 (1)
  139. Transfer(1) Y-C: 5 (1)
  140. Transfer(1) Y-D: 5 (1)
  141. Transfer(1) Y-E: 5 (1)
  142. Transfer(1) Z-A: 5 (1)
  143. // exits
  144. ForceExit(1) A: 5
  145. Exit(1) K: 5 (1)
  146. Exit(1) X: 5 (1)
  147. Exit(1) Y: 5 (1)
  148. Exit(1) Z: 5 (1)
  149. > batch
  150. // block:1 batch:2
  151. Deposit(1) A: 50
  152. Deposit(1) B: 5
  153. Deposit(1) C: 20
  154. Deposit(1) D: 25
  155. Deposit(1) E: 25
  156. Deposit(1) F: 25
  157. Deposit(1) G: 25
  158. Deposit(1) H: 25
  159. Deposit(1) I: 25
  160. Transfer(1) A-B: 5 (1)
  161. Transfer(1) A-L: 10 (1)
  162. Transfer(1) A-M: 5 (1)
  163. Transfer(1) B-N: 5 (1)
  164. Transfer(1) C-O: 5 (1)
  165. Transfer(1) H-O: 5 (1)
  166. Transfer(1) I-H: 5 (1)
  167. Exit(1) A: 5 (1)
  168. // create CoordinatorTx CreateAccount for D, TokenId 2, used at SetPool0 for
  169. // 'PoolTransfer(2) B-D: 3 (1)'
  170. CreateAccountCoordinator(2) D
  171. > batchL1
  172. > batchL1
  173. > block
  174. `
  175. // SetPool0 contains a set of transactions from the PoolL2
  176. var SetPool0 = `
  177. Type: PoolL2
  178. PoolTransfer(1) A-B: 6 (1)
  179. PoolTransfer(1) B-C: 3 (1)
  180. PoolTransfer(1) C-A: 3 (1)
  181. PoolTransfer(1) A-B: 1 (1)
  182. PoolTransfer(2) A-B: 15 (1)
  183. PoolTransfer(2) B-D: 3 (1)
  184. PoolExit(1) A: 3 (1)
  185. PoolTransfer(1) A-B: 6 (1)
  186. PoolTransfer(1) B-C: 3 (1)
  187. PoolTransfer(1) A-C: 3 (1)
  188. PoolTransferToEthAddr(1) A-C: 3 (1)
  189. PoolTransferToBJJ(1) A-C: 3 (1)
  190. `
  191. // Minimum flow
  192. // SetBlockchainMinimumFlow0 contains a set of transactions with a minimal flow
  193. var SetBlockchainMinimumFlow0 = `
  194. Type: Blockchain
  195. // Idxs:
  196. // 256: A(0)
  197. // 257: C(1)
  198. // 258: A(1)
  199. // 259: B(0)
  200. // 260: D(0)
  201. // 261: Coord(1)
  202. // 262: Coord(0)
  203. // 263: B(1)
  204. // 264: C(0)
  205. // 265: F(0)
  206. AddToken(1)
  207. // close Block:0, Batch:1
  208. > batch
  209. CreateAccountDeposit(0) A: 500
  210. CreateAccountDeposit(1) C: 0
  211. // close Block:0, Batch:2
  212. > batchL1 // freeze L1User{2}, forge L1Coord{0}
  213. // Expected balances:
  214. // C(0): 0
  215. CreateAccountDeposit(1) A: 500
  216. // close Block:0, Batch:3
  217. > batchL1 // freeze L1User{1}, forge L1User{2}
  218. // Expected balances:
  219. // A(0): 500
  220. // C(0): 0, C(1): 0
  221. // close Block:0, Batch:4
  222. > batchL1 // freeze L1User{nil}, forge L1User{1}
  223. // Expected balances:
  224. // A(0): 500, A(1): 500
  225. // C(0): 0
  226. CreateAccountDepositTransfer(0) B-A: 500, 100
  227. // close Block:0, Batch:5
  228. > batchL1 // freeze L1User{1}, forge L1User{nil}
  229. CreateAccountDeposit(0) D: 800
  230. // close Block:0, Batch:6
  231. > batchL1 // freeze L1User{1}, forge L1User{1}
  232. // Expected balances:
  233. // A(0): 600, A(1): 500
  234. // B(0): 400
  235. // C(0): 0
  236. // Coordinator creates needed accounts to receive Fees
  237. // Coordinator creates needed 'To' accounts for the L2Txs
  238. // sorted in the way that the TxSelector creates them
  239. CreateAccountCoordinator(1) Coord
  240. CreateAccountCoordinator(1) B
  241. CreateAccountCoordinator(0) Coord
  242. CreateAccountCoordinator(0) C
  243. Transfer(1) A-B: 200 (126)
  244. Transfer(0) B-C: 100 (126)
  245. // close Block:0, Batch:7
  246. > batchL1 // forge L1User{1}, forge L1Coord{4}, forge L2{2}
  247. // Expected balances:
  248. // Coord(0): 10, Coord(1): 20
  249. // A(0): 600, A(1): 280
  250. // B(0): 290, B(1): 200
  251. // C(0): 100, C(1): 0
  252. // D(0): 800
  253. Deposit(0) C: 500
  254. DepositTransfer(0) C-D: 400, 100
  255. Transfer(0) A-B: 100 (126)
  256. Transfer(0) C-A: 50 (126)
  257. Transfer(1) B-C: 100 (126)
  258. Exit(0) A: 100 (126)
  259. ForceTransfer(0) D-B: 200
  260. ForceExit(0) B: 100
  261. // close Block:0, Batch:8
  262. > batchL1 // freeze L1User{4}, forge L1User{nil}, forge L2{4}
  263. > block
  264. // Expected balances:
  265. // Coord(0): 35, Coord(1): 30
  266. // A(0): 430, A(1): 280
  267. // B(0): 390, B(1): 90
  268. // C(0): 45, C(1): 100
  269. // D(0): 800
  270. Transfer(0) D-A: 300 (126)
  271. Transfer(0) B-D: 100 (126)
  272. // close (batch9) Block:1, Batch:1
  273. > batchL1 // freeze L1User{nil}, forge L1User{4}, forge L2{2}
  274. // Expected balances:
  275. // Coord(0): 75, Coord(1): 30
  276. // A(0): 730, A(1): 280
  277. // B(0): 380, B(1): 90
  278. // C(0): 845, C(1): 100
  279. // D(0): 470
  280. CreateAccountCoordinator(0) F
  281. > batch // batch10: forge L1CoordinatorTx{1}
  282. > block
  283. `
  284. // SetPoolL2MinimumFlow0 contains a set of transactions with a minimal flow
  285. var SetPoolL2MinimumFlow0 = `
  286. Type: PoolL2
  287. PoolTransfer(0) A-B: 100 (126)
  288. PoolTransferToEthAddr(0) D-F: 100 (126)
  289. PoolExit(0) A: 100 (126)
  290. PoolTransferToEthAddr(1) A-B: 100 (126)
  291. // Expected balances:
  292. // Coord(0): 105, Coord(1): 40
  293. // A(0): 510, A(1): 170
  294. // B(0): 480, B(1): 190
  295. // C(0): 845, C(1): 100
  296. // D(0): 360
  297. // F(0): 100
  298. `
  299. // SetPoolL2MinimumFlow1 contains the same transactions than the
  300. // SetPoolL2MinimumFlow0, but simulating coming from the smart contract
  301. // (always with the parameter ToIdx filled)
  302. var SetPoolL2MinimumFlow1 = `
  303. Type: PoolL2
  304. PoolTransfer(0) A-B: 100 (126)
  305. PoolTransfer(0) D-F: 100 (126)
  306. PoolExit(0) A: 100 (126)
  307. PoolTransfer(1) A-B: 100 (126)
  308. // Expected balances:
  309. // Coord(0): 105, Coord(1): 40
  310. // A(0): 510, A(1): 170
  311. // B(0): 480, B(1): 190
  312. // C(0): 845, C(1): 100
  313. // D(0): 360
  314. // F(0): 100
  315. `