Merge pull request #467 from cosmos/bez/fix-broken-state-tests

Fix broken state unit tests
This commit is contained in:
Jack Zampolin 2018-08-15 15:31:13 -07:00 committed by GitHub
commit c1e6ebf80a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 33 deletions

View File

@ -96,9 +96,11 @@ func NewDatabase(stateDB, codeDB dbm.DB, storeCacheSize int) (*Database, error)
db.ethTrieDB = ethtrie.NewDatabase(&core.EthereumDB{CodeDB: codeDB})
var err error
if db.codeSizeCache, err = lru.New(codeSizeCacheSize); err != nil {
return nil, err
}
if db.storeCache, err = lru.New(storeCacheSize); err != nil {
return nil, err
}

View File

@ -7,25 +7,17 @@ import (
ethcmn "github.com/ethereum/go-ethereum/common"
ethstate "github.com/ethereum/go-ethereum/core/state"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tendermint/libs/db"
)
func newDatabase() *Database {
memDB := dbm.NewMemDB()
db, _ := NewDatabase(memDB, memDB)
return db
}
func TestDatabaseInterface(t *testing.T) {
require.Implements(t, (*ethstate.Database)(nil), new(Database))
}
func TestDatabaseLatestVersion(t *testing.T) {
testDB := newDatabase()
var version int64
testDB := newTestDatabase()
version = testDB.LatestVersion()
require.Equal(t, int64(0), version)
@ -34,27 +26,13 @@ func TestDatabaseLatestVersion(t *testing.T) {
require.Equal(t, int64(1), version)
}
// func TestDatabaseOpenTrie(t *testing.T) {
// testDB := newDatabase()
// testTrie, err := testDB.OpenTrie(rootHashFromVersion(0))
// require.Nil(t, err)
// require.IsType(t, &Trie{}, testTrie)
// require.NotNil(t, testTrie.(*Trie).store)
// require.NotNil(t, testTrie.(*Trie).accountsCache)
// require.NotNil(t, testTrie.(*Trie).storageCache)
// require.NotNil(t, testTrie.(*Trie).ethTrieDB)
// require.False(t, testTrie.(*Trie).empty)
// }
func TestDatabaseCopyTrie(t *testing.T) {
// TODO: Implement once CopyTrie is implemented
t.SkipNow()
}
func TestDatabaseContractCode(t *testing.T) {
testDB := newDatabase()
testDB := newTestDatabase()
testCases := []struct {
db *Database
@ -87,7 +65,7 @@ func TestDatabaseContractCode(t *testing.T) {
}
func TestDatabaseContractCodeSize(t *testing.T) {
testDB := newDatabase()
testDB := newTestDatabase()
testCases := []struct {
db *Database
@ -125,7 +103,7 @@ func TestDatabaseContractCodeSize(t *testing.T) {
}
func TestDatabaseTrieDB(t *testing.T) {
testDB := newDatabase()
testDB := newTestDatabase()
db := testDB.TrieDB()
require.Equal(t, testDB.ethTrieDB, db)

View File

@ -1,10 +1,13 @@
package state
import (
"fmt"
"math/rand"
"time"
ethcmn "github.com/ethereum/go-ethereum/common"
dbm "github.com/tendermint/tendermint/libs/db"
)
type (
@ -21,3 +24,14 @@ type (
func init() {
rand.Seed(time.Now().UnixNano())
}
func newTestDatabase() *Database {
memDB := dbm.NewMemDB()
testDB, err := NewDatabase(memDB, memDB, 100)
if err != nil {
panic(fmt.Sprintf("failed to create database: %v", err))
}
return testDB
}

View File

@ -8,20 +8,17 @@ import (
ethcmn "github.com/ethereum/go-ethereum/common"
ethstate "github.com/ethereum/go-ethereum/core/state"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tendermint/libs/db"
)
func newTestTrie() *Trie {
memDB := dbm.NewMemDB()
testDB, _ := NewDatabase(memDB, memDB)
testDB := newTestDatabase()
testTrie, _ := testDB.OpenTrie(rootHashFromVersion(0))
return testTrie.(*Trie)
}
func newTestPrefixTrie() *Trie {
memDB := dbm.NewMemDB()
testDB, _ := NewDatabase(memDB, memDB)
testDB := newTestDatabase()
prefix := make([]byte, ethcmn.HashLength)
rand.Read(prefix)