Beispiel #1
0
 public ICOContractTests()
 {
     this.mContractLogger      = new Mock <IContractLogger>();
     this.mContractState       = new Mock <ISmartContractState>();
     this.mTransactionExecutor = new Mock <IInternalTransactionExecutor>();
     this.persistentState      = new InMemoryState();
     this.network = new Mock <Network>();
     this.mBlock  = new Mock <IBlock>();
     this.mContractState.Setup(s => s.Block).Returns(this.mBlock.Object);
     this.mContractState.Setup(s => s.PersistentState).Returns(this.persistentState);
     this.mContractState.Setup(s => s.ContractLogger).Returns(this.mContractLogger.Object);
     this.mContractState.Setup(s => s.InternalTransactionExecutor).Returns(this.mTransactionExecutor.Object);
     this.serializer = new Serializer(new ContractPrimitiveSerializer(this.network.Object));
     this.mContractState.Setup(s => s.Serializer).Returns(this.serializer);
     this.sender         = "0x0000000000000000000000000000000000000001".HexToAddress();
     this.owner          = "0x0000000000000000000000000000000000000002".HexToAddress();
     this.investor       = "0x0000000000000000000000000000000000000003".HexToAddress();
     this.identity       = "0x0000000000000000000000000000000000000004".HexToAddress();
     this.contract       = "0x0000000000000000000000000000000000000005".HexToAddress();
     this.tokenContract  = "0x0000000000000000000000000000000000000006".HexToAddress();
     this.kycContract    = "0x0000000000000000000000000000000000000007".HexToAddress();
     this.mapperContract = "0x0000000000000000000000000000000000000008".HexToAddress();
     this.createSuccess  = CreateResult.Succeeded(this.tokenContract);
     this.name           = "Test Token";
     this.symbol         = "TST";
     this.totalSupply    = 100 * Satoshis;
     this.persistentState.IsContractResult = true;
 }
Beispiel #2
0
        public void CreateStakingMarket_Success()
        {
            const uint transactionFee = 3;
            var        marketOwner    = Owner;

            var createParams = new object[] { transactionFee, StakingToken };

            SetupCreate <OpdexStakingMarket>(CreateResult.Succeeded(StakingMarket), 0, createParams);

            var createRouterParams = new object[] { StakingMarket, transactionFee, false, false };

            SetupCreate <OpdexRouter>(CreateResult.Succeeded(Router), 0, createRouterParams);

            var deployer = CreateNewOpdexMarketDeployer();

            SetupMessage(Deployer, marketOwner);

            State.SetContract(StakingToken, true);

            var market = deployer.CreateStakingMarket(StakingToken);

            market.Should().Be(StakingMarket);

            VerifyLog(new CreateMarketLog
            {
                Market           = StakingMarket,
                Owner            = marketOwner,
                Router           = Router,
                TransactionFee   = transactionFee,
                StakingToken     = StakingToken,
                MarketFeeEnabled = true
            }, Times.Once);
        }
Beispiel #3
0
        public void CreateStandardMarket_Success(bool authPoolCreators, bool authProviders, bool authTraders, uint fee)
        {
            var marketOwner = Trader0;

            var createParams = new object[] { marketOwner, authPoolCreators, authProviders, authTraders, fee };

            SetupCreate <OpdexStandardMarket>(CreateResult.Succeeded(StandardMarket), 0, createParams);

            var deployer = CreateNewOpdexMarketDeployer();

            SetupMessage(Deployer, Owner);

            var market = deployer.CreateStandardMarket(marketOwner, authPoolCreators, authProviders, authTraders, fee);

            market.Should().Be(StandardMarket);

            VerifyLog(new CreateMarketLog
            {
                Market           = StandardMarket,
                Owner            = marketOwner,
                AuthPoolCreators = authPoolCreators,
                AuthProviders    = authProviders,
                AuthTraders      = authTraders,
                Fee = fee
            }, Times.Once);
        }
