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.

795 lines
34 KiB

  1. package eth
  2. import (
  3. "crypto/ecdsa"
  4. "encoding/binary"
  5. "encoding/hex"
  6. "math/big"
  7. "testing"
  8. ethCommon "github.com/ethereum/go-ethereum/common"
  9. ethCrypto "github.com/ethereum/go-ethereum/crypto"
  10. "github.com/hermeznetwork/hermez-node/common"
  11. "github.com/iden3/go-iden3-crypto/babyjub"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/require"
  14. )
  15. var rollupClient *RollupClient
  16. var auctionClient *AuctionClient
  17. var ethHashForge ethCommon.Hash
  18. var argsForge *RollupForgeBatchArgs
  19. var absoluteMaxL1L2BatchTimeout = int64(240)
  20. var maxTx = int64(512)
  21. var nLevels = int64(32)
  22. var tokenIDERC777 uint32
  23. var tokenHEZID uint32
  24. type keys struct {
  25. BJJSecretKey *babyjub.PrivateKey
  26. BJJPublicKey *babyjub.PublicKey
  27. Addr ethCommon.Address
  28. }
  29. func genKeysBjj(i int64) *keys {
  30. i++ // i = 0 doesn't work for the ecdsa key generation
  31. var sk babyjub.PrivateKey
  32. binary.LittleEndian.PutUint64(sk[:], uint64(i))
  33. // eth address
  34. var key ecdsa.PrivateKey
  35. key.D = big.NewInt(i) // only for testing
  36. key.PublicKey.X, key.PublicKey.Y = ethCrypto.S256().ScalarBaseMult(key.D.Bytes())
  37. key.Curve = ethCrypto.S256()
  38. return &keys{
  39. BJJSecretKey: &sk,
  40. BJJPublicKey: sk.Public(),
  41. }
  42. }
  43. func TestRollupConstants(t *testing.T) {
  44. rollupConstants, err := rollupClient.RollupConstants()
  45. require.Nil(t, err)
  46. assert.Equal(t, absoluteMaxL1L2BatchTimeout, rollupConstants.AbsoluteMaxL1L2BatchTimeout)
  47. assert.Equal(t, auctionAddressConst, rollupConstants.HermezAuctionContract)
  48. assert.Equal(t, tokenHEZAddressConst, rollupConstants.TokenHEZ)
  49. assert.Equal(t, maxTx, rollupConstants.Verifiers[0].MaxTx)
  50. assert.Equal(t, nLevels, rollupConstants.Verifiers[0].NLevels)
  51. assert.Equal(t, governanceAddressConst, rollupConstants.HermezGovernanceDAOAddress)
  52. assert.Equal(t, safetyAddressConst, rollupConstants.SafetyAddress)
  53. assert.Equal(t, wdelayerAddressConst, rollupConstants.WithdrawDelayerContract)
  54. }
  55. func TestRollupRegisterTokensCount(t *testing.T) {
  56. registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
  57. require.Nil(t, err)
  58. assert.Equal(t, big.NewInt(1), registerTokensCount)
  59. }
  60. func TestAddToken(t *testing.T) {
  61. feeAddToken := big.NewInt(10)
  62. // Addtoken ERC20Permit
  63. registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
  64. require.Nil(t, err)
  65. _, err = rollupClient.RollupAddToken(tokenHEZAddressConst, feeAddToken, deadline)
  66. require.Nil(t, err)
  67. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  68. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  69. assert.Equal(t, tokenHEZAddressConst, rollupEvents.AddToken[0].TokenAddress)
  70. assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt())
  71. tokenHEZID = rollupEvents.AddToken[0].TokenID
  72. }
  73. func TestRollupForgeBatch(t *testing.T) {
  74. // Register Coordinator
  75. forgerAddress := governanceAddressConst
  76. _, err := auctionClient.AuctionSetCoordinator(forgerAddress, URL)
  77. require.Nil(t, err)
  78. // MultiBid
  79. currentSlot, err := auctionClient.AuctionGetCurrentSlotNumber()
  80. require.Nil(t, err)
  81. slotSet := [6]bool{true, false, true, false, true, false}
  82. maxBid := new(big.Int)
  83. maxBid.SetString("15000000000000000000", 10)
  84. minBid := new(big.Int)
  85. minBid.SetString("11000000000000000000", 10)
  86. budget := new(big.Int)
  87. budget.SetString("45200000000000000000", 10)
  88. _, err = auctionClient.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline)
  89. require.Nil(t, err)
  90. // Add Blocks
  91. blockNum := int64(int(BLOCKSPERSLOT)*int(currentSlot+4) + int(genesisBlock))
  92. currentBlockNum, _ := auctionClient.client.EthCurrentBlock()
  93. blocksToAdd := blockNum - currentBlockNum
  94. addBlocks(blocksToAdd, ethClientDialURL)
  95. // Forge
  96. args := new(RollupForgeBatchArgs)
  97. args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified.
  98. l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001")
  99. require.Nil(t, err)
  100. numTxsL1 := len(l1CoordinatorBytes) / common.L1CoordinatorTxBytesLen
  101. for i := 0; i < numTxsL1; i++ {
  102. bytesL1Coordinator := l1CoordinatorBytes[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
  103. var signature []byte
  104. v := bytesL1Coordinator[0]
  105. s := bytesL1Coordinator[1:33]
  106. r := bytesL1Coordinator[33:65]
  107. signature = append(signature, r[:]...)
  108. signature = append(signature, s[:]...)
  109. signature = append(signature, v)
  110. l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator)
  111. require.Nil(t, err)
  112. args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
  113. args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
  114. }
  115. args.L2TxsData = []common.L2Tx{}
  116. newStateRoot := new(big.Int)
  117. newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
  118. newExitRoot := new(big.Int)
  119. bytesNumExitRoot, err := hex.DecodeString("10a89d5fe8d488eda1ba371d633515739933c706c210c604f5bd209180daa43b")
  120. require.Nil(t, err)
  121. newExitRoot.SetBytes(bytesNumExitRoot)
  122. args.NewLastIdx = int64(256)
  123. args.NewStRoot = newStateRoot
  124. args.NewExitRoot = newExitRoot
  125. args.L1Batch = true
  126. args.VerifierIdx = 0
  127. args.ProofA[0] = big.NewInt(0)
  128. args.ProofA[1] = big.NewInt(0)
  129. args.ProofB[0][0] = big.NewInt(0)
  130. args.ProofB[0][1] = big.NewInt(0)
  131. args.ProofB[1][0] = big.NewInt(0)
  132. args.ProofB[1][1] = big.NewInt(0)
  133. args.ProofC[0] = big.NewInt(0)
  134. args.ProofC[1] = big.NewInt(0)
  135. argsForge = args
  136. _, err = rollupClient.RollupForgeBatch(argsForge)
  137. require.Nil(t, err)
  138. currentBlockNum, _ = rollupClient.client.EthCurrentBlock()
  139. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  140. assert.Equal(t, int64(1), rollupEvents.ForgeBatch[0].BatchNum)
  141. ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash
  142. }
  143. func TestRollupForgeBatchArgs(t *testing.T) {
  144. args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge)
  145. require.Nil(t, err)
  146. assert.Equal(t, *sender, rollupClient.client.account.Address)
  147. assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator)
  148. assert.Equal(t, argsForge.L1Batch, args.L1Batch)
  149. assert.Equal(t, argsForge.L1CoordinatorTxs, args.L1CoordinatorTxs)
  150. assert.Equal(t, argsForge.L1CoordinatorTxsAuths, args.L1CoordinatorTxsAuths)
  151. assert.Equal(t, argsForge.L2TxsData, args.L2TxsData)
  152. assert.Equal(t, argsForge.NewLastIdx, args.NewLastIdx)
  153. assert.Equal(t, argsForge.NewStRoot, args.NewStRoot)
  154. assert.Equal(t, argsForge.VerifierIdx, args.VerifierIdx)
  155. }
  156. func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
  157. newForgeL1L2BatchTimeout := int64(222)
  158. _, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout)
  159. require.Nil(t, err)
  160. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  161. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  162. assert.Equal(t, newForgeL1L2BatchTimeout, rollupEvents.UpdateForgeL1L2BatchTimeout[0].NewForgeL1L2BatchTimeout)
  163. }
  164. func TestRollupUpdateFeeAddToken(t *testing.T) {
  165. newFeeAddToken := big.NewInt(12)
  166. _, err := rollupClient.RollupUpdateFeeAddToken(newFeeAddToken)
  167. require.Nil(t, err)
  168. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  169. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  170. assert.Equal(t, newFeeAddToken, rollupEvents.UpdateFeeAddToken[0].NewFeeAddToken)
  171. }
  172. func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
  173. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  174. require.Nil(t, err)
  175. key := genKeysBjj(2)
  176. fromIdxInt64 := int64(0)
  177. toIdxInt64 := int64(0)
  178. tokenIDUint32 := uint32(0)
  179. l1Tx := common.L1Tx{
  180. FromBJJ: key.BJJPublicKey,
  181. FromIdx: common.Idx(fromIdxInt64),
  182. ToIdx: common.Idx(toIdxInt64),
  183. LoadAmount: big.NewInt(10),
  184. TokenID: common.TokenID(tokenIDUint32),
  185. Amount: big.NewInt(0),
  186. }
  187. _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
  188. require.Nil(t, err)
  189. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  190. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  191. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  192. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  193. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  194. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  195. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  196. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  197. }
  198. func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
  199. rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
  200. require.Nil(t, err)
  201. key := genKeysBjj(1)
  202. fromIdxInt64 := int64(0)
  203. toIdxInt64 := int64(0)
  204. l1Tx := common.L1Tx{
  205. FromBJJ: key.BJJPublicKey,
  206. FromIdx: common.Idx(fromIdxInt64),
  207. ToIdx: common.Idx(toIdxInt64),
  208. LoadAmount: big.NewInt(10),
  209. TokenID: common.TokenID(tokenHEZID),
  210. Amount: big.NewInt(0),
  211. }
  212. _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
  213. require.Nil(t, err)
  214. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  215. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  216. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  217. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  218. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  219. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  220. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  221. assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  222. }
  223. func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
  224. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  225. require.Nil(t, err)
  226. key := genKeysBjj(3)
  227. fromIdxInt64 := int64(0)
  228. toIdxInt64 := int64(0)
  229. l1Tx := common.L1Tx{
  230. FromBJJ: key.BJJPublicKey,
  231. FromIdx: common.Idx(fromIdxInt64),
  232. ToIdx: common.Idx(toIdxInt64),
  233. LoadAmount: big.NewInt(10),
  234. TokenID: common.TokenID(tokenIDERC777),
  235. Amount: big.NewInt(0),
  236. }
  237. _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
  238. require.Nil(t, err)
  239. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  240. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  241. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  242. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  243. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  244. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  245. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  246. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  247. }
  248. func TestRollupL1UserTxETHDeposit(t *testing.T) {
  249. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  250. require.Nil(t, err)
  251. key := genKeysBjj(2)
  252. fromIdxInt64 := int64(0)
  253. toIdxInt64 := int64(0)
  254. tokenIDUint32 := uint32(0)
  255. l1Tx := common.L1Tx{
  256. FromBJJ: key.BJJPublicKey,
  257. FromIdx: common.Idx(fromIdxInt64),
  258. ToIdx: common.Idx(toIdxInt64),
  259. LoadAmount: big.NewInt(10),
  260. TokenID: common.TokenID(tokenIDUint32),
  261. Amount: big.NewInt(0),
  262. }
  263. _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
  264. require.Nil(t, err)
  265. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  266. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  267. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  268. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  269. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  270. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  271. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  272. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  273. }
  274. func TestRollupL1UserTxERC20Deposit(t *testing.T) {
  275. rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
  276. require.Nil(t, err)
  277. key := genKeysBjj(1)
  278. fromIdxInt64 := int64(0)
  279. toIdxInt64 := int64(0)
  280. l1Tx := common.L1Tx{
  281. FromBJJ: key.BJJPublicKey,
  282. FromIdx: common.Idx(fromIdxInt64),
  283. ToIdx: common.Idx(toIdxInt64),
  284. LoadAmount: big.NewInt(10),
  285. TokenID: common.TokenID(tokenHEZID),
  286. Amount: big.NewInt(0),
  287. }
  288. _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
  289. require.Nil(t, err)
  290. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  291. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  292. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  293. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  294. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  295. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  296. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  297. assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  298. }
  299. func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
  300. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  301. require.Nil(t, err)
  302. key := genKeysBjj(3)
  303. fromIdxInt64 := int64(0)
  304. toIdxInt64 := int64(0)
  305. l1Tx := common.L1Tx{
  306. FromBJJ: key.BJJPublicKey,
  307. FromIdx: common.Idx(fromIdxInt64),
  308. ToIdx: common.Idx(toIdxInt64),
  309. LoadAmount: big.NewInt(10),
  310. TokenID: common.TokenID(tokenIDERC777),
  311. Amount: big.NewInt(0),
  312. }
  313. _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
  314. require.Nil(t, err)
  315. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  316. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  317. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  318. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  319. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  320. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  321. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  322. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  323. }
  324. func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
  325. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  326. require.Nil(t, err)
  327. key := genKeysBjj(2)
  328. fromIdxInt64 := int64(0)
  329. toIdxInt64 := int64(0)
  330. tokenIDUint32 := uint32(0)
  331. l1Tx := common.L1Tx{
  332. FromBJJ: key.BJJPublicKey,
  333. FromIdx: common.Idx(fromIdxInt64),
  334. ToIdx: common.Idx(toIdxInt64),
  335. LoadAmount: big.NewInt(10),
  336. TokenID: common.TokenID(tokenIDUint32),
  337. Amount: big.NewInt(0),
  338. }
  339. _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
  340. require.Nil(t, err)
  341. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  342. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  343. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  344. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  345. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  346. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  347. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  348. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  349. }
  350. func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
  351. rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
  352. require.Nil(t, err)
  353. key := genKeysBjj(1)
  354. fromIdxInt64 := int64(0)
  355. toIdxInt64 := int64(0)
  356. l1Tx := common.L1Tx{
  357. FromBJJ: key.BJJPublicKey,
  358. FromIdx: common.Idx(fromIdxInt64),
  359. ToIdx: common.Idx(toIdxInt64),
  360. LoadAmount: big.NewInt(10),
  361. TokenID: common.TokenID(tokenHEZID),
  362. Amount: big.NewInt(0),
  363. }
  364. _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
  365. require.Nil(t, err)
  366. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  367. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  368. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  369. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  370. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  371. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  372. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  373. assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  374. }
  375. func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
  376. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  377. require.Nil(t, err)
  378. key := genKeysBjj(3)
  379. fromIdxInt64 := int64(0)
  380. toIdxInt64 := int64(0)
  381. l1Tx := common.L1Tx{
  382. FromBJJ: key.BJJPublicKey,
  383. FromIdx: common.Idx(fromIdxInt64),
  384. ToIdx: common.Idx(toIdxInt64),
  385. LoadAmount: big.NewInt(10),
  386. TokenID: common.TokenID(tokenIDERC777),
  387. Amount: big.NewInt(0),
  388. }
  389. _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
  390. require.Nil(t, err)
  391. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  392. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  393. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  394. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  395. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  396. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  397. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  398. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  399. }
  400. func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
  401. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  402. require.Nil(t, err)
  403. key := genKeysBjj(2)
  404. fromIdxInt64 := int64(0)
  405. toIdxInt64 := int64(0)
  406. tokenIDUint32 := uint32(0)
  407. l1Tx := common.L1Tx{
  408. FromBJJ: key.BJJPublicKey,
  409. FromIdx: common.Idx(fromIdxInt64),
  410. ToIdx: common.Idx(toIdxInt64),
  411. LoadAmount: big.NewInt(10),
  412. TokenID: common.TokenID(tokenIDUint32),
  413. Amount: big.NewInt(0),
  414. }
  415. _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
  416. require.Nil(t, err)
  417. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  418. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  419. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  420. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  421. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  422. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  423. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  424. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  425. }
  426. func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
  427. rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
  428. require.Nil(t, err)
  429. key := genKeysBjj(1)
  430. fromIdxInt64 := int64(0)
  431. toIdxInt64 := int64(0)
  432. l1Tx := common.L1Tx{
  433. FromBJJ: key.BJJPublicKey,
  434. FromIdx: common.Idx(fromIdxInt64),
  435. ToIdx: common.Idx(toIdxInt64),
  436. LoadAmount: big.NewInt(10),
  437. TokenID: common.TokenID(tokenHEZID),
  438. Amount: big.NewInt(0),
  439. }
  440. _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
  441. require.Nil(t, err)
  442. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  443. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  444. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  445. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  446. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  447. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  448. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  449. assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  450. }
  451. func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
  452. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  453. require.Nil(t, err)
  454. key := genKeysBjj(3)
  455. fromIdxInt64 := int64(0)
  456. toIdxInt64 := int64(0)
  457. l1Tx := common.L1Tx{
  458. FromBJJ: key.BJJPublicKey,
  459. FromIdx: common.Idx(fromIdxInt64),
  460. ToIdx: common.Idx(toIdxInt64),
  461. LoadAmount: big.NewInt(10),
  462. TokenID: common.TokenID(tokenIDERC777),
  463. Amount: big.NewInt(0),
  464. }
  465. _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
  466. require.Nil(t, err)
  467. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  468. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  469. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  470. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  471. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  472. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  473. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  474. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  475. }
  476. func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
  477. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  478. require.Nil(t, err)
  479. key := genKeysBjj(2)
  480. fromIdxInt64 := int64(0)
  481. toIdxInt64 := int64(0)
  482. tokenIDUint32 := uint32(0)
  483. l1Tx := common.L1Tx{
  484. FromBJJ: key.BJJPublicKey,
  485. FromIdx: common.Idx(fromIdxInt64),
  486. ToIdx: common.Idx(toIdxInt64),
  487. LoadAmount: big.NewInt(10),
  488. TokenID: common.TokenID(tokenIDUint32),
  489. Amount: big.NewInt(0),
  490. }
  491. _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
  492. require.Nil(t, err)
  493. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  494. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  495. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  496. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  497. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  498. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  499. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  500. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  501. }
  502. func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
  503. rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
  504. require.Nil(t, err)
  505. key := genKeysBjj(1)
  506. fromIdxInt64 := int64(0)
  507. toIdxInt64 := int64(0)
  508. l1Tx := common.L1Tx{
  509. FromBJJ: key.BJJPublicKey,
  510. FromIdx: common.Idx(fromIdxInt64),
  511. ToIdx: common.Idx(toIdxInt64),
  512. LoadAmount: big.NewInt(10),
  513. TokenID: common.TokenID(tokenHEZID),
  514. Amount: big.NewInt(0),
  515. }
  516. _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
  517. require.Nil(t, err)
  518. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  519. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  520. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  521. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  522. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  523. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  524. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  525. assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  526. }
  527. func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
  528. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  529. require.Nil(t, err)
  530. key := genKeysBjj(3)
  531. fromIdxInt64 := int64(0)
  532. toIdxInt64 := int64(0)
  533. l1Tx := common.L1Tx{
  534. FromBJJ: key.BJJPublicKey,
  535. FromIdx: common.Idx(fromIdxInt64),
  536. ToIdx: common.Idx(toIdxInt64),
  537. LoadAmount: big.NewInt(10),
  538. TokenID: common.TokenID(tokenIDERC777),
  539. Amount: big.NewInt(0),
  540. }
  541. _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
  542. require.Nil(t, err)
  543. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  544. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  545. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  546. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  547. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  548. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  549. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  550. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  551. }
  552. func TestRollupL1UserTxETHForceExit(t *testing.T) {
  553. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  554. require.Nil(t, err)
  555. key := genKeysBjj(2)
  556. fromIdxInt64 := int64(0)
  557. toIdxInt64 := int64(0)
  558. tokenIDUint32 := uint32(0)
  559. l1Tx := common.L1Tx{
  560. FromBJJ: key.BJJPublicKey,
  561. FromIdx: common.Idx(fromIdxInt64),
  562. ToIdx: common.Idx(toIdxInt64),
  563. LoadAmount: big.NewInt(10),
  564. TokenID: common.TokenID(tokenIDUint32),
  565. Amount: big.NewInt(0),
  566. }
  567. _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
  568. require.Nil(t, err)
  569. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  570. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  571. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  572. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  573. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  574. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  575. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  576. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  577. }
  578. func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
  579. rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
  580. require.Nil(t, err)
  581. key := genKeysBjj(1)
  582. fromIdxInt64 := int64(0)
  583. toIdxInt64 := int64(0)
  584. l1Tx := common.L1Tx{
  585. FromBJJ: key.BJJPublicKey,
  586. FromIdx: common.Idx(fromIdxInt64),
  587. ToIdx: common.Idx(toIdxInt64),
  588. LoadAmount: big.NewInt(10),
  589. TokenID: common.TokenID(tokenHEZID),
  590. Amount: big.NewInt(0),
  591. }
  592. _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
  593. require.Nil(t, err)
  594. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  595. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  596. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  597. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  598. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  599. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  600. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  601. assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  602. }
  603. func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
  604. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  605. require.Nil(t, err)
  606. key := genKeysBjj(3)
  607. fromIdxInt64 := int64(0)
  608. toIdxInt64 := int64(0)
  609. fromIdx := new(common.Idx)
  610. *fromIdx = 0
  611. l1Tx := common.L1Tx{
  612. FromBJJ: key.BJJPublicKey,
  613. FromIdx: common.Idx(fromIdxInt64),
  614. ToIdx: common.Idx(toIdxInt64),
  615. LoadAmount: big.NewInt(10),
  616. TokenID: common.TokenID(tokenIDERC777),
  617. Amount: big.NewInt(0),
  618. }
  619. _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
  620. require.Nil(t, err)
  621. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  622. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  623. assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
  624. assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
  625. assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
  626. assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
  627. assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
  628. assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
  629. }
  630. func TestRollupForgeBatch2(t *testing.T) {
  631. // Forge
  632. args := new(RollupForgeBatchArgs)
  633. feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
  634. require.Nil(t, err)
  635. lenFeeIdxCoordinatorBytes := int(4)
  636. numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
  637. for i := 0; i < numFeeIdxCoordinator; i++ {
  638. var paddedFeeIdx [6]byte
  639. if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
  640. copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
  641. } else {
  642. copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
  643. }
  644. FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
  645. require.Nil(t, err)
  646. args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
  647. }
  648. newStateRoot := new(big.Int)
  649. newStateRoot.SetString("0", 10)
  650. newExitRoot := new(big.Int)
  651. newExitRoot.SetString("6442511778188868333499919207091562876207840300369859025739972956758642594045", 10)
  652. args.NewLastIdx = int64(1000)
  653. args.NewStRoot = newStateRoot
  654. args.NewExitRoot = newExitRoot
  655. args.L1Batch = true
  656. args.VerifierIdx = 0
  657. args.ProofA[0] = big.NewInt(0)
  658. args.ProofA[1] = big.NewInt(0)
  659. args.ProofB[0] = [2]*big.Int{big.NewInt(0), big.NewInt(0)}
  660. args.ProofB[1] = [2]*big.Int{big.NewInt(0), big.NewInt(0)}
  661. args.ProofC[0] = big.NewInt(0)
  662. args.ProofC[1] = big.NewInt(0)
  663. argsForge = args
  664. _, err = rollupClient.RollupForgeBatch(argsForge)
  665. require.Nil(t, err)
  666. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  667. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  668. assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum)
  669. ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash
  670. }
  671. func TestRollupWithdrawMerkleProof(t *testing.T) {
  672. rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
  673. require.Nil(t, err)
  674. var pkComp babyjub.PublicKeyComp
  675. pkCompB, err := hex.DecodeString("9a0c13552c3a0b7b2b63ec4ab8a906b4af471ef3aa4463491ff08a0b489ac50f")
  676. require.Nil(t, err)
  677. pkCompL := common.SwapEndianness(pkCompB)
  678. err = pkComp.UnmarshalText([]byte(hex.EncodeToString(pkCompL)))
  679. require.Nil(t, err)
  680. pk, err := pkComp.Decompress()
  681. require.Nil(t, err)
  682. require.Nil(t, err)
  683. tokenID := uint32(1)
  684. numExitRoot := int64(2)
  685. fromIdx := int64(256)
  686. amount := big.NewInt(10)
  687. siblingBytes0, _ := new(big.Int).SetString("19508838618377323910556678335932426220272947530531646682154552299216398748115", 10)
  688. require.Nil(t, err)
  689. siblingBytes1, _ := new(big.Int).SetString("15198806719713909654457742294233381653226080862567104272457668857208564789571", 10)
  690. require.Nil(t, err)
  691. var siblings []*big.Int
  692. siblings = append(siblings, siblingBytes0)
  693. siblings = append(siblings, siblingBytes1)
  694. instantWithdraw := true
  695. _, err = rollupClientAux.RollupWithdrawMerkleProof(pk, tokenID, numExitRoot, fromIdx, amount, siblings, instantWithdraw)
  696. require.Nil(t, err)
  697. currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
  698. rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
  699. assert.Equal(t, uint64(fromIdx), rollupEvents.WithdrawEvent[0].Idx)
  700. assert.Equal(t, instantWithdraw, rollupEvents.WithdrawEvent[0].InstantWithdraw)
  701. assert.Equal(t, uint64(numExitRoot), rollupEvents.WithdrawEvent[0].NumExitRoot)
  702. }