Skip to content

Commit

Permalink
Minting NFT and sending to recipient is not possible if whitelisting …
Browse files Browse the repository at this point in the history
…is enabled
  • Loading branch information
Wojtek committed Oct 16, 2023
1 parent 2bed6f6 commit f8f2949
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions x/asset/nft/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ func (k Keeper) Mint(ctx sdk.Context, settings types.MintSettings) error {
return sdkerrors.Wrapf(types.ErrInvalidInput, "ID %q has been burnt for the class", settings.ID)
}

if err := k.isNFTReceivable(ctx, settings.ClassID, settings.ID, settings.Recipient); err != nil {
return sdkerrors.Wrapf(cosmoserrors.ErrUnauthorized, "address %q is unauthorized to receive NFT", settings.Recipient.String())
}

params := k.GetParams(ctx)
if params.MintFee.IsPositive() {
coinsToBurn := sdk.NewCoins(params.MintFee)
Expand Down
42 changes: 41 additions & 1 deletion x/asset/nft/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestKeeper_MintWithRecipient(t *testing.T) {
URIHash: "content-hash",
}

// mint first NFT
// mint NFT
err = nftKeeper.Mint(ctx, settings)
requireT.NoError(err)

Expand All @@ -281,6 +281,46 @@ func TestKeeper_MintWithRecipient(t *testing.T) {
requireT.Equal(sdkmath.ZeroInt().String(), balance.Amount.String())
}

func TestKeeper_MintWithRecipientAndWhitelisting(t *testing.T) {
requireT := require.New(t)
testApp := simapp.New()
ctx := testApp.NewContext(false, tmproto.Header{})
nftKeeper := testApp.AssetNFTKeeper

nftParams := types.Params{
MintFee: sdk.NewInt64Coin(constant.DenomDev, 10_000_000),
}
requireT.NoError(nftKeeper.SetParams(ctx, nftParams))

addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
randomAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
requireT.NoError(testApp.FundAccount(ctx, addr, sdk.NewCoins(nftParams.MintFee)))
classSettings := types.IssueClassSettings{
Issuer: addr,
Symbol: "symbol",
Features: []types.ClassFeature{
types.ClassFeature_whitelisting,
},
}

classID, err := nftKeeper.IssueClass(ctx, classSettings)
requireT.NoError(err)
requireT.EqualValues(classSettings.Symbol+"-"+addr.String(), classID)

settings := types.MintSettings{
Sender: addr,
Recipient: randomAddr,
ClassID: classID,
ID: "my-id",
URI: "https://my-nft-meta.invalid/1",
URIHash: "content-hash",
}

// mint NFT - should fail because recipient is not whitelisted, and cannot be because nft does not exist
err = nftKeeper.Mint(ctx, settings)
requireT.ErrorIs(err, cosmoserrors.ErrUnauthorized)
}

func TestKeeper_Burn(t *testing.T) {
requireT := require.New(t)
testApp := simapp.New()
Expand Down

0 comments on commit f8f2949

Please sign in to comment.