Beispiel #4
0
        public void StartGame_Success()
        {
            // Set up create for player vs opponent.
            this.mockInternalExecutor.Setup(s =>
                                            s.Create <Player>(
                                                It.IsAny <ISmartContractState>(),
                                                It.IsAny <ulong>(),
                                                It.Is <object[]>(o =>
                                                                 (Address)o[0] == PlayerAddress &&
                                                                 (Address)o[1] == OpponentAddress),
                                                It.IsAny <ulong>()))
            .Returns(CreateResult.Succeeded(PlayerContractAddress));

            // Set up create for opponent vs player.
            this.mockInternalExecutor.Setup(s =>
                                            s.Create <Player>(
                                                It.IsAny <ISmartContractState>(),
                                                It.IsAny <ulong>(),
                                                It.Is <object[]>(o =>
                                                                 (Address)o[0] == OpponentAddress &&
                                                                 (Address)o[1] == PlayerAddress),
                                                It.IsAny <ulong>()))
            .Returns(CreateResult.Succeeded(OpponentContractAddress));

            var starter = new Starter(this.mockContractState.Object);

            starter.StartGame(PlayerAddress, OpponentAddress, "Test");

            this.mockInternalExecutor.Verify(
                s => s.Create <Player>(
                    this.mockContractState.Object,
                    0,
                    It.Is <object[]>(o =>
                                     (Address)o[0] == PlayerAddress &&
                                     (Address)o[1] == OpponentAddress &&
                                     (string)o[2] == "Test"),
                    0), Times.Once);

            this.mockInternalExecutor.Verify(
                s => s.Create <Player>(
                    this.mockContractState.Object,
                    0,
                    It.Is <object[]>(o =>
                                     (Address)o[0] == OpponentAddress &&
                                     (Address)o[1] == PlayerAddress &&
                                     (string)o[2] == "Test"),
                    0), Times.Once);

            this.mockContractLogger.Verify(
                l => l.Log(
                    It.IsAny <ISmartContractState>(),
                    new Starter.GameCreated
            {
                Player1Contract = PlayerContractAddress,
                Player2Contract = OpponentContractAddress,
                GameName        = "Test"
            }),
                Times.Once);
        }
Beispiel #5
0
        protected IOpdexMarketDeployer CreateNewOpdexMarketDeployer()
        {
            SetupBalance(0);
            SetupBlock(10);
            SetupMessage(Deployer, Owner);

            SetupCreate <OpdexStakingMarket>(CreateResult.Succeeded(StakingMarket), 0ul, new object[] { StakingToken, (uint)3 });

            return(new OpdexMarketDeployer(_mockContractState.Object, StakingToken));
        }
Beispiel #6
0
        protected IOpdexMinedToken CreateNewOpdexToken(byte[] ownerSchedule, byte[] miningSchedule, ulong block = 10)
        {
            _mockContractState.Setup(x => x.Message).Returns(new Message(ODX, Owner, 0));

            SetupBalance(0);
            SetupBlock(block);
            SetupCreate <OpdexMiningGovernance>(CreateResult.Succeeded(MiningGovernance), 0ul, new object[] { ODX, BlocksPerMonth });
            SetupCreate <OpdexVault>(CreateResult.Succeeded(Vault), 0ul, new object[] { ODX, BlocksPerYear, 100ul, 200ul });

            return(new OpdexMinedToken(_mockContractState.Object, "Opdex", "ODX", ownerSchedule, miningSchedule, BlocksPerYear, 100, 200));
        }
Beispiel #7
0
        protected IOpdexStakingPool CreateNewOpdexStakingPool(ulong balance = 0, uint fee = 3)
        {
            SetupBlock(10);
            SetupBalance(balance);
            SetupMessage(Pool, StakingMarket);

            State.SetContract(StakingToken, true);

            SetupCreate <OpdexMiningPool>(CreateResult.Succeeded(MiningPool1), 0ul, new object[] { StakingToken, Pool });

            return(new OpdexStakingPool(_mockContractState.Object, Token, StakingToken, fee));
        }
Beispiel #8
0
        public void CreatesPoolWithStakingToken_Success()
        {
            var market = CreateNewOpdexStakingMarket();

            State.SetContract(Token, true);
            State.SetAddress(nameof(StakingToken), StakingToken);

            SetupCreate <OpdexStakingPool>(CreateResult.Succeeded(Pool), parameters: new object[] { Token, StakingToken, market.Fee });

            var pool = market.CreatePool(Token);

            market.GetPool(Token).Should().Be(pool).And.Be(Pool);

            var expectedPoolCreatedLog = new CreateLiquidityPoolLog {
                Token = Token, Pool = Pool
            };

            VerifyLog(expectedPoolCreatedLog, Times.Once);
        }
