protected async Task <ResultMessage> AssertQuantumHandling(MessageEnvelope quantum, Type excpectedException = null) { try { var result = await context.QuantumHandler.HandleAsync(quantum); await SnapshotHelper.ApplyUpdates(context); //check that processed quanta is saved to the storage var lastApex = await context.PermanentStorage.GetLastApex(); Assert.AreEqual(context.QuantumStorage.CurrentApex, lastApex); return(result); } catch (Exception exc) { if (excpectedException == null || excpectedException.FullName != exc.GetType().FullName) { throw; } return(null); } }
/// <summary> /// This method inits Global, generates genesis snapshot and adds clients to constellation /// </summary> /// <param name="clients">Clients to add to constellation</param> /// <param name="auditors">Auditors to add to constellation</param> /// <param name="settings">Settings that will be used to init Global</param> public static async Task Setup(List <KeyPair> clients, List <KeyPair> auditors, BaseSettings settings, IStorage storage) { await Global.Setup(settings, storage); var assets = new List <AssetSettings> { new AssetSettings { Id = 1, Code = "X", Issuer = KeyPair.Random() } }; var initQuantum = new ConstellationInitQuantum { Apex = 1, Assets = assets, Auditors = auditors.Select(a => (RawPubKey)a.PublicKey).ToList(), MinAccountBalance = 1, MinAllowedLotSize = 1, Vault = settings is AlphaSettings ? settings.KeyPair.PublicKey : ((AuditorSettings)settings).AlphaKeyPair.PublicKey, PrevHash = new byte[] { }, RequestRateLimits = new RequestRateLimits { HourLimit = 1000, MinuteLimit = 100 } }; if (!Global.IsAlpha) { initQuantum.Timestamp = DateTime.UtcNow.Ticks; } var envelope = initQuantum.CreateEnvelope(); if (!Global.IsAlpha) { var alphaKeyPair = KeyPair.FromSecretSeed(TestEnvironment.AlphaKeyPair.SecretSeed); envelope.Sign(alphaKeyPair); } await Global.QuantumHandler.HandleAsync(envelope); var deposits = new List <PaymentBase>(); Action <byte[], int> addAssetsFn = (acc, asset) => { deposits.Add(new Deposit { Destination = acc, Amount = 10000, Asset = asset, PaymentResult = PaymentResults.Success }); }; for (int i = 0; i < clients.Count; i++) { //add xlm addAssetsFn(clients[i].PublicKey, 0); for (var c = 0; c < assets.Count; c++) { addAssetsFn(clients[i].PublicKey, assets[c].Id); } } var depositQuantum = new TxCommitQuantum { Apex = 2, PrevHash = Global.QuantumStorage.LastQuantumHash, Source = new TxNotification { TxCursor = 2, Payments = deposits }.CreateEnvelope() }; depositQuantum.Source.Sign(TestEnvironment.Auditor1KeyPair); await Global.QuantumHandler.HandleAsync(depositQuantum.CreateEnvelope()); //save all effects await SnapshotHelper.ApplyUpdates(); }