status-go/mobile/response_test.go
Siddarth Kumar d43e06f4c2
converting desktop key to mobile readable (#3042)
In desktop when a community is created the share url looks like :

https://join.status.im/c/zQ3shTAten2v9CwyQD1Kc7VXAqNPDcHZAMsfbLHCZEx6nFqk9 where
zQ3shTAten2v9CwyQD1Kc7VXAqNPDcHZAMsfbLHCZEx6nFqk9
is the serialised key which desktop uses.

In mobile when a community is created the share url looks like :
https://join.status.im/c/0x025596a7ff87da36860a84b0908191ce60a504afc94aac93c1abd774f182967ce6 where
0x025596a7ff87da36860a84b0908191ce60a504afc94aac93c1abd774f182967ce6
is the non serialised key (but compressed) key which mobile uses.

The goal of this PR is to give mobile the ability to go from
zQ3shTAten2v9CwyQD1Kc7VXAqNPDcHZAMsfbLHCZEx6nFqk9 to 0x025596a7ff87da36860a84b0908191ce60a504afc94aac93c1abd774f182967ce6
2023-01-04 07:25:07 +05:30

35 lines
988 B
Go

package statusgo
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
type nonJSON struct{}
func (*nonJSON) MarshalJSON() ([]byte, error) {
return nil, errors.New("invalid JSON")
}
func TestPrepareJSONResponseErrorWithResult(t *testing.T) {
data := prepareJSONResponse("0x123", nil)
require.Equal(t, `{"result":"0x123"}`, data)
data = prepareJSONResponse(&nonJSON{}, nil)
require.Contains(t, data, `{"error":{"code":1,"message":`)
}
func TestPrepareJSONResponseErrorWithError(t *testing.T) {
data := prepareJSONResponse("0x123", errors.New("some error"))
require.Contains(t, data, `{"error":{"message":"some error"}}`)
}
func TestDeserializeAndCompressKeyApi(t *testing.T) {
desktopKey := "zQ3shTAten2v9CwyQD1Kc7VXAqNPDcHZAMsfbLHCZEx6nFqk9"
mobileKeyExpected := "0x025596a7ff87da36860a84b0908191ce60a504afc94aac93c1abd774f182967ce6"
mobileKeyConverted := DeserializeAndCompressKey(desktopKey)
require.Equal(t, mobileKeyConverted, mobileKeyExpected)
}