public void Execute() { var shopState = _initialState.GetShopState(); Assert.NotEmpty(shopState.Products); var(productId, shopItem) = shopState.Products.FirstOrDefault(); Assert.NotNull(shopItem); var tax = shopItem.Price.DivRem(100, out _) * Buy.TaxRate; var taxedPrice = shopItem.Price - tax; var buyAction = new Buy { buyerAvatarAddress = _buyerAvatarAddress, productId = productId, sellerAgentAddress = _sellerAgentAddress, sellerAvatarAddress = _sellerAvatarAddress, }; var nextState = buyAction.Execute(new ActionContext() { BlockIndex = 0, PreviousStates = _initialState, Random = new TestRandom(), Rehearsal = false, Signer = _buyerAgentAddress, }); var nextShopState = nextState.GetShopState(); Assert.Empty(nextShopState.Products); var nextBuyerAvatarState = nextState.GetAvatarState(_buyerAvatarAddress); Assert.True( nextBuyerAvatarState.inventory.TryGetNonFungibleItem(shopItem.ItemUsable.ItemId, out ItemUsable _)); var goldCurrencyState = nextState.GetGoldCurrency(); var goldCurrencyGold = nextState.GetBalance(Addresses.GoldCurrency, goldCurrencyState); Assert.Equal(tax, goldCurrencyGold); var sellerGold = nextState.GetBalance(_sellerAgentAddress, goldCurrencyState); Assert.Equal(taxedPrice, sellerGold); var buyerGold = nextState.GetBalance(_buyerAgentAddress, goldCurrencyState); Assert.Equal(new FungibleAssetValue(goldCurrencyState, 0, 0), buyerGold); }
private static void ShowCommands() { User miel = new User("Miel"); IGame BoI = new GamePlaceHolder(Constants.TestGame, miel.ID); Buy buyGame = new Buy(BoI); Download downloadGame = new Download(BoI); Install installGame = new Install(BoI); Start startGame = new Start(BoI); Uninstall uninstallGame = new Uninstall(BoI); Update updateGame = new Update(BoI); buyGame.Execute(); Console.ReadLine(); downloadGame.Execute(); Console.ReadLine(); installGame.Execute(); Console.ReadLine(); startGame.Execute(); Console.ReadLine(); uninstallGame.Execute(); Console.ReadLine(); updateGame.Execute(); Console.ReadLine(); CommandContext uniCmd = new CommandContext(buyGame); uniCmd.Execute(); Console.ReadLine(); uniCmd = new CommandContext(downloadGame); uniCmd.Execute(); Console.ReadLine(); uniCmd = new CommandContext(installGame); uniCmd.Execute(); Console.ReadLine(); uniCmd = new CommandContext(startGame); uniCmd.Execute(); Console.ReadLine(); uniCmd = new CommandContext(uninstallGame); uniCmd.Execute(); Console.ReadLine(); uniCmd = new CommandContext(updateGame); uniCmd.Execute(); Console.ReadLine(); }