From c7e626b7b6527ea8e742a4e8232ef4cc69b3c78c Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 25 Jul 2024 16:33:10 +0800 Subject: [PATCH] add ut --- contract/Forest/ForestContract_Creators.cs | 1 + test/Forest.Tests/ForestContractTests_List.cs | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/contract/Forest/ForestContract_Creators.cs b/contract/Forest/ForestContract_Creators.cs index ff0ec91..6c9af15 100644 --- a/contract/Forest/ForestContract_Creators.cs +++ b/contract/Forest/ForestContract_Creators.cs @@ -9,6 +9,7 @@ public partial class ForestContract public override Empty SetRoyalty(SetRoyaltyInput input) { AssertContractInitialized(); + AssertSenderIsAdmin(); Assert(0 <= input.Royalty && input.Royalty < FeeDenominator, "Royalty should be between 0% to 100%."); var tokenInfo = State.TokenContract.GetTokenInfo.Call(new GetTokenInfoInput { diff --git a/test/Forest.Tests/ForestContractTests_List.cs b/test/Forest.Tests/ForestContractTests_List.cs index 93cdfc3..f02f8fb 100644 --- a/test/Forest.Tests/ForestContractTests_List.cs +++ b/test/Forest.Tests/ForestContractTests_List.cs @@ -3260,4 +3260,60 @@ public async void BatchCancelListTest() } } + + [Fact] + public async void RoyaltyTest() + { + await InitializeForestContract(); + await PrepareNftData(); + + await AdminForestContractStub.SetRoyalty.SendAsync(new SetRoyaltyInput() + { + Symbol = "TESTNFT-0", + RoyaltyFeeReceiver = User1Address, + Royalty = 250 + }); + + var royaltyInfo = await ForestContractStub.GetRoyalty.CallAsync(new GetRoyaltyInput() + { + Symbol = "TESTNFT-0" + }); + royaltyInfo.ShouldNotBeNull(); + royaltyInfo.Royalty.ShouldBe(250); + royaltyInfo.RoyaltyFeeReceiver.ShouldBe(User1Address); + + //exception + // var exception = await Assert.ThrowsAsync(act); + var result = await AdminForestContractStub.SetRoyalty.SendWithExceptionAsync(new SetRoyaltyInput() + { + Symbol = "TEST-0", + RoyaltyFeeReceiver = User1Address, + Royalty = 250 + }); + result.TransactionResult.Error.ShouldContain("TokenInfo not found"); + + result = await AdminForestContractStub.SetRoyalty.SendWithExceptionAsync(new SetRoyaltyInput() + { + Symbol = "TESTNFT-0", + RoyaltyFeeReceiver = User1Address, + Royalty = -250 + }); + result.TransactionResult.Error.ShouldContain("Royalty should be between"); + + result = await AdminForestContractStub.SetRoyalty.SendWithExceptionAsync(new SetRoyaltyInput() + { + Symbol = "TESTNFT-0", + RoyaltyFeeReceiver = User1Address, + Royalty = 10000 + }); + result.TransactionResult.Error.ShouldContain("Royalty should be between"); + + result = await Seller1ForestContractStub.SetRoyalty.SendWithExceptionAsync(new SetRoyaltyInput() + { + Symbol = "TESTNFT-0", + RoyaltyFeeReceiver = User1Address, + Royalty = 10000 + }); + result.TransactionResult.Error.ShouldContain("No permission"); + } } \ No newline at end of file