Skip to content

Commit e0d9ea1

Browse files
committed
itest: test order validation
1 parent 5419272 commit e0d9ea1

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

itest/rfq_test.go

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,35 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
8787
bidAmt := uint64(90000)
8888
buyOrderExpiry := uint64(time.Now().Add(24 * time.Hour).Unix())
8989

90-
_, err = ts.CarolTapd.AddAssetBuyOrder(
91-
ctxt, &rfqrpc.AddAssetBuyOrderRequest{
92-
AssetSpecifier: &rfqrpc.AssetSpecifier{
93-
Id: &rfqrpc.AssetSpecifier_AssetId{
94-
AssetId: mintedAssetId,
95-
},
90+
// We first try to add a buy order without specifying the asset skip
91+
// flag. That should result in an error, since we only have a normal
92+
// channel and not an asset channel.
93+
buyReq := &rfqrpc.AddAssetBuyOrderRequest{
94+
AssetSpecifier: &rfqrpc.AssetSpecifier{
95+
Id: &rfqrpc.AssetSpecifier_AssetId{
96+
AssetId: mintedAssetId,
9697
},
97-
AssetMaxAmt: purchaseAssetAmt,
98-
Expiry: buyOrderExpiry,
98+
},
99+
AssetMaxAmt: purchaseAssetAmt,
100+
Expiry: buyOrderExpiry,
99101

100-
// Here we explicitly specify Bob as the destination
101-
// peer for the buy order. This will prompt Carol's tapd
102-
// node to send a request for quote message to Bob's
103-
// node.
104-
PeerPubKey: ts.BobLnd.PubKey[:],
102+
// Here we explicitly specify Bob as the destination
103+
// peer for the buy order. This will prompt Carol's tapd
104+
// node to send a request for quote message to Bob's
105+
// node.
106+
PeerPubKey: ts.BobLnd.PubKey[:],
105107

106-
TimeoutSeconds: uint32(rfqTimeout.Seconds()),
107-
},
108+
TimeoutSeconds: uint32(rfqTimeout.Seconds()),
109+
}
110+
_, err = ts.AliceTapd.AddAssetBuyOrder(ctxt, buyReq)
111+
require.ErrorContains(
112+
t.t, err, "error checking peer channel: error checking asset "+
113+
"channel",
108114
)
115+
116+
// Now we set the skip flag and we shouldn't get an error anymore.
117+
buyReq.SkipAssetChannelCheck = true
118+
_, err = ts.CarolTapd.AddAssetBuyOrder(ctxt, buyReq)
109119
require.NoError(t.t, err, "unable to upsert asset buy order")
110120

111121
// Wait until Carol receives an incoming quote accept message (sent from
@@ -266,25 +276,35 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
266276
askAmt := uint64(42000)
267277
sellOrderExpiry := uint64(time.Now().Add(24 * time.Hour).Unix())
268278

269-
_, err = ts.AliceTapd.AddAssetSellOrder(
270-
ctxt, &rfqrpc.AddAssetSellOrderRequest{
271-
AssetSpecifier: &rfqrpc.AssetSpecifier{
272-
Id: &rfqrpc.AssetSpecifier_AssetId{
273-
AssetId: mintedAssetIdBytes,
274-
},
279+
// We first try to add a sell order without specifying the asset skip
280+
// flag. That should result in an error, since we only have a normal
281+
// channel and not an asset channel.
282+
sellReq := &rfqrpc.AddAssetSellOrderRequest{
283+
AssetSpecifier: &rfqrpc.AssetSpecifier{
284+
Id: &rfqrpc.AssetSpecifier_AssetId{
285+
AssetId: mintedAssetIdBytes,
275286
},
276-
PaymentMaxAmt: askAmt,
277-
Expiry: sellOrderExpiry,
287+
},
288+
PaymentMaxAmt: askAmt,
289+
Expiry: sellOrderExpiry,
278290

279-
// Here we explicitly specify Bob as the destination
280-
// peer for the sell order. This will prompt Alice's
281-
// tapd node to send a request for quote message to
282-
// Bob's node.
283-
PeerPubKey: ts.BobLnd.PubKey[:],
291+
// Here we explicitly specify Bob as the destination
292+
// peer for the sell order. This will prompt Alice's
293+
// tapd node to send a request for quote message to
294+
// Bob's node.
295+
PeerPubKey: ts.BobLnd.PubKey[:],
284296

285-
TimeoutSeconds: uint32(rfqTimeout.Seconds()),
286-
},
297+
TimeoutSeconds: uint32(rfqTimeout.Seconds()),
298+
}
299+
_, err = ts.AliceTapd.AddAssetSellOrder(ctxt, sellReq)
300+
require.ErrorContains(
301+
t.t, err, "error checking peer channel: error checking asset "+
302+
"channel",
287303
)
304+
305+
// Now we set the skip flag and we shouldn't get an error anymore.
306+
sellReq.SkipAssetChannelCheck = true
307+
_, err = ts.AliceTapd.AddAssetSellOrder(ctxt, sellReq)
288308
require.NoError(t.t, err, "unable to upsert asset sell order")
289309

290310
// Wait until Alice receives an incoming sell quote accept message (sent

0 commit comments

Comments
 (0)