-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store non-hash values in a BPT [#3513]
- Loading branch information
1 parent
be144e5
commit 29006a1
Showing
9 changed files
with
173 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Accumulate Authors | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
package bpt | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue" | ||
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/memory" | ||
"gitlab.com/accumulatenetwork/accumulate/pkg/types/record" | ||
) | ||
|
||
var testValues = []struct { | ||
Key *record.Key | ||
Value []byte | ||
}{ | ||
{record.NewKey(record.KeyHash{0x00}), []byte{1}}, | ||
{record.NewKey(record.KeyHash{0x80}), []byte{2}}, | ||
{record.NewKey(record.KeyHash{0x40}), []byte{3}}, | ||
{record.NewKey(record.KeyHash{0xC0}), []byte{4}}, | ||
} | ||
|
||
func TestNonHashValues(t *testing.T) { | ||
store := memory.New(nil).Begin(nil, true) | ||
model := new(ChangeSet) | ||
model.store = keyvalue.RecordStore{Store: store} | ||
|
||
for _, e := range testValues { | ||
require.NoError(t, model.BPT().Insert(e.Key, e.Value)) | ||
} | ||
require.NoError(t, model.Commit()) | ||
|
||
lup := map[[32]byte][]byte{} | ||
for _, entry := range testValues { | ||
lup[entry.Key.Hash()] = entry.Value | ||
} | ||
|
||
for it := model.BPT().Iterate(100); it.Next(); { | ||
for _, leaf := range it.Value() { | ||
require.Equal(t, lup[leaf.Key.Hash()], leaf.Value) | ||
} | ||
} | ||
|
||
Print(t, model.BPT(), true) | ||
} |