Skip to content

Commit

Permalink
Merge branch 'main' into cf/merge-master-5-30
Browse files Browse the repository at this point in the history
  • Loading branch information
chasefleming committed May 30, 2024
2 parents d5e18ab + 39af92e commit 7919c40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion accounts/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
16 changes: 9 additions & 7 deletions accounts/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7919c40

Please sign in to comment.