2023-11-09 18:59:01 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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{
|
2023-11-09 18:59:01 +00:00
|
|
|
Address: "0x32433445133424",
|
|
|
|
Name: "Status Account",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
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{
|
2023-11-09 18:59:01 +00:00
|
|
|
Address: "0x3845354643324",
|
|
|
|
Name: "Money Box",
|
|
|
|
ColorID: "red",
|
|
|
|
Emoji: ":o)",
|
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",
|
|
|
|
ChainID: 3,
|
|
|
|
TokenID: "0x12321389592999f903",
|
|
|
|
CommunityID: "0x01312357798976535",
|
|
|
|
AccountAddress: "0x32433445133424",
|
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,
|
|
|
|
CommunityID: "0x32433445133424",
|
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",
|
|
|
|
ChainID: 2,
|
|
|
|
CommunityID: "",
|
2024-02-15 19:13:12 +00:00
|
|
|
ShowcaseVisibility: identity.ProfileShowcaseVisibilityContacts,
|
2024-01-25 16:48:27 +00:00
|
|
|
Order: 1,
|
|
|
|
},
|
|
|
|
},
|
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-01-25 16:48:27 +00:00
|
|
|
s.Require().Equal(len(preferencesBack.Communities), len(preferences.Communities))
|
|
|
|
for i := 0; i < len(preferences.Communities); i++ {
|
|
|
|
s.Require().Equal(*preferences.Communities[i], *preferencesBack.Communities[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(len(preferencesBack.Accounts), len(preferences.Accounts))
|
|
|
|
for i := 0; i < len(preferences.Accounts); i++ {
|
|
|
|
s.Require().Equal(*preferences.Accounts[i], *preferencesBack.Accounts[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(len(preferencesBack.Collectibles), len(preferences.Collectibles))
|
|
|
|
for i := 0; i < len(preferences.Collectibles); i++ {
|
|
|
|
s.Require().Equal(*preferences.Collectibles[i], *preferencesBack.Collectibles[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(len(preferencesBack.VerifiedTokens), len(preferences.VerifiedTokens))
|
|
|
|
for i := 0; i < len(preferences.VerifiedTokens); i++ {
|
|
|
|
s.Require().Equal(*preferences.VerifiedTokens[i], *preferencesBack.VerifiedTokens[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().Equal(len(preferencesBack.UnverifiedTokens), len(preferences.UnverifiedTokens))
|
|
|
|
for i := 0; i < len(preferences.UnverifiedTokens); i++ {
|
|
|
|
s.Require().Equal(*preferences.UnverifiedTokens[i], *preferencesBack.UnverifiedTokens[i])
|
|
|
|
}
|
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",
|
|
|
|
Address: "0x3845354643324",
|
|
|
|
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",
|
|
|
|
ChainID: 2,
|
|
|
|
TokenID: "0x12321389592999f903",
|
|
|
|
CommunityID: "0x01312357798976535",
|
|
|
|
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,
|
|
|
|
CommunityID: "",
|
|
|
|
Order: 0,
|
|
|
|
},
|
2024-02-15 19:13:12 +00:00
|
|
|
&identity.ProfileShowcaseUnverifiedToken{
|
2024-01-25 16:48:27 +00:00
|
|
|
ContractAddress: "0x12312323323233",
|
|
|
|
ChainID: 2,
|
|
|
|
CommunityID: "0x32433445133424",
|
|
|
|
Order: 1,
|
|
|
|
},
|
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",
|
|
|
|
ChainID: 2,
|
|
|
|
TokenID: "0x12321389592999f903",
|
|
|
|
CommunityID: "0x01312357798976535",
|
|
|
|
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])
|
|
|
|
}
|
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))
|
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)
|
|
|
|
|
|
|
|
deleteAccountAddress := "0x3243344513424"
|
|
|
|
updateAccountAddress := "0x3845354643324"
|
|
|
|
|
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,
|
|
|
|
Name: "Status Account",
|
|
|
|
ColorID: "blue",
|
|
|
|
Emoji: "-_-",
|
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,
|
|
|
|
Name: "Money Box",
|
|
|
|
ColorID: "red",
|
|
|
|
Emoji: ":o)",
|
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])
|
|
|
|
|
|
|
|
account.Name = "Music Box"
|
|
|
|
account.ColorID = "green"
|
|
|
|
account.Emoji = ">:-]"
|
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])
|
|
|
|
}
|