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 10, 2023
1 parent 70a9559 commit 54f716f
Show file tree
Hide file tree
Showing 2 changed files with 138 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
134 changes: 134 additions & 0 deletions itest/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"encoding/hex"
"fmt"
"io"
prand "math/rand"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"

tap "github.com/lightninglabs/taproot-assets"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/fn"
Expand All @@ -18,6 +20,7 @@ import (
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightninglabs/taproot-assets/universe"

"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -527,3 +530,134 @@ 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) {
ctx := context.Background()

// 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,
ProofType: universe.ProofTypeIssuance,
}
uniIdRpc1 := unirpc.MarshalUniverseID(assetIDBytes1, nil)
uniIdRpc1.ProofType = unirpc.ProofType_PROOF_TYPE_ISSUANCE

// Generate universe ID #2.
assetIDBytes2 := make([]byte, 32)
_, _ = rand.Read(assetIDBytes2)

var assetID2 asset.ID
copy(assetID2[:], assetIDBytes2)

uniID2 := universe.Identifier{
AssetID: assetID2,
ProofType: universe.ProofTypeTransfer,
}
uniIdRpc2 := unirpc.MarshalUniverseID(assetIDBytes2, nil)
uniIdRpc2.ProofType = unirpc.ProofType_PROOF_TYPE_TRANSFER

// Set both the global and a universe specific federation sync configs.
globalConfigs := []*unirpc.GlobalFederationSyncConfig{
{
ProofType: universe.ProofTypeIssuance.String(),
AllowSyncInsert: true,
AllowSyncExport: false,
},
{
ProofType: universe.ProofTypeTransfer.String(),
AllowSyncInsert: false,
AllowSyncExport: true,
},
}

assetSyncConfigs := []*unirpc.AssetFederationSyncConfig{
{
Id: uniIdRpc1,
AllowSyncInsert: false,
AllowSyncExport: true,
},
{
Id: uniIdRpc2,
AllowSyncInsert: true,
AllowSyncExport: false,
},
}

_, err := t.tapd.UniverseClient.SetFederationSyncConfig(
ctx, &unirpc.SetFederationSyncConfigRequest{
GlobalSyncConfigs: globalConfigs,
AssetSyncConfigs: assetSyncConfigs,
},
)
require.NoError(t.t, err)

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

// Ensure that the global configs are set as expected.
require.Equal(t.t, len(resp.GlobalSyncConfigs), 2)

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

// Match proof type.
switch config.ProofType {
case universe.ProofTypeIssuance.String():
require.True(t.t, config.AllowSyncInsert)
require.False(t.t, config.AllowSyncExport)

case universe.ProofTypeTransfer.String():
require.False(t.t, config.AllowSyncInsert)
require.True(t.t, config.AllowSyncExport)

default:
t.Fatalf("unexpected global proof type: %s",
config.ProofType)
}
}

// 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.AssetID {
case uniID1.AssetID:
require.Equal(
t.t, uniID.ProofType,
universe.ProofTypeIssuance,
)
require.False(t.t, config.AllowSyncInsert)
require.True(t.t, config.AllowSyncExport)

case uniID2.AssetID:
require.Equal(
t.t, uniID.ProofType,
universe.ProofTypeTransfer,
)
require.True(t.t, config.AllowSyncInsert)
require.False(t.t, config.AllowSyncExport)
default:
t.Fatalf("unexpected universe ID: %v", config.Id)
}
}
}

0 comments on commit 54f716f

Please sign in to comment.