Skip to content

Commit ebd4f4a

Browse files
committed
tapdb: Update assets store tests to include new filter options
1 parent 5383bfc commit ebd4f4a

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

tapdb/assets_store_test.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,12 @@ func filterMinAmt(amt uint64) filterOpt {
724724
}
725725
}
726726

727+
func filterMaxAmt(amt uint64) filterOpt {
728+
return func(f *AssetQueryFilters) {
729+
f.MaxAmt = amt
730+
}
731+
}
732+
727733
func filterCoinSelectType(typ tapsend.CoinSelectType) filterOpt {
728734
return func(f *AssetQueryFilters) {
729735
f.CoinSelectType = typ
@@ -742,6 +748,18 @@ func filterAnchorHeight(height int32) filterOpt {
742748
}
743749
}
744750

751+
func filterAnchorPoint(point *wire.OutPoint) filterOpt {
752+
return func(f *AssetQueryFilters) {
753+
f.AnchorPoint = point
754+
}
755+
}
756+
757+
func filterScriptKey(key *asset.ScriptKey) filterOpt {
758+
return func(f *AssetQueryFilters) {
759+
f.ScriptKey = key
760+
}
761+
}
762+
745763
// TestFetchAllAssets tests that the different AssetQueryFilters work as
746764
// expected.
747765
func TestFetchAllAssets(t *testing.T) {
@@ -780,6 +798,7 @@ func TestFetchAllAssets(t *testing.T) {
780798
assetGen: assetGen.assetGens[2],
781799
anchorPoint: assetGen.anchorPoints[0],
782800
amt: 34,
801+
scriptKey: scriptKeyWithScript,
783802
}, {
784803
assetGen: assetGen.assetGens[3],
785804
anchorPoint: assetGen.anchorPoints[1],
@@ -898,6 +917,38 @@ func TestFetchAllAssets(t *testing.T) {
898917
includeLeased: true,
899918
includeSpent: true,
900919
numAssets: 8,
920+
}, {
921+
name: "max amount",
922+
filter: makeFilter(
923+
filterMaxAmt(100),
924+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
925+
),
926+
numAssets: 6,
927+
}, {
928+
name: "max amount, include spent",
929+
filter: makeFilter(
930+
filterMaxAmt(100),
931+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
932+
),
933+
includeSpent: true,
934+
numAssets: 7,
935+
}, {
936+
name: "max amount, include leased",
937+
filter: makeFilter(
938+
filterMaxAmt(100),
939+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
940+
),
941+
includeLeased: true,
942+
numAssets: 8,
943+
}, {
944+
name: "max amount, include leased, include spent",
945+
filter: makeFilter(
946+
filterMaxAmt(100),
947+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
948+
),
949+
includeLeased: true,
950+
includeSpent: true,
951+
numAssets: 9,
901952
}, {
902953
name: "default min height, include spent",
903954
filter: makeFilter(
@@ -914,7 +965,7 @@ func TestFetchAllAssets(t *testing.T) {
914965
),
915966
numAssets: 0,
916967
}, {
917-
name: "default min height, include spent",
968+
name: "specific height, include spent",
918969
filter: makeFilter(
919970
filterAnchorHeight(502),
920971
filterCoinSelectType(tapsend.ScriptTreesAllowed),
@@ -928,6 +979,21 @@ func TestFetchAllAssets(t *testing.T) {
928979
filterCoinSelectType(tapsend.Bip86Only),
929980
),
930981
numAssets: 0,
982+
}, {
983+
name: "query by script key",
984+
filter: makeFilter(
985+
filterScriptKey(scriptKeyWithScript),
986+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
987+
),
988+
numAssets: 1,
989+
}, {
990+
name: "query by script key, include leased",
991+
filter: makeFilter(
992+
filterScriptKey(scriptKeyWithScript),
993+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
994+
),
995+
includeLeased: true,
996+
numAssets: 2,
931997
}, {
932998
name: "query by group key only",
933999
filter: makeFilter(
@@ -952,6 +1018,13 @@ func TestFetchAllAssets(t *testing.T) {
9521018
)), filterDistinctSpecifier(),
9531019
),
9541020
numAssets: 2,
1021+
}, {
1022+
name: "query by anchor point",
1023+
filter: makeFilter(
1024+
filterAnchorPoint(&assetGen.anchorPoints[0]),
1025+
filterCoinSelectType(tapsend.ScriptTreesAllowed),
1026+
),
1027+
numAssets: 3,
9551028
}}
9561029

9571030
for _, tc := range testCases {

0 commit comments

Comments
 (0)