Exemplo n.º 1
0
        public HoardExchangeFixture()
        {
            base.Initialize(HoardGameTestName);

            Users = GetUsers();

            RunExchangeServer();

            BCExchangeService = new BCExchangeService(HoardService);
            BCExchangeService.Init().Wait();

            HoardExchangeService = new HoardExchangeService(HoardService);
            HoardExchangeService.Init().Wait();

            try
            {
                GameIDs = HoardService.GetAllHoardGames().Result;
                foreach (var game in GameIDs)
                {
                    HoardService.RegisterHoardGame(game);
                }
            }
            catch (Exception)
            {
                Assert.True(false);
            }

            Items = GetGameItems(Users[0]).Result;
            Assert.Equal(3, Items.Count);
            Assert.True(Items[0].Metadata is ERC223GameItemContract.Metadata);
            Assert.True(Items[1].Metadata is ERC223GameItemContract.Metadata);
            Assert.True(Items[2].Metadata is ERC721GameItemContract.Metadata);
        }
Exemplo n.º 2
0
        public void Initialize(string testName = null)
        {
            Deploy(testName);

            HoardServiceOptions options = new HoardServiceOptions();

            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadFile("settings.ini");

            options.GameCenterContract = data["hoard_game_center"]["contract_addr"];
            Assert.NotEmpty(options.GameCenterContract);

            options.BCClientOptions = new EthereumClientOptions(new Nethereum.JsonRpc.Client.RpcClient(new Uri(string.Format("http://{0}:{1}", data["network"]["host"], data["network"]["port"]))));

            HoardService = HoardService.Instance;

            try
            {
                HoardService.Initialize(options);
            }
            catch (Exception)
            {
                Assert.True(false);
            }

            //authenticate user
            UserIDs.Add(CreateUser().Result);
        }
Exemplo n.º 3
0
        public void RegisterHoardGame()
        {
            hoardFixture.Initialize(HoardGameTestName);
            HoardService = hoardFixture.HoardService;

            GameID[] games = HoardService.GetAllHoardGames().Result;
            Assert.NotEmpty(games);

            GameID gameID = GameID.FromName("12345");

            Assert.DoesNotContain(gameID, games);
            try
            {
                HoardService.RegisterHoardGame(gameID);

                gameID = new GameID(System.Numerics.BigInteger.Parse("2c3257614189ee907c819a4c92b04c6b9e6e9346051563e780d3c302e67e76b1", System.Globalization.NumberStyles.AllowHexSpecifier));
                Assert.Contains(gameID, games);
                HoardService.RegisterHoardGame(gameID);

                HoardService.Shutdown();
            }
            catch (Exception)
            {
                Assert.True(false);
            }
        }
Exemplo n.º 4
0
        public void TestCryptoKittyProvider()
        {
            hoardFixture.InitializeFromConfig();
            HoardService hoard = hoardFixture.HoardService;

            if (hoard.DefaultGame != GameID.kInvalidID)
            {
                ErrorCallbackProvider.ReportInfo("\tName: " + hoard.DefaultGame.Name);
                ErrorCallbackProvider.ReportInfo("\tBackend Url: " + hoard.DefaultGame.Url);
                ErrorCallbackProvider.ReportInfo("\tGameID: " + hoard.DefaultGame.ID);
            }

            //Hoard.PlayerID myId = new PlayerID("0x5d0774af3a8f7656dc61bcf30e383056275911b7","");
            //Assert.True(myId != PlayerID.kInvalidID, "ERROR: Invalid player ID!");
            //ErrorCallbackProvider.ReportInfo(string.Format("Current player is: {0}", myId.ID));

            GameID myGame = GameID.FromName("mygame");

            try
            {
                hoard.RegisterGame(myGame, new CKGameItemProvider(myGame));
                GameItem[] items = hoard.GetPlayerItems(hoardFixture.UserIDs[0], myGame).Result;
                ErrorCallbackProvider.ReportInfo("Shutting down HOARD...");
                hoard.Shutdown();
            }
            catch (Exception)
            {
                Assert.True(false);
            }
        }
Exemplo n.º 5
0
        public async Task <List <GameItem> > GetGameItems(Profile profile)
        {
            var items = new List <GameItem>();

            foreach (var game in GameIDs)
            {
                items.AddRange(await HoardService.GetPlayerItems(profile, game));
            }
            return(items);
        }
Exemplo n.º 6
0
        public HoardServiceTests(HoardServiceFixture _hoardFixture)
        {
            hoardFixture = _hoardFixture;
            hoardFixture.InitializeFromConfig();
            HoardService = hoardFixture.HoardService;

            Assert.True(HoardService.Options.BCClientOptions is PlasmaClientOptions);

            playerProfile = KeyStoreProfileService.CreateProfileDirect("keyStore", "0xea93fd741e8508d4f9a5039761496c31b742001e88b88c260c2a47105e329d37");

            gameID = new GameID(BigInteger.Parse("2c3257614189ee907c819a4c92b04c6b9e6e9346051563e780d3c302e67e76b1", System.Globalization.NumberStyles.AllowHexSpecifier));

            //HoardService.Shutdown();
        }
