X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=database%2Fwallet_store_test.go;h=96cd9b1e5494276d58641113d2abf6d1ccad9012;hb=d762991e4a41d3e4b9dbab0a48548d9ba8f6fbc6;hp=3c0f91e55f556688c1200b57331bdd1f3f9dd23b;hpb=e278744e6d00511a70af4e03161151fb88d1f542;p=bytom%2Fvapor.git diff --git a/database/wallet_store_test.go b/database/wallet_store_test.go index 3c0f91e5..96cd9b1e 100644 --- a/database/wallet_store_test.go +++ b/database/wallet_store_test.go @@ -2,6 +2,7 @@ package database import ( "bytes" + "encoding/hex" "encoding/json" "io/ioutil" "os" @@ -854,3 +855,1153 @@ func TestDeleteWalletTransactions(t *testing.T) { 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") + } +} + +func TestGetStandardUTXO(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") + accountStore := NewAccountStore(testDB) + as := accountStore.InitBatch() + // store utxos + for _, utxo := range c.utxos { + if err := as.SetStandardUTXO(utxo.OutputID, utxo); err != nil { + t.Fatal(err) + } + } + + if err := as.CommitBatch(); err != nil { + t.Fatal(err) + } + + // get utxo by outputID + walletStore := NewWalletStore(testDB) + for _, utxo := range c.utxos { + gotUTXO, err := walletStore.GetStandardUTXO(utxo.OutputID) + if err != nil { + t.Fatal(err) + } + + if !testutil.DeepEqual(gotUTXO, utxo) { + t.Errorf("case %v: got standard utxo, got: %v, want: %v.", i, gotUTXO, utxo) + } + } + + testDB.Close() + os.RemoveAll("temp") + } +} + +func TestListAccountUTXOs(t *testing.T) { + cases := []struct { + standardUTXOs []*acc.UTXO + contractUTXOs []*acc.UTXO + id string + isSmartContract bool + want []*acc.UTXO + }{ + { + standardUTXOs: []*acc.UTXO{}, + contractUTXOs: []*acc.UTXO{}, + id: "", + isSmartContract: false, + want: []*acc.UTXO{}, + }, + { + standardUTXOs: []*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{0x01, 0xff, 0xfe, 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), + }, + }, + contractUTXOs: []*acc.UTXO{}, + id: "01f3", + isSmartContract: false, + want: []*acc.UTXO{}, + }, + { + standardUTXOs: []*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{0x01, 0xff, 0xfe, 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), + }, + }, + contractUTXOs: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xfe, 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), + }, + }, + id: "01f3", + isSmartContract: true, + want: []*acc.UTXO{}, + }, + { + standardUTXOs: []*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, 0xfe, 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), + }, + }, + contractUTXOs: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xfe, 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), + }, + }, + id: "", + isSmartContract: false, + want: []*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, 0xfe, 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), + }, + }, + }, + { + standardUTXOs: []*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, 0xfe, 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), + }, + }, + contractUTXOs: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xfe, 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), + }, + }, + id: "02", + isSmartContract: false, + want: []*acc.UTXO{ + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x02, 0xff, 0xfe, 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), + }, + }, + }, + { + standardUTXOs: []*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{0x01, 0xff, 0xfe, 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), + }, + }, + contractUTXOs: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xfe, 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), + }, + }, + id: "", + isSmartContract: true, + want: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xfe, 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), + }, + }, + }, + { + standardUTXOs: []*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{0x01, 0xff, 0xfe, 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), + }, + }, + contractUTXOs: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + &acc.UTXO{ + OutputID: bc.NewHash([32]byte{0x04, 0xff, 0xfe, 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), + }, + }, + id: "03", + isSmartContract: true, + want: []*acc.UTXO{ + &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: "address0", + Amount: uint64(0), + Change: true, + AccountID: "account", + SourcePos: uint64(0), + }, + }, + }, + } + + for i, c := range cases { + testDB := dbm.NewDB("testdb", "leveldb", "temp") + accountStore := NewAccountStore(testDB) + as := accountStore.InitBatch() + // store standard utxos + for _, utxo := range c.standardUTXOs { + if err := as.SetStandardUTXO(utxo.OutputID, utxo); err != nil { + t.Fatal(err) + } + } + + if err := as.CommitBatch(); err != nil { + t.Fatal(err) + } + + // store contract utxos + walletStore := NewWalletStore(testDB) + ws := walletStore.InitBatch() + for _, utxo := range c.contractUTXOs { + if err := ws.SetContractUTXO(utxo.OutputID, utxo); err != nil { + t.Fatal(err) + } + } + + if err := ws.CommitBatch(); err != nil { + t.Fatal(err) + } + + gotUTXOs, err := ws.ListAccountUTXOs(c.id, c.isSmartContract) + if err != nil { + t.Fatal(err) + } + + if !testutil.DeepEqual(gotUTXOs, c.want) { + t.Errorf("case %v: list account utxos, got: %v, want: %v.", i, gotUTXOs, c.want) + } + + testDB.Close() + os.RemoveAll("temp") + } +} + +func TestListTransactions(t *testing.T) { + cases := []struct { + unconfirmedTxs []*query.AnnotatedTx + confirmedTxs []*query.AnnotatedTx + height uint64 + accountID string + startTxID string + count uint + unconfirmed bool + want []*query.AnnotatedTx + }{ + { + unconfirmedTxs: []*query.AnnotatedTx{}, + confirmedTxs: []*query.AnnotatedTx{}, + height: uint64(0), + accountID: "", + startTxID: "", + count: uint(0), + unconfirmed: false, + want: []*query.AnnotatedTx{}, + }, + { + unconfirmedTxs: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(1), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + confirmedTxs: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(102), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(103), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + height: uint64(100), + accountID: "", + startTxID: "", + count: uint(0), + unconfirmed: false, + want: []*query.AnnotatedTx{}, + }, + { + unconfirmedTxs: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(120), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + confirmedTxs: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(130), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(140), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + height: uint64(100), + accountID: "", + startTxID: "", + count: uint(2), + unconfirmed: false, + want: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(130), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(140), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + }, + { + unconfirmedTxs: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(120), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + confirmedTxs: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(130), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(140), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + height: uint64(100), + accountID: "", + startTxID: "", + count: uint(2), + unconfirmed: true, + want: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(120), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + }, + { + unconfirmedTxs: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(120), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account2", + }, + }, + }, + }, + confirmedTxs: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(130), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(140), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + height: uint64(100), + accountID: "account1", + startTxID: "", + count: uint(2), + unconfirmed: true, + want: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + }, + { + unconfirmedTxs: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(120), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + confirmedTxs: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(130), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(140), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + height: uint64(100), + accountID: "", + startTxID: hex.EncodeToString([]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}), + count: uint(2), + unconfirmed: true, + want: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + }, + { + unconfirmedTxs: []*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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(101), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(120), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + confirmedTxs: []*query.AnnotatedTx{ + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(130), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + &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(100), + BlockID: 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}), + BlockHeight: uint64(100), + Position: uint32(140), + Inputs: []*query.AnnotatedInput{ + &query.AnnotatedInput{ + AccountID: "account1", + }, + }, + }, + }, + height: uint64(100), + accountID: "", + startTxID: hex.EncodeToString([]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}), + count: uint(2), + unconfirmed: true, + want: []*query.AnnotatedTx{}, + }, + } + + for i, c := range cases { + testDB := dbm.NewDB("testdb", "leveldb", "temp") + walletStore := NewWalletStore(testDB) + ws := walletStore.InitBatch() + // store unconfirmed txs + for _, tx := range c.unconfirmedTxs { + if err := ws.SetUnconfirmedTransaction(tx.ID.String(), tx); err != nil { + t.Fatal(err) + } + } + + // store confirmed txs + for _, tx := range c.confirmedTxs { + if err := ws.SetTransaction(c.height, tx); err != nil { + t.Fatal(err) + } + } + + if err := ws.CommitBatch(); err != nil { + t.Fatal(err) + } + + // get txs by given accountID, startID, count, unconfirmed + gotTxs, err := ws.ListTransactions(c.accountID, c.startTxID, c.count, c.unconfirmed) + if err != nil { + t.Fatal(err) + } + + sort.Sort(SortAnnotatedTxs(gotTxs)) + sort.Sort(SortAnnotatedTxs(c.want)) + + if !testutil.DeepEqual(gotTxs, c.want) { + t.Errorf("case %v: list transactions, got: %v, want: %v.", i, gotTxs, c.want) + } + + testDB.Close() + os.RemoveAll("temp") + } +} + +type SortAnnotatedTxs []*query.AnnotatedTx + +func (s SortAnnotatedTxs) Len() int { return len(s) } +func (s SortAnnotatedTxs) Less(i, j int) bool { + return bytes.Compare(s[i].ID.Bytes(), s[j].ID.Bytes()) < 0 +} +func (s SortAnnotatedTxs) Swap(i, j int) { s[i], s[j] = s[j], s[i] }