Browse Source

Testing random operations

PascalCoin 6 years ago
parent
commit
1e16e5cdef

+ 1 - 1
src/gui-classic/UFRMOperationsExplorer.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   {$IFnDEF FPC}
-    Windows, AppEvnts,
+    Windows, AppEvnts, System.Actions,
   {$ELSE}
     LCLIntf, LCLType, LMessages, FileUtil,
   {$ENDIF}

+ 184 - 61
src/gui-classic/UFRMRandomOperations.pas

@@ -29,10 +29,43 @@ uses
   {$ENDIF}
   Classes, SysUtils,  Forms, Controls, Graphics, Dialogs, StdCtrls,
   ExtCtrls, Menus, ActnList, UAccounts, UBlockChain, UNode, UCrypto, UBaseTypes,
-  UWallet, UConst, UTxMultiOperation, UOpTransaction;
+  UWallet, UConst, UTxMultiOperation, UOpTransaction, UThread;
 
 type
 
+  { TRandomGeneratorThread }
+
+  TRandomGeneratorThread = Class(TPCThread)
+  private
+    FLastCall_Error: String;
+    FLastCall_OperationsExecuted: Integer;
+    FLastCall_OperationsFailed: Integer;
+    FLastCall_OperationsTotal: Integer;
+    FOnUpdated: TNotifyEvent;
+    FNeedSanitize : Boolean;
+    FAllowExecute: Boolean;
+    procedure OnBankNewBlock(Sender : TObject);
+  protected
+    FBankNotify : TPCBankNotify;
+    FSourceNode: TNode;
+    FSourceWalletKeys: TWalletKeysExt;
+    FnOperationsCreated : Int64;
+    FnOperationsCreatedFailed : Int64;
+    FnOperationsExecutedOk : Int64;
+    FnCallsToAddNodeTotal : Int64;
+    FnCallsToAddNodeFailed : Int64;
+    procedure BCExecute; override;
+  public
+    Constructor Create(ASourceNode: TNode; ASourceWalletKeys: TWalletKeysExt);
+    Destructor Destroy; override;
+    property LastCall_OperationsTotal : Integer read FLastCall_OperationsTotal;
+    property LastCall_OperationsExecuted : Integer read FLastCall_OperationsExecuted;
+    property LastCall_OperationsFailed : Integer read FLastCall_OperationsFailed;
+    property LastCall_Error : String read FLastCall_Error;
+    property OnUpdated : TNotifyEvent read FOnUpdated write FOnUpdated;
+    property AllowExecute : Boolean read FAllowExecute write FAllowExecute;
+  end;
+
   { TFRMRandomOperations }
 
   TFRMRandomOperations = class(TForm)
@@ -50,16 +83,16 @@ type
   private
     FSourceNode: TNode;
     FSourceWalletKeys: TWalletKeysExt;
-    FStopRandomOperations : Boolean;
-    FIsProcessingRandomOperations : Boolean;
     FBankNotify : TPCBankNotify;
     FCurrOperationsComp : TPCOperationsComp;
+    FRandomGeneratorThread : TRandomGeneratorThread;
     procedure SetSourceNode(AValue: TNode);
     procedure SetSourceWalletKeys(AValue: TWalletKeysExt);
-    procedure DoRandomOperations(max : Integer; operationsComp : TPCOperationsComp);
-    procedure DoProcessRandomOperations;
     procedure NewLog(logTxt : String);
     procedure OnBankNewBlock(Sender : TObject);
+    procedure UpdateRandomGeneratorThread(DestroyOnly : Boolean);
+    procedure OnRandomGeneratoThreadUpdated(Sender : TObject);
+    function IsProcessingRandomOperations : Boolean;
   public
     Property SourceNode : TNode read FSourceNode write SetSourceNode;
     Property SourceWalletKeys : TWalletKeysExt read FSourceWalletKeys write SetSourceWalletKeys;
@@ -83,6 +116,114 @@ implementation
   {$R *.lfm}
 {$ENDIF}
 
