/** * @TODO this should extend file system based tests and resolve tests via autofac container */ public DeltaExecutorTests() { _specProvider = new CatalystSpecProvider(); _stateProvider = new StateProvider(new StateDb(), new StateDb(), LimboLogs.Instance); var storageProvider = new StorageProvider(new StateDb(), _stateProvider, LimboLogs.Instance); IKvm virtualMachine = new KatVirtualMachine(_stateProvider, storageProvider, new StateUpdateHashProvider(), _specProvider, LimboLogs.Instance); var logger = Substitute.For <ILogger>(); logger.IsEnabled(Arg.Any <LogEventLevel>()).Returns(true); _senderPrivateKey = _cryptoContext.GeneratePrivateKey(); _senderPublicKey = _senderPrivateKey.GetPublicKey(); _recipient = _cryptoContext.GeneratePrivateKey().GetPublicKey(); _poorSender = _cryptoContext.GeneratePrivateKey().GetPublicKey(); _stateProvider.CreateAccount(_poorSender.ToKvmAddress(), 0.Kat()); _stateProvider.CreateAccount(_senderPublicKey.ToKvmAddress(), 1000.Kat()); _stateProvider.CreateAccount(Address.Zero, 1000.Kat()); _stateProvider.Commit(_specProvider.GenesisSpec); _executor = new DeltaExecutor(_specProvider, _stateProvider, storageProvider, virtualMachine, new FfiWrapper(), logger); _signingContext = new SigningContext { NetworkType = NetworkType.Devnet, SignatureType = SignatureType.TransactionPublic }; }
public async Task KeyStoreEncryptAsync(IPrivateKey privateKey, NetworkType networkType, KeyRegistryTypes keyIdentifier) { try { var publicKeyHash = _hashProvider.ComputeMultiHash(privateKey.GetPublicKey().Bytes).ToArray() .ToByteString(); var address = new Address { PublicKeyHash = publicKeyHash, AccountType = AccountType.PublicAccount, NetworkType = networkType }; var securePassword = _passwordManager.RetrieveOrPromptPassword(_defaultNodePassword, "Please create a password for this node"); var password = StringFromSecureString(securePassword); var json = EncryptAndGenerateDefaultKeyStoreAsJson( password, _cryptoContext.ExportPrivateKey(privateKey), address.RawBytes.ToBase32()); _passwordManager.AddPasswordToRegistry(_defaultNodePassword, securePassword); await _fileSystem.WriteTextFileToCddSubDirectoryAsync(keyIdentifier.Name, Constants.KeyStoreDataSubDir, json); } catch (Exception e) { _logger.Error(e.Message); } }