Merge pull request #467 from cosmos/bez/fix-broken-state-tests
Fix broken state unit tests
This commit is contained in:
commit
c1e6ebf80a
@ -96,9 +96,11 @@ func NewDatabase(stateDB, codeDB dbm.DB, storeCacheSize int) (*Database, error)
|
|||||||
db.ethTrieDB = ethtrie.NewDatabase(&core.EthereumDB{CodeDB: codeDB})
|
db.ethTrieDB = ethtrie.NewDatabase(&core.EthereumDB{CodeDB: codeDB})
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if db.codeSizeCache, err = lru.New(codeSizeCacheSize); err != nil {
|
if db.codeSizeCache, err = lru.New(codeSizeCacheSize); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if db.storeCache, err = lru.New(storeCacheSize); err != nil {
|
if db.storeCache, err = lru.New(storeCacheSize); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,25 +7,17 @@ import (
|
|||||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||||
ethstate "github.com/ethereum/go-ethereum/core/state"
|
ethstate "github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestDatabaseInterface(t *testing.T) {
|
||||||
require.Implements(t, (*ethstate.Database)(nil), new(Database))
|
require.Implements(t, (*ethstate.Database)(nil), new(Database))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatabaseLatestVersion(t *testing.T) {
|
func TestDatabaseLatestVersion(t *testing.T) {
|
||||||
testDB := newDatabase()
|
|
||||||
|
|
||||||
var version int64
|
var version int64
|
||||||
|
|
||||||
|
testDB := newTestDatabase()
|
||||||
|
|
||||||
version = testDB.LatestVersion()
|
version = testDB.LatestVersion()
|
||||||
require.Equal(t, int64(0), version)
|
require.Equal(t, int64(0), version)
|
||||||
|
|
||||||
@ -34,27 +26,13 @@ func TestDatabaseLatestVersion(t *testing.T) {
|
|||||||
require.Equal(t, int64(1), version)
|
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) {
|
func TestDatabaseCopyTrie(t *testing.T) {
|
||||||
// TODO: Implement once CopyTrie is implemented
|
// TODO: Implement once CopyTrie is implemented
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatabaseContractCode(t *testing.T) {
|
func TestDatabaseContractCode(t *testing.T) {
|
||||||
testDB := newDatabase()
|
testDB := newTestDatabase()
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
db *Database
|
db *Database
|
||||||
@ -87,7 +65,7 @@ func TestDatabaseContractCode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDatabaseContractCodeSize(t *testing.T) {
|
func TestDatabaseContractCodeSize(t *testing.T) {
|
||||||
testDB := newDatabase()
|
testDB := newTestDatabase()
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
db *Database
|
db *Database
|
||||||
@ -125,7 +103,7 @@ func TestDatabaseContractCodeSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDatabaseTrieDB(t *testing.T) {
|
func TestDatabaseTrieDB(t *testing.T) {
|
||||||
testDB := newDatabase()
|
testDB := newTestDatabase()
|
||||||
|
|
||||||
db := testDB.TrieDB()
|
db := testDB.TrieDB()
|
||||||
require.Equal(t, testDB.ethTrieDB, db)
|
require.Equal(t, testDB.ethTrieDB, db)
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
|
dbm "github.com/tendermint/tendermint/libs/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -21,3 +24,14 @@ type (
|
|||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
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
|
||||||
|
}
|
||||||
|
@ -8,20 +8,17 @@ import (
|
|||||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||||
ethstate "github.com/ethereum/go-ethereum/core/state"
|
ethstate "github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
dbm "github.com/tendermint/tendermint/libs/db"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestTrie() *Trie {
|
func newTestTrie() *Trie {
|
||||||
memDB := dbm.NewMemDB()
|
testDB := newTestDatabase()
|
||||||
testDB, _ := NewDatabase(memDB, memDB)
|
|
||||||
testTrie, _ := testDB.OpenTrie(rootHashFromVersion(0))
|
testTrie, _ := testDB.OpenTrie(rootHashFromVersion(0))
|
||||||
|
|
||||||
return testTrie.(*Trie)
|
return testTrie.(*Trie)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestPrefixTrie() *Trie {
|
func newTestPrefixTrie() *Trie {
|
||||||
memDB := dbm.NewMemDB()
|
testDB := newTestDatabase()
|
||||||
testDB, _ := NewDatabase(memDB, memDB)
|
|
||||||
|
|
||||||
prefix := make([]byte, ethcmn.HashLength)
|
prefix := make([]byte, ethcmn.HashLength)
|
||||||
rand.Read(prefix)
|
rand.Read(prefix)
|
||||||
|
Loading…
Reference in New Issue
Block a user