Browse Source

Update ethclient

feature/sql-semaphore1
laisolizq 3 years ago
parent
commit
18031343ec
21 changed files with 1494 additions and 1235 deletions
  1. +1
    -2
      api/config_test.go
  2. +3
    -4
      common/ethrollup.go
  3. +5
    -6
      common/ethwdelayer.go
  4. +23
    -0
      common/l1tx.go
  5. +25
    -0
      common/l1tx_test.go
  6. +2
    -2
      common/l2tx.go
  7. +1
    -1
      common/l2tx_test.go
  8. +10
    -10
      eth/README.md
  9. +18
    -9
      eth/auction.go
  10. +6
    -2
      eth/auction_test.go
  11. +1
    -1
      eth/contracts/README.md
  12. +238
    -161
      eth/contracts/auction/HermezAuctionProtocol.go
  13. +237
    -263
      eth/contracts/hermez/Hermez.go
  14. +41
    -42
      eth/contracts/tokenHEZ/HEZ.go
  15. +284
    -371
      eth/contracts/withdrawdelayer/WithdrawalDelayer.go
  16. +14
    -30
      eth/main_test.go
  17. +222
    -38
      eth/rollup.go
  18. +243
    -131
      eth/rollup_test.go
  19. +76
    -91
      eth/wdelayer.go
  20. +29
    -54
      eth/wdelayer_test.go
  21. +15
    -17
      test/ethclient.go

+ 1
- 2
api/config_test.go

