Ejemplo n.º 1
0
 public MockStellarTxListenerBase(MockStellarDataProvider dataProvider, List <TxModel> txs, Action <TxModel> onTxCallback)
     : base(onTxCallback)
 {
     this.dataProvider     = dataProvider;
     dataProvider.TxAdded += DataProvider_TxAdded;
     foreach (var tx in txs)
     {
         this.txs.Add(tx);
     }
 }
        public void Setup()
        {
            EnvironmentHelper.SetTestEnvironmentVariable();
            var settings = new AlphaSettings
            {
                CWD = "AppData"
            };
            var stellarProvider = new MockStellarDataProvider(settings.NetworkPassphrase, settings.HorizonUrl);

            context = new AlphaContext(settings, new MongoStorage(), stellarProvider);

            context.Init().Wait();
        }
        /// <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 <ExecutionContext> Setup(List <KeyPair> clients, List <KeyPair> auditors, BaseSettings settings, IStorage storage)
        {
            var stellarProvider = new MockStellarDataProvider(settings.NetworkPassphrase, settings.HorizonUrl);

            var context = settings is AlphaSettings
                ? (ExecutionContext) new AlphaContext((AlphaSettings)settings, storage, stellarProvider)
                : new AuditorContext((AuditorSettings)settings, storage, stellarProvider);

            await context.Init();

            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 (!context.IsAlpha)
            {
                initQuantum.Timestamp = DateTime.UtcNow.Ticks;
            }

            var envelope = initQuantum.CreateEnvelope();

            if (!context.IsAlpha)
            {
                var alphaKeyPair = KeyPair.FromSecretSeed(TestEnvironment.AlphaKeyPair.SecretSeed);
                envelope.Sign(alphaKeyPair);
            }

            await context.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 = context.QuantumStorage.LastQuantumHash,
                Source   = new TxNotification
                {
                    TxCursor = 2,
                    Payments = deposits
                }.CreateEnvelope().Sign(TestEnvironment.Auditor1KeyPair)
            };

            await context.QuantumHandler.HandleAsync(depositQuantum.CreateEnvelope().Sign(TestEnvironment.AlphaKeyPair));

            //save all effects
            await SnapshotHelper.ApplyUpdates(context);

            return(context);
        }
Ejemplo n.º 4
0
 public IntegrationTestEnvironment()
 {
     StellarProvider = new MockStellarDataProvider(NetworkPassphrase, HorizonUrl);
     Reset           = new ManualResetEvent(false);
 }
Ejemplo n.º 5
0
        public void Setup()
        {
            EnvironmentHelper.SetTestEnvironmentVariable();
            var settings = new AlphaSettings
            {
                HorizonUrl        = "https://horizon-testnet.stellar.org",
                NetworkPassphrase = "Test SDF Network ; September 2015",
                CWD = "AppData"
            };

            var stellarProvider = new MockStellarDataProvider(settings.NetworkPassphrase, settings.HorizonUrl);

            context = new AlphaContext(settings, new MockStorage(), stellarProvider, useLegacyOrderbook);
            context.Init().Wait();

            var requestRateLimits = new RequestRateLimits {
                HourLimit = 1000, MinuteLimit = 100
            };

            var account1 = new AccountWrapper(new Models.Account
            {
                Id     = 1,
                Pubkey = new RawPubKey()
                {
                    Data = KeyPair.Random().PublicKey
                },
                Balances = new List <Balance>()
            }, requestRateLimits);

            account1.Account.CreateBalance(0);
            account1.Account.GetBalance(0).UpdateBalance(10000000000);
            account1.Account.CreateBalance(1);
            account1.Account.GetBalance(1).UpdateBalance(10000000000);

            var account2 = new AccountWrapper(new Models.Account
            {
                Id     = 2,
                Pubkey = new RawPubKey()
                {
                    Data = KeyPair.Random().PublicKey
                },
                Balances = new List <Balance>()
            }, requestRateLimits);

            account2.Account.CreateBalance(0);
            account2.Account.GetBalance(0).UpdateBalance(10000000000);
            account2.Account.CreateBalance(1);
            account2.Account.GetBalance(1).UpdateBalance(10000000000);

            context.Setup(new Snapshot
            {
                Accounts = new List <AccountWrapper> {
                    account1, account2
                },
                Apex     = 0,
                TxCursor = 1,
                Orders   = new List <Order>(),
                Settings = new ConstellationSettings
                {
                    Vault  = KeyPair.Random().PublicKey,
                    Assets = new List <AssetSettings> {
                        new AssetSettings {
                            Id = 1, Code = "X", Issuer = new RawPubKey()
                        }
                    },
                    RequestRateLimits = requestRateLimits
                },
            }).Wait();

            this.account1 = context.AccountStorage.GetAccount(account1.Id);
            this.account2 = context.AccountStorage.GetAccount(account2.Id);
        }