diff --git a/account/account.go b/account/account.go index 56c7c623..2c63d82d 100644 --- a/account/account.go +++ b/account/account.go @@ -712,8 +712,8 @@ func (account *Account) ClassHashAt(ctx context.Context, blockID rpc.BlockID, co // Returns: // - []rpc.FeeEstimate: An array of rpc.FeeEstimate 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, simulationFlag rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimate, error) { - return account.provider.EstimateFee(ctx, requests, simulationFlag, blockID) +func (account *Account) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimate, error) { + return account.provider.EstimateFee(ctx, requests, simulationFlags, blockID) } // EstimateMessageFee estimates the fee for a given message in the context of an account. diff --git a/mocks/mock_account.go b/mocks/mock_account.go index 04a9ddd5..5107db17 100644 --- a/mocks/mock_account.go +++ b/mocks/mock_account.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: account/account.go - +// Source: account.go +// +// Generated by this command: +// +// mockgen -destination=../mocks/mock_account.go -package=mocks -source=account.go AccountInterface +// // Package mocks is a generated GoMock package. package mocks @@ -47,7 +51,7 @@ func (m *MockAccountInterface) PrecomputeAddress(deployerAddress, salt, classHas } // PrecomputeAddress indicates an expected call of PrecomputeAddress. -func (mr *MockAccountInterfaceMockRecorder) PrecomputeAddress(deployerAddress, salt, classHash, constructorCalldata interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) PrecomputeAddress(deployerAddress, salt, classHash, constructorCalldata any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrecomputeAddress", reflect.TypeOf((*MockAccountInterface)(nil).PrecomputeAddress), deployerAddress, salt, classHash, constructorCalldata) } @@ -62,7 +66,7 @@ func (m *MockAccountInterface) Sign(ctx context.Context, msg *felt.Felt) ([]*fel } // Sign indicates an expected call of Sign. -func (mr *MockAccountInterfaceMockRecorder) Sign(ctx, msg interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) Sign(ctx, msg any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*MockAccountInterface)(nil).Sign), ctx, msg) } @@ -76,7 +80,7 @@ func (m *MockAccountInterface) SignDeclareTransaction(ctx context.Context, tx *r } // SignDeclareTransaction indicates an expected call of SignDeclareTransaction. -func (mr *MockAccountInterfaceMockRecorder) SignDeclareTransaction(ctx, tx interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) SignDeclareTransaction(ctx, tx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignDeclareTransaction", reflect.TypeOf((*MockAccountInterface)(nil).SignDeclareTransaction), ctx, tx) } @@ -90,7 +94,7 @@ func (m *MockAccountInterface) SignDeployAccountTransaction(ctx context.Context, } // SignDeployAccountTransaction indicates an expected call of SignDeployAccountTransaction. -func (mr *MockAccountInterfaceMockRecorder) SignDeployAccountTransaction(ctx, tx, precomputeAddress interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) SignDeployAccountTransaction(ctx, tx, precomputeAddress any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignDeployAccountTransaction", reflect.TypeOf((*MockAccountInterface)(nil).SignDeployAccountTransaction), ctx, tx, precomputeAddress) } @@ -104,7 +108,7 @@ func (m *MockAccountInterface) SignInvokeTransaction(ctx context.Context, tx *rp } // SignInvokeTransaction indicates an expected call of SignInvokeTransaction. -func (mr *MockAccountInterfaceMockRecorder) SignInvokeTransaction(ctx, tx interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) SignInvokeTransaction(ctx, tx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignInvokeTransaction", reflect.TypeOf((*MockAccountInterface)(nil).SignInvokeTransaction), ctx, tx) } @@ -119,13 +123,13 @@ func (m *MockAccountInterface) TransactionHashDeclare(tx rpc.DeclareTxnType) (*f } // TransactionHashDeclare indicates an expected call of TransactionHashDeclare. -func (mr *MockAccountInterfaceMockRecorder) TransactionHashDeclare(tx interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) TransactionHashDeclare(tx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionHashDeclare", reflect.TypeOf((*MockAccountInterface)(nil).TransactionHashDeclare), tx) } // TransactionHashDeployAccount mocks base method. -func (m *MockAccountInterface) TransactionHashDeployAccount(tx rpc.DeployAccountTxn, contractAddress *felt.Felt) (*felt.Felt, error) { +func (m *MockAccountInterface) TransactionHashDeployAccount(tx rpc.DeployAccountType, contractAddress *felt.Felt) (*felt.Felt, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "TransactionHashDeployAccount", tx, contractAddress) ret0, _ := ret[0].(*felt.Felt) @@ -134,7 +138,7 @@ func (m *MockAccountInterface) TransactionHashDeployAccount(tx rpc.DeployAccount } // TransactionHashDeployAccount indicates an expected call of TransactionHashDeployAccount. -func (mr *MockAccountInterfaceMockRecorder) TransactionHashDeployAccount(tx, contractAddress interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) TransactionHashDeployAccount(tx, contractAddress any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionHashDeployAccount", reflect.TypeOf((*MockAccountInterface)(nil).TransactionHashDeployAccount), tx, contractAddress) } @@ -149,7 +153,7 @@ func (m *MockAccountInterface) TransactionHashInvoke(invokeTxn rpc.InvokeTxnType } // TransactionHashInvoke indicates an expected call of TransactionHashInvoke. -func (mr *MockAccountInterfaceMockRecorder) TransactionHashInvoke(invokeTxn interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) TransactionHashInvoke(invokeTxn any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionHashInvoke", reflect.TypeOf((*MockAccountInterface)(nil).TransactionHashInvoke), invokeTxn) } @@ -164,7 +168,7 @@ func (m *MockAccountInterface) WaitForTransactionReceipt(ctx context.Context, tr } // WaitForTransactionReceipt indicates an expected call of WaitForTransactionReceipt. -func (mr *MockAccountInterfaceMockRecorder) WaitForTransactionReceipt(ctx, transactionHash, pollInterval interface{}) *gomock.Call { +func (mr *MockAccountInterfaceMockRecorder) WaitForTransactionReceipt(ctx, transactionHash, pollInterval any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitForTransactionReceipt", reflect.TypeOf((*MockAccountInterface)(nil).WaitForTransactionReceipt), ctx, transactionHash, pollInterval) } diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 1b6ed5a1..c11ef581 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -236,18 +236,18 @@ func (mr *MockRpcProviderMockRecorder) ClassHashAt(ctx, blockID, contractAddress } // EstimateFee mocks base method. -func (m *MockRpcProvider) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlag 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.FeeEstimate, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EstimateFee", ctx, requests, simulationFlag, blockID) + ret := m.ctrl.Call(m, "EstimateFee", ctx, requests, simulationFlags, blockID) ret0, _ := ret[0].([]rpc.FeeEstimate) ret1, _ := ret[1].(error) return ret0, ret1 } // EstimateFee indicates an expected call of EstimateFee. -func (mr *MockRpcProviderMockRecorder) EstimateFee(ctx, requests, simulationFlag, blockID any) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) EstimateFee(ctx, requests, simulationFlags, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateFee", reflect.TypeOf((*MockRpcProvider)(nil).EstimateFee), ctx, requests, simulationFlag, blockID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateFee", reflect.TypeOf((*MockRpcProvider)(nil).EstimateFee), ctx, requests, simulationFlags, blockID) } // EstimateMessageFee mocks base method. diff --git a/rpc/contract.go b/rpc/contract.go index 9c8782a4..9772691a 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -137,9 +137,9 @@ 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, simulationFlag SimulationFlag, blockID BlockID) ([]FeeEstimate, error) { +func (provider *Provider) EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimate, error) { var raw []FeeEstimate - if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, simulationFlag, blockID); err != nil { + if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, simulationFlags, blockID); err != nil { return nil, tryUnwrapToRPCErr(err, ErrTxnExec, ErrBlockNotFound) } return raw, nil diff --git a/rpc/contract_test.go b/rpc/contract_test.go index d8c7274e..e914a345 100644 --- a/rpc/contract_test.go +++ b/rpc/contract_test.go @@ -411,3 +411,105 @@ func TestEstimateMessageFee(t *testing.T) { } } + +func TestEstimateFee(t *testing.T) { + testConfig := beforeEach(t) + + testBlockNumber := uint64(15643) + type testSetType struct { + txs []BroadcastTxn + simFlags []SimulationFlag + blockID BlockID + expectedResp []FeeEstimate + expectedError error + } + testSet := map[string][]testSetType{ + "mainnet": { + { + txs: []BroadcastTxn{ + InvokeTxnV0{ + Type: TransactionType_Invoke, + Version: TransactionV0, + MaxFee: utils.TestHexToFelt(t, "0x95e566845d000"), + FunctionCall: FunctionCall{ + ContractAddress: utils.TestHexToFelt(t, "0x45e92c365ba0908382bc346159f896e528214470c60ae2cd4038a0fff747b1e"), + EntryPointSelector: utils.TestHexToFelt(t, "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad"), + Calldata: utils.TestHexArrToFelt(t, []string{ + "0x1", + "0x4a3621276a83251b557a8140e915599ae8e7b6207b067ea701635c0d509801e", + "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354", + "0x0", + "0x3", + "0x3", + "0x697066733a2f2f516d57554c7a475135556a52616953514776717765347931", + "0x4731796f4757324e6a5a76564e77776a66514577756a", + "0x0", + "0x2"}), + }, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x63e4618ca2e323a45b9f860f12a4f5c4984648f1d110aa393e79d596d82abcc"), + utils.TestHexToFelt(t, "0x2844257b088ad4f49e2fe3df1ea6a8530aa2d21d8990112b7e88c4bd0ce9d50"), + }, + }, + }, + simFlags: []SimulationFlag{}, + blockID: BlockID{Number: &testBlockNumber}, + expectedError: nil, + expectedResp: []FeeEstimate{ + { + GasConsumed: utils.TestHexToFelt(t, "0x39b8"), + GasPrice: utils.TestHexToFelt(t, "0x350da9915"), + OverallFee: utils.TestHexToFelt(t, "0xbf62c933b418"), + FeeUnit: UnitWei, + }, + }, + }, + { + + txs: []BroadcastTxn{ + DeployAccountTxn{ + + Type: TransactionType_DeployAccount, + Version: TransactionV1, + MaxFee: utils.TestHexToFelt(t, "0xdec823b1380c"), + Nonce: utils.TestHexToFelt(t, "0x0"), + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x41dbc4b41f6506502a09eb7aea85759de02e91f49d0565776125946e54a2ec6"), + utils.TestHexToFelt(t, "0x85dcf2bc8e3543071a6657947cc9c157a9f6ad7844a686a975b588199634a9"), + }, + ContractAddressSalt: utils.TestHexToFelt(t, "0x74ddc51af144d1bd805eb4184d07453d7c4388660270a7851fec387e654a50e"), + ClassHash: utils.TestHexToFelt(t, "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918"), + ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ + "0x33434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2", + "0x79dc0da7c54b95f10aa182ad0a46400db63156920adb65eca2654c0945a463", + "0x2", + "0x74ddc51af144d1bd805eb4184d07453d7c4388660270a7851fec387e654a50e", + "0x0", + }), + }, + }, + simFlags: []SimulationFlag{}, + blockID: BlockID{Hash: utils.TestHexToFelt(t, "0x1b0df1bafcb826b1fc053495aef5cdc24d0345cbfa1259b15939d01b89dc6d9")}, + expectedError: nil, + expectedResp: []FeeEstimate{ + { + GasConsumed: utils.TestHexToFelt(t, "0x15be"), + GasPrice: utils.TestHexToFelt(t, "0x378f962c4"), + OverallFee: utils.TestHexToFelt(t, "0x4b803e316178"), + FeeUnit: UnitWei, + }, + }, + }, + }, + "mock": {}, + "testnet": {}, + }[testEnv] + + for _, test := range testSet { + spy := NewSpy(testConfig.provider.c) + testConfig.provider.c = spy + resp, err := testConfig.provider.EstimateFee(context.Background(), test.txs, test.simFlags, test.blockID) + require.Equal(t, test.expectedError, err) + require.Equal(t, test.expectedResp, resp) + } +} diff --git a/rpc/provider.go b/rpc/provider.go index 9c9d7e36..36b33a38 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -41,7 +41,7 @@ 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, simulationFlag SimulationFlag, blockID BlockID) ([]FeeEstimate, error) + EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimate, error) EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimate, error) Events(ctx context.Context, input EventsInput) (*EventChunk, error) GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error) diff --git a/rpc/types.go b/rpc/types.go index c1026173..e0fc7d47 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -198,7 +198,7 @@ type FeeEstimate struct { OverallFee *felt.Felt `json:"overall_fee"` // Units in which the fee is given - FeeUnit FeePaymentUnit `json:"fee_unit"` + FeeUnit FeePaymentUnit `json:"unit"` } type TxnExecutionStatus string