From eed5b3e85fd951f6b0cd6136903dd55014a8953c Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Thu, 26 Dec 2024 16:55:40 +0900 Subject: [PATCH] Make feeEstimateToV0_7 private --- rpc/estimate_fee.go | 6 ++--- rpc/estimate_fee_pkg_test.go | 43 ++++++++++++++++++++++++++++++++++++ rpc/estimate_fee_test.go | 35 ----------------------------- 3 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 rpc/estimate_fee_pkg_test.go diff --git a/rpc/estimate_fee.go b/rpc/estimate_fee.go index 5533c77041..5923703dd8 100644 --- a/rpc/estimate_fee.go +++ b/rpc/estimate_fee.go @@ -52,7 +52,7 @@ type FeeEstimate struct { Estimate Fee Handlers *****************************************************/ -func FeeEstimateToV0_7(feeEstimate FeeEstimate) FeeEstimateV0_7 { +func feeEstimateToV0_7(feeEstimate FeeEstimate) FeeEstimateV0_7 { return FeeEstimateV0_7{ GasConsumed: feeEstimate.L1GasConsumed, GasPrice: feeEstimate.L1GasPrice, @@ -72,7 +72,7 @@ func (h *Handler) EstimateFeeV0_7(broadcastedTxns []BroadcastedTransaction, } return utils.Map(result, func(tx SimulatedTransaction) FeeEstimateV0_7 { - return FeeEstimateToV0_7(tx.FeeEstimation) + return feeEstimateToV0_7(tx.FeeEstimation) }), httpHeader, nil } @@ -95,7 +95,7 @@ func (h *Handler) EstimateMessageFeeV0_7(msg MsgFromL1, id BlockID) (*FeeEstimat if err != nil { return nil, header, err } - estimateV0_7 := FeeEstimateToV0_7(*estimate) + estimateV0_7 := feeEstimateToV0_7(*estimate) return &estimateV0_7, header, nil } diff --git a/rpc/estimate_fee_pkg_test.go b/rpc/estimate_fee_pkg_test.go new file mode 100644 index 0000000000..43530e545a --- /dev/null +++ b/rpc/estimate_fee_pkg_test.go @@ -0,0 +1,43 @@ +package rpc + +import ( + "testing" + + "github.com/NethermindEth/juno/core/felt" + "github.com/stretchr/testify/assert" +) + +func TestFeeEstimateToV0_7(t *testing.T) { + t.Run("empty", func(t *testing.T) { + assert.Equal(t, FeeEstimateV0_7{}, feeEstimateToV0_7(FeeEstimate{})) + }) + + t.Run("full", func(t *testing.T) { + gasConsumed := new(felt.Felt).SetUint64(1) + gasPrice := new(felt.Felt).SetUint64(2) + dataGasConsumed := new(felt.Felt).SetUint64(3) + dataGasPrice := new(felt.Felt).SetUint64(4) + overallFee := new(felt.Felt).SetUint64(5) + unit := WEI + assert.Equal( + t, + FeeEstimateV0_7{ + GasConsumed: gasConsumed, + GasPrice: gasPrice, + DataGasConsumed: dataGasConsumed, + DataGasPrice: dataGasPrice, + OverallFee: overallFee, + Unit: &unit, + }, + feeEstimateToV0_7(FeeEstimate{ + L1GasConsumed: gasConsumed, + L1GasPrice: gasPrice, + L2GasConsumed: new(felt.Felt).SetUint64(6), + L2GasPrice: new(felt.Felt).SetUint64(7), + L1DataGasConsumed: dataGasConsumed, + L1DataGasPrice: dataGasPrice, + OverallFee: overallFee, + Unit: &unit, + })) + }) +} diff --git a/rpc/estimate_fee_test.go b/rpc/estimate_fee_test.go index 09589af693..c1ade1b8cf 100644 --- a/rpc/estimate_fee_test.go +++ b/rpc/estimate_fee_test.go @@ -164,38 +164,3 @@ func assertEqualCairo1Class(t *testing.T, cairo1Class *core.Cairo1Class, class * assert.Equal(t, cairo1Class.EntryPoints.External[idx].Selector, class.EntryPoints.External[idx].Selector) } } - -func TestFeeEstimateToV0_7(t *testing.T) { - t.Run("empty", func(t *testing.T) { - assert.Equal(t, rpc.FeeEstimateV0_7{}, rpc.FeeEstimateToV0_7(rpc.FeeEstimate{})) - }) - - t.Run("full", func(t *testing.T) { - gasConsumed := new(felt.Felt).SetUint64(1) - gasPrice := new(felt.Felt).SetUint64(2) - dataGasConsumed := new(felt.Felt).SetUint64(3) - dataGasPrice := new(felt.Felt).SetUint64(4) - overallFee := new(felt.Felt).SetUint64(5) - unit := rpc.WEI - assert.Equal( - t, - rpc.FeeEstimateV0_7{ - GasConsumed: gasConsumed, - GasPrice: gasPrice, - DataGasConsumed: dataGasConsumed, - DataGasPrice: dataGasPrice, - OverallFee: overallFee, - Unit: &unit, - }, - rpc.FeeEstimateToV0_7(rpc.FeeEstimate{ - L1GasConsumed: gasConsumed, - L1GasPrice: gasPrice, - L2GasConsumed: new(felt.Felt).SetUint64(6), - L2GasPrice: new(felt.Felt).SetUint64(7), - L1DataGasConsumed: dataGasConsumed, - L1DataGasPrice: dataGasPrice, - OverallFee: overallFee, - Unit: &unit, - })) - }) -}