Skip to content

Commit

Permalink
Add FeeEstimateToV0_7 and TestFeeEstimateToV0_7
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Dec 22, 2024
1 parent ac78762 commit 49278bf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
20 changes: 12 additions & 8 deletions rpc/estimate_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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

Check warning on line 76 in rpc/estimate_fee.go

View check run for this annotation

Codecov / codecov/patch

rpc/estimate_fee.go#L75-L76

Added lines #L75 - L76 were not covered by tests
}

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

0 comments on commit 49278bf

Please sign in to comment.