OSDN Git Service

feat(version): update version to 1.1.0
[bytom/bytom.git] / test / wallet_test_util.go
index d8bf730..1b27ac5 100644 (file)
@@ -7,15 +7,16 @@ import (
        "path"
        "reflect"
 
-       dbm "github.com/tendermint/tmlibs/db"
-
-       "github.com/bytom/account"
-       "github.com/bytom/asset"
-       "github.com/bytom/blockchain/pseudohsm"
-       "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/protocol"
-       "github.com/bytom/protocol/bc/types"
-       w "github.com/bytom/wallet"
+       "github.com/bytom/bytom/account"
+       "github.com/bytom/bytom/asset"
+       "github.com/bytom/bytom/blockchain/pseudohsm"
+       "github.com/bytom/bytom/blockchain/signers"
+       "github.com/bytom/bytom/crypto/ed25519/chainkd"
+       dbm "github.com/bytom/bytom/database/leveldb"
+       "github.com/bytom/bytom/event"
+       "github.com/bytom/bytom/protocol"
+       "github.com/bytom/bytom/protocol/bc/types"
+       w "github.com/bytom/bytom/wallet"
 )
 
 type walletTestConfig struct {
@@ -152,7 +153,7 @@ func (ctx *walletTestContext) createAsset(accountAlias string, assetAlias string
        if err != nil {
                return nil, err
        }
-       return ctx.Wallet.AssetReg.Define(acc.XPubs, len(acc.XPubs), nil, assetAlias, nil)
+       return ctx.Wallet.AssetReg.Define(acc.XPubs, len(acc.XPubs), nil, 0, assetAlias, nil)
 }
 
 func (ctx *walletTestContext) newBlock(txs []*types.Tx, coinbaseAccount string) (*types.Block, error) {
@@ -164,7 +165,7 @@ func (ctx *walletTestContext) newBlock(txs []*types.Tx, coinbaseAccount string)
 }
 
 func (ctx *walletTestContext) createKey(name string, password string) error {
-       _, err := ctx.Wallet.Hsm.XCreate(name, password)
+       _, _, err := ctx.Wallet.Hsm.XCreate(name, password, "en")
        return err
 }
 
@@ -177,7 +178,7 @@ func (ctx *walletTestContext) createAccount(name string, keys []string, quorum i
                }
                xpubs = append(xpubs, *xpub)
        }
-       _, err := ctx.Wallet.AccountMgr.Create(xpubs, quorum, name)
+       _, err := ctx.Wallet.AccountMgr.Create(xpubs, quorum, name, signers.BIP0044)
        return err
 }
 
@@ -192,7 +193,7 @@ func (ctx *walletTestContext) update(block *types.Block) error {
 }
 
 func (ctx *walletTestContext) getBalance(accountAlias string, assetAlias string) (uint64, error) {
-       balances, _ := ctx.Wallet.GetAccountBalances("")
+       balances, _ := ctx.Wallet.GetAccountBalances("", "")
        for _, balance := range balances {
                if balance.Alias == accountAlias && balance.AssetAlias == assetAlias {
                        return balance.Amount, nil
@@ -203,7 +204,7 @@ func (ctx *walletTestContext) getBalance(accountAlias string, assetAlias string)
 
 func (ctx *walletTestContext) getAccBalances() map[string]map[string]uint64 {
        accBalances := make(map[string]map[string]uint64)
-       balances, _ := ctx.Wallet.GetAccountBalances("")
+       balances, _ := ctx.Wallet.GetAccountBalances("", "")
        for _, balance := range balances {
                if accBalance, ok := accBalances[balance.Alias]; ok {
                        if _, ok := accBalance[balance.AssetAlias]; ok {
@@ -251,11 +252,15 @@ func (cfg *walletTestConfig) Run() error {
        }
 
        db := dbm.NewDB("wallet_test_db", "leveldb", path.Join(dirPath, "wallet_test_db"))
-       chain, _, _, _ := MockChain(db)
+       chain, _, _, err := MockChain(db)
+       if err != nil {
+               return err
+       }
        walletDB := dbm.NewDB("wallet", "leveldb", path.Join(dirPath, "wallet_db"))
        accountManager := account.NewManager(walletDB, chain)
        assets := asset.NewRegistry(walletDB, chain)
-       wallet, err := w.NewWallet(walletDB, accountManager, assets, hsm, chain)
+       dispatcher := event.NewDispatcher()
+       wallet, err := w.NewWallet(walletDB, accountManager, assets, hsm, chain, dispatcher, false)
        if err != nil {
                return err
        }