Skip to content

Commit

Permalink
chore: Update EstimateFee and EstimateMessageFee to use FeeEstimation…
Browse files Browse the repository at this point in the history
… instead of FeeEstimate
  • Loading branch information
thiagodeev committed Sep 2, 2024
1 parent 9adb94f commit a3e8d71
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,9 @@ func (account *Account) ClassHashAt(ctx context.Context, blockID rpc.BlockID, co
// - requests: An array of rpc.BroadcastTxn objects representing the requests to estimate the fee for.
// - blockID: The rpc.BlockID object representing the block ID for which to estimate the fee.
// Returns:
// - []rpc.FeeEstimate: An array of rpc.FeeEstimate objects representing the estimated fees.
// - []rpc.FeeEstimation: An array of rpc.FeeEstimation objects representing the estimated fees.
// - error: An error object if any error occurred during the estimation process.
func (account *Account) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimate, error) {
func (account *Account) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimation, error) {
return account.provider.EstimateFee(ctx, requests, simulationFlags, blockID)
}

Expand All @@ -695,9 +695,9 @@ func (account *Account) EstimateFee(ctx context.Context, requests []rpc.Broadcas
// - msg: The rpc.MsgFromL1 object representing the message.
// - blockID: The rpc.BlockID object representing the block ID.
// Returns:
// - *rpc.FeeEstimate: a pointer to rpc.FeeEstimate
// - *rpc.FeeEstimation: a pointer to rpc.FeeEstimation
// - error: an error if any.
func (account *Account) EstimateMessageFee(ctx context.Context, msg rpc.MsgFromL1, blockID rpc.BlockID) (*rpc.FeeEstimate, error) {
func (account *Account) EstimateMessageFee(ctx context.Context, msg rpc.MsgFromL1, blockID rpc.BlockID) (*rpc.FeeEstimation, error) {
return account.provider.EstimateMessageFee(ctx, msg, blockID)
}

Expand Down
8 changes: 4 additions & 4 deletions mocks/mock_rpc_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAd
// Estimates the resources required by a given sequence of transactions when applied on a given state.
// If one of the transactions reverts or fails due to any reason (e.g. validation failure or an internal error),
// a TRANSACTION_EXECUTION_ERROR is returned. For v0-2 transactions the estimate is given in wei, and for v3 transactions it is given in fri.
func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimate, error) {
var raw []FeeEstimate
func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error) {
var raw []FeeEstimation
if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, simulationFlags, blockID); err != nil {
return nil, tryUnwrapToRPCErr(err, ErrTxnExec, ErrBlockNotFound)
}
Expand All @@ -150,10 +150,10 @@ func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastT
// - msg: The message to estimate the fee for
// - blockID: The ID of the block to estimate the fee in
// Returns:
// - *FeeEstimate: the fee estimated for the message
// - *FeeEstimation: the fee estimated for the message
// - error: an error if any occurred during the execution
func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimate, error) {
var raw FeeEstimate
func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error) {
var raw FeeEstimation
if err := do(ctx, provider.c, "starknet_estimateMessageFee", &raw, msg, blockID); err != nil {

return nil, tryUnwrapToRPCErr(err, ErrContractError, ErrBlockNotFound)
Expand Down
20 changes: 10 additions & 10 deletions rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func TestEstimateMessageFee(t *testing.T) {
type testSetType struct {
MsgFromL1
BlockID
ExpectedFeeEst *FeeEstimate
ExpectedFeeEst *FeeEstimation
ExpectedError error
}

Expand All @@ -425,7 +425,7 @@ func TestEstimateMessageFee(t *testing.T) {
{
MsgFromL1: MsgFromL1{FromAddress: "0x0", ToAddress: &felt.Zero, Selector: &felt.Zero, Payload: []*felt.Felt{&felt.Zero}},
BlockID: BlockID{Tag: "latest"},
ExpectedFeeEst: &FeeEstimate{
ExpectedFeeEst: &FeeEstimation{
GasConsumed: new(felt.Felt).SetUint64(1),
GasPrice: new(felt.Felt).SetUint64(2),
OverallFee: new(felt.Felt).SetUint64(3),
Expand All @@ -436,7 +436,7 @@ func TestEstimateMessageFee(t *testing.T) {
{
MsgFromL1: l1Handler,
BlockID: WithBlockNumber(122476),
ExpectedFeeEst: &FeeEstimate{
ExpectedFeeEst: &FeeEstimation{
GasConsumed: utils.TestHexToFelt(t, "0x567b"),
GasPrice: utils.TestHexToFelt(t, "0x28fb3be9e"),
DataGasConsumed: &felt.Zero,
Expand Down Expand Up @@ -481,7 +481,7 @@ func TestEstimateFee(t *testing.T) {
txs []BroadcastTxn
simFlags []SimulationFlag
blockID BlockID
expectedResp []FeeEstimate
expectedResp []FeeEstimation
expectedError error
}

Expand Down Expand Up @@ -523,7 +523,7 @@ func TestEstimateFee(t *testing.T) {
simFlags: []SimulationFlag{},
blockID: WithBlockNumber(15643),
expectedError: nil,
expectedResp: []FeeEstimate{
expectedResp: []FeeEstimation{
{
GasConsumed: utils.TestHexToFelt(t, "0x3074"),
GasPrice: utils.TestHexToFelt(t, "0x350da9915"),
Expand Down Expand Up @@ -560,7 +560,7 @@ func TestEstimateFee(t *testing.T) {
simFlags: []SimulationFlag{},
blockID: WithBlockHash(utils.TestHexToFelt(t, "0x1b0df1bafcb826b1fc053495aef5cdc24d0345cbfa1259b15939d01b89dc6d9")),
expectedError: nil,
expectedResp: []FeeEstimate{
expectedResp: []FeeEstimation{
{
GasConsumed: utils.TestHexToFelt(t, "0x1154"),
GasPrice: utils.TestHexToFelt(t, "0x378f962c4"),
Expand All @@ -580,7 +580,7 @@ func TestEstimateFee(t *testing.T) {
simFlags: []SimulationFlag{},
blockID: WithBlockTag("latest"),
expectedError: nil,
expectedResp: []FeeEstimate{
expectedResp: []FeeEstimation{
{
GasConsumed: utils.RANDOM_FELT,
GasPrice: utils.RANDOM_FELT,
Expand All @@ -598,7 +598,7 @@ func TestEstimateFee(t *testing.T) {
simFlags: []SimulationFlag{SKIP_VALIDATE},
blockID: WithBlockTag("latest"),
expectedError: nil,
expectedResp: []FeeEstimate{
expectedResp: []FeeEstimation{
{
GasConsumed: new(felt.Felt).SetUint64(1234),
GasPrice: new(felt.Felt).SetUint64(1234),
Expand All @@ -618,7 +618,7 @@ func TestEstimateFee(t *testing.T) {
simFlags: []SimulationFlag{},
blockID: WithBlockNumber(100000),
expectedError: nil,
expectedResp: []FeeEstimate{
expectedResp: []FeeEstimation{
{
GasConsumed: utils.TestHexToFelt(t, "0x123c"),
GasPrice: utils.TestHexToFelt(t, "0x831211d3b"),
Expand All @@ -636,7 +636,7 @@ func TestEstimateFee(t *testing.T) {
simFlags: []SimulationFlag{SKIP_VALIDATE},
blockID: WithBlockNumber(100000),
expectedError: nil,
expectedResp: []FeeEstimate{
expectedResp: []FeeEstimation{
{
GasConsumed: utils.TestHexToFelt(t, "0x1239"),
GasPrice: utils.TestHexToFelt(t, "0x831211d3b"),
Expand Down
10 changes: 5 additions & 5 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ func mock_starknet_estimateFee(result interface{}, args ...interface{}) error {
return errWrongArgs
}

var output FeeEstimate
var output FeeEstimation

if len(flags) > 0 {
output = FeeEstimate{
output = FeeEstimation{
GasConsumed: new(felt.Felt).SetUint64(1234),
GasPrice: new(felt.Felt).SetUint64(1234),
DataGasConsumed: new(felt.Felt).SetUint64(1234),
Expand All @@ -690,7 +690,7 @@ func mock_starknet_estimateFee(result interface{}, args ...interface{}) error {
FeeUnit: UnitWei,
}
} else {
output = FeeEstimate{
output = FeeEstimation{
GasConsumed: utils.RANDOM_FELT,
GasPrice: utils.RANDOM_FELT,
DataGasConsumed: utils.RANDOM_FELT,
Expand All @@ -700,7 +700,7 @@ func mock_starknet_estimateFee(result interface{}, args ...interface{}) error {
}
}

outputContent, err := json.Marshal([]FeeEstimate{output})
outputContent, err := json.Marshal([]FeeEstimation{output})
if err != nil {
return err
}
Expand Down Expand Up @@ -737,7 +737,7 @@ func mock_starknet_estimateMessageFee(result interface{}, args ...interface{}) e
return errWrongArgs
}

output := FeeEstimate{
output := FeeEstimation{
GasConsumed: new(felt.Felt).SetUint64(1),
GasPrice: new(felt.Felt).SetUint64(2),
OverallFee: new(felt.Felt).SetUint64(3),
Expand Down
4 changes: 2 additions & 2 deletions rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type RpcProvider interface {
Class(ctx context.Context, blockID BlockID, classHash *felt.Felt) (ClassOutput, error)
ClassAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (ClassOutput, error)
ClassHashAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error)
EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimate, error)
EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimate, error)
EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error)
EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error)
Events(ctx context.Context, input EventsInput) (*EventChunk, error)
BlockWithReceipts(ctx context.Context, blockID BlockID) (interface{}, error)
GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error)
Expand Down
2 changes: 1 addition & 1 deletion rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestSimulateTransaction(t *testing.T) {
require.NoError(t, err)

for i, trace := range resp {
require.Equal(t, test.ExpectedResp.Txns[i].FeeEstimate, trace.FeeEstimate)
require.Equal(t, test.ExpectedResp.Txns[i].FeeEstimation, trace.FeeEstimation)
compareTraceTxs(t, test.ExpectedResp.Txns[i].TxnTrace, trace.TxnTrace)
}
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ type TxDetails struct {
Version TransactionVersion
}

type FeeEstimate struct {
type FeeEstimation struct {
// The Ethereum gas consumption of the transaction
GasConsumed *felt.Felt `json:"gas_consumed"`

Expand Down
14 changes: 7 additions & 7 deletions rpc/types_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type SimulateTransactionOutput struct {
}

type SimulatedTransaction struct {
TxnTrace `json:"transaction_trace"`
FeeEstimate `json:"fee_estimation"`
TxnTrace `json:"transaction_trace"`
FeeEstimation `json:"fee_estimation"`
}

type TxnTrace interface{}
Expand Down Expand Up @@ -163,10 +163,10 @@ func (txn *SimulatedTransaction) UnmarshalJSON(data []byte) error {
return err
}

var feeEstimate FeeEstimate
var feeEstimation FeeEstimation

if feeEstimateData, ok := dec["fee_estimation"]; ok {
err = remarshal(feeEstimateData, &feeEstimate)
if feeEstimationData, ok := dec["fee_estimation"]; ok {
err = remarshal(feeEstimationData, &feeEstimation)
if err != nil {
return err
}
Expand All @@ -175,8 +175,8 @@ func (txn *SimulatedTransaction) UnmarshalJSON(data []byte) error {
}

*txn = SimulatedTransaction{
TxnTrace: trace,
FeeEstimate: feeEstimate,
TxnTrace: trace,
FeeEstimation: feeEstimation,
}
return nil
}
Expand Down

0 comments on commit a3e8d71

Please sign in to comment.