Skip to content

Commit

Permalink
Make feeEstimateToV0_7 private
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Dec 26, 2024
1 parent d53108a commit eed5b3e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
6 changes: 3 additions & 3 deletions rpc/estimate_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
43 changes: 43 additions & 0 deletions rpc/estimate_fee_pkg_test.go
Original file line number Diff line number Diff line change
@@ -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,
}))
})
}
35 changes: 0 additions & 35 deletions rpc/estimate_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
})
}

0 comments on commit eed5b3e

Please sign in to comment.