From 20f38bf62b2fa80c28762b98d440e9999853ee3c Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 24 May 2023 16:40:40 +0200 Subject: [PATCH] tests: `GetProfileKeypairForTest` from test helper updated and provides higher granularity --- multiaccounts/accounts/database_test.go | 2 +- .../accounts/keycard_database_test.go | 2 +- multiaccounts/accounts/test_helper.go | 66 ++++++++++--------- protocol/messenger_backup_test.go | 4 +- .../messenger_sync_keycard_change_test.go | 2 +- .../messenger_sync_keycards_state_test.go | 2 +- protocol/messenger_sync_wallets_test.go | 8 +-- 7 files changed, 45 insertions(+), 41 deletions(-) diff --git a/multiaccounts/accounts/database_test.go b/multiaccounts/accounts/database_test.go index d677e55b7..663321028 100644 --- a/multiaccounts/accounts/database_test.go +++ b/multiaccounts/accounts/database_test.go @@ -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 } diff --git a/multiaccounts/accounts/keycard_database_test.go b/multiaccounts/accounts/keycard_database_test.go index 6cecb556b..e0647243c 100644 --- a/multiaccounts/accounts/keycard_database_test.go +++ b/multiaccounts/accounts/keycard_database_test.go @@ -14,7 +14,7 @@ func TestKeycards(t *testing.T) { keycardUID := "00000000000000000000000000000000" - kp1 := GetProfileKeypairForTest(false) + kp1 := GetProfileKeypairForTest(true, true, true) keycard1 := GetProfileKeycardForTest() kp2 := GetSeedImportedKeypair1ForTest() diff --git a/multiaccounts/accounts/test_helper.go b/multiaccounts/accounts/test_helper.go index c6c453d15..a5e2c746d 100644 --- a/multiaccounts/accounts/test_helper.go +++ b/multiaccounts/accounts/test_helper.go @@ -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) diff --git a/protocol/messenger_backup_test.go b/protocol/messenger_backup_test.go index f970c4eaa..0303f6121 100644 --- a/protocol/messenger_backup_test.go +++ b/protocol/messenger_backup_test.go @@ -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() diff --git a/protocol/messenger_sync_keycard_change_test.go b/protocol/messenger_sync_keycard_change_test.go index aa684443e..fcce09480 100644 --- a/protocol/messenger_sync_keycard_change_test.go +++ b/protocol/messenger_sync_keycard_change_test.go @@ -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() diff --git a/protocol/messenger_sync_keycards_state_test.go b/protocol/messenger_sync_keycards_state_test.go index 3520dc33a..7f1637a9f 100644 --- a/protocol/messenger_sync_keycards_state_test.go +++ b/protocol/messenger_sync_keycards_state_test.go @@ -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() diff --git a/protocol/messenger_sync_wallets_test.go b/protocol/messenger_sync_wallets_test.go index 3a689eeb4..46e31569d 100644 --- a/protocol/messenger_sync_wallets_test.go +++ b/protocol/messenger_sync_wallets_test.go @@ -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"