},
},
{
- height: uint64(0),
+ height: uint64(1000000),
txs: []*query.AnnotatedTx{
&query.AnnotatedTx{
ID: bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
os.RemoveAll("temp")
}
}
+
+func TestDeleteWalletTransactions(t *testing.T) {
+ cases := []struct {
+ height uint64
+ txs []*query.AnnotatedTx
+ }{
+ {
+ height: uint64(0),
+ txs: []*query.AnnotatedTx{},
+ },
+ {
+ height: uint64(0),
+ txs: []*query.AnnotatedTx{
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(0),
+ Position: uint32(2333),
+ },
+ },
+ },
+ {
+ height: uint64(1000000),
+ txs: []*query.AnnotatedTx{
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(0),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x02, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(1),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x03, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(2),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x04, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(3),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x05, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(4),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x06, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(5),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x07, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(6),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x08, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(7),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x09, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(8),
+ },
+ &query.AnnotatedTx{
+ ID: bc.NewHash([32]byte{0x0a, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Timestamp: uint64(9988000),
+ BlockHeight: uint64(1000000),
+ Position: uint32(9),
+ },
+ },
+ },
+ }
+
+ for i, c := range cases {
+ testDB := dbm.NewDB("testdb", "leveldb", "temp")
+ walletStore := NewWalletStore(testDB)
+ ws := walletStore.InitBatch()
+ // store txs by given height
+ for _, tx := range c.txs {
+ if err := ws.SetTransaction(c.height, tx); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if err := ws.CommitBatch(); err != nil {
+ t.Fatal(err)
+ }
+
+ // delete all txs
+ ws = walletStore.InitBatch()
+ ws.DeleteWalletTransactions()
+ if err := ws.CommitBatch(); err != nil {
+ t.Fatal(err)
+ }
+
+ // get tx by txID, it should return err
+ for _, tx := range c.txs {
+ _, err := ws.GetTransaction(tx.ID.String())
+ if err == nil {
+ t.Errorf("case: %v: it should return some err.", i)
+ }
+ }
+
+ testDB.Close()
+ os.RemoveAll("temp")
+ }
+}