Skip to content

Commit

Permalink
Remove old royalty rate stored in class config
Browse files Browse the repository at this point in the history
  • Loading branch information
elise-ng committed Jul 1, 2022
1 parent c35f4fe commit 06d1ad3
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 303 deletions.
1 change: 0 additions & 1 deletion proto/likechain/likenft/class_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 44,6 @@ message ClassConfig {
bool burnable = 1;
uint64 max_supply = 2;
BlindBoxConfig blind_box_config = 3 [(gogoproto.nullable) = true];
uint64 royalty_basis_points = 4;
}

message BlindBoxConfig {
Expand Down
3 changes: 1 addition & 2 deletions x/likenft/client/cli/tx_new_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 37,7 @@ func CmdNewClass() *cobra.Command {
}
],
"reveal_time": "2022-02-01T00:00:00Z"
},
"royalty_basis_points": 0 // each base point is 0.01%, max 10% / 1000 bps
}
}
}
`,
Expand Down
3 changes: 1 addition & 2 deletions x/likenft/client/cli/tx_update_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 36,7 @@ func CmdUpdateClass() *cobra.Command {
}
],
"reveal_time": "2022-02-01T00:00:00Z"
},
"royalty_basis_points": 0 // each base point is 0.01%, max 10% / 1000 bps
}
}
}`,
Args: cobra.ExactArgs(2),
Expand Down
5 changes: 0 additions & 5 deletions x/likenft/keeper/class_validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 86,5 @@ func (k msgServer) sanitizeClassConfig(ctx sdk.Context, classConfig types.ClassC
return nil, sdkerrors.ErrInvalidRequest.Wrapf("New max supply %d is less than mintable count %d", classConfig.MaxSupply, mintableCount)
}

// Assert royalty <= 10%
if classConfig.RoyaltyBasisPoints > k.MaxRoyaltyBasisPoints(ctx) {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("Royalty basis points cannot be greater than %s", k.MaxRoyaltyBasisPointsText(ctx))
}

return &classConfig, nil
}
96 changes: 0 additions & 96 deletions x/likenft/keeper/msg_server_new_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 59,6 @@ func TestNewClassISCNNormal(t *testing.T) {
},
}
revealTime := *testutil.MustParseTime(time.RFC3339, "2322-04-20T00:00:00Z")
royaltyBasisPoints := uint64(123)

// Mock keeper calls
iscnLatestVersion := uint64(2)
Expand Down Expand Up @@ -97,7 96,6 @@ func TestNewClassISCNNormal(t *testing.T) {
MintPeriods: mintPeriods,
RevealTime: revealTime,
},
RoyaltyBasisPoints: royaltyBasisPoints,
},
},
})
Expand Down Expand Up @@ -129,8 127,6 @@ func TestNewClassISCNNormal(t *testing.T) {
require.Equal(t, mintPeriod.MintPrice, mintPeriods[i].MintPrice)
}

require.Equal(t, royaltyBasisPoints, classData.Config.RoyaltyBasisPoints)

// Check mock was called as expected
ctrl.Finish()
}
Expand Down Expand Up @@ -1023,95 1019,3 @@ func TestNewClassBlindBoxNoMintPeriod(t *testing.T) {
// Check mock was called as expected
ctrl.Finish()
}

