public void CreateNonDivisibleToken() { var owner = KeyPair.Generate(); var simulator = new ChainSimulator(owner, 1234); var nexus = simulator.Nexus; var accountChain = nexus.FindChainByName("account"); var symbol = "BLA"; var tokenSupply = UnitConversion.ToBigInteger(100000000, 18); simulator.BeginBlock(); simulator.GenerateToken(owner, symbol, "BlaToken", tokenSupply, 0, TokenFlags.Transferable | TokenFlags.Fungible | TokenFlags.Finite); simulator.MintTokens(owner, symbol, tokenSupply); simulator.EndBlock(); var token = nexus.GetTokenInfo(symbol); var testUser = KeyPair.Generate(); var amount = UnitConversion.ToBigInteger(2, token.Decimals); var oldBalance = nexus.RootChain.GetTokenBalance(symbol, owner.Address); Assert.IsTrue(oldBalance > amount); // Send from Genesis address to test user simulator.BeginBlock(); var tx = simulator.GenerateTransfer(owner, testUser.Address, nexus.RootChain, symbol, amount); simulator.EndBlock(); // verify test user balance var transferBalance = nexus.RootChain.GetTokenBalance(symbol, testUser.Address); Assert.IsTrue(transferBalance == amount); var newBalance = nexus.RootChain.GetTokenBalance(symbol, owner.Address); Assert.IsTrue(transferBalance + newBalance == oldBalance); }
public void TestNachoPurchase() { var owner = KeyPair.Generate(); var simulator = new ChainSimulator(owner, 1234); var tokenSupply = ToBigInteger(69931640.63m, NACHO_TOKEN_DECIMALS); simulator.BeginBlock(); simulator.GenerateToken(owner, NACHO_SYMBOL, NACHO_SYMBOL, Nexus.PlatformName, Hash.FromString(NACHO_SYMBOL), tokenSupply, NACHO_TOKEN_DECIMALS, Fungible | Transferable | Finite | Divisible); simulator.MintTokens(owner, owner.Address, NACHO_SYMBOL, tokenSupply); simulator.EndBlock(); var buyer = KeyPair.Generate(); var receiver = KeyPair.Generate(); var nexus = simulator.Nexus; simulator.BeginBlock(); simulator.GenerateTransfer(owner, buyer.Address, nexus.RootChain, FuelTokenSymbol, 100000000); simulator.MintTokens(owner, owner.Address, FiatTokenSymbol, new BigInteger("1000000000000000000000000000000000000000000000000", 10) * GetUnitValue(FiatTokenDecimals)); //simulator.GenerateTransfer(owner, buyer.Address, nexus.RootChain, Nexus.FiatTokenSymbol, 1000000 * UnitConversion.GetUnitValue(Nexus.FiatTokenDecimals)); simulator.EndBlock(); var ownerFiat = simulator.Nexus.RootChain.GetTokenBalance(Nexus.FiatTokenSymbol, owner.Address); decimal requiredMoney = 0; for (int stage = 0; stage < stageCount; stage++) { for (int milestone = 1; milestone <= milestoneCount; milestone++) { decimal milestoneTokens = stageTokenAmount[stage] * milestone / 10m; milestoneTokens = Math.Round(milestoneTokens, 2, AwayFromZero); decimal milestoneTokensPerUsd = stageTokensPerUsd[stage] * tokenDecreaseFactor[stage]; milestoneTokensPerUsd = Math.Round(milestoneTokensPerUsd, 3, AwayFromZero); requiredMoney += milestoneTokens / milestoneTokensPerUsd; Assert.IsTrue(requiredMoney >= 500, "unexpected order size: not enough for 40% bonus"); requiredMoney = requiredMoney / 1.4m; var bigintMoney = ToBigInteger(requiredMoney, FiatTokenDecimals); simulator.BeginBlock(); simulator.GenerateTransfer(owner, buyer.Address, nexus.RootChain, FiatTokenSymbol, bigintMoney); simulator.EndBlock(); var initialNachos = simulator.Nexus.RootChain.GetTokenBalance(NACHO_SYMBOL, receiver.Address); var initialFiat = simulator.Nexus.RootChain.GetTokenBalance(Nexus.FiatTokenSymbol, receiver.Address); simulator.BeginBlock(); simulator.GenerateCustomTransaction(buyer, ProofOfWork.None, () => ScriptUtils.BeginScript().AllowGas(buyer.Address, Address.Null, 1, 9999) .CallContract("nacho", "BuyInApp", buyer.Address, FiatTokenSymbol, bigintMoney). SpendGas(buyer.Address).EndScript()); simulator.EndBlock(); var finalNachos = simulator.Nexus.RootChain.GetTokenBalance(NACHO_SYMBOL, receiver.Address); var finalFiat = simulator.Nexus.RootChain.GetTokenBalance(Nexus.FiatTokenSymbol, receiver.Address); var milestoneTokensBigInt = ToBigInteger(milestoneTokens, NACHO_TOKEN_DECIMALS); Assert.IsTrue(finalNachos == initialNachos + milestoneTokensBigInt); Assert.IsTrue(finalFiat == initialFiat - bigintMoney); } } }