os.RemoveAll("temp")
}
}
+
+func TestDeleteWalletUTXOs(t *testing.T) {
+ cases := []struct {
+ utxos []*acc.UTXO
+ }{
+ {
+ utxos: []*acc.UTXO{},
+ },
+ {
+ utxos: []*acc.UTXO{
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{}),
+ Address: "address0",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ },
+ },
+ {
+ utxos: []*acc.UTXO{
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address0",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ },
+ },
+ {
+ utxos: []*acc.UTXO{
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address0",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address1",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address2",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address3",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address4",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address5",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address6",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address7",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address8",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ &acc.UTXO{
+ OutputID: bc.NewHash([32]byte{0x0a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+ Address: "address9",
+ Amount: uint64(0),
+ Change: true,
+ AccountID: "account",
+ SourcePos: uint64(0),
+ },
+ },
+ },
+ }
+
+ for i, c := range cases {
+ testDB := dbm.NewDB("testdb", "leveldb", "temp")
+ walletStore := NewWalletStore(testDB)
+ ws := walletStore.InitBatch()
+ // store utxos
+ for _, utxo := range c.utxos {
+ if err := ws.SetContractUTXO(utxo.OutputID, utxo); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if err := ws.CommitBatch(); err != nil {
+ t.Fatal(err)
+ }
+
+ // delete all utxos
+ ws = walletStore.InitBatch()
+ ws.DeleteWalletUTXOs()
+ if err := ws.CommitBatch(); err != nil {
+ t.Fatal(err)
+ }
+
+ // get utxo by outputID, it should return err
+ accountStore := NewAccountStore(testDB)
+ for _, utxo := range c.utxos {
+ _, err := accountStore.GetUTXO(utxo.OutputID)
+ if err == nil {
+ t.Errorf("case: %v: it should return some err.", i)
+ }
+ }
+
+ testDB.Close()
+ os.RemoveAll("temp")
+ }
+}