+Uses ULog;
+
+{ TRandomGeneratorThread }
+
+procedure TRandomGeneratorThread.OnBankNewBlock(Sender: TObject);
+begin
+  FNeedSanitize := True;
+end;
+
+procedure TRandomGeneratorThread.BCExecute;
+Var nCounter, nTotalRound, iLastSend, i : Integer;
+  operationsComp : TPCOperationsComp;
+  ohtToAdd : TOperationsHashTree;
+  errors : AnsiString;
+  nAddedOperations : Integer;
+begin
+  operationsComp := TPCOperationsComp.Create(Nil);
+  try
+    operationsComp.bank := FSourceNode.Bank;
+    iLastSend := -1;
+    while (Not Terminated) do begin
+      nTotalRound := Random(100);
+      nCounter := 0;
+      if FNeedSanitize then begin
+        FNeedSanitize := False;
+        operationsComp.SanitizeOperations;
+        iLastSend := operationsComp.Count-1;
+        TLog.NewLog(ltdebug,ClassName,Format('Sanitized. Current pending operations %d',[operationsComp.Count]));
+      end;
+      while (nCounter<nTotalRound) And (Not Terminated) And (FAllowExecute) do begin
+        inc(nCounter);
+        //
+        Case Random(30) of
+          0..20 : begin
+            If TRandomGenerateOperation.GenerateOpTransaction(FSourceNode.Bank.SafeBox.CurrentProtocol,operationsComp,FSourceWalletKeys) then inc(FnOperationsCreated)
+            else inc(FnOperationsCreatedFailed);
+          end;
+          21..25 : begin
+            If TRandomGenerateOperation.GenerateOpMultiOperation(FSourceNode.Bank.SafeBox.CurrentProtocol,operationsComp,FSourceWalletKeys) then inc(FnOperationsCreated)
+            else inc(FnOperationsCreatedFailed);
+          end;
+        end;
+      end;
+      if (Not Terminated) And (Not FNeedSanitize) And (FAllowExecute) then begin
+        //
+        ohtToAdd := TOperationsHashTree.Create;
+        Try
+          for i := iLastSend+1 to operationsComp.OperationsHashTree.OperationsCount-1 do begin
+            ohtToAdd.AddOperationToHashTree(operationsComp.Operation[i]);
+          end;
+          errors := '';
+          nAddedOperations := FSourceNode.AddOperations(Nil,ohtToAdd,nil,errors);
+          iLastSend := operationsComp.OperationsHashTree.OperationsCount-1;
+          // Notify info
+          inc(FnCallsToAddNodeTotal);
+          inc(FnOperationsExecutedOk,nAddedOperations);
+          FLastCall_OperationsTotal:=ohtToAdd.OperationsCount;
+          FLastCall_OperationsExecuted:=nAddedOperations;
+          FLastCall_OperationsFailed:=ohtToAdd.OperationsCount - nAddedOperations;
+          FLastCall_Error:=errors;
+          if (ohtToAdd.OperationsCount <> nAddedOperations) then begin
+            inc(FnOperationsCreatedFailed,(ohtToAdd.OperationsCount - nAddedOperations));
+            inc(FnCallsToAddNodeFailed,1);
+          end;
+        Finally
+          ohtToAdd.Free;
+        End;
+        //
+        if Assigned(FOnUpdated) then FOnUpdated(Self);
+      end;
+      Sleep(1);
+    end;
+  finally
+    operationsComp.Free;
+  end;
+end;
+
+constructor TRandomGeneratorThread.Create(ASourceNode: TNode; ASourceWalletKeys: TWalletKeysExt);
+begin
+  FSourceNode := ASourceNode;
+  FSourceWalletKeys := ASourceWalletKeys;
+  FnOperationsCreated := 0;
+  FnOperationsCreatedFailed := 0;
+  FnOperationsExecutedOk := 0;
+  FnCallsToAddNodeTotal := 0;
+  FnCallsToAddNodeFailed := 0;
+  FLastCall_Error:='';
+  FLastCall_OperationsFailed:=0;
+  FLastCall_OperationsExecuted:=0;
+  FLastCall_OperationsTotal:=0;
+  //FOperationsComp := TPCOperationsComp.Create(Nil);
+  //FOperationsComp.bank := FSourceNode.Bank;
+  FBankNotify := TPCBankNotify.Create(Nil);
+  FBankNotify.Bank := FSourceNode.Bank;
+  FBankNotify.OnNewBlock:=OnBankNewBlock;
+  FNeedSanitize := True;
+  FAllowExecute := False;
+  inherited Create(False);
+end;
+
+destructor TRandomGeneratorThread.Destroy;
+begin
+  FBankNotify.Bank := Nil;
+  FBankNotify.OnNewBlock := Nil;
+  FBankNotify.Free;
+  inherited Destroy;
+end;
+
 { TRandomGenerateOperation }
 
 class function TRandomGenerateOperation.GetRandomSigner(const operationsComp: TPCOperationsComp; const aWalletKeys: TWalletKeysExt; out iKey: Integer; out nAccount: Cardinal): Boolean;
@@ -255,16 +396,16 @@ procedure TFRMRandomOperations.FormCreate(Sender: TObject);
 begin
   FSourceNode := Nil;
   FSourceWalletKeys := Nil;
-  FIsProcessingRandomOperations := False;
-  FStopRandomOperations := True;
   FBankNotify := TPCBankNotify.Create(Nil);
   FBankNotify.OnNewBlock:=OnBankNewBlock;
   FCurrOperationsComp := TPCOperationsComp.Create(Nil);
