Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account.Code bug found and fixed. Tests are updated #57

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions db/substate_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func TestSubstateDB_GetSubstate(t *testing.T) {
t.Fatal("substate is nil")
}

// todo code does weird stuff
//if err = ss.Equal(testSubstate); err != nil {
// t.Fatalf("substates are different; %v", err)
//}
if err = ss.Equal(testSubstate); err != nil {
t.Fatalf("substates are different; %v", err)
}
}

func TestSubstateDB_DeleteSubstate(t *testing.T) {
Expand Down Expand Up @@ -121,6 +120,8 @@ func createDbAndPutSubstate(dbPath string) (*substateDB, error) {
h2 := types.Hash{}
h2.SetBytes(nil)

tt := &testSubstate
_ = tt
evgensheff marked this conversation as resolved.
Show resolved Hide resolved
testSubstate.InputSubstate[types.Address{1}] = substate.NewAccount(1, new(big.Int).SetUint64(1), h1[:])
testSubstate.OutputSubstate[types.Address{2}] = substate.NewAccount(2, new(big.Int).SetUint64(2), h2[:])
testSubstate.Env.BlockHashes[1] = types.BytesToHash([]byte{1})
Expand Down
7 changes: 3 additions & 4 deletions db/update_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ func TestUpdateDB_GetUpdateSet(t *testing.T) {
t.Fatal("update-set is nil")
}

// todo code does weird stuff
//if err = ss.Equal(testSubstate); err != nil {
// t.Fatalf("substates are different; %v", err)
//}
if !us.Equal(testUpdateSet) {
t.Fatal("substates are different")
}
}

func TestUpdateDB_DeleteUpdateSet(t *testing.T) {
Expand Down
12 changes: 10 additions & 2 deletions rlp/rlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ func (r *RLP) ToSubstate(getHashFunc func(codeHash types.Hash) ([]byte, error),
return nil, err
}

input, err := r.InputSubstate.ToSubstate(getHashFunc)
if err != nil {
return nil, err
}
output, err := r.OutputSubstate.ToSubstate(getHashFunc)
if err != nil {
return nil, err
}
return &substate.Substate{
InputSubstate: r.InputSubstate.ToSubstate(),
OutputSubstate: r.OutputSubstate.ToSubstate(),
InputSubstate: input,
OutputSubstate: output,
Env: r.Env.ToSubstate(),
Message: msg,
Result: r.Result.ToSubstate(),
Expand Down
2 changes: 1 addition & 1 deletion rlp/rlp_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Message struct {
func (m Message) ToSubstate(getHashFunc func(codeHash types.Hash) ([]byte, error)) (*substate.Message, error) {
sm := &substate.Message{
Nonce: m.Nonce,
CheckNonce: !m.CheckNonce, //TODO: find out if this is correct
CheckNonce: m.CheckNonce,
GasPrice: m.GasPrice,
Gas: m.Gas,
From: m.From,
Expand Down
10 changes: 7 additions & 3 deletions rlp/rlp_world_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type WorldState struct {
}

// ToSubstate transforms a from WorldState to substate.WorldState.
func (ws WorldState) ToSubstate() substate.WorldState {
func (ws WorldState) ToSubstate(getHashFunc func(codeHash types.Hash) ([]byte, error)) (substate.WorldState, error) {
sws := make(substate.WorldState)

// iterate through addresses and assign it correctly to substate.WorldState
Expand All @@ -34,11 +34,15 @@ func (ws WorldState) ToSubstate() substate.WorldState {
// Address at second position matches SubstateAccountRLP at second position, and so on
for i, addr := range ws.Addresses {
acc := ws.Accounts[i]
sws[addr] = substate.NewAccount(acc.Nonce, acc.Balance, acc.CodeHash[:])
code, err := getHashFunc(acc.CodeHash)
if err != nil {
return nil, err
}
sws[addr] = substate.NewAccount(acc.Nonce, acc.Balance, code)
for pos := range acc.Storage {
sws[addr].Storage[acc.Storage[pos][0]] = acc.Storage[pos][1]
}
}

return sws
return sws, nil
}
20 changes: 20 additions & 0 deletions updateset/update_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ func (up UpdateSetRLP) ToWorldState(getCodeFunc func(codeHash types.Hash) ([]byt

return NewUpdateSet(worldState, block), nil
}

func (x *UpdateSet) Equal(y *UpdateSet) bool {
if x == y {
return true
}
if !x.WorldState.Equal(y.WorldState) {
return false
}

if x.Block != y.Block {
return false
}

for i, val := range x.DeletedAccounts {
if val != y.DeletedAccounts[i] {
return false
}
}
return true
}