Beispiel #9
0
        public void CreatesNewStandardPool_Throws_Unauthorized()
        {
            var unauthorizedUser = Trader0;

            var market = CreateNewOpdexStandardMarket(authPoolCreators: true);

            State.SetContract(Token, true);

            var parameters = new object[] { Token, false, false, market.TransactionFee };

            SetupCreate <OpdexStandardPool>(CreateResult.Succeeded(Pool), parameters: parameters);

            SetupMessage(StandardMarket, unauthorizedUser);

            market
            .Invoking(p => p.CreatePool(Token))
            .Should()
            .Throw <SmartContractAssertException>()
            .WithMessage("OPDEX: UNAUTHORIZED");
        }
        public void ListItem_Success_PartyA_PartyB(string sender, ulong itemPrice)
        {
            var senderAddress      = sender.HexToAddress();
            var newContractAddress = NewContractAddress.HexToAddress();
            var itemName           = "Test";

            var bazaar = this.NewBazaar();

            this.mockContractState.Setup(s => s.Message.Sender).Returns(senderAddress);

            this.mockInternalExecutor.Setup(i => i.Create <ItemListing>(this.mockContractState.Object, 0, It.IsAny <object[]>(), 0)).Returns(CreateResult.Succeeded(newContractAddress));

            bazaar.ListItem("Test", itemPrice);

            this.mockInternalExecutor.Verify(i => i.Create <ItemListing>(this.mockContractState.Object, 0,
                                                                         It.Is <object[]>(o =>
                                                                                          (string)o[0] == itemName &&
                                                                                          (ulong)o[1] == itemPrice &&
                                                                                          (Address)o[2] == senderAddress &&
                                                                                          (Address)o[3] == BazaarContractAddress &&
                                                                                          (Address)o[4] == PartyA &&
                                                                                          (Address)o[5] == PartyB
                                                                                          ),
                                                                         0));

            this.mockPersistentState.Verify(s => s.SetAddress(nameof(Bazaar.CurrentItemListing), newContractAddress));

            this.mockPersistentState.Verify(s => s.SetUInt32(nameof(Bazaar.State), (uint)Bazaar.StateEnum.ItemListed));
        }
Beispiel #11
0
        public void CreateStandardMarket_Success(bool authPoolCreators, bool authProviders, bool authTraders, uint fee, bool enableMarketFee)
        {
            var marketOwner = Trader0;

            var ownerToSet   = authProviders || authTraders ? Deployer : marketOwner;
            var createParams = new object[] { fee, ownerToSet, authPoolCreators, authProviders, authTraders, enableMarketFee };

            SetupCreate <OpdexStandardMarket>(CreateResult.Succeeded(StandardMarket), 0, createParams);

            var createRouterParams = new object[] { StandardMarket, fee, authProviders, authTraders };

            SetupCreate <OpdexRouter>(CreateResult.Succeeded(Router), 0, createRouterParams);

            object[] authProviderParams = null;
            if (authProviders)
            {
                authProviderParams = new object[] { Router, (byte)Permissions.Provide, true };
                SetupCall(StandardMarket, 0, nameof(IOpdexStandardMarket.Authorize), authProviderParams, TransferResult.Transferred(null));
            }

            object[] authTraderParams = null;
            if (authTraders)
            {
                authTraderParams = new object[] { Router, (byte)Permissions.Trade, true };
                SetupCall(StandardMarket, 0, nameof(IOpdexStandardMarket.Authorize), authTraderParams, TransferResult.Transferred(null));
            }

            object[] setOwnerParams = null;
            if (ownerToSet != marketOwner)
            {
                setOwnerParams = new object[] { marketOwner };
                SetupCall(StandardMarket, 0, nameof(IOpdexStandardMarket.SetPendingOwnership), setOwnerParams, TransferResult.Transferred(null));
            }

            var deployer = CreateNewOpdexMarketDeployer();

            SetupMessage(Deployer, Owner);

            var market = deployer.CreateStandardMarket(marketOwner, fee, authPoolCreators, authProviders, authTraders, enableMarketFee);

            market.Should().Be(StandardMarket);

            if (authProviders)
            {
                VerifyCall(StandardMarket, 0, nameof(IOpdexStandardMarket.Authorize), authProviderParams, Times.Once);
            }

            if (authTraders)
            {
                VerifyCall(StandardMarket, 0, nameof(IOpdexStandardMarket.Authorize), authTraderParams, Times.Once);
            }

            if (ownerToSet != marketOwner)
            {
                VerifyCall(StandardMarket, 0, nameof(IOpdexStandardMarket.SetPendingOwnership), setOwnerParams, Times.Once);
            }

            VerifyLog(new CreateMarketLog
            {
                Market           = StandardMarket,
                Owner            = ownerToSet,
                Router           = Router,
                AuthPoolCreators = authPoolCreators,
                AuthProviders    = authProviders,
                AuthTraders      = authTraders,
                TransactionFee   = fee,
                MarketFeeEnabled = enableMarketFee
            }, Times.Once);
        }