Skip to content

Commit

Permalink
itest: refactor more psbt tests to use grouped assets
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed May 9, 2023
1 parent bc9f53b commit 53f24c2
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 21 deletions.
150 changes: 133 additions & 17 deletions itest/psbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ func testPsbtScriptCheckSigSend(t *harnessTest) {
t.Logf("Got alice assets: %s", assetsJSON)
}

// testPsbtInteractiveFullValueSend tests that we can properly send assets back
// and forth, using the full amount, between nodes with the use of PSBTs.
func testPsbtInteractiveFullValueSend(t *harnessTest) {
// testPsbtNormalInteractiveFullValueSend tests that we can properly send normal
// assets back and forth, using the full amount, between nodes with the use of
// PSBTs.
func testPsbtNormalInteractiveFullValueSend(t *harnessTest) {
// First, we'll make a normal asset with a bunch of units that we are
// going to send backand forth. We're also minting a passive asset that
// should remain where it is.
Expand All @@ -291,7 +292,8 @@ func testPsbtInteractiveFullValueSend(t *harnessTest) {
},
)

genInfo := rpcAssets[0].AssetGenesis
mintedAsset := rpcAssets[0]
genInfo := mintedAsset.AssetGenesis

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
Expand All @@ -311,15 +313,66 @@ func testPsbtInteractiveFullValueSend(t *harnessTest) {
}()

runPsbtInteractiveFullValueSendTest(
ctxt, t, t.tarod, secondTarod, genInfo, rpcAssets[0],
rpcAssets[1], 1, 0,
ctxt, t, t.tarod, secondTarod, genInfo, mintedAsset,
rpcAssets[1],
)
}

// testPsbtGroupedInteractiveFullValueSend tests that we can properly send
// grouped assets back and forth, using the full amount, between nodes with the
// use of PSBTs.
func testPsbtGroupedInteractiveFullValueSend(t *harnessTest) {
// First, we'll make a normal asset with a bunch of units that we are
// going to send backand forth. We're also minting a passive asset that
// should remain where it is.
rpcAssets := mintAssetsConfirmBatch(
t, t.tarod, []*mintrpc.MintAssetRequest{
issuableAssets[0],
// Our "passive" asset.
{
Asset: &mintrpc.MintAsset{
AssetType: tarorpc.AssetType_NORMAL,
Name: "itestbuxx-passive",
AssetMeta: &tarorpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 123,
},
},
},
)

mintedAsset := rpcAssets[0]
genInfo := mintedAsset.AssetGenesis

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

// Now that we have the asset created, we'll make a new node that'll
// serve as the node which'll receive the assets.
secondTarod := setupTarodHarness(
t.t, t, t.lndHarness.Bob, t.universeServer,
func(params *tarodHarnessParams) {
params.startupSyncNode = t.tarod
params.startupSyncNumAssets = len(rpcAssets)
},
)
defer func() {
require.NoError(t.t, secondTarod.stop(true))
}()

runPsbtInteractiveFullValueSendTest(
ctxt, t, t.tarod, secondTarod, genInfo, mintedAsset,
rpcAssets[1],
)
}

