Skip to content

Commit d142812

Browse files
committed
itest: extend testSupplyCommitIgnoreAsset to fetch from universe server
Extend itest testSupplyCommitIgnoreAsset to fetch the supply commitment from the universe server. The issuer's supply commit state machine should push the commitment to the universe server, which must validate it before serving it. The universe server should only serve the snapshot after successful validation. This change verifies that the commitment can be fetched from the universe server as expected.
1 parent 7269bb3 commit d142812

File tree

1 file changed

+84
-10
lines changed

1 file changed

+84
-10
lines changed

itest/supply_commit_test.go

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,19 @@ func testSupplyCommitIgnoreAsset(t *harnessTest) {
206206
_, newIgnoreBlockHeight := t.lndHarness.Miner().GetBestBlock()
207207

208208
// Ignore the asset outpoint owned by the secondary node.
209+
ignoreAmt := sendAssetAmount
209210
ignoreReq := &unirpc.IgnoreAssetOutPointRequest{
210211
AssetOutPoint: &taprpc.AssetOutPoint{
211212
AnchorOutPoint: transferOutput.Anchor.Outpoint,
212213
AssetId: rpcAsset.AssetGenesis.AssetId,
213214
ScriptKey: transferOutput.ScriptKey,
214215
},
215-
Amount: sendAssetAmount,
216+
Amount: ignoreAmt,
216217
}
217218
respIgnore, err := t.tapd.IgnoreAssetOutPoint(ctxb, ignoreReq)
218219
require.NoError(t.t, err)
219220
require.NotNil(t.t, respIgnore)
220-
require.EqualValues(t.t, sendAssetAmount, respIgnore.Leaf.RootSum)
221+
require.EqualValues(t.t, ignoreAmt, respIgnore.Leaf.RootSum)
221222

222223
// We also ignore our change output, so we can later verify that the
223224
// proof verifier correctly denies spending the change output.
@@ -503,14 +504,87 @@ func testSupplyCommitIgnoreAsset(t *harnessTest) {
503504
withError("is ignored"),
504505
)
505506

506-
// TODO(ffranr): The above only tests that the node that issued the
507-
// ignore request has it in its ignore tree and can then deny spending
508-
// it. What we should also test is that the secondary node can sync the
509-
// ignore tree and then also deny spending the ignored asset outpoint
510-
// they received from the primary node.
511-
// Another test case we should add is that a node that _does not_ sync
512-
// the ignore tree can _send_ an ignored asset, but a synced node will
513-
// deny accepting it (transfer will never complete).
507+
t.Log("Fetch first supply commitment from universe server")
508+
// Ensure that the supply commitment was pushed to the universe server
509+
// and that it is retrievable.
510+
var uniFetchResp *unirpc.FetchSupplyCommitResponse
511+
require.Eventually(t.t, func() bool {
512+
// nolint: lll
513+
uniFetchResp, err = t.universeServer.service.FetchSupplyCommit(
514+
ctxb, &unirpc.FetchSupplyCommitRequest{
515+
GroupKey: &unirpc.FetchSupplyCommitRequest_GroupKeyBytes{
516+
GroupKeyBytes: groupKeyBytes,
517+
},
518+
Locator: &unirpc.FetchSupplyCommitRequest_VeryFirst{
519+
VeryFirst: true,
520+
},
521+
},
522+
)
523+
require.NoError(t.t, err)
524+
525+
// If the fetch response does not include a block height, the
526+
// supply commitment transaction has not been mined yet, so we
527+
// should retry.
528+
if uniFetchResp.ChainData.BlockHeight == 0 {
529+
return false
530+
}
531+
532+
return true
533+
}, defaultWaitTimeout, time.Second)
534+
535+
// Assert universe supply commitment fetch response.
536+
require.Len(t.t, uniFetchResp.IssuanceLeaves, 1)
537+
require.Len(t.t, uniFetchResp.BurnLeaves, 0)
538+
require.Len(t.t, uniFetchResp.IgnoreLeaves, 2)
539+
540+
// Assert issuance leaf properties.
541+
issuanceLeaf := uniFetchResp.IssuanceLeaves[0]
542+
require.EqualValues(
543+
t.t, rpcAsset.Amount, issuanceLeaf.LeafNode.RootSum,
544+
)
545+
546+
// Assert ignored leaf properties.
547+
//
548+
// Determine which ignore leaf was the first one we added, so we
549+
// can assert its properties.
550+
firstIgnoreLeaf := uniFetchResp.IgnoreLeaves[0]
551+
secondIgnoreLeaf := uniFetchResp.IgnoreLeaves[1]
552+
if firstIgnoreLeaf.LeafNode.RootSum != int64(ignoreAmt) {
553+
firstIgnoreLeaf, secondIgnoreLeaf = secondIgnoreLeaf,
554+
firstIgnoreLeaf
555+
}
556+
557+
require.EqualValues(t.t, ignoreAmt, firstIgnoreLeaf.LeafNode.RootSum)
558+
require.EqualValues(
559+
t.t, rpcAsset.Amount-sendAssetAmount,
560+
uint32(secondIgnoreLeaf.LeafNode.RootSum),
561+
)
562+
563+
// Assert supply subtree root properties.
564+
require.NotNil(t.t, uniFetchResp.IssuanceSubtreeRoot)
565+
require.NotNil(t.t, uniFetchResp.BurnSubtreeRoot)
566+
require.NotNil(t.t, uniFetchResp.IgnoreSubtreeRoot)
567+
568+
// Assert that the issuance subtree root sum matches the total
569+
// amount of issued assets.
570+
require.EqualValues(
571+
t.t, rpcAsset.Amount,
572+
uniFetchResp.IssuanceSubtreeRoot.RootNode.RootSum,
573+
)
574+
575+
// Assert that the burn subtree root sum is zero, as no assets have
576+
// been burned.
577+
require.EqualValues(
578+
t.t, 0,
579+
uniFetchResp.BurnSubtreeRoot.RootNode.RootSum,
580+
)
581+
582+
// Assert that the ignore subtree root sum equals the total issued
583+
// amount, since the entire issuance has been recorded as ignored.
584+
require.EqualValues(
585+
t.t, rpcAsset.Amount,
586+
uniFetchResp.IgnoreSubtreeRoot.RootNode.RootSum,
587+
)
514588
}
515589

516590
// AssertInclusionProof checks that the inclusion proof for a given leaf key

0 commit comments

Comments
 (0)