+  FRandomGeneratorThread := Nil;
   mLogs.Clear;
 end;
 
 procedure TFRMRandomOperations.FormDestroy(Sender: TObject);
 begin
+  UpdateRandomGeneratorThread(True);
   FreeAndNil(FBankNotify);
   FreeAndNil(FCurrOperationsComp);
 end;
@@ -272,10 +413,14 @@ end;
 procedure TFRMRandomOperations.bbRandomOperationsClick(Sender: TObject);
 begin
   {$IFDEF TESTNET}
-  If FIsProcessingRandomOperations then begin
-    FStopRandomOperations := True;
+  If IsProcessingRandomOperations then begin
+    FRandomGeneratorThread.AllowExecute := False;
+    bbRandomOperations.Caption:='GENERATE RANDOM';
   end else begin
-    DoProcessRandomOperations;
+    if Assigned(FRandomGeneratorThread) then begin
+      FRandomGeneratorThread.AllowExecute := True;
+      bbRandomOperations.Caption:='STOP RANDOM';
+    end else bbRandomOperations.Caption:='???';
   end;
   {$ELSE}
   Raise Exception.Create('Random operations not valid in PRODUCTION MODE');
@@ -284,13 +429,11 @@ end;
 
 procedure TFRMRandomOperations.FormClose(Sender: TObject; var CloseAction: TCloseAction);
 begin
-  FStopRandomOperations := True;
   CloseAction := caFree;
 end;
 
 procedure TFRMRandomOperations.FormCloseQuery(Sender: TObject; var CanClose: boolean);
 begin
-  FStopRandomOperations := True;
   CanClose := True;
 end;
 
@@ -299,78 +442,58 @@ begin
   if FSourceNode=AValue then Exit;
   FBankNotify.Bank := Nil;
   FSourceNode:=AValue;
+
   If Assigned(AValue) then begin
     FBankNotify.Bank := AValue.Bank;
     FCurrOperationsComp.bank := AValue.Bank;
   end;
+  UpdateRandomGeneratorThread(False);
 end;
 
 procedure TFRMRandomOperations.SetSourceWalletKeys(AValue: TWalletKeysExt);
 begin
   if FSourceWalletKeys=AValue then Exit;
   FSourceWalletKeys:=AValue;
+  UpdateRandomGeneratorThread(False);
 end;
 
-procedure TFRMRandomOperations.DoRandomOperations(max: Integer; operationsComp : TPCOperationsComp);
-Var
-  nCounter : Integer;
+procedure TFRMRandomOperations.NewLog(logTxt: String);
 begin
-  nCounter := 0;
-  While (nCounter<max) And (Not FStopRandomOperations) do begin
-    Case Random(30) of
-      0..20 : begin
-        If TRandomGenerateOperation.GenerateOpTransaction(SourceNode.Bank.SafeBox.CurrentProtocol,operationsComp,FSourceWalletKeys) then inc(nCounter);
-      end;
-      21..25 : begin
-        If TRandomGenerateOperation.GenerateOpMultiOperation(SourceNode.Bank.SafeBox.CurrentProtocol,operationsComp,FSourceWalletKeys) then inc(nCounter);
-      end;
-    else Sleep(10);
-    end;
-    Application.ProcessMessages;
-  end;
+  if length(logTxt)>300 then logTxt := Copy(logTxt,1,300)+'...';
+  
+  mLogs.Lines.Add(Format('%s %s',[FormatDateTime('hh:nn:ss.zzz',Now),logTxt]));
 end;
 
-procedure TFRMRandomOperations.DoProcessRandomOperations;
-Var errors : AnsiString;
-  i : Integer;
+procedure TFRMRandomOperations.OnBankNewBlock(Sender: TObject);
 begin
-  newLog('Start Random');
-  Try
-    FCurrOperationsComp.Clear(True);
-    FStopRandomOperations:=False;
-    FIsProcessingRandomOperations:=True;
-    Try
-      bbRandomOperations.Caption:='STOP';
-      Application.ProcessMessages;
-      While (FIsProcessingRandomOperations) And (Not FStopRandomOperations) do begin
-        //
-        FCurrOperationsComp.Clear(True);
-        FCurrOperationsComp.SafeBoxTransaction.CopyFrom(FSourceNode.Operations.SafeBoxTransaction);
-        //
-        DoRandomOperations(Random(50),FCurrOperationsComp);
-        i := FSourceNode.AddOperations(Nil,FCurrOperationsComp.OperationsHashTree,nil,errors);
-        //
-        newLog(Format('Added %d/%d operations - Errors: %s',[i,FCurrOperationsComp.Count, errors]));
-        Application.ProcessMessages;
-      end;
-    finally
-      FIsProcessingRandomOperations := False;
-      bbRandomOperations.Caption:='Random Operations';
-    end;
-  finally
-    newLog('End Random');
+  NewLog(Format('Updating to new block %d',[FBankNotify.Bank.BlocksCount]));
+  FCurrOperationsComp.SanitizeOperations;
+end;
+
+procedure TFRMRandomOperations.UpdateRandomGeneratorThread(DestroyOnly : Boolean);
+begin
+  if Assigned(FRandomGeneratorThread) then begin
+    FRandomGeneratorThread.AllowExecute:=False;
+    FRandomGeneratorThread.Terminate;
+    FRandomGeneratorThread.WaitFor;
+    FreeAndNil(FRandomGeneratorThread);
+  end;
+  if (Not DestroyOnly) And Assigned(FSourceNode) And Assigned(FSourceWalletKeys) then begin
+    FRandomGeneratorThread := TRandomGeneratorThread.Create(FSourceNode,FSourceWalletKeys);
+    FRandomGeneratorThread.OnUpdated:=OnRandomGeneratoThreadUpdated;
   end;
 end;
 