@ -15,8 +15,7 @@ func getConfigTest() Config {
var rollupPublicConstants common.RollupConstants
rollupPublicConstants.AbsoluteMaxL1L2BatchTimeout = 240
rollupPublicConstants.HermezAuctionContract = ethCommon.HexToAddress("0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e")
rollupPublicConstants.HermezGovernanceDAOAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4")
rollupPublicConstants.SafetyAddress = ethCommon.HexToAddress("0xE5904695748fe4A84b40b3fc79De2277660BD1D3")
rollupPublicConstants.HermezGovernanceAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4")
rollupPublicConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB")
rollupPublicConstants.WithdrawDelayerContract = ethCommon.HexToAddress("0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe")
var verifier common.RollupVerifierStruct

+ 3
- 4
common/ethrollup.go

@ -34,8 +34,8 @@ import (
// WithdrawDelayerVars contains the Withdrawal Delayer smart contract variables
// type WithdrawDelayerVars struct {
// HermezRollupAddress eth.Address
// HermezGovernanceDAOAddress eth.Address
// WhiteHackGroupAddress eth.Address
// HermezGovernanceAddress eth.Address
// EmergencyCouncilAddress eth.Address
// WithdrawalDelay uint
// EmergencyModeStartingTime time.Time
// EmergencyModeEnabled bool
@ -142,8 +142,7 @@ type RollupConstants struct {
TokenHEZ ethCommon.Address `json:"tokenHEZ"`
Verifiers []RollupVerifierStruct `json:"verifiers"`
HermezAuctionContract ethCommon.Address `json:"hermezAuctionContract"`
HermezGovernanceDAOAddress ethCommon.Address `json:"hermezGovernanceDAOAddress"`
SafetyAddress ethCommon.Address `json:"safetyAddress"`
HermezGovernanceAddress ethCommon.Address `json:"hermezGovernanceAddress"`
WithdrawDelayerContract ethCommon.Address `json:"withdrawDelayerContract"`
}

+ 5
- 6
common/ethwdelayer.go

@ -16,12 +16,11 @@ type WDelayerConstants struct {
type WDelayerVariables struct {
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
// HermezRollupAddress ethCommon.Address `json:"hermezRollupAddress" meddler:"rollup_address"`
HermezGovernanceDAOAddress ethCommon.Address `json:"hermezGovernanceDAOAddress" meddler:"govdao_address" validate:"required"`
WhiteHackGroupAddress ethCommon.Address `json:"whiteHackGroupAddress" meddler:"whg_address" validate:"required"`
HermezKeeperAddress ethCommon.Address `json:"hermezKeeperAddress" meddler:"keeper_address" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
EmergencyModeStartingTime uint64 `json:"emergencyModeStartingTime" meddler:"emergency_start_time"`
EmergencyMode bool `json:"emergencyMode" meddler:"emergency_mode"`
HermezGovernanceAddress ethCommon.Address `json:"hermezGovernanceAddress" meddler:"govdao_address" validate:"required"`
EmergencyCouncilAddress ethCommon.Address `json:"whiteHackGroupAddress" meddler:"whg_address" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
EmergencyModeStartingTime uint64 `json:"emergencyModeStartingTime" meddler:"emergency_start_time"`
EmergencyMode bool `json:"emergencyMode" meddler:"emergency_mode"`
}
// Copy returns a deep copy of the Variables

+ 23
- 0
common/l1tx.go

@ -217,6 +217,29 @@ func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
return b[:], nil
}
// L1TxFromDataAvailability decodes a L1Tx from []byte (Data Availability)
func L1TxFromDataAvailability(b []byte, nLevels uint32) (*L1Tx, error) {
idxLen := nLevels / 8 //nolint:gomnd
fromIdxBytes := b[0:idxLen]
toIdxBytes := b[idxLen : idxLen*2]
amountBytes := b[idxLen*2 : idxLen*2+2]
l1tx := L1Tx{}
fromIdx, err := IdxFromBytes(ethCommon.LeftPadBytes(fromIdxBytes, 6))
if err != nil {
return nil, err
}
l1tx.FromIdx = fromIdx
toIdx, err := IdxFromBytes(ethCommon.LeftPadBytes(toIdxBytes, 6))
if err != nil {
return nil, err
}
l1tx.ToIdx = toIdx
l1tx.EffectiveAmount = Float16FromBytes(amountBytes).BigInt()
return &l1tx, nil
}
// BytesGeneric returns the generic representation of a L1Tx. This method is
// used to compute the []byte representation of a L1UserTx, and also to compute
// the L1TxData for the ZKInputs (at the HashGlobalInputs), using this method

+ 25
- 0
common/l1tx_test.go

@ -87,6 +87,31 @@ func TestBytesDataAvailability(t *testing.T) {
assert.Equal(t, "0000000200000003000400", hex.EncodeToString(txCompressedData))
}
func TestL1TxFromDataAvailability(t *testing.T) {
tx := L1Tx{
FromIdx: 2,
ToIdx: 3,
Amount: big.NewInt(4),
}
txCompressedData, err := tx.BytesDataAvailability(32)
assert.Nil(t, err)
l1tx, err := L1TxFromDataAvailability(txCompressedData, 32)
assert.Equal(t, tx.FromIdx, l1tx.FromIdx)
assert.Equal(t, tx.ToIdx, l1tx.ToIdx)
tx = L1Tx{
FromIdx: 2,
ToIdx: 3,
EffectiveAmount: big.NewInt(4),
}
txCompressedData, err = tx.BytesDataAvailability(32)
assert.Nil(t, err)
l1tx, err = L1TxFromDataAvailability(txCompressedData, 32)
assert.Equal(t, tx.FromIdx, l1tx.FromIdx)
assert.Equal(t, tx.ToIdx, l1tx.ToIdx)
assert.Equal(t, tx.EffectiveAmount, l1tx.EffectiveAmount)
}
func TestL1userTxByteParsers(t *testing.T) {
var pkComp babyjub.PublicKeyComp
pkCompL := []byte("0x56ca90f80d7c374ae7485e9bcc47d4ac399460948da6aeeb899311097925a72c")

+ 2
- 2
common/l2tx.go

@ -134,8 +134,8 @@ func (tx L2Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
return b[:], nil
}
// L2TxFromBytes decodes a L1Tx from []byte
func L2TxFromBytes(b []byte, nLevels int) (*L2Tx, error) {
// L2TxFromBytesDataAvailability decodes a L2Tx from []byte (Data Availability)
func L2TxFromBytesDataAvailability(b []byte, nLevels int) (*L2Tx, error) {
idxLen := nLevels / 8 //nolint:gomnd
tx := &L2Tx{}
var err error

+ 1
- 1
common/l2tx_test.go

@ -36,7 +36,7 @@ func TestL2TxByteParsers(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, expected, hex.EncodeToString(encodedData))
decodedData, err := L2TxFromBytes(encodedData, 32)
decodedData, err := L2TxFromBytesDataAvailability(encodedData, 32)
require.Nil(t, err)
assert.Equal(t, l2Tx, decodedData)
}

+ 10
- 10
eth/README.md

@ -8,7 +8,7 @@ The first step is to clone the github repository where the contracts are located
While the prepared deployment is not found to master, branch in repository must be changed:
`git checkout feature/newDeploymentScript-ethclient` (tested with commit `af4c93916d6cd93d866c121cc63b6a6794f649b2`)
`git checkout feature/newDeploymentScript-eth` (tested with commit `f3b627d2145a029fd967f05c1fd32f23d614ec8e`)
Now, install the dependencies:
@ -27,7 +27,7 @@ Now, in a terminal start a local blockchain with ganache:
```
Once ganache is ready, in another terminal run the deployment in the local ganache network:
```
npx buidler run --network ganache test-deployment.js
npx buidler run --network localhostMnemonic test-deployment.js
```
An output file necessary for the next step is obtained: `deploy-output`.
@ -42,13 +42,13 @@ They must be taken from the output file of the previous step.
They can be provided by file called `.env`:
```
GENESIS_BLOCK=97
AUCTION="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F"
AUCTION_TEST="0x56D4563E85477AC8Aa6a3b980b831DDb18a826ec"
TOKENHEZ="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3"
HERMEZ="0x6F4e99522F4eB37e0B73D0C0373147893EF12fD5"
WDELAYER="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77"
WDELAYER_TEST="0xdc05EFc3029024068FCc86f05323411f14D69280"
GENESIS_BLOCK=98
AUCTION="0x317113D2593e3efF1FfAE0ba2fF7A61861Df7ae5"
AUCTION_TEST="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3"
TOKENHEZ="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77"
HERMEZ="0x8EEaea23686c319133a7cC110b840d1591d9AeE0"
WDELAYER="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F"
WDELAYER_TEST="0xc8F466fFeF9E9788fb363c2F4fBDdF2cAe477805"
```
> An example is found in `hermez-node/eth/.env.example`
@ -59,4 +59,4 @@ And then run test from `hermez-node/eth/`:
Or they can be provided as a parameter in the command that runs the test:
`INTEGRATION=1 GENESIS_BLOCK=97 AUCTION="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F" AUCTION_TEST="0x56D4563E85477AC8Aa6a3b980b831DDb18a826ec" TOKENHEZ="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3" HERMEZ="0x6F4e99522F4eB37e0B73D0C0373147893EF12fD5" WDELAYER="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77" WDELAYER_TEST="0xdc05EFc3029024068FCc86f05323411f14D69280" go test`
`INTEGRATION=1 GENESIS_BLOCK=98 AUCTION="0x317113D2593e3efF1FfAE0ba2fF7A61861Df7ae5" AUCTION_TEST="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3" TOKENHEZ="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77" HERMEZ="0x8EEaea23686c319133a7cC110b840d1591d9AeE0" WDELAYER="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F" WDELAYER_TEST="0xc8F466fFeF9E9788fb363c2F4fBDdF2cAe477805" go test`

+ 18
- 9
eth/auction.go

@ -32,10 +32,11 @@ type SlotState struct {
// NewSlotState returns an empty SlotState
func NewSlotState() *SlotState {
return &SlotState{
Bidder: ethCommon.Address{},
Fulfilled: false,
BidAmount: big.NewInt(0),
ClosedMinBid: big.NewInt(0),
Bidder: ethCommon.Address{},
Fulfilled: false,
ForgerCommitment: false,
BidAmount: big.NewInt(0),
ClosedMinBid: big.NewInt(0),
}
}
@ -84,7 +85,8 @@ type AuctionEventNewDonationAddress struct {
// AuctionEventNewBootCoordinator is an event of the Auction Smart Contract
type AuctionEventNewBootCoordinator struct {
NewBootCoordinator ethCommon.Address
NewBootCoordinator ethCommon.Address
NewBootCoordinatorURL string
}
// AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract
@ -187,7 +189,7 @@ type AuctionInterface interface {
AuctionGetAllocationRatio() ([3]uint16, error)
AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
AuctionGetDonationAddress() (*ethCommon.Address, error)
AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error)
AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address, newBootCoordinatorURL string) (*types.Transaction, error)
AuctionGetBootCoordinator() (*ethCommon.Address, error)
AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error)
@ -408,11 +410,11 @@ func (c *AuctionClient) AuctionGetDonationAddress() (donationAddress *ethCommon.
}
// AuctionSetBootCoordinator is the interface to call the smart contract function
func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (tx *types.Transaction, err error) {
func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address, newBootCoordinatorURL string) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.auction.SetBootCoordinator(auth, newBootCoordinator)
return c.auction.SetBootCoordinator(auth, newBootCoordinator, newBootCoordinatorURL)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting bootCoordinator: %w", err))
@ -642,6 +644,10 @@ func (c *AuctionClient) AuctionConstants() (auctionConstants *common.AuctionCons
if err != nil {
return tracerr.Wrap(err)
}
auctionConstants.GovernanceAddress, err = c.auction.GovernanceAddress(nil)
if err != nil {
return tracerr.Wrap(err)
}
auctionConstants.TokenHEZ, err = c.auction.TokenHEZ(nil)
return tracerr.Wrap(err)
}); err != nil {
@ -703,7 +709,7 @@ var (
logAuctionNewClosedAuctionSlots = crypto.Keccak256Hash([]byte("NewClosedAuctionSlots(uint16)"))
logAuctionNewOutbidding = crypto.Keccak256Hash([]byte("NewOutbidding(uint16)"))
logAuctionNewDonationAddress = crypto.Keccak256Hash([]byte("NewDonationAddress(address)"))
logAuctionNewBootCoordinator = crypto.Keccak256Hash([]byte("NewBootCoordinator(address)"))
logAuctionNewBootCoordinator = crypto.Keccak256Hash([]byte("NewBootCoordinator(address,string)"))
logAuctionNewOpenAuctionSlots = crypto.Keccak256Hash([]byte("NewOpenAuctionSlots(uint16)"))
logAuctionNewAllocationRatio = crypto.Keccak256Hash([]byte("NewAllocationRatio(uint16[3])"))
logAuctionSetCoordinator = crypto.Keccak256Hash([]byte("SetCoordinator(address,address,string)"))
@ -780,6 +786,9 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e
auctionEvents.NewDonationAddress = append(auctionEvents.NewDonationAddress, newDonationAddress)
case logAuctionNewBootCoordinator:
var newBootCoordinator AuctionEventNewBootCoordinator
if err := c.contractAbi.Unpack(&newBootCoordinator, "NewBootCoordinator", vLog.Data); err != nil {
return nil, nil, tracerr.Wrap(err)
}
newBootCoordinator.NewBootCoordinator = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
auctionEvents.NewBootCoordinator = append(auctionEvents.NewBootCoordinator, newBootCoordinator)
case logAuctionNewOpenAuctionSlots:

+ 6
- 2
eth/auction_test.go

@ -38,6 +38,7 @@ func TestAuctionConstants(t *testing.T) {
assert.Equal(t, auctionConstants.HermezRollup, hermezRollupTestAddressConst)
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
assert.Equal(t, auctionConstants.TokenHEZ, tokenHEZAddressConst)
assert.Equal(t, auctionConstants.GovernanceAddress, governanceAddressConst)
}
func TestAuctionVariables(t *testing.T) {
@ -199,8 +200,10 @@ func TestAuctionSetDonationAddress(t *testing.T) {
func TestAuctionSetBootCoordinator(t *testing.T) {
newBootCoordinator := governanceAddressConst
bootCoordinatorURL := "https://boot.coordinator2.io"
newBootCoordinatorURL := "https://boot.coordinator2.io"
_, err := auctionClientTest.AuctionSetBootCoordinator(newBootCoordinator)
_, err := auctionClientTest.AuctionSetBootCoordinator(newBootCoordinator, newBootCoordinatorURL)
require.Nil(t, err)
bootCoordinator, err := auctionClientTest.AuctionGetBootCoordinator()
require.Nil(t, err)
@ -210,7 +213,8 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
auctionEvents, _, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, newBootCoordinator, auctionEvents.NewBootCoordinator[0].NewBootCoordinator)
_, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst)
assert.Equal(t, newBootCoordinatorURL, auctionEvents.NewBootCoordinator[0].NewBootCoordinatorURL)
_, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst, bootCoordinatorURL)
require.Nil(t, err)
}

+ 1
- 1
eth/contracts/README.md

@ -11,7 +11,7 @@ abigen --abi=HEZ.abi --bin=HEZ.bin --pkg=HEZ --out=HEZ.go
You must compile the contracts to get the `.bin` and `.abi` files. The contracts used are in the repo: https://github.com/hermeznetwork/contracts
Branch: `feature/newDeploymentScript`
Specifically they have been processed in the commit with hash: `4489f8e7fe4dd17cf22f1e96741b09bdf81946d8`
Specifically they have been processed in the commit with hash: `254dc035142c56553d6d4ee9b2ea9d97259357c2`
Versions:
```

+ 238
- 161
eth/contracts/auction/HermezAuctionProtocol.go
File diff suppressed because it is too large
View File


+ 237
- 263
eth/contracts/hermez/Hermez.go
File diff suppressed because it is too large
View File


+ 41
- 42
eth/contracts/tokenHEZ/HEZ.go
File diff suppressed because it is too large
View File


+ 284
- 371
eth/contracts/withdrawdelayer/WithdrawalDelayer.go
File diff suppressed because it is too large
View File


+ 14
- 30
eth/main_test.go

@ -64,21 +64,12 @@ var (
bootCoordinatorAccount *accounts.Account
bootCoordinatorAddressConst ethCommon.Address
safetyAccount *accounts.Account
safetyAddressConst ethCommon.Address
)
// Ethereum Accounts
var (
hermezGovernanceDAOAccount *accounts.Account
hermezGovernanceDAOAddressConst ethCommon.Address
whiteHackGroupAccount *accounts.Account
whiteHackGroupAddressConst ethCommon.Address
hermezKeeperAccount *accounts.Account
hermezKeeperAddressConst ethCommon.Address
emergencyCouncilAccount *accounts.Account
emergencyCouncilAddressConst ethCommon.Address
governanceAccount *accounts.Account
governanceAddressConst ethCommon.Address
@ -94,14 +85,12 @@ var (
)
var (
ks *keystore.KeyStore
ethClient *ethclient.Client
ethereumClientWhite *EthereumClient
ethereumClientKep *EthereumClient
ethereumClientGovDAO *EthereumClient
ethereumClientAux *EthereumClient
ethereumClientAux2 *EthereumClient
ethereumClientHermez *EthereumClient
ks *keystore.KeyStore
ethClient *ethclient.Client
ethereumClientEmergencyCouncil *EthereumClient
ethereumClientAux *EthereumClient
ethereumClientAux2 *EthereumClient
ethereumClientHermez *EthereumClient
)
func getEnvVariables() {
@ -163,14 +152,11 @@ func TestMain(m *testing.M) {
// into the keystore
bootCoordinatorAccount, bootCoordinatorAddressConst = genAcc(w, ks, 0)
governanceAccount, governanceAddressConst = genAcc(w, ks, 1)
safetyAccount, safetyAddressConst = genAcc(w, ks, 2)
hermezKeeperAccount, hermezKeeperAddressConst = genAcc(w, ks, 6)
hermezGovernanceDAOAccount, hermezGovernanceDAOAddressConst = genAcc(w, ks, 7)
whiteHackGroupAccount, whiteHackGroupAddressConst = genAcc(w, ks, 8)
donationAccount, donationAddressConst = genAcc(w, ks, 9)
aux2Account, aux2AddressConst = genAcc(w, ks, 11)
hermezRollupTestAccount, hermezRollupTestAddressConst = genAcc(w, ks, 12)
auxAccount, auxAddressConst = genAcc(w, ks, 13)
emergencyCouncilAccount, emergencyCouncilAddressConst = genAcc(w, ks, 2)
donationAccount, donationAddressConst = genAcc(w, ks, 3)
hermezRollupTestAccount, hermezRollupTestAddressConst = genAcc(w, ks, 4)
auxAccount, auxAddressConst = genAcc(w, ks, 5)
aux2Account, aux2AddressConst = genAcc(w, ks, 6)
ethClient, err = ethclient.Dial(ethClientDialURL)
if err != nil {
@ -200,9 +186,7 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
ethereumClientKep = NewEthereumClient(ethClient, hermezKeeperAccount, ks, nil)
ethereumClientWhite = NewEthereumClient(ethClient, whiteHackGroupAccount, ks, nil)
ethereumClientGovDAO = NewEthereumClient(ethClient, hermezGovernanceDAOAccount, ks, nil)
ethereumClientEmergencyCouncil = NewEthereumClient(ethClient, emergencyCouncilAccount, ks, nil)
ethereumClientAux = NewEthereumClient(ethClient, auxAccount, ks, nil)
ethereumClientAux2 = NewEthereumClient(ethClient, aux2Account, ks, nil)
ethereumClientHermez = NewEthereumClient(ethClient, hermezRollupTestAccount, ks, nil)

+ 222
- 38
eth/rollup.go

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"strconv"
"strings"
"github.com/ethereum/go-ethereum"
@ -74,7 +75,8 @@ type RollupEventAddToken struct {
type RollupEventForgeBatch struct {
BatchNum int64
// Sender ethCommon.Address
EthTxHash ethCommon.Hash
EthTxHash ethCommon.Hash
L1UserTxsLen uint16
}
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
@ -95,6 +97,33 @@ type RollupEventWithdraw struct {
TxHash ethCommon.Hash // Hash of the transaction that generated this event
}
// RollupEventUpdateBucketWithdraw is an event of the Rollup Smart Contract
type RollupEventUpdateBucketWithdraw struct {
NumBucket uint8
BlockStamp *big.Int
Withdrawals *big.Int
}
// RollupEventUpdateWithdrawalDelay is an event of the Rollup Smart Contract
type RollupEventUpdateWithdrawalDelay struct {
NewWithdrawalDelay uint64
}
// RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract
type RollupEventUpdateBucketsParameters struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
}
// RollupEventUpdateTokenExchange is an event of the Rollup Smart Contract
type RollupEventUpdateTokenExchange struct {
AddressArray []ethCommon.Address
ValueArray []uint64
}
// RollupEventSafeMode is an event of the Rollup Smart Contract
type RollupEventSafeMode struct {
}
// RollupEvents is the list of events in a block of the Rollup Smart Contract
type RollupEvents struct {
L1UserTx []RollupEventL1UserTx
@ -103,6 +132,11 @@ type RollupEvents struct {
UpdateForgeL1L2BatchTimeout []RollupEventUpdateForgeL1L2BatchTimeout
UpdateFeeAddToken []RollupEventUpdateFeeAddToken
Withdraw []RollupEventWithdraw
UpdateWithdrawalDelay []RollupEventUpdateWithdrawalDelay
UpdateBucketWithdraw []RollupEventUpdateBucketWithdraw
UpdateBucketsParameters []RollupEventUpdateBucketsParameters
UpdateTokenExchange []RollupEventUpdateTokenExchange
SafeMode []RollupEventSafeMode
}
// NewRollupEvents creates an empty RollupEvents with the slices initialized.
@ -122,6 +156,7 @@ type RollupForgeBatchArgs struct {
NewLastIdx int64
NewStRoot *big.Int
NewExitRoot *big.Int
L1UserTxs []common.L1Tx
L1CoordinatorTxs []common.L1Tx
L1CoordinatorTxsAuths [][]byte // Authorization for accountCreations for each L1CoordinatorTx
L2TxsData []common.L2Tx
@ -140,7 +175,7 @@ type RollupForgeBatchArgsAux struct {
NewStRoot *big.Int
NewExitRoot *big.Int
EncodedL1CoordinatorTx []byte
L2TxsData []byte
L1L2TxsData []byte
FeeIdxCoordinator []byte
// Circuit selector
VerifierIdx uint8
@ -181,7 +216,7 @@ type RollupInterface interface {
RollupConstants() (*common.RollupConstants, error)
RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethCommon.Hash, error)
RollupForgeBatchArgs(ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error)
RollupForgeBatchArgs(ethCommon.Hash, uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error)
}
//
@ -240,6 +275,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
lenBytes := nLevels / 8 //nolint:gomnd
newLastIdx := big.NewInt(int64(args.NewLastIdx))
// L1CoordinatorBytes
var l1CoordinatorBytes []byte
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
l1 := args.L1CoordinatorTxs[i]
@ -249,15 +285,33 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
}
l1CoordinatorBytes = append(l1CoordinatorBytes, bytesl1[:]...)
}
var l2DataBytes []byte
// L1L2TxData
var l1l2TxData []byte
for i := 0; i < len(args.L1UserTxs); i++ {
l1User := args.L1UserTxs[i]
bytesl1User, err := l1User.BytesDataAvailability(uint32(nLevels))
if err != nil {
return nil, tracerr.Wrap(err)
}
l1l2TxData = append(l1l2TxData, bytesl1User[:]...)
}
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
l1Coord := args.L1CoordinatorTxs[i]
bytesl1Coord, err := l1Coord.BytesDataAvailability(uint32(nLevels))
if err != nil {
return nil, tracerr.Wrap(err)
}
l1l2TxData = append(l1l2TxData, bytesl1Coord[:]...)
}
for i := 0; i < len(args.L2TxsData); i++ {
l2 := args.L2TxsData[i]
bytesl2, err := l2.BytesDataAvailability(uint32(nLevels))
if err != nil {
return nil, tracerr.Wrap(err)
}
l2DataBytes = append(l2DataBytes, bytesl2[:]...)
l1l2TxData = append(l1l2TxData, bytesl2[:]...)
}
// FeeIdxCoordinator
var feeIdxCoordinator []byte
if len(args.FeeIdxCoordinator) > common.RollupConstMaxFeeIdxCoordinator {
return nil, tracerr.Wrap(fmt.Errorf("len(args.FeeIdxCoordinator) > %v",
@ -274,7 +328,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
}
feeIdxCoordinator = append(feeIdxCoordinator, bytesFeeIdx[len(bytesFeeIdx)-int(lenBytes):]...)
}
return c.hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l2DataBytes, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC)
return c.hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l1l2TxData, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed forge batch: %w", err))
@ -317,7 +371,7 @@ func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tok
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
numExitRootB := big.NewInt(numExitRoot)
numExitRootB := uint32(numExitRoot)
idxBig := big.NewInt(idx)
return c.hermez.WithdrawMerkleProof(auth, tokenID, amount, babyPubKey, numExitRootB, siblings, idxBig, instantWithdraw)
},
@ -338,9 +392,14 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
var babyPubKey *big.Int
if fromBJJ != nil {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey = new(big.Int).SetBytes(pkCompB)
} else {
babyPubKey = big.NewInt(0)
}
fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
@ -369,9 +428,14 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
var babyPubKey *big.Int
if fromBJJ != nil {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey = new(big.Int).SetBytes(pkCompB)
} else {
babyPubKey = big.NewInt(0)
}
fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
@ -454,6 +518,69 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ
return tx, nil
}
// RollupUpdateBucketsParameters is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateBucketsParameters(arrayBuckets [common.RollupConstNumBuckets][4]*big.Int) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
12500000,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateBucketsParameters(auth, arrayBuckets)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Buckets Parameters: %w", err))
}
return tx, nil
}
// RollupUpdateTokenExchange is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateTokenExchange(addressArray []ethCommon.Address, valueArray []uint64) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateTokenExchange(auth, addressArray, valueArray)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Token Exchange: %w", err))
}
return tx, nil
}
// RollupUpdateWithdrawalDelay is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateWithdrawalDelay(newWithdrawalDelay uint64) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateWithdrawalDelay(auth, newWithdrawalDelay)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update WithdrawalDelay: %w", err))
}
return tx, nil
}
// RollupSafeMode is the interface to call the smart contract function
func (c *RollupClient) RollupSafeMode() (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.SafeMode(auth)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Safe Mode: %w", err))
}
return tx, nil
}
// RollupInstantWithdrawalViewer is the interface to call the smart contract function
func (c *RollupClient) RollupInstantWithdrawalViewer(tokenAddress ethCommon.Address, amount *big.Int) (instantAllowed bool, err error) {
if err := c.client.Call(func(ec *ethclient.Client) error {
instantAllowed, err = c.hermez.InstantWithdrawalViewer(nil, tokenAddress, amount)
return tracerr.Wrap(err)
}); err != nil {
return false, tracerr.Wrap(err)
}
return instantAllowed, nil
}
// RollupConstants returns the Constants of the Rollup Smart Contract
func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstants, err error) {
rollupConstants = new(common.RollupConstants)
@ -481,11 +608,7 @@ func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstant
if err != nil {
return tracerr.Wrap(err)
}
rollupConstants.HermezGovernanceDAOAddress, err = c.hermez.HermezGovernanceDAOAddress(nil)
if err != nil {
return tracerr.Wrap(err)
}
rollupConstants.SafetyAddress, err = c.hermez.SafetyAddress(nil)
rollupConstants.HermezGovernanceAddress, err = c.hermez.HermezGovernanceAddress(nil)
if err != nil {
return tracerr.Wrap(err)
}
@ -498,12 +621,17 @@ func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstant
}
var (
logHermezL1UserTxEvent = crypto.Keccak256Hash([]byte("L1UserTxEvent(uint64,uint8,bytes)"))
logHermezL1UserTxEvent = crypto.Keccak256Hash([]byte("L1UserTxEvent(uint32,uint8,bytes)"))
logHermezAddToken = crypto.Keccak256Hash([]byte("AddToken(address,uint32)"))
logHermezForgeBatch = crypto.Keccak256Hash([]byte("ForgeBatch(uint64)"))
logHermezForgeBatch = crypto.Keccak256Hash([]byte("ForgeBatch(uint32,uint16)"))
logHermezUpdateForgeL1L2BatchTimeout = crypto.Keccak256Hash([]byte("UpdateForgeL1L2BatchTimeout(uint8)"))
logHermezUpdateFeeAddToken = crypto.Keccak256Hash([]byte("UpdateFeeAddToken(uint256)"))
logHermezWithdrawEvent = crypto.Keccak256Hash([]byte("WithdrawEvent(uint48,uint48,bool)"))
logHermezWithdrawEvent = crypto.Keccak256Hash([]byte("WithdrawEvent(uint48,uint32,bool)"))
logHermezUpdateBucketWithdraw = crypto.Keccak256Hash([]byte("UpdateBucketWithdraw(uint8,uint256,uint256)"))
logHermezUpdateWithdrawalDelay = crypto.Keccak256Hash([]byte("UpdateWithdrawalDelay(uint64)"))
logHermezUpdateBucketsParameters = crypto.Keccak256Hash([]byte("UpdateBucketsParameters(uint256[4][" + strconv.Itoa(common.RollupConstNumBuckets) + "])"))
logHermezUpdateTokenExchange = crypto.Keccak256Hash([]byte("UpdateTokenExchange(address[],uint64[])"))
logHermezSafeMode = crypto.Keccak256Hash([]byte("SafeMode()"))
)
// RollupEventsByBlock returns the events in a block that happened in the Rollup Smart Contract
@ -560,6 +688,10 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
rollupEvents.AddToken = append(rollupEvents.AddToken, addToken)
case logHermezForgeBatch:
var forgeBatch RollupEventForgeBatch
err := c.contractAbi.Unpack(&forgeBatch, "ForgeBatch", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
forgeBatch.BatchNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
forgeBatch.EthTxHash = vLog.TxHash
// forgeBatch.Sender = vLog.Address
@ -593,6 +725,40 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
}
withdraw.TxHash = vLog.TxHash
rollupEvents.Withdraw = append(rollupEvents.Withdraw, withdraw)
case logHermezUpdateBucketWithdraw:
var updateBucketWithdraw RollupEventUpdateBucketWithdraw
err := c.contractAbi.Unpack(&updateBucketWithdraw, "UpdateBucketWithdraw", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
updateBucketWithdraw.NumBucket = uint8(new(big.Int).SetBytes(vLog.Topics[1][:]).Int64())
updateBucketWithdraw.BlockStamp = new(big.Int).SetBytes(vLog.Topics[2][:])
rollupEvents.UpdateBucketWithdraw = append(rollupEvents.UpdateBucketWithdraw, updateBucketWithdraw)
case logHermezUpdateWithdrawalDelay:
var withdrawalDelay RollupEventUpdateWithdrawalDelay
err := c.contractAbi.Unpack(&withdrawalDelay, "UpdateWithdrawalDelay", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupEvents.UpdateWithdrawalDelay = append(rollupEvents.UpdateWithdrawalDelay, withdrawalDelay)
case logHermezUpdateBucketsParameters:
var bucketsParameters RollupEventUpdateBucketsParameters
err := c.contractAbi.Unpack(&bucketsParameters, "UpdateBucketsParameters", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters, bucketsParameters)
case logHermezUpdateTokenExchange:
var tokensExchange RollupEventUpdateTokenExchange
err := c.contractAbi.Unpack(&tokensExchange, "UpdateTokenExchange", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupEvents.UpdateTokenExchange = append(rollupEvents.UpdateTokenExchange, tokensExchange)
case logHermezSafeMode:
var safeMode RollupEventSafeMode
rollupEvents.SafeMode = append(rollupEvents.SafeMode, safeMode)
}
}
return &rollupEvents, blockHash, nil
@ -600,7 +766,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the
// Rollup Smart Contract in the given transaction, and the sender address.
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numL1TxUser uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
tx, _, err := c.client.client.TransactionByHash(context.Background(), ethTxHash)
if err != nil {
return nil, nil, tracerr.Wrap(err)
@ -637,8 +803,40 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
L2TxsData: []common.L2Tx{},
FeeIdxCoordinator: []common.Idx{},
}
numTxsL1 := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
for i := 0; i < numTxsL1; i++ {
rollupConsts, err := c.RollupConstants()
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
lenL1L2TxsBytes := int((nLevels/8)*2 + 2 + 1)
numBytesL1TxUser := int(numL1TxUser) * lenL1L2TxsBytes
numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
numBytesL1TxCoord := numTxsL1Coord * lenL1L2TxsBytes
numBeginL2Tx := numBytesL1TxCoord + numBytesL1TxUser
l1UserTxsData := []byte{}
if numL1TxUser > 0 {
l1UserTxsData = aux.L1L2TxsData[:numBytesL1TxUser]
}
for i := 0; i < int(numL1TxUser); i++ {
l1Tx, err := common.L1TxFromDataAvailability(l1UserTxsData[i*lenL1L2TxsBytes:(i+1)*lenL1L2TxsBytes], uint32(nLevels))
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupForgeBatchArgs.L1UserTxs = append(rollupForgeBatchArgs.L1UserTxs, *l1Tx)
}
l2TxsData := []byte{}
if numBeginL2Tx < len(aux.L1L2TxsData) {
l2TxsData = aux.L1L2TxsData[numBeginL2Tx:]
}
numTxsL2 := len(l2TxsData) / lenL1L2TxsBytes
for i := 0; i < numTxsL2; i++ {
l2Tx, err := common.L2TxFromBytesDataAvailability(l2TxsData[i*lenL1L2TxsBytes:(i+1)*lenL1L2TxsBytes], int(nLevels))
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx)
}
for i := 0; i < numTxsL1Coord; i++ {
bytesL1Coordinator := aux.EncodedL1CoordinatorTx[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
var signature []byte
v := bytesL1Coordinator[0]
@ -654,20 +852,6 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, *l1Tx)
rollupForgeBatchArgs.L1CoordinatorTxsAuths = append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature)
}
rollupConsts, err := c.RollupConstants()
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
lenL2TxsBytes := int((nLevels/8)*2 + 2 + 1)
numTxsL2 := len(aux.L2TxsData) / lenL2TxsBytes
for i := 0; i < numTxsL2; i++ {
l2Tx, err := common.L2TxFromBytes(aux.L2TxsData[i*lenL2TxsBytes:(i+1)*lenL2TxsBytes], int(nLevels))
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx)
}
lenFeeIdxCoordinatorBytes := int(nLevels / 8) //nolint:gomnd
numFeeIdxCoordinator := len(aux.FeeIdxCoordinator) / lenFeeIdxCoordinatorBytes
for i := 0; i < numFeeIdxCoordinator; i++ {

+ 243
- 131
eth/rollup_test.go

@ -29,6 +29,9 @@ var nLevels = int64(32)
var tokenIDERC777 uint32
var tokenHEZID uint32
var L1UserTxs []common.L1Tx
var blockStampBucket int64
type keys struct {
BJJSecretKey *babyjub.PrivateKey
BJJPublicKey *babyjub.PublicKey
@ -60,8 +63,7 @@ func TestRollupConstants(t *testing.T) {
assert.Equal(t, tokenHEZAddressConst, rollupConstants.TokenHEZ)
assert.Equal(t, maxTx, rollupConstants.Verifiers[0].MaxTx)
assert.Equal(t, nLevels, rollupConstants.Verifiers[0].NLevels)
assert.Equal(t, governanceAddressConst, rollupConstants.HermezGovernanceDAOAddress)
assert.Equal(t, safetyAddressConst, rollupConstants.SafetyAddress)
assert.Equal(t, governanceAddressConst, rollupConstants.HermezGovernanceAddress)
assert.Equal(t, wdelayerAddressConst, rollupConstants.WithdrawDelayerContract)
}
@ -115,7 +117,7 @@ func TestRollupForgeBatch(t *testing.T) {
blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL)
// Forge
// Forge Batch 1
args := new(RollupForgeBatchArgs)
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")
@ -135,6 +137,7 @@ func TestRollupForgeBatch(t *testing.T) {
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
}
args.L1UserTxs = []common.L1Tx{}
args.L2TxsData = []common.L2Tx{}
newStateRoot := new(big.Int)
newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
@ -142,7 +145,7 @@ func TestRollupForgeBatch(t *testing.T) {
bytesNumExitRoot, err := hex.DecodeString("10a89d5fe8d488eda1ba371d633515739933c706c210c604f5bd209180daa43b")
require.Nil(t, err)
newExitRoot.SetBytes(bytesNumExitRoot)
args.NewLastIdx = int64(256)
args.NewLastIdx = int64(300)
args.NewStRoot = newStateRoot
args.NewExitRoot = newExitRoot
args.L1Batch = true
@ -166,11 +169,12 @@ func TestRollupForgeBatch(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, int64(1), rollupEvents.ForgeBatch[0].BatchNum)
assert.Equal(t, uint16(len(L1UserTxs)), rollupEvents.ForgeBatch[0].L1UserTxsLen)
ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash
}
func TestRollupForgeBatchArgs(t *testing.T) {
args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge)
args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge, uint16(len(L1UserTxs)))
require.Nil(t, err)
assert.Equal(t, *sender, rollupClient.client.account.Address)
assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator)
@ -209,6 +213,59 @@ func TestRollupUpdateFeeAddToken(t *testing.T) {
assert.Equal(t, newFeeAddToken, rollupEvents.UpdateFeeAddToken[0].NewFeeAddToken)
}
func TestRollupUpdateBucketsParameters(t *testing.T) {
var bucketsParameters [common.RollupConstNumBuckets][4]*big.Int
for i := range bucketsParameters {
bucketsParameters[i][0] = big.NewInt(int64((i + 1) * 100)) // ceilUSD
bucketsParameters[i][1] = big.NewInt(int64(i + 1)) // withdrawals
bucketsParameters[i][2] = big.NewInt(int64(i+1) * 100) // blockWithdrawalRate
bucketsParameters[i][3] = big.NewInt(int64(100000000000)) // maxWithdrawals
}
_, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters)
require.Nil(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
blockStampBucket = currentBlockNum
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
for i := range bucketsParameters {
assert.Equal(t, bucketsParameters[i][0].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][0].String())
assert.Equal(t, bucketsParameters[i][1].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][1].String())
assert.Equal(t, bucketsParameters[i][2].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][2].String())
assert.Equal(t, bucketsParameters[i][3].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][3].String())
}
}
func TestRollupUpdateWithdrawalDelay(t *testing.T) {
newWithdrawalDelay := uint64(100000)
_, err := rollupClient.RollupUpdateWithdrawalDelay(newWithdrawalDelay)
require.Nil(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, newWithdrawalDelay, rollupEvents.UpdateWithdrawalDelay[0].NewWithdrawalDelay)
}
func TestRollupUpdateTokenExchange(t *testing.T) {
var addressArray []ethCommon.Address
var valueArray []uint64
addressToken1, err := rollupClient.hermez.TokenList(nil, big.NewInt(1))
addressArray = append(addressArray, addressToken1)
tokenPrice := 10
valueArray = append(valueArray, uint64(tokenPrice*1e14))
require.Nil(t, err)
_, err = rollupClient.RollupUpdateTokenExchange(addressArray, valueArray)
require.Nil(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, addressArray, rollupEvents.UpdateTokenExchange[0].AddressArray)
assert.Equal(t, valueArray, rollupEvents.UpdateTokenExchange[0].ValueArray)
}
func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
@ -216,14 +273,16 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
@ -246,14 +305,16 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
@ -276,14 +337,16 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
@ -303,18 +366,19 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
func TestRollupL1UserTxETHDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
fromIdxInt64 := int64(256)
toIdxInt64 := int64(0)
tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromBJJ: nil,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
@ -323,7 +387,6 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -334,17 +397,18 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
func TestRollupL1UserTxERC20Deposit(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
fromIdxInt64 := int64(257)
toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromBJJ: nil,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
@ -353,7 +417,6 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -364,17 +427,17 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
fromIdxInt64 := int64(258)
toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
@ -383,7 +446,6 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -394,18 +456,19 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(256)
toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("100000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
@ -414,7 +477,6 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -425,17 +487,18 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(257)
toIdxInt64 := int64(258)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("100000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
@ -444,7 +507,6 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -455,17 +517,18 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(258)
toIdxInt64 := int64(259)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("100000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
@ -474,7 +537,6 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -485,18 +547,19 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(256)
toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("20000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
@ -505,7 +568,6 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -516,17 +578,18 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(257)
toIdxInt64 := int64(258)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("30000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
@ -535,7 +598,6 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -546,17 +608,18 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(258)
toIdxInt64 := int64(259)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
amount, _ := new(big.Int).SetString("40000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: loadAmount,
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
@ -565,7 +628,6 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -576,18 +638,18 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(256)
toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0)
amount, _ := new(big.Int).SetString("20000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
@ -596,7 +658,6 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -607,17 +668,17 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(257)
toIdxInt64 := int64(258)
amount, _ := new(big.Int).SetString("10000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
@ -626,7 +687,6 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -637,17 +697,17 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(259)
toIdxInt64 := int64(260)
amount, _ := new(big.Int).SetString("30000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
@ -656,7 +716,6 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -667,18 +726,18 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
func TestRollupL1UserTxETHForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(256)
toIdxInt64 := int64(1)
tokenIDUint32 := uint32(0)
amount, _ := new(big.Int).SetString("10000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDUint32),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
@ -687,7 +746,6 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -698,17 +756,17 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(257)
toIdxInt64 := int64(1)
amount, _ := new(big.Int).SetString("20000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
@ -717,7 +775,6 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -728,19 +785,19 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
toIdxInt64 := int64(0)
fromIdxInt64 := int64(258)
toIdxInt64 := int64(1)
fromIdx := new(common.Idx)
*fromIdx = 0
amount, _ := new(big.Int).SetString("30000000000000000000", 10)
l1Tx := common.L1Tx{
FromBJJ: key.BJJPublicKey,
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
LoadAmount: big.NewInt(0),
TokenID: common.TokenID(tokenIDERC777),
Amount: big.NewInt(0),
Amount: amount,
}
L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
@ -749,7 +806,6 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
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)
@ -758,27 +814,46 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
}
func TestRollupForgeBatch2(t *testing.T) {
// Forge
// Forge Batch 2
_, err := rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum)
// Forge Batch 3
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[:])
args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified.
args.L1CoordinatorTxs = argsForge.L1CoordinatorTxs
args.L1CoordinatorTxsAuths = argsForge.L1CoordinatorTxsAuths
for i := 0; i < len(L1UserTxs); i++ {
l1UserTx := L1UserTxs[i]
l1UserTx.EffectiveAmount = l1UserTx.Amount
l1Bytes, err := l1UserTx.BytesDataAvailability(uint32(nLevels))
require.Nil(t, err)
l1UserTxDataAvailability, err := common.L1TxFromDataAvailability(l1Bytes, uint32(nLevels))
require.Nil(t, err)
args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
args.L1UserTxs = append(args.L1UserTxs, *l1UserTxDataAvailability)
}
newStateRoot := new(big.Int)
newStateRoot.SetString("0", 10)
newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
newExitRoot := new(big.Int)
newExitRoot.SetString("4694629460381124336935185586347620040847956843554725549791403956105308092690", 10)
newExitRoot.SetString("1114281409737474688393837964161044726766678436313681099613347372031079422302", 10)
amount := new(big.Int)
amount.SetString("79000000", 10)
l2Tx := common.L2Tx{
ToIdx: 256,
Amount: amount,
FromIdx: 257,
Fee: 201,
}
l2Txs := []common.L2Tx{}
l2Txs = append(l2Txs, l2Tx)
l2Txs = append(l2Txs, l2Tx)
args.L2TxsData = l2Txs
args.NewLastIdx = int64(1000)
args.NewStRoot = newStateRoot
args.NewExitRoot = newExitRoot
@ -792,16 +867,34 @@ func TestRollupForgeBatch2(t *testing.T) {
args.ProofC[1] = big.NewInt(0)
argsForge = args
_, err = rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock()
currentBlockNum, err = rollupClient.client.EthLastBlock()
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
rollupEvents, _, err = rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum)
assert.Equal(t, int64(3), rollupEvents.ForgeBatch[0].BatchNum)
assert.Equal(t, uint16(len(L1UserTxs)), rollupEvents.ForgeBatch[0].L1UserTxsLen)
ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash
}
func TestRollupForgeBatchArgs2(t *testing.T) {
args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge, uint16(len(L1UserTxs)))
require.Nil(t, err)
assert.Equal(t, *sender, rollupClient.client.account.Address)
assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator)
assert.Equal(t, argsForge.L1Batch, args.L1Batch)
assert.Equal(t, argsForge.L1UserTxs, args.L1UserTxs)
assert.Equal(t, argsForge.L1CoordinatorTxs, args.L1CoordinatorTxs)
assert.Equal(t, argsForge.L1CoordinatorTxsAuths, args.L1CoordinatorTxsAuths)
assert.Equal(t, argsForge.L2TxsData, args.L2TxsData)
assert.Equal(t, argsForge.NewLastIdx, args.NewLastIdx)
assert.Equal(t, argsForge.NewStRoot, args.NewStRoot)
assert.Equal(t, argsForge.VerifierIdx, args.VerifierIdx)
}
func TestRollupWithdrawMerkleProof(t *testing.T) {
@ -813,17 +906,15 @@ func TestRollupWithdrawMerkleProof(t *testing.T) {
require.Nil(t, err)
pkCompLE := common.SwapEndianness(pkCompBE)
copy(pkComp[:], pkCompLE)
// 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)
tokenID := uint32(tokenHEZID)
numExitRoot := int64(3)
fromIdx := int64(256)
amount := big.NewInt(10)
amount, _ := new(big.Int).SetString("20000000000000000000", 10)
// siblingBytes0, err := new(big.Int).SetString("19508838618377323910556678335932426220272947530531646682154552299216398748115", 10)
// require.Nil(t, err)
// siblingBytes1, err := new(big.Int).SetString("15198806719713909654457742294233381653226080862567104272457668857208564789571", 10)
@ -844,4 +935,25 @@ func TestRollupWithdrawMerkleProof(t *testing.T) {
assert.Equal(t, uint64(fromIdx), rollupEvents.Withdraw[0].Idx)
assert.Equal(t, instantWithdraw, rollupEvents.Withdraw[0].InstantWithdraw)
assert.Equal(t, uint64(numExitRoot), rollupEvents.Withdraw[0].NumExitRoot)
// tokenAmount = 20
// amountUSD = tokenAmount * tokenPrice = 20 * 10 = 200
// Bucket[0].ceilUSD = 100, Bucket[1].ceilUSD = 200, ...
// Bucket 1
// Bucket[0].withdrawals = 1, Bucket[1].withdrawals = 2, ...
// Bucket[1].withdrawals - 1 = 1
assert.Equal(t, uint8(1), rollupEvents.UpdateBucketWithdraw[0].NumBucket)
assert.Equal(t, big.NewInt(blockStampBucket), rollupEvents.UpdateBucketWithdraw[0].BlockStamp)
assert.Equal(t, big.NewInt(1), rollupEvents.UpdateBucketWithdraw[0].Withdrawals)
}
func TestRollupSafeMode(t *testing.T) {
_, err := rollupClient.RollupSafeMode()
require.Nil(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
auxEvent := new(RollupEventSafeMode)
assert.Equal(t, auxEvent, &rollupEvents.SafeMode[0])
}

+ 76
- 91
eth/wdelayer.go

@ -58,44 +58,37 @@ type WDelayerEventEscapeHatchWithdrawal struct {
Amount *big.Int
}
// WDelayerEventNewHermezKeeperAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezKeeperAddress struct {
NewHermezKeeperAddress ethCommon.Address
// WDelayerEventNewEmergencyCouncil an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewEmergencyCouncil struct {
NewEmergencyCouncil ethCommon.Address
}
// WDelayerEventNewWhiteHackGroupAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewWhiteHackGroupAddress struct {
NewWhiteHackGroupAddress ethCommon.Address
}
// WDelayerEventNewHermezGovernanceDAOAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezGovernanceDAOAddress struct {
NewHermezGovernanceDAOAddress ethCommon.Address
// WDelayerEventNewHermezGovernanceAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezGovernanceAddress struct {
NewHermezGovernanceAddress ethCommon.Address
}
// WDelayerEvents is the lis of events in a block of the WithdrawalDelayer Smart Contract
type WDelayerEvents struct {
Deposit []WDelayerEventDeposit
Withdraw []WDelayerEventWithdraw
EmergencyModeEnabled []WDelayerEventEmergencyModeEnabled
NewWithdrawalDelay []WDelayerEventNewWithdrawalDelay
EscapeHatchWithdrawal []WDelayerEventEscapeHatchWithdrawal
NewHermezKeeperAddress []WDelayerEventNewHermezKeeperAddress
NewWhiteHackGroupAddress []WDelayerEventNewWhiteHackGroupAddress
NewHermezGovernanceDAOAddress []WDelayerEventNewHermezGovernanceDAOAddress
Deposit []WDelayerEventDeposit
Withdraw []WDelayerEventWithdraw
EmergencyModeEnabled []WDelayerEventEmergencyModeEnabled
NewWithdrawalDelay []WDelayerEventNewWithdrawalDelay
EscapeHatchWithdrawal []WDelayerEventEscapeHatchWithdrawal
NewEmergencyCouncil []WDelayerEventNewEmergencyCouncil
NewHermezGovernanceAddress []WDelayerEventNewHermezGovernanceAddress
}
// NewWDelayerEvents creates an empty WDelayerEvents with the slices initialized.
func NewWDelayerEvents() WDelayerEvents {
return WDelayerEvents{
Deposit: make([]WDelayerEventDeposit, 0),
Withdraw: make([]WDelayerEventWithdraw, 0),
EmergencyModeEnabled: make([]WDelayerEventEmergencyModeEnabled, 0),
NewWithdrawalDelay: make([]WDelayerEventNewWithdrawalDelay, 0),
EscapeHatchWithdrawal: make([]WDelayerEventEscapeHatchWithdrawal, 0),
NewHermezKeeperAddress: make([]WDelayerEventNewHermezKeeperAddress, 0),
NewWhiteHackGroupAddress: make([]WDelayerEventNewWhiteHackGroupAddress, 0),
NewHermezGovernanceDAOAddress: make([]WDelayerEventNewHermezGovernanceDAOAddress, 0),
Deposit: make([]WDelayerEventDeposit, 0),
Withdraw: make([]WDelayerEventWithdraw, 0),
EmergencyModeEnabled: make([]WDelayerEventEmergencyModeEnabled, 0),
NewWithdrawalDelay: make([]WDelayerEventNewWithdrawalDelay, 0),
EscapeHatchWithdrawal: make([]WDelayerEventEscapeHatchWithdrawal, 0),
NewEmergencyCouncil: make([]WDelayerEventNewEmergencyCouncil, 0),
NewHermezGovernanceAddress: make([]WDelayerEventNewHermezGovernanceAddress, 0),
}
}
@ -105,12 +98,12 @@ type WDelayerInterface interface {
// Smart Contract Methods
//
WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error)
WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error)
WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error)
WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerGetHermezGovernanceAddress() (*ethCommon.Address, error)
WDelayerTransferGovernance(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerClaimGovernance() (*types.Transaction, error)
WDelayerGetEmergencyCouncil() (*ethCommon.Address, error)
WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerClaimEmergencyCouncil() (*types.Transaction, error)
WDelayerIsEmergencyMode() (bool, error)
WDelayerGetWithdrawalDelay() (*big.Int, error)
WDelayerGetEmergencyModeStartingTime() (*big.Int, error)
@ -155,77 +148,78 @@ func NewWDelayerClient(client *EthereumClient, address ethCommon.Address) (*WDel
}, nil
}
// WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (hermezGovernanceDAOAddress *ethCommon.Address, err error) {
var _hermezGovernanceDAOAddress ethCommon.Address
// WDelayerGetHermezGovernanceAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezGovernanceAddress() (hermezGovernanceAddress *ethCommon.Address, err error) {
var _hermezGovernanceAddress ethCommon.Address
if err := c.client.Call(func(ec *ethclient.Client) error {
_hermezGovernanceDAOAddress, err = c.wdelayer.GetHermezGovernanceDAOAddress(nil)
_hermezGovernanceAddress, err = c.wdelayer.GetHermezGovernanceAddress(nil)
return tracerr.Wrap(err)
}); err != nil {
return nil, tracerr.Wrap(err)
}
return &_hermezGovernanceDAOAddress, nil
return &_hermezGovernanceAddress, nil
}
// WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferGovernance is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerTransferGovernance(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.SetHermezGovernanceDAOAddress(auth, newAddress)
return c.wdelayer.TransferGovernance(auth, newAddress)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting hermezGovernanceDAOAddress: %w", err))
return nil, tracerr.Wrap(fmt.Errorf("Failed transfer hermezGovernanceAddress: %w", err))
}
return tx, nil
}
// WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezKeeperAddress() (hermezKeeperAddress *ethCommon.Address, err error) {
var _hermezKeeperAddress ethCommon.Address
if err := c.client.Call(func(ec *ethclient.Client) error {
_hermezKeeperAddress, err = c.wdelayer.GetHermezKeeperAddress(nil)
return tracerr.Wrap(err)
}); err != nil {
return nil, tracerr.Wrap(err)
}
return &_hermezKeeperAddress, nil
}
// WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerClaimGovernance is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerClaimGovernance() (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.SetHermezKeeperAddress(auth, newAddress)
return c.wdelayer.ClaimGovernance(auth)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting hermezKeeperAddress: %w", err))
return nil, tracerr.Wrap(fmt.Errorf("Failed claim hermezGovernanceAddress: %w", err))
}
return tx, nil
}
// WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetWhiteHackGroupAddress() (whiteHackGroupAddress *ethCommon.Address, err error) {
var _whiteHackGroupAddress ethCommon.Address
// WDelayerGetEmergencyCouncil is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetEmergencyCouncil() (emergencyCouncilAddress *ethCommon.Address, err error) {
var _emergencyCouncilAddress ethCommon.Address
if err := c.client.Call(func(ec *ethclient.Client) error {
_whiteHackGroupAddress, err = c.wdelayer.GetWhiteHackGroupAddress(nil)
_emergencyCouncilAddress, err = c.wdelayer.GetEmergencyCouncil(nil)
return tracerr.Wrap(err)
}); err != nil {
return nil, tracerr.Wrap(err)
}
return &_whiteHackGroupAddress, nil
return &_emergencyCouncilAddress, nil
}
// WDelayerTransferEmergencyCouncil is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.TransferEmergencyCouncil(auth, newAddress)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed transfer EmergencyCouncil: %w", err))
}
return tx, nil
}
// WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerClaimEmergencyCouncil is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerClaimEmergencyCouncil() (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.SetWhiteHackGroupAddress(auth, newAddress)
return c.wdelayer.ClaimEmergencyCouncil(auth)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting whiteHackGroupAddress: %w", err))
return nil, tracerr.Wrap(fmt.Errorf("Failed claim EmergencyCouncil: %w", err))
}
return tx, nil
}
@ -365,14 +359,13 @@ func (c *WDelayerClient) WDelayerConstants() (constants *common.WDelayerConstant
}
var (
logWDelayerDeposit = crypto.Keccak256Hash([]byte("Deposit(address,address,uint192,uint64)"))
logWDelayerWithdraw = crypto.Keccak256Hash([]byte("Withdraw(address,address,uint192)"))
logWDelayerEmergencyModeEnabled = crypto.Keccak256Hash([]byte("EmergencyModeEnabled()"))
logWDelayerNewWithdrawalDelay = crypto.Keccak256Hash([]byte("NewWithdrawalDelay(uint64)"))
logWDelayerEscapeHatchWithdrawal = crypto.Keccak256Hash([]byte("EscapeHatchWithdrawal(address,address,address,uint256)"))
logWDelayerNewHermezKeeperAddress = crypto.Keccak256Hash([]byte("NewHermezKeeperAddress(address)"))
logWDelayerNewWhiteHackGroupAddress = crypto.Keccak256Hash([]byte("NewWhiteHackGroupAddress(address)"))
logWDelayerNewHermezGovernanceDAOAddress = crypto.Keccak256Hash([]byte("NewHermezGovernanceDAOAddress(address)"))
logWDelayerDeposit = crypto.Keccak256Hash([]byte("Deposit(address,address,uint192,uint64)"))
logWDelayerWithdraw = crypto.Keccak256Hash([]byte("Withdraw(address,address,uint192)"))
logWDelayerEmergencyModeEnabled = crypto.Keccak256Hash([]byte("EmergencyModeEnabled()"))
logWDelayerNewWithdrawalDelay = crypto.Keccak256Hash([]byte("NewWithdrawalDelay(uint64)"))
logWDelayerEscapeHatchWithdrawal = crypto.Keccak256Hash([]byte("EscapeHatchWithdrawal(address,address,address,uint256)"))
logWDelayerNewEmergencyCouncil = crypto.Keccak256Hash([]byte("NewEmergencyCouncil(address)"))
logWDelayerNewHermezGovernanceAddress = crypto.Keccak256Hash([]byte("NewHermezGovernanceAddress(address)"))
)
// WDelayerEventsByBlock returns the events in a block that happened in the
@ -449,29 +442,21 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents,
escapeHatchWithdrawal.Token = ethCommon.BytesToAddress(vLog.Topics[3].Bytes())
wdelayerEvents.EscapeHatchWithdrawal = append(wdelayerEvents.EscapeHatchWithdrawal, escapeHatchWithdrawal)
case logWDelayerNewHermezKeeperAddress:
var keeperAddress WDelayerEventNewHermezKeeperAddress
err := c.contractAbi.Unpack(&keeperAddress, "NewHermezKeeperAddress", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
wdelayerEvents.NewHermezKeeperAddress = append(wdelayerEvents.NewHermezKeeperAddress, keeperAddress)
case logWDelayerNewWhiteHackGroupAddress:
var whiteHackGroupAddress WDelayerEventNewWhiteHackGroupAddress
err := c.contractAbi.Unpack(&whiteHackGroupAddress, "NewWhiteHackGroupAddress", vLog.Data)
case logWDelayerNewEmergencyCouncil:
var emergencyCouncil WDelayerEventNewEmergencyCouncil
err := c.contractAbi.Unpack(&emergencyCouncil, "NewEmergencyCouncil", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
wdelayerEvents.NewWhiteHackGroupAddress = append(wdelayerEvents.NewWhiteHackGroupAddress, whiteHackGroupAddress)
wdelayerEvents.NewEmergencyCouncil = append(wdelayerEvents.NewEmergencyCouncil, emergencyCouncil)
case logWDelayerNewHermezGovernanceDAOAddress:
var governanceDAOAddress WDelayerEventNewHermezGovernanceDAOAddress
err := c.contractAbi.Unpack(&governanceDAOAddress, "NewHermezGovernanceDAOAddress", vLog.Data)
case logWDelayerNewHermezGovernanceAddress:
var governanceAddress WDelayerEventNewHermezGovernanceAddress
err := c.contractAbi.Unpack(&governanceAddress, "NewHermezGovernanceAddress", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
wdelayerEvents.NewHermezGovernanceDAOAddress = append(wdelayerEvents.NewHermezGovernanceDAOAddress, governanceDAOAddress)
wdelayerEvents.NewHermezGovernanceAddress = append(wdelayerEvents.NewHermezGovernanceAddress, governanceAddress)
}
}
return &wdelayerEvents, blockHash, nil

+ 29
- 54
eth/wdelayer_test.go

@ -12,8 +12,6 @@ import (
var wdelayerClient *WDelayerClient
var wdelayerClientTest *WDelayerClient
// var wdelayerClientKep *WDelayerClient
var initWithdrawalDelay = big.NewInt(60)
var newWithdrawalDelay = big.NewInt(79)
var maxEmergencyModeTime = time.Hour * 24 * 7 * 26
@ -27,78 +25,59 @@ func TestWDelayerConstants(t *testing.T) {
assert.Equal(t, hermezRollupTestAddressConst, wDelayerConstants.HermezRollup)
}
func TestWDelayerGetHermezGovernanceDAOAddress(t *testing.T) {
governanceAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceDAOAddress()
func TestWDelayerGetHermezGovernanceAddress(t *testing.T) {
governanceAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceAddress()
require.Nil(t, err)
assert.Equal(t, &hermezGovernanceDAOAddressConst, governanceAddress)
assert.Equal(t, &governanceAddressConst, governanceAddress)
}
func TestWDelayerSetHermezGovernanceDAOAddress(t *testing.T) {
wdelayerClientGov, err := NewWDelayerClient(ethereumClientGovDAO, wdelayerTestAddressConst)
func TestWDelayerSetHermezGovernanceAddress(t *testing.T) {
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientTest.WDelayerTransferGovernance(auxAddressConst)
require.Nil(t, err)
_, err = wdelayerClientGov.WDelayerSetHermezGovernanceDAOAddress(auxAddressConst)
_, err = wdelayerClientAux.WDelayerClaimGovernance()
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceDAOAddress()
auxAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
wdelayerEvents, _, err := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezGovernanceDAOAddress[0].NewHermezGovernanceDAOAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezGovernanceAddress[0].NewHermezGovernanceAddress)
_, err = wdelayerClientAux.WDelayerTransferGovernance(governanceAddressConst)
require.Nil(t, err)
_, err = wdelayerClientAux.WDelayerSetHermezGovernanceDAOAddress(hermezGovernanceDAOAddressConst)
_, err = wdelayerClientTest.WDelayerClaimGovernance()
require.Nil(t, err)
}
func TestWDelayerGetHermezKeeperAddress(t *testing.T) {
keeperAddress, err := wdelayerClientTest.WDelayerGetHermezKeeperAddress()
func TestWDelayerGetEmergencyCouncil(t *testing.T) {
emergencyCouncil, err := wdelayerClientTest.WDelayerGetEmergencyCouncil()
require.Nil(t, err)
assert.Equal(t, &hermezKeeperAddressConst, keeperAddress)
assert.Equal(t, &emergencyCouncilAddressConst, emergencyCouncil)
}
func TestWDelayerSetHermezKeeperAddress(t *testing.T) {
wdelayerClientKep, err := NewWDelayerClient(ethereumClientKep, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientKep.WDelayerSetHermezKeeperAddress(auxAddressConst)
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetHermezKeeperAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
wdelayerEvents, _, err := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
func TestWDelayerSetEmergencyCouncil(t *testing.T) {
wdelayerClientEmergencyCouncil, err := NewWDelayerClient(ethereumClientEmergencyCouncil, wdelayerTestAddressConst)
require.Nil(t, err)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezKeeperAddress[0].NewHermezKeeperAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientAux.WDelayerSetHermezKeeperAddress(hermezKeeperAddressConst)
require.Nil(t, err)
}
func TestWDelayerGetWhiteHackGroupAddress(t *testing.T) {
whiteHackGroupAddress, err := wdelayerClientTest.WDelayerGetWhiteHackGroupAddress()
require.Nil(t, err)
assert.Equal(t, &whiteHackGroupAddressConst, whiteHackGroupAddress)
}
func TestWDelayerSetWhiteHackGroupAddress(t *testing.T) {
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
_, err = wdelayerClientEmergencyCouncil.WDelayerTransferEmergencyCouncil(auxAddressConst)
require.Nil(t, err)
_, err = wdelayerClientWhite.WDelayerSetWhiteHackGroupAddress(auxAddressConst)
_, err = wdelayerClientAux.WDelayerClaimEmergencyCouncil()
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetWhiteHackGroupAddress()
auxAddress, err := wdelayerClientTest.WDelayerGetEmergencyCouncil()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
wdelayerEvents, _, err := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewWhiteHackGroupAddress[0].NewWhiteHackGroupAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewEmergencyCouncil[0].NewEmergencyCouncil)
_, err = wdelayerClientAux.WDelayerTransferEmergencyCouncil(emergencyCouncilAddressConst)
require.Nil(t, err)
_, err = wdelayerClientAux.WDelayerSetWhiteHackGroupAddress(whiteHackGroupAddressConst)
_, err = wdelayerClientEmergencyCouncil.WDelayerClaimEmergencyCouncil()
require.Nil(t, err)
}
@ -115,9 +94,7 @@ func TestWDelayerGetWithdrawalDelay(t *testing.T) {
}
func TestWDelayerChangeWithdrawalDelay(t *testing.T) {
wdelayerClientKep, err := NewWDelayerClient(ethereumClientKep, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientKep.WDelayerChangeWithdrawalDelay(newWithdrawalDelay.Uint64())
_, err := wdelayerClientTest.WDelayerChangeWithdrawalDelay(newWithdrawalDelay.Uint64())
require.Nil(t, err)
withdrawalDelay, err := wdelayerClientTest.WDelayerGetWithdrawalDelay()
require.Nil(t, err)
@ -188,9 +165,7 @@ func TestWDelayerSecondDeposit(t *testing.T) {
}
func TestWDelayerEnableEmergencyMode(t *testing.T) {
wdelayerClientKep, err := NewWDelayerClient(ethereumClientKep, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientKep.WDelayerEnableEmergencyMode()
_, err := wdelayerClientTest.WDelayerEnableEmergencyMode()
require.Nil(t, err)
emergencyMode, err := wdelayerClientTest.WDelayerIsEmergencyMode()
require.Nil(t, err)
@ -216,13 +191,13 @@ func TestWDelayerGetEmergencyModeStartingTime(t *testing.T) {
func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
amount := new(big.Int)
amount.SetString("10000000000000000", 10)
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
wdelayerClientEmergencyCouncil, err := NewWDelayerClient(ethereumClientEmergencyCouncil, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
_, err = wdelayerClientEmergencyCouncil.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Contains(t, err.Error(), "NO_MAX_EMERGENCY_MODE_TIME")
seconds := maxEmergencyModeTime.Seconds()
addTime(seconds, ethClientDialURL)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
_, err = wdelayerClientEmergencyCouncil.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
@ -230,6 +205,6 @@ func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Token)
assert.Equal(t, governanceAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].To)
assert.Equal(t, whiteHackGroupAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Who)
assert.Equal(t, emergencyCouncilAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Who)
assert.Equal(t, amount, wdelayerEvents.EscapeHatchWithdrawal[0].Amount)
}

+ 15
- 17
test/ethclient.go

@ -292,11 +292,10 @@ func NewClientSetupExample() *ClientSetup {
NLevels: 32,
},
},
TokenHEZ: tokenHEZ,
HermezGovernanceDAOAddress: governanceAddress,
SafetyAddress: ethCommon.HexToAddress("0x84d8B79E84fe87B14ad61A554e740f6736bF4c20"),
HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"),
WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"),
TokenHEZ: tokenHEZ,
HermezGovernanceAddress: governanceAddress,
HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"),
WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"),
}
rollupVariables := &common.RollupVariables{
FeeAddToken: big.NewInt(11),
@ -329,12 +328,11 @@ func NewClientSetupExample() *ClientSetup {
HermezRollup: auctionConstants.HermezRollup,
}
wDelayerVariables := &common.WDelayerVariables{
HermezGovernanceDAOAddress: ethCommon.HexToAddress("0xcfD0d163AE6432a72682323E2C3A5a69e6B37D12"),
WhiteHackGroupAddress: ethCommon.HexToAddress("0x2730700932a4FDB97B9268A3Ca29f97Ea5fd7EA0"),
HermezKeeperAddress: ethCommon.HexToAddress("0x92aAD86176dC0f0046FE85Ed5dA008a828bE3868"),
WithdrawalDelay: 60,
EmergencyModeStartingTime: 0,
EmergencyMode: false,
HermezGovernanceAddress: ethCommon.HexToAddress("0xcfD0d163AE6432a72682323E2C3A5a69e6B37D12"),
EmergencyCouncilAddress: ethCommon.HexToAddress("0x2730700932a4FDB97B9268A3Ca29f97Ea5fd7EA0"),
WithdrawalDelay: 60,
EmergencyModeStartingTime: 0,
EmergencyMode: false,
}
return &ClientSetup{
RollupConstants: rollupConstants,
@ -1061,7 +1059,7 @@ func (c *Client) RollupEventsByBlock(blockNum int64) (*eth.RollupEvents, *ethCom
}
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the Rollup Smart Contract in the given transaction
func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error) {
func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numL1TxUser uint16) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
@ -1220,7 +1218,7 @@ func (c *Client) AuctionGetDonationAddress() (*ethCommon.Address, error) {
}
// AuctionSetBootCoordinator is the interface to call the smart contract function
func (c *Client) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (tx *types.Transaction, err error) {
func (c *Client) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address, newBootCoordinatorURL string) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
@ -1511,8 +1509,8 @@ func (c *Client) AuctionEventsByBlock(blockNum int64) (*eth.AuctionEvents, *ethC
// WDelayer
//
// WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error) {
// WDelayerGetHermezGovernanceAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetHermezGovernanceAddress() (*ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
@ -1520,8 +1518,8 @@ func (c *Client) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, er
return nil, tracerr.Wrap(errTODO)
}
// WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerSetHermezGovernanceAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetHermezGovernanceAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()

Loading…
Cancel
Save