2023-07-12 09:46:56 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2023-08-10 13:57:52 +00:00
|
|
|
"context"
|
2023-12-15 19:50:12 +00:00
|
|
|
"crypto/rand"
|
2023-07-12 09:46:56 +00:00
|
|
|
"errors"
|
2024-02-16 18:34:04 +00:00
|
|
|
"fmt"
|
2023-12-15 19:50:12 +00:00
|
|
|
"math/big"
|
2024-03-26 20:02:12 +00:00
|
|
|
mathRand "math/rand"
|
2023-10-24 10:15:32 +00:00
|
|
|
"sync"
|
2023-10-20 14:23:02 +00:00
|
|
|
"time"
|
2023-07-12 09:46:56 +00:00
|
|
|
|
2024-02-21 02:51:12 +00:00
|
|
|
"github.com/status-im/status-go/protocol/wakusync"
|
|
|
|
|
2024-02-17 18:07:20 +00:00
|
|
|
"github.com/status-im/status-go/protocol/identity"
|
|
|
|
|
2024-02-20 15:49:39 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2024-02-16 18:34:04 +00:00
|
|
|
waku2 "github.com/status-im/status-go/wakuv2"
|
|
|
|
|
2023-08-10 13:57:52 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2023-07-12 09:46:56 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2023-12-15 19:50:12 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
2023-07-12 09:46:56 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2023-12-15 19:50:12 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2023-07-12 09:46:56 +00:00
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
|
|
|
)
|
|
|
|
|
2023-12-15 19:50:12 +00:00
|
|
|
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
var hexRunes = []rune("0123456789abcdef")
|
|
|
|
|
2023-07-12 09:46:56 +00:00
|
|
|
// WaitOnMessengerResponse Wait until the condition is true or the timeout is reached.
|
|
|
|
func WaitOnMessengerResponse(m *Messenger, condition func(*MessengerResponse) bool, errorMessage string) (*MessengerResponse, error) {
|
|
|
|
response := &MessengerResponse{}
|
|
|
|
err := tt.RetryWithBackOff(func() error {
|
|
|
|
var err error
|
|
|
|
r, err := m.RetrieveAll()
|
2023-08-10 15:12:23 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-07-12 09:46:56 +00:00
|
|
|
if err := response.Merge(r); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil && !condition(response) {
|
|
|
|
err = errors.New(errorMessage)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
})
|
2023-08-04 10:41:24 +00:00
|
|
|
return response, err
|
2023-07-12 09:46:56 +00:00
|
|
|
}
|
|
|
|
|
2023-10-20 14:23:02 +00:00
|
|
|
type MessengerSignalsHandlerMock struct {
|
|
|
|
MessengerSignalsHandler
|
|
|
|
|
2024-02-21 02:51:12 +00:00
|
|
|
responseChan chan *MessengerResponse
|
|
|
|
communityFoundChan chan *communities.Community
|
|
|
|
wakuBackedUpDataResponseChan chan *wakusync.WakuBackedUpDataResponse
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandlerMock) SendWakuFetchingBackupProgress(response *wakusync.WakuBackedUpDataResponse) {
|
|
|
|
m.wakuBackedUpDataResponseChan <- response
|
|
|
|
}
|
|
|
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpProfile(*wakusync.WakuBackedUpDataResponse) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpSettings(*wakusync.WakuBackedUpDataResponse) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpKeypair(*wakusync.WakuBackedUpDataResponse) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpWatchOnlyAccount(*wakusync.WakuBackedUpDataResponse) {
|
2023-10-20 14:23:02 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 12:49:09 +00:00
|
|
|
func (m *MessengerSignalsHandlerMock) BackupPerformed(uint64) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) HistoryArchivesProtocolEnabled() {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) HistoryArchivesProtocolDisabled() {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) CreatingHistoryArchives(string) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) NoHistoryArchivesCreated(string, int, int) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) HistoryArchivesCreated(string, int, int) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) HistoryArchivesSeeding(string) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) HistoryArchivesUnseeded(string) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) HistoryArchiveDownloaded(string, int, int) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) DownloadingHistoryArchivesStarted(string) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) DownloadingHistoryArchivesFinished(string) {}
|
|
|
|
func (m *MessengerSignalsHandlerMock) ImportingHistoryArchiveMessages(string) {}
|
|
|
|
|
2023-10-20 14:23:02 +00:00
|
|
|
func (m *MessengerSignalsHandlerMock) MessengerResponse(response *MessengerResponse) {
|
|
|
|
// Non-blocking send
|
|
|
|
select {
|
|
|
|
case m.responseChan <- response:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandlerMock) MessageDelivered(chatID string, messageID string) {}
|
|
|
|
|
2023-12-15 19:50:12 +00:00
|
|
|
func (m *MessengerSignalsHandlerMock) CommunityInfoFound(community *communities.Community) {
|
|
|
|
select {
|
|
|
|
case m.communityFoundChan <- community:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 02:51:12 +00:00
|
|
|
func WaitOnSignaledSendWakuFetchingBackupProgress(m *Messenger, condition func(*wakusync.WakuBackedUpDataResponse) bool, errorMessage string) (*wakusync.WakuBackedUpDataResponse, error) {
|
|
|
|
interval := 500 * time.Millisecond
|
|
|
|
timeoutChan := time.After(10 * time.Second)
|
|
|
|
|
|
|
|
if m.config.messengerSignalsHandler != nil {
|
|
|
|
return nil, errors.New("messengerSignalsHandler already provided/mocked")
|
|
|
|
}
|
|
|
|
|
|
|
|
responseChan := make(chan *wakusync.WakuBackedUpDataResponse, 1000)
|
|
|
|
m.config.messengerSignalsHandler = &MessengerSignalsHandlerMock{
|
|
|
|
wakuBackedUpDataResponseChan: responseChan,
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
m.config.messengerSignalsHandler = nil
|
|
|
|
}()
|
|
|
|
|
|
|
|
for {
|
|
|
|
_, err := m.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case r := <-responseChan:
|
|
|
|
if condition(r) {
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
case <-timeoutChan:
|
|
|
|
return nil, errors.New("timed out: " + errorMessage)
|
|
|
|
default: // No immediate response, rest & loop back to retrieve again
|
|
|
|
time.Sleep(interval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:23:02 +00:00
|
|
|
func WaitOnSignaledMessengerResponse(m *Messenger, condition func(*MessengerResponse) bool, errorMessage string) (*MessengerResponse, error) {
|
|
|
|
interval := 500 * time.Millisecond
|
|
|
|
timeoutChan := time.After(10 * time.Second)
|
|
|
|
|
|
|
|
if m.config.messengerSignalsHandler != nil {
|
|
|
|
return nil, errors.New("messengerSignalsHandler already provided/mocked")
|
|
|
|
}
|
|
|
|
|
2024-02-19 09:52:22 +00:00
|
|
|
responseChan := make(chan *MessengerResponse, 64)
|
2023-10-20 14:23:02 +00:00
|
|
|
m.config.messengerSignalsHandler = &MessengerSignalsHandlerMock{
|
|
|
|
responseChan: responseChan,
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
m.config.messengerSignalsHandler = nil
|
|
|
|
}()
|
|
|
|
|
|
|
|
for {
|
|
|
|
_, err := m.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case r := <-responseChan:
|
|
|
|
if condition(r) {
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case <-timeoutChan:
|
2024-02-19 09:52:22 +00:00
|
|
|
return nil, errors.New(errorMessage)
|
2023-10-20 14:23:02 +00:00
|
|
|
|
|
|
|
default: // No immediate response, rest & loop back to retrieve again
|
|
|
|
time.Sleep(interval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-15 19:50:12 +00:00
|
|
|
func WaitOnSignaledCommunityFound(m *Messenger, action func(), condition func(community *communities.Community) bool, timeout time.Duration, errorMessage string) error {
|
|
|
|
timeoutChan := time.After(timeout)
|
|
|
|
|
|
|
|
if m.config.messengerSignalsHandler != nil {
|
|
|
|
return errors.New("messengerSignalsHandler already provided/mocked")
|
|
|
|
}
|
|
|
|
|
|
|
|
communityFoundChan := make(chan *communities.Community, 1)
|
|
|
|
m.config.messengerSignalsHandler = &MessengerSignalsHandlerMock{
|
|
|
|
communityFoundChan: communityFoundChan,
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
m.config.messengerSignalsHandler = nil
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Call the action after setting up the mock
|
|
|
|
action()
|
|
|
|
|
|
|
|
// Wait for condition after
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case c := <-communityFoundChan:
|
|
|
|
if condition(c) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case <-timeoutChan:
|
2024-01-18 18:54:54 +00:00
|
|
|
return errors.New("timed out: " + errorMessage)
|
2023-12-15 19:50:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-16 18:34:04 +00:00
|
|
|
func WaitForConnectionStatus(s *suite.Suite, waku *waku2.Waku, action func() bool) {
|
|
|
|
subscription := waku.SubscribeToConnStatusChanges()
|
|
|
|
defer subscription.Unsubscribe()
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// Action should return the desired online status
|
|
|
|
wantedOnline := action()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case status := <-subscription.C:
|
|
|
|
if status.IsOnline == wantedOnline {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
|
|
s.Require().Fail(fmt.Sprintf("timeout waiting for waku connection status '%t'", wantedOnline))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-20 15:49:39 +00:00
|
|
|
func hasAllPeers(m map[string]types.WakuV2Peer, checkSlice []string) bool {
|
|
|
|
for _, check := range checkSlice {
|
|
|
|
if _, ok := m[check]; !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func WaitForPeersConnected(s *suite.Suite, waku *waku2.Waku, action func() []string) {
|
2024-02-16 18:34:04 +00:00
|
|
|
subscription := waku.SubscribeToConnStatusChanges()
|
|
|
|
defer subscription.Unsubscribe()
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// Action should return the desired peer ID
|
2024-02-20 15:49:39 +00:00
|
|
|
peerIDs := action()
|
|
|
|
if hasAllPeers(waku.Peers(), peerIDs) {
|
2024-02-16 18:34:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case status := <-subscription.C:
|
2024-02-20 15:49:39 +00:00
|
|
|
if hasAllPeers(status.Peers, peerIDs) {
|
2024-03-08 15:50:46 +00:00
|
|
|
// Give some time for p2p events, otherwise might look like peer is available, but fail to send a message.
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
2024-02-16 18:34:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-ctx.Done():
|
2024-02-20 15:49:39 +00:00
|
|
|
s.Require().Fail(fmt.Sprintf("timeout waiting for peers connected '%+v'", peerIDs))
|
2024-02-16 18:34:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 09:46:56 +00:00
|
|
|
func FindFirstByContentType(messages []*common.Message, contentType protobuf.ChatMessage_ContentType) *common.Message {
|
|
|
|
for _, message := range messages {
|
|
|
|
if message.ContentType == contentType {
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-10 13:57:52 +00:00
|
|
|
|
|
|
|
func PairDevices(s *suite.Suite, device1, device2 *Messenger) {
|
|
|
|
// Send pairing data
|
|
|
|
response, err := device1.SendPairInstallation(context.Background(), nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Len(response.Chats(), 1)
|
|
|
|
s.False(response.Chats()[0].Active)
|
|
|
|
|
|
|
|
i, ok := device1.allInstallations.Load(device1.installationID)
|
|
|
|
s.Require().True(ok)
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
device2,
|
|
|
|
func(r *MessengerResponse) bool {
|
feat(pairing)!: Add fallback flow to pairing
feat(pairing)!: add fallback flow to pairing
This commit includes the following changes:
*Breaking change in connection string*
The local pairing code that was parsing the connection string had a few non-upgradable features:
- It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
- It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
- Version is not used. Better not to use something than to use it wrongly, rarely version is needed if the protocol is correctly upgraded.
- Two parameters have been added, `installation-id` and `key-uid`. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing should be supported (a new might be able to parse a v2 client, but not the other way around). It is to be considered a complete breaking change. 2.30 -> 2.30 syncing only is supported, but going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
*Changed `MessengerResponse` to use internally a map of `installations` rather than an array (minor)*
Just moving towards maps as arrays tend to lead to subtle bugs.
*Moved pairing methods to messenger_pairing.go*
Just moved some methods
*Added 2 new methods for the fallback flow*
`FinishPairingThroughSeedPhraseProcess`
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
`EnableAndSyncInstallation`
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
*Flow for clients*
Client A1 is logged in
Client A2 is logged out
1) Client A1 shows a QR code
2) Client A2 scans a QR code
3) If connection fails on A2, the user will be prompted to enter a seed phrase.
4) If the generated account matches the `key-uid` from the QR code, A2 should call `FinishPairingThroughSeedPhraseProcess` with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
5) Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to `Enable and Sync`, which should call the `EnableAndSyncInstallation` endpoint. This should finish the fallback syncing flow.
*Current issues*
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the `DisplayName` is not changed on the receiving device. I haven't had time to look into it further.
2024-07-15 18:29:24 +00:00
|
|
|
for _, installation := range r.Installations() {
|
2023-08-10 13:57:52 +00:00
|
|
|
if installation.ID == device1.installationID {
|
|
|
|
return installation.InstallationMetadata != nil &&
|
|
|
|
i.InstallationMetadata.Name == installation.InstallationMetadata.Name &&
|
|
|
|
i.InstallationMetadata.DeviceType == installation.InstallationMetadata.DeviceType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
},
|
|
|
|
"installation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
// Ensure installation is enabled
|
|
|
|
err = device2.EnableInstallation(device1.installationID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
2023-10-24 10:15:32 +00:00
|
|
|
|
2023-11-13 20:07:35 +00:00
|
|
|
func SetSettingsAndWaitForChange(s *suite.Suite, messenger *Messenger, timeout time.Duration,
|
|
|
|
actionCallback func(), eventCallback func(*SelfContactChangeEvent) bool) {
|
|
|
|
|
|
|
|
allEventsReceived := false
|
|
|
|
channel := messenger.SubscribeToSelfContactChanges()
|
2023-10-24 10:15:32 +00:00
|
|
|
wg := sync.WaitGroup{}
|
2023-11-13 20:07:35 +00:00
|
|
|
wg.Add(1)
|
2023-10-24 10:15:32 +00:00
|
|
|
|
2023-11-13 20:07:35 +00:00
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
for !allEventsReceived {
|
|
|
|
select {
|
|
|
|
case event := <-channel:
|
|
|
|
allEventsReceived = eventCallback(event)
|
|
|
|
case <-time.After(timeout):
|
|
|
|
return
|
2023-10-24 10:15:32 +00:00
|
|
|
}
|
2023-11-13 20:07:35 +00:00
|
|
|
}
|
|
|
|
}()
|
2023-10-24 10:15:32 +00:00
|
|
|
|
|
|
|
actionCallback()
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
2023-11-13 20:07:35 +00:00
|
|
|
s.Require().True(allEventsReceived)
|
2023-10-24 10:15:32 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 20:07:35 +00:00
|
|
|
func SetIdentityImagesAndWaitForChange(s *suite.Suite, messenger *Messenger, timeout time.Duration, actionCallback func()) {
|
|
|
|
channel := messenger.SubscribeToSelfContactChanges()
|
2023-10-24 10:15:32 +00:00
|
|
|
ok := false
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
select {
|
2023-11-13 20:07:35 +00:00
|
|
|
case event := <-channel:
|
|
|
|
if event.ImagesChanged {
|
|
|
|
ok = true
|
|
|
|
}
|
2023-10-24 10:15:32 +00:00
|
|
|
case <-time.After(timeout):
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
actionCallback()
|
|
|
|
|
|
|
|
wg.Wait()
|
2023-11-13 20:07:35 +00:00
|
|
|
|
2023-10-24 10:15:32 +00:00
|
|
|
s.Require().True(ok)
|
|
|
|
}
|
2023-11-25 23:24:20 +00:00
|
|
|
|
|
|
|
func WaitForAvailableStoreNode(s *suite.Suite, m *Messenger, timeout time.Duration) {
|
2023-12-15 19:50:12 +00:00
|
|
|
available := m.waitForAvailableStoreNode(timeout)
|
|
|
|
s.Require().True(available)
|
2023-11-25 23:24:20 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 17:01:13 +00:00
|
|
|
func TearDownMessenger(s *suite.Suite, m *Messenger) {
|
2023-12-27 13:53:19 +00:00
|
|
|
if m == nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-27 17:01:13 +00:00
|
|
|
s.Require().NoError(m.Shutdown())
|
|
|
|
if m.database != nil {
|
|
|
|
s.Require().NoError(m.database.Close())
|
|
|
|
}
|
|
|
|
if m.multiAccounts != nil {
|
|
|
|
s.Require().NoError(m.multiAccounts.Close())
|
|
|
|
}
|
|
|
|
}
|
2023-12-15 19:50:12 +00:00
|
|
|
|
|
|
|
func randomInt(length int) int {
|
|
|
|
max := big.NewInt(int64(length))
|
|
|
|
value, err := rand.Int(rand.Reader, max)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return int(value.Int64())
|
|
|
|
}
|
|
|
|
|
|
|
|
func randomString(length int, runes []rune) string {
|
|
|
|
out := make([]rune, length)
|
|
|
|
for i := range out {
|
|
|
|
out[i] = runes[randomInt(len(runes))] // nolint: gosec
|
|
|
|
}
|
|
|
|
return string(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RandomLettersString(length int) string {
|
|
|
|
return randomString(length, letterRunes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RandomColor() string {
|
|
|
|
return "#" + randomString(6, hexRunes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RandomCommunityTags(count int) []string {
|
2024-03-26 20:02:12 +00:00
|
|
|
availableTagsCount := requests.AvailableTagsCount()
|
2023-12-15 19:50:12 +00:00
|
|
|
|
2024-03-26 20:02:12 +00:00
|
|
|
if count > availableTagsCount {
|
|
|
|
count = availableTagsCount
|
2023-12-15 19:50:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 20:02:12 +00:00
|
|
|
//source := mathRand.New(mathRand.NewSource(time.Now().UnixNano()))
|
|
|
|
indices := mathRand.Perm(availableTagsCount)
|
|
|
|
shuffled := make([]string, count)
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
shuffled[i] = requests.TagByIndex(uint32(indices[i]))
|
2023-12-15 19:50:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 20:02:12 +00:00
|
|
|
return shuffled
|
2023-12-15 19:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func RandomBytes(length int) []byte {
|
|
|
|
out := make([]byte, length)
|
|
|
|
_, err := rand.Read(out)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
2024-02-17 18:07:20 +00:00
|
|
|
|
2024-02-22 08:08:58 +00:00
|
|
|
func DummyProfileShowcasePreferences(withCollectibles bool) *identity.ProfileShowcasePreferences {
|
|
|
|
preferences := &identity.ProfileShowcasePreferences{
|
2024-03-29 10:22:44 +00:00
|
|
|
Communities: []*identity.ProfileShowcaseCommunityPreference{
|
|
|
|
{
|
|
|
|
CommunityID: "0x254254546768764565565",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CommunityID: "0x865241434343432412343",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
},
|
|
|
|
},
|
2024-02-17 18:07:20 +00:00
|
|
|
Accounts: []*identity.ProfileShowcaseAccountPreference{
|
|
|
|
{
|
2024-02-22 08:08:58 +00:00
|
|
|
Address: "0x0000000000000000000000000033433445133423",
|
2024-02-17 18:07:20 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
{
|
2024-02-22 08:08:58 +00:00
|
|
|
Address: "0x0000000000000000000000000032433445133424",
|
2024-02-17 18:07:20 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
VerifiedTokens: []*identity.ProfileShowcaseVerifiedTokenPreference{
|
|
|
|
{
|
|
|
|
Symbol: "ETH",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Symbol: "DAI",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityIDVerifiedContacts,
|
|
|
|
Order: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Symbol: "SNT",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityNoOne,
|
|
|
|
Order: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
UnverifiedTokens: []*identity.ProfileShowcaseUnverifiedTokenPreference{
|
|
|
|
{
|
|
|
|
ContractAddress: "0x454525452023452",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 11155111,
|
2024-02-17 18:07:20 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ContractAddress: "0x12312323323233",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 1,
|
2024-02-17 18:07:20 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
2024-02-26 13:53:40 +00:00
|
|
|
SocialLinks: []*identity.ProfileShowcaseSocialLinkPreference{
|
|
|
|
&identity.ProfileShowcaseSocialLinkPreference{
|
|
|
|
Text: identity.TwitterID,
|
|
|
|
URL: "https://twitter.com/ethstatus",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
&identity.ProfileShowcaseSocialLinkPreference{
|
|
|
|
Text: identity.TwitterID,
|
|
|
|
URL: "https://twitter.com/StatusIMBlog",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityIDVerifiedContacts,
|
|
|
|
Order: 2,
|
|
|
|
},
|
|
|
|
&identity.ProfileShowcaseSocialLinkPreference{
|
|
|
|
Text: identity.GithubID,
|
|
|
|
URL: "https://github.com/status-im",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
Order: 3,
|
|
|
|
},
|
|
|
|
},
|
2024-02-17 18:07:20 +00:00
|
|
|
}
|
2024-02-22 08:08:58 +00:00
|
|
|
|
|
|
|
if withCollectibles {
|
|
|
|
preferences.Collectibles = []*identity.ProfileShowcaseCollectiblePreference{
|
|
|
|
{
|
|
|
|
ContractAddress: "0x12378534257568678487683576",
|
|
|
|
ChainID: 1,
|
|
|
|
TokenID: "12321389592999903",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
preferences.Collectibles = []*identity.ProfileShowcaseCollectiblePreference{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return preferences
|
2024-02-17 18:07:20 +00:00
|
|
|
}
|