tests: `GetProfileKeypairForTest` from test helper updated and provides higher granularity

This commit is contained in:
Sale Djenic 2023-05-24 16:40:40 +02:00 committed by saledjenic
parent 0eca7f5088
commit 20f38bf62b
7 changed files with 45 additions and 41 deletions

View File

@ -178,7 +178,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
func TestKeypairs(t *testing.T) {
keypairs := []*Keypair{
GetProfileKeypairForTest(false),
GetProfileKeypairForTest(true, true, true),
GetSeedImportedKeypair1ForTest(),
GetPrivKeyImportedKeypairForTest(), // in this context (when testing db functions) there is not limitations for private key imported keypair
}

View File

@ -14,7 +14,7 @@ func TestKeycards(t *testing.T) {
keycardUID := "00000000000000000000000000000000"
kp1 := GetProfileKeypairForTest(false)
kp1 := GetProfileKeypairForTest(true, true, true)
keycard1 := GetProfileKeycardForTest()
kp2 := GetSeedImportedKeypair1ForTest()

View File

@ -30,7 +30,7 @@ func GetWatchOnlyAccountsForTest() []*Account {
return []*Account{wo1, wo2, wo3}
}
func GetProfileKeypairForTest(onlyChatAndDefaultWalletAccount bool) *Keypair {
func GetProfileKeypairForTest(includeChatAccount bool, includeDefaultWalletAccount bool, includeAdditionalAccounts bool) *Keypair {
kp := &Keypair{
KeyUID: "0000000000000000000000000000000000000000000000000000000000000001",
Name: "Profile Name",
@ -38,39 +38,43 @@ func GetProfileKeypairForTest(onlyChatAndDefaultWalletAccount bool) *Keypair {
DerivedFrom: "0x0001",
}
profileAccount := &Account{
Address: types.Address{0x01},
KeyUID: kp.KeyUID,
Wallet: false,
Chat: true,
Type: AccountTypeGenerated,
Path: "m/43'/60'/1581'/0'/0",
PublicKey: types.Hex2Bytes("0x000000001"),
Name: "Profile Name",
Operable: AccountFullyOperable,
if includeChatAccount {
profileAccount := &Account{
Address: types.Address{0x01},
KeyUID: kp.KeyUID,
Wallet: false,
Chat: true,
Type: AccountTypeGenerated,
Path: "m/43'/60'/1581'/0'/0",
PublicKey: types.Hex2Bytes("0x000000001"),
Name: "Profile Name",
Operable: AccountFullyOperable,
}
kp.Accounts = append(kp.Accounts, profileAccount)
}
kp.Accounts = append(kp.Accounts, profileAccount)
defaultWalletAccount := &Account{
Address: types.Address{0x02},
KeyUID: kp.KeyUID,
Wallet: true,
Chat: false,
Type: AccountTypeGenerated,
Path: "m/44'/60'/0'/0/0",
PublicKey: types.Hex2Bytes("0x000000002"),
Name: "Generated Acc 1",
Emoji: "emoji-1",
Color: "blue",
Hidden: false,
Clock: 0,
Removed: false,
Operable: AccountFullyOperable,
if includeDefaultWalletAccount {
defaultWalletAccount := &Account{
Address: types.Address{0x02},
KeyUID: kp.KeyUID,
Wallet: true,
Chat: false,
Type: AccountTypeGenerated,
Path: "m/44'/60'/0'/0/0",
PublicKey: types.Hex2Bytes("0x000000002"),
Name: "Generated Acc 1",
Emoji: "emoji-1",
Color: "blue",
Hidden: false,
Clock: 0,
Removed: false,
Operable: AccountFullyOperable,
}
kp.Accounts = append(kp.Accounts, defaultWalletAccount)
kp.LastUsedDerivationIndex = 0
}
kp.Accounts = append(kp.Accounts, defaultWalletAccount)
kp.LastUsedDerivationIndex = 0
if !onlyChatAndDefaultWalletAccount {
if includeAdditionalAccounts {
generatedWalletAccount1 := &Account{
Address: types.Address{0x03},
KeyUID: kp.KeyUID,
@ -241,7 +245,7 @@ func GetPrivKeyImportedKeypairForTest() *Keypair {
}
func GetProfileKeycardForTest() *Keycard {
profileKp := GetProfileKeypairForTest(false)
profileKp := GetProfileKeypairForTest(true, true, true)
keycard1Addresses := []types.Address{}
for _, acc := range profileKp.Accounts {
keycard1Addresses = append(keycard1Addresses, acc.Address)

View File

@ -675,7 +675,7 @@ func (s *MessengerBackupSuite) TestBackupCommunities() {
func (s *MessengerBackupSuite) TestBackupKeypairs() {
// Create bob1
bob1 := s.m
profileKp := accounts.GetProfileKeypairForTest(false)
profileKp := accounts.GetProfileKeypairForTest(true, true, true)
seedKp := accounts.GetSeedImportedKeypair1ForTest()
// Create a main account on bob1
@ -734,7 +734,7 @@ func (s *MessengerBackupSuite) TestBackupKeycards() {
// Create bob1
bob1 := s.m
kp1 := accounts.GetProfileKeypairForTest(false)
kp1 := accounts.GetProfileKeypairForTest(true, true, true)
keycard1 := accounts.GetProfileKeycardForTest()
kp2 := accounts.GetSeedImportedKeypair1ForTest()

View File

@ -76,7 +76,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
s.Require().NoError(err)
// Pre-condition - both sides have to know about keypairs migrated to a keycards
kp1 := accounts.GetProfileKeypairForTest(false)
kp1 := accounts.GetProfileKeypairForTest(true, true, true)
kp2 := accounts.GetSeedImportedKeypair1ForTest()
// kp3 := accounts.GetSeedImportedKeypair2ForTest()

View File

@ -76,7 +76,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
s.Require().NoError(err)
// Pre-condition - both sides have to know about keypairs migrated to a keycards
kp1 := accounts.GetProfileKeypairForTest(false)
kp1 := accounts.GetProfileKeypairForTest(true, true, true)
kp2 := accounts.GetSeedImportedKeypair1ForTest()
kp3 := accounts.GetSeedImportedKeypair2ForTest()

View File

@ -66,7 +66,7 @@ func (s *MessengerSyncWalletSuite) newMessenger(shh types.Waku) *Messenger {
}
func (s *MessengerSyncWalletSuite) TestSyncWallets() {
profileKp := accounts.GetProfileKeypairForTest(false)
profileKp := accounts.GetProfileKeypairForTest(true, true, true)
// Create a main account on alice
err := s.m.settings.SaveOrUpdateKeypair(profileKp)
@ -82,7 +82,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
s.Require().NoError(err)
// Store only chat and default wallet account on other device
profileKpOtherDevice := accounts.GetProfileKeypairForTest(true)
profileKpOtherDevice := accounts.GetProfileKeypairForTest(true, true, false)
err = alicesOtherDevice.settings.SaveOrUpdateKeypair(profileKpOtherDevice)
s.Require().NoError(err, "profile keypair alicesOtherDevice.settings.SaveOrUpdateKeypair")
@ -194,7 +194,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
s.Require().True(haveSameElements(dbAccounts1, dbAccounts2, accounts.SameAccounts))
// Update keypair name on alice's primary device
profileKpUpdated := accounts.GetProfileKeypairForTest(true)
profileKpUpdated := accounts.GetProfileKeypairForTest(true, true, false)
profileKpUpdated.Name = profileKp.Name + "Updated"
profileKpUpdated.Accounts = profileKp.Accounts[:0]
err = s.m.SaveOrUpdateKeypair(profileKpUpdated)
@ -222,7 +222,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
s.Require().Equal(profileKpUpdated.Name, dbProfileKp2.Name)
// Update accounts on alice's primary device
profileKpUpdated = accounts.GetProfileKeypairForTest(false)
profileKpUpdated = accounts.GetProfileKeypairForTest(true, true, true)
accountsToUpdate := profileKpUpdated.Accounts[2:]
for _, acc := range accountsToUpdate {
acc.Name = acc.Name + "Updated"