Skip to content

Commit c5c7fb6

Browse files
ZZiigguurraattZZiigguurraatt
ZZiigguurraatt
authored and
ZZiigguurraatt
committed
itest: cleaner distribution of on-chain assets
This fixes lightninglabs/taproot-assets#1432 by defining the on chain asset amounts sent to each node and the sizes of channels opened by each node relative to each other without hard coding the values. This then allows the channel sizes to be adjusted more easily as needed.
1 parent bad957b commit c5c7fb6

File tree

1 file changed

+77
-15
lines changed

1 file changed

+77
-15
lines changed

itest/litd_custom_channels_test.go

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var (
4646
AssetType: taprpc.AssetType_NORMAL,
4747
Name: "itest-asset-cents",
4848
AssetMeta: dummyMetaData,
49+
50+
// Note: Amount must be large enough to satisfy `daveFundingAmount`,
51+
// `erinFundingAmount`, and `charlieFundingAmount` defined below in each
52+
// test case.
4953
Amount: 1_000_000,
5054
}
5155

@@ -196,15 +200,23 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
196200
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
197201
t.Logf("Universes synced between all nodes, distributing assets...")
198202

203+
// Define the sizes of each channel that is opened.
204+
// Note: Dave needs to have the larger channel size.
199205
const (
200206
daveFundingAmount = uint64(400_000)
201207
erinFundingAmount = uint64(200_000)
202208
)
203-
charlieFundingAmount := cents.Amount - uint64(2*400_000)
209+
210+
// Give Dave and Erin both the same amount of on chain funds even though
211+
// Erin won't use it all.
212+
const assetSendAmount = daveFundingAmount
213+
214+
// Charlie uses the rest of the funds that are minted in his channel
215+
charlieFundingAmount := cents.Amount - 2*assetSendAmount
204216

205217
chanPointCD, _, _ := createTestAssetNetwork(
206218
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
207-
universeTap, cents, 400_000, charlieFundingAmount,
219+
universeTap, cents, assetSendAmount, charlieFundingAmount,
208220
daveFundingAmount, erinFundingAmount, DefaultPushSat,
209221
)
210222

@@ -385,15 +397,23 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
385397
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
386398
t.Logf("Universes synced between all nodes, distributing assets...")
387399

400+
// Define the sizes of each channel that is opened.
401+
// Note: Dave needs to have the larger channel size.
388402
const (
389403
daveFundingAmount = uint64(startAmount)
390404
erinFundingAmount = uint64(fundingAmount)
391405
)
392-
charlieFundingAmount := cents.Amount - 2*startAmount
406+
407+
// Give Dave and Erin both the same amount of on chain funds even though
408+
// Erin won't use it all.
409+
const assetSendAmount = daveFundingAmount
410+
411+
// Charlie uses the rest of the funds that are minted in his channel
412+
charlieFundingAmount := cents.Amount - 2*assetSendAmount
393413

394414
chanPointCD, chanPointDY, chanPointEF := createTestAssetNetwork(
395415
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
396-
universeTap, cents, startAmount, charlieFundingAmount,
416+
universeTap, cents, assetSendAmount, charlieFundingAmount,
397417
daveFundingAmount, erinFundingAmount, DefaultPushSat,
398418
)
399419

@@ -852,15 +872,23 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
852872
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
853873
t.Logf("Universes synced between all nodes, distributing assets...")
854874

875+
// Define the sizes of each channel that is opened.
876+
// Note: Dave needs to have the larger channel size.
855877
const (
856878
daveFundingAmount = uint64(startAmount)
857879
erinFundingAmount = uint64(fundingAmount)
858880
)
859-
charlieFundingAmount := cents.Amount - 2*startAmount
881+
882+
// Give Dave and Erin both the same amount of on chain funds even though
883+
// Erin won't use it all.
884+
const assetSendAmount = daveFundingAmount
885+
886+
// Charlie uses the rest of the funds that are minted in his channel
887+
charlieFundingAmount := cents.Amount - 2*assetSendAmount
860888

861889
chanPointCD, chanPointDY, chanPointEF := createTestAssetNetwork(
862890
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
863-
universeTap, cents, startAmount, charlieFundingAmount,
891+
universeTap, cents, assetSendAmount, charlieFundingAmount,
864892
daveFundingAmount, erinFundingAmount, DefaultPushSat,
865893
)
866894

