OSDN Git Service

filter change output (#248)
[bytom/vapor.git] / account / accounts_test.go
index b1710df..d2722bb 100644 (file)
@@ -7,18 +7,14 @@ import (
        "strings"
        "testing"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/signers"
-       "github.com/vapor/common"
        "github.com/vapor/config"
-       "github.com/vapor/consensus"
-       engine "github.com/vapor/consensus/consensus"
-       dpos "github.com/vapor/consensus/consensus/dpos"
        "github.com/vapor/crypto/ed25519/chainkd"
-       "github.com/vapor/database/leveldb"
+       "github.com/vapor/database"
+       dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/errors"
+       "github.com/vapor/event"
        "github.com/vapor/protocol"
        "github.com/vapor/testutil"
 )
@@ -65,7 +61,7 @@ func TestCreateAccount(t *testing.T) {
        m := mockAccountManager(t)
        account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias", signers.BIP0044)
        if err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        found, err := m.FindByID(account.ID)
@@ -125,12 +121,12 @@ func TestDeleteAccount(t *testing.T) {
 
        account1, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias1", signers.BIP0044)
        if err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        account2, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias2", signers.BIP0044)
        if err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        found, err := m.FindByID(account1.ID)
@@ -139,7 +135,7 @@ func TestDeleteAccount(t *testing.T) {
        }
 
        if err = m.DeleteAccount(account2.ID); err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        found, err = m.FindByID(account2.ID)
@@ -154,7 +150,7 @@ func TestFindByID(t *testing.T) {
 
        found, err := m.FindByID(account.ID)
        if err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        if !testutil.DeepEqual(account, found) {
@@ -168,7 +164,7 @@ func TestFindByAlias(t *testing.T) {
 
        found, err := m.FindByAlias("some-alias")
        if err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        if !testutil.DeepEqual(account, found) {
@@ -210,35 +206,18 @@ func TestGetAccountIndexKey(t *testing.T) {
 }
 
 func mockAccountManager(t *testing.T) *Manager {
-
-       config.CommonConfig = config.DefaultConfig()
-       consensus.SoloNetParams.Signer = "78673764e0ba91a4c5ba9ec0c8c23c69e3d73bf27970e05e0a977e81e13bde475264d3b177a96646bc0ce517ae7fd63504c183ab6d330dea184331a4cf5912d5"
-       config.CommonConfig.Consensus.SelfVoteSigners = append(config.CommonConfig.Consensus.SelfVoteSigners, "vsm1qkm743xmgnvh84pmjchq2s4tnfpgu9ae2f9slep")
-       config.CommonConfig.Consensus.XPrv = "a8e281b615809046698fb0b0f2804a36d824d48fa443350f10f1b80649d39e5f1e85cf9855548915e36137345910606cbc8e7dd8497c831dce899ee6ac112445"
-       for _, v := range config.CommonConfig.Consensus.SelfVoteSigners {
-               address, err := common.DecodeAddress(v, &consensus.SoloNetParams)
-               if err != nil {
-                       t.Fatal(err)
-               }
-               config.CommonConfig.Consensus.Signers = append(config.CommonConfig.Consensus.Signers, address)
-       }
        dirPath, err := ioutil.TempDir(".", "")
        if err != nil {
                t.Fatal(err)
        }
        defer os.RemoveAll(dirPath)
 
-       testDB := dbm.NewDB("testdb", "memdb", "temp")
-       defer os.RemoveAll("temp")
-
-       store := leveldb.NewStore(testDB)
-       txPool := protocol.NewTxPool(store)
-       var engine engine.Engine
-       switch config.CommonConfig.Consensus.Type {
-       case "dpos":
-               engine = dpos.GDpos
-       }
-       chain, err := protocol.NewChain(store, txPool, engine)
+       testDB := dbm.NewDB("testdb", "memdb", dirPath)
+       dispatcher := event.NewDispatcher()
+       store := database.NewStore(testDB)
+       txPool := protocol.NewTxPool(store, dispatcher)
+       config.CommonConfig = config.DefaultConfig()
+       chain, err := protocol.NewChain(store, txPool, dispatcher)
        if err != nil {
                t.Fatal(err)
        }
@@ -249,7 +228,7 @@ func mockAccountManager(t *testing.T) *Manager {
 func (m *Manager) createTestAccount(t testing.TB, alias string, tags map[string]interface{}) *Account {
        account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, alias, signers.BIP0044)
        if err != nil {
-               testutil.FatalErr(t, err)
+               t.Fatal(err)
        }
 
        return account