Skip to content

Commit

Permalink
itest: add test to check set/query for federation sync config
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Oct 3, 2023
1 parent 7125e3a commit f38d319
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itest/test_list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ var testCases = []*testCase{
name: "burn test",
test: testBurnAssets,
},
{
name: "federation sync config",
test: testFederationSyncConfig,
},
}

var optionalTestCases = []*testCase{
Expand Down
91 changes: 91 additions & 0 deletions itest/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/universe"
"io"
prand "math/rand"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
Expand Down Expand Up @@ -506,3 +509,91 @@ func testUniverseFederation(t *harnessTest) {
require.NoError(t.t, err)
require.Equal(t.t, 0, len(fedNodes.Servers))
}

// testFederationSyncConfig tests that we can properly set and query the
// federation sync config.
func testFederationSyncConfig(t *harnessTest) {
var (
ctx = context.Background()

excludeAllProofs = universe.ProofTypeNone
issuanceOnly = universe.ProofTypeIssuance
transferOnly = universe.ProofTypeTransfer
)

// Generate a random asset ID in order to generate a universe ID.
rand := prand.New(prand.NewSource(1))

// Generate universe ID #1.
assetIDBytes1 := make([]byte, 32)
_, _ = rand.Read(assetIDBytes1)
var assetID1 asset.ID
copy(assetID1[:], assetIDBytes1)
uniID1 := universe.Identifier{
AssetID: assetID1,
}
uniIdRpc1 := unirpc.MarshalUniverseID(assetIDBytes1, nil)

// Generate universe ID #2.
assetIDBytes2 := make([]byte, 32)
_, _ = rand.Read(assetIDBytes2)
var assetID2 asset.ID
copy(assetID2[:], assetIDBytes2)
uniID2 := universe.Identifier{
AssetID: assetID2,
}
uniIdRpc2 := unirpc.MarshalUniverseID(assetIDBytes2, nil)

// Set both the general and a universe specific federation sync configs.
_, err := t.tapd.UniverseClient.SetFederationSyncConfig(
ctx, &unirpc.SetFederationSyncConfigRequest{
GeneralSyncConfig: &unirpc.GeneralFederationSyncConfig{
ProofTypes: issuanceOnly.String(),
},
AssetSyncConfig: []*unirpc.AssetFederationSyncConfig{
{
Id: uniIdRpc1,
ProofTypes: excludeAllProofs.String(),
},
{
Id: uniIdRpc2,
ProofTypes: transferOnly.String(),
},
},
},
)
require.NoError(t.t, err)

resp, err := t.tapd.UniverseClient.QueryFederationSyncConfig(
ctx, &unirpc.QueryFederationSyncConfigRequest{},
)
require.NoError(t.t, err)

// In general, we expect to only sync issuance proofs.
require.Equal(
t.t, resp.GeneralSyncConfig.ProofTypes, issuanceOnly.String(),
)

// Ensure that the universe specific config is set as expected.
require.Equal(t.t, len(resp.AssetSyncConfigs), 2)

for i := range resp.AssetSyncConfigs {
config := resp.AssetSyncConfigs[i]

// Unmarshal the universe ID.
uniID, err := tap.UnmarshalUniID(config.Id)
require.NoError(t.t, err)

// Match universe ID and assert proof type.
switch uniID {
case uniID1:
proofType := excludeAllProofs.String()
require.Equal(t.t, config.ProofTypes, proofType)
case uniID2:
proofType := transferOnly.String()
require.Equal(t.t, config.ProofTypes, proofType)
default:
t.Fatalf("unexpected universe ID: %v", config.Id)
}
}
}

0 comments on commit f38d319

Please sign in to comment.