From a3e8d71fdda900bab98118876de7170c331ffe74 Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Mon, 2 Sep 2024 00:21:38 -0300 Subject: [PATCH] chore: Update EstimateFee and EstimateMessageFee to use FeeEstimation instead of FeeEstimate --- account/account.go | 8 ++++---- mocks/mock_rpc_provider.go | 8 ++++---- rpc/contract.go | 10 +++++----- rpc/contract_test.go | 20 ++++++++++---------- rpc/mock_test.go | 10 +++++----- rpc/provider.go | 4 ++-- rpc/trace_test.go | 2 +- rpc/types.go | 2 +- rpc/types_trace.go | 14 +++++++------- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/account/account.go b/account/account.go index fac716f4..763e28a9 100644 --- a/account/account.go +++ b/account/account.go @@ -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) } @@ -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) } diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index a7b3bf1c..6e86bf39 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -252,10 +252,10 @@ func (mr *MockRpcProviderMockRecorder) ClassHashAt(ctx, blockID, contractAddress } // EstimateFee mocks base method. -func (m *MockRpcProvider) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimate, error) { +func (m *MockRpcProvider) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimation, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EstimateFee", ctx, requests, simulationFlags, blockID) - ret0, _ := ret[0].([]rpc.FeeEstimate) + ret0, _ := ret[0].([]rpc.FeeEstimation) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -267,10 +267,10 @@ func (mr *MockRpcProviderMockRecorder) EstimateFee(ctx, requests, simulationFlag } // EstimateMessageFee mocks base method. -func (m *MockRpcProvider) EstimateMessageFee(ctx context.Context, msg rpc.MsgFromL1, blockID rpc.BlockID) (*rpc.FeeEstimate, error) { +func (m *MockRpcProvider) EstimateMessageFee(ctx context.Context, msg rpc.MsgFromL1, blockID rpc.BlockID) (*rpc.FeeEstimation, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EstimateMessageFee", ctx, msg, blockID) - ret0, _ := ret[0].(*rpc.FeeEstimate) + ret0, _ := ret[0].(*rpc.FeeEstimation) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/rpc/contract.go b/rpc/contract.go index 1f5dab02..8dcbe64e 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -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) } @@ -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) diff --git a/rpc/contract_test.go b/rpc/contract_test.go index 9ab0cb14..5b621e5c 100644 --- a/rpc/contract_test.go +++ b/rpc/contract_test.go @@ -402,7 +402,7 @@ func TestEstimateMessageFee(t *testing.T) { type testSetType struct { MsgFromL1 BlockID - ExpectedFeeEst *FeeEstimate + ExpectedFeeEst *FeeEstimation ExpectedError error } @@ -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), @@ -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, @@ -481,7 +481,7 @@ func TestEstimateFee(t *testing.T) { txs []BroadcastTxn simFlags []SimulationFlag blockID BlockID - expectedResp []FeeEstimate + expectedResp []FeeEstimation expectedError error } @@ -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"), @@ -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"), @@ -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, @@ -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), @@ -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"), @@ -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"), diff --git a/rpc/mock_test.go b/rpc/mock_test.go index e98bf261..cee0a729 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -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), @@ -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, @@ -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 } @@ -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), diff --git a/rpc/provider.go b/rpc/provider.go index 0aba9393..f7a5e53a 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -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) diff --git a/rpc/trace_test.go b/rpc/trace_test.go index 4707be40..9b6f2a69 100644 --- a/rpc/trace_test.go +++ b/rpc/trace_test.go @@ -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) } } diff --git a/rpc/types.go b/rpc/types.go index 4287b281..9634ea66 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -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"` diff --git a/rpc/types_trace.go b/rpc/types_trace.go index 5004a7aa..bc44af08 100644 --- a/rpc/types_trace.go +++ b/rpc/types_trace.go @@ -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{} @@ -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 } @@ -175,8 +175,8 @@ func (txn *SimulatedTransaction) UnmarshalJSON(data []byte) error { } *txn = SimulatedTransaction{ - TxnTrace: trace, - FeeEstimate: feeEstimate, + TxnTrace: trace, + FeeEstimation: feeEstimation, } return nil }