Skip to content

Commit 7cf6fde

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 26775dd commit 7cf6fde

File tree

1 file changed

+85
-10
lines changed

1 file changed

+85
-10
lines changed

itest/supply_commit_test.go

Lines changed: 85 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,88 @@ 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+
509+
// Ensure that the supply commitment was pushed to the universe server
510+
// and that it is retrievable.
511+
var uniFetchResp *unirpc.FetchSupplyCommitResponse
512+
require.Eventually(t.t, func() bool {
513+
// nolint: lll
514+
uniFetchResp, err = t.universeServer.service.FetchSupplyCommit(
515+
ctxb, &unirpc.FetchSupplyCommitRequest{
516+
GroupKey: &unirpc.FetchSupplyCommitRequest_GroupKeyBytes{
517+
GroupKeyBytes: groupKeyBytes,
518+
},
519+
Locator: &unirpc.FetchSupplyCommitRequest_VeryFirst{
520+
VeryFirst: true,
521+
},
522+
},
523+
)
524+
require.NoError(t.t, err)
525+
526+
// If the fetch response does not include a block height, the
527+
// supply commitment transaction has not been mined yet, so we
528+
// should retry.
529+
if uniFetchResp.ChainData.BlockHeight == 0 {
530+
return false
531+
}
532+
533+
return true
534+
}, defaultWaitTimeout, time.Second)
535+
536+
// Assert universe supply commitment fetch response.
537+
require.Len(t.t, uniFetchResp.IssuanceLeaves, 1)
538+
require.Len(t.t, uniFetchResp.BurnLeaves, 0)
539+
require.Len(t.t, uniFetchResp.IgnoreLeaves, 2)
540+
541+
// Assert issuance leaf properties.
542+
issuanceLeaf := uniFetchResp.IssuanceLeaves[0]
543+
require.EqualValues(
544+
t.t, rpcAsset.Amount, issuanceLeaf.LeafNode.RootSum,
545+
)
546+
547+
// Assert ignored leaf properties.
548+
//
549+
// Determine which ignore leaf was the first one we added, so we
550+
// can assert its properties.
551+
firstIgnoreLeaf := uniFetchResp.IgnoreLeaves[0]
552+
secondIgnoreLeaf := uniFetchResp.IgnoreLeaves[1]
553+
if firstIgnoreLeaf.LeafNode.RootSum != int64(ignoreAmt) {
554+
firstIgnoreLeaf, secondIgnoreLeaf = secondIgnoreLeaf,
555+
firstIgnoreLeaf
556+
}
557+
558+
require.EqualValues(t.t, ignoreAmt, firstIgnoreLeaf.LeafNode.RootSum)
559+
require.EqualValues(
560+
t.t, rpcAsset.Amount-sendAssetAmount,
561+
uint32(secondIgnoreLeaf.LeafNode.RootSum),
562+
)
563+
564+
// Assert supply subtree root properties.
565+
require.NotNil(t.t, uniFetchResp.IssuanceSubtreeRoot)
566+
require.NotNil(t.t, uniFetchResp.BurnSubtreeRoot)
567+
require.NotNil(t.t, uniFetchResp.IgnoreSubtreeRoot)
568+
569+
// Assert that the issuance subtree root sum matches the total
570+
// amount of issued assets.
571+
require.EqualValues(
572+
t.t, rpcAsset.Amount,
573+
uniFetchResp.IssuanceSubtreeRoot.RootNode.RootSum,
574+
)
575+
576+
// Assert that the burn subtree root sum is zero, as no assets have
577+
// been burned.
578+
require.EqualValues(
579+
t.t, 0,
580+
uniFetchResp.BurnSubtreeRoot.RootNode.RootSum,
581+
)
582+
583+
// Assert that the ignore subtree root sum equals the total issued
584+
// amount, since the entire issuance has been recorded as ignored.
585+
require.EqualValues(
586+
t.t, rpcAsset.Amount,
587+
uniFetchResp.IgnoreSubtreeRoot.RootNode.RootSum,
588+
)
514589
}
515590

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

0 commit comments

Comments
 (0)