2023-11-09 18:59:01 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2024-03-08 16:20:23 +00:00
|
|
|
"reflect"
|
2023-11-09 18:59:01 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2024-02-15 19:13:12 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/protocol/identity"
|
2023-11-09 18:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProfileShowcasePersistenceSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(TestProfileShowcasePersistence))
|
|
|
|
}
|
|
|
|
|
|
|
|
type TestProfileShowcasePersistence struct {
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestProfileShowcasePersistence) TestProfileShowcasePreferences() {
|
|
|
|
db, err := openTestDB()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
persistence := newSQLitePersistence(db)
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
preferences := &identity.ProfileShowcasePreferences{
|
|
|
|
Communities: []*identity.ProfileShowcaseCommunityPreference{
|
|
|
|
&identity.ProfileShowcaseCommunityPreference{
|
2023-11-09 18:59:01 +00:00
|
|
|
CommunityID: "0x32433445133424",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2023-11-09 18:59:01 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
Accounts: []*identity.ProfileShowcaseAccountPreference{
|
|
|
|
&identity.ProfileShowcaseAccountPreference{
|
2024-02-22 08:08:58 +00:00
|
|
|
Address: "0x0000000000000000000000000032433445133422",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2023-11-09 18:59:01 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseAccountPreference{
|
2024-02-22 08:08:58 +00:00
|
|
|
Address: "0x0000000000000000000000000032433445133424",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
2023-11-09 18:59:01 +00:00
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
Collectibles: []*identity.ProfileShowcaseCollectiblePreference{
|
|
|
|
&identity.ProfileShowcaseCollectiblePreference{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x12378534257568678487683576",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 11155111,
|
|
|
|
TokenID: "123213895929994903",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2023-11-09 18:59:01 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
2024-01-25 16:48:27 +00:00
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
VerifiedTokens: []*identity.ProfileShowcaseVerifiedTokenPreference{
|
|
|
|
&identity.ProfileShowcaseVerifiedTokenPreference{
|
2024-01-25 16:48:27 +00:00
|
|
|
Symbol: "ETH",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2024-01-25 16:48:27 +00:00
|
|
|
Order: 1,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseVerifiedTokenPreference{
|
2023-11-09 18:59:01 +00:00
|
|
|
Symbol: "DAI",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityIDVerifiedContacts,
|
2023-11-09 18:59:01 +00:00
|
|
|
Order: 2,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseVerifiedTokenPreference{
|
2023-11-09 18:59:01 +00:00
|
|
|
Symbol: "SNT",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityNoOne,
|
2023-11-09 18:59:01 +00:00
|
|
|
Order: 3,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
UnverifiedTokens: []*identity.ProfileShowcaseUnverifiedTokenPreference{
|
|
|
|
&identity.ProfileShowcaseUnverifiedTokenPreference{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x454525452023452",
|
|
|
|
ChainID: 1,
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2024-01-25 16:48:27 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseUnverifiedTokenPreference{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x12312323323233",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 11155111,
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
2024-01-25 16:48:27 +00:00
|
|
|
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.ProfileShowcaseVisibilityContacts,
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = persistence.SaveProfileShowcasePreferences(preferences)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
preferencesBack, err := persistence.GetProfileShowcasePreferences()
|
|
|
|
s.Require().NoError(err)
|
2024-03-08 16:20:23 +00:00
|
|
|
s.Require().True(reflect.DeepEqual(preferences, preferencesBack))
|
2023-11-09 18:59:01 +00:00
|
|
|
|
2024-03-08 16:20:23 +00:00
|
|
|
newPreferences := &identity.ProfileShowcasePreferences{
|
|
|
|
Communities: []*identity.ProfileShowcaseCommunityPreference{
|
|
|
|
&identity.ProfileShowcaseCommunityPreference{
|
|
|
|
CommunityID: "0x32433445133424",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Accounts: []*identity.ProfileShowcaseAccountPreference{
|
|
|
|
&identity.ProfileShowcaseAccountPreference{
|
|
|
|
Address: "0x0000000000000000000000000032433445133422",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Collectibles: []*identity.ProfileShowcaseCollectiblePreference{},
|
|
|
|
VerifiedTokens: []*identity.ProfileShowcaseVerifiedTokenPreference{
|
|
|
|
&identity.ProfileShowcaseVerifiedTokenPreference{
|
|
|
|
Symbol: "ETH",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
UnverifiedTokens: []*identity.ProfileShowcaseUnverifiedTokenPreference{
|
|
|
|
&identity.ProfileShowcaseUnverifiedTokenPreference{
|
|
|
|
ContractAddress: "0x12312323323233",
|
|
|
|
ChainID: 11155111,
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SocialLinks: []*identity.ProfileShowcaseSocialLinkPreference{
|
|
|
|
&identity.ProfileShowcaseSocialLinkPreference{
|
|
|
|
Text: identity.TwitterID,
|
|
|
|
URL: "https://twitter.com/ethstatus",
|
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
2024-01-25 16:48:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 16:20:23 +00:00
|
|
|
err = persistence.SaveProfileShowcasePreferences(newPreferences)
|
|
|
|
s.Require().NoError(err)
|
2024-02-26 13:53:40 +00:00
|
|
|
|
2024-03-08 16:20:23 +00:00
|
|
|
preferencesBack, err = persistence.GetProfileShowcasePreferences()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(reflect.DeepEqual(newPreferences, preferencesBack))
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestProfileShowcasePersistence) TestProfileShowcaseContacts() {
|
|
|
|
db, err := openTestDB()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
persistence := newSQLitePersistence(db)
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
showcase1 := &identity.ProfileShowcase{
|
2023-11-09 18:59:01 +00:00
|
|
|
ContactID: "contact_1",
|
2024-02-15 19:13:12 +00:00
|
|
|
Communities: []*identity.ProfileShowcaseCommunity{
|
|
|
|
&identity.ProfileShowcaseCommunity{
|
2023-11-09 18:59:01 +00:00
|
|
|
CommunityID: "0x012312234234234",
|
|
|
|
Order: 6,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseCommunity{
|
2023-11-09 18:59:01 +00:00
|
|
|
CommunityID: "0x04523233466753",
|
|
|
|
Order: 7,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
Accounts: []*identity.ProfileShowcaseAccount{
|
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_1",
|
|
|
|
Address: "0x32433445133424",
|
|
|
|
Name: "Status Account",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
|
|
|
Order: 0,
|
2024-01-25 16:48:27 +00:00
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_1",
|
2024-02-22 08:08:58 +00:00
|
|
|
Address: "0x0000000000000000000000000032433445133424",
|
2024-01-25 13:29:29 +00:00
|
|
|
Name: "Money Box",
|
|
|
|
ColorID: "red",
|
|
|
|
Emoji: ":o)",
|
|
|
|
Order: 1,
|
2024-01-25 16:48:27 +00:00
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
Collectibles: []*identity.ProfileShowcaseCollectible{
|
|
|
|
&identity.ProfileShowcaseCollectible{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x12378534257568678487683576",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 1,
|
|
|
|
TokenID: "123213895929994903",
|
2024-01-25 16:48:27 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
VerifiedTokens: []*identity.ProfileShowcaseVerifiedToken{
|
|
|
|
&identity.ProfileShowcaseVerifiedToken{
|
2023-11-09 18:59:01 +00:00
|
|
|
Symbol: "ETH",
|
|
|
|
Order: 1,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseVerifiedToken{
|
2024-01-25 16:48:27 +00:00
|
|
|
Symbol: "DAI",
|
|
|
|
Order: 2,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseVerifiedToken{
|
2024-01-25 16:48:27 +00:00
|
|
|
Symbol: "SNT",
|
|
|
|
Order: 3,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
UnverifiedTokens: []*identity.ProfileShowcaseUnverifiedToken{
|
|
|
|
&identity.ProfileShowcaseUnverifiedToken{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x454525452023452",
|
|
|
|
ChainID: 1,
|
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseUnverifiedToken{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x12312323323233",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 11155111,
|
2024-01-25 16:48:27 +00:00
|
|
|
Order: 1,
|
|
|
|
},
|
2023-11-09 18:59:01 +00:00
|
|
|
},
|
2024-02-26 13:53:40 +00:00
|
|
|
SocialLinks: []*identity.ProfileShowcaseSocialLink{
|
|
|
|
&identity.ProfileShowcaseSocialLink{
|
|
|
|
URL: "https://status.app/",
|
|
|
|
Text: "Status",
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
&identity.ProfileShowcaseSocialLink{
|
|
|
|
URL: "https://github.com/status-im",
|
|
|
|
Text: "Github",
|
|
|
|
Order: 2,
|
|
|
|
},
|
|
|
|
},
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
|
|
|
err = persistence.SaveProfileShowcaseForContact(showcase1)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
showcase2 := &identity.ProfileShowcase{
|
2023-11-09 18:59:01 +00:00
|
|
|
ContactID: "contact_2",
|
2024-02-15 19:13:12 +00:00
|
|
|
Communities: []*identity.ProfileShowcaseCommunity{
|
|
|
|
&identity.ProfileShowcaseCommunity{
|
2023-11-09 18:59:01 +00:00
|
|
|
CommunityID: "0x012312234234234", // same id to check query
|
|
|
|
Order: 3,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseCommunity{
|
2023-11-09 18:59:01 +00:00
|
|
|
CommunityID: "0x096783478384593",
|
|
|
|
Order: 7,
|
|
|
|
},
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
Collectibles: []*identity.ProfileShowcaseCollectible{
|
|
|
|
&identity.ProfileShowcaseCollectible{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x12378534257568678487683576",
|
2024-02-22 08:08:58 +00:00
|
|
|
ChainID: 1,
|
|
|
|
TokenID: "123213895929994903",
|
2024-01-25 16:48:27 +00:00
|
|
|
Order: 1,
|
2023-11-09 18:59:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err = persistence.SaveProfileShowcaseForContact(showcase2)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
showcase1Back, err := persistence.GetProfileShowcaseForContact("contact_1")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal(len(showcase1.Communities), len(showcase1Back.Communities))
|
2024-01-25 16:48:27 +00:00
|
|
|
for i := 0; i < len(showcase1.Communities); i++ {
|
|
|
|
s.Require().Equal(*showcase1.Communities[i], *showcase1Back.Communities[i])
|
|
|
|
}
|
|
|
|
s.Require().Equal(len(showcase1.Accounts), len(showcase1Back.Accounts))
|
|
|
|
for i := 0; i < len(showcase1.Accounts); i++ {
|
|
|
|
s.Require().Equal(*showcase1.Accounts[i], *showcase1Back.Accounts[i])
|
|
|
|
}
|
|
|
|
s.Require().Equal(len(showcase1.Collectibles), len(showcase1Back.Collectibles))
|
|
|
|
for i := 0; i < len(showcase1.Collectibles); i++ {
|
|
|
|
s.Require().Equal(*showcase1.Collectibles[i], *showcase1Back.Collectibles[i])
|
|
|
|
}
|
|
|
|
s.Require().Equal(len(showcase1.VerifiedTokens), len(showcase1Back.VerifiedTokens))
|
|
|
|
for i := 0; i < len(showcase1.VerifiedTokens); i++ {
|
|
|
|
s.Require().Equal(*showcase1.VerifiedTokens[i], *showcase1Back.VerifiedTokens[i])
|
|
|
|
}
|
|
|
|
s.Require().Equal(len(showcase1.UnverifiedTokens), len(showcase1Back.UnverifiedTokens))
|
|
|
|
for i := 0; i < len(showcase1.UnverifiedTokens); i++ {
|
|
|
|
s.Require().Equal(*showcase1.UnverifiedTokens[i], *showcase1Back.UnverifiedTokens[i])
|
|
|
|
}
|
2024-02-26 13:53:40 +00:00
|
|
|
s.Require().Equal(len(showcase1.SocialLinks), len(showcase1Back.SocialLinks))
|
|
|
|
for i := 0; i < len(showcase1.SocialLinks); i++ {
|
|
|
|
s.Require().Equal(*showcase1.SocialLinks[i], *showcase1Back.SocialLinks[i])
|
|
|
|
}
|
2023-11-09 18:59:01 +00:00
|
|
|
|
|
|
|
showcase2Back, err := persistence.GetProfileShowcaseForContact("contact_2")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal(len(showcase2.Communities), len(showcase2Back.Communities))
|
|
|
|
s.Require().Equal(*showcase2.Communities[0], *showcase2Back.Communities[0])
|
|
|
|
s.Require().Equal(*showcase2.Communities[1], *showcase2Back.Communities[1])
|
|
|
|
s.Require().Equal(len(showcase2.Collectibles), len(showcase2Back.Collectibles))
|
|
|
|
s.Require().Equal(*showcase2.Collectibles[0], *showcase2Back.Collectibles[0])
|
|
|
|
s.Require().Equal(0, len(showcase2Back.Accounts))
|
2024-01-25 16:48:27 +00:00
|
|
|
s.Require().Equal(0, len(showcase2Back.VerifiedTokens))
|
|
|
|
s.Require().Equal(0, len(showcase2Back.UnverifiedTokens))
|
2024-02-26 13:53:40 +00:00
|
|
|
s.Require().Equal(0, len(showcase2Back.SocialLinks))
|
2023-11-09 18:59:01 +00:00
|
|
|
}
|
2024-01-25 13:29:29 +00:00
|
|
|
|
|
|
|
func (s *TestProfileShowcasePersistence) TestFetchingProfileShowcaseAccountsByAddress() {
|
|
|
|
db, err := openTestDB()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
persistence := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
conatacts := []*Contact{
|
|
|
|
&Contact{
|
|
|
|
ID: "contact_1",
|
|
|
|
},
|
|
|
|
&Contact{
|
|
|
|
ID: "contact_2",
|
|
|
|
},
|
|
|
|
&Contact{
|
|
|
|
ID: "contact_3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = persistence.SaveContacts(conatacts)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
showcase1 := &identity.ProfileShowcase{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_1",
|
2024-02-15 19:13:12 +00:00
|
|
|
Accounts: []*identity.ProfileShowcaseAccount{
|
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_1",
|
|
|
|
Address: "0x0000000000000000000000000000000000000001",
|
|
|
|
Name: "Contact1-Account1",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_1",
|
|
|
|
Address: "0x0000000000000000000000000000000000000002",
|
|
|
|
Name: "Contact1-Account2",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-02-15 19:13:12 +00:00
|
|
|
showcase2 := &identity.ProfileShowcase{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_2",
|
2024-02-15 19:13:12 +00:00
|
|
|
Accounts: []*identity.ProfileShowcaseAccount{
|
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_2",
|
|
|
|
Address: "0x0000000000000000000000000000000000000001",
|
|
|
|
Name: "Contact2-Account1",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_2",
|
|
|
|
Address: "0x0000000000000000000000000000000000000002",
|
|
|
|
Name: "Contact2-Account2",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-02-15 19:13:12 +00:00
|
|
|
showcase3 := &identity.ProfileShowcase{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_3",
|
2024-02-15 19:13:12 +00:00
|
|
|
Accounts: []*identity.ProfileShowcaseAccount{
|
|
|
|
&identity.ProfileShowcaseAccount{
|
2024-01-25 13:29:29 +00:00
|
|
|
ContactID: "contact_3",
|
|
|
|
Address: "0x0000000000000000000000000000000000000001",
|
|
|
|
Name: "Contact3-Account1",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
|
|
|
Order: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = persistence.SaveProfileShowcaseForContact(showcase1)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
err = persistence.SaveProfileShowcaseForContact(showcase2)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
err = persistence.SaveProfileShowcaseForContact(showcase3)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
showcaseAccounts, err := persistence.GetProfileShowcaseAccountsByAddress(showcase1.Accounts[0].Address)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal(3, len(showcaseAccounts))
|
|
|
|
for i := 0; i < len(showcaseAccounts); i++ {
|
|
|
|
if showcaseAccounts[i].ContactID == showcase1.ContactID {
|
|
|
|
s.Require().Equal(showcase1.Accounts[0].Address, showcase1.Accounts[0].Address)
|
|
|
|
} else if showcaseAccounts[i].ContactID == showcase2.ContactID {
|
|
|
|
s.Require().Equal(showcase2.Accounts[0].Address, showcase2.Accounts[0].Address)
|
|
|
|
} else if showcaseAccounts[i].ContactID == showcase3.ContactID {
|
|
|
|
s.Require().Equal(showcase3.Accounts[0].Address, showcase3.Accounts[0].Address)
|
|
|
|
} else {
|
|
|
|
s.Require().Fail("unexpected contact id")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
showcaseAccounts, err = persistence.GetProfileShowcaseAccountsByAddress(showcase1.Accounts[1].Address)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal(2, len(showcaseAccounts))
|
|
|
|
for i := 0; i < len(showcaseAccounts); i++ {
|
|
|
|
if showcaseAccounts[i].ContactID == showcase1.ContactID {
|
|
|
|
s.Require().Equal(showcase1.Accounts[0].Address, showcase1.Accounts[0].Address)
|
|
|
|
} else if showcaseAccounts[i].ContactID == showcase2.ContactID {
|
|
|
|
s.Require().Equal(showcase2.Accounts[0].Address, showcase2.Accounts[0].Address)
|
|
|
|
} else {
|
|
|
|
s.Require().Fail("unexpected contact id")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-07 09:30:56 +00:00
|
|
|
|
|
|
|
func (s *TestProfileShowcasePersistence) TestUpdateProfileShowcaseAccountOnWalletAccountChange() {
|
|
|
|
db, err := openTestDB()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
persistence := newSQLitePersistence(db)
|
|
|
|
|
2024-02-22 08:08:58 +00:00
|
|
|
deleteAccountAddress := "0x0000000000000000000000000033433445133423"
|
|
|
|
updateAccountAddress := "0x0000000000000000000000000032433445133424"
|
2024-02-07 09:30:56 +00:00
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
preferences := &identity.ProfileShowcasePreferences{
|
|
|
|
Accounts: []*identity.ProfileShowcaseAccountPreference{
|
|
|
|
&identity.ProfileShowcaseAccountPreference{
|
2024-02-07 09:30:56 +00:00
|
|
|
Address: deleteAccountAddress,
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2024-02-07 09:30:56 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseAccountPreference{
|
2024-02-07 09:30:56 +00:00
|
|
|
Address: updateAccountAddress,
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
2024-02-07 09:30:56 +00:00
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = persistence.SaveProfileShowcasePreferences(preferences)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
account, err := persistence.GetProfileShowcaseAccountPreference(updateAccountAddress)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(account)
|
|
|
|
s.Require().Equal(*account, *preferences.Accounts[1])
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
account.ShowcaseVisibility = identity.ProfileShowcaseVisibilityIDVerifiedContacts
|
2024-02-07 09:30:56 +00:00
|
|
|
account.Order = 7
|
|
|
|
|
|
|
|
err = persistence.SaveProfileShowcaseAccountPreference(account)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2024-02-09 09:37:54 +00:00
|
|
|
deleted, err := persistence.DeleteProfileShowcaseAccountPreference(deleteAccountAddress)
|
2024-02-07 09:30:56 +00:00
|
|
|
s.Require().NoError(err)
|
2024-02-09 09:37:54 +00:00
|
|
|
s.Require().True(deleted)
|
|
|
|
|
|
|
|
// One more time to check correct error handling
|
|
|
|
deleted, err = persistence.DeleteProfileShowcaseAccountPreference(deleteAccountAddress)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(deleted)
|
2024-02-07 09:30:56 +00:00
|
|
|
|
|
|
|
preferencesBack, err := persistence.GetProfileShowcasePreferences()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Len(preferencesBack.Accounts, 1)
|
|
|
|
s.Require().Equal(*preferencesBack.Accounts[0], *account)
|
|
|
|
}
|
2024-02-09 09:37:54 +00:00
|
|
|
|
|
|
|
func (s *TestProfileShowcasePersistence) TestUpdateProfileShowcaseCommunityOnChange() {
|
|
|
|
db, err := openTestDB()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
persistence := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
deleteCommunityID := "0x3243344513424"
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
preferences := &identity.ProfileShowcasePreferences{
|
|
|
|
Communities: []*identity.ProfileShowcaseCommunityPreference{
|
|
|
|
&identity.ProfileShowcaseCommunityPreference{
|
2024-02-09 09:37:54 +00:00
|
|
|
CommunityID: "0x32433445133424",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityEveryone,
|
2024-02-09 09:37:54 +00:00
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseCommunityPreference{
|
2024-02-09 09:37:54 +00:00
|
|
|
CommunityID: deleteCommunityID,
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
2024-02-09 09:37:54 +00:00
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = persistence.SaveProfileShowcasePreferences(preferences)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
deleted, err := persistence.DeleteProfileShowcaseCommunityPreference(deleteCommunityID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(deleted)
|
|
|
|
|
|
|
|
// One more time to check correct error handling
|
|
|
|
deleted, err = persistence.DeleteProfileShowcaseCommunityPreference(deleteCommunityID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(deleted)
|
|
|
|
|
|
|
|
preferencesBack, err := persistence.GetProfileShowcasePreferences()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Len(preferencesBack.Communities, 1)
|
|
|
|
s.Require().Equal(*preferencesBack.Communities[0], *preferences.Communities[0])
|
|
|
|
}
|