Commit a950d842 authored by HAOYUatHZ's avatar HAOYUatHZ Committed by Paladz

test: add test for PR#1708 https://github.com/Bytom/bytom/pull/1708 (#1723)

parent 82856be0
......@@ -201,6 +201,56 @@ func TestWalletUpdate(t *testing.T) {
}
}
func TestRescanWallet(t *testing.T) {
// prepare wallet & db
dirPath, err := ioutil.TempDir(".", "")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dirPath)
testDB := dbm.NewDB("testdb", "leveldb", "temp")
defer os.RemoveAll("temp")
store := database.NewStore(testDB)
dispatcher := event.NewDispatcher()
txPool := protocol.NewTxPool(store, dispatcher)
chain, err := protocol.NewChain(store, txPool)
if err != nil {
t.Fatal(err)
}
statusInfo := StatusInfo{
Version: currentVersion,
WorkHash: bc.Hash{V0: 0xff},
}
rawWallet, err := json.Marshal(statusInfo)
if err != nil {
t.Fatal("save wallet info")
}
w := mockWallet(testDB, nil, nil, chain, dispatcher, false)
w.DB.Set(walletKey, rawWallet)
rawWallet = w.DB.Get(walletKey)
if rawWallet == nil {
t.Fatal("fail to load wallet StatusInfo")
}
if err := json.Unmarshal(rawWallet, &w.status); err != nil {
t.Fatal(err)
}
// rescan wallet
if err := w.loadWalletInfo(); err != nil {
t.Fatal(err)
}
block := config.GenesisBlock()
if w.status.WorkHash != block.Hash() {
t.Fatal("reattach from genesis block")
}
}
func TestMemPoolTxQueryLoop(t *testing.T) {
dirPath, err := ioutil.TempDir(".", "")
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment