Skip to content

Commit

Permalink
releases properly resources for State tests (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjezek authored Sep 16, 2024
1 parent a7cc9b3 commit be883e3
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 97 deletions.
54 changes: 52 additions & 2 deletions go/database/mpt/root_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func TestS5RootHash_EmptyTrie(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

hash, err := state.GetHash()
if err != nil {
t.Fatalf("failed to get hash for empty state: %v", err)
Expand All @@ -47,6 +53,12 @@ func TestS5RootHash_SingleAccount(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

balance := amount.New(12)
state.SetNonce(common.Address{1}, common.ToNonce(10))
state.SetBalance(common.Address{1}, balance)
Expand All @@ -67,6 +79,12 @@ func TestS5RootHash_SingleAccountWithSingleValue(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

balance := amount.New(12)
state.SetNonce(common.Address{1}, common.ToNonce(10))
state.SetBalance(common.Address{1}, balance)
Expand All @@ -88,6 +106,12 @@ func TestS5RootHash_TwoAccounts(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

balance := amount.New(12)
state.SetNonce(common.Address{1}, common.ToNonce(10))
state.SetBalance(common.Address{2}, balance)
Expand All @@ -108,6 +132,12 @@ func TestS5RootHash_TwoAccountsWithValues(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

balance := amount.New(12)
state.SetNonce(common.Address{1}, common.ToNonce(10))
state.trie.SetValue(common.Address{1}, common.Key{1}, common.Value{0, 0, 1})
Expand Down Expand Up @@ -140,6 +170,12 @@ func TestS5RootHash_TwoAccountsWithExtensionNodeWithEvenLength(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

balance := amount.New(12)
state.SetNonce(addr1, common.ToNonce(10))
state.SetBalance(addr2, balance)
Expand Down Expand Up @@ -167,6 +203,12 @@ func TestS5RootHash_TwoAccountsWithExtensionNodeWithOddLength(t *testing.T) {
if err != nil {
t.Fatalf("failed to open empty state: %v", err)
}
defer func() {
if err := state.Close(); err != nil {
t.Fatalf("failed to close state: %v", err)
}
}()

balance := amount.New(12)
state.SetNonce(addr1, common.ToNonce(10))
state.SetBalance(addr2, balance)
Expand Down Expand Up @@ -200,7 +242,11 @@ func TestS5RootHash_AddressAndKeys(t *testing.T) {
if err != nil {
t.Fatalf("failed to open trie: %v", err)
}
defer trie.Close()
defer func() {
if err := trie.Close(); err != nil {
t.Fatalf("failed to close trie: %v", err)
}
}()

address := getTestAddresses(N)
keys := getTestKeys(N)
Expand Down Expand Up @@ -266,7 +312,11 @@ func TestS5RootHash_Values(t *testing.T) {
if err != nil {
t.Fatalf("failed to open trie: %v", err)
}
defer trie.Close()
defer func() {
if err := trie.Close(); err != nil {
t.Fatalf("failed to close trie: %v", err)
}
}()

trgAddr := common.Address{}
keys := getTestKeys(N)
Expand Down
Loading

0 comments on commit be883e3

Please sign in to comment.