arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #253 from hermeznetwork/feature/api-config-refactor

API config refactor
a_bennassar arnaubennassar5@gmail.com
Wed, 04 Nov 2020 15:09:16 +0100
commit

c4004c08767689a30ec3421a8ae089d9e8828550

parent

11dbf673774cc0bbf03efa5c8318ca6cd7c5a02e

6 files changed, 107 insertions(+), 83 deletions(-)

jump to
M api/api_test.go → api/api_test.go

@@ -26,7 +26,6 @@ "github.com/hermeznetwork/hermez-node/db/statedb"

"github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/test" "github.com/iden3/go-iden3-crypto/babyjub" - "github.com/stretchr/testify/assert" ) const apiPort = ":4010"

@@ -89,48 +88,9 @@ }

// L2DB l2DB := l2db.NewL2DB(database, 10, 100, 24*time.Hour) test.WipeDB(l2DB.DB()) // this will clean HistoryDB and L2DB + // Config (smart contract constants) - config.RollupConstants.ExchangeMultiplier = common.RollupConstExchangeMultiplier - config.RollupConstants.ExitIdx = common.RollupConstExitIDx - config.RollupConstants.ReservedIdx = common.RollupConstReservedIDx - config.RollupConstants.LimitLoadAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10) - config.RollupConstants.LimitL2TransferAmount, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10) - config.RollupConstants.LimitTokens = common.RollupConstLimitTokens - config.RollupConstants.L1CoordinatorTotalBytes = common.RollupConstL1CoordinatorTotalBytes - config.RollupConstants.L1UserTotalBytes = common.RollupConstL1UserTotalBytes - config.RollupConstants.MaxL1UserTx = common.RollupConstMaxL1UserTx - config.RollupConstants.MaxL1Tx = common.RollupConstMaxL1Tx - config.RollupConstants.InputSHAConstantBytes = common.RollupConstInputSHAConstantBytes - config.RollupConstants.NumBuckets = common.RollupConstNumBuckets - config.RollupConstants.MaxWithdrawalDelay = common.RollupConstMaxWithdrawalDelay - var rollupPublicConstants common.RollupConstants - rollupPublicConstants.AbsoluteMaxL1L2BatchTimeout = 240 - rollupPublicConstants.HermezAuctionContract = ethCommon.HexToAddress("0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e") - rollupPublicConstants.HermezGovernanceDAOAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4") - rollupPublicConstants.SafetyAddress = ethCommon.HexToAddress("0xE5904695748fe4A84b40b3fc79De2277660BD1D3") - rollupPublicConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB") - rollupPublicConstants.WithdrawDelayerContract = ethCommon.HexToAddress("0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe") - var verifier common.RollupVerifierStruct - verifier.MaxTx = 512 - verifier.NLevels = 32 - rollupPublicConstants.Verifiers = append(rollupPublicConstants.Verifiers, verifier) - - var auctionConstants common.AuctionConstants - auctionConstants.BlocksPerSlot = 40 - auctionConstants.GenesisBlockNum = 100 - auctionConstants.GovernanceAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4") - auctionConstants.InitialMinimalBidding, _ = new(big.Int).SetString("10000000000000000000", 10) - auctionConstants.HermezRollup = ethCommon.HexToAddress("0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0") - auctionConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB") - - var wdelayerConstants common.WDelayerConstants - wdelayerConstants.HermezRollup = ethCommon.HexToAddress("0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0") - wdelayerConstants.MaxEmergencyModeTime = uint64(1000000) - wdelayerConstants.MaxWithdrawalDelay = uint64(10000000) - - config.RollupConstants.PublicConstants = rollupPublicConstants - config.AuctionConstants = auctionConstants - config.WDelayerConstants = wdelayerConstants + config = getConfigTest() // API api := gin.Default()

