Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
fyannch committed Jul 25, 2024
1 parent 3c28051 commit c7e626b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions contract/Forest/ForestContract_Creators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
56 changes: 56 additions & 0 deletions test/Forest.Tests/ForestContractTests_List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception>(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");
}
}

0 comments on commit c7e626b

Please sign in to comment.