Skip to content

Commit

Permalink
Add integration tests for v3 transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Nov 30, 2023
1 parent a94ff83 commit e7d53d4
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 64 deletions.
2 changes: 1 addition & 1 deletion account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
74 changes: 39 additions & 35 deletions mocks/mock_rpc_provider.go

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

54 changes: 34 additions & 20 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,35 +658,49 @@ 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
}
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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit e7d53d4

Please sign in to comment.