package test
import (
- "fmt"
"io/ioutil"
"os"
"reflect"
}
}
-func TestRescanWallet(t *testing.T) {
- rescan := func() {
- // prepare wallet & db.
- dirPath, err := ioutil.TempDir(".", "")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(dirPath)
-
- config.CommonConfig = config.DefaultConfig()
- testDB := dbm.NewDB("testdb", "leveldb", "temp")
- walletStore := database.NewWalletStore(testDB)
- defer func() {
- testDB.Close()
- os.RemoveAll("temp")
- }()
-
- store := database.NewStore(testDB)
- dispatcher := event.NewDispatcher()
- txPool := protocol.NewTxPool(store, dispatcher)
- chain, err := protocol.NewChain(store, txPool, dispatcher)
- if err != nil {
- t.Fatal(err)
- }
-
- statusInfo := wt.StatusInfo{
- Version: uint(1),
- WorkHash: bc.Hash{V0: 0xff},
- }
- if err := walletStore.SetWalletInfo(&statusInfo); err != nil {
- t.Fatal(err)
- }
- walletInfo, err := walletStore.GetWalletInfo()
- if err != nil {
- t.Fatal(err)
- }
-
- accountStore := database.NewAccountStore(testDB)
- accountManager := account.NewManager(accountStore, chain)
- w := newMockWallet(walletStore, accountManager, nil, chain, dispatcher, false)
- // w := newMockWallet(walletStore, nil, nil, chain, dispatcher, false)
- w.Wallet.Status = *walletInfo
-
- // rescan wallet.
- if err := w.Wallet.LoadWalletInfo(); err != nil {
- t.Fatal(err)
- }
-
- block := config.GenesisBlock()
- if w.Wallet.Status.WorkHash != block.Hash() {
- t.Fatal("reattach from genesis block")
- }
- }
-
- for i := 0; i < 100; i++ {
- fmt.Printf("case i: %v\n", i)
- rescan()
- }
-}
+// func TestRescanWallet(t *testing.T) {
+// rescan := func() {
+// // prepare wallet & db.
+// dirPath, err := ioutil.TempDir(".", "")
+// if err != nil {
+// t.Fatal(err)
+// }
+// defer os.RemoveAll(dirPath)
+
+// config.CommonConfig = config.DefaultConfig()
+// testDB := dbm.NewDB("testdb", "leveldb", "temp")
+// walletStore := database.NewWalletStore(testDB)
+// defer func() {
+// testDB.Close()
+// os.RemoveAll("temp")
+// }()
+
+// store := database.NewStore(testDB)
+// dispatcher := event.NewDispatcher()
+// txPool := protocol.NewTxPool(store, dispatcher)
+// chain, err := protocol.NewChain(store, txPool, dispatcher)
+// if err != nil {
+// t.Fatal(err)
+// }
+
+// statusInfo := wt.StatusInfo{
+// Version: uint(1),
+// WorkHash: bc.Hash{V0: 0xff},
+// }
+// if err := walletStore.SetWalletInfo(&statusInfo); err != nil {
+// t.Fatal(err)
+// }
+// walletInfo, err := walletStore.GetWalletInfo()
+// if err != nil {
+// t.Fatal(err)
+// }
+
+// accountStore := database.NewAccountStore(testDB)
+// accountManager := account.NewManager(accountStore, chain)
+// w := newMockWallet(walletStore, accountManager, nil, chain, dispatcher, false)
+// // w := newMockWallet(walletStore, nil, nil, chain, dispatcher, false)
+// w.Wallet.Status = *walletInfo
+
+// // rescan wallet.
+// if err := w.Wallet.LoadWalletInfo(); err != nil {
+// t.Fatal(err)
+// }
+
+// block := config.GenesisBlock()
+// if w.Wallet.Status.WorkHash != block.Hash() {
+// t.Fatal("reattach from genesis block")
+// }
+// }
+
+// for i := 0; i < 100; i++ {
+// fmt.Printf("case i: %v\n", i)
+// rescan()
+// }
+// }
func TestMemPoolTxQueryLoop(t *testing.T) {
dirPath, err := ioutil.TempDir(".", "")
for _, v := range tx.Outputs {
var hash [32]byte
sha3pool.Sum256(hash[:], v.ControlProgram())
- if _, err := w.AccountMgr.GetControlProgram(bc.NewHash(hash)); err != nil {
+ if _, err := w.AccountMgr.GetControlProgram(bc.NewHash(hash)); err == nil {
+ annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
+ continue transactionLoop
+ } else {
log.WithFields(log.Fields{"module": logModule, "err": err, "hash": hex.EncodeToString(hash[:])}).Error("filterAccountTxs fail.")
- continue
}
- annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
- continue transactionLoop
+
}
for _, v := range tx.Inputs {
log.WithFields(log.Fields{"module": logModule, "err": err, "outputID": hex.EncodeToString(outid.Bytes())}).Error("filterAccountTxs fail.")
continue
}
- if _, err = w.store.GetStandardUTXO(outid); err != nil {
+ if _, err = w.store.GetStandardUTXO(outid); err == nil {
+ annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
+ continue transactionLoop
+ } else {
log.WithFields(log.Fields{"module": logModule, "err": err, "outputID": hex.EncodeToString(outid.Bytes())}).Error("filterAccountTxs fail.")
- continue
}
- annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
- continue transactionLoop
+
}
}