-procedure TFRMRandomOperations.NewLog(logTxt: String);
+procedure TFRMRandomOperations.OnRandomGeneratoThreadUpdated(Sender: TObject);
+Var RGT : TRandomGeneratorThread;
 begin
-  mLogs.Lines.Add(Format('%s %s',[FormatDateTime('hh:nn:ss.zzz',Now),logTxt]));
+  RGT := TRandomGeneratorThread(Sender);
+  NewLog(Format('Generated %d Operations-> Ok:%d Failed:%d Errors:%s',[RGT.LastCall_OperationsTotal,RGT.LastCall_OperationsExecuted,RGT.LastCall_OperationsFailed,RGT.LastCall_Error]));
 end;
 
-procedure TFRMRandomOperations.OnBankNewBlock(Sender: TObject);
+function TFRMRandomOperations.IsProcessingRandomOperations: Boolean;
 begin
-  NewLog(Format('Updating to new block %d',[FBankNotify.Bank.BlocksCount]));
-  FCurrOperationsComp.SanitizeOperations;
+  Result := Assigned(FRandomGeneratorThread) And (FRandomGeneratorThread.AllowExecute);
 end;
 
 end.

+ 0 - 36
src/gui-classic/UFRMWallet.dfm

@@ -421,10 +421,6 @@ object FRMWallet: TFRMWallet
     OnChange = PageControlChange
     object tsMyAccounts: TTabSheet
       Caption = 'Account Explorer'
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       object Splitter1: TSplitter
         Left = 400
         Top = 66
@@ -662,10 +658,6 @@ object FRMWallet: TFRMWallet
         TabOrder = 2
         object tsAccountOperations: TTabSheet
           Caption = 'Operations of selected Account'
-          ExplicitLeft = 0
-          ExplicitTop = 0
-          ExplicitWidth = 0
-          ExplicitHeight = 0
           object dgAccountOperations: TDrawGrid
             Left = 0
             Top = 0
@@ -679,10 +671,6 @@ object FRMWallet: TFRMWallet
         object tsMultiSelectAccounts: TTabSheet
           Caption = 'Selected accounts for massive operations'
           ImageIndex = 1
-          ExplicitLeft = 0
-          ExplicitTop = 0
-          ExplicitWidth = 0
-          ExplicitHeight = 0
           object dgSelectedAccounts: TDrawGrid
             Left = 41
             Top = 31
@@ -874,10 +862,6 @@ object FRMWallet: TFRMWallet
     object tsPendingOperations: TTabSheet
       Caption = 'Pending Operations'
       ImageIndex = 5
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       object dgPendingOperations: TDrawGrid
         Left = 0
         Top = 86
@@ -924,10 +908,6 @@ object FRMWallet: TFRMWallet
     object tsBlockChain: TTabSheet
       Caption = 'Block Explorer'
       ImageIndex = 1
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       object Panel2: TPanel
         Left = 0
         Top = 0
@@ -1020,10 +1000,6 @@ object FRMWallet: TFRMWallet
     object tsOperations: TTabSheet
       Caption = 'Operations Explorer'
       ImageIndex = 1
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       object Panel1: TPanel
         Left = 0
         Top = 0
@@ -1072,10 +1048,6 @@ object FRMWallet: TFRMWallet
     object tsLogs: TTabSheet
       Caption = 'Logs'
       ImageIndex = 2
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       object pnlTopLogs: TPanel
         Left = 0
         Top = 0
@@ -1107,10 +1079,6 @@ object FRMWallet: TFRMWallet
     object tsNodeStats: TTabSheet
       Caption = 'Node Stats'
       ImageIndex = 3
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       DesignSize = (
         857
         438)