func TestNewClassRoyaltyTooHigh(t *testing.T) {
// Setup
ctrl := gomock.NewController(t)
accountKeeper := testutil.NewMockAccountKeeper(ctrl)
bankKeeper := testutil.NewMockBankKeeper(ctrl)
iscnKeeper := testutil.NewMockIscnKeeper(ctrl)
nftKeeper := testutil.NewMockNftKeeper(ctrl)
msgServer, goCtx, _ := setupMsgServer(t, keeper.LikenftDependedKeepers{
AccountKeeper: accountKeeper,
BankKeeper: bankKeeper,
IscnKeeper: iscnKeeper,
NftKeeper: nftKeeper,
})

// Test Input
ownerAddressBytes := []byte{0, 1, 0, 1, 0, 1, 0, 1}
ownerAddress, _ := sdk.Bech32ifyAddressBytes("cosmos", ownerAddressBytes)
iscnId := iscntypes.NewIscnId("likecoin-chain", "abcdef", 1)
name := "Class Name"
symbol := "ABC"
description := "Testing Class 123"
uri := "ipfs://abcdef"
uriHash := "abcdef"
metadata := types.JsonInput(
`{
"abc": "def",
"qwerty": 1234,
"bool": false,
"null": null,
"nested": {
"object": {
"abc": "def"
}
}
}`)
burnable := true
maxSupply := uint64(5)
mintPeriods := []types.MintPeriod{
{
StartTime: *testutil.MustParseTime(time.RFC3339, "2020-01-01T00:00:00Z"),
AllowedAddresses: make([]string, 0),
MintPrice: 1000000000,
},
}
revealTime := *testutil.MustParseTime(time.RFC3339, "2322-04-20T00:00:00Z")
royaltyBasisPoints := uint64(1001)

// Mock keeper calls
iscnLatestVersion := uint64(2)
iscnKeeper.
EXPECT().
GetContentIdRecord(gomock.Any(), gomock.Eq(iscnId.Prefix)).
Return(&iscntypes.ContentIdRecord{
OwnerAddressBytes: ownerAddressBytes,
LatestVersion: iscnLatestVersion,
})

// Run
res, err := msgServer.NewClass(goCtx, &types.MsgNewClass{
Creator: ownerAddress,
Parent: types.ClassParentInput{
Type: types.ClassParentType_ISCN,
IscnIdPrefix: iscnId.Prefix.String(),
},
Input: types.ClassInput{
Name: name,
Symbol: symbol,
Description: description,
Uri: uri,
UriHash: uriHash,
Metadata: metadata,
Config: types.ClassConfig{
Burnable: burnable,
MaxSupply: maxSupply,
BlindBoxConfig: &types.BlindBoxConfig{
MintPeriods: mintPeriods,
RevealTime: revealTime,
},
RoyaltyBasisPoints: royaltyBasisPoints,
},
},
})

// Check output
require.Empty(t, res)
require.Error(t, err)
require.Contains(t, err.Error(), sdkerrors.ErrInvalidRequest.Error())

// Check mock was called as expected
ctrl.Finish()
}
120 changes: 6 additions & 114 deletions x/likenft/keeper/msg_server_update_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 64,8 @@ func TestUpdateClassISCNNormal(t *testing.T) {
IscnIdPrefix: iscnId.Prefix.String(),
},
Config: types.ClassConfig{
Burnable: false,
MaxSupply: uint64(500),
RoyaltyBasisPoints: uint64(321),
Burnable: false,
MaxSupply: uint64(500),
},
}
oldClassDataInAny, _ := cdctypes.NewAnyWithValue(&oldClassData)
Expand Down Expand Up @@ -119,9 118,8 @@ func TestUpdateClassISCNNormal(t *testing.T) {
UriHash: uriHash,
Metadata: metadata,
Config: types.ClassConfig{
Burnable: burnable,
MaxSupply: maxSupply,
RoyaltyBasisPoints: uint64(123),
Burnable: burnable,
MaxSupply: maxSupply,
},
},
})
Expand All @@ -142,9 140,8 @@ func TestUpdateClassISCNNormal(t *testing.T) {
require.Equal(t, iscnId.Prefix.String(), classData.Parent.IscnIdPrefix)
require.Equal(t, iscnLatestVersion, classData.Parent.IscnVersionAtMint)
require.Equal(t, types.ClassConfig{
Burnable: burnable,
MaxSupply: maxSupply,
RoyaltyBasisPoints: uint64(123),
Burnable: burnable,
MaxSupply: maxSupply,
}, classData.Config)

// Check mock was called as expected
Expand Down Expand Up @@ -2175,108 2172,3 @@ func TestUpdateClassMaxSupplyNotLessThanMintableCount(t *testing.T) {
// Check mock was called as expected
ctrl.Finish()
}

func TestUpdateClassRoyaltyTooHigh(t *testing.T) {
// Setup
ctrl := gomock.NewController(t)
accountKeeper := testutil.NewMockAccountKeeper(ctrl)
bankKeeper := testutil.NewMockBankKeeper(ctrl)
iscnKeeper := testutil.NewMockIscnKeeper(ctrl)
nftKeeper := testutil.NewMockNftKeeper(ctrl)
msgServer, goCtx, keeper := setupMsgServer(t, keeper.LikenftDependedKeepers{
AccountKeeper: accountKeeper,
BankKeeper: bankKeeper,
IscnKeeper: iscnKeeper,
NftKeeper: nftKeeper,
})
ctx := sdk.UnwrapSDKContext(goCtx)

// Test Input
ownerAddressBytes := []byte{0, 1, 0, 1, 0, 1, 0, 1}
ownerAddress, _ := sdk.Bech32ifyAddressBytes("cosmos", ownerAddressBytes)
classId := "likenft1aabbccddeeff"
iscnId := iscntypes.NewIscnId("likecoin-chain", "abcdef", 1)
name := "Class Name"
symbol := "ABC"
description := "Testing Class 123"
uri := "ipfs://abcdef"
uriHash := "abcdef"
metadata := types.JsonInput(
`{
"abc": "def",
"qwerty": 1234,
"bool": false,
"null": null,
"nested": {
"object": {
"abc": "def"
}
}
}`)
burnable := true
maxSupply := uint64(5)

// Mock keeper calls
oldClassData := types.ClassData{
Metadata: types.JsonInput(`{"aaaa": "bbbb"}`),
Parent: types.ClassParent{
Type: types.ClassParentType_ISCN,
IscnIdPrefix: iscnId.Prefix.String(),
},
Config: types.ClassConfig{
Burnable: false,
MaxSupply: uint64(500),
RoyaltyBasisPoints: uint64(321),
},
}
oldClassDataInAny, _ := cdctypes.NewAnyWithValue(&oldClassData)
nftKeeper.
EXPECT().
GetClass(gomock.Any(), classId).
Return(nft.Class{
Id: classId,
Name: "Old Name",
Symbol: "OLD",
Description: "Old Class 234",
Uri: "ipfs://11223344",
UriHash: "11223344",
Data: oldClassDataInAny,
}, true)

nftKeeper.
EXPECT().
GetTotalSupply(gomock.Any(), classId).
Return(uint64(0))

keeper.SetClassesByISCN(ctx, types.ClassesByISCN{
IscnIdPrefix: iscnId.Prefix.String(),
ClassIds: []string{classId},
})

// Run
res, err := msgServer.UpdateClass(goCtx, &types.MsgUpdateClass{
Creator: ownerAddress,
ClassId: classId,
Input: types.ClassInput{
Name: name,
Symbol: symbol,
Description: description,
Uri: uri,
UriHash: uriHash,
Metadata: metadata,
Config: types.ClassConfig{
Burnable: burnable,
MaxSupply: maxSupply,
RoyaltyBasisPoints: uint64(1001),
},
},
})

// Check output
require.Nil(t, res)
require.Error(t, err)
require.Contains(t, err.Error(), sdkerrors.ErrInvalidRequest.Error())

// Check mock was called as expected
ctrl.Finish()
}
Loading

0 comments on commit 06d1ad3

Please sign in to comment.