tests: `GetProfileKeypairForTest` from test helper updated and provides higher granularity
This commit is contained in:
parent
0eca7f5088
commit
20f38bf62b
|
@ -178,7 +178,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
|
||||||
|
|
||||||
func TestKeypairs(t *testing.T) {
|
func TestKeypairs(t *testing.T) {
|
||||||
keypairs := []*Keypair{
|
keypairs := []*Keypair{
|
||||||
GetProfileKeypairForTest(false),
|
GetProfileKeypairForTest(true, true, true),
|
||||||
GetSeedImportedKeypair1ForTest(),
|
GetSeedImportedKeypair1ForTest(),
|
||||||
GetPrivKeyImportedKeypairForTest(), // in this context (when testing db functions) there is not limitations for private key imported keypair
|
GetPrivKeyImportedKeypairForTest(), // in this context (when testing db functions) there is not limitations for private key imported keypair
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ func TestKeycards(t *testing.T) {
|
||||||
|
|
||||||
keycardUID := "00000000000000000000000000000000"
|
keycardUID := "00000000000000000000000000000000"
|
||||||
|
|
||||||
kp1 := GetProfileKeypairForTest(false)
|
kp1 := GetProfileKeypairForTest(true, true, true)
|
||||||
keycard1 := GetProfileKeycardForTest()
|
keycard1 := GetProfileKeycardForTest()
|
||||||
|
|
||||||
kp2 := GetSeedImportedKeypair1ForTest()
|
kp2 := GetSeedImportedKeypair1ForTest()
|
||||||
|
|
|
@ -30,7 +30,7 @@ func GetWatchOnlyAccountsForTest() []*Account {
|
||||||
return []*Account{wo1, wo2, wo3}
|
return []*Account{wo1, wo2, wo3}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetProfileKeypairForTest(onlyChatAndDefaultWalletAccount bool) *Keypair {
|
func GetProfileKeypairForTest(includeChatAccount bool, includeDefaultWalletAccount bool, includeAdditionalAccounts bool) *Keypair {
|
||||||
kp := &Keypair{
|
kp := &Keypair{
|
||||||
KeyUID: "0000000000000000000000000000000000000000000000000000000000000001",
|
KeyUID: "0000000000000000000000000000000000000000000000000000000000000001",
|
||||||
Name: "Profile Name",
|
Name: "Profile Name",
|
||||||
|
@ -38,39 +38,43 @@ func GetProfileKeypairForTest(onlyChatAndDefaultWalletAccount bool) *Keypair {
|
||||||
DerivedFrom: "0x0001",
|
DerivedFrom: "0x0001",
|
||||||
}
|
}
|
||||||
|
|
||||||
profileAccount := &Account{
|
if includeChatAccount {
|
||||||
Address: types.Address{0x01},
|
profileAccount := &Account{
|
||||||
KeyUID: kp.KeyUID,
|
Address: types.Address{0x01},
|
||||||
Wallet: false,
|
KeyUID: kp.KeyUID,
|
||||||
Chat: true,
|
Wallet: false,
|
||||||
Type: AccountTypeGenerated,
|
Chat: true,
|
||||||
Path: "m/43'/60'/1581'/0'/0",
|
Type: AccountTypeGenerated,
|
||||||
PublicKey: types.Hex2Bytes("0x000000001"),
|
Path: "m/43'/60'/1581'/0'/0",
|
||||||
Name: "Profile Name",
|
PublicKey: types.Hex2Bytes("0x000000001"),
|
||||||
Operable: AccountFullyOperable,
|
Name: "Profile Name",
|
||||||
|
Operable: AccountFullyOperable,
|
||||||
|
}
|
||||||
|
kp.Accounts = append(kp.Accounts, profileAccount)
|
||||||
}
|
}
|
||||||
kp.Accounts = append(kp.Accounts, profileAccount)
|
|
||||||
|
|
||||||
defaultWalletAccount := &Account{
|
if includeDefaultWalletAccount {
|
||||||
Address: types.Address{0x02},
|
defaultWalletAccount := &Account{
|
||||||
KeyUID: kp.KeyUID,
|
Address: types.Address{0x02},
|
||||||
Wallet: true,
|
KeyUID: kp.KeyUID,
|
||||||
Chat: false,
|
Wallet: true,
|
||||||
Type: AccountTypeGenerated,
|
Chat: false,
|
||||||
Path: "m/44'/60'/0'/0/0",
|
Type: AccountTypeGenerated,
|
||||||
PublicKey: types.Hex2Bytes("0x000000002"),
|
Path: "m/44'/60'/0'/0/0",
|
||||||
Name: "Generated Acc 1",
|
PublicKey: types.Hex2Bytes("0x000000002"),
|
||||||
Emoji: "emoji-1",
|
Name: "Generated Acc 1",
|
||||||
Color: "blue",
|
Emoji: "emoji-1",
|
||||||
Hidden: false,
|
Color: "blue",
|
||||||
Clock: 0,
|
Hidden: false,
|
||||||
Removed: false,
|
Clock: 0,
|
||||||
Operable: AccountFullyOperable,
|
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{
|
generatedWalletAccount1 := &Account{
|
||||||
Address: types.Address{0x03},
|
Address: types.Address{0x03},
|
||||||
KeyUID: kp.KeyUID,
|
KeyUID: kp.KeyUID,
|
||||||
|
@ -241,7 +245,7 @@ func GetPrivKeyImportedKeypairForTest() *Keypair {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetProfileKeycardForTest() *Keycard {
|
func GetProfileKeycardForTest() *Keycard {
|
||||||
profileKp := GetProfileKeypairForTest(false)
|
profileKp := GetProfileKeypairForTest(true, true, true)
|
||||||
keycard1Addresses := []types.Address{}
|
keycard1Addresses := []types.Address{}
|
||||||
for _, acc := range profileKp.Accounts {
|
for _, acc := range profileKp.Accounts {
|
||||||
keycard1Addresses = append(keycard1Addresses, acc.Address)
|
keycard1Addresses = append(keycard1Addresses, acc.Address)
|
||||||
|
|
|
@ -675,7 +675,7 @@ func (s *MessengerBackupSuite) TestBackupCommunities() {
|
||||||
func (s *MessengerBackupSuite) TestBackupKeypairs() {
|
func (s *MessengerBackupSuite) TestBackupKeypairs() {
|
||||||
// Create bob1
|
// Create bob1
|
||||||
bob1 := s.m
|
bob1 := s.m
|
||||||
profileKp := accounts.GetProfileKeypairForTest(false)
|
profileKp := accounts.GetProfileKeypairForTest(true, true, true)
|
||||||
seedKp := accounts.GetSeedImportedKeypair1ForTest()
|
seedKp := accounts.GetSeedImportedKeypair1ForTest()
|
||||||
|
|
||||||
// Create a main account on bob1
|
// Create a main account on bob1
|
||||||
|
@ -734,7 +734,7 @@ func (s *MessengerBackupSuite) TestBackupKeycards() {
|
||||||
// Create bob1
|
// Create bob1
|
||||||
bob1 := s.m
|
bob1 := s.m
|
||||||
|
|
||||||
kp1 := accounts.GetProfileKeypairForTest(false)
|
kp1 := accounts.GetProfileKeypairForTest(true, true, true)
|
||||||
keycard1 := accounts.GetProfileKeycardForTest()
|
keycard1 := accounts.GetProfileKeycardForTest()
|
||||||
|
|
||||||
kp2 := accounts.GetSeedImportedKeypair1ForTest()
|
kp2 := accounts.GetSeedImportedKeypair1ForTest()
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
// 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()
|
kp2 := accounts.GetSeedImportedKeypair1ForTest()
|
||||||
// kp3 := accounts.GetSeedImportedKeypair2ForTest()
|
// kp3 := accounts.GetSeedImportedKeypair2ForTest()
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
// 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()
|
kp2 := accounts.GetSeedImportedKeypair1ForTest()
|
||||||
kp3 := accounts.GetSeedImportedKeypair2ForTest()
|
kp3 := accounts.GetSeedImportedKeypair2ForTest()
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ func (s *MessengerSyncWalletSuite) newMessenger(shh types.Waku) *Messenger {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncWalletSuite) TestSyncWallets() {
|
func (s *MessengerSyncWalletSuite) TestSyncWallets() {
|
||||||
profileKp := accounts.GetProfileKeypairForTest(false)
|
profileKp := accounts.GetProfileKeypairForTest(true, true, true)
|
||||||
|
|
||||||
// Create a main account on alice
|
// Create a main account on alice
|
||||||
err := s.m.settings.SaveOrUpdateKeypair(profileKp)
|
err := s.m.settings.SaveOrUpdateKeypair(profileKp)
|
||||||
|
@ -82,7 +82,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Store only chat and default wallet account on other device
|
// 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)
|
err = alicesOtherDevice.settings.SaveOrUpdateKeypair(profileKpOtherDevice)
|
||||||
s.Require().NoError(err, "profile keypair alicesOtherDevice.settings.SaveOrUpdateKeypair")
|
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))
|
s.Require().True(haveSameElements(dbAccounts1, dbAccounts2, accounts.SameAccounts))
|
||||||
|
|
||||||
// Update keypair name on alice's primary device
|
// Update keypair name on alice's primary device
|
||||||
profileKpUpdated := accounts.GetProfileKeypairForTest(true)
|
profileKpUpdated := accounts.GetProfileKeypairForTest(true, true, false)
|
||||||
profileKpUpdated.Name = profileKp.Name + "Updated"
|
profileKpUpdated.Name = profileKp.Name + "Updated"
|
||||||
profileKpUpdated.Accounts = profileKp.Accounts[:0]
|
profileKpUpdated.Accounts = profileKp.Accounts[:0]
|
||||||
err = s.m.SaveOrUpdateKeypair(profileKpUpdated)
|
err = s.m.SaveOrUpdateKeypair(profileKpUpdated)
|
||||||
|
@ -222,7 +222,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
|
||||||
s.Require().Equal(profileKpUpdated.Name, dbProfileKp2.Name)
|
s.Require().Equal(profileKpUpdated.Name, dbProfileKp2.Name)
|
||||||
|
|
||||||
// Update accounts on alice's primary device
|
// Update accounts on alice's primary device
|
||||||
profileKpUpdated = accounts.GetProfileKeypairForTest(false)
|
profileKpUpdated = accounts.GetProfileKeypairForTest(true, true, true)
|
||||||
accountsToUpdate := profileKpUpdated.Accounts[2:]
|
accountsToUpdate := profileKpUpdated.Accounts[2:]
|
||||||
for _, acc := range accountsToUpdate {
|
for _, acc := range accountsToUpdate {
|
||||||
acc.Name = acc.Name + "Updated"
|
acc.Name = acc.Name + "Updated"
|
||||||
|
|
Loading…
Reference in New Issue