mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #195 from hermeznetwork/feature/ethclient16-sc
Update ethclient rollup iteration 3
This commit is contained in:
373
eth/rollup.go
373
eth/rollup.go
@@ -22,11 +22,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// RollupConstFeeIdxCoordinatorLen is the number of tokens the coordinator can use
|
||||
// to collect fees (determines the number of tokens that the
|
||||
// coordinator can collect fees from). This value is determined by the
|
||||
// circuit.
|
||||
RollupConstFeeIdxCoordinatorLen = 64
|
||||
// RollupConstMaxFeeIdxCoordinator is the maximum number of tokens the
|
||||
// coordinator can use to collect fees (determines the number of tokens
|
||||
// that the coordinator can collect fees from). This value is
|
||||
// determined by the circuit.
|
||||
RollupConstMaxFeeIdxCoordinator = 64
|
||||
// RollupConstReservedIDx First 256 indexes reserved, first user index will be the 256
|
||||
RollupConstReservedIDx = 255
|
||||
// RollupConstExitIDx IDX 1 is reserved for exits
|
||||
@@ -99,38 +99,6 @@ var (
|
||||
RollupConstERC20Signature = crypto.Keccak256([]byte("decimals()"))
|
||||
)
|
||||
|
||||
// RollupConstants are the constants of the Rollup Smart Contract
|
||||
/* type RollupConstants struct {
|
||||
// Maxim Deposit allowed
|
||||
MaxAmountDeposit *big.Int
|
||||
MaxAmountL2 *big.Int
|
||||
MaxTokens int64
|
||||
// maximum L1 transactions allowed to be queued for a batch
|
||||
MaxL1Tx int
|
||||
// maximum L1 user transactions allowed to be queued for a batch
|
||||
MaxL1UserTx int
|
||||
Rfield *big.Int
|
||||
L1CoordinatorBytes int
|
||||
L1UserBytes int
|
||||
L2Bytes int
|
||||
MaxTxVerifiers []int
|
||||
TokenHEZ ethCommon.Address
|
||||
// Only test
|
||||
GovernanceAddress ethCommon.Address
|
||||
// Only test
|
||||
SafetyBot ethCommon.Address
|
||||
// Only test
|
||||
ConsensusContract ethCommon.Address
|
||||
// Only test
|
||||
WithdrawalContract ethCommon.Address
|
||||
ReservedIDx uint32
|
||||
LastIDx uint32
|
||||
ExitIDx uint32
|
||||
NoLimitToken int
|
||||
NumBuckets int
|
||||
MaxWDelay int64
|
||||
}*/
|
||||
|
||||
// RollupPublicConstants are the constants of the Rollup Smart Contract
|
||||
type RollupPublicConstants struct {
|
||||
AbsoluteMaxL1L2BatchTimeout int64
|
||||
@@ -187,20 +155,20 @@ type RollupState struct {
|
||||
type RollupEventL1UserTx struct {
|
||||
ToForgeL1TxsNum int64 // QueueIndex *big.Int
|
||||
Position int // TransactionIndex *big.Int
|
||||
L1Tx common.L1Tx
|
||||
L1UserTx common.L1Tx
|
||||
}
|
||||
|
||||
// RollupEventL1UserTxAux is an event of the Rollup Smart Contract
|
||||
type RollupEventL1UserTxAux struct {
|
||||
ToForgeL1TxsNum uint64 // QueueIndex *big.Int
|
||||
Position uint8 // TransactionIndex *big.Int
|
||||
L1Tx []byte
|
||||
L1UserTx []byte
|
||||
}
|
||||
|
||||
// RollupEventAddToken is an event of the Rollup Smart Contract
|
||||
type RollupEventAddToken struct {
|
||||
Address ethCommon.Address
|
||||
TokenID uint32
|
||||
TokenAddress ethCommon.Address
|
||||
TokenID uint32
|
||||
}
|
||||
|
||||
// RollupEventForgeBatch is an event of the Rollup Smart Contract
|
||||
@@ -211,12 +179,12 @@ type RollupEventForgeBatch struct {
|
||||
|
||||
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
|
||||
type RollupEventUpdateForgeL1L2BatchTimeout struct {
|
||||
ForgeL1L2BatchTimeout uint8
|
||||
NewForgeL1L2BatchTimeout int64
|
||||
}
|
||||
|
||||
// RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract
|
||||
type RollupEventUpdateFeeAddToken struct {
|
||||
FeeAddToken *big.Int
|
||||
NewFeeAddToken *big.Int
|
||||
}
|
||||
|
||||
// RollupEventWithdrawEvent is an event of the Rollup Smart Contract
|
||||
@@ -291,29 +259,20 @@ type RollupInterface interface {
|
||||
|
||||
RollupForgeBatch(*RollupForgeBatchArgs) (*types.Transaction, error)
|
||||
RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error)
|
||||
RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey,
|
||||
numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error)
|
||||
RollupForceExit(fromIdx int64, amountF common.Float16, tokenID int64) (*types.Transaction, error)
|
||||
RollupForceTransfer(fromIdx int64, amountF common.Float16, tokenID, toIdx int64) (*types.Transaction, error)
|
||||
RollupCreateAccountDepositTransfer(babyPubKey babyjub.PublicKey,
|
||||
loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (*types.Transaction, error)
|
||||
RollupDepositTransfer(fromIdx int64, loadAmountF, amountF common.Float16,
|
||||
tokenID int64, toIdx int64) (*types.Transaction, error)
|
||||
RollupDeposit(fromIdx int64, loadAmountF common.Float16, tokenID int64) (*types.Transaction, error)
|
||||
RollupCreateAccountDepositFromRelayer(accountCreationAuthSig []byte,
|
||||
babyPubKey babyjub.PublicKey, loadAmountF common.Float16) (*types.Transaction, error)
|
||||
RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAmountF common.Float16,
|
||||
tokenID int64) (*types.Transaction, error)
|
||||
|
||||
RollupGetCurrentTokens() (*big.Int, error)
|
||||
// RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error)
|
||||
// RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error)
|
||||
// RollupGetQueue(queue int64) ([]byte, error)
|
||||
RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error)
|
||||
RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error)
|
||||
|
||||
RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
|
||||
RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
|
||||
|
||||
// Governance Public Functions
|
||||
RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (*types.Transaction, error)
|
||||
RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error)
|
||||
RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.Transaction, error)
|
||||
|
||||
// Viewers
|
||||
RollupRegisterTokensCount() (*big.Int, error)
|
||||
|
||||
//
|
||||
// Smart Contract Status
|
||||
//
|
||||
@@ -388,8 +347,15 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
||||
l2DataBytes = append(l2DataBytes, bytesl2[:]...)
|
||||
}
|
||||
var feeIdxCoordinator []byte
|
||||
for i := 0; i < len(args.FeeIdxCoordinator); i++ {
|
||||
feeIdx := args.FeeIdxCoordinator[i]
|
||||
if len(args.FeeIdxCoordinator) > RollupConstMaxFeeIdxCoordinator {
|
||||
return nil, fmt.Errorf("len(args.FeeIdxCoordinator) > %v",
|
||||
RollupConstMaxFeeIdxCoordinator)
|
||||
}
|
||||
for i := 0; i < RollupConstMaxFeeIdxCoordinator; i++ {
|
||||
feeIdx := common.Idx(0)
|
||||
if i < len(args.FeeIdxCoordinator) {
|
||||
feeIdx = args.FeeIdxCoordinator[i]
|
||||
}
|
||||
bytesFeeIdx, err := feeIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -436,90 +402,183 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToke
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// RollupWithdrawSNARK is the interface to call the smart contract function
|
||||
// func (c *RollupClient) RollupWithdrawSNARK() (*types.Transaction, error) { // TODO (Not defined in Hermez.sol)
|
||||
// return nil, errTODO
|
||||
// }
|
||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkCompL := fromBJJ.Compress()
|
||||
pkCompB := common.SwapEndianness(pkCompL[:])
|
||||
babyPubKey := new(big.Int).SetBytes(pkCompB)
|
||||
numExitRootB := big.NewInt(numExitRoot)
|
||||
idxBig := big.NewInt(idx)
|
||||
return hermez.WithdrawMerkleProof(auth, tokenID, amount, babyPubKey, numExitRootB, siblings, idxBig, instantWithdraw)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed update WithdrawMerkleProof: %w", err)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// RollupWithdraw is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error) {
|
||||
// RollupWithdrawCircuit is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupForceExit is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupForceExit(fromIdx int64, amountF common.Float16, tokenID int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
// RollupL1UserTxERC20ETH is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkCompL := fromBJJ.Compress()
|
||||
pkCompB := common.SwapEndianness(pkCompL[:])
|
||||
babyPubKey := new(big.Int).SetBytes(pkCompB)
|
||||
fromIdxBig := big.NewInt(fromIdx)
|
||||
toIdxBig := big.NewInt(toIdx)
|
||||
tokenIDBig := uint32(tokenID)
|
||||
loadAmountF, err := common.NewFloat16(loadAmount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
amountF, err := common.NewFloat16(amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tokenID == 0 {
|
||||
auth.Value = loadAmount
|
||||
}
|
||||
return hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF), uint16(amountF), tokenIDBig, toIdxBig)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// RollupForceTransfer is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupForceTransfer(fromIdx int64, amountF common.Float16, tokenID, toIdx int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addL1TxFnSignature := []byte("addL1Transaction(uint256,uint48,uint16,uint16,uint32,uint48)")
|
||||
hash := sha3.NewLegacyKeccak256()
|
||||
_, err = hash.Write(addL1TxFnSignature)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
methodID := hash.Sum(nil)[:4]
|
||||
pkCompL := fromBJJ.Compress()
|
||||
pkCompB := common.SwapEndianness(pkCompL[:])
|
||||
paddedAddress := ethCommon.LeftPadBytes(pkCompB, 32)
|
||||
fromIdxB, err := common.Idx(fromIdx).Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paddedFromIdx := ethCommon.LeftPadBytes(fromIdxB[:], 32)
|
||||
loadAmountF, err := common.NewFloat16(loadAmount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paddedLoadAmount := ethCommon.LeftPadBytes(loadAmountF.Bytes(), 32)
|
||||
amountF, err := common.NewFloat16(amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paddedAmount := ethCommon.LeftPadBytes(amountF.Bytes(), 32)
|
||||
tokenIDB := common.TokenID(tokenID).Bytes()
|
||||
paddedTokenID := ethCommon.LeftPadBytes(tokenIDB, 32)
|
||||
toIdxB, err := common.Idx(toIdx).Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paddedToIdx := ethCommon.LeftPadBytes(toIdxB[:], 32)
|
||||
var data []byte
|
||||
data = append(data, methodID...)
|
||||
data = append(data, paddedAddress[:]...)
|
||||
data = append(data, paddedFromIdx[:]...)
|
||||
data = append(data, paddedLoadAmount[:]...)
|
||||
data = append(data, paddedAmount[:]...)
|
||||
data = append(data, paddedTokenID[:]...)
|
||||
data = append(data, paddedToIdx[:]...)
|
||||
return tokens.Send(auth, c.address, loadAmount, data)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed add L1 Tx ERC777: %w", err)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// RollupCreateAccountDepositTransfer is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupCreateAccountDepositTransfer(babyPubKey babyjub.PublicKey, loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
// RollupRegisterTokensCount is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupRegisterTokensCount() (*big.Int, error) {
|
||||
var registerTokensCount *big.Int
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
registerTokensCount, err = hermez.RegisterTokensCount(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return registerTokensCount, nil
|
||||
}
|
||||
|
||||
// RollupDepositTransfer is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupDepositTransfer(fromIdx int64, loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupDeposit is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupDeposit(fromIdx int64, loadAmountF common.Float16, tokenID int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupCreateAccountDepositFromRelayer is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupCreateAccountDepositFromRelayer(accountCreationAuthSig []byte, babyPubKey babyjub.PublicKey, loadAmountF common.Float16) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupCreateAccountDeposit is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAmountF common.Float16, tokenID int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupGetTokenAddress is the interface to call the smart contract function
|
||||
/* func (c *RollupClient) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
||||
return nil, errTODO
|
||||
} */
|
||||
|
||||
// RollupGetCurrentTokens is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupGetCurrentTokens() (*big.Int, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
||||
/* func (c *RollupClient) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||
return nil, errTODO
|
||||
} */
|
||||
|
||||
// RollupGetQueue is the interface to call the smart contract function
|
||||
/* func (c *RollupClient) RollupGetQueue(queue int64) ([]byte, error) {
|
||||
return nil, errTODO
|
||||
}*/
|
||||
|
||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return hermez.UpdateForgeL1L2BatchTimeout(auth, uint8(newForgeL1L2BatchTimeout))
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed update ForgeL1L2BatchTimeout: %w", err)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// RollupUpdateFeeAddToken is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return hermez.UpdateFeeAddToken(auth, newFeeAddToken)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed update FeeAddToken: %w", err)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// RollupConstants returns the Constants of the Rollup Smart Contract
|
||||
@@ -611,13 +670,13 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
L1Tx, err := common.L1TxFromBytes(L1UserTxAux.L1Tx)
|
||||
L1Tx, err := common.L1TxFromBytes(L1UserTxAux.L1UserTx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
L1UserTx.ToForgeL1TxsNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
|
||||
L1UserTx.Position = int(new(big.Int).SetBytes(vLog.Topics[2][:]).Int64())
|
||||
L1UserTx.L1Tx = *L1Tx
|
||||
L1UserTx.L1UserTx = *L1Tx
|
||||
rollupEvents.L1UserTx = append(rollupEvents.L1UserTx, L1UserTx)
|
||||
case logHermezAddToken:
|
||||
var addToken RollupEventAddToken
|
||||
@@ -625,7 +684,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addToken.Address = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
|
||||
addToken.TokenAddress = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
|
||||
rollupEvents.AddToken = append(rollupEvents.AddToken, addToken)
|
||||
case logHermezForgeBatch:
|
||||
var forgeBatch RollupEventForgeBatch
|
||||
@@ -633,12 +692,17 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
forgeBatch.EthTxHash = vLog.TxHash
|
||||
rollupEvents.ForgeBatch = append(rollupEvents.ForgeBatch, forgeBatch)
|
||||
case logHermezUpdateForgeL1L2BatchTimeout:
|
||||
var updateForgeL1L2BatchTimeout RollupEventUpdateForgeL1L2BatchTimeout
|
||||
var updateForgeL1L2BatchTimeout struct {
|
||||
NewForgeL1L2BatchTimeout uint8
|
||||
}
|
||||
err := c.contractAbi.Unpack(&updateForgeL1L2BatchTimeout, "UpdateForgeL1L2BatchTimeout", vLog.Data)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
rollupEvents.UpdateForgeL1L2BatchTimeout = append(rollupEvents.UpdateForgeL1L2BatchTimeout, updateForgeL1L2BatchTimeout)
|
||||
rollupEvents.UpdateForgeL1L2BatchTimeout = append(rollupEvents.UpdateForgeL1L2BatchTimeout,
|
||||
RollupEventUpdateForgeL1L2BatchTimeout{
|
||||
NewForgeL1L2BatchTimeout: int64(updateForgeL1L2BatchTimeout.NewForgeL1L2BatchTimeout),
|
||||
})
|
||||
case logHermezUpdateFeeAddToken:
|
||||
var updateFeeAddToken RollupEventUpdateFeeAddToken
|
||||
err := c.contractAbi.Unpack(&updateFeeAddToken, "UpdateFeeAddToken", vLog.Data)
|
||||
@@ -648,12 +712,12 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
rollupEvents.UpdateFeeAddToken = append(rollupEvents.UpdateFeeAddToken, updateFeeAddToken)
|
||||
case logHermezWithdrawEvent:
|
||||
var withdraw RollupEventWithdrawEvent
|
||||
err := c.contractAbi.Unpack(&withdraw, "WithdrawEvent", vLog.Data)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
withdraw.Idx = new(big.Int).SetBytes(vLog.Topics[1][:]).Uint64()
|
||||
withdraw.NumExitRoot = new(big.Int).SetBytes(vLog.Topics[2][:]).Uint64()
|
||||
instantWithdraw := new(big.Int).SetBytes(vLog.Topics[3][:]).Uint64()
|
||||
if instantWithdraw == 1 {
|
||||
withdraw.InstantWithdraw = true
|
||||
}
|
||||
rollupEvents.WithdrawEvent = append(rollupEvents.WithdrawEvent, withdraw)
|
||||
}
|
||||
}
|
||||
@@ -675,15 +739,20 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
||||
if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var rollupForgeBatchArgs RollupForgeBatchArgs
|
||||
rollupForgeBatchArgs.L1Batch = aux.L1Batch
|
||||
rollupForgeBatchArgs.NewExitRoot = aux.NewExitRoot
|
||||
rollupForgeBatchArgs.NewLastIdx = aux.NewLastIdx.Int64()
|
||||
rollupForgeBatchArgs.NewStRoot = aux.NewStRoot
|
||||
rollupForgeBatchArgs.ProofA = aux.ProofA
|
||||
rollupForgeBatchArgs.ProofB = aux.ProofB
|
||||
rollupForgeBatchArgs.ProofC = aux.ProofC
|
||||
rollupForgeBatchArgs.VerifierIdx = aux.VerifierIdx
|
||||
rollupForgeBatchArgs := RollupForgeBatchArgs{
|
||||
L1Batch: aux.L1Batch,
|
||||
NewExitRoot: aux.NewExitRoot,
|
||||
NewLastIdx: aux.NewLastIdx.Int64(),
|
||||
NewStRoot: aux.NewStRoot,
|
||||
ProofA: aux.ProofA,
|
||||
ProofB: aux.ProofB,
|
||||
ProofC: aux.ProofC,
|
||||
VerifierIdx: aux.VerifierIdx,
|
||||
L1CoordinatorTxs: []common.L1Tx{},
|
||||
L1CoordinatorTxsAuths: [][]byte{},
|
||||
L2TxsData: []common.L2Tx{},
|
||||
FeeIdxCoordinator: []common.Idx{},
|
||||
}
|
||||
numTxsL1 := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
|
||||
for i := 0; i < numTxsL1; i++ {
|
||||
bytesL1Coordinator := aux.EncodedL1CoordinatorTx[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
|
||||
@@ -725,11 +794,13 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
||||
} else {
|
||||
copy(paddedFeeIdx[:], aux.FeeIdxCoordinator[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
}
|
||||
FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||
feeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rollupForgeBatchArgs.FeeIdxCoordinator = append(rollupForgeBatchArgs.FeeIdxCoordinator, FeeIdxCoordinator)
|
||||
if feeIdxCoordinator != common.Idx(0) {
|
||||
rollupForgeBatchArgs.FeeIdxCoordinator = append(rollupForgeBatchArgs.FeeIdxCoordinator, feeIdxCoordinator)
|
||||
}
|
||||
}
|
||||
return &rollupForgeBatchArgs, nil
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
ethCrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -21,6 +25,32 @@ var absoluteMaxL1L2BatchTimeout = int64(240)
|
||||
var maxTx = int64(512)
|
||||
var nLevels = int64(32)
|
||||
|
||||
var tokenIDERC777 uint32
|
||||
var tokenIDERC20 uint32
|
||||
|
||||
type keys struct {
|
||||
BJJSecretKey *babyjub.PrivateKey
|
||||
BJJPublicKey *babyjub.PublicKey
|
||||
Addr ethCommon.Address
|
||||
}
|
||||
|
||||
func genKeysBjj(i int64) *keys {
|
||||
i++ // i = 0 doesn't work for the ecdsa key generation
|
||||
var sk babyjub.PrivateKey
|
||||
binary.LittleEndian.PutUint64(sk[:], uint64(i))
|
||||
|
||||
// eth address
|
||||
var key ecdsa.PrivateKey
|
||||
key.D = big.NewInt(i) // only for testing
|
||||
key.PublicKey.X, key.PublicKey.Y = ethCrypto.S256().ScalarBaseMult(key.D.Bytes())
|
||||
key.Curve = ethCrypto.S256()
|
||||
|
||||
return &keys{
|
||||
BJJSecretKey: &sk,
|
||||
BJJPublicKey: sk.Public(),
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollupConstants(t *testing.T) {
|
||||
rollupConstants, err := rollupClient.RollupConstants()
|
||||
require.Nil(t, err)
|
||||
@@ -34,11 +64,37 @@ func TestRollupConstants(t *testing.T) {
|
||||
assert.Equal(t, wdelayerAddressConst, rollupConstants.WithdrawDelayerContract)
|
||||
}
|
||||
|
||||
func TestRollupRegisterTokensCount(t *testing.T) {
|
||||
registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, big.NewInt(1), registerTokensCount)
|
||||
}
|
||||
|
||||
func TestAddToken(t *testing.T) {
|
||||
feeAddToken := big.NewInt(10)
|
||||
// Addtoken
|
||||
_, err := rollupClient.RollupAddToken(tokenERC777AddressConst, feeAddToken)
|
||||
// Addtoken ERC20
|
||||
registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
|
||||
require.Nil(t, err)
|
||||
_, err = rollupClient.RollupAddToken(tokenERC20AddressConst, feeAddToken)
|
||||
require.Nil(t, err)
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
|
||||
assert.Equal(t, tokenERC20AddressConst, rollupEvents.AddToken[0].TokenAddress)
|
||||
assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt())
|
||||
tokenIDERC20 = rollupEvents.AddToken[0].TokenID
|
||||
|
||||
// Addtoken ERC777
|
||||
registerTokensCount, err = rollupClient.RollupRegisterTokensCount()
|
||||
require.Nil(t, err)
|
||||
_, err = rollupClient.RollupAddToken(tokenERC777AddressConst, feeAddToken)
|
||||
require.Nil(t, err)
|
||||
currentBlockNum, _ = rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ = rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
|
||||
assert.Equal(t, tokenERC777AddressConst, rollupEvents.AddToken[0].TokenAddress)
|
||||
assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt())
|
||||
tokenIDERC777 = rollupEvents.AddToken[0].TokenID
|
||||
}
|
||||
|
||||
func TestRollupForgeBatch(t *testing.T) {
|
||||
@@ -68,21 +124,22 @@ func TestRollupForgeBatch(t *testing.T) {
|
||||
|
||||
// Forge
|
||||
args := new(RollupForgeBatchArgs)
|
||||
feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||
require.Nil(t, err)
|
||||
lenFeeIdxCoordinatorBytes := int(4)
|
||||
numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
|
||||
for i := 0; i < numFeeIdxCoordinator; i++ {
|
||||
var paddedFeeIdx [6]byte
|
||||
if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
|
||||
copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
} else {
|
||||
copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
}
|
||||
FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||
require.Nil(t, err)
|
||||
args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
|
||||
}
|
||||
// feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||
// require.Nil(t, err)
|
||||
// lenFeeIdxCoordinatorBytes := int(4)
|
||||
// numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
|
||||
// for i := 0; i < numFeeIdxCoordinator; i++ {
|
||||
// var paddedFeeIdx [6]byte
|
||||
// if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
|
||||
// copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
// } else {
|
||||
// copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
// }
|
||||
// FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||
// require.Nil(t, err)
|
||||
// args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
|
||||
// }
|
||||
args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified.
|
||||
l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001")
|
||||
require.Nil(t, err)
|
||||
numTxsL1 := len(l1CoordinatorBytes) / common.L1CoordinatorTxBytesLen
|
||||
@@ -95,14 +152,18 @@ func TestRollupForgeBatch(t *testing.T) {
|
||||
signature = append(signature, r[:]...)
|
||||
signature = append(signature, s[:]...)
|
||||
signature = append(signature, v)
|
||||
L1Tx, err := common.L1TxFromCoordinatorBytes(bytesL1Coordinator)
|
||||
l1Tx, err := common.L1TxFromCoordinatorBytes(bytesL1Coordinator)
|
||||
require.Nil(t, err)
|
||||
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *L1Tx)
|
||||
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
|
||||
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
|
||||
}
|
||||
args.L2TxsData = []common.L2Tx{}
|
||||
newStateRoot := new(big.Int)
|
||||
newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
|
||||
newExitRoot := big.NewInt(0)
|
||||
newExitRoot := new(big.Int)
|
||||
bytesNumExitRoot, err := hex.DecodeString("10a89d5fe8d488eda1ba371d633515739933c706c210c604f5bd209180daa43b")
|
||||
require.Nil(t, err)
|
||||
newExitRoot.SetBytes(bytesNumExitRoot)
|
||||
args.NewLastIdx = int64(256)
|
||||
args.NewStRoot = newStateRoot
|
||||
args.NewExitRoot = newExitRoot
|
||||
@@ -140,3 +201,621 @@ func TestRollupForgeBatchArgs(t *testing.T) {
|
||||
assert.Equal(t, argsForge.NewStRoot, args.NewStRoot)
|
||||
assert.Equal(t, argsForge.VerifierIdx, args.VerifierIdx)
|
||||
}
|
||||
|
||||
func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
|
||||
newForgeL1L2BatchTimeout := int64(222)
|
||||
_, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
|
||||
assert.Equal(t, newForgeL1L2BatchTimeout, rollupEvents.UpdateForgeL1L2BatchTimeout[0].NewForgeL1L2BatchTimeout)
|
||||
}
|
||||
|
||||
func TestRollupUpdateFeeAddToken(t *testing.T) {
|
||||
newFeeAddToken := big.NewInt(12)
|
||||
_, err := rollupClient.RollupUpdateFeeAddToken(newFeeAddToken)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
|
||||
assert.Equal(t, newFeeAddToken, rollupEvents.UpdateFeeAddToken[0].NewFeeAddToken)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(2)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC20),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC777CreateAccountDeposit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxETHDeposit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(2)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC20Deposit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC20),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC777Deposit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(2)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC20),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC777DepositTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(2)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC20),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC777CreateAccountDepositTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(2)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC20),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC777ForceTransfer(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxETHForceExit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(2)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC20),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupL1UserTxERC777ForceExit(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
fromIdx := new(common.Idx)
|
||||
*fromIdx = 0
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(10),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
}
|
||||
|
||||
func TestRollupForgeBatch2(t *testing.T) {
|
||||
// Forge
|
||||
args := new(RollupForgeBatchArgs)
|
||||
feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||
require.Nil(t, err)
|
||||
lenFeeIdxCoordinatorBytes := int(4)
|
||||
numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
|
||||
for i := 0; i < numFeeIdxCoordinator; i++ {
|
||||
var paddedFeeIdx [6]byte
|
||||
if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
|
||||
copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
} else {
|
||||
copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
|
||||
}
|
||||
FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||
require.Nil(t, err)
|
||||
args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
|
||||
}
|
||||
newStateRoot := new(big.Int)
|
||||
newStateRoot.SetString("0", 10)
|
||||
newExitRoot := new(big.Int)
|
||||
newExitRoot.SetString("6442511778188868333499919207091562876207840300369859025739972956758642594045", 10)
|
||||
args.NewLastIdx = int64(1000)
|
||||
args.NewStRoot = newStateRoot
|
||||
args.NewExitRoot = newExitRoot
|
||||
args.L1Batch = true
|
||||
args.VerifierIdx = 0
|
||||
args.ProofA[0] = big.NewInt(0)
|
||||
args.ProofA[1] = big.NewInt(0)
|
||||
args.ProofB[0] = [2]*big.Int{big.NewInt(0), big.NewInt(0)}
|
||||
args.ProofB[1] = [2]*big.Int{big.NewInt(0), big.NewInt(0)}
|
||||
args.ProofC[0] = big.NewInt(0)
|
||||
args.ProofC[1] = big.NewInt(0)
|
||||
|
||||
argsForge = args
|
||||
_, err = rollupClient.RollupForgeBatch(argsForge)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
|
||||
assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum)
|
||||
ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash
|
||||
}
|
||||
|
||||
func TestRollupWithdrawMerkleProof(t *testing.T) {
|
||||
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
|
||||
require.Nil(t, err)
|
||||
|
||||
var pkComp babyjub.PublicKeyComp
|
||||
pkCompB, err := hex.DecodeString("9a0c13552c3a0b7b2b63ec4ab8a906b4af471ef3aa4463491ff08a0b489ac50f")
|
||||
require.Nil(t, err)
|
||||
pkCompL := common.SwapEndianness(pkCompB)
|
||||
err = pkComp.UnmarshalText([]byte(hex.EncodeToString(pkCompL)))
|
||||
require.Nil(t, err)
|
||||
|
||||
pk, err := pkComp.Decompress()
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Nil(t, err)
|
||||
tokenID := uint32(1)
|
||||
numExitRoot := int64(2)
|
||||
fromIdx := int64(256)
|
||||
amount := big.NewInt(10)
|
||||
siblingBytes0, _ := new(big.Int).SetString("19508838618377323910556678335932426220272947530531646682154552299216398748115", 10)
|
||||
require.Nil(t, err)
|
||||
siblingBytes1, _ := new(big.Int).SetString("15198806719713909654457742294233381653226080862567104272457668857208564789571", 10)
|
||||
require.Nil(t, err)
|
||||
var siblings []*big.Int
|
||||
siblings = append(siblings, siblingBytes0)
|
||||
siblings = append(siblings, siblingBytes1)
|
||||
instantWithdraw := true
|
||||
|
||||
_, err = rollupClientAux.RollupWithdrawMerkleProof(pk, tokenID, numExitRoot, fromIdx, amount, siblings, instantWithdraw)
|
||||
require.Nil(t, err)
|
||||
|
||||
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
|
||||
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
|
||||
assert.Equal(t, uint64(fromIdx), rollupEvents.WithdrawEvent[0].Idx)
|
||||
assert.Equal(t, instantWithdraw, rollupEvents.WithdrawEvent[0].InstantWithdraw)
|
||||
assert.Equal(t, uint64(numExitRoot), rollupEvents.WithdrawEvent[0].NumExitRoot)
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ func (s *Synchronizer) rollupSync(blockNum int64) (*rollupData, error) {
|
||||
var token common.Token
|
||||
|
||||
token.TokenID = common.TokenID(evtAddToken.TokenID)
|
||||
token.EthAddr = evtAddToken.Address
|
||||
token.EthAddr = evtAddToken.TokenAddress
|
||||
token.EthBlockNum = blockNum
|
||||
|
||||
// TODO: Add external information consulting SC about it using Address
|
||||
@@ -584,17 +584,17 @@ func getL1UserTx(eventsL1UserTx []eth.RollupEventL1UserTx, blockNum int64) ([]co
|
||||
for _, evtL1UserTx := range eventsL1UserTx {
|
||||
// Fill aditional Tx fields
|
||||
toForge := evtL1UserTx.ToForgeL1TxsNum
|
||||
evtL1UserTx.L1Tx.ToForgeL1TxsNum = &toForge
|
||||
evtL1UserTx.L1Tx.Position = evtL1UserTx.Position
|
||||
evtL1UserTx.L1Tx.UserOrigin = true
|
||||
evtL1UserTx.L1Tx.EthBlockNum = blockNum
|
||||
nL1Tx, err := common.NewL1Tx(&evtL1UserTx.L1Tx)
|
||||
evtL1UserTx.L1UserTx.ToForgeL1TxsNum = &toForge
|
||||
evtL1UserTx.L1UserTx.Position = evtL1UserTx.Position
|
||||
evtL1UserTx.L1UserTx.UserOrigin = true
|
||||
evtL1UserTx.L1UserTx.EthBlockNum = blockNum
|
||||
nL1Tx, err := common.NewL1Tx(&evtL1UserTx.L1UserTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
evtL1UserTx.L1Tx = *nL1Tx
|
||||
evtL1UserTx.L1UserTx = *nL1Tx
|
||||
|
||||
l1Txs = append(l1Txs, evtL1UserTx.L1Tx)
|
||||
l1Txs = append(l1Txs, evtL1UserTx.L1UserTx)
|
||||
}
|
||||
return l1Txs, nil
|
||||
}
|
||||
|
||||
@@ -599,12 +599,42 @@ func (c *Client) CtlAddL1TxUser(l1Tx *common.L1Tx) {
|
||||
}
|
||||
queue.L1TxQueue = append(queue.L1TxQueue, *l1Tx)
|
||||
r.Events.L1UserTx = append(r.Events.L1UserTx, eth.RollupEventL1UserTx{
|
||||
L1Tx: *l1Tx,
|
||||
L1UserTx: *l1Tx,
|
||||
ToForgeL1TxsNum: r.State.LastToForgeL1TxsNum,
|
||||
Position: len(queue.L1TxQueue) - 1,
|
||||
})
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC20ETH is the interface to call the smart contract function
|
||||
func (c *Client) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||
func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupRegisterTokensCount is the interface to call the smart contract function
|
||||
func (c *Client) RollupRegisterTokensCount() (*big.Int, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupWithdrawCircuit is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
type transactionData struct {
|
||||
Name string
|
||||
Value interface{}
|
||||
@@ -710,72 +740,11 @@ func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big
|
||||
|
||||
r.State.TokenMap[tokenAddress] = true
|
||||
r.State.TokenList = append(r.State.TokenList, tokenAddress)
|
||||
r.Events.AddToken = append(r.Events.AddToken, eth.RollupEventAddToken{Address: tokenAddress,
|
||||
r.Events.AddToken = append(r.Events.AddToken, eth.RollupEventAddToken{TokenAddress: tokenAddress,
|
||||
TokenID: uint32(len(r.State.TokenList) - 1)})
|
||||
return r.addTransaction(newTransaction("addtoken", tokenAddress)), nil
|
||||
}
|
||||
|
||||
// RollupWithdrawSNARK is the interface to call the smart contract function
|
||||
// func (c *Client) RollupWithdrawSNARK() (*types.Transaction, error) { // TODO (Not defined in Hermez.sol)
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupWithdraw is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupForceExit is the interface to call the smart contract function
|
||||
func (c *Client) RollupForceExit(fromIdx int64, amountF common.Float16, tokenID int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupForceTransfer is the interface to call the smart contract function
|
||||
func (c *Client) RollupForceTransfer(fromIdx int64, amountF common.Float16, tokenID, toIdx int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupCreateAccountDepositTransfer is the interface to call the smart contract function
|
||||
func (c *Client) RollupCreateAccountDepositTransfer(babyPubKey babyjub.PublicKey, loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupGetCurrentTokens is the interface to call the smart contract function
|
||||
func (c *Client) RollupGetCurrentTokens() (*big.Int, error) {
|
||||
c.rw.RLock()
|
||||
@@ -785,89 +754,6 @@ func (c *Client) RollupGetCurrentTokens() (*big.Int, error) {
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupDepositTransfer is the interface to call the smart contract function
|
||||
func (c *Client) RollupDepositTransfer(fromIdx int64, loadAmountF, amountF common.Float16, tokenID int64, toIdx int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupDeposit is the interface to call the smart contract function
|
||||
func (c *Client) RollupDeposit(fromIdx int64, loadAmountF common.Float16, tokenID int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupCreateAccountDepositFromRelayer is the interface to call the smart contract function
|
||||
func (c *Client) RollupCreateAccountDepositFromRelayer(accountCreationAuthSig []byte, babyPubKey babyjub.PublicKey, loadAmountF common.Float16) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupCreateAccountDeposit is the interface to call the smart contract function
|
||||
func (c *Client) RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAmountF common.Float16, tokenID int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
if c.addr == nil {
|
||||
return nil, eth.ErrAccountNil
|
||||
}
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupGetTokenAddress is the interface to call the smart contract function
|
||||
// func (c *Client) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
||||
// c.rw.RLock()
|
||||
// defer c.rw.RUnlock()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
||||
// func (c *Client) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||
// c.rw.RLock()
|
||||
// defer c.rw.RUnlock()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupGetQueue is the interface to call the smart contract function
|
||||
// func (c *Client) RollupGetQueue(queue int64) ([]byte, error) {
|
||||
// c.rw.RLock()
|
||||
// defer c.rw.RUnlock()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||
func (c *Client) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
|
||||
@@ -180,7 +180,7 @@ func TestClientRollup(t *testing.T) {
|
||||
NewExitRoot: big.NewInt(100),
|
||||
L1CoordinatorTxs: []common.L1Tx{},
|
||||
L2TxsData: []common.L2Tx{},
|
||||
FeeIdxCoordinator: make([]common.Idx, eth.RollupConstFeeIdxCoordinatorLen),
|
||||
FeeIdxCoordinator: []common.Idx{},
|
||||
VerifierIdx: 0,
|
||||
L1Batch: true,
|
||||
})
|
||||
@@ -217,7 +217,7 @@ func TestClientRollup(t *testing.T) {
|
||||
NewExitRoot: big.NewInt(100),
|
||||
L1CoordinatorTxs: []common.L1Tx{},
|
||||
L2TxsData: []common.L2Tx{},
|
||||
FeeIdxCoordinator: make([]common.Idx, eth.RollupConstFeeIdxCoordinatorLen),
|
||||
FeeIdxCoordinator: []common.Idx{},
|
||||
VerifierIdx: 0,
|
||||
L1Batch: true,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user