-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
169 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package itest | ||
|
||
import ( | ||
"context" | ||
"encoding/binary" | ||
"encoding/hex" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/lightninglabs/taproot-assets/taprpc" | ||
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
const ( | ||
// testDataFileName is the name of the directory with the test data. | ||
testDataFileName = "testdata" | ||
) | ||
|
||
var ( | ||
// Raw data of Cryptopunk 0 saved as a PNG. | ||
ImageMetadataFileName = filepath.Join( | ||
testDataFileName, "8k-metadata.hex", | ||
) | ||
) | ||
|
||
func testMintBatchStressTest(t *harnessTest) { | ||
// Read base metadata. | ||
imageMetadataHex, err := os.ReadFile(ImageMetadataFileName) | ||
require.NoError(t.t, err) | ||
|
||
imageMetadataBytes, err := hex.DecodeString( | ||
strings.Trim(string(imageMetadataHex), "\n"), | ||
) | ||
require.NoError(t.t, err) | ||
|
||
var ( | ||
batchSize = 10000 | ||
batchRequests = make([]*mintrpc.MintAssetRequest, batchSize) | ||
baseName = "jpeg" | ||
metaPrefixSize = binary.MaxVarintLen16 | ||
metadataPrefix = make([]byte, metaPrefixSize) | ||
) | ||
|
||
// Each asset in the batch will share a name and metdata preimage, that | ||
// will be updated based on the asset's index in the batch. | ||
collectibleRequestTemplate := mintrpc.MintAssetRequest{ | ||
Asset: &mintrpc.MintAsset{ | ||
AssetType: taprpc.AssetType_COLLECTIBLE, | ||
Name: baseName, | ||
AssetMeta: &taprpc.AssetMeta{ | ||
Data: imageMetadataBytes, | ||
Type: 0, | ||
}, | ||
Amount: 1, | ||
}, | ||
EnableEmission: false, | ||
} | ||
|
||
// Update the asset name and metadata to match an index. | ||
incrementMintAsset := func(asset *mintrpc.MintAsset, ind int) { | ||
asset.Name = asset.Name + strconv.Itoa(ind) | ||
binary.PutUvarint(metadataPrefix, uint64(ind)) | ||
copy(asset.AssetMeta.Data[0:metaPrefixSize], metadataPrefix) | ||
} | ||
|
||
fmt.Println(len(imageMetadataBytes)) | ||
|
||
// Use the first asset of the batch as the asset group anchor. | ||
collectibleAnchor := copyRequest(&collectibleRequestTemplate) | ||
incrementMintAsset(collectibleAnchor.Asset, 0) | ||
collectibleAnchor.EnableEmission = true | ||
batchRequests[0] = collectibleAnchor | ||
|
||
// Generate the rest of the batch, with each asset referencing the group | ||
// anchor we created above. | ||
for i := 1; i < batchSize; i++ { | ||
groupedAsset := copyRequest(&collectibleRequestTemplate) | ||
incrementMintAsset(groupedAsset.Asset, i) | ||
groupedAsset.Asset.GroupAnchor = collectibleAnchor.Asset.Name | ||
batchRequests[i] = groupedAsset | ||
} | ||
|
||
// Submit the batch for minting. Use an extended timeout for the TX | ||
// appearing in the mempool so we can observe the minter hitting its own | ||
// shorter default timeout. | ||
minterTimeout := defaultWaitTimeout * 2 | ||
_ = mintAssetsConfirmBatch(t, t.tapd, &minterTimeout, batchRequests) | ||
|
||
// groupKey := rpcBatchAssets[0].AssetGroup.TweakedGroupKey | ||
|
||
// Assert that some expected properties of the mint hold; we should have | ||
// one asset group, with a balance equal to the number of assets, and | ||
// with the correct group anchor set. | ||
groupCount := 1 | ||
assertNumGroups(t.t, t.tapd, groupCount) | ||
ctxb := context.Background() | ||
balancesResp, err := t.tapd.ListBalances( | ||
ctxb, &taprpc.ListBalancesRequest{ | ||
GroupBy: &taprpc.ListBalancesRequest_GroupKey{ | ||
GroupKey: true, | ||
}, | ||
}, | ||
) | ||
require.NoError(t.t, err) | ||
|
||
groupBalances := balancesResp.AssetGroupBalances | ||
require.Len(t.t, maps.Values(groupBalances), groupCount) | ||
groupBalance := maps.Values(groupBalances)[0] | ||
require.Equal(t.t, groupBalance.Balance, uint64(batchSize)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.