public void AuctionEnd_Transfer_Token_To_Owner_When_Auction_Ended_Without_Bid_Success()
        {
            SetupMessage(creator, 0);

            var store = new NFTAuctionStore(mContractState.Object);

            SetupBlock(101);

            SetupMessage(tokenOwner, 0);

            SetAuctionInfo(new AuctionInfo { Seller = tokenOwner, EndBlock = 100, StartingPrice = 100 });

            SetupSafeTransferToken(contract, tokenOwner, tokenId, TransferResult.Succeed(true));

            store.AuctionEnd(tokenContract, tokenId);

            store.GetAuctionInfo(tokenContract, tokenId)
                 .Should()
                 .Be(new AuctionInfo {
                    Seller = tokenOwner,
                    OnAuction = true,
                    EndBlock = 100, 
                    StartingPrice = 100,
                 });

            VerifyLog(new AuctionEndSucceedLog { Contract = tokenContract, TokenId = tokenId, HighestBid = 0, HighestBidder = Address.Zero });
        }
        public void OnNonFungibleTokenReceived_Owner_Sell_Token_Success()
        {
            SetupMessage(creator, 0);
            SetupBlock(1);
            var store = new NFTAuctionStore(mContractState.Object);

            SetupMessage(tokenContract, 0);
            SetupGetOwnerOfToken(TransferResult.Succeed(contract));
            
            var parameters = new AuctionParam { StartingPrice = 100, Duration = duration };

            var paramBytes = Array.Empty<byte>();

            mSerializer.Setup(s => s.ToStruct<AuctionParam>(paramBytes)).Returns(parameters);

            store.OnNonFungibleTokenReceived(tokenOwner, tokenOwner, tokenId, paramBytes)
                 .Should()
                 .BeTrue();

            store.GetAuctionInfo(tokenContract, tokenId)
                 .Should()
                 .Be(new AuctionInfo { Seller = tokenOwner, EndBlock = 101, StartingPrice = 100 });

            VerifyLog(new AuctionStartedLog
            {
                Contract = tokenContract,
                TokenId = tokenId,
                startingPrice = 100,
                Seller = tokenOwner,
                EndBlock = 101
            });

        }
        public void AuctionEnd_Refund_Token_Return_False_Fails()
        {
            SetupMessage(creator, 0);

            var store = new NFTAuctionStore(mContractState.Object);

            SetupBlock(101);

            SetupMessage(tokenOwner, 0);

            SetAuctionInfo(new AuctionInfo { Seller = tokenOwner, EndBlock = 100, StartingPrice = 100 });

            SetupSafeTransferToken(contract, tokenOwner, tokenId, TransferResult.Succeed(false));

            store.Invoking(m => m.AuctionEnd(tokenContract, tokenId))
                 .Should()
                 .Throw<SmartContractAssertException>()
                 .WithMessage("The token transfer failed.");
        }
        public void AuctionEnd_Success()
        {
            SetupMessage(creator, 0);

            var store = new NFTAuctionStore(mContractState.Object);

            SetupBlock(101);

            SetupMessage(tokenOwner, 0);

            SetAuctionInfo(new AuctionInfo
            {
                Seller = tokenOwner,
                HighestBid = 100,
                HighestBidder = buyer,
                OnAuction = false,
                EndBlock = 100,
                StartingPrice = 100
            });

            SetupSafeTransferToken(contract, buyer, tokenId, TransferResult.Succeed(true));

            SetupTransfer(tokenOwner, 100, TransferResult.Succeed());

            store.AuctionEnd(tokenContract, tokenId);

            store.GetAuctionInfo(tokenContract, tokenId)
                 .Should()
                 .Be(new AuctionInfo
                 {
                     Seller = tokenOwner,
                     HighestBid = 100,
                     HighestBidder = buyer,
                     OnAuction = true,
                     EndBlock = 100,
                     StartingPrice = 100,
                 });


            VerifyLog(new AuctionEndSucceedLog { Contract = tokenContract, TokenId = tokenId, HighestBid = 100, HighestBidder = buyer });
        }
        public void OnNonFungibleTokenReceived_Selling_Already_OnSale_Token_Fails()
        {
            SetupMessage(creator, 0);
            SetupBlock(1);
            var store = new NFTAuctionStore(mContractState.Object);

            SetupMessage(tokenContract, 0);
            SetupGetOwnerOfToken(TransferResult.Succeed(contract));
            
            var parameters = new AuctionParam { StartingPrice = 100, Duration = duration };

            var paramBytes = Array.Empty<byte>();

            mSerializer.Setup(s => s.ToStruct<AuctionParam>(paramBytes)).Returns(parameters);

            store.OnNonFungibleTokenReceived(tokenOwner, tokenOwner, tokenId, paramBytes);

            store.Invoking(s => s.OnNonFungibleTokenReceived(tokenOwner, tokenOwner, tokenId, paramBytes))
                 .Should()
                 .Throw<SmartContractAssertException>()
                 .WithMessage("The token is already on sale.");
        }