OSDN Git Service

update TestXPubsRecoveryLock
authorChengcheng Zhang <943420582@qq.com>
Wed, 3 Jul 2019 08:23:08 +0000 (16:23 +0800)
committerChengcheng Zhang <943420582@qq.com>
Wed, 3 Jul 2019 08:23:08 +0000 (16:23 +0800)
wallet/recovery_test.go
wallet/wallet_test.go

index 9074466..b422970 100644 (file)
@@ -137,7 +137,7 @@ func TestXPubsRecoveryLock(t *testing.T) {
        defer os.RemoveAll(dirPath)
 
        testDB := dbm.NewDB("testdb", "leveldb", dirPath)
-       testStore := database.NewWalletStore(testDB)
+       walletStore := newMockWalletStore(testDB)
        hsm, err := pseudohsm.New(dirPath)
        if err != nil {
                t.Fatal(err)
@@ -148,9 +148,9 @@ func TestXPubsRecoveryLock(t *testing.T) {
                t.Fatal(err)
        }
 
-       acctStore := database.NewAccountStore(testDB)
+       acctStore := newMockAccountStore(testDB)
        acctMgr := account.NewManager(acctStore, nil)
-       recoveryMgr := newRecoveryManager(testStore, acctMgr)
+       recoveryMgr := newRecoveryManager(walletStore, acctMgr)
        recoveryMgr.state = newRecoveryState()
        recoveryMgr.state.XPubs = []chainkd.XPub{xpub.XPub}
        recoveryMgr.state.XPubsStatus = newBranchRecoveryState(acctRecoveryWindow)
index c5f0c53..35585d5 100644 (file)
@@ -21,11 +21,13 @@ import (
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database"
        dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/storage"
        "github.com/vapor/errors"
        "github.com/vapor/event"
        "github.com/vapor/protocol"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
+       "github.com/vapor/protocol/state"
 )
 
 func TestEncodeDecodeGlobalTxIndex(t *testing.T) {
@@ -129,6 +131,7 @@ func TestWalletUpdate(t *testing.T) {
        }()
 
        store := database.NewStore(testDB)
+       // store := newStore(testDB)
        walletStore := database.NewWalletStore(testDB)
        // walletStore := newMockWalletStore(testDB)
        dispatcher := event.NewDispatcher()
@@ -141,6 +144,7 @@ func TestWalletUpdate(t *testing.T) {
 
        accountStore := database.NewAccountStore(testDB)
        accountManager := account.NewManager(accountStore, chain)
+       // accountManager := account.NewManager(accountStore, nil)
        hsm, err := pseudohsm.New(dirPath)
        if err != nil {
                t.Fatal(err)
@@ -164,6 +168,7 @@ func TestWalletUpdate(t *testing.T) {
        controlProg.KeyIndex = 1
 
        reg := asset.NewRegistry(testDB, chain)
+       // reg := asset.NewRegistry(testDB, nil)
        asset := bc.AssetID{V0: 5}
 
        utxos := []*account.UTXO{}
@@ -185,6 +190,7 @@ func TestWalletUpdate(t *testing.T) {
        store.SaveBlock(block, txStatus)
 
        w := mockWallet(walletStore, accountManager, reg, chain, dispatcher, true)
+       // w := mockWallet(walletStore, accountManager, reg, nil, dispatcher, true)
        err = w.AttachBlock(block)
        if err != nil {
                t.Fatal(err)
@@ -505,7 +511,8 @@ func (store *mockWalletStore) GetStandardUTXO(bc.Hash) (*acc.UTXO, error)
 func (store *mockWalletStore) GetUnconfirmedTransaction(string) (*query.AnnotatedTx, error) {
        return nil, nil
 }
-func (store *mockWalletStore) GetRecoveryStatus([]byte) []byte              { return nil }
+
+// func (store *mockWalletStore) GetRecoveryStatus([]byte) []byte              { return nil }
 func (store *mockWalletStore) ListAccountUTXOs(string) ([]*acc.UTXO, error) { return nil, nil }
 func (store *mockWalletStore) ListTransactions(string, string, uint, bool) ([]*query.AnnotatedTx, error) {
        return nil, nil
@@ -516,12 +523,18 @@ func (store *mockWalletStore) ListUnconfirmedTransactions() ([]*query.AnnotatedT
 func (store *mockWalletStore) SetAssetDefinition(*bc.AssetID, []byte)             { return }
 func (store *mockWalletStore) SetContractUTXO(bc.Hash, *acc.UTXO) error           { return nil }
 func (store *mockWalletStore) SetGlobalTransactionIndex(string, *bc.Hash, uint64) { return }
-func (store *mockWalletStore) SetRecoveryStatus([]byte, []byte)                   { return }
-func (store *mockWalletStore) SetTransaction(uint64, *query.AnnotatedTx) error    { return nil }
+
+// func (store *mockWalletStore) SetRecoveryStatus([]byte, []byte)                   { return }
+func (store *mockWalletStore) SetTransaction(uint64, *query.AnnotatedTx) error { return nil }
 func (store *mockWalletStore) SetUnconfirmedTransaction(string, *query.AnnotatedTx) error {
        return nil
 }
 
+// GetRecoveryStatus delete recovery status
+func (store *mockWalletStore) GetRecoveryStatus(recoveryKey []byte) []byte {
+       return store.walletDB.Get(recoveryKey)
+}
+
 // GetTransaction get tx by txid
 func (store *mockWalletStore) GetTransaction(txID string) (*query.AnnotatedTx, error) {
        formatKey := store.walletDB.Get(calcTxIndexKey(txID))
@@ -541,6 +554,15 @@ func (store *mockWalletStore) GetWalletInfo() []byte {
        return store.walletDB.Get([]byte(WalletKey))
 }
 
+// SetRecoveryStatus set recovery status
+func (store *mockWalletStore) SetRecoveryStatus(recoveryKey, rawStatus []byte) {
+       if store.batch == nil {
+               store.walletDB.Set(recoveryKey, rawStatus)
+       } else {
+               store.batch.Set(recoveryKey, rawStatus)
+       }
+}
+
 // SetWalletInfo get wallet information
 func (store *mockWalletStore) SetWalletInfo(rawWallet []byte) {
        if store.batch == nil {
@@ -549,3 +571,30 @@ func (store *mockWalletStore) SetWalletInfo(rawWallet []byte) {
                store.batch.Set([]byte(WalletKey), rawWallet)
        }
 }
+
+type mockStore struct {
+       db dbm.DB
+}
+
+// newStore creates and returns a new Store object.
+func newStore(db dbm.DB) *mockStore {
+       return &mockStore{
+               db: db,
+       }
+}
+
+func (s *mockStore) BlockExist(hash *bc.Hash) bool                                { return false }
+func (s *mockStore) GetBlock(*bc.Hash) (*types.Block, error)                      { return nil, nil }
+func (s *mockStore) GetBlockHeader(*bc.Hash) (*types.BlockHeader, error)          { return nil, nil }
+func (s *mockStore) GetStoreStatus() *protocol.BlockStoreState                    { return nil }
+func (s *mockStore) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
+func (s *mockStore) GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error     { return nil }
+func (s *mockStore) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)                 { return nil, nil }
+func (s *mockStore) GetVoteResult(uint64) (*state.VoteResult, error)              { return nil, nil }
+func (s *mockStore) GetMainChainHash(uint64) (*bc.Hash, error)                    { return nil, nil }
+func (s *mockStore) GetBlockHashesByHeight(uint64) ([]*bc.Hash, error)            { return nil, nil }
+func (s *mockStore) SaveBlock(*types.Block, *bc.TransactionStatus) error          { return nil }
+func (s *mockStore) SaveBlockHeader(*types.BlockHeader) error                     { return nil }
+func (s *mockStore) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.VoteResult) error {
+       return nil
+}