diff --git a/rpc/estimate_fee.go b/rpc/estimate_fee.go index e76746bf7..96be64ed1 100644 --- a/rpc/estimate_fee.go +++ b/rpc/estimate_fee.go @@ -52,6 +52,17 @@ type FeeEstimate struct { Estimate Fee Handlers *****************************************************/ +func FeeEstimateToV0_7(feeEstimate FeeEstimate) FeeEstimateV0_7 { + return FeeEstimateV0_7{ + GasConsumed: feeEstimate.L1GasConsumed, + GasPrice: feeEstimate.L1GasPrice, + DataGasConsumed: feeEstimate.L1DataGasConsumed, + DataGasPrice: feeEstimate.L1DataGasPrice, + OverallFee: feeEstimate.OverallFee, + Unit: feeEstimate.Unit, + } +} + func (h *Handler) EstimateFeeV0_7(broadcastedTxns []BroadcastedTransaction, simulationFlags []SimulationFlag, id BlockID, ) ([]FeeEstimateV0_7, http.Header, *jsonrpc.Error) { @@ -61,14 +72,7 @@ func (h *Handler) EstimateFeeV0_7(broadcastedTxns []BroadcastedTransaction, } return utils.Map(result, func(tx SimulatedTransaction) FeeEstimateV0_7 { - return FeeEstimateV0_7{ - GasConsumed: tx.FeeEstimation.L1GasConsumed, - GasPrice: tx.FeeEstimation.L1GasPrice, - DataGasConsumed: tx.FeeEstimation.L1DataGasConsumed, - DataGasPrice: tx.FeeEstimation.L1DataGasPrice, - OverallFee: tx.FeeEstimation.OverallFee, - Unit: tx.FeeEstimation.Unit, - } + return FeeEstimateToV0_7(tx.FeeEstimation) }), httpHeader, nil } diff --git a/rpc/estimate_fee_test.go b/rpc/estimate_fee_test.go index c1ade1b8c..09589af69 100644 --- a/rpc/estimate_fee_test.go +++ b/rpc/estimate_fee_test.go @@ -164,3 +164,38 @@ 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, + })) + }) +}