Exemple #1
0
        public void CreateContract_Throws_InvalidMiningGovernance()
        {
            SetupBalance(0);
            SetupBlock(10);

            SetupCall(StakingToken, 0, "get_MiningGovernance", null, TransferResult.Failed());

            this.Invoking(p => p.BlankMiningPool())
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("OPDEX: INVALID_MINING_GOVERNANCE");
        }
        public void Withdraw_Fail_TokenContractAddressTransferFailure()
        {
            CurrentBlock = EndBlock;
            var airdrop = NewAirdrop(Registrant, Owner, CurrentBlock, EndBlock, TotalSupply);

            // Set the initial NumberOfRegistrants to 1
            MockPersistentState.Setup(x => x.GetUInt64(nameof(NumberOfRegistrants))).Returns(1);
            MockPersistentState.Setup(x => x.GetString($"Status:{Registrant}")).Returns(EnrolledStatus);

            // Mock the contract call to return a failure
            MockInternalExecutor.Setup(s =>
                                       s.Call(
                                           It.IsAny <ISmartContractState>(),
                                           It.IsAny <Address>(),
                                           It.IsAny <ulong>(),
                                           "TransferFrom",
                                           It.IsAny <object[]>(),
                                           It.IsAny <ulong>()))
            .Returns(TransferResult.Failed());

            // Contract should fail
            Assert.Throws <SmartContractAssertException>(() => airdrop.Withdraw());

            // Verify the call was made only once
            var amountToDistribute = airdrop.GetAmountToDistribute();
            var transferFromParams = new object[] { Owner, Registrant, amountToDistribute };

            MockInternalExecutor.Verify(s => s
                                        .Call(MockContractState.Object, TokenContractAddress, amountToDistribute, "TransferFrom", transferFromParams, 0), Times.Once);

            // Make sure the status was never changed
            MockPersistentState.Verify(x => x.SetString($"Status:{Registrant}", FundedStatus), Times.Never);

            // Make sure the status update was never logged
            MockContractLogger.Verify(x => x.Log(It.IsAny <ISmartContractState>(), new StatusLog {
                Registrant = Registrant, Status = FundedStatus
            }), Times.Never);
        }
Exemple #3
0
        public void CollectMarketFees_Throws_InvalidTransferTo()
        {
            UInt256 amount = 250;

            var market = CreateNewOpdexStandardMarket(marketFeeEnabled: true);

            State.SetAddress($"{MarketStateKeys.Pool}:{Token}", Pool);

            var transferParams = new object[] { Owner, amount };

            SetupCall(Pool, 0, nameof(IOpdexLiquidityPool.TransferTo), transferParams, TransferResult.Failed());

            SetupMessage(StandardMarket, Owner);

            market
            .Invoking(m => m.CollectMarketFees(Token, amount))
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("OPDEX: INVALID_TRANSFER_TO");
        }
Exemple #4
0
        public void Invest_Fails_If_GetClaim_Call_Fails()
        {
            var amount = 10ul;

            this.mTransactionExecutor.Setup(m => m.Create <StandardToken>(this.mContractState.Object, 0, new object[] { this.totalSupply, this.name, this.symbol }, It.IsAny <ulong>())).Returns(this.createSuccess);
            this.mTransactionExecutor.Setup(m => m.Call(this.mContractState.Object, this.mapperContract, 0, "GetSecondaryAddress", new object[] { this.investor }, It.IsAny <ulong>())).Returns(TransferResult.Transferred(this.identity));
            this.mTransactionExecutor.Setup(m => m.Call(this.mContractState.Object, this.kycContract, 0, "GetClaim", new object[] { this.identity, 3 /*shufti kyc*/ }, It.IsAny <ulong>())).Returns(TransferResult.Failed());
            var(contract, _) = this.Create(TokenType.StandardToken);
            this.mContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.investor, amount));

            Assert.Throws <SmartContractAssertException>(() => contract.Invest());
        }