本文整理汇总了Golang中github.com/decred/dcrd/blockchain/stake.TicketDB.Store方法的典型用法代码示例。如果您正苦于以下问题:Golang TicketDB.Store方法的具体用法?Golang TicketDB.Store怎么用?Golang TicketDB.Store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/decred/dcrd/blockchain/stake.TicketDB
的用法示例。
在下文中一共展示了TicketDB.Store方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTicketDB
//.........这里部分代码省略.........
// Create snapshot of tmdb at block 168
CopyOfMapsAtBlock168, err = cloneTicketDB(&tmdb)
if err != nil {
t.Errorf("db cloning at block 168 failure! %v", err)
}
}
}
// Remove five blocks from HEAD~1
_, _, _, err = tmdb.RemoveBlockToHeight(50)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the roll back was symmetric to the earlier snapshot
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), CopyOfMapsAtBlock50) {
t.Errorf("The td did not restore to a previous block height correctly!")
}
// Test rescanning a ticket db
err = tmdb.RescanTicketDB()
if err != nil {
t.Errorf("rescanticketdb err: %v", err.Error())
}
// Test if the db file storage was symmetric to the earlier snapshot
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), CopyOfMapsAtBlock168) {
t.Errorf("The td did not rescan to HEAD correctly!")
}
err = os.Mkdir("testdata/", os.FileMode(0700))
if err != nil {
t.Error(err)
}
// Store the ticket db to disk
err = tmdb.Store("testdata/", "testtmdb")
if err != nil {
t.Errorf("error: %v", err)
}
var tmdb2 stake.TicketDB
err = tmdb2.LoadTicketDBs("testdata/", "testtmdb", simNetParams, database)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the db file storage was symmetric to previously rescanned one
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), tmdb2.DumpMapsPointer()) {
t.Errorf("The td did not rescan to a previous block height correctly!")
}
tmdb2.Close()
// Test dumping missing tickets from block 152
missedIn152, _ := chainhash.NewHashFromStr(
"84f7f866b0af1cc278cb8e0b2b76024a07542512c76487c83628c14c650de4fa")
tmdb.RemoveBlockToHeight(152)
missedTix, err := tmdb.DumpMissedTickets()
if err != nil {
t.Errorf("err dumping missed tix: %v", err.Error())
}
if _, exists := missedTix[*missedIn152]; !exists {
t.Errorf("couldn't finding missed tx 1 %v in tmdb @ block 152!",
missedIn152)
}
tmdb.RescanTicketDB()
// Make sure that the revoked map contains the revoked tx
revokedSlice := []*chainhash.Hash{missedIn152}
revokedTix, err := tmdb.DumpRevokedTickets()
if err != nil {
t.Errorf("err dumping missed tix: %v", err.Error())
}
if len(revokedTix) != 1 {
t.Errorf("revoked ticket map is wrong len, got %v, want %v",
len(revokedTix), 1)
}
_, wasMissedIn152 := revokedTix[*revokedSlice[0]]
ticketsRevoked := wasMissedIn152
if !ticketsRevoked {
t.Errorf("revoked ticket map did not include tickets missed in " +
"block 152 and later revoked")
}
database.Close()
tmdb.Close()
os.RemoveAll("ticketdb_test")
os.Remove("./ticketdb_test.ver")
os.Remove("testdata/testtmdb")
os.Remove("testdata")
}