diff --git a/accounts/account.go b/accounts/account.go index a3c8b15c..c00eea44 100644 --- a/accounts/account.go +++ b/accounts/account.go @@ -185,7 +185,7 @@ func (a Accounts) ByName(name string) (*Account, error) { func (a *Accounts) AddOrUpdate(account *Account) { for i, acc := range *a { if acc.Name == account.Name { - (*a)[i] = acc + (*a)[i] = *account return } } diff --git a/accounts/account_test.go b/accounts/account_test.go index c4c684e8..07419286 100644 --- a/accounts/account_test.go +++ b/accounts/account_test.go @@ -87,18 +87,20 @@ func Test_Accounts(t *testing.T) { Account{Name: "bob"}, } - accs.AddOrUpdate(&Account{Name: "mike"}) + initialMike := &Account{Name: "mike"} + accs.AddOrUpdate(initialMike) assert.Equal(t, "alice,bob,mike", accs.String()) - m1, err := accs.ByName("mike") + initialMikeFromState, err := accs.ByName("mike") assert.NoError(t, err) - assert.Equal(t, "0000000000000000", m1.Address.String()) + assert.Equal(t, "0000000000000000", initialMikeFromState.Address.String()) - m1.Address = flow.HexToAddress("0x02") - accs.AddOrUpdate(m1) - m2, err := accs.ByName("mike") + updatedMike := &Account{Name: "mike", Address: flow.HexToAddress("0x02")} + accs.AddOrUpdate(updatedMike) + + updatedMikeFromState, err := accs.ByName("mike") assert.NoError(t, err) - assert.Equal(t, "0000000000000002", m2.Address.String()) + assert.Equal(t, "0000000000000002", updatedMikeFromState.Address.String()) }) t.Run("Remove", func(t *testing.T) {