From c03de88b410a53bfb6aca56c1ac4fb3d847f04ba Mon Sep 17 00:00:00 2001 From: Vsevolod Brekelov Date: Tue, 19 Nov 2019 17:11:46 +0300 Subject: [PATCH] core: unit tests blockchain state --- pkg/core/blockchain_state_test.go | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pkg/core/blockchain_state_test.go diff --git a/pkg/core/blockchain_state_test.go b/pkg/core/blockchain_state_test.go new file mode 100644 index 000000000..3a625c784 --- /dev/null +++ b/pkg/core/blockchain_state_test.go @@ -0,0 +1,46 @@ +package core + +import ( + "testing" + + "github.com/CityOfZion/neo-go/pkg/core/storage" + "github.com/CityOfZion/neo-go/pkg/core/transaction" + "github.com/stretchr/testify/require" +) + +func TestNewBlockChainStateAndCommit(t *testing.T) { + memCachedStore := storage.NewMemCachedStore(storage.NewMemoryStore()) + bcState := NewBlockChainState(memCachedStore) + err := bcState.commit() + require.NoError(t, err) +} + +func TestStoreAsBlock(t *testing.T) { + memCachedStore := storage.NewMemCachedStore(storage.NewMemoryStore()) + bcState := NewBlockChainState(memCachedStore) + + block := newBlock(0, newMinerTX()) + err := bcState.storeAsBlock(block, 0) + require.NoError(t, err) +} + +func TestStoreAsCurrentBlock(t *testing.T) { + memCachedStore := storage.NewMemCachedStore(storage.NewMemoryStore()) + bcState := NewBlockChainState(memCachedStore) + + block := newBlock(0, newMinerTX()) + err := bcState.storeAsCurrentBlock(block) + require.NoError(t, err) +} + +func TestStoreAsTransaction(t *testing.T) { + memCachedStore := storage.NewMemCachedStore(storage.NewMemoryStore()) + bcState := NewBlockChainState(memCachedStore) + + tx := &transaction.Transaction{ + Type: transaction.MinerType, + Data: &transaction.MinerTX{}, + } + err := bcState.storeAsTransaction(tx, 0) + require.NoError(t, err) +}