2024-06-24 14:29:40 +00:00
|
|
|
package connector
|
|
|
|
|
|
|
|
import (
|
2024-09-19 18:24:28 +00:00
|
|
|
"context"
|
2024-06-24 14:29:40 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2024-07-18 15:30:10 +00:00
|
|
|
"github.com/status-im/status-go/services/connector/commands"
|
2024-06-24 14:29:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCallRPC(t *testing.T) {
|
2024-09-19 18:24:28 +00:00
|
|
|
state, closeFn := setupTests(t)
|
|
|
|
t.Cleanup(closeFn)
|
2024-06-24 14:29:40 +00:00
|
|
|
|
|
|
|
tests := []struct {
|
2024-07-18 15:30:10 +00:00
|
|
|
request string
|
|
|
|
expectError error
|
2024-06-24 14:29:40 +00:00
|
|
|
}{
|
|
|
|
{
|
2024-07-18 15:30:10 +00:00
|
|
|
request: "{\"method\": \"eth_chainId\", \"params\": []}",
|
|
|
|
expectError: commands.ErrRequestMissingDAppData,
|
2024-06-24 14:29:40 +00:00
|
|
|
},
|
|
|
|
{
|
2024-07-18 15:30:10 +00:00
|
|
|
request: "{\"method\": \"eth_accounts\", \"params\": []}",
|
|
|
|
expectError: commands.ErrRequestMissingDAppData,
|
2024-06-24 14:29:40 +00:00
|
|
|
},
|
|
|
|
{
|
2024-07-18 15:30:10 +00:00
|
|
|
request: "{\"method\": \"eth_requestAccounts\", \"params\": []}",
|
|
|
|
expectError: commands.ErrRequestMissingDAppData,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
request: "{\"method\": \"eth_sendTransaction\", \"params\": []}",
|
|
|
|
expectError: commands.ErrRequestMissingDAppData,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
request: "{\"method\": \"wallet_switchEthereumChain\", \"params\": []}",
|
|
|
|
expectError: commands.ErrRequestMissingDAppData,
|
2024-06-24 14:29:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-19 18:24:28 +00:00
|
|
|
ctx := context.Background()
|
2024-06-24 14:29:40 +00:00
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.request, func(t *testing.T) {
|
2024-09-19 18:24:28 +00:00
|
|
|
_, err := state.api.CallRPC(ctx, tt.request)
|
2024-07-18 15:30:10 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Equal(t, tt.expectError, err)
|
2024-06-24 14:29:40 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|