Browse Source

fixed rollup event parsing

refactore/rollupUpdateBuckets
Mikelle 3 years ago
parent
commit
aa1f0a2618
2 changed files with 22 additions and 12 deletions
  1. +13
    -10
      eth/rollup.go
  2. +9
    -2
      eth/rollup_test.go

+ 13
- 10
eth/rollup.go

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"math/big" "math/big"
"strconv"
"strings" "strings"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
@ -157,7 +156,7 @@ type RollupUpdateBucketsParameters struct {
} }
type rollupEventUpdateBucketsParametersAux struct { type rollupEventUpdateBucketsParametersAux struct {
ArrayBuckets [common.RollupConstNumBuckets][6]*big.Int
ArrayBuckets []*big.Int
} }
// RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract // RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract
@ -613,7 +612,7 @@ func (c *RollupClient) RollupUpdateBucketsParameters(
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
12500000, //nolint:gomnd 12500000, //nolint:gomnd
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
params := []*big.Int{}
params := make([]*big.Int, len(arrayBuckets))
for i, bucket := range arrayBuckets { for i, bucket := range arrayBuckets {
params[i], err = c.hermez.PackBucket(c.opts, bucket.CeilUSD, bucket.BlockStamp, bucket.Withdrawals, bucket.RateBlocks, bucket.RateWithdrawals, bucket.MaxWithdrawals) params[i], err = c.hermez.PackBucket(c.opts, bucket.CeilUSD, bucket.BlockStamp, bucket.Withdrawals, bucket.RateBlocks, bucket.RateWithdrawals, bucket.MaxWithdrawals)
if err != nil { if err != nil {
@ -743,7 +742,7 @@ var (
logHermezUpdateWithdrawalDelay = crypto.Keccak256Hash([]byte( logHermezUpdateWithdrawalDelay = crypto.Keccak256Hash([]byte(
"UpdateWithdrawalDelay(uint64)")) "UpdateWithdrawalDelay(uint64)"))
logHermezUpdateBucketsParameters = crypto.Keccak256Hash([]byte( logHermezUpdateBucketsParameters = crypto.Keccak256Hash([]byte(
"UpdateBucketsParameters(uint256[4][" + strconv.Itoa(common.RollupConstNumBuckets) + "])"))
"UpdateBucketsParameters(uint256[])"))
logHermezUpdateTokenExchange = crypto.Keccak256Hash([]byte( logHermezUpdateTokenExchange = crypto.Keccak256Hash([]byte(
"UpdateTokenExchange(address[],uint64[])")) "UpdateTokenExchange(address[],uint64[])"))
logHermezSafeMode = crypto.Keccak256Hash([]byte( logHermezSafeMode = crypto.Keccak256Hash([]byte(
@ -911,12 +910,16 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64,
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
for i, bucket := range bucketsParametersAux.ArrayBuckets { for i, bucket := range bucketsParametersAux.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0]
bucketsParameters.ArrayBuckets[i].BlockStamp = bucket[1]
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[2]
bucketsParameters.ArrayBuckets[i].RateBlocks = bucket[3]
bucketsParameters.ArrayBuckets[i].RateWithdrawals = bucket[4]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[5]
bucket, err := c.hermez.UnpackBucket(c.opts, bucket)
if err != nil {
return nil, tracerr.Wrap(err)
}
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket.CeilUSD
bucketsParameters.ArrayBuckets[i].BlockStamp = bucket.BlockStamp
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket.Withdrawals
bucketsParameters.ArrayBuckets[i].RateBlocks = bucket.RateBlocks
bucketsParameters.ArrayBuckets[i].RateWithdrawals = bucket.RateWithdrawals
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket.MaxWithdrawals
} }
rollupEvents.UpdateBucketsParameters = rollupEvents.UpdateBucketsParameters =
append(rollupEvents.UpdateBucketsParameters, bucketsParameters) append(rollupEvents.UpdateBucketsParameters, bucketsParameters)

+ 9
- 2
eth/rollup_test.go

@ -241,7 +241,7 @@ func TestRollupUpdateBucketsParameters(t *testing.T) {
bucketsParameters[i].Withdrawals = big.NewInt(int64(i + 1)) bucketsParameters[i].Withdrawals = big.NewInt(int64(i + 1))
bucketsParameters[i].RateBlocks = big.NewInt(int64(i+1) * 4) bucketsParameters[i].RateBlocks = big.NewInt(int64(i+1) * 4)
bucketsParameters[i].RateWithdrawals = big.NewInt(int64(3)) bucketsParameters[i].RateWithdrawals = big.NewInt(int64(3))
bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(100000000000))
bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(1215752192))
} }
_, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters) _, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters)
require.NoError(t, err) require.NoError(t, err)
@ -250,7 +250,14 @@ func TestRollupUpdateBucketsParameters(t *testing.T) {
blockStampBucket = currentBlockNum blockStampBucket = currentBlockNum
rollupEvents, err := rollupClient.RollupEventsByBlock(currentBlockNum, nil) rollupEvents, err := rollupClient.RollupEventsByBlock(currentBlockNum, nil)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, bucketsParameters, rollupEvents.UpdateBucketsParameters[0].ArrayBuckets)
for i := range bucketsParameters {
assert.Equal(t, 0, bucketsParameters[i].CeilUSD.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].CeilUSD))
assert.Equal(t, 0, bucketsParameters[i].BlockStamp.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].BlockStamp))
assert.Equal(t, 0, bucketsParameters[i].Withdrawals.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].Withdrawals))
assert.Equal(t, 0, bucketsParameters[i].RateBlocks.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].RateBlocks))
assert.Equal(t, 0, bucketsParameters[i].RateWithdrawals.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].RateWithdrawals))
assert.Equal(t, 0, bucketsParameters[i].MaxWithdrawals.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].MaxWithdrawals))
}
} }
func TestRollupUpdateWithdrawalDelay(t *testing.T) { func TestRollupUpdateWithdrawalDelay(t *testing.T) {

Loading…
Cancel
Save