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.

798 lines
34 KiB

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