status-go/db/tx_test.go
Dmitry Shulyak 14c513bd5a
Execute writes atomically only after request was processed without errors (#1454)
* Replace request ID when same request is restarted

* Remove unnecessary changes

* Execute all writes atomically only if request was processed succesfully

* Fix linter

* Fix shadowed errors

* Fix spelling

* Do not append same reference to a byte slice
2019-05-06 09:33:19 +03:00

24 lines
488 B
Go

package db
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestTxWritesOnCommit(t *testing.T) {
storage, err := NewMemoryLevelDBStorage()
tx := storage.NewTx()
require.NoError(t, err)
key := []byte{1}
val := []byte{1, 1}
require.NoError(t, tx.Put(key, val))
result, err := storage.Get(key)
require.Error(t, err)
require.Nil(t, result)
require.NoError(t, tx.Commit())
result, err = storage.Get(key)
require.NoError(t, err)
require.Equal(t, val, result)
}