Golang implemented sidechain for Bytom
Revision | edf86e95debe0e8e1acac499e58d84e61a69cedc (tree) |
---|---|
Time | 2019-07-19 12:03:29 |
Author | Chengcheng Zhang <943420582@qq.c...> |
Commiter | Chengcheng Zhang |
add TestListAccountUTXOs
@@ -1157,3 +1157,62 @@ func TestGetStandardUTXO(t *testing.T) { | ||
1157 | 1157 | os.RemoveAll("temp") |
1158 | 1158 | } |
1159 | 1159 | } |
1160 | + | |
1161 | +func TestListAccountUTXOs(t *testing.T) { | |
1162 | + cases := []struct { | |
1163 | + standardUTXOs []*acc.UTXO | |
1164 | + contractUTXOs []*acc.UTXO | |
1165 | + id string | |
1166 | + isSmartContract bool | |
1167 | + want []*acc.UTXO | |
1168 | + }{ | |
1169 | + { | |
1170 | + standardUTXOs: []*acc.UTXO{}, | |
1171 | + contractUTXOs: []*acc.UTXO{}, | |
1172 | + id: "", | |
1173 | + isSmartContract: false, | |
1174 | + want: []*acc.UTXO{}, | |
1175 | + }, | |
1176 | + } | |
1177 | + | |
1178 | + for i, c := range cases { | |
1179 | + testDB := dbm.NewDB("testdb", "leveldb", "temp") | |
1180 | + accountStore := NewAccountStore(testDB) | |
1181 | + as := accountStore.InitBatch() | |
1182 | + // store standard utxos | |
1183 | + for _, utxo := range c.standardUTXOs { | |
1184 | + if err := as.SetStandardUTXO(utxo.OutputID, utxo); err != nil { | |
1185 | + t.Fatal(err) | |
1186 | + } | |
1187 | + } | |
1188 | + | |
1189 | + if err := as.CommitBatch(); err != nil { | |
1190 | + t.Fatal(err) | |
1191 | + } | |
1192 | + | |
1193 | + // store contract utxos | |
1194 | + walletStore := NewWalletStore(testDB) | |
1195 | + ws := walletStore.InitBatch() | |
1196 | + for _, utxo := range c.contractUTXOs { | |
1197 | + if err := ws.SetContractUTXO(utxo.OutputID, utxo); err != nil { | |
1198 | + t.Fatal(err) | |
1199 | + } | |
1200 | + } | |
1201 | + | |
1202 | + if err := ws.CommitBatch(); err != nil { | |
1203 | + t.Fatal(err) | |
1204 | + } | |
1205 | + | |
1206 | + gotUTXOs, err := ws.ListAccountUTXOs(c.id, c.isSmartContract) | |
1207 | + if err != nil { | |
1208 | + t.Fatal(err) | |
1209 | + } | |
1210 | + | |
1211 | + if !testutil.DeepEqual(gotUTXOs, c.want) { | |
1212 | + t.Errorf("case %v: list account utxos, got: %v, want: %v.", i, gotUTXOs, c.want) | |
1213 | + } | |
1214 | + | |
1215 | + testDB.Close() | |
1216 | + os.RemoveAll("temp") | |
1217 | + } | |
1218 | +} |