Fixed sql tx close, fixed unit tests. Refactoring. Added missing structs and methods.

This commit is contained in:
Oleksandr Brezhniev
2021-06-25 23:34:20 +03:00
parent cadeb222c6
commit 113995d6f4
13 changed files with 1531 additions and 1044 deletions

View File

@@ -46,7 +46,9 @@ func (m *Storage) Get(key []byte) (*merkletree.Node, error) {
func (m *Storage) GetRoot() (*merkletree.Hash, error) {
if m.currentRoot != nil {
return m.currentRoot, nil
hash := merkletree.Hash{}
copy(hash[:], m.currentRoot[:])
return &hash, nil
}
return nil, merkletree.ErrNotFound
}
@@ -97,7 +99,7 @@ func (tx *StorageTx) Put(k []byte, v *merkletree.Node) error {
func (tx *StorageTx) GetRoot() (*merkletree.Hash, error) {
if tx.currentRoot != nil {
hash := merkletree.Hash{}
copy(tx.currentRoot[:], hash[:])
copy(hash[:], tx.currentRoot[:])
return &hash, nil
}
return nil, merkletree.ErrNotFound
@@ -105,6 +107,9 @@ func (tx *StorageTx) GetRoot() (*merkletree.Hash, error) {
// SetRoot sets a hash of merkle tree root in the interface db.Tx
func (tx *StorageTx) SetRoot(hash *merkletree.Hash) error {
// TODO: do tx.Put('currentroot', hash) here ?
root := &merkletree.Hash{}
copy(root[:], hash[:])
tx.currentRoot = root
@@ -116,6 +121,10 @@ func (tx *StorageTx) Commit() error {
for _, v := range tx.kv {
tx.s.kv.Put(v.K, v.V)
}
//if tx.currentRoot == nil {
// tx.currentRoot = &merkletree.Hash{}
//}
tx.s.currentRoot = tx.currentRoot
tx.kv = nil
return nil
}

View File

@@ -22,4 +22,29 @@ func TestMemory(t *testing.T) {
test.TestConcatTx(t, NewMemoryStorage())
test.TestList(t, NewMemoryStorage())
test.TestIterate(t, NewMemoryStorage())
test.TestNewTree(t, NewMemoryStorage())
test.TestAddDifferentOrder(t, NewMemoryStorage(), NewMemoryStorage())
test.TestAddRepeatedIndex(t, NewMemoryStorage())
test.TestGet(t, NewMemoryStorage())
test.TestUpdate(t, NewMemoryStorage())
test.TestUpdate2(t, NewMemoryStorage())
test.TestGenerateAndVerifyProof128(t, NewMemoryStorage())
test.TestTreeLimit(t, NewMemoryStorage())
test.TestSiblingsFromProof(t, NewMemoryStorage())
test.TestVerifyProofCases(t, NewMemoryStorage())
test.TestVerifyProofFalse(t, NewMemoryStorage())
test.TestGraphViz(t, NewMemoryStorage())
test.TestDelete(t, NewMemoryStorage())
test.TestDelete2(t, NewMemoryStorage(), NewMemoryStorage())
test.TestDelete3(t, NewMemoryStorage(), NewMemoryStorage())
test.TestDelete4(t, NewMemoryStorage(), NewMemoryStorage())
test.TestDelete5(t, NewMemoryStorage(), NewMemoryStorage())
test.TestDeleteNonExistingKeys(t, NewMemoryStorage())
test.TestDumpLeafsImportLeafs(t, NewMemoryStorage(), NewMemoryStorage())
test.TestAddAndGetCircomProof(t, NewMemoryStorage())
test.TestUpdateCircomProcessorProof(t, NewMemoryStorage())
test.TestSmtVerifier(t, NewMemoryStorage())
test.TestTypesMarshalers(t, NewMemoryStorage())
}