@@ -350,14 +310,6 @@ if err := os.RemoveAll(dir); err != nil {

panic(err) } os.Exit(result) -} - -func TestGetConfig(t *testing.T) { - endpoint := apiURL + "config" - var configTest configAPI - assert.NoError(t, doGoodReq("GET", endpoint, nil, &configTest)) - assert.Equal(t, config, configTest) - assert.Equal(t, cg, &configTest) } func doGoodReqPaginated(
A api/config.go

@@ -0,0 +1,37 @@

+package api + +import ( + "math/big" + "net/http" + + "github.com/gin-gonic/gin" + "github.com/hermeznetwork/hermez-node/common" +) + +type rollupConstants struct { + PublicConstants common.RollupConstants `json:"publicConstants"` + MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"` + ReservedIdx int `json:"reservedIdx"` + ExitIdx int `json:"exitIdx"` + LimitLoadAmount *big.Int `json:"limitLoadAmount"` + LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"` + LimitTokens int `json:"limitTokens"` + L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"` + L1UserTotalBytes int `json:"l1UserTotalBytes"` + MaxL1UserTx int `json:"maxL1UserTx"` + MaxL1Tx int `json:"maxL1Tx"` + InputSHAConstantBytes int `json:"inputSHAConstantBytes"` + NumBuckets int `json:"numBuckets"` + MaxWithdrawalDelay int `json:"maxWithdrawalDelay"` + ExchangeMultiplier int `json:"exchangeMultiplier"` +} + +type configAPI struct { + RollupConstants rollupConstants `json:"hermez"` + AuctionConstants common.AuctionConstants `json:"auction"` + WDelayerConstants common.WDelayerConstants `json:"withdrawalDelayer"` +} + +func getConfig(c *gin.Context) { + c.JSON(http.StatusOK, cg) +}
A api/config_test.go

@@ -0,0 +1,66 @@

+package api + +import ( + "math/big" + "testing" + + ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/hermez-node/common" + "github.com/stretchr/testify/assert" +) + +func getConfigTest() configAPI { + var config configAPI + + config.RollupConstants.ExchangeMultiplier = common.RollupConstExchangeMultiplier + config.RollupConstants.ExitIdx = common.RollupConstExitIDx + config.RollupConstants.ReservedIdx = common.RollupConstReservedIDx + config.RollupConstants.LimitLoadAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10) + config.RollupConstants.LimitL2TransferAmount, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10) + config.RollupConstants.LimitTokens = common.RollupConstLimitTokens + config.RollupConstants.L1CoordinatorTotalBytes = common.RollupConstL1CoordinatorTotalBytes + config.RollupConstants.L1UserTotalBytes = common.RollupConstL1UserTotalBytes + config.RollupConstants.MaxL1UserTx = common.RollupConstMaxL1UserTx + config.RollupConstants.MaxL1Tx = common.RollupConstMaxL1Tx + config.RollupConstants.InputSHAConstantBytes = common.RollupConstInputSHAConstantBytes + config.RollupConstants.NumBuckets = common.RollupConstNumBuckets + config.RollupConstants.MaxWithdrawalDelay = common.RollupConstMaxWithdrawalDelay + var rollupPublicConstants common.RollupConstants + rollupPublicConstants.AbsoluteMaxL1L2BatchTimeout = 240 + rollupPublicConstants.HermezAuctionContract = ethCommon.HexToAddress("0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e") + rollupPublicConstants.HermezGovernanceDAOAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4") + rollupPublicConstants.SafetyAddress = ethCommon.HexToAddress("0xE5904695748fe4A84b40b3fc79De2277660BD1D3") + rollupPublicConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB") + rollupPublicConstants.WithdrawDelayerContract = ethCommon.HexToAddress("0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe") + var verifier common.RollupVerifierStruct + verifier.MaxTx = 512 + verifier.NLevels = 32 + rollupPublicConstants.Verifiers = append(rollupPublicConstants.Verifiers, verifier) + + var auctionConstants common.AuctionConstants + auctionConstants.BlocksPerSlot = 40 + auctionConstants.GenesisBlockNum = 100 + auctionConstants.GovernanceAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4") + auctionConstants.InitialMinimalBidding, _ = new(big.Int).SetString("10000000000000000000", 10) + auctionConstants.HermezRollup = ethCommon.HexToAddress("0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0") + auctionConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB") + + var wdelayerConstants common.WDelayerConstants + wdelayerConstants.HermezRollup = ethCommon.HexToAddress("0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0") + wdelayerConstants.MaxEmergencyModeTime = uint64(1000000) + wdelayerConstants.MaxWithdrawalDelay = uint64(10000000) + + config.RollupConstants.PublicConstants = rollupPublicConstants + config.AuctionConstants = auctionConstants + config.WDelayerConstants = wdelayerConstants + + return config +} + +func TestGetConfig(t *testing.T) { + endpoint := apiURL + "config" + var configTest configAPI + assert.NoError(t, doGoodReq("GET", endpoint, nil, &configTest)) + assert.Equal(t, config, configTest) + assert.Equal(t, cg, &configTest) +}
M api/dbtoapistructs.go → api/dbtoapistructs.go

@@ -2,7 +2,6 @@ package api

import ( "encoding/base64" - "math/big" "strconv" ethCommon "github.com/ethereum/go-ethereum/common"

@@ -36,29 +35,3 @@ return exitIdx

} return "hez:" + tokenSymbol + ":" + strconv.Itoa(int(idx)) } - -// Config - -type rollupConstants struct { - PublicConstants common.RollupConstants `json:"publicConstants"` - MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"` - ReservedIdx int `json:"reservedIdx"` - ExitIdx int `json:"exitIdx"` - LimitLoadAmount *big.Int `json:"limitLoadAmount"` - LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"` - LimitTokens int `json:"limitTokens"` - L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"` - L1UserTotalBytes int `json:"l1UserTotalBytes"` - MaxL1UserTx int `json:"maxL1UserTx"` - MaxL1Tx int `json:"maxL1Tx"` - InputSHAConstantBytes int `json:"inputSHAConstantBytes"` - NumBuckets int `json:"numBuckets"` - MaxWithdrawalDelay int `json:"maxWithdrawalDelay"` - ExchangeMultiplier int `json:"exchangeMultiplier"` -} - -type configAPI struct { - RollupConstants rollupConstants `json:"hermez"` - AuctionConstants common.AuctionConstants `json:"auction"` - WDelayerConstants common.WDelayerConstants `json:"withdrawalDelayer"` -}
M api/handlers.go → api/handlers.go

@@ -48,10 +48,6 @@ func getState(c *gin.Context) {

} -func getConfig(c *gin.Context) { - c.JSON(http.StatusOK, cg) -} - func getRecommendedFee(c *gin.Context) { }
M api/swagger.yml → api/swagger.yml

@@ -889,7 +889,7 @@ get:

tags: - Hermez status summary: Get a list of bids made for a specific slot auction. - description: Get a list of bids made for a specific slot auction. + description: Get a list of bids made for a specific slot auction. Is necessary to add a filter (`slotNum` or `bidderAddr`). operationId: getSlotBids parameters: - name: slotNum

@@ -900,7 +900,7 @@ schema:

$ref: '#/components/schemas/SlotNum' - name: bidderAddr in: query - description: Get only bids made by a coordinator identified by its bidder address. + description: Get only bids made by a coordinator identified by its bidder address. In this case, the bids will be returned in the order that the coordinator made them. required: false schema: $ref: '#/components/schemas/EthereumAddress'