Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split enableEmission into newGroupedAsset and groupedAsset #681

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions cmd/tapcli/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var (
assetMetaBytesName = "meta_bytes"
assetMetaFilePathName = "meta_file_path"
assetMetaTypeName = "meta_type"
assetEmissionName = "enable_emission"
assetNewGroupedAssetName = "new_grouped_asset"
assetGroupedAssetName = "grouped_asset"
assetShowWitnessName = "show_witness"
assetShowSpentName = "show_spent"
assetGroupKeyName = "group_key"
Expand Down Expand Up @@ -91,10 +92,15 @@ var mintAssetCommand = cli.Command{
Usage: "the type of the meta data for the asset",
},
cli.BoolFlag{
Name: assetEmissionName,
Name: assetNewGroupedAssetName,
Usage: "if true, then the asset supports on going " +
"emission",
},
cli.BoolFlag{
Name: assetGroupedAssetName,
Usage: "if true, then the asset is minted into a " +
"specific group",
},
cli.StringFlag{
Name: assetGroupKeyName,
Usage: "the specific group key to use to mint the " +
Expand Down Expand Up @@ -218,18 +224,19 @@ func mintAsset(ctx *cli.Context) error {

resp, err := client.MintAsset(ctxc, &mintrpc.MintAssetRequest{
Asset: &mintrpc.MintAsset{
AssetType: assetType,
Name: ctx.String(assetTagName),
AssetMeta: assetMeta,
Amount: amount,
GroupKey: groupKey,
GroupAnchor: ctx.String(assetGroupAnchorName),
AssetType: assetType,
Name: ctx.String(assetTagName),
AssetMeta: assetMeta,
Amount: amount,
NewGroupedAsset: ctx.Bool(assetNewGroupedAssetName),
GroupedAsset: ctx.Bool(assetGroupedAssetName),
GroupKey: groupKey,
GroupAnchor: ctx.String(assetGroupAnchorName),
AssetVersion: taprpc.AssetVersion(
ctx.Uint64(assetVersionName),
),
},
EnableEmission: ctx.Bool(assetEmissionName),
ShortResponse: ctx.Bool(shortResponseName),
ShortResponse: ctx.Bool(shortResponseName),
})
if err != nil {
return fmt.Errorf("unable to mint asset: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion itest/addrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ func testAddressAssetSyncer(t *harnessTest) {
// If Alice now mints a reissuance for the second asset group, Bob
// should successfully sync that new asset.
secondGroupMember := CopyRequest(issuableAssets[1])
secondGroupMember.EnableEmission = false
secondGroupMember.Asset.NewGroupedAsset = false
secondGroupMember.Asset.Name += "-2"
secondGroupMember.Asset.GroupKey = secondGroup.TweakedGroupKey
secondGroupMember.Asset.GroupedAsset = true

reissuedAsset := MintAssetsConfirmBatch(
t.t, miner, t.tapd, fn.MakeSlice(secondGroupMember),
Expand Down
28 changes: 20 additions & 8 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ var (
AssetMeta: &taprpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 5000,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V1,
Amount: 5000,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V1,
NewGroupedAsset: true,
},
EnableEmission: true,
},
{
Asset: &mintrpc.MintAsset{
Expand All @@ -62,10 +62,10 @@ var (
AssetMeta: &taprpc.AssetMeta{
Data: []byte("some metadata"),
},
Amount: 1,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V0,
Amount: 1,
AssetVersion: taprpc.AssetVersion_ASSET_VERSION_V0,
NewGroupedAsset: true,
},
EnableEmission: true,
},
}

Expand Down Expand Up @@ -242,14 +242,24 @@ func testMintAssetNameCollisionError(t *harnessTest) {
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

equalityCheck := func(a, b *mintrpc.MintAsset) {
equalityCheck := func(a *mintrpc.MintAsset, b *mintrpc.PendingAsset) {
require.Equal(t.t, a.AssetType, b.AssetType)
require.Equal(t.t, a.Name, b.Name)
require.Equal(t.t, a.AssetMeta.Data, b.AssetMeta.Data)
require.Equal(t.t, a.Amount, b.Amount)
require.Equal(t.t, a.GroupKey, b.GroupKey)
require.Equal(t.t, a.GroupAnchor, b.GroupAnchor)
}

equalityCheckSeedlings := func(a, b *mintrpc.PendingAsset) {
require.Equal(t.t, a.AssetType, b.AssetType)
require.Equal(t.t, a.Name, b.Name)
require.Equal(t.t, a.AssetMeta.Data, b.AssetMeta.Data)
require.Equal(t.t, a.Amount, b.Amount)
require.Equal(t.t, a.NewGroupedAsset, b.NewGroupedAsset)
require.Equal(t.t, a.GroupKey, b.GroupKey)
require.Equal(t.t, a.GroupAnchor, b.GroupAnchor)
}
// If we attempt to add both assets to the same batch, the second mint
// call should fail.
collideResp, err := t.tapd.MintAsset(ctxt, &assetCollide)
Expand Down Expand Up @@ -305,7 +315,9 @@ func testMintAssetNameCollisionError(t *harnessTest) {
require.Len(t.t, cancelBatch.Batches, 1)
cancelBatchCollide := cancelBatch.Batches[0]
require.Len(t.t, cancelBatchCollide.Assets, 1)
equalityCheck(batchCollide.Assets[0], cancelBatchCollide.Assets[0])
equalityCheckSeedlings(
batchCollide.Assets[0], cancelBatchCollide.Assets[0],
)
cancelBatchState := cancelBatchCollide.State
require.Equal(
t.t, cancelBatchState,
Expand Down
8 changes: 5 additions & 3 deletions itest/collectible_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func testCollectibleGroupSend(t *harnessTest) {
Data: []byte("foo"),
Type: 0,
},
Amount: 1,
Amount: 1,
NewGroupedAsset: false,
},
EnableEmission: false,
}

// Update the asset name and metadata to match an index.
Expand All @@ -245,7 +245,7 @@ func testCollectibleGroupSend(t *harnessTest) {
// Use the first asset of the batch as the asset group anchor.
collectibleAnchorReq := CopyRequest(&collectibleRequestTemplate)
incrementMintAsset(collectibleAnchorReq.Asset, 0)
collectibleAnchorReq.EnableEmission = true
collectibleAnchorReq.Asset.NewGroupedAsset = true
batchReqs[0] = collectibleAnchorReq

// Generate the rest of the batch, with each asset referencing the group
Expand All @@ -254,6 +254,8 @@ func testCollectibleGroupSend(t *harnessTest) {
groupedAsset := CopyRequest(&collectibleRequestTemplate)
incrementMintAsset(groupedAsset.Asset, i)
groupedAsset.Asset.GroupAnchor = collectibleAnchorReq.Asset.Name
groupedAsset.Asset.NewGroupedAsset = false
groupedAsset.Asset.GroupedAsset = true
batchReqs[i] = groupedAsset
}

Expand Down
8 changes: 5 additions & 3 deletions itest/loadtest/mint_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func mintTest(t *testing.T, ctx context.Context, cfg *Config) {
Data: imageMetadataBytes,
Type: 0,
},
Amount: 1,
Amount: 1,
NewGroupedAsset: false,
},
EnableEmission: false,
}

// Update the asset name and metadata to match an index.
Expand All @@ -75,7 +75,7 @@ func mintTest(t *testing.T, ctx context.Context, cfg *Config) {
// Use the first asset of the batch as the asset group anchor.
collectibleAnchorReq := itest.CopyRequest(&collectibleRequestTemplate)
incrementMintAsset(collectibleAnchorReq.Asset, 0)
collectibleAnchorReq.EnableEmission = true
collectibleAnchorReq.Asset.NewGroupedAsset = true
batchReqs[0] = collectibleAnchorReq

// Generate the rest of the batch, with each asset referencing the group
Expand All @@ -84,6 +84,8 @@ func mintTest(t *testing.T, ctx context.Context, cfg *Config) {
groupedAsset := itest.CopyRequest(&collectibleRequestTemplate)
incrementMintAsset(groupedAsset.Asset, i)
groupedAsset.Asset.GroupAnchor = collectibleAnchorReq.Asset.Name
groupedAsset.Asset.GroupedAsset = true
groupedAsset.Asset.NewGroupedAsset = false
batchReqs[i] = groupedAsset
}

Expand Down
7 changes: 4 additions & 3 deletions itest/mint_batch_stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ func mintBatchStressTest(
Data: imageMetadataBytes,
Type: 0,
},
Amount: 1,
Amount: 1,
NewGroupedAsset: false,
},
EnableEmission: false,
}

// Update the asset name and metadata to match an index.
Expand All @@ -129,7 +129,8 @@ func mintBatchStressTest(
// Use the first asset of the batch as the asset group anchor.
collectibleAnchorReq := CopyRequest(&collectibleRequestTemplate)
incrementMintAsset(collectibleAnchorReq.Asset, 0)
collectibleAnchorReq.EnableEmission = true
collectibleAnchorReq.Asset.NewGroupedAsset = false
collectibleAnchorReq.Asset.GroupedAsset = true
batchReqs[0] = collectibleAnchorReq

// Generate the rest of the batch, with each asset referencing the group
Expand Down
11 changes: 7 additions & 4 deletions itest/multi_asset_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func testMintMultiAssetGroups(t *harnessTest) {
// and one new group of 3 assets.
complexBatch := []*mintrpc.MintAssetRequest{simpleAssets[0]}
issuableAsset := CopyRequest(simpleAssets[1])
issuableAsset.EnableEmission = true
issuableAsset.Asset.NewGroupedAsset = true
complexBatch = append(complexBatch, issuableAsset)

normalGroupMembers := 2
Expand Down Expand Up @@ -195,7 +195,8 @@ func createMultiAssetGroup(anchor *mintrpc.MintAssetRequest,
groupSum := uint64(0)
for i := uint64(1); i <= numAssets; i++ {
assetReq := CopyRequest(anchor)
assetReq.EnableEmission = false
assetReq.Asset.NewGroupedAsset = false
assetReq.Asset.GroupedAsset = true
assetReq.Asset.GroupAnchor = anchorName
assetReq.Asset.Name = fmt.Sprintf(
"%s-tranche-%d", anchorName, i,
Expand Down Expand Up @@ -227,6 +228,7 @@ func testMintMultiAssetGroupErrors(t *harnessTest) {
// group anchor is invalid if there is no pending batch.
groupedAsset := CopyRequest(simpleAssets[0])
groupedAsset.Asset.GroupAnchor = groupedAsset.Asset.Name
groupedAsset.Asset.GroupedAsset = true

_, err := t.tapd.MintAsset(ctxb, groupedAsset)
require.ErrorContains(t.t, err, "batch empty, group anchor")
Expand All @@ -236,6 +238,7 @@ func testMintMultiAssetGroupErrors(t *harnessTest) {
simpleAsset := CopyRequest(simpleAssets[1])
_, err = t.tapd.MintAsset(ctxb, simpleAsset)
require.NoError(t.t, err)

_, err = t.tapd.MintAsset(ctxb, groupedAsset)
require.ErrorContains(t.t, err, "not present in batch")

Expand All @@ -252,7 +255,7 @@ func testMintMultiAssetGroupErrors(t *harnessTest) {
require.ErrorContains(t.t, err, "has emission disabled")

// Finally, we'll modify the assets to make the multi-asset group valid.
validAnchor.EnableEmission = true
validAnchor.Asset.NewGroupedAsset = true
validAnchor.Asset.AssetMeta = &taprpc.AssetMeta{
Data: []byte("metadata for itest group anchors"),
}
Expand Down Expand Up @@ -284,7 +287,7 @@ func testMultiAssetGroupSend(t *harnessTest) {

// First, we'll build a batch to mint.
issuableAsset := CopyRequest(simpleAssets[1])
issuableAsset.EnableEmission = true
issuableAsset.Asset.NewGroupedAsset = true

collectibleGroupMembers := 50
collectibleGroup, collectibleGroupSum := createMultiAssetGroup(
Expand Down
47 changes: 39 additions & 8 deletions itest/re-issuance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func testReIssuance(t *harnessTest) {

reissuedAssets[0].Asset.Amount = normalGroupMintHalf
reissuedAssets[0].Asset.GroupKey = normalGroupKey
reissuedAssets[0].Asset.GroupedAsset = true
reissuedAssets[1].Asset.GroupKey = collectGroupKey
reissuedAssets[1].Asset.GroupedAsset = true

normalReissueGen := MintAssetsConfirmBatch(
t.t, miner, t.tapd,
Expand Down Expand Up @@ -241,7 +243,7 @@ func testReIssuanceAmountOverflow(t *harnessTest) {
assetIssueReqs := CopyRequests(issuableAssets)
assetIssueReq := assetIssueReqs[0]

assetIssueReq.EnableEmission = true
assetIssueReq.Asset.NewGroupedAsset = true
assetIssueReq.Asset.Amount = math.MaxUint64

assets := MintAssetsConfirmBatch(
Expand All @@ -262,7 +264,7 @@ func testReIssuanceAmountOverflow(t *harnessTest) {
// Reissue an amount which is minimally sufficient to lead to an
// overflow error.
assetIssueReq.Asset.Amount = 1
assetIssueReq.EnableEmission = false
assetIssueReq.Asset.GroupedAsset = true
assetIssueReq.Asset.GroupKey = groupKey

ctxb := context.Background()
Expand Down Expand Up @@ -292,16 +294,45 @@ func testMintWithGroupKeyErrors(t *harnessTest) {
// Now, create a minting request to try and reissue into the group
// created during minting.
reissueRequest := CopyRequest(simpleAssets[0])

// An asset cannot be both a new grouped asset and grouped asset.
reissueRequest.Asset.NewGroupedAsset = true
reissueRequest.Asset.GroupedAsset = true
_, err := t.tapd.MintAsset(ctxb, reissueRequest)
require.ErrorContains(t.t, err, "cannot set both new grouped asset")

// A grouped asset must specify a specific group.
reissueRequest.Asset.NewGroupedAsset = false
reissueRequest.Asset.GroupedAsset = true
_, err = t.tapd.MintAsset(ctxb, reissueRequest)
require.ErrorContains(t.t, err, "must specify a group key or")

// An asset cannot specify a group without being a grouped asset.
reissueRequest.Asset.NewGroupedAsset = false
reissueRequest.Asset.GroupedAsset = false
reissueRequest.Asset.GroupKey = collectGroupKey
_, err = t.tapd.MintAsset(ctxb, reissueRequest)
require.ErrorContains(t.t, err, "must set grouped asset to mint")

// A request must not have the emission flag set if a group key is given.
reissueRequest.EnableEmission = true
// A grouped asset cannot specify both a group key and group anchor.
reissueRequest.Asset.NewGroupedAsset = false
reissueRequest.Asset.GroupedAsset = true
reissueRequest.Asset.GroupKey = collectGroupKey
reissueRequest.Asset.GroupAnchor = collectGenInfo.Name
_, err = t.tapd.MintAsset(ctxb, reissueRequest)
require.ErrorContains(t.t, err, "cannot specify both a group key")

_, err := t.tapd.MintAsset(ctxb, reissueRequest)
require.ErrorContains(t.t, err, "must disable emission")
// An asset cannot be a new grouped asset and reference a specific
// group.
reissueRequest.Asset.NewGroupedAsset = true
reissueRequest.Asset.GroupedAsset = false
_, err = t.tapd.MintAsset(ctxb, reissueRequest)
require.ErrorContains(t.t, err, "must disable emission to specify")

// Restore the emission flag.
reissueRequest.EnableEmission = false
// Restore the correct flags for a new grouped asset.
reissueRequest.Asset.NewGroupedAsset = false
reissueRequest.Asset.GroupedAsset = true
reissueRequest.Asset.GroupAnchor = ""

// A given group key must be parseable, so a group key with an invalid
// parity byte should be rejected.
Expand Down
10 changes: 6 additions & 4 deletions itest/universe_pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func mintBatchAssetsTest(
Data: imageMetadataBytes,
Type: 0,
},
Amount: 1,
Amount: 1,
NewGroupedAsset: false,
},
EnableEmission: false,
}

// Update the asset name and metadata to match an index.
Expand All @@ -96,7 +96,7 @@ func mintBatchAssetsTest(
// Use the first asset of the batch as the asset group anchor.
collectibleAnchorReq := CopyRequest(&collectibleRequestTemplate)
incrementMintAsset(collectibleAnchorReq.Asset, 0)
collectibleAnchorReq.EnableEmission = true
collectibleAnchorReq.Asset.NewGroupedAsset = true
batchReqs = append(batchReqs, collectibleAnchorReq)

groupSize := testGroupSize
Expand All @@ -116,10 +116,12 @@ func mintBatchAssetsTest(

incrementMintAsset(groupedAsset.Asset, i)
collectibleAnchorReq = CopyRequest(groupedAsset)
groupedAsset.EnableEmission = true
groupedAsset.Asset.NewGroupedAsset = true
} else {
groupedAsset.Asset.GroupAnchor =
collectibleAnchorReq.Asset.Name
groupedAsset.Asset.GroupedAsset = true
groupedAsset.Asset.NewGroupedAsset = false

incrementMintAsset(groupedAsset.Asset, i)
}
Expand Down
Loading
Loading