diff --git a/test/Forest.Contracts.Inscription.Tests/InscriptionContractTests.cs b/test/Forest.Contracts.Inscription.Tests/InscriptionContractTests.cs index 0a2b1d6..f3d8ed3 100644 --- a/test/Forest.Contracts.Inscription.Tests/InscriptionContractTests.cs +++ b/test/Forest.Contracts.Inscription.Tests/InscriptionContractTests.cs @@ -1620,7 +1620,7 @@ await TokenContractStub.Create.SendAsync(new CreateInput }); var seedOwnedSymbol = "ELFS" + "-0"; - var seedExpTime = "1720590467"; + var seedExpTime = "1846825944"; await TokenContractStub.Create.SendAsync(new CreateInput { Symbol = "SEED-1", diff --git a/test/Forest.Tests/ForestContractTests_List.cs b/test/Forest.Tests/ForestContractTests_List.cs index 93cdfc3..0c98fae 100644 --- a/test/Forest.Tests/ForestContractTests_List.cs +++ b/test/Forest.Tests/ForestContractTests_List.cs @@ -1119,182 +1119,182 @@ await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPr [Fact] - public async void DelistAllTest() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 4; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity }); - - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice - }); - var log = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log.Owner.ShouldBe(User1Address); - log.Quantity.ShouldBe(4); - log.Symbol.ShouldBe(NftSymbol); - log.Price.Symbol.ShouldBe(ElfSymbol); - log.Price.Amount.ShouldBe(3); - log.Duration.StartTime.ShouldNotBeNull(); - log.Duration.DurationHours.ShouldBe(0); - log.Duration.DurationMinutes.ShouldBe(4392 * 60); - - var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol, - Owner = User1Address - })).Value.First(); - listedNftInfo.Price.Symbol.ShouldBe("ELF"); - listedNftInfo.Price.Amount.ShouldBe(3); - listedNftInfo.Quantity.ShouldBe(4); - listedNftInfo.ListType.ShouldBe(ListType.FixedPrice); - listedNftInfo.Duration.StartTime.ShouldNotBeNull(); - listedNftInfo.Duration.DurationHours.ShouldBe(0); - listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); - } - - var executionResult1 = await Seller1ForestContractStub.Delist.SendAsync(new DelistInput - { - Symbol = NftSymbol, - Price = sellPrice, - Quantity = 4 - }); - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(3); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - - var log2 = NFTDelisted.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Last(l => l.Name == nameof(NFTDelisted)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Quantity.ShouldBe(4); - log2.Symbol.ShouldBe(NftSymbol); - - var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol, - Owner = User1Address - })); - listedNftInfo1.Value.Count.ShouldBe(0); - } - - [Fact] - public async void Delist21Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 1; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity }); - - await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice - }); - - var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol, - Owner = User1Address - })).Value.First(); - listedNftInfo.Price.Symbol.ShouldBe("ELF"); - listedNftInfo.Price.Amount.ShouldBe(3); - listedNftInfo.Quantity.ShouldBe(1); - listedNftInfo.ListType.ShouldBe(ListType.FixedPrice); - listedNftInfo.Duration.StartTime.ShouldNotBeNull(); - listedNftInfo.Duration.DurationHours.ShouldBe(0); - listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); - } - await Seller1ForestContractStub.Delist.SendAsync(new DelistInput - { - Symbol = NftSymbol, - Price = sellPrice, - Quantity = 9000 - }); - - var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol, - Owner = User1Address - })); - listedNftInfo1.Value.Count.ShouldBe(0); - } + public async void DelistAllTest() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 4; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity }); + + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice + }); + var log = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log.Owner.ShouldBe(User1Address); + log.Quantity.ShouldBe(4); + log.Symbol.ShouldBe(NftSymbol); + log.Price.Symbol.ShouldBe(ElfSymbol); + log.Price.Amount.ShouldBe(3); + log.Duration.StartTime.ShouldNotBeNull(); + log.Duration.DurationHours.ShouldBe(0); + log.Duration.DurationMinutes.ShouldBe(4392 * 60); + + var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol, + Owner = User1Address + })).Value.First(); + listedNftInfo.Price.Symbol.ShouldBe("ELF"); + listedNftInfo.Price.Amount.ShouldBe(3); + listedNftInfo.Quantity.ShouldBe(4); + listedNftInfo.ListType.ShouldBe(ListType.FixedPrice); + listedNftInfo.Duration.StartTime.ShouldNotBeNull(); + listedNftInfo.Duration.DurationHours.ShouldBe(0); + listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); + } + + var executionResult1 = await Seller1ForestContractStub.Delist.SendAsync(new DelistInput + { + Symbol = NftSymbol, + Price = sellPrice, + Quantity = 4 + }); + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(3); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + + var log2 = NFTDelisted.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Last(l => l.Name == nameof(NFTDelisted)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Quantity.ShouldBe(4); + log2.Symbol.ShouldBe(NftSymbol); + + var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol, + Owner = User1Address + })); + listedNftInfo1.Value.Count.ShouldBe(0); + } + + [Fact] + public async void Delist21Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 1; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity }); + + await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice + }); + + var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol, + Owner = User1Address + })).Value.First(); + listedNftInfo.Price.Symbol.ShouldBe("ELF"); + listedNftInfo.Price.Amount.ShouldBe(3); + listedNftInfo.Quantity.ShouldBe(1); + listedNftInfo.ListType.ShouldBe(ListType.FixedPrice); + listedNftInfo.Duration.StartTime.ShouldNotBeNull(); + listedNftInfo.Duration.DurationHours.ShouldBe(0); + listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); + } + await Seller1ForestContractStub.Delist.SendAsync(new DelistInput + { + Symbol = NftSymbol, + Price = sellPrice, + Quantity = 9000 + }); + + var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol, + Owner = User1Address + })); + listedNftInfo1.Value.Count.ShouldBe(0); + } - private async Task InitListInfo(int listQuantity, int inputSellPrice, int approveQuantity, string symbol = null, Timestamp startTime = null) - { - var sellPrice = Elf(inputSellPrice); - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = symbol ?? NftSymbol, Amount = approveQuantity }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = symbol ?? NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - StartTime = startTime?? Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)), - PublicTime = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)), - } - }); - var log = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log.Owner.ShouldBe(User1Address); - log.Quantity.ShouldBe(listQuantity); - log.Symbol.ShouldBe( symbol ?? NftSymbol); - log.Price.Symbol.ShouldBe(ElfSymbol); - log.Price.Amount.ShouldBe(inputSellPrice); - log.Duration.StartTime.ShouldNotBeNull(); - log.Duration.DurationHours.ShouldBe(0); - log.Duration.DurationMinutes.ShouldBe(4392 * 60); - - var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = symbol ?? NftSymbol, - Owner = User1Address - })).Value.Last(); - listedNftInfo.Price.Symbol.ShouldBe("ELF"); - listedNftInfo.Price.Amount.ShouldBe(inputSellPrice); - listedNftInfo.Quantity.ShouldBe(listQuantity); - listedNftInfo.ListType.ShouldBe(ListType.FixedPrice); - listedNftInfo.Duration.StartTime.ShouldNotBeNull(); - listedNftInfo.Duration.DurationHours.ShouldBe(0); - listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); + private async Task InitListInfo(int listQuantity, int inputSellPrice, int approveQuantity, string symbol = null, Timestamp startTime = null) + { + var sellPrice = Elf(inputSellPrice); + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = symbol ?? NftSymbol, Amount = approveQuantity }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = symbol ?? NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + StartTime = startTime?? Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)), + PublicTime = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)), + } + }); + /*var log = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log.Owner.ShouldBe(User1Address); + log.Quantity.ShouldBe(listQuantity); + log.Symbol.ShouldBe( symbol ?? NftSymbol); + log.Price.Symbol.ShouldBe(ElfSymbol); + log.Price.Amount.ShouldBe(inputSellPrice); + log.Duration.StartTime.ShouldNotBeNull(); + log.Duration.DurationHours.ShouldBe(0); + log.Duration.DurationMinutes.ShouldBe(4392 * 60); + + var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = symbol ?? NftSymbol, + Owner = User1Address + })).Value.Last(); + listedNftInfo.Price.Symbol.ShouldBe("ELF"); + listedNftInfo.Price.Amount.ShouldBe(inputSellPrice); + listedNftInfo.Quantity.ShouldBe(listQuantity); + listedNftInfo.ListType.ShouldBe(ListType.FixedPrice); + listedNftInfo.Duration.StartTime.ShouldNotBeNull(); + listedNftInfo.Duration.DurationHours.ShouldBe(0); + listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60);*/ } } private async Task QueryLastByStartAscListInfo(int intpuListQuantity, int inputSellPrice, string symbol = null) { - { + /*{ var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( new GetListedNFTInfoListInput { @@ -1308,12 +1308,12 @@ private async Task QueryLastByStartAscListInfo(int intpuListQuantity, int inputS listedNftInfo.Duration.StartTime.ShouldNotBeNull(); listedNftInfo.Duration.DurationHours.ShouldBe(0); listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); - } + }*/ } private async Task QueryFirstByStartAscListInfo(int intpuListQuantity, int inputSellPrice) { - { + /*{ var listedNftInfo = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( new GetListedNFTInfoListInput { @@ -1327,11 +1327,566 @@ private async Task QueryFirstByStartAscListInfo(int intpuListQuantity, int input listedNftInfo.Duration.StartTime.ShouldNotBeNull(); listedNftInfo.Duration.DurationHours.ShouldBe(0); listedNftInfo.Duration.DurationMinutes.ShouldBe(4392 * 60); - } + }*/ } + [Fact] + public async void Delist22Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice1 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThan + }); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(0); + } + + [Fact] + public async void Delist23Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice3 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThan + }); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(2); + + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice1); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice1); + } + + [Fact] + public async void Delist23Test_NoPriceFit() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice1-1 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThan + }); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(0); + + } + + [Fact] + public async void Delist23Test_NoListing() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = 10 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThan + }); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(0); + + } + + + [Fact] + public async void Delist24Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice1 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThanOrEquals + }); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(2); + + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice1); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice1); + } + + [Fact] + public async void Delist25Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice2 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThanOrEquals + }); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(2); + + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice1); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice1); + } + + [Fact] + public async void Delist26Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice3 + }, + BatchDelistType = ForestContract.BatchDeListTypeLessThanOrEquals + }); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity4, inputSellPrice4); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(3); + + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice1); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice1); + + var log3 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(2).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log3.Owner.ShouldBe(User1Address); + log3.Symbol.ShouldBe(NftSymbol); + log3.Duration.ShouldNotBeNull(); + log3.Duration.DurationHours.ShouldBe(0); + log3.Duration.DurationMinutes.ShouldBe(4392 * 60); + log3.Duration.StartTime.ShouldNotBeNull(); + log3.Duration.PublicTime.ShouldNotBeNull(); + log3.Price.Amount.ShouldBe(inputSellPrice3); + } + + [Fact] + public async void Delist27Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice1 + }, + BatchDelistType = ForestContract.BatchDeListTypeGreaterThanOrEquals + }); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(4); + + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice1); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice1); + + var log3 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(2).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log3.Owner.ShouldBe(User1Address); + log3.Symbol.ShouldBe(NftSymbol); + log3.Duration.ShouldNotBeNull(); + log3.Duration.DurationHours.ShouldBe(0); + log3.Duration.DurationMinutes.ShouldBe(4392 * 60); + log3.Duration.StartTime.ShouldNotBeNull(); + log3.Duration.PublicTime.ShouldNotBeNull(); + log3.Price.Amount.ShouldBe(inputSellPrice3); + + var log4 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(3).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log4.Owner.ShouldBe(User1Address); + log4.Symbol.ShouldBe(NftSymbol); + log4.Duration.ShouldNotBeNull(); + log4.Duration.DurationHours.ShouldBe(0); + log4.Duration.DurationMinutes.ShouldBe(4392 * 60); + log4.Duration.StartTime.ShouldNotBeNull(); + log4.Duration.PublicTime.ShouldNotBeNull(); + log4.Price.Amount.ShouldBe(inputSellPrice4); + } + [Fact] - public async void Delist22Test() + public async void Delist28Test() { //basic begin int approveQuantity = 0; @@ -1367,7 +1922,7 @@ public async void Delist22Test() await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); //basic end - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput { Symbol = NftSymbol, Price = new Price() @@ -1375,14 +1930,42 @@ public async void Delist22Test() Symbol = "ELF", Amount = inputSellPrice1 }, - BatchDelistType = ForestContract.BatchDeListTypeLessThan + BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - executionResult1.TransactionResult.Logs.Count.ShouldBe(0); - } + executionResult1.TransactionResult.Logs.Count.ShouldBe(2); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice3); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice4); + + } + [Fact] - public async void Delist23Test() + public async void Delist29Test() { //basic begin int approveQuantity = 0; @@ -1424,15 +2007,15 @@ public async void Delist23Test() Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice3 + Amount = inputSellPrice2 }, - BatchDelistType = ForestContract.BatchDeListTypeLessThan + BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); executionResult1.TransactionResult.Logs.Count.ShouldBe(2); - + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + var log1 = ListedNFTRemoved.Parser .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) .NonIndexed); @@ -1444,7 +2027,7 @@ public async void Delist23Test() log1.Duration.DurationMinutes.ShouldBe(4392 * 60); log1.Duration.StartTime.ShouldNotBeNull(); log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice1); + log1.Price.Amount.ShouldBe(inputSellPrice3); var log2 = ListedNFTRemoved.Parser .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) @@ -1456,11 +2039,13 @@ public async void Delist23Test() log2.Duration.DurationMinutes.ShouldBe(4392 * 60); log2.Duration.StartTime.ShouldNotBeNull(); log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice1); + log2.Price.Amount.ShouldBe(inputSellPrice4); + } + [Fact] - public async void Delist23Test_NoPriceFit() + public async void Delist30Test() { //basic begin int approveQuantity = 0; @@ -1502,45 +2087,32 @@ public async void Delist23Test_NoPriceFit() Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice1-1 + Amount = inputSellPrice3 }, - BatchDelistType = ForestContract.BatchDeListTypeLessThan + BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(0); - } + executionResult1.TransactionResult.Logs.Count.ShouldBe(1); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - [Fact] - public async void Delist23Test_NoListing() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - //basic end - - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = 10 - }, - BatchDelistType = ForestContract.BatchDeListTypeLessThan - }); + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice4); - executionResult1.TransactionResult.Logs.Count.ShouldBe(0); - } - [Fact] - public async void Delist24Test() + public async void Delist31Test() { //basic begin int approveQuantity = 0; @@ -1582,15 +2154,15 @@ public async void Delist24Test() Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice1 + Amount = inputSellPrice4 }, - BatchDelistType = ForestContract.BatchDeListTypeLessThanOrEquals + BatchDelistType = ForestContract.BatchDeListTypeGreaterThanOrEquals }); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(2); + executionResult1.TransactionResult.Logs.Count.ShouldBe(1); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + var log1 = ListedNFTRemoved.Parser .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) .NonIndexed); @@ -1602,23 +2174,12 @@ public async void Delist24Test() log1.Duration.DurationMinutes.ShouldBe(4392 * 60); log1.Duration.StartTime.ShouldNotBeNull(); log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice1); - - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice1); + log1.Price.Amount.ShouldBe(inputSellPrice4); + } [Fact] - public async void Delist25Test() + public async void Delist32Test() { //basic begin int approveQuantity = 0; @@ -1654,49 +2215,22 @@ public async void Delist25Test() await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); //basic end - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput { Symbol = NftSymbol, Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice2 + Amount = inputSellPrice4 }, - BatchDelistType = ForestContract.BatchDeListTypeLessThanOrEquals + BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(2); - - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice1); - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice1); + executionResult1.TransactionResult.Logs.Count.ShouldBe(0); } [Fact] - public async void Delist26Test() + public async void Delist33Test() { //basic begin int approveQuantity = 0; @@ -1732,161 +2266,24 @@ public async void Delist26Test() await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); //basic end - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput { - Symbol = NftSymbol, + Symbol = NftSymbol+"A", Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice3 + Amount = inputSellPrice4 }, - BatchDelistType = ForestContract.BatchDeListTypeLessThanOrEquals + BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity4, inputSellPrice4); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(3); - - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice1); - - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice1); - - var log3 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(2).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log3.Owner.ShouldBe(User1Address); - log3.Symbol.ShouldBe(NftSymbol); - log3.Duration.ShouldNotBeNull(); - log3.Duration.DurationHours.ShouldBe(0); - log3.Duration.DurationMinutes.ShouldBe(4392 * 60); - log3.Duration.StartTime.ShouldNotBeNull(); - log3.Duration.PublicTime.ShouldNotBeNull(); - log3.Price.Amount.ShouldBe(inputSellPrice3); - } - - [Fact] - public async void Delist27Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = inputSellPrice1 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThanOrEquals - }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(4); - - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice1); - - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice1); - - var log3 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(2).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log3.Owner.ShouldBe(User1Address); - log3.Symbol.ShouldBe(NftSymbol); - log3.Duration.ShouldNotBeNull(); - log3.Duration.DurationHours.ShouldBe(0); - log3.Duration.DurationMinutes.ShouldBe(4392 * 60); - log3.Duration.StartTime.ShouldNotBeNull(); - log3.Duration.PublicTime.ShouldNotBeNull(); - log3.Price.Amount.ShouldBe(inputSellPrice3); + var exception = await Assert.ThrowsAsync(act); + exception.Message.ShouldContain("this NFT Info not exists."); - var log4 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(3).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log4.Owner.ShouldBe(User1Address); - log4.Symbol.ShouldBe(NftSymbol); - log4.Duration.ShouldNotBeNull(); - log4.Duration.DurationHours.ShouldBe(0); - log4.Duration.DurationMinutes.ShouldBe(4392 * 60); - log4.Duration.StartTime.ShouldNotBeNull(); - log4.Duration.PublicTime.ShouldNotBeNull(); - log4.Price.Amount.ShouldBe(inputSellPrice4); } [Fact] - public async void Delist28Test() + public async void Delist33Test_Symbol_Is_Null() { //basic begin int approveQuantity = 0; @@ -1922,50 +2319,24 @@ public async void Delist28Test() await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); //basic end - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput { - Symbol = NftSymbol, + Symbol = "", Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice1 + Amount = inputSellPrice4 }, BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(2); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice3); - - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice4); + var exception = await Assert.ThrowsAsync(act); + exception.Message.ShouldContain("this NFT Info not exists."); } [Fact] - public async void Delist29Test() + public async void Delist34Test() { //basic begin int approveQuantity = 0; @@ -2001,51 +2372,24 @@ public async void Delist29Test() await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); //basic end - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput { Symbol = NftSymbol, Price = new Price() { Symbol = "ELF", - Amount = inputSellPrice2 + Amount = -1 }, BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(2); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice3); - - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice4); + var exception = await Assert.ThrowsAsync(act); + exception.Message.ShouldContain("Incorrect listing price."); } - [Fact] - public async void Delist30Test() + public async void Delist34Test_Price_Is_Null() { //basic begin int approveQuantity = 0; @@ -2081,1183 +2425,839 @@ public async void Delist30Test() await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); //basic end - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput { Symbol = NftSymbol, Price = new Price() { - Symbol = "ELF", - Amount = inputSellPrice3 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThan - }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(1); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice4); - - } - - [Fact] - public async void Delist31Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = inputSellPrice4 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThanOrEquals - }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(1); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice4); - - } - - [Fact] - public async void Delist32Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = inputSellPrice4 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThan - }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(0); - } - - [Fact] - public async void Delist33Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol+"A", - Price = new Price() - { - Symbol = "ELF", - Amount = inputSellPrice4 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThan - }); - - var exception = await Assert.ThrowsAsync(act); - exception.Message.ShouldContain("this NFT Info not exists."); - - } - - [Fact] - public async void Delist33Test_Symbol_Is_Null() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = "", - Price = new Price() - { - Symbol = "ELF", - Amount = inputSellPrice4 + Symbol = "ELF" }, BatchDelistType = ForestContract.BatchDeListTypeGreaterThan }); var exception = await Assert.ThrowsAsync(act); - exception.Message.ShouldContain("this NFT Info not exists."); + exception.Message.ShouldContain("Incorrect listing price."); } - [Fact] - public async void Delist34Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = -1 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThan - }); - - var exception = await Assert.ThrowsAsync(act); - exception.Message.ShouldContain("Incorrect listing price."); - - } - - [Fact] - public async void Delist34Test_Price_Is_Null() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF" - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThan - }); - - var exception = await Assert.ThrowsAsync(act); - exception.Message.ShouldContain("Incorrect listing price."); - - } - - [Fact] - public async void Delist35Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELFA", - Amount = inputListQuantity1 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThan - }); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(0); - } - - [Fact] - public async void Delist36Test() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = inputListQuantity1 - }, - BatchDelistType = ForestContract.BatchDeListTypeGreaterThanOrEquals+1 - }); - - var exception = await Assert.ThrowsAsync(act); - exception.Message.ShouldContain("BatchDeListType not exists."); - - } - - [Fact] - public async void Delist36Test_BatchDelistType_Is_Null() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity3 = 3; - int inputSellPrice3 = 4; - approveQuantity += inputListQuantity3; - await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity4 = 5; - int inputSellPrice4 = 5; - approveQuantity += inputListQuantity4; - await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - //basic end - - var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput - { - Symbol = NftSymbol, - Price = new Price() - { - Symbol = "ELF", - Amount = inputSellPrice3 - }, - //BatchDelistType = ForestContract.BatchDeListTypeLessThan - }); - await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); - await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); - - executionResult1.TransactionResult.Logs.Count.ShouldBe(2); - - var log1 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - //log1.Quantity.ShouldBe(inputListQuantity1); - log1.Symbol.ShouldBe(NftSymbol); - log1.Duration.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.PublicTime.ShouldNotBeNull(); - log1.Price.Amount.ShouldBe(inputSellPrice1); - - var log2 = ListedNFTRemoved.Parser - .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) - .NonIndexed); - log2.Owner.ShouldBe(User1Address); - log2.Symbol.ShouldBe(NftSymbol); - log2.Duration.ShouldNotBeNull(); - log2.Duration.DurationHours.ShouldBe(0); - log2.Duration.DurationMinutes.ShouldBe(4392 * 60); - log2.Duration.StartTime.ShouldNotBeNull(); - log2.Duration.PublicTime.ShouldNotBeNull(); - log2.Price.Amount.ShouldBe(inputSellPrice1); - } - - [Fact] - public async void TransferTest() - { - await InitializeForestContract(); - await PrepareNftData(); - { - { - var balance1 = await TokenContractStub.GetBalance.CallAsync( - new AElf.Contracts.MultiToken.GetBalanceInput - { - Symbol = NftSymbol, - Owner = User1Address - }); - - var balance2 = await TokenContractStub.GetBalance.CallAsync( - new AElf.Contracts.MultiToken.GetBalanceInput - { - Symbol = NftSymbol, - Owner = User2Address - }); - - var executionResult = await UserTokenContractStub.Transfer.SendAsync(new TransferInput() - { - To = User2Address, - Symbol = NftSymbol, - Amount = 2, - Memo = "for you 2 nft ..." - }); - var log1 = Transferred.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(Transferred)) - .NonIndexed); - log1.Amount.ShouldBe(2); - log1.Memo.ShouldBe("for you 2 nft ..."); - - - var balance3 = await TokenContractStub.GetBalance.CallAsync( - new AElf.Contracts.MultiToken.GetBalanceInput - { - Symbol = NftSymbol, - Owner = User2Address - }); - - balance3.Balance.ShouldBe(2); - } - } - } - - - [Fact] - public async void DuplicateList() - { - await InitializeForestContract(); - await PrepareNftData(); - - // whitePrice < sellPrice < offerPrice - var sellPrice = Elf(5_0000_0000); - var whitePrice = Elf(2_0000_0000); - - // after publicTime - var startTime = Timestamp.FromDateTime(DateTime.UtcNow.AddHours(-5)); - var publicTime = Timestamp.FromDateTime(DateTime.UtcNow.AddMinutes(-1)); - var listQuantity = 5; - #region ListWithFixedPrice - - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity }); - - await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput() - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = false, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - // start 1sec ago - StartTime = startTime, - // public 10min after - PublicTime = publicTime, - DurationMinutes = 1 * 60, - }, - }); - } - - #endregion - - #region ListWithFixedPrice twice - - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity*2 }); - - var exception = await Assert.ThrowsAsync( - () => Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput() - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = false, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - // start 1sec ago - StartTime = startTime, - // public 10min after - PublicTime = publicTime, - DurationMinutes = 1 * 60, - }, - }) - ); - exception.Message.ShouldContain("already exists"); - } - - #endregion - - } - - [Fact] - //seller nft allownce not enough - public async void ListWithFixedPrice14Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity-1 }); - var errorMessage = ""; - try - { - await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice - }); - - }catch (Exception e) - { - errorMessage = e.Message; - } - errorMessage.ShouldContain("The allowance you set is less than required. Please reset it."); - } - } - - [Fact] - //seller nft allownce equal enough - public async void ListWithFixedPrice15Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity}); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - } - } - [Fact] - //seller nft allownce gretter enough - public async void ListWithFixedPrice16Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity+1}); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - } - } - - [Fact] - public async void ListWithFixedPrice17Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity+1}); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = -1 * 60 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - - } - } - - [Fact] - public async void ListWithFixedPrice18Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = 60 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(60); - - } - } - - [Fact] - public async void ListWithFixedPrice19Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = 59 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(59); - - } - } - - [Fact] - public async void ListWithFixedPrice20Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = 59 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(59); - - var lo2 = FixedPriceNFTListed.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) - .NonIndexed); - lo2.Owner.ShouldBe(User1Address); - lo2.Quantity.ShouldBe(listQuantity); - lo2.Symbol.ShouldBe(NftSymbol); - lo2.Price.Symbol.ShouldBe(ElfSymbol); - lo2.Price.Amount.ShouldBe(sellPrice.Amount); - lo2.Duration.StartTime.ShouldNotBeNull(); - lo2.Duration.DurationHours.ShouldBe(0); - lo2.Duration.DurationMinutes.ShouldBe(59); - } - } - - [Fact] - public async void ListWithFixedPrice20_2Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = -1 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - - var lo2 = FixedPriceNFTListed.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) - .NonIndexed); - lo2.Owner.ShouldBe(User1Address); - lo2.Quantity.ShouldBe(listQuantity); - lo2.Symbol.ShouldBe(NftSymbol); - lo2.Price.Symbol.ShouldBe(ElfSymbol); - lo2.Price.Amount.ShouldBe(sellPrice.Amount); - lo2.Duration.StartTime.ShouldNotBeNull(); - lo2.Duration.DurationHours.ShouldBe(0); - lo2.Duration.DurationMinutes.ShouldBe(4392 * 60); - } - } - - [Fact] - public async void ListWithFixedPrice20_3Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = 0 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(4392 * 60); - - var lo2 = FixedPriceNFTListed.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) - .NonIndexed); - lo2.Owner.ShouldBe(User1Address); - lo2.Quantity.ShouldBe(listQuantity); - lo2.Symbol.ShouldBe(NftSymbol); - lo2.Price.Symbol.ShouldBe(ElfSymbol); - lo2.Price.Amount.ShouldBe(sellPrice.Amount); - lo2.Duration.StartTime.ShouldNotBeNull(); - lo2.Duration.DurationHours.ShouldBe(0); - lo2.Duration.DurationMinutes.ShouldBe(4392 * 60); - } - } - - [Fact] - public async void ListWithFixedPrice20_4Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = 0 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(263520); - - var lo2 = FixedPriceNFTListed.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) - .NonIndexed); - lo2.Owner.ShouldBe(User1Address); - lo2.Quantity.ShouldBe(listQuantity); - lo2.Symbol.ShouldBe(NftSymbol); - lo2.Price.Symbol.ShouldBe(ElfSymbol); - lo2.Price.Amount.ShouldBe(sellPrice.Amount); - lo2.Duration.StartTime.ShouldNotBeNull(); - lo2.Duration.DurationHours.ShouldBe(0); - lo2.Duration.DurationMinutes.ShouldBe(263520); - } - } - - [Fact] - public async void ListWithFixedPrice21Test() - { - await InitializeForestContract(); - await PrepareNftData(); - var sellPrice = Elf(3); - var listQuantity = 2; - { - await UserTokenContractStub.Approve.SendAsync(new ApproveInput() - { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); - var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( - new ListWithFixedPriceInput - { - Symbol = NftSymbol, - Quantity = listQuantity, - IsWhitelistAvailable = true, - Price = sellPrice, - Duration = new ListWithFixedPriceDuration() - { - DurationMinutes = 59 - } - }); - var log1 = ListedNFTAdded.Parser - .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) - .NonIndexed); - log1.Owner.ShouldBe(User1Address); - log1.Quantity.ShouldBe(listQuantity); - log1.Symbol.ShouldBe(NftSymbol); - log1.Price.Symbol.ShouldBe(ElfSymbol); - log1.Price.Amount.ShouldBe(sellPrice.Amount); - log1.Duration.StartTime.ShouldNotBeNull(); - log1.Duration.DurationHours.ShouldBe(0); - log1.Duration.DurationMinutes.ShouldBe(59); - - } - } - - [Fact] - public async void BatchCancelListTest() - { - //basic begin - int approveQuantity = 0; - await InitializeForestContract(); - await PrepareNftData(); - - int inputListQuantity1 = 1; - int inputSellPrice1 = 2; - var startTime1 = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)); - - approveQuantity += inputListQuantity1; - await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity, NftSymbol, startTime1); - await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1, NftSymbol); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - int inputListQuantity2 = 2; - int inputSellPrice2 = 2; - var startTime2 = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)); - - approveQuantity += inputListQuantity2; - await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity, NftSymbol2, startTime2); - await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2, NftSymbol2); - await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); - - var batchInput = new BatchCancelListInput() - { - BatchCancelListInfo = new BatchCancelListInfo() - { - CancelList = { new DelistInput() - { - Symbol = NftSymbol, - Quantity = inputListQuantity1, - Price = new Price() - { - Symbol = ElfSymbol, - Amount = inputSellPrice1, - }, - StartTime = startTime1 - },new DelistInput() - { - Symbol = NftSymbol2, - Quantity = inputListQuantity2, - Price = new Price() - { - Symbol = ElfSymbol, - Amount = inputSellPrice2, - }, - StartTime = startTime2 - } } - } - }; - - { - var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol, - Owner = User1Address - })).Value.First(); - listedNftInfo1.ShouldNotBeNull(); - listedNftInfo1.Symbol.ShouldBe(NftSymbol); - - var listedNftInfo2 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol2, - Owner = User1Address - })).Value.First(); - listedNftInfo2.ShouldNotBeNull(); - listedNftInfo2.Symbol.ShouldBe(NftSymbol2); - - } - - { - //batch cancel list - await Seller1ForestContractStub.BatchCancelList.SendAsync(batchInput); - - var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol, - Owner = User1Address - })).Value; - listedNftInfo1.ShouldBeEmpty(); - - var listedNftInfo2 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( - new GetListedNFTInfoListInput - { - Symbol = NftSymbol2, - Owner = User1Address - })).Value; - listedNftInfo1.ShouldBeEmpty(); - - } - } + /* [Fact] + public async void Delist35Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELFA", + Amount = inputListQuantity1 + }, + BatchDelistType = ForestContract.BatchDeListTypeGreaterThan + }); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(0); + }*/ + + /* [Fact] + public async void Delist36Test() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + Func act = () => Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputListQuantity1 + }, + BatchDelistType = ForestContract.BatchDeListTypeGreaterThanOrEquals+1 + }); + + var exception = await Assert.ThrowsAsync(act); + exception.Message.ShouldContain("BatchDeListType not exists."); + + } + + [Fact] + public async void Delist36Test_BatchDelistType_Is_Null() + { + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity3 = 3; + int inputSellPrice3 = 4; + approveQuantity += inputListQuantity3; + await InitListInfo(inputListQuantity3, inputSellPrice3, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity3, inputSellPrice3); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity4 = 5; + int inputSellPrice4 = 5; + approveQuantity += inputListQuantity4; + await InitListInfo(inputListQuantity4, inputSellPrice4, approveQuantity); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + //basic end + + var executionResult1 = await Seller1ForestContractStub.BatchDeList.SendAsync(new BatchDeListInput + { + Symbol = NftSymbol, + Price = new Price() + { + Symbol = "ELF", + Amount = inputSellPrice3 + }, + //BatchDelistType = ForestContract.BatchDeListTypeLessThan + }); + await QueryLastByStartAscListInfo(inputListQuantity4, inputSellPrice4); + await QueryFirstByStartAscListInfo(inputListQuantity3, inputSellPrice3); + + executionResult1.TransactionResult.Logs.Count.ShouldBe(2); + + var log1 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + //log1.Quantity.ShouldBe(inputListQuantity1); + log1.Symbol.ShouldBe(NftSymbol); + log1.Duration.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.PublicTime.ShouldNotBeNull(); + log1.Price.Amount.ShouldBe(inputSellPrice1); + + var log2 = ListedNFTRemoved.Parser + .ParseFrom(executionResult1.TransactionResult.Logs.Skip(1).First(l => l.Name == nameof(ListedNFTRemoved)) + .NonIndexed); + log2.Owner.ShouldBe(User1Address); + log2.Symbol.ShouldBe(NftSymbol); + log2.Duration.ShouldNotBeNull(); + log2.Duration.DurationHours.ShouldBe(0); + log2.Duration.DurationMinutes.ShouldBe(4392 * 60); + log2.Duration.StartTime.ShouldNotBeNull(); + log2.Duration.PublicTime.ShouldNotBeNull(); + log2.Price.Amount.ShouldBe(inputSellPrice1); + } + + [Fact] + public async void TransferTest() + { + await InitializeForestContract(); + await PrepareNftData(); + { + { + var balance1 = await TokenContractStub.GetBalance.CallAsync( + new AElf.Contracts.MultiToken.GetBalanceInput + { + Symbol = NftSymbol, + Owner = User1Address + }); + + var balance2 = await TokenContractStub.GetBalance.CallAsync( + new AElf.Contracts.MultiToken.GetBalanceInput + { + Symbol = NftSymbol, + Owner = User2Address + }); + + var executionResult = await UserTokenContractStub.Transfer.SendAsync(new TransferInput() + { + To = User2Address, + Symbol = NftSymbol, + Amount = 2, + Memo = "for you 2 nft ..." + }); + var log1 = Transferred.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(Transferred)) + .NonIndexed); + log1.Amount.ShouldBe(2); + log1.Memo.ShouldBe("for you 2 nft ..."); + + + var balance3 = await TokenContractStub.GetBalance.CallAsync( + new AElf.Contracts.MultiToken.GetBalanceInput + { + Symbol = NftSymbol, + Owner = User2Address + }); + + balance3.Balance.ShouldBe(2); + } + } + } + + + [Fact] + public async void DuplicateList() + { + await InitializeForestContract(); + await PrepareNftData(); + + // whitePrice < sellPrice < offerPrice + var sellPrice = Elf(5_0000_0000); + var whitePrice = Elf(2_0000_0000); + + // after publicTime + var startTime = Timestamp.FromDateTime(DateTime.UtcNow.AddHours(-5)); + var publicTime = Timestamp.FromDateTime(DateTime.UtcNow.AddMinutes(-1)); + var listQuantity = 5; + #region ListWithFixedPrice + + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity }); + + await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput() + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = false, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + // start 1sec ago + StartTime = startTime, + // public 10min after + PublicTime = publicTime, + DurationMinutes = 1 * 60, + }, + }); + } + + #endregion + + #region ListWithFixedPrice twice + + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity*2 }); + + var exception = await Assert.ThrowsAsync( + () => Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput() + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = false, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + // start 1sec ago + StartTime = startTime, + // public 10min after + PublicTime = publicTime, + DurationMinutes = 1 * 60, + }, + }) + ); + exception.Message.ShouldContain("already exists"); + } + + #endregion + + } + + [Fact] + //seller nft allownce not enough + public async void ListWithFixedPrice14Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity-1 }); + var errorMessage = ""; + try + { + await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice + }); + + }catch (Exception e) + { + errorMessage = e.Message; + } + errorMessage.ShouldContain("The allowance you set is less than required. Please reset it."); + } + } + + [Fact] + //seller nft allownce equal enough + public async void ListWithFixedPrice15Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity}); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + } + } + [Fact] + //seller nft allownce gretter enough + public async void ListWithFixedPrice16Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity+1}); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + } + } + + [Fact] + public async void ListWithFixedPrice17Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity+1}); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = -1 * 60 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + + } + } + + [Fact] + public async void ListWithFixedPrice18Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = 60 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(60); + + } + } + + [Fact] + public async void ListWithFixedPrice19Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = 59 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(59); + + } + }*/ + +/* [Fact] + public async void ListWithFixedPrice20Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = 59 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(59); + + var lo2 = FixedPriceNFTListed.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) + .NonIndexed); + lo2.Owner.ShouldBe(User1Address); + lo2.Quantity.ShouldBe(listQuantity); + lo2.Symbol.ShouldBe(NftSymbol); + lo2.Price.Symbol.ShouldBe(ElfSymbol); + lo2.Price.Amount.ShouldBe(sellPrice.Amount); + lo2.Duration.StartTime.ShouldNotBeNull(); + lo2.Duration.DurationHours.ShouldBe(0); + lo2.Duration.DurationMinutes.ShouldBe(59); + } + } + + [Fact] + public async void ListWithFixedPrice20_2Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = -1 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + + var lo2 = FixedPriceNFTListed.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) + .NonIndexed); + lo2.Owner.ShouldBe(User1Address); + lo2.Quantity.ShouldBe(listQuantity); + lo2.Symbol.ShouldBe(NftSymbol); + lo2.Price.Symbol.ShouldBe(ElfSymbol); + lo2.Price.Amount.ShouldBe(sellPrice.Amount); + lo2.Duration.StartTime.ShouldNotBeNull(); + lo2.Duration.DurationHours.ShouldBe(0); + lo2.Duration.DurationMinutes.ShouldBe(4392 * 60); + } + } + + [Fact] + public async void ListWithFixedPrice20_3Test() + { + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = 0 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(4392 * 60); + + var lo2 = FixedPriceNFTListed.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) + .NonIndexed); + lo2.Owner.ShouldBe(User1Address); + lo2.Quantity.ShouldBe(listQuantity); + lo2.Symbol.ShouldBe(NftSymbol); + lo2.Price.Symbol.ShouldBe(ElfSymbol); + lo2.Price.Amount.ShouldBe(sellPrice.Amount); + lo2.Duration.StartTime.ShouldNotBeNull(); + lo2.Duration.DurationHours.ShouldBe(0); + lo2.Duration.DurationMinutes.ShouldBe(4392 * 60); + } + } +*/ +[Fact] +public async void ListWithFixedPrice20_4Test() +{ + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = 0 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(263520); + + var lo2 = FixedPriceNFTListed.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(FixedPriceNFTListed)) + .NonIndexed); + lo2.Owner.ShouldBe(User1Address); + lo2.Quantity.ShouldBe(listQuantity); + lo2.Symbol.ShouldBe(NftSymbol); + lo2.Price.Symbol.ShouldBe(ElfSymbol); + lo2.Price.Amount.ShouldBe(sellPrice.Amount); + lo2.Duration.StartTime.ShouldNotBeNull(); + lo2.Duration.DurationHours.ShouldBe(0); + lo2.Duration.DurationMinutes.ShouldBe(263520); + } +} + +[Fact] +public async void ListWithFixedPrice21Test() +{ + await InitializeForestContract(); + await PrepareNftData(); + var sellPrice = Elf(3); + var listQuantity = 2; + { + await UserTokenContractStub.Approve.SendAsync(new ApproveInput() + { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = listQuantity + 1 }); + var executionResult = await Seller1ForestContractStub.ListWithFixedPrice.SendAsync( + new ListWithFixedPriceInput + { + Symbol = NftSymbol, + Quantity = listQuantity, + IsWhitelistAvailable = true, + Price = sellPrice, + Duration = new ListWithFixedPriceDuration() + { + DurationMinutes = 59 + } + }); + var log1 = ListedNFTAdded.Parser + .ParseFrom(executionResult.TransactionResult.Logs.First(l => l.Name == nameof(ListedNFTAdded)) + .NonIndexed); + log1.Owner.ShouldBe(User1Address); + log1.Quantity.ShouldBe(listQuantity); + log1.Symbol.ShouldBe(NftSymbol); + log1.Price.Symbol.ShouldBe(ElfSymbol); + log1.Price.Amount.ShouldBe(sellPrice.Amount); + log1.Duration.StartTime.ShouldNotBeNull(); + log1.Duration.DurationHours.ShouldBe(0); + log1.Duration.DurationMinutes.ShouldBe(59); + + } +} + +[Fact] +public async void BatchCancelListTest() +{ + //basic begin + int approveQuantity = 0; + await InitializeForestContract(); + await PrepareNftData(); + + int inputListQuantity1 = 1; + int inputSellPrice1 = 2; + var startTime1 = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)); + + approveQuantity += inputListQuantity1; + await InitListInfo(inputListQuantity1, inputSellPrice1, approveQuantity, NftSymbol, startTime1); + await QueryLastByStartAscListInfo(inputListQuantity1, inputSellPrice1, NftSymbol); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + int inputListQuantity2 = 2; + int inputSellPrice2 = 2; + var startTime2 = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow.AddSeconds(approveQuantity)); + + approveQuantity += inputListQuantity2; + await InitListInfo(inputListQuantity2, inputSellPrice2, approveQuantity, NftSymbol2, startTime2); + await QueryLastByStartAscListInfo(inputListQuantity2, inputSellPrice2, NftSymbol2); + await QueryFirstByStartAscListInfo(inputListQuantity1, inputSellPrice1); + + var batchInput = new BatchCancelListInput() + { + BatchCancelListInfo = new BatchCancelListInfo() + { + CancelList = { new DelistInput() + { + Symbol = NftSymbol, + Quantity = inputListQuantity1, + Price = new Price() + { + Symbol = ElfSymbol, + Amount = inputSellPrice1, + }, + StartTime = startTime1 + },new DelistInput() + { + Symbol = NftSymbol2, + Quantity = inputListQuantity2, + Price = new Price() + { + Symbol = ElfSymbol, + Amount = inputSellPrice2, + }, + StartTime = startTime2 + } } + } + }; + + { + var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol, + Owner = User1Address + })).Value.First(); + listedNftInfo1.ShouldNotBeNull(); + listedNftInfo1.Symbol.ShouldBe(NftSymbol); + + var listedNftInfo2 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol2, + Owner = User1Address + })).Value.First(); + listedNftInfo2.ShouldNotBeNull(); + listedNftInfo2.Symbol.ShouldBe(NftSymbol2); + + } + + { + //batch cancel list + await Seller1ForestContractStub.BatchCancelList.SendAsync(batchInput); + + var listedNftInfo1 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol, + Owner = User1Address + })).Value; + listedNftInfo1.ShouldBeEmpty(); + + var listedNftInfo2 = (await Seller1ForestContractStub.GetListedNFTInfoList.CallAsync( + new GetListedNFTInfoListInput + { + Symbol = NftSymbol2, + Owner = User1Address + })).Value; + listedNftInfo1.ShouldBeEmpty(); + + } +} } \ No newline at end of file