// runPsbtInteractiveFullValueSendTest runs a single test of sending an asset
// back and forth between two nodes using PSBTs and the full amount.
func runPsbtInteractiveFullValueSendTest(ctxt context.Context, t *harnessTest,
alice, bob *tarodHarness, genInfo *tarorpc.GenesisInfo,
mintedAsset, passiveAsset *tarorpc.Asset, numRuns, runIdx int) {
mintedAsset, passiveAsset *tarorpc.Asset) {

var (
sender = alice
Expand Down Expand Up @@ -418,9 +471,60 @@ func runPsbtInteractiveFullValueSendTest(ctxt context.Context, t *harnessTest,
)
}

// testPsbtInteractiveSplitSend tests that we can properly send assets back
// and forth, using the full amount, between nodes with the use of PSBTs.
func testPsbtInteractiveSplitSend(t *harnessTest) {
// testPsbtNormalInteractiveSplitSend tests that we can properly send normal
// assets back and forth, using the full amount, between nodes with the use of
// PSBTs.
func testPsbtNormalInteractiveSplitSend(t *harnessTest) {
// First, we'll make a normal asset with a bunch of units that we are
// going to send backand forth. We're also minting a passive asset that
// should remain where it is.
rpcAssets := mintAssetsConfirmBatch(
t, t.tarod, []*mintrpc.MintAssetRequest{
simpleAssets[0],
// Our "passive" asset.
{
Asset: &mintrpc.MintAsset{
AssetType: tarorpc.AssetType_NORMAL,
Name: "itestbuxx-passive",
AssetMeta: &tarorpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 123,
},
},
},
)

mintedAsset := rpcAssets[0]
genInfo := rpcAssets[0].AssetGenesis

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

// Now that we have the asset created, we'll make a new node that'll
// serve as the node which'll receive the assets.
secondTarod := setupTarodHarness(
t.t, t, t.lndHarness.Bob, t.universeServer,
func(params *tarodHarnessParams) {
params.startupSyncNode = t.tarod
params.startupSyncNumAssets = len(rpcAssets)
},
)
defer func() {
require.NoError(t.t, secondTarod.stop(true))
}()

runPsbtInteractiveSplitSendTest(
ctxt, t, t.tarod, secondTarod, genInfo, mintedAsset,
rpcAssets[1],
)
}

// testPsbtGroupedInteractiveSplitSend tests that we can properly send grouped
// assets back and forth, using the full amount, between nodes with the use of
// PSBTs.
func testPsbtGroupedInteractiveSplitSend(t *harnessTest) {
// First, we'll make a normal asset with a bunch of units that we are
// going to send backand forth. We're also minting a passive asset that
// should remain where it is.
Expand All @@ -441,8 +545,8 @@ func testPsbtInteractiveSplitSend(t *harnessTest) {
},
)

mintedAsset := rpcAssets[0]
genInfo := rpcAssets[0].AssetGenesis
chainParams := &address.RegressionNetTaro

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
Expand All @@ -461,12 +565,25 @@ func testPsbtInteractiveSplitSend(t *harnessTest) {
require.NoError(t.t, secondTarod.stop(true))
}()

runPsbtInteractiveSplitSendTest(
ctxt, t, t.tarod, secondTarod, genInfo, mintedAsset,
rpcAssets[1],
)
}

// runPsbtInteractiveSplitSendTest runs a single test of sending an asset
// back and forth between two nodes using PSBTs and a split amount.
func runPsbtInteractiveSplitSendTest(ctxt context.Context, t *harnessTest,
alice, bob *tarodHarness, genInfo *tarorpc.GenesisInfo,
mintedAsset, passiveAsset *tarorpc.Asset) {

var (
sender = t.tarod
receiver = secondTarod
senderSum = rpcAssets[0].Amount
sender = alice
receiver = bob
senderSum = mintedAsset.Amount
receiverSum = uint64(0)
id [32]byte
chainParams = &address.RegressionNetTaro
)
copy(id[:], genInfo.AssetId)

Expand Down Expand Up @@ -565,10 +682,9 @@ func testPsbtInteractiveSplitSend(t *harnessTest) {
}

// Finally, make sure we can still send out the passive asset.
passiveAsset := rpcAssets[1]
passiveGen := rpcAssets[1].AssetGenesis
passiveGen := passiveAsset.AssetGenesis
sendAssetAndAssert(
ctxt, t, t.tarod, secondTarod, passiveAsset.Amount, 0,
ctxt, t, alice, bob, passiveAsset.Amount, 0,
passiveGen, passiveAsset, 2, 3, 1,
)
}
Expand Down
16 changes: 12 additions & 4 deletions itest/test_list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ var testCases = []*testCase{
test: testPsbtScriptCheckSigSend,
},
{
name: "psbt interactive full value send",
test: testPsbtInteractiveFullValueSend,
name: "psbt normal interactive full value send",
test: testPsbtNormalInteractiveFullValueSend,
},
{
name: "psbt interactive split send",
test: testPsbtInteractiveSplitSend,
name: "psbt grouped interactive full value send",
test: testPsbtGroupedInteractiveFullValueSend,
},
{
name: "psbt normal interactive split send",
test: testPsbtNormalInteractiveSplitSend,
},
{
name: "psbt grouped interactive split send",
test: testPsbtGroupedInteractiveSplitSend,
},
{
name: "psbt interactive tapscript sibling",
Expand Down

0 comments on commit 53f24c2

Please sign in to comment.