@@ -1180,10 +1148,6 @@ object FRMWallet: TFRMWallet
     object tsMessages: TTabSheet
       Caption = 'Messages'
       ImageIndex = 6
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
       DesignSize = (
         857
         438)

+ 77 - 78
src/gui-classic/UFRMWallet.lfm

@@ -1,6 +1,6 @@
 object FRMWallet: TFRMWallet
   Left = 389
-  Height = 580
+  Height = 600
   Top = 201
   Width = 865
   Caption = 'Pascal Coin Wallet, JSON-RPC Miner & Explorer'
@@ -16,7 +16,7 @@ object FRMWallet: TFRMWallet
   OnCreate = FormCreate
   OnDestroy = FormDestroy
   Position = poOwnerFormCenter
-  Visible = False
+  LCLVersion = '1.8.0.6'
   object pnlTop: TPanel
     Left = 0
     Height = 91
@@ -168,7 +168,7 @@ object FRMWallet: TFRMWallet
       Left = 90
       Height = 13
       Top = 11
-      Width = 70
+      Width = 60
       Caption = 'Total Blocks:'
       ParentColor = False
     end
@@ -176,7 +176,7 @@ object FRMWallet: TFRMWallet
       Left = 166
       Height = 13
       Top = 11
-      Width = 21
+      Width = 18
       Caption = '000'
       ParentColor = False
     end
@@ -184,7 +184,7 @@ object FRMWallet: TFRMWallet
       Left = 90
       Height = 13
       Top = 26
-      Width = 107
+      Width = 90
       Caption = 'Current Block Age:'
       ParentColor = False
     end
@@ -192,7 +192,7 @@ object FRMWallet: TFRMWallet
       Left = 198
       Height = 13
       Top = 26
-      Width = 96
+      Width = 81
       Caption = '000 seconds ago'
       ParentColor = False
     end
@@ -200,7 +200,7 @@ object FRMWallet: TFRMWallet
       Left = 90
       Height = 13
       Top = 41
-      Width = 115
+      Width = 98
       Caption = 'Pending Operations:'
       ParentColor = False
     end
@@ -208,7 +208,7 @@ object FRMWallet: TFRMWallet
       Left = 207
       Height = 13
       Top = 41
-      Width = 21
+      Width = 18
       Caption = '000'
       ParentColor = False
     end
@@ -216,7 +216,7 @@ object FRMWallet: TFRMWallet
       Left = 90
       Height = 13
       Top = 56
-      Width = 77
+      Width = 65
       Caption = 'Miner Clients:'
       ParentColor = False
     end
@@ -224,7 +224,7 @@ object FRMWallet: TFRMWallet
       Left = 177
       Height = 13
       Top = 56
-      Width = 21
+      Width = 18
       Caption = '000'
       ParentColor = False
     end
@@ -232,7 +232,7 @@ object FRMWallet: TFRMWallet
       Left = 429
       Height = 13
       Top = 11
-      Width = 86
+      Width = 76
       Caption = 'Current Target:'
       ParentColor = False
     end
@@ -240,7 +240,7 @@ object FRMWallet: TFRMWallet
       Left = 518
       Height = 13
       Top = 11
-      Width = 21
+      Width = 18
       Caption = '000'
       ParentColor = False
     end
@@ -248,7 +248,7 @@ object FRMWallet: TFRMWallet
       Left = 370
       Height = 13
       Top = 26
-      Width = 21
+      Width = 18
       Caption = '000'
       ParentColor = False
     end
@@ -256,7 +256,7 @@ object FRMWallet: TFRMWallet
       Left = 285
       Height = 13
       Top = 26
-      Width = 83
+      Width = 69
       Caption = 'Time average:'
       ParentColor = False
     end
@@ -264,7 +264,7 @@ object FRMWallet: TFRMWallet
       Left = 90
       Height = 13
       Top = 70
-      Width = 72
+      Width = 63
       Caption = 'Node Status:'
       ParentColor = False
     end
@@ -272,7 +272,7 @@ object FRMWallet: TFRMWallet
       Left = 168
       Height = 13
       Top = 70
-      Width = 18
+      Width = 15
       Caption = '???'
       ParentColor = False
     end
@@ -280,7 +280,7 @@ object FRMWallet: TFRMWallet
       Left = 285
       Height = 13
       Top = 11
-      Width = 55
+      Width = 48
       Caption = 'Accounts:'
       ParentColor = False
     end
@@ -288,7 +288,7 @@ object FRMWallet: TFRMWallet
       Left = 344
       Height = 13
       Top = 11
-      Width = 21
+      Width = 18
       Caption = '000'
       ParentColor = False
     end
@@ -296,7 +296,7 @@ object FRMWallet: TFRMWallet
       Left = 370
       Height = 13
       Top = 41
-      Width = 21
+      Width = 18
       Caption = '000'
       Font.Color = clGray
       Font.Height = -11