@@ -1818,15 +1846,23 @@ func testCustomChannelsLiquidityEdgeCases(ctx context.Context,
18181846
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
18191847
t.Logf("Universes synced between all nodes, distributing assets...")
18201848

1849+
// Define the sizes of each channel that is opened.
1850+
// Note: Dave needs to have the larger channel size.
18211851
const (
18221852
daveFundingAmount = uint64(400_000)
18231853
erinFundingAmount = uint64(200_000)
18241854
)
1825-
charlieFundingAmount := cents.Amount - uint64(2*400_000)
1855+
1856+
// Give Dave and Erin both the same amount of on chain funds even though
1857+
// Erin won't use it all.
1858+
const assetSendAmount = daveFundingAmount
1859+
1860+
// Charlie uses the rest of the funds that are minted in his channel
1861+
charlieFundingAmount := cents.Amount - 2*assetSendAmount
18261862

18271863
_, _, _ = createTestAssetNetwork(
18281864
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
1829-
universeTap, cents, 400_000, charlieFundingAmount,
1865+
universeTap, cents, assetSendAmount, charlieFundingAmount,
18301866
daveFundingAmount, erinFundingAmount, 0,
18311867
)
18321868

@@ -2265,15 +2301,23 @@ func testCustomChannelsStrictForwarding(ctx context.Context,
22652301
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
22662302
t.Logf("Universes synced between all nodes, distributing assets...")
22672303

2304+
// Define the sizes of each channel that is opened.
2305+
// Note: Dave needs to have the larger channel size.
22682306
const (
22692307
daveFundingAmount = uint64(400_000)
22702308
erinFundingAmount = uint64(200_000)
22712309
)
2272-
charlieFundingAmount := cents.Amount - uint64(2*400_000)
2310+
2311+
// Give Dave and Erin both the same amount of on chain funds even though
2312+
// Erin won't use it all.
2313+
const assetSendAmount = daveFundingAmount
2314+
2315+
// Charlie uses the rest of the funds that are minted in his channel
2316+
charlieFundingAmount := cents.Amount - 2*assetSendAmount
22732317

22742318
_, _, _ = createTestAssetNetwork(
22752319
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
2276-
universeTap, cents, 400_000, charlieFundingAmount,
2320+
universeTap, cents, assetSendAmount, charlieFundingAmount,
22772321
daveFundingAmount, erinFundingAmount, 0,
22782322
)
22792323

@@ -2850,16 +2894,26 @@ func testCustomChannelsOraclePricing(ctx context.Context, net *NetworkHarness,
28502894
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
28512895
t.Logf("Universes synced between all nodes, distributing assets...")
28522896

2897+
2898+
2899+
2900+
// Define the sizes of each channel that is opened.
2901+
// Note: Dave needs to have the larger channel size.
28532902
const (
2854-
sendAmount = uint64(400_000_000)
28552903
daveFundingAmount = uint64(400_000_000)
28562904
erinFundingAmount = uint64(200_000_000)
28572905
)
2858-
charlieFundingAmount := usdAsset.Amount - 2*sendAmount
2906+
2907+
// Give Dave and Erin both the same amount of on chain funds even though
2908+
// Erin won't use it all.
2909+
const assetSendAmount = daveFundingAmount
2910+
2911+
// Charlie uses the rest of the funds that are minted in his channel
2912+
charlieFundingAmount := usdAsset.Amount - 2*assetSendAmount
28592913

28602914
chanPointCD, chanPointDY, chanPointEF := createTestAssetNetwork(
28612915
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
2862-
universeTap, usdAsset, sendAmount, charlieFundingAmount,
2916+
universeTap, usdAsset, assetSendAmount, charlieFundingAmount,
28632917
daveFundingAmount, erinFundingAmount, 0,
28642918
)
28652919

@@ -3739,15 +3793,23 @@ func testCustomChannelsForwardBandwidth(ctx context.Context,
37393793
syncUniverses(t.t, charlieTap, dave, erin, fabia, yara)
37403794
t.Logf("Universes synced between all nodes, distributing assets...")
37413795

3796+
// Define the sizes of each channel that is opened.
3797+
// Note: Dave needs to have the larger channel size.
37423798
const (
37433799
daveFundingAmount = uint64(400_000)
37443800
erinFundingAmount = uint64(200_000)
37453801
)
3746-
charlieFundingAmount := cents.Amount - uint64(2*400_000)
3802+
3803+
// Give Dave and Erin both the same amount of on chain funds even though
3804+
// Erin won't use it all.
3805+
const assetSendAmount = daveFundingAmount
3806+
3807+
// Charlie uses the rest of the funds that are minted in his channel
3808+
charlieFundingAmount := cents.Amount - 2*assetSendAmount
37473809

37483810
_, _, chanPointEF := createTestAssetNetwork(
37493811
t, net, charlieTap, daveTap, erinTap, fabiaTap, yaraTap,
3750-
universeTap, cents, 400_000, charlieFundingAmount,
3812+
universeTap, cents, assetSendAmount, charlieFundingAmount,
37513813
daveFundingAmount, erinFundingAmount, 0,
37523814
)
37533815

0 commit comments

Comments
 (0)