Exemplo n.º 7
0
        public void InitializeFromConfig(string configPath = null)
        {
            HoardServiceConfig config = HoardServiceConfig.Load(configPath);

            BCClientOptions clientOpts = null;

            if (config.BCClient is EthereumClientConfig)
            {
                var ethConfig = config.BCClient as EthereumClientConfig;
                clientOpts = new EthereumClientOptions(
                    new Nethereum.JsonRpc.Client.RpcClient(new Uri(ethConfig.ClientUrl))
                    );
            }
            else
            {
                var plasmaConfig = config.BCClient as PlasmaClientConfig;

                PlasmaCore.RPC.RpcClient watcherClient    = new PlasmaCore.RPC.RpcClient(new Uri(plasmaConfig.WatcherUrl));
                PlasmaCore.RPC.RpcClient childChainClient = null;
                if (plasmaConfig.ChildChainUrl != null && plasmaConfig.ChildChainUrl != string.Empty)
                {
                    childChainClient = new PlasmaCore.RPC.RpcClient(new Uri(plasmaConfig.ChildChainUrl));
                }

                clientOpts = new PlasmaClientOptions(
                    new Nethereum.JsonRpc.Client.RpcClient(new Uri(plasmaConfig.ClientUrl)),
                    plasmaConfig.RootChainAddress,
                    plasmaConfig.RootChainVersion,
                    watcherClient,
                    childChainClient
                    );
            }

            HoardServiceOptions options = new HoardServiceOptions(config, clientOpts);

            HoardService = HoardService.Instance;

            try
            {
                HoardService.Initialize(options);
            }
            catch (Exception)
            {
                Assert.True(false);
            }

            //authenticate user
            UserIDs.Add(CreateUser().Result);
        }
Exemplo n.º 8
0
        public void TestHoardGames()
        {
            hoardFixture.InitializeFromConfig();
            HoardService = hoardFixture.HoardService;

            //ulong amount = (ulong)HoardService.GetHRDAmount(HoardService.DefaultPlayer);

            if (HoardService.DefaultGame != GameID.kInvalidID)
            {
                ErrorCallbackProvider.ReportInfo("\tName: " + HoardService.DefaultGame.Name);
                ErrorCallbackProvider.ReportInfo("\tBackend Url: " + HoardService.DefaultGame.Url);
                ErrorCallbackProvider.ReportInfo("\tGameID: " + HoardService.DefaultGame.ID);
            }

            ErrorCallbackProvider.ReportInfo("Getting Hoard games...");

            GameID[] games = HoardService.GetAllHoardGames().Result;

            ErrorCallbackProvider.ReportInfo(string.Format("Found {0} Hoard games.", games.Length));

            foreach (GameID game in games)
            {
                //Register hoard provider for this gam
                ErrorCallbackProvider.ReportInfo(string.Format("Registering Hoard game {0}", game.Name));
                HoardService.RegisterHoardGame(game);

                ErrorCallbackProvider.ReportInfo(string.Format("Getting player items for game {0}", game.Name));
                GameItem[] items = HoardService.GetPlayerItems(hoardFixture.UserIDs[0], game).Result;

                ErrorCallbackProvider.ReportInfo(string.Format("Found {0} items.", items.Length));
                foreach (GameItem gi in items)
                {
                    //assume we need to populate properties
                    //TODO: if properties is not null we would need to compare state with some cached data and if there is mismatch update too
                    ErrorCallbackProvider.ReportInfo(string.Format("Getting properties for item {0}:{1}...", gi.Symbol, gi.State));
                    if (gi.Properties == null)
                    {
                        HoardService.FetchItemProperties(gi);
                    }
                    //TODO: enumerate properties...
                }
            }

            // Check exchange
            IExchangeService exchange = HoardService.ExchangeService;

            if (exchange != null)
            {
                var orders = exchange.ListOrders(null, null, null).Result;
                ErrorCallbackProvider.ReportInfo(string.Format("Found {0} exchange orders.", orders.Length));
                foreach (Order order in orders)
                {
                    ErrorCallbackProvider.ReportInfo(string.Format("Order: Buy {0} {1} for {2} {3}.",
                                                                   order.amountGive,
                                                                   order.gameItemGive.Symbol,
                                                                   order.amountGet,
                                                                   order.gameItemGet.Symbol
                                                                   ));
                }
                // test trade:

                /*if (orders.Length > 1)
                 * {
                 *  Order order = orders[0];
                 *  bool result = exchange.Deposit(order.gameItemGet, order.amountGet).Result;
                 *  result = exchange.Trade(order, order.amountGet).Result;
                 *  result = exchange.Withdraw(order.gameItemGive, order.amountGive).Result;
                 * }*/
            }

            ErrorCallbackProvider.ReportInfo("Shutting down HOARD...");

            HoardService.Shutdown();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates new instance of <see cref="HoardExchangeService"/>
 /// </summary>
 /// <param name="hoard">Hoard service</param>
 public HoardExchangeService(HoardService hoard)
 {
     Hoard = hoard;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates new instance of <see cref="BCExchangeService"/>
 /// </summary>
 /// <param name="hoard">Hoard service</param>
 public BCExchangeService(HoardService hoard)
 {
     Hoard  = hoard;
     BCComm = (BC.BCComm)hoard.BCComm;
 }