@@ -308,7 +308,7 @@ object FRMWallet: TFRMWallet
       Left = 360
       Height = 13
       Top = 56
-      Width = 89
+      Width = 76
       Caption = 'Blocks Found:'
       Font.Color = clWindowText
       Font.Height = -11
@@ -322,7 +322,7 @@ object FRMWallet: TFRMWallet
       Height = 13
       Hint = 'Blocks found while Miner is running...'
       Top = 56
-      Width = 24
+      Width = 21
       Caption = '000'
       Font.Color = clWindowText
       Font.Height = -11
@@ -336,9 +336,9 @@ object FRMWallet: TFRMWallet
     object lblReceivedMessages: TLabel
       Cursor = crHandPoint
       Left = 360
-      Height = 22
+      Height = 23
       Top = 66
-      Width = 210
+      Width = 184
       Caption = 'Received Messages'
       Font.Color = clRed
       Font.Height = -19
@@ -350,9 +350,9 @@ object FRMWallet: TFRMWallet
     end
     object lblBuild: TLabel
       Left = 586
-      Height = 22
+      Height = 23
       Top = 3
-      Width = 56
+      Width = 49
       Caption = 'Build'
       Font.Color = clWindowText
       Font.Height = -19
@@ -364,8 +364,8 @@ object FRMWallet: TFRMWallet
   end
   object StatusBar: TStatusBar
     Left = 0
-    Height = 21
-    Top = 559
+    Height = 23
+    Top = 557
     Width = 865
     Panels = <    
       item
@@ -385,7 +385,7 @@ object FRMWallet: TFRMWallet
   end
   object PageControl: TPageControl
     Left = 0
-    Height = 468
+    Height = 466
     Top = 91
     Width = 865
     ActivePage = tsMyAccounts
@@ -395,11 +395,11 @@ object FRMWallet: TFRMWallet
     OnChange = PageControlChange
     object tsMyAccounts: TTabSheet
       Caption = 'Account Explorer'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       object Splitter1: TSplitter
-        Left = 410
-        Height = 375
+        Left = 400
+        Height = 374
         Top = 66
         Width = 5
       end
@@ -407,42 +407,42 @@ object FRMWallet: TFRMWallet
         Left = 0
         Height = 66
         Top = 0
-        Width = 861
+        Width = 857
         Align = alTop
         BevelOuter = bvNone
         ClientHeight = 66
-        ClientWidth = 861
+        ClientWidth = 857
         TabOrder = 0
         object Label18: TLabel
           Left = 11
           Height = 13
           Top = 35
-          Width = 70
+          Width = 61
           Caption = 'Find account'
           ParentColor = False
         end
         object cbMyPrivateKeys: TComboBox
           Left = 260
-          Height = 31
+          Height = 21
           Top = 7
           Width = 411
-          ItemHeight = 0
+          ItemHeight = 13
           OnChange = cbMyPrivateKeysChange
           Style = csDropDownList
           TabOrder = 0
         end
         object cbExploreMyAccounts: TCheckBox
           Left = 11
-          Height = 24
+          Height = 19
           Top = 10
-          Width = 329
+          Width = 235
           Caption = 'Explore accounts with one of my Wallet Keys'
           OnClick = cbExploreMyAccountsClick
           TabOrder = 1
         end
         object ebFindAccountNumber: TEdit
           Left = 87
-          Height = 23
+          Height = 21
           Top = 33
           Width = 83
           OnChange = ebFindAccountNumberChange
@@ -460,16 +460,16 @@ object FRMWallet: TFRMWallet
         end
         object cbFilterAccounts: TCheckBox
           Left = 260
-          Height = 24
+          Height = 19
           Top = 35
-          Width = 202
+          Width = 145
           Caption = 'Filter accounts by balance'
           OnClick = cbFilterAccountsClick
           TabOrder = 4
         end
         object ebFilterAccountByBalanceMin: TEdit
           Left = 412
-          Height = 23
+          Height = 21
           Hint = 'Min balance'
           Top = 33
           Width = 83
@@ -479,7 +479,7 @@ object FRMWallet: TFRMWallet
         end
         object ebFilterAccountByBalanceMax: TEdit
           Left = 503
-          Height = 23
+          Height = 21
           Hint = 'Max balance'
           Top = 33
           Width = 83
@@ -525,19 +525,19 @@ object FRMWallet: TFRMWallet
       end
       object pnlAccounts: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 66
-        Width = 410
+        Width = 400
         Align = alLeft
         BevelOuter = bvNone
-        ClientHeight = 375
-        ClientWidth = 410
+        ClientHeight = 374
+        ClientWidth = 400
         TabOrder = 1
         object dgAccounts: TDrawGrid
           Left = 0
