fix: saved addresses sync (`TestSyncDeletesOfSavedAddresses` flaky test) (#4742)
This commit is contained in:
parent
526e3d74f1
commit
789ee81201
|
@ -3,6 +3,8 @@ package protocol
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
|
|
||||||
ensservice "github.com/status-im/status-go/services/ens"
|
ensservice "github.com/status-im/status-go/services/ens"
|
||||||
|
|
||||||
"github.com/status-im/status-go/services/browsers"
|
"github.com/status-im/status-go/services/browsers"
|
||||||
|
@ -510,11 +512,7 @@ func (r *MessengerResponse) AddSavedAddress(er *wallet.SavedAddress) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MessengerResponse) SavedAddresses() []*wallet.SavedAddress {
|
func (r *MessengerResponse) SavedAddresses() []*wallet.SavedAddress {
|
||||||
var ers []*wallet.SavedAddress
|
return maps.Values(r.savedAddresses)
|
||||||
for _, er := range r.savedAddresses {
|
|
||||||
ers = append(ers, er)
|
|
||||||
}
|
|
||||||
return ers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *MessengerResponse) AddEnsUsernameDetail(detail *ensservice.UsernameDetail) {
|
func (r *MessengerResponse) AddEnsUsernameDetail(detail *ensservice.UsernameDetail) {
|
||||||
|
|
|
@ -15,15 +15,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *Messenger) UpsertSavedAddress(ctx context.Context, sa wallet.SavedAddress) error {
|
func (m *Messenger) UpsertSavedAddress(ctx context.Context, sa wallet.SavedAddress) error {
|
||||||
updatedClock, err := m.savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa)
|
sa.UpdateClock, _ = m.getLastClockWithRelatedChat()
|
||||||
|
err := m.savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return m.syncNewSavedAddress(ctx, &sa, updatedClock, m.dispatchMessage)
|
return m.syncNewSavedAddress(ctx, &sa, sa.UpdateClock, m.dispatchMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) DeleteSavedAddress(ctx context.Context, address gethcommon.Address, isTest bool) error {
|
func (m *Messenger) DeleteSavedAddress(ctx context.Context, address gethcommon.Address, isTest bool) error {
|
||||||
updateClock := uint64(time.Now().Unix())
|
updateClock, _ := m.getLastClockWithRelatedChat()
|
||||||
_, err := m.savedAddressesManager.DeleteSavedAddress(address, isTest, updateClock)
|
_, err := m.savedAddressesManager.DeleteSavedAddress(address, isTest, updateClock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -31,7 +32,7 @@ func (m *Messenger) DeleteSavedAddress(ctx context.Context, address gethcommon.A
|
||||||
return m.syncDeletedSavedAddress(ctx, address, isTest, updateClock, m.dispatchMessage)
|
return m.syncDeletedSavedAddress(ctx, address, isTest, updateClock, m.dispatchMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) GetSavedAddresses(ctx context.Context) ([]wallet.SavedAddress, error) {
|
func (m *Messenger) GetSavedAddresses(ctx context.Context) ([]*wallet.SavedAddress, error) {
|
||||||
return m.savedAddressesManager.GetSavedAddresses()
|
return m.savedAddressesManager.GetSavedAddresses()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,13 +90,13 @@ func (m *Messenger) syncDeletedSavedAddress(ctx context.Context, address gethcom
|
||||||
}, rawMessageHandler)
|
}, rawMessageHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) syncSavedAddress(ctx context.Context, savedAddress wallet.SavedAddress, rawMessageHandler RawMessageHandler) (err error) {
|
func (m *Messenger) syncSavedAddress(ctx context.Context, savedAddress *wallet.SavedAddress, rawMessageHandler RawMessageHandler) (err error) {
|
||||||
if savedAddress.Removed {
|
if savedAddress.Removed {
|
||||||
if err = m.syncDeletedSavedAddress(ctx, savedAddress.Address, savedAddress.IsTest, savedAddress.UpdateClock, rawMessageHandler); err != nil {
|
if err = m.syncDeletedSavedAddress(ctx, savedAddress.Address, savedAddress.IsTest, savedAddress.UpdateClock, rawMessageHandler); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = m.syncNewSavedAddress(ctx, &savedAddress, savedAddress.UpdateClock, rawMessageHandler); err != nil {
|
if err = m.syncNewSavedAddress(ctx, savedAddress, savedAddress.UpdateClock, rawMessageHandler); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,12 +106,14 @@ func (m *Messenger) syncSavedAddress(ctx context.Context, savedAddress wallet.Sa
|
||||||
func (m *Messenger) HandleSyncSavedAddress(state *ReceivedMessageState, syncMessage *protobuf.SyncSavedAddress, statusMessage *v1protocol.StatusMessage) (err error) {
|
func (m *Messenger) HandleSyncSavedAddress(state *ReceivedMessageState, syncMessage *protobuf.SyncSavedAddress, statusMessage *v1protocol.StatusMessage) (err error) {
|
||||||
address := gethcommon.BytesToAddress(syncMessage.Address)
|
address := gethcommon.BytesToAddress(syncMessage.Address)
|
||||||
if syncMessage.Removed {
|
if syncMessage.Removed {
|
||||||
_, err = m.savedAddressesManager.DeleteSavedAddress(
|
deleted, err := m.savedAddressesManager.DeleteSavedAddress(
|
||||||
address, syncMessage.IsTest, syncMessage.UpdateClock)
|
address, syncMessage.IsTest, syncMessage.UpdateClock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
state.Response.AddSavedAddress(&wallet.SavedAddress{Address: address, ENSName: syncMessage.Ens, IsTest: syncMessage.IsTest, Removed: true})
|
if deleted {
|
||||||
|
state.Response.AddSavedAddress(&wallet.SavedAddress{Address: address, ENSName: syncMessage.Ens, IsTest: syncMessage.IsTest, Removed: true})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sa := wallet.SavedAddress{
|
sa := wallet.SavedAddress{
|
||||||
Address: address,
|
Address: address,
|
||||||
|
@ -120,12 +123,15 @@ func (m *Messenger) HandleSyncSavedAddress(state *ReceivedMessageState, syncMess
|
||||||
IsTest: syncMessage.IsTest,
|
IsTest: syncMessage.IsTest,
|
||||||
ColorID: multiAccCommon.CustomizationColor(syncMessage.Color),
|
ColorID: multiAccCommon.CustomizationColor(syncMessage.Color),
|
||||||
}
|
}
|
||||||
|
sa.UpdateClock = syncMessage.UpdateClock
|
||||||
|
|
||||||
_, err = m.savedAddressesManager.AddSavedAddressIfNewerUpdate(sa, syncMessage.UpdateClock)
|
added, err := m.savedAddressesManager.AddSavedAddressIfNewerUpdate(sa)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
state.Response.AddSavedAddress(&sa)
|
if added {
|
||||||
|
state.Response.AddSavedAddress(&sa)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package protocol
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
@ -45,14 +47,14 @@ func (s *MessengerSyncSavedAddressesSuite) SetupTest() {
|
||||||
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
||||||
s.Require().NoError(shh.Start())
|
s.Require().NoError(shh.Start())
|
||||||
|
|
||||||
s.main = s.newMessenger(s.shh)
|
s.main = s.newMessenger(s.logger.Named("main"))
|
||||||
s.privateKey = s.main.identity
|
s.privateKey = s.main.identity
|
||||||
// Start the main messenger in order to receive installations
|
// Start the main messenger in order to receive installations
|
||||||
_, err := s.main.Start()
|
_, err := s.main.Start()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Create new device and add main account to
|
// Create new device and add main account to
|
||||||
s.other, err = newMessengerWithKey(s.shh, s.main.identity, s.logger, nil)
|
s.other, err = newMessengerWithKey(s.shh, s.main.identity, s.logger.Named("other"), nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Pair devices (main and other)
|
// Pair devices (main and other)
|
||||||
|
@ -82,11 +84,11 @@ func (s *MessengerSyncSavedAddressesSuite) TearDownTest() {
|
||||||
TearDownMessenger(&s.Suite, s.main)
|
TearDownMessenger(&s.Suite, s.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncSavedAddressesSuite) newMessenger(shh types.Waku) *Messenger {
|
func (s *MessengerSyncSavedAddressesSuite) newMessenger(logger *zap.Logger) *Messenger {
|
||||||
privateKey, err := crypto.GenerateKey()
|
privateKey, err := crypto.GenerateKey()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
messenger, err := newMessengerWithKey(s.shh, privateKey, s.logger, nil)
|
messenger, err := newMessengerWithKey(s.shh, privateKey, logger, nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
return messenger
|
return messenger
|
||||||
|
@ -104,6 +106,9 @@ func contains[T comparable](container []T, element T, isEqual func(T, T) bool) b
|
||||||
}
|
}
|
||||||
|
|
||||||
func haveSameElements[T comparable](a []T, b []T, isEqual func(T, T) bool) bool {
|
func haveSameElements[T comparable](a []T, b []T, isEqual func(T, T) bool) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for _, v := range a {
|
for _, v := range a {
|
||||||
if !contains(b, v, isEqual) {
|
if !contains(b, v, isEqual) {
|
||||||
return false
|
return false
|
||||||
|
@ -112,7 +117,7 @@ func haveSameElements[T comparable](a []T, b []T, isEqual func(T, T) bool) bool
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func savedAddressDataIsEqual(a, b wallet.SavedAddress) bool {
|
func savedAddressDataIsEqual(a, b *wallet.SavedAddress) bool {
|
||||||
return a.Address == b.Address && a.IsTest == b.IsTest && a.Name == b.Name &&
|
return a.Address == b.Address && a.IsTest == b.IsTest && a.Name == b.Name &&
|
||||||
a.ENSName == b.ENSName && a.ChainShortNames == b.ChainShortNames && a.ColorID == b.ColorID
|
a.ENSName == b.ENSName && a.ChainShortNames == b.ChainShortNames && a.ColorID == b.ColorID
|
||||||
}
|
}
|
||||||
|
@ -134,15 +139,9 @@ func (s *MessengerSyncSavedAddressesSuite) TestSyncExistingSavedAddresses() {
|
||||||
IsTest: isTestChain2,
|
IsTest: isTestChain2,
|
||||||
}
|
}
|
||||||
|
|
||||||
savedAddressesManager := s.main.savedAddressesManager
|
err := s.main.UpsertSavedAddress(context.Background(), sa1)
|
||||||
|
|
||||||
_, err := savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa1)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
_, err = savedAddressesManager.UpdateMetadataAndUpsertSavedAddress(sa2)
|
err = s.main.UpsertSavedAddress(context.Background(), sa2)
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
// Trigger's a sync between devices
|
|
||||||
err = s.main.SyncDevices(context.Background(), "ens-name", "profile-image", nil)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Wait and check that saved addresses are synced
|
// Wait and check that saved addresses are synced
|
||||||
|
@ -151,7 +150,7 @@ func (s *MessengerSyncSavedAddressesSuite) TestSyncExistingSavedAddresses() {
|
||||||
func(r *MessengerResponse) bool {
|
func(r *MessengerResponse) bool {
|
||||||
if len(r.SavedAddresses()) == 2 {
|
if len(r.SavedAddresses()) == 2 {
|
||||||
sas := r.SavedAddresses()
|
sas := r.SavedAddresses()
|
||||||
s.Require().True(haveSameElements([]wallet.SavedAddress{sa1, sa2}, []wallet.SavedAddress{*sas[0], *sas[1]}, savedAddressDataIsEqual))
|
s.Require().True(haveSameElements([]*wallet.SavedAddress{&sa1, &sa2}, []*wallet.SavedAddress{sas[0], sas[1]}, savedAddressDataIsEqual))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -163,7 +162,7 @@ func (s *MessengerSyncSavedAddressesSuite) TestSyncExistingSavedAddresses() {
|
||||||
savedAddresses, err := s.other.savedAddressesManager.GetSavedAddresses()
|
savedAddresses, err := s.other.savedAddressesManager.GetSavedAddresses()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(2, len(savedAddresses))
|
s.Require().Equal(2, len(savedAddresses))
|
||||||
s.Require().True(haveSameElements([]wallet.SavedAddress{sa1, sa2}, savedAddresses, savedAddressDataIsEqual))
|
s.Require().True(haveSameElements([]*wallet.SavedAddress{&sa1, &sa2}, savedAddresses, savedAddressDataIsEqual))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncSavedAddressesSuite) TestSyncSavedAddresses() {
|
func (s *MessengerSyncSavedAddressesSuite) TestSyncSavedAddresses() {
|
||||||
|
@ -193,7 +192,7 @@ func (s *MessengerSyncSavedAddressesSuite) TestSyncSavedAddresses() {
|
||||||
func(r *MessengerResponse) bool {
|
func(r *MessengerResponse) bool {
|
||||||
if len(r.SavedAddresses()) == 2 {
|
if len(r.SavedAddresses()) == 2 {
|
||||||
sas := r.SavedAddresses()
|
sas := r.SavedAddresses()
|
||||||
s.Require().True(haveSameElements([]wallet.SavedAddress{sa1, sa2}, []wallet.SavedAddress{*sas[0], *sas[1]}, savedAddressDataIsEqual))
|
s.Require().True(haveSameElements([]*wallet.SavedAddress{&sa1, &sa2}, []*wallet.SavedAddress{sas[0], sas[1]}, savedAddressDataIsEqual))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -205,25 +204,30 @@ func (s *MessengerSyncSavedAddressesSuite) TestSyncSavedAddresses() {
|
||||||
savedAddresses, err := s.other.savedAddressesManager.GetSavedAddresses()
|
savedAddresses, err := s.other.savedAddressesManager.GetSavedAddresses()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(2, len(savedAddresses))
|
s.Require().Equal(2, len(savedAddresses))
|
||||||
s.Require().True(haveSameElements([]wallet.SavedAddress{sa1, sa2}, savedAddresses, savedAddressDataIsEqual))
|
s.Require().True(haveSameElements([]*wallet.SavedAddress{&sa1, &sa2}, savedAddresses, savedAddressDataIsEqual))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncSavedAddressesSuite) testSyncDeletesOfSavedAddressesWithTestModes(testModeMain bool, testModeOther bool) {
|
func (s *MessengerSyncSavedAddressesSuite) requireSavedAddressesEqual(a, b []*wallet.SavedAddress) {
|
||||||
var isTestChain1 bool = true
|
sort.Slice(a, func(i, j int) bool {
|
||||||
var isTestChain2 bool = false
|
return a[i].Address.Hex() < a[j].Address.Hex()
|
||||||
var testAddress1 = common.Address{1}
|
})
|
||||||
var testAddress2 = common.Address{2}
|
sort.Slice(b, func(i, j int) bool {
|
||||||
|
return b[i].Address.Hex() < b[j].Address.Hex()
|
||||||
|
})
|
||||||
|
s.Require().True(reflect.DeepEqual(a, b))
|
||||||
|
}
|
||||||
|
|
||||||
// Add saved addresses to main device
|
func (s *MessengerSyncSavedAddressesSuite) testSyncDeletesOfSavedAddresses(testModeMain bool, testModeOther bool) {
|
||||||
sa1 := wallet.SavedAddress{
|
|
||||||
Address: testAddress1,
|
sa1 := &wallet.SavedAddress{
|
||||||
|
Address: common.Address{1},
|
||||||
Name: "TestC1A1",
|
Name: "TestC1A1",
|
||||||
IsTest: isTestChain1,
|
IsTest: true,
|
||||||
}
|
}
|
||||||
sa2 := wallet.SavedAddress{
|
sa2 := &wallet.SavedAddress{
|
||||||
Address: testAddress2,
|
Address: common.Address{2},
|
||||||
Name: "TestC1A2",
|
Name: "TestC1A2",
|
||||||
IsTest: isTestChain2,
|
IsTest: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.main.settings.SaveSettingField(settings.TestNetworksEnabled, testModeMain)
|
err := s.main.settings.SaveSettingField(settings.TestNetworksEnabled, testModeMain)
|
||||||
|
@ -231,92 +235,142 @@ func (s *MessengerSyncSavedAddressesSuite) testSyncDeletesOfSavedAddressesWithTe
|
||||||
err = s.other.settings.SaveSettingField(settings.TestNetworksEnabled, testModeOther)
|
err = s.other.settings.SaveSettingField(settings.TestNetworksEnabled, testModeOther)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Add saved addresses to main device
|
||||||
|
err = s.main.UpsertSavedAddress(context.Background(), *sa1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
err = s.main.UpsertSavedAddress(context.Background(), sa1)
|
err = s.main.UpsertSavedAddress(context.Background(), *sa2)
|
||||||
s.Require().NoError(err)
|
|
||||||
err = s.main.UpsertSavedAddress(context.Background(), sa2)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Wait and check that saved addresses are synced
|
// Wait and check that saved addresses are synced
|
||||||
_, err = WaitOnMessengerResponse(
|
{
|
||||||
s.other,
|
response, err := WaitOnMessengerResponse(
|
||||||
func(r *MessengerResponse) bool {
|
s.other,
|
||||||
if len(r.SavedAddresses()) == 2 {
|
func(r *MessengerResponse) bool {
|
||||||
sas := r.SavedAddresses()
|
return len(r.SavedAddresses()) == 2
|
||||||
s.Require().True(haveSameElements([]wallet.SavedAddress{sa1, sa2}, []wallet.SavedAddress{*sas[0], *sas[1]}, savedAddressDataIsEqual))
|
},
|
||||||
return true
|
"expected to receive two changes",
|
||||||
}
|
)
|
||||||
return false
|
s.Require().NoError(err)
|
||||||
},
|
|
||||||
"expected to receive two changes",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
savedAddresses, err := s.other.savedAddressesManager.GetSavedAddresses()
|
otherSavedAddresses := response.SavedAddresses()
|
||||||
s.Require().NoError(err)
|
s.Require().Len(otherSavedAddresses, 2)
|
||||||
s.Require().Equal(2, len(savedAddresses))
|
|
||||||
|
|
||||||
// Delete saved addresses with test mode = true and sync with the other device
|
// Check that the UpdateClock was bumped
|
||||||
err = s.main.DeleteSavedAddress(context.Background(), sa1.Address, sa1.IsTest)
|
s.Require().GreaterOrEqual(otherSavedAddresses[0].CreatedAt, int64(0))
|
||||||
s.Require().NoError(err)
|
s.Require().GreaterOrEqual(otherSavedAddresses[1].CreatedAt, int64(0))
|
||||||
|
s.Require().Greater(otherSavedAddresses[0].UpdateClock, uint64(0))
|
||||||
|
s.Require().Greater(otherSavedAddresses[1].UpdateClock, uint64(0))
|
||||||
|
|
||||||
// Wait and check that saved addresses are synced
|
// Reset the UpdateClock to 0 for comparison
|
||||||
_, err = WaitOnMessengerResponse(
|
otherSavedAddresses[0].CreatedAt = 0
|
||||||
s.other,
|
otherSavedAddresses[1].CreatedAt = 0
|
||||||
func(r *MessengerResponse) bool {
|
otherSavedAddresses[0].UpdateClock = 0
|
||||||
if len(r.SavedAddresses()) == 1 {
|
otherSavedAddresses[1].UpdateClock = 0
|
||||||
sa := r.SavedAddresses()[0]
|
s.requireSavedAddressesEqual([]*wallet.SavedAddress{sa1, sa2}, otherSavedAddresses)
|
||||||
// We expect the deleted event to report address, ens, isTest
|
|
||||||
s.Require().Equal(sa1.Address, sa.Address)
|
|
||||||
s.Require().Equal(sa1.IsTest, sa.IsTest)
|
|
||||||
s.Require().Equal("", sa.Name)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
"expected to receive one change",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
savedAddresses, err = s.other.savedAddressesManager.GetSavedAddresses()
|
// Ensure the messenger actually has the saved addresses, not just the response
|
||||||
s.Require().NoError(err)
|
savedAddresses, err := s.other.savedAddressesManager.GetSavedAddresses()
|
||||||
s.Require().True(haveSameElements([]wallet.SavedAddress{sa2}, savedAddresses, savedAddressDataIsEqual))
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(savedAddresses, 2)
|
||||||
|
|
||||||
// Delete saved addresses with test mode = false and sync with the other device
|
// Reset the UpdateClock to 0 for comparison
|
||||||
err = s.main.DeleteSavedAddress(context.Background(), sa2.Address, sa2.IsTest)
|
savedAddresses[0].CreatedAt = 0
|
||||||
s.Require().NoError(err)
|
savedAddresses[1].CreatedAt = 0
|
||||||
|
savedAddresses[0].UpdateClock = 0
|
||||||
|
savedAddresses[1].UpdateClock = 0
|
||||||
|
s.requireSavedAddressesEqual([]*wallet.SavedAddress{sa1, sa2}, savedAddresses)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait and check that saved addresses are synced
|
// Delete saved address 1 (test mode = true) and sync with the other device
|
||||||
_, err = WaitOnMessengerResponse(
|
{
|
||||||
s.other,
|
err = s.main.DeleteSavedAddress(context.Background(), sa1.Address, sa1.IsTest)
|
||||||
func(r *MessengerResponse) bool {
|
s.Require().NoError(err)
|
||||||
if len(r.SavedAddresses()) == 1 {
|
|
||||||
sa := r.SavedAddresses()[0]
|
|
||||||
// We expect the deleted event to report address, ens, isTest
|
|
||||||
s.Require().Equal(sa2.Address, sa.Address)
|
|
||||||
s.Require().Equal(sa2.IsTest, sa.IsTest)
|
|
||||||
s.Require().Equal("", sa.Name)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
"expected to receive one change",
|
|
||||||
)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
savedAddresses, err = s.other.savedAddressesManager.GetSavedAddresses()
|
// Ensure the removal
|
||||||
s.Require().NoError(err)
|
savedAddresses, err := s.main.savedAddressesManager.GetSavedAddresses()
|
||||||
s.Require().Equal(0, len(savedAddresses))
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(savedAddresses, 1)
|
||||||
|
sa2.CreatedAt = savedAddresses[0].CreatedAt // force same value
|
||||||
|
sa2.UpdateClock = savedAddresses[0].UpdateClock // force same value
|
||||||
|
s.Require().Equal(sa2, savedAddresses[0])
|
||||||
|
|
||||||
|
// Wait other device to receive the change
|
||||||
|
response, err := WaitOnMessengerResponse(
|
||||||
|
s.other,
|
||||||
|
func(r *MessengerResponse) bool {
|
||||||
|
return len(r.SavedAddresses()) == 1
|
||||||
|
},
|
||||||
|
"saved address removal wasn't received",
|
||||||
|
)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// We expect the delete event to report address, ens, isTest
|
||||||
|
sa := response.SavedAddresses()[0]
|
||||||
|
s.Require().Equal(sa1.Address, sa.Address)
|
||||||
|
s.Require().Equal(sa1.IsTest, sa.IsTest)
|
||||||
|
s.Require().Equal("", sa.Name)
|
||||||
|
|
||||||
|
// Ensure the messenger doesn't return the removed address
|
||||||
|
savedAddresses, err = s.other.savedAddressesManager.GetSavedAddresses()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(savedAddresses, 1)
|
||||||
|
savedAddresses[0].CreatedAt = sa2.CreatedAt // force same value
|
||||||
|
s.Require().Equal(sa2, savedAddresses[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete saved address 2 (test mode = false) and sync with the other device
|
||||||
|
{
|
||||||
|
err = s.main.DeleteSavedAddress(context.Background(), sa2.Address, sa2.IsTest)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Ensure the removal
|
||||||
|
savedAddresses, err := s.main.savedAddressesManager.GetSavedAddresses()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(savedAddresses, 0)
|
||||||
|
|
||||||
|
// Wait other device to receive the change
|
||||||
|
response, err := WaitOnMessengerResponse(
|
||||||
|
s.other,
|
||||||
|
func(r *MessengerResponse) bool {
|
||||||
|
return len(r.SavedAddresses()) == 1
|
||||||
|
},
|
||||||
|
"expected to receive one change",
|
||||||
|
)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
sa := response.SavedAddresses()[0]
|
||||||
|
// We expect the deleted event to report address, ens, isTest
|
||||||
|
s.Require().Equal(sa2.Address, sa.Address)
|
||||||
|
s.Require().Equal(sa2.IsTest, sa.IsTest)
|
||||||
|
s.Require().Equal("", sa.Name)
|
||||||
|
|
||||||
|
savedAddresses, err = s.other.savedAddressesManager.GetSavedAddresses()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(savedAddresses, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncSavedAddressesSuite) TestSyncDeletesOfSavedAddressesSameTestModeOnBothDevices() {
|
func (s *MessengerSyncSavedAddressesSuite) TestSyncDeletesOfSavedAddresses() {
|
||||||
testModeMain := true
|
testCases := []struct {
|
||||||
testModeOther := testModeMain
|
Name string
|
||||||
s.testSyncDeletesOfSavedAddressesWithTestModes(testModeMain, testModeOther)
|
TestModeMain bool
|
||||||
}
|
TestModeOther bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Name: "same test mode on both devices",
|
||||||
|
TestModeMain: true,
|
||||||
|
TestModeOther: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "different test mode on devices",
|
||||||
|
TestModeMain: true,
|
||||||
|
TestModeOther: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MessengerSyncSavedAddressesSuite) TestSyncDeletesOfSavedAddressesDifferentTestModeOnDevices() {
|
for _, tc := range testCases {
|
||||||
testModeMain := true
|
s.Run(tc.Name, func() {
|
||||||
testModeOther := !testModeMain
|
s.testSyncDeletesOfSavedAddresses(tc.TestModeMain, tc.TestModeOther)
|
||||||
s.testSyncDeletesOfSavedAddressesWithTestModes(testModeMain, testModeOther)
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1076,7 +1076,7 @@ func (api *PublicAPI) DeleteSavedAddress(ctx context.Context, address ethcommon.
|
||||||
return api.service.messenger.DeleteSavedAddress(ctx, address, isTest)
|
return api.service.messenger.DeleteSavedAddress(ctx, address, isTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) GetSavedAddresses(ctx context.Context) ([]wallet.SavedAddress, error) {
|
func (api *PublicAPI) GetSavedAddresses(ctx context.Context) ([]*wallet.SavedAddress, error) {
|
||||||
return api.service.messenger.GetSavedAddresses(ctx)
|
return api.service.messenger.GetSavedAddresses(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@ func NewSavedAddressesManager(db *sql.DB) *SavedAddressesManager {
|
||||||
const rawQueryColumnsOrder = "address, name, removed, update_clock, chain_short_names, ens_name, is_test, created_at, color"
|
const rawQueryColumnsOrder = "address, name, removed, update_clock, chain_short_names, ens_name, is_test, created_at, color"
|
||||||
|
|
||||||
// getSavedAddressesFromDBRows retrieves all data based on SELECT Query using rawQueryColumnsOrder
|
// getSavedAddressesFromDBRows retrieves all data based on SELECT Query using rawQueryColumnsOrder
|
||||||
func getSavedAddressesFromDBRows(rows *sql.Rows) ([]SavedAddress, error) {
|
func getSavedAddressesFromDBRows(rows *sql.Rows) ([]*SavedAddress, error) {
|
||||||
var addresses []SavedAddress
|
var addresses []*SavedAddress
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
sa := SavedAddress{}
|
sa := &SavedAddress{}
|
||||||
// based on rawQueryColumnsOrder
|
// based on rawQueryColumnsOrder
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&sa.Address,
|
&sa.Address,
|
||||||
|
@ -68,7 +68,7 @@ func getSavedAddressesFromDBRows(rows *sql.Rows) ([]SavedAddress, error) {
|
||||||
return addresses, nil
|
return addresses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sam *SavedAddressesManager) getSavedAddresses(condition string) ([]SavedAddress, error) {
|
func (sam *SavedAddressesManager) getSavedAddresses(condition string) ([]*SavedAddress, error) {
|
||||||
var whereCondition string
|
var whereCondition string
|
||||||
if condition != "" {
|
if condition != "" {
|
||||||
whereCondition = fmt.Sprintf("WHERE %s", condition)
|
whereCondition = fmt.Sprintf("WHERE %s", condition)
|
||||||
|
@ -84,12 +84,12 @@ func (sam *SavedAddressesManager) getSavedAddresses(condition string) ([]SavedAd
|
||||||
return addresses, err
|
return addresses, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sam *SavedAddressesManager) GetSavedAddresses() ([]SavedAddress, error) {
|
func (sam *SavedAddressesManager) GetSavedAddresses() ([]*SavedAddress, error) {
|
||||||
return sam.getSavedAddresses("removed != 1")
|
return sam.getSavedAddresses("removed != 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRawSavedAddresses provides access to the soft-delete and sync metadata
|
// GetRawSavedAddresses provides access to the soft-delete and sync metadata
|
||||||
func (sam *SavedAddressesManager) GetRawSavedAddresses() ([]SavedAddress, error) {
|
func (sam *SavedAddressesManager) GetRawSavedAddresses() ([]*SavedAddress, error) {
|
||||||
return sam.getSavedAddresses("")
|
return sam.getSavedAddresses("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,13 +153,8 @@ func (sam *SavedAddressesManager) upsertSavedAddress(sa SavedAddress, tx *sql.Tx
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sam *SavedAddressesManager) UpdateMetadataAndUpsertSavedAddress(sa SavedAddress) (updatedClock uint64, err error) {
|
func (sam *SavedAddressesManager) UpdateMetadataAndUpsertSavedAddress(sa SavedAddress) error {
|
||||||
sa.UpdateClock = uint64(time.Now().Unix())
|
return sam.upsertSavedAddress(sa, nil)
|
||||||
err = sam.upsertSavedAddress(sa, nil)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return sa.UpdateClock, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sam *SavedAddressesManager) startTransactionAndCheckIfNewerChange(address common.Address, isTest bool, updateClock uint64) (newer bool, tx *sql.Tx, err error) {
|
func (sam *SavedAddressesManager) startTransactionAndCheckIfNewerChange(address common.Address, isTest bool, updateClock uint64) (newer bool, tx *sql.Tx, err error) {
|
||||||
|
@ -180,8 +175,8 @@ func (sam *SavedAddressesManager) startTransactionAndCheckIfNewerChange(address
|
||||||
return dbUpdateClock < updateClock, tx, nil
|
return dbUpdateClock < updateClock, tx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sam *SavedAddressesManager) AddSavedAddressIfNewerUpdate(sa SavedAddress, updateClock uint64) (insertedOrUpdated bool, err error) {
|
func (sam *SavedAddressesManager) AddSavedAddressIfNewerUpdate(sa SavedAddress) (insertedOrUpdated bool, err error) {
|
||||||
newer, tx, err := sam.startTransactionAndCheckIfNewerChange(sa.Address, sa.IsTest, updateClock)
|
newer, tx, err := sam.startTransactionAndCheckIfNewerChange(sa.Address, sa.IsTest, sa.UpdateClock)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
|
@ -193,7 +188,6 @@ func (sam *SavedAddressesManager) AddSavedAddressIfNewerUpdate(sa SavedAddress,
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.UpdateClock = updateClock
|
|
||||||
err = sam.upsertSavedAddress(sa, tx)
|
err = sam.upsertSavedAddress(sa, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -45,7 +45,7 @@ func TestSavedAddressesAdd(t *testing.T) {
|
||||||
IsTest: false,
|
IsTest: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = manager.UpdateMetadataAndUpsertSavedAddress(sa)
|
err = manager.UpdateMetadataAndUpsertSavedAddress(sa)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rst, err = manager.GetRawSavedAddresses()
|
rst, err = manager.GetRawSavedAddresses()
|
||||||
|
@ -77,7 +77,7 @@ func haveSameElements[T comparable](a []T, b []T, isEqual func(T, T) bool) bool
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func savedAddressDataIsEqual(a, b SavedAddress) bool {
|
func savedAddressDataIsEqual(a, b *SavedAddress) bool {
|
||||||
return a.Address == b.Address && a.Name == b.Name && a.ChainShortNames == b.ChainShortNames &&
|
return a.Address == b.Address && a.Name == b.Name && a.ChainShortNames == b.ChainShortNames &&
|
||||||
a.ENSName == b.ENSName && a.IsTest == b.IsTest && a.ColorID == b.ColorID
|
a.ENSName == b.ENSName && a.IsTest == b.IsTest && a.ColorID == b.ColorID
|
||||||
}
|
}
|
||||||
|
@ -117,10 +117,12 @@ func TestSavedAddressesMetadata(t *testing.T) {
|
||||||
Name: "Simple",
|
Name: "Simple",
|
||||||
ColorID: multiAccCommon.CustomizationColorBlue,
|
ColorID: multiAccCommon.CustomizationColorBlue,
|
||||||
IsTest: false,
|
IsTest: false,
|
||||||
|
savedAddressMeta: savedAddressMeta{
|
||||||
|
UpdateClock: 42,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var sa2UpdatedClock uint64
|
err = manager.UpdateMetadataAndUpsertSavedAddress(sa2)
|
||||||
sa2UpdatedClock, err = manager.UpdateMetadataAndUpsertSavedAddress(sa2)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dbSavedAddresses, err = manager.GetRawSavedAddresses()
|
dbSavedAddresses, err = manager.GetRawSavedAddresses()
|
||||||
|
@ -129,7 +131,7 @@ func TestSavedAddressesMetadata(t *testing.T) {
|
||||||
// The order is not guaranteed check raw entry to decide
|
// The order is not guaranteed check raw entry to decide
|
||||||
rawIndex := 0
|
rawIndex := 0
|
||||||
simpleIndex := 1
|
simpleIndex := 1
|
||||||
if dbSavedAddresses[0] != sa1 {
|
if dbSavedAddresses[0].Address == sa1.Address {
|
||||||
rawIndex = 1
|
rawIndex = 1
|
||||||
simpleIndex = 0
|
simpleIndex = 0
|
||||||
}
|
}
|
||||||
|
@ -141,18 +143,20 @@ func TestSavedAddressesMetadata(t *testing.T) {
|
||||||
|
|
||||||
// Check the default values
|
// Check the default values
|
||||||
require.False(t, dbSavedAddresses[rawIndex].Removed)
|
require.False(t, dbSavedAddresses[rawIndex].Removed)
|
||||||
require.Equal(t, dbSavedAddresses[rawIndex].UpdateClock, sa2UpdatedClock)
|
require.Equal(t, dbSavedAddresses[rawIndex].UpdateClock, sa2.UpdateClock)
|
||||||
require.Greater(t, dbSavedAddresses[rawIndex].UpdateClock, uint64(0))
|
require.Greater(t, dbSavedAddresses[rawIndex].UpdateClock, uint64(0))
|
||||||
|
|
||||||
sa2Older := sa2
|
sa2Older := sa2
|
||||||
sa2Older.IsTest = false
|
sa2Older.IsTest = false
|
||||||
|
sa2Older.UpdateClock = dbSavedAddresses[rawIndex].UpdateClock - 1
|
||||||
|
|
||||||
sa2Newer := sa2
|
sa2Newer := sa2
|
||||||
sa2Newer.IsTest = false
|
sa2Newer.IsTest = false
|
||||||
|
sa2Newer.UpdateClock = dbSavedAddresses[rawIndex].UpdateClock + 1
|
||||||
|
|
||||||
// Try to add an older entry
|
// Try to add an older entry
|
||||||
updated := false
|
updated := false
|
||||||
updated, err = manager.AddSavedAddressIfNewerUpdate(sa2Older, dbSavedAddresses[rawIndex].UpdateClock-1)
|
updated, err = manager.AddSavedAddressIfNewerUpdate(sa2Older)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, updated)
|
require.False(t, updated)
|
||||||
|
|
||||||
|
@ -161,18 +165,18 @@ func TestSavedAddressesMetadata(t *testing.T) {
|
||||||
|
|
||||||
rawIndex = 0
|
rawIndex = 0
|
||||||
simpleIndex = 1
|
simpleIndex = 1
|
||||||
if dbSavedAddresses[0] != sa1 {
|
if dbSavedAddresses[0].Address == sa1.Address {
|
||||||
rawIndex = 1
|
rawIndex = 1
|
||||||
simpleIndex = 0
|
simpleIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, 2, len(dbSavedAddresses))
|
require.Equal(t, 2, len(dbSavedAddresses))
|
||||||
require.True(t, haveSameElements([]SavedAddress{sa1, sa2}, dbSavedAddresses, savedAddressDataIsEqual))
|
require.True(t, haveSameElements([]*SavedAddress{&sa1, &sa2}, dbSavedAddresses, savedAddressDataIsEqual))
|
||||||
require.Equal(t, sa1.savedAddressMeta, dbSavedAddresses[simpleIndex].savedAddressMeta)
|
require.Equal(t, sa1.savedAddressMeta, dbSavedAddresses[simpleIndex].savedAddressMeta)
|
||||||
|
|
||||||
// Try to update sa2 with a newer entry
|
// Try to update sa2 with a newer entry
|
||||||
updatedClock := dbSavedAddresses[rawIndex].UpdateClock + 1
|
updatedClock := dbSavedAddresses[rawIndex].UpdateClock + 1
|
||||||
updated, err = manager.AddSavedAddressIfNewerUpdate(sa2Newer, updatedClock)
|
updated, err = manager.AddSavedAddressIfNewerUpdate(sa2Newer)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, updated)
|
require.True(t, updated)
|
||||||
|
|
||||||
|
@ -180,7 +184,7 @@ func TestSavedAddressesMetadata(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, 2, len(dbSavedAddresses))
|
require.Equal(t, 2, len(dbSavedAddresses))
|
||||||
require.True(t, haveSameElements([]SavedAddress{sa1, sa2Newer}, dbSavedAddresses, savedAddressDataIsEqual))
|
require.True(t, haveSameElements([]*SavedAddress{&sa1, &sa2Newer}, dbSavedAddresses, savedAddressDataIsEqual))
|
||||||
require.Equal(t, updatedClock, dbSavedAddresses[rawIndex].UpdateClock)
|
require.Equal(t, updatedClock, dbSavedAddresses[rawIndex].UpdateClock)
|
||||||
|
|
||||||
// Try to delete the sa2 newer entry
|
// Try to delete the sa2 newer entry
|
||||||
|
@ -254,7 +258,7 @@ func TestSavedAddressesGet(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(dbSavedAddresses))
|
require.Equal(t, 1, len(dbSavedAddresses))
|
||||||
|
|
||||||
require.True(t, savedAddressDataIsEqual(sa, dbSavedAddresses[0]))
|
require.True(t, savedAddressDataIsEqual(&sa, dbSavedAddresses[0]))
|
||||||
|
|
||||||
dbSavedAddresses, err = manager.GetSavedAddresses()
|
dbSavedAddresses, err = manager.GetSavedAddresses()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -277,7 +281,7 @@ func TestSavedAddressesDelete(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(rst))
|
require.Equal(t, 1, len(rst))
|
||||||
|
|
||||||
require.True(t, savedAddressDataIsEqual(sa0, rst[0]))
|
require.True(t, savedAddressDataIsEqual(&sa0, rst[0]))
|
||||||
|
|
||||||
// Modify IsTest flag, insert
|
// Modify IsTest flag, insert
|
||||||
sa1 := sa0
|
sa1 := sa0
|
||||||
|
@ -294,7 +298,7 @@ func TestSavedAddressesDelete(t *testing.T) {
|
||||||
rst, err = manager.GetSavedAddresses()
|
rst, err = manager.GetSavedAddresses()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(rst))
|
require.Equal(t, 1, len(rst))
|
||||||
require.True(t, savedAddressDataIsEqual(sa1, rst[0]))
|
require.True(t, savedAddressDataIsEqual(&sa1, rst[0]))
|
||||||
|
|
||||||
// Test that we still have both addresses
|
// Test that we still have both addresses
|
||||||
rst, err = manager.GetRawSavedAddresses()
|
rst, err = manager.GetRawSavedAddresses()
|
||||||
|
@ -325,7 +329,7 @@ func testInsertSameAddressWithOneChange(t *testing.T, member int) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(rst))
|
require.Equal(t, 1, len(rst))
|
||||||
|
|
||||||
require.True(t, savedAddressDataIsEqual(sa, rst[0]))
|
require.True(t, savedAddressDataIsEqual(&sa, rst[0]))
|
||||||
|
|
||||||
sa2 := sa
|
sa2 := sa
|
||||||
|
|
||||||
|
@ -350,12 +354,12 @@ func testInsertSameAddressWithOneChange(t *testing.T, member int) {
|
||||||
// guaranteed to be the same as insertions, so swap indices if first record does not match
|
// guaranteed to be the same as insertions, so swap indices if first record does not match
|
||||||
firstIndex := 0
|
firstIndex := 0
|
||||||
secondIndex := 1
|
secondIndex := 1
|
||||||
if rst[firstIndex] != sa {
|
if rst[firstIndex].Address == sa.Address {
|
||||||
firstIndex = 1
|
firstIndex = 1
|
||||||
secondIndex = 0
|
secondIndex = 0
|
||||||
}
|
}
|
||||||
require.True(t, savedAddressDataIsEqual(sa, rst[firstIndex]))
|
require.True(t, savedAddressDataIsEqual(&sa, rst[firstIndex]))
|
||||||
require.True(t, savedAddressDataIsEqual(sa2, rst[secondIndex]))
|
require.True(t, savedAddressDataIsEqual(&sa2, rst[secondIndex]))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSavedAddressesAddDifferentIsTest(t *testing.T) {
|
func TestSavedAddressesAddDifferentIsTest(t *testing.T) {
|
||||||
|
@ -380,7 +384,7 @@ func TestSavedAddressesAddSame(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(rst))
|
require.Equal(t, 1, len(rst))
|
||||||
|
|
||||||
require.True(t, savedAddressDataIsEqual(sa, rst[0]))
|
require.True(t, savedAddressDataIsEqual(&sa, rst[0]))
|
||||||
|
|
||||||
sa2 := sa
|
sa2 := sa
|
||||||
err = manager.upsertSavedAddress(sa2, nil)
|
err = manager.upsertSavedAddress(sa2, nil)
|
||||||
|
|
Loading…
Reference in New Issue