github.com/status-im/status-go@v1.1.0/rpc/route_test.go (about) 1 package rpc 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 // localMethods are methods that should be executed locally. 10 var localTestMethods = []string{"some_weirdo_method", "shh_newMessageFilter", "eth_accounts"} 11 12 func TestRouteWithUpstream(t *testing.T) { 13 router := newRouter(true) 14 15 for _, method := range remoteMethods { 16 require.True(t, router.routeRemote(method), "method "+method+" should routed to remote") 17 } 18 19 for _, method := range localTestMethods { 20 t.Run(method, func(t *testing.T) { 21 require.False(t, router.routeRemote(method), "method "+method+" should routed to local") 22 }) 23 } 24 } 25 26 func TestRouteWithoutUpstream(t *testing.T) { 27 router := newRouter(false) 28 29 for _, method := range remoteMethods { 30 require.False(t, router.routeRemote(method), "method "+method+" should routed to locally without UpstreamEnabled") 31 } 32 33 for _, method := range localTestMethods { 34 require.False(t, router.routeRemote(method), "method "+method+" should routed to local") 35 } 36 } 37 38 func TestBlockedRoutes(t *testing.T) { 39 // Be explicit as any change to `blockedMethods` 40 // should be confirmed with a unit test fail. 41 expectedBlockedMethods := [...]string{"shh_getPrivateKey"} 42 require.Equal(t, expectedBlockedMethods, blockedMethods) 43 require.Equal(t, expectedBlockedMethods[:], BlockedMethods()) 44 45 router := newRouter(false) 46 for _, method := range blockedMethods { 47 require.True(t, router.routeBlocked(method)) 48 } 49 }