-          Height = 341
+          Height = 340
           Top = 0
-          Width = 410
+          Width = 400
           Align = alClient
           ExtendedSelect = False
           TabOrder = 0
@@ -549,18 +549,18 @@ object FRMWallet: TFRMWallet
         object pnlAccountsInfo: TPanel
           Left = 0
           Height = 34
-          Top = 341
-          Width = 410
+          Top = 340
+          Width = 400
           Align = alBottom
           BevelOuter = bvNone
           ClientHeight = 34
-          ClientWidth = 410
+          ClientWidth = 400
           TabOrder = 1
           object Label17: TLabel
             Left = 5
             Height = 13
             Top = 10
-            Width = 55
+            Width = 48
             Caption = 'Accounts:'
             ParentColor = False
           end
@@ -568,7 +568,7 @@ object FRMWallet: TFRMWallet
             Left = 136
             Height = 13
             Top = 10
-            Width = 49
+            Width = 41
             Caption = 'Balance:'
             ParentColor = False
           end
@@ -576,7 +576,7 @@ object FRMWallet: TFRMWallet
             Left = 60
             Height = 13
             Top = 10
-            Width = 21
+            Width = 18
             Caption = '000'
             ParentColor = False
           end
@@ -584,12 +584,12 @@ object FRMWallet: TFRMWallet
             Left = 200
             Height = 13
             Top = 10
-            Width = 21
+            Width = 18
             Caption = '000'
             ParentColor = False
           end
           object bbAccountsRefresh: TBitBtn
-            Left = 332
+            Left = 322
             Height = 25
             Top = 6
             Width = 75
@@ -629,10 +629,10 @@ object FRMWallet: TFRMWallet
         end
       end
       object pcAccountsOptions: TPageControl
-        Left = 415
-        Height = 375
+        Left = 405
+        Height = 374
         Top = 66
-        Width = 446
+        Width = 452
         ActivePage = tsAccountOperations
         Align = alClient
         TabIndex = 0
@@ -640,12 +640,12 @@ object FRMWallet: TFRMWallet
         object tsAccountOperations: TTabSheet
           Caption = 'Operations of selected Account'
           ClientHeight = 348
-          ClientWidth = 442
+          ClientWidth = 444
           object dgAccountOperations: TDrawGrid
             Left = 0
             Height = 348
             Top = 0
-            Width = 442
+            Width = 444
             Align = alClient
             ExtendedSelect = False
             TabOrder = 0
@@ -658,7 +658,7 @@ object FRMWallet: TFRMWallet
         object tsMultiSelectAccounts: TTabSheet
           Caption = 'Selected accounts for massive operations'
           ClientHeight = 348
-          ClientWidth = 442
+          ClientWidth = 444
           ImageIndex = 1
           object dgSelectedAccounts: TDrawGrid
             Left = 41
@@ -855,8 +855,8 @@ object FRMWallet: TFRMWallet
     end
     object tsPendingOperations: TTabSheet
       Caption = 'Pending Operations'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       ImageIndex = 5
       object dgPendingOperations: TDrawGrid
         Left = 0
@@ -901,8 +901,8 @@ object FRMWallet: TFRMWallet
     end
     object tsBlockChain: TTabSheet
       Caption = 'Block Explorer'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       ImageIndex = 1
       object Panel2: TPanel
         Left = 0
@@ -970,7 +970,7 @@ object FRMWallet: TFRMWallet
           Height = 21
           Top = 7
           Width = 56
