github.com/status-im/status-go@v1.1.0/mobile/response_test.go (about) 1 package statusgo 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 type nonJSON struct{} 11 12 func (*nonJSON) MarshalJSON() ([]byte, error) { 13 return nil, errors.New("invalid JSON") 14 } 15 16 func TestPrepareJSONResponseErrorWithResult(t *testing.T) { 17 data := prepareJSONResponse("0x123", nil) 18 require.Equal(t, `{"result":"0x123"}`, data) 19 20 data = prepareJSONResponse(&nonJSON{}, nil) 21 require.Contains(t, data, `{"error":{"code":1,"message":`) 22 } 23 24 func TestPrepareJSONResponseErrorWithError(t *testing.T) { 25 data := prepareJSONResponse("0x123", errors.New("some error")) 26 require.Contains(t, data, `{"error":{"message":"some error"}}`) 27 } 28 29 func TestDeserializeAndCompressKeyApi(t *testing.T) { 30 desktopKey := "zQ3shTAten2v9CwyQD1Kc7VXAqNPDcHZAMsfbLHCZEx6nFqk9" 31 mobileKeyExpected := "0x025596a7ff87da36860a84b0908191ce60a504afc94aac93c1abd774f182967ce6" 32 mobileKeyConverted := DeserializeAndCompressKey(desktopKey) 33 require.Equal(t, mobileKeyConverted, mobileKeyExpected) 34 }