Skip to content

Commit e0292dd

Browse files
committed
itest: extend testSupplyCommitIgnoreAsset to check peer commit retrieval
Extend the testSupplyCommitIgnoreAsset integration test to verify that the verifying peer node correctly processes the supply commitment and that the commitment can be retrieved from this peer.
1 parent 056591e commit e0292dd

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

itest/supply_commit_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package itest
33
import (
44
"bytes"
55
"context"
6+
"strings"
67
"time"
78

89
"github.com/btcsuite/btcd/btcec/v2"
@@ -586,6 +587,60 @@ func testSupplyCommitIgnoreAsset(t *harnessTest) {
586587
t.t, rpcAsset.Amount,
587588
uniFetchResp.IgnoreSubtreeRoot.RootNode.RootSum,
588589
)
590+
591+
t.Log("Attempting to fetch supply commit from secondary node")
592+
593+
var peerFetchResp *unirpc.FetchSupplyCommitResponse
594+
require.Eventually(t.t, func() bool {
595+
// nolint: lll
596+
peerFetchResp, err = secondTapd.FetchSupplyCommit(
597+
ctxb, &unirpc.FetchSupplyCommitRequest{
598+
GroupKey: &unirpc.FetchSupplyCommitRequest_GroupKeyBytes{
599+
GroupKeyBytes: groupKeyBytes,
600+
},
601+
Locator: &unirpc.FetchSupplyCommitRequest_VeryFirst{
602+
VeryFirst: true,
603+
},
604+
},
605+
)
606+
if err != nil &&
607+
strings.Contains(err.Error(), "commitment not found") {
608+
609+
return false
610+
}
611+
require.NoError(t.t, err)
612+
613+
// If the fetch response has no block height or hash,
614+
// it means that the supply commitment transaction has not
615+
// been mined yet, so we should retry.
616+
if peerFetchResp.ChainData.BlockHeight == 0 ||
617+
len(peerFetchResp.ChainData.BlockHash) == 0 {
618+
619+
return false
620+
}
621+
622+
// Once the ignore tree includes the ignored asset outpoint, we
623+
// know that the supply commitment has been updated.
624+
if peerFetchResp.IgnoreSubtreeRoot == nil {
625+
return false
626+
}
627+
628+
return true
629+
}, defaultWaitTimeout, time.Second)
630+
631+
require.NotNil(t.t, peerFetchResp)
632+
require.Len(t.t, peerFetchResp.IssuanceLeaves, 1)
633+
require.Len(t.t, peerFetchResp.BurnLeaves, 0)
634+
require.Len(t.t, peerFetchResp.IgnoreLeaves, 2)
635+
636+
require.EqualValues(
637+
t.t, rpcAsset.Amount,
638+
peerFetchResp.IssuanceLeaves[0].LeafNode.RootSum,
639+
)
640+
require.EqualValues(
641+
t.t, rpcAsset.Amount,
642+
peerFetchResp.IgnoreSubtreeRoot.RootNode.RootSum,
643+
)
589644
}
590645

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

0 commit comments

Comments
 (0)