-          ItemHeight = 0
+          ItemHeight = 13
           ItemIndex = 1
           Items.Strings = (
             'Kh/s'
@@ -1000,8 +1000,8 @@ object FRMWallet: TFRMWallet
     end
     object tsOperations: TTabSheet
       Caption = 'Operations Explorer'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       ImageIndex = 1
       object Panel1: TPanel
         Left = 0
@@ -1055,8 +1055,8 @@ object FRMWallet: TFRMWallet
     end
     object tsLogs: TTabSheet
       Caption = 'Logs'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       ImageIndex = 2
       object pnlTopLogs: TPanel
         Left = 0
@@ -1090,8 +1090,8 @@ object FRMWallet: TFRMWallet
     end
     object tsNodeStats: TTabSheet
       Caption = 'Node Stats'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       ImageIndex = 3
       object Label3: TLabel
         Left = 15
@@ -1155,8 +1155,8 @@ object FRMWallet: TFRMWallet
     end
     object tsMessages: TTabSheet
       Caption = 'Messages'
-      ClientHeight = 441
-      ClientWidth = 861
+      ClientHeight = 440
+      ClientWidth = 857
       ImageIndex = 6
       object Label11: TLabel
         Left = 15
@@ -1203,7 +1203,6 @@ object FRMWallet: TFRMWallet
         MultiSelect = True
         ScrollWidth = 273
         TabOrder = 0
-        TopIndex = -1
       end
       object bbSendAMessage: TButton
         Left = 315

+ 37 - 5
src/gui-classic/UFRMWallet.pas

@@ -237,11 +237,14 @@ type
     Procedure FinishedLoadingApp;
     Procedure FillAccountInformation(Const Strings : TStrings; Const AccountNumber : Cardinal);
     Procedure FillOperationInformation(Const Strings : TStrings; Const OperationResume : TOperationResume);
-    {$IFDEF TESTING_NO_POW_CHECK}
+    {$IFDEF TESTNET}
     Procedure InitMenuForTesting;
+    Procedure Test_RandomOperations(Sender: TObject);
+    {$IFDEF TESTING_NO_POW_CHECK}
     Procedure Test_CreateABlock(Sender: TObject);
-    Procedure Test_ShowPublicKeys(Sender: TObject);
     {$ENDIF}
+    {$ENDIF}
+    Procedure Test_ShowPublicKeys(Sender: TObject);
   protected
     { Private declarations }
     FNode : TNode;
@@ -316,6 +319,9 @@ implementation
 Uses UFolderHelper, UOpenSSL, UOpenSSLdef, UTime, UFileStorage,
   UThread, UOpTransaction, UECIES, UFRMPascalCoinWalletConfig,
   UFRMOperationsExplorer,
+  {$IFDEF TESTNET}
+  UFRMRandomOperations,
+  {$ENDIF}
   UFRMAbout, UFRMOperation, UFRMWalletKeys, UFRMPayloadDecoder, UFRMNodesIp, UFRMMemoText,
   USettings, UCommon;
 
@@ -911,23 +917,30 @@ begin
   end;
 end;
 
-{$IFDEF TESTING_NO_POW_CHECK}
+{$IFDEF TESTNET}
 procedure TFRMWallet.InitMenuForTesting;
 var mi : TMenuItem;
 begin
   mi := TMenuItem.Create(MainMenu);
   mi.Caption:='-';
   miAbout.Add(mi);
+  {$IFDEF TESTING_NO_POW_CHECK}
   mi := TMenuItem.Create(MainMenu);
   mi.Caption:='Create a block';
   mi.OnClick:=Test_CreateABlock;
   miAbout.Add(mi);
+  {$ENDIF}
   mi := TMenuItem.Create(MainMenu);
   mi.Caption:='Show public keys state';
   mi.OnClick:=Test_ShowPublicKeys;
   miAbout.Add(mi);
+  mi := TMenuItem.Create(MainMenu);
+  mi.Caption:='Create Random operations';
+  mi.OnClick:=Test_RandomOperations;
+  miAbout.Add(mi);
 end;
 
+{$IFDEF TESTING_NO_POW_CHECK}
 procedure TFRMWallet.Test_CreateABlock(Sender: TObject);
 var ops : TPCOperationsComp;
   nba : TBlockAccount;
@@ -949,6 +962,21 @@ begin
   Raise Exception.Create('NOT ALLOWED!');
   {$ENDIF}
 end;
+{$ENDIF}
+
+procedure TFRMWallet.Test_RandomOperations(Sender: TObject);
+Var FRM : TFRMRandomOperations;
+begin
+  FRM := TFRMRandomOperations.Create(Self);
+  Try
+    FRM.SourceNode := FNode;
+    FRM.SourceWalletKeys := FWalletKeys;
+    FRM.ShowModal;
+  finally
+    FRM.Free;
+  end;
+end;
+{$ENDIF}
 
 procedure TFRMWallet.Test_ShowPublicKeys(Sender: TObject);
 var F : TFRMMemoText;
@@ -1014,7 +1042,6 @@ begin
     sl.Free;
   end;
 end;
-{$ENDIF}
 
 function TFRMWallet.ForceMining: Boolean;
 begin
@@ -1032,6 +1059,11 @@ end;
 procedure TFRMWallet.FormCreate(Sender: TObject);
 Var i : Integer;
 begin
+  {$IFNDEF FPC}
+  {$IFDEF TESTNET}
+  System.ReportMemoryLeaksOnShutdown := True; // Delphi memory leaks testing
+  {$ENDIF}
+  {$ENDIF}
   FLastNodesCacheUpdatedTS := Now;
   FBackgroundPanel := Nil;
   FBackgroundLabel := Nil;
@@ -1126,7 +1158,7 @@ begin
   cbHashRateUnits.Items.Add('Th/s');
   cbHashRateUnits.Items.Add('Ph/s');
   cbHashRateUnits.Items.Add('Eh/s');
-  {$IFDEF TESTING_NO_POW_CHECK}
+  {$IFDEF TESTNET}
   // Things for testing purposes only
   InitMenuForTesting;
   {$ENDIF}