diff --git a/account/account.go b/account/account.go index 75c289c9..075dac36 100644 --- a/account/account.go +++ b/account/account.go @@ -520,7 +520,7 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti // Returns: // - *rpc.AddInvokeTransactionResponse: The response for the AddInvokeTransactionResponse // - error: an error if any. -func (account *Account) AddInvokeTransaction(ctx context.Context, invokeTx rpc.BroadcastInvokeTxn) (*rpc.AddInvokeTransactionResponse, error) { +func (account *Account) AddInvokeTransaction(ctx context.Context, invokeTx rpc.BroadcastInvokeTxnType) (*rpc.AddInvokeTransactionResponse, error) { return account.provider.AddInvokeTransaction(ctx, invokeTx) } diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 0fe87974..a120912c 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: rpc/provider.go - +// Source: provider.go +// +// Generated by this command: +// +// mockgen -destination=../mocks/mock_rpc_provider.go -package=mocks -source=provider.go api +// // Package mocks is a generated GoMock package. package mocks @@ -46,7 +50,7 @@ func (m *MockRpcProvider) AddDeclareTransaction(ctx context.Context, declareTran } // AddDeclareTransaction indicates an expected call of AddDeclareTransaction. -func (mr *MockRpcProviderMockRecorder) AddDeclareTransaction(ctx, declareTransaction interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) AddDeclareTransaction(ctx, declareTransaction any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddDeclareTransaction", reflect.TypeOf((*MockRpcProvider)(nil).AddDeclareTransaction), ctx, declareTransaction) } @@ -61,13 +65,13 @@ func (m *MockRpcProvider) AddDeployAccountTransaction(ctx context.Context, deplo } // AddDeployAccountTransaction indicates an expected call of AddDeployAccountTransaction. -func (mr *MockRpcProviderMockRecorder) AddDeployAccountTransaction(ctx, deployAccountTransaction interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) AddDeployAccountTransaction(ctx, deployAccountTransaction any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddDeployAccountTransaction", reflect.TypeOf((*MockRpcProvider)(nil).AddDeployAccountTransaction), ctx, deployAccountTransaction) } // AddInvokeTransaction mocks base method. -func (m *MockRpcProvider) AddInvokeTransaction(ctx context.Context, invokeTxn rpc.BroadcastInvokeTxn) (*rpc.AddInvokeTransactionResponse, error) { +func (m *MockRpcProvider) AddInvokeTransaction(ctx context.Context, invokeTxn rpc.BroadcastInvokeTxnType) (*rpc.AddInvokeTransactionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddInvokeTransaction", ctx, invokeTxn) ret0, _ := ret[0].(*rpc.AddInvokeTransactionResponse) @@ -76,7 +80,7 @@ func (m *MockRpcProvider) AddInvokeTransaction(ctx context.Context, invokeTxn rp } // AddInvokeTransaction indicates an expected call of AddInvokeTransaction. -func (mr *MockRpcProviderMockRecorder) AddInvokeTransaction(ctx, invokeTxn interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) AddInvokeTransaction(ctx, invokeTxn any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddInvokeTransaction", reflect.TypeOf((*MockRpcProvider)(nil).AddInvokeTransaction), ctx, invokeTxn) } @@ -91,7 +95,7 @@ func (m *MockRpcProvider) BlockHashAndNumber(ctx context.Context) (*rpc.BlockHas } // BlockHashAndNumber indicates an expected call of BlockHashAndNumber. -func (mr *MockRpcProviderMockRecorder) BlockHashAndNumber(ctx interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) BlockHashAndNumber(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockHashAndNumber", reflect.TypeOf((*MockRpcProvider)(nil).BlockHashAndNumber), ctx) } @@ -106,7 +110,7 @@ func (m *MockRpcProvider) BlockNumber(ctx context.Context) (uint64, error) { } // BlockNumber indicates an expected call of BlockNumber. -func (mr *MockRpcProviderMockRecorder) BlockNumber(ctx interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) BlockNumber(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockNumber", reflect.TypeOf((*MockRpcProvider)(nil).BlockNumber), ctx) } @@ -121,37 +125,37 @@ func (m *MockRpcProvider) BlockTransactionCount(ctx context.Context, blockID rpc } // BlockTransactionCount indicates an expected call of BlockTransactionCount. -func (mr *MockRpcProviderMockRecorder) BlockTransactionCount(ctx, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) BlockTransactionCount(ctx, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockTransactionCount", reflect.TypeOf((*MockRpcProvider)(nil).BlockTransactionCount), ctx, blockID) } // BlockWithTxHashes mocks base method. -func (m *MockRpcProvider) BlockWithTxHashes(ctx context.Context, blockID rpc.BlockID) (interface{}, error) { +func (m *MockRpcProvider) BlockWithTxHashes(ctx context.Context, blockID rpc.BlockID) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "BlockWithTxHashes", ctx, blockID) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(any) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockWithTxHashes indicates an expected call of BlockWithTxHashes. -func (mr *MockRpcProviderMockRecorder) BlockWithTxHashes(ctx, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) BlockWithTxHashes(ctx, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockWithTxHashes", reflect.TypeOf((*MockRpcProvider)(nil).BlockWithTxHashes), ctx, blockID) } // BlockWithTxs mocks base method. -func (m *MockRpcProvider) BlockWithTxs(ctx context.Context, blockID rpc.BlockID) (interface{}, error) { +func (m *MockRpcProvider) BlockWithTxs(ctx context.Context, blockID rpc.BlockID) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "BlockWithTxs", ctx, blockID) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(any) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockWithTxs indicates an expected call of BlockWithTxs. -func (mr *MockRpcProviderMockRecorder) BlockWithTxs(ctx, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) BlockWithTxs(ctx, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockWithTxs", reflect.TypeOf((*MockRpcProvider)(nil).BlockWithTxs), ctx, blockID) } @@ -166,7 +170,7 @@ func (m *MockRpcProvider) Call(ctx context.Context, call rpc.FunctionCall, block } // Call indicates an expected call of Call. -func (mr *MockRpcProviderMockRecorder) Call(ctx, call, block interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) Call(ctx, call, block any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Call", reflect.TypeOf((*MockRpcProvider)(nil).Call), ctx, call, block) } @@ -181,7 +185,7 @@ func (m *MockRpcProvider) ChainID(ctx context.Context) (string, error) { } // ChainID indicates an expected call of ChainID. -func (mr *MockRpcProviderMockRecorder) ChainID(ctx interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) ChainID(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainID", reflect.TypeOf((*MockRpcProvider)(nil).ChainID), ctx) } @@ -196,7 +200,7 @@ func (m *MockRpcProvider) Class(ctx context.Context, blockID rpc.BlockID, classH } // Class indicates an expected call of Class. -func (mr *MockRpcProviderMockRecorder) Class(ctx, blockID, classHash interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) Class(ctx, blockID, classHash any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Class", reflect.TypeOf((*MockRpcProvider)(nil).Class), ctx, blockID, classHash) } @@ -211,7 +215,7 @@ func (m *MockRpcProvider) ClassAt(ctx context.Context, blockID rpc.BlockID, cont } // ClassAt indicates an expected call of ClassAt. -func (mr *MockRpcProviderMockRecorder) ClassAt(ctx, blockID, contractAddress interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) ClassAt(ctx, blockID, contractAddress any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClassAt", reflect.TypeOf((*MockRpcProvider)(nil).ClassAt), ctx, blockID, contractAddress) } @@ -226,7 +230,7 @@ func (m *MockRpcProvider) ClassHashAt(ctx context.Context, blockID rpc.BlockID, } // ClassHashAt indicates an expected call of ClassHashAt. -func (mr *MockRpcProviderMockRecorder) ClassHashAt(ctx, blockID, contractAddress interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) ClassHashAt(ctx, blockID, contractAddress any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClassHashAt", reflect.TypeOf((*MockRpcProvider)(nil).ClassHashAt), ctx, blockID, contractAddress) } @@ -241,7 +245,7 @@ func (m *MockRpcProvider) EstimateFee(ctx context.Context, requests []rpc.Broadc } // EstimateFee indicates an expected call of EstimateFee. -func (mr *MockRpcProviderMockRecorder) EstimateFee(ctx, requests, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) EstimateFee(ctx, requests, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateFee", reflect.TypeOf((*MockRpcProvider)(nil).EstimateFee), ctx, requests, blockID) } @@ -256,7 +260,7 @@ func (m *MockRpcProvider) EstimateMessageFee(ctx context.Context, msg rpc.MsgFro } // EstimateMessageFee indicates an expected call of EstimateMessageFee. -func (mr *MockRpcProviderMockRecorder) EstimateMessageFee(ctx, msg, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) EstimateMessageFee(ctx, msg, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateMessageFee", reflect.TypeOf((*MockRpcProvider)(nil).EstimateMessageFee), ctx, msg, blockID) } @@ -271,7 +275,7 @@ func (m *MockRpcProvider) Events(ctx context.Context, input rpc.EventsInput) (*r } // Events indicates an expected call of Events. -func (mr *MockRpcProviderMockRecorder) Events(ctx, input interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) Events(ctx, input any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Events", reflect.TypeOf((*MockRpcProvider)(nil).Events), ctx, input) } @@ -286,7 +290,7 @@ func (m *MockRpcProvider) GetTransactionStatus(ctx context.Context, transactionH } // GetTransactionStatus indicates an expected call of GetTransactionStatus. -func (mr *MockRpcProviderMockRecorder) GetTransactionStatus(ctx, transactionHash interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) GetTransactionStatus(ctx, transactionHash any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionStatus", reflect.TypeOf((*MockRpcProvider)(nil).GetTransactionStatus), ctx, transactionHash) } @@ -301,7 +305,7 @@ func (m *MockRpcProvider) Nonce(ctx context.Context, blockID rpc.BlockID, contra } // Nonce indicates an expected call of Nonce. -func (mr *MockRpcProviderMockRecorder) Nonce(ctx, blockID, contractAddress interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) Nonce(ctx, blockID, contractAddress any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nonce", reflect.TypeOf((*MockRpcProvider)(nil).Nonce), ctx, blockID, contractAddress) } @@ -316,7 +320,7 @@ func (m *MockRpcProvider) SimulateTransactions(ctx context.Context, blockID rpc. } // SimulateTransactions indicates an expected call of SimulateTransactions. -func (mr *MockRpcProviderMockRecorder) SimulateTransactions(ctx, blockID, txns, simulationFlags interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) SimulateTransactions(ctx, blockID, txns, simulationFlags any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SimulateTransactions", reflect.TypeOf((*MockRpcProvider)(nil).SimulateTransactions), ctx, blockID, txns, simulationFlags) } @@ -331,7 +335,7 @@ func (m *MockRpcProvider) SpecVersion(ctx context.Context) (string, error) { } // SpecVersion indicates an expected call of SpecVersion. -func (mr *MockRpcProviderMockRecorder) SpecVersion(ctx interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) SpecVersion(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpecVersion", reflect.TypeOf((*MockRpcProvider)(nil).SpecVersion), ctx) } @@ -346,7 +350,7 @@ func (m *MockRpcProvider) StateUpdate(ctx context.Context, blockID rpc.BlockID) } // StateUpdate indicates an expected call of StateUpdate. -func (mr *MockRpcProviderMockRecorder) StateUpdate(ctx, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) StateUpdate(ctx, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdate", reflect.TypeOf((*MockRpcProvider)(nil).StateUpdate), ctx, blockID) } @@ -361,7 +365,7 @@ func (m *MockRpcProvider) StorageAt(ctx context.Context, contractAddress *felt.F } // StorageAt indicates an expected call of StorageAt. -func (mr *MockRpcProviderMockRecorder) StorageAt(ctx, contractAddress, key, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) StorageAt(ctx, contractAddress, key, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StorageAt", reflect.TypeOf((*MockRpcProvider)(nil).StorageAt), ctx, contractAddress, key, blockID) } @@ -376,7 +380,7 @@ func (m *MockRpcProvider) Syncing(ctx context.Context) (*rpc.SyncStatus, error) } // Syncing indicates an expected call of Syncing. -func (mr *MockRpcProviderMockRecorder) Syncing(ctx interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) Syncing(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Syncing", reflect.TypeOf((*MockRpcProvider)(nil).Syncing), ctx) } @@ -391,7 +395,7 @@ func (m *MockRpcProvider) TraceBlockTransactions(ctx context.Context, blockID rp } // TraceBlockTransactions indicates an expected call of TraceBlockTransactions. -func (mr *MockRpcProviderMockRecorder) TraceBlockTransactions(ctx, blockID interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) TraceBlockTransactions(ctx, blockID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TraceBlockTransactions", reflect.TypeOf((*MockRpcProvider)(nil).TraceBlockTransactions), ctx, blockID) } @@ -406,7 +410,7 @@ func (m *MockRpcProvider) TraceTransaction(ctx context.Context, transactionHash } // TraceTransaction indicates an expected call of TraceTransaction. -func (mr *MockRpcProviderMockRecorder) TraceTransaction(ctx, transactionHash interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) TraceTransaction(ctx, transactionHash any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TraceTransaction", reflect.TypeOf((*MockRpcProvider)(nil).TraceTransaction), ctx, transactionHash) } @@ -421,7 +425,7 @@ func (m *MockRpcProvider) TransactionByBlockIdAndIndex(ctx context.Context, bloc } // TransactionByBlockIdAndIndex indicates an expected call of TransactionByBlockIdAndIndex. -func (mr *MockRpcProviderMockRecorder) TransactionByBlockIdAndIndex(ctx, blockID, index interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) TransactionByBlockIdAndIndex(ctx, blockID, index any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByBlockIdAndIndex", reflect.TypeOf((*MockRpcProvider)(nil).TransactionByBlockIdAndIndex), ctx, blockID, index) } @@ -436,7 +440,7 @@ func (m *MockRpcProvider) TransactionByHash(ctx context.Context, hash *felt.Felt } // TransactionByHash indicates an expected call of TransactionByHash. -func (mr *MockRpcProviderMockRecorder) TransactionByHash(ctx, hash interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) TransactionByHash(ctx, hash any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByHash", reflect.TypeOf((*MockRpcProvider)(nil).TransactionByHash), ctx, hash) } @@ -451,7 +455,7 @@ func (m *MockRpcProvider) TransactionReceipt(ctx context.Context, transactionHas } // TransactionReceipt indicates an expected call of TransactionReceipt. -func (mr *MockRpcProviderMockRecorder) TransactionReceipt(ctx, transactionHash interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) TransactionReceipt(ctx, transactionHash any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionReceipt", reflect.TypeOf((*MockRpcProvider)(nil).TransactionReceipt), ctx, transactionHash) } diff --git a/rpc/mock_test.go b/rpc/mock_test.go index 884e2157..f165da66 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -658,6 +658,8 @@ func mock_starknet_estimateMessageFee(result interface{}, method string, args .. // Returns: // - error: an error if any func mock_starknet_addInvokeTransaction(result interface{}, method string, args ...interface{}) error { + fmt.Println("mock_starknet_addInvokeTransaction") + r, ok := result.(*json.RawMessage) if !ok { return errWrongType @@ -665,28 +667,40 @@ func mock_starknet_addInvokeTransaction(result interface{}, method string, args if len(args) != 1 { return errors.Wrap(errWrongArgs, fmt.Sprint("wrong number of args ", len(args))) } - invokeTx, ok := args[0].(InvokeTxnV1) - if !ok { - return errors.Wrap(errWrongArgs, fmt.Sprintf("args[0] should be InvokeTxnV1, got %T\n", args[0])) - } - if invokeTx.SenderAddress != nil { - - if invokeTx.SenderAddress.Equal(new(felt.Felt).SetUint64(123)) { - unexpErr := *ErrUnexpectedError - unexpErr.data = "Something crazy happened" - return &unexpErr + switch invokeTx := args[0].(type) { + case InvokeTxnV1: + if invokeTx.SenderAddress != nil { + if invokeTx.SenderAddress.Equal(new(felt.Felt).SetUint64(123)) { + unexpErr := *ErrUnexpectedError + unexpErr.data = "Something crazy happened" + return &unexpErr + } } + deadbeefFelt, err := utils.HexToFelt("0xdeadbeef") + if err != nil { + return err + } + output := AddInvokeTransactionResponse{ + TransactionHash: deadbeefFelt, + } + outputContent, _ := json.Marshal(output) + json.Unmarshal(outputContent, r) + return nil + case InvokeTxnV3: + deadbeefFelt, err := utils.HexToFelt("0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd") + if err != nil { + return err + } + output := AddInvokeTransactionResponse{ + TransactionHash: deadbeefFelt, + } + outputContent, _ := json.Marshal(output) + json.Unmarshal(outputContent, r) + return nil + default: + return errors.Wrap(errWrongArgs, fmt.Sprintf("args[0] should be InvokeTxnV1 or InvokeTxnV3, got %T\n", args[0])) } - deadbeefFelt, err := utils.HexToFelt("0xdeadbeef") - if err != nil { - return err - } - output := AddInvokeTransactionResponse{ - TransactionHash: deadbeefFelt, - } - outputContent, _ := json.Marshal(output) - json.Unmarshal(outputContent, r) - return nil + } // mock_starknet_getStorageAt mocks the behavior of the StarkNet getStorageAt function. diff --git a/rpc/provider.go b/rpc/provider.go index fac8b7ca..d088354a 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -28,7 +28,7 @@ func NewProvider(c *rpc.Client) *Provider { //go:generate mockgen -destination=../mocks/mock_rpc_provider.go -package=mocks -source=provider.go api type RpcProvider interface { - AddInvokeTransaction(ctx context.Context, invokeTxn BroadcastInvokeTxn) (*AddInvokeTransactionResponse, error) + AddInvokeTransaction(ctx context.Context, invokeTxn BroadcastInvokeTxnType) (*AddInvokeTransactionResponse, error) AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastDeclareTxn) (*AddDeclareTransactionResponse, error) AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction BroadcastDeployAccountTxn) (*AddDeployAccountTransactionResponse, error) BlockHashAndNumber(ctx context.Context) (*BlockHashAndNumberOutput, error) diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index 69264735..857ab91f 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -13,11 +13,12 @@ var ( _ BroadcastTxn = BroadcastDeployAccountTxn{} ) -type BroadcastInvokeTxn interface{} +type BroadcastInvokeTxnType interface{} var ( - _ BroadcastInvokeTxn = BroadcastInvokev0Txn{} - _ BroadcastInvokeTxn = BroadcastInvokev1Txn{} + _ BroadcastInvokeTxnType = BroadcastInvokev0Txn{} + _ BroadcastInvokeTxnType = BroadcastInvokev1Txn{} + _ BroadcastInvokeTxnType = BroadcastInvokev3Txn{} ) type BroadcastDeclareTxn interface{} @@ -35,6 +36,10 @@ type BroadcastInvokev1Txn struct { InvokeTxnV1 } +type BroadcastInvokev3Txn struct { + InvokeTxnV3 +} + type BroadcastDeclareV1Txn struct { Type TransactionType `json:"type"` // SenderAddress the address of the account contract sending the declaration transaction diff --git a/rpc/write.go b/rpc/write.go index b563c02a..8382968e 100644 --- a/rpc/write.go +++ b/rpc/write.go @@ -12,7 +12,7 @@ import ( // Returns: // - *AddInvokeTransactionResponse: the response of adding the invoke transaction // - error: an error if any -func (provider *Provider) AddInvokeTransaction(ctx context.Context, invokeTxn BroadcastInvokeTxn) (*AddInvokeTransactionResponse, error) { +func (provider *Provider) AddInvokeTransaction(ctx context.Context, invokeTxn BroadcastInvokeTxnType) (*AddInvokeTransactionResponse, error) { var output AddInvokeTransactionResponse if err := do(ctx, provider.c, "starknet_addInvokeTransaction", &output, invokeTxn); err != nil { return nil, tryUnwrapToRPCErr( diff --git a/rpc/write_test.go b/rpc/write_test.go index c03eb14e..36e66c59 100644 --- a/rpc/write_test.go +++ b/rpc/write_test.go @@ -22,7 +22,8 @@ import ( // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestDeclareTransaction(t *testing.T) { testConfig := beforeEach(t) @@ -80,13 +81,14 @@ func TestDeclareTransaction(t *testing.T) { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestAddInvokeTransaction(t *testing.T) { testConfig := beforeEach(t) type testSetType struct { - InvokeTx InvokeTxnV1 + InvokeTx InvokeTxnType ExpectedResp AddInvokeTransactionResponse ExpectedError RPCError } @@ -107,6 +109,52 @@ func TestAddInvokeTransaction(t *testing.T) { ExpectedResp: AddInvokeTransactionResponse{utils.TestHexToFelt(t, "0xdeadbeef")}, ExpectedError: RPCError{}, }, + { + InvokeTx: InvokeTxnV3{ + Type: TransactionType_Invoke, + Version: TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x71a9b2cd8a8a6a4ca284dcddcdefc6c4fd20b92c1b201bd9836e4ce376fad16"), + utils.TestHexToFelt(t, "0x6bef4745194c9447fdc8dd3aec4fc738ab0a560b0d2c7bf62fbf58aef3abfc5"), + }, + Nonce: utils.TestHexToFelt(t, "0xe97"), + NonceDataMode: DAModeL1, + FeeMode: DAModeL1, + ResourceBounds: ResourceBoundsMapping{ + L1Gas: ResourceBounds{ + MaxAmount: utils.TestHexToFelt(t, "0x186a0"), + MaxPricePerUnit: utils.TestHexToFelt(t, "0x5af3107a4000"), + }, + L2Gas: ResourceBounds{ + MaxAmount: utils.TestHexToFelt(t, "0x0"), + MaxPricePerUnit: utils.TestHexToFelt(t, "0x0"), + }, + }, + Tip: new(felt.Felt), + PayMasterData: []*felt.Felt{}, + SenderAddress: utils.TestHexToFelt(t, "0x3f6f3bc663aedc5285d6013cc3ffcbc4341d86ab488b8b68d297f8258793c41"), + Calldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x2"), + utils.TestHexToFelt(t, "0x450703c32370cf7ffff540b9352e7ee4ad583af143a361155f2b485c0c39684"), + utils.TestHexToFelt(t, "0x27c3334165536f239cfd400ed956eabff55fc60de4fb56728b6a4f6b87db01c"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x4"), + utils.TestHexToFelt(t, "0x4c312760dfd17a954cdd09e76aa9f149f806d88ec3e402ffaf5c4926f568a42"), + utils.TestHexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf"), + utils.TestHexToFelt(t, "0x4"), + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x5"), + utils.TestHexToFelt(t, "0x450703c32370cf7ffff540b9352e7ee4ad583af143a361155f2b485c0c39684"), + utils.TestHexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf"), + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x7fe4fd616c7fece1244b3616bb516562e230be8c9f29668b46ce0369d5ca829"), + utils.TestHexToFelt(t, "0x287acddb27a2f9ba7f2612d72788dc96a5b30e401fc1e8072250940e024a587"), + }, + AccountDeploymentData: []*felt.Felt{}, + }, + ExpectedResp: AddInvokeTransactionResponse{utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd")}, + ExpectedError: RPCError{}, + }, }, "testnet": {}, }[testEnv]