Exemple #1
0
        public void Buy_Token_Buying_Success()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            var saleInfo = new SaleInfo
            {
                Price  = 100,
                Seller = tokenOwner
            };

            SetSaleInfo(saleInfo);

            SetupMessage(buyer, 100);

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

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

            store.Buy(tokenContract, tokenId);

            VerifyLog(new TokenPurchasedLog {
                Contract = tokenContract, TokenId = tokenId, Seller = tokenOwner, Buyer = buyer
            });

            store.GetSaleInfo(tokenContract, tokenId)
            .Should()
            .Be(default(SaleInfo));
        }
Exemple #2
0
        public void CancelSale_Success()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            var saleInfo = new SaleInfo
            {
                Price  = 100,
                Seller = tokenOwner
            };

            SetSaleInfo(saleInfo);

            SetupMessage(tokenOwner, 0);

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

            store.CancelSale(tokenContract, tokenId);

            store.GetSaleInfo(tokenContract, tokenId)
            .Should()
            .Be(default(SaleInfo));

            VerifyLog(new TokenSaleCanceledLog {
                Contract = tokenContract, TokenId = tokenId, Seller = tokenOwner
            });
        }
Exemple #3
0
        public void OnNonFungibleTokenReceived_Operator_Mint_And_Sell_Token_Success()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            SetupMessage(tokenContract, 0);
            SetupGetOwnerOfToken(TransferResult.Succeed(contract));
            var price      = 5_00_000_000ul;
            var priceBytes = BitConverter.GetBytes(price);

            mSerializer.Setup(m => m.ToUInt64(priceBytes)).Returns(price);


            store.OnNonFungibleTokenReceived(operatorAddress, Address.Zero, tokenId, priceBytes)
            .Should()
            .BeTrue();

            store.GetSaleInfo(tokenContract, tokenId)
            .Should()
            .Be(new SaleInfo {
                Price = price, Seller = operatorAddress
            });

            VerifyLog(new TokenOnSaleLog
            {
                Contract = tokenContract,
                TokenId  = tokenId,
                Seller   = operatorAddress,
                Operator = operatorAddress,
                Price    = price
            });
        }
Exemple #4
0
        public void OnNonFungibleTokenReceived_GetOwner_Call_Raise_Exception_Fails()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            SetupGetOwnerOfToken(TransferResult.Failed());
            SetupMessage(tokenContract, 0);
            var price      = 5_00_000_000ul;
            var priceBytes = BitConverter.GetBytes(price);

            mSerializer.Setup(m => m.ToUInt64(priceBytes)).Returns(price);

            store.Invoking(s => s.OnNonFungibleTokenReceived(tokenOwner, tokenOwner, tokenId, priceBytes))
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("OwnerOf method call failed.");
        }
Exemple #5
0
        public void OnNonFungibleTokenReceived_Selling_Already_OnSale_Token_Fails()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            SetupMessage(tokenContract, 0);
            SetupGetOwnerOfToken(TransferResult.Succeed(contract));
            var price      = 5_00_000_000ul;
            var priceBytes = BitConverter.GetBytes(price);

            mSerializer.Setup(m => m.ToUInt64(priceBytes)).Returns(price);

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

            store.Invoking(s => s.OnNonFungibleTokenReceived(tokenOwner, tokenOwner, tokenId, priceBytes))
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("The token is already on sale.");
        }
Exemple #6
0
        public void CancelSale_Called_By_None_Token_Owner_Or_Operator_Fails()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            var saleInfo = new SaleInfo
            {
                Price  = 100,
                Seller = tokenOwner
            };

            SetSaleInfo(saleInfo);

            SetupMessage(attacker, 0);
            SetupIsApprovedForAll(tokenOwner, attacker, TransferResult.Succeed(false));

            store.Invoking(s => s.CancelSale(tokenContract, tokenId))
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("The caller is not owner of the token nor approved for all.");
        }
Exemple #7
0
        public void CancelSale_SafeTokenTransfer_Returns_False_Fails()
        {
            SetupMessage(creator, 0);

            var store = new NFTStore(mContractState.Object);

            var saleInfo = new SaleInfo
            {
                Price  = 100,
                Seller = tokenOwner
            };

            SetSaleInfo(saleInfo);

            SetupMessage(tokenOwner, 0);

            SetupSafeTransferToken(contract, tokenOwner, tokenId, TransferResult.Failed());

            store.Invoking(s => s.CancelSale(tokenContract, tokenId))
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("The token transfer failed.");
        }
Exemple #8
0
 private void SetupIsApprovedForAll(Address owner, Address delegator, TransferResult result)
 {
     mTransactionExecutor.Setup(m => m.Call(mContractState.Object, tokenContract, 0, "IsApprovedForAll", new object[] { owner, delegator }, 0))
     .Returns(result);
 }
Exemple #9
0
 private void SetupGetOwnerOfToken(TransferResult result)
 {
     mTransactionExecutor.Setup(m => m.Call(mContractState.Object, tokenContract, 0, "OwnerOf", new object[] { tokenId }, 0))
     .Returns(result);
 }
Exemple #10
0
 private void SetupTransfer(Address to, ulong amount, TransferResult result)
 {
     mTransactionExecutor.Setup(m => m.Transfer(mContractState.Object, to, amount))
     .Returns(result);
 }
Exemple #11
0
 private void SetupSafeTransferToken(Address from, Address to, UInt256 tokenId, TransferResult result)
 {
     mTransactionExecutor.Setup(m => m.Call(mContractState.Object, tokenContract, 0, "SafeTransferFrom", new object[] { from, to, tokenId }, 0))
     .Returns(result);
 }