Skip to content

Commit

Permalink
w3types: fix merge of account with empty code (#176)
Browse files Browse the repository at this point in the history
* added test: merge empty code

* fixed account deep copy

---------

Co-authored-by: lmittmann <lmittmann@users.noreply.github.com>
  • Loading branch information
lmittmann and lmittmann authored Aug 8, 2024
1 parent 69c6c9b commit 2ed7c99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion w3types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (acc *Account) deepCopy() *Account {
if acc.Balance != nil {
newAcc.Balance = new(big.Int).Set(acc.Balance)
}
if len(acc.Code) > 0 {
if acc.Code != nil {
newAcc.Code = bytes.Clone(acc.Code)
}
if len(acc.Storage) > 0 {
Expand Down
18 changes: 18 additions & 0 deletions w3types/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ func TestStateMerge(t *testing.T) {
StateSrc: w3types.State{common.Address{}: {Storage: w3types.Storage{common.Hash{}: common.Hash{0x02}}}},
Want: w3types.State{common.Address{}: {Storage: w3types.Storage{common.Hash{}: common.Hash{0x02}}}},
},

// https://github.com/lmittmann/w3/pull/176
{
Name: "empty-code",
StateDst: w3types.State{common.Address{}: {Code: []byte{}}},
StateSrc: w3types.State{},
Want: w3types.State{
common.Address{}: {Code: []byte{}},
},
},
{
Name: "empty-code2",
StateDst: w3types.State{},
StateSrc: w3types.State{common.Address{}: {Code: []byte{}}},
Want: w3types.State{
common.Address{}: {Code: []byte{}},
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 2ed7c99

Please sign in to comment.