11using System . Text ;
22using System . Threading . Tasks ;
33using AElf . Contracts . TestContract . BasicSecurity ;
4+ using AElf . Kernel ;
5+ using AElf . Kernel . Blockchain . Application ;
6+ using AElf . Kernel . SmartContract ;
7+ using AElf . Kernel . SmartContract . Application ;
48using AElf . Sdk . CSharp ;
9+ using AElf . TestBase ;
510using AElf . Types ;
611using Google . Protobuf ;
712using Google . Protobuf . WellKnownTypes ;
13+ using Microsoft . Extensions . DependencyInjection ;
814using Shouldly ;
915using Xunit ;
1016using SmartContractConstants = AElf . Kernel . SmartContract . SmartContractConstants ;
@@ -385,7 +391,7 @@ await TestBasicSecurityContractStub.TestMapped2State.SendAsync(new ProtobufInput
385391 }
386392 }
387393
388- [ Fact ]
394+ [ IgnoreOnCIFact ]
389395 public async Task TestBranchCount ( )
390396 {
391397 {
@@ -434,7 +440,7 @@ await TestBasicSecurityContractStub.TestForeachInfiniteLoop.SendWithExceptionAsy
434440 }
435441 }
436442
437- [ Fact ]
443+ [ IgnoreOnCIFact ]
438444 public async Task TestMethodCallCount ( )
439445 {
440446 {
@@ -453,4 +459,130 @@ await TestBasicSecurityContractStub.TestInfiniteRecursiveCallInSeparateClass.Sen
453459 txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeCallThresholdExceededException ) ) ;
454460 }
455461 }
462+
463+ [ Fact ]
464+ public async Task TestBranchCountWithReducedThreshold ( )
465+ {
466+ // Get required services
467+ var blockchainService = Application . ServiceProvider . GetRequiredService < IBlockchainService > ( ) ;
468+ var executionObserverThresholdProvider =
469+ Application . ServiceProvider . GetRequiredService < IExecutionObserverThresholdProvider > ( ) ;
470+
471+ // Get current best chain block
472+ var bestChainBlock = await blockchainService . GetBestChainLastBlockHeaderAsync ( ) ;
473+ var blockIndex = new BlockIndex
474+ {
475+ BlockHash = bestChainBlock . GetHash ( ) ,
476+ BlockHeight = bestChainBlock . Height
477+ } ;
478+
479+ // Set reduced threshold to 5000
480+ const int reducedThreshold = 5000 ;
481+ var newThreshold = new ExecutionObserverThreshold
482+ {
483+ ExecutionBranchThreshold = reducedThreshold ,
484+ ExecutionCallThreshold = reducedThreshold
485+ } ;
486+ await executionObserverThresholdProvider . SetExecutionObserverThresholdAsync ( blockIndex , newThreshold ) ;
487+
488+ // Verify threshold was set correctly
489+ var currentThreshold = executionObserverThresholdProvider . GetExecutionObserverThreshold ( blockIndex ) ;
490+ currentThreshold . ExecutionBranchThreshold . ShouldBe ( reducedThreshold ) ;
491+ currentThreshold . ExecutionCallThreshold . ShouldBe ( reducedThreshold ) ;
492+
493+ {
494+ await TestBasicSecurityContractStub . TestWhileInfiniteLoop . SendAsync ( new Int32Input
495+ { Int32Value = reducedThreshold - 1 } ) ;
496+ var txResult = await TestBasicSecurityContractStub . TestWhileInfiniteLoop . SendWithExceptionAsync (
497+ new Int32Input
498+ { Int32Value = reducedThreshold } ) ;
499+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeBranchThresholdExceededException ) ) ;
500+ }
501+
502+ {
503+ await TestBasicSecurityContractStub . TestForInfiniteLoop . SendAsync ( new Int32Input { Int32Value = reducedThreshold - 1 } ) ;
504+ var txResult = await TestBasicSecurityContractStub . TestForInfiniteLoop . SendWithExceptionAsync (
505+ new Int32Input
506+ { Int32Value = reducedThreshold } ) ;
507+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeBranchThresholdExceededException ) ) ;
508+ }
509+
510+ {
511+ await TestBasicSecurityContractStub . TestForInfiniteLoopInSeparateClass . SendAsync ( new Int32Input
512+ { Int32Value = reducedThreshold - 1 } ) ;
513+ var txResult = await TestBasicSecurityContractStub . TestForInfiniteLoop . SendWithExceptionAsync (
514+ new Int32Input
515+ { Int32Value = reducedThreshold } ) ;
516+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeBranchThresholdExceededException ) ) ;
517+ }
518+
519+ {
520+ await TestBasicSecurityContractStub . TestWhileInfiniteLoopWithState . SendAsync ( new Int32Input
521+ { Int32Value = reducedThreshold - 1 } ) ;
522+ var txResult =
523+ await TestBasicSecurityContractStub . TestWhileInfiniteLoopWithState . SendWithExceptionAsync (
524+ new Int32Input
525+ { Int32Value = reducedThreshold } ) ;
526+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeBranchThresholdExceededException ) ) ;
527+ }
528+
529+ {
530+ await TestBasicSecurityContractStub . TestForeachInfiniteLoop . SendAsync ( new ListInput
531+ { List = { new int [ reducedThreshold - 1 ] } } ) ;
532+ var txResult =
533+ await TestBasicSecurityContractStub . TestForeachInfiniteLoop . SendWithExceptionAsync (
534+ new ListInput { List = { new int [ reducedThreshold ] } } ) ;
535+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeBranchThresholdExceededException ) ) ;
536+ }
537+ }
538+
539+ [ Fact ]
540+ public async Task TestMethodCallCountWithReducedThreshold ( )
541+ {
542+ // Get required services
543+ var blockchainService = Application . ServiceProvider . GetRequiredService < IBlockchainService > ( ) ;
544+ var executionObserverThresholdProvider =
545+ Application . ServiceProvider . GetRequiredService < IExecutionObserverThresholdProvider > ( ) ;
546+
547+ // Get current best chain block
548+ var bestChainBlock = await blockchainService . GetBestChainLastBlockHeaderAsync ( ) ;
549+ var blockIndex = new BlockIndex
550+ {
551+ BlockHash = bestChainBlock . GetHash ( ) ,
552+ BlockHeight = bestChainBlock . Height
553+ } ;
554+
555+ // Set reduced threshold to 5000
556+ const int reducedThreshold = 5000 ;
557+ var newThreshold = new ExecutionObserverThreshold
558+ {
559+ ExecutionBranchThreshold = reducedThreshold ,
560+ ExecutionCallThreshold = reducedThreshold
561+ } ;
562+ await executionObserverThresholdProvider . SetExecutionObserverThresholdAsync ( blockIndex , newThreshold ) ;
563+
564+ // Verify threshold was set correctly
565+ var currentThreshold = executionObserverThresholdProvider . GetExecutionObserverThreshold ( blockIndex ) ;
566+ currentThreshold . ExecutionBranchThreshold . ShouldBe ( reducedThreshold ) ;
567+ currentThreshold . ExecutionCallThreshold . ShouldBe ( reducedThreshold ) ;
568+
569+ // Test recursive call with reduced threshold
570+ {
571+ await TestBasicSecurityContractStub . TestInfiniteRecursiveCall . SendAsync ( new Int32Input
572+ { Int32Value = reducedThreshold - 100 } ) ;
573+ var txResult = await TestBasicSecurityContractStub . TestInfiniteRecursiveCall . SendWithExceptionAsync (
574+ new Int32Input { Int32Value = reducedThreshold } ) ;
575+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeCallThresholdExceededException ) ) ;
576+ }
577+
578+ // Test recursive call in separate class with reduced threshold
579+ {
580+ await TestBasicSecurityContractStub . TestInfiniteRecursiveCallInSeparateClass . SendAsync ( new Int32Input
581+ { Int32Value = reducedThreshold - 100 } ) ;
582+ var txResult =
583+ await TestBasicSecurityContractStub . TestInfiniteRecursiveCallInSeparateClass . SendWithExceptionAsync (
584+ new Int32Input { Int32Value = reducedThreshold } ) ;
585+ txResult . TransactionResult . Error . ShouldContain ( nameof ( RuntimeCallThresholdExceededException ) ) ;
586+ }
587+ }
456588}
0 commit comments