Skip to content

Commit be520e7

Browse files
committed
fix: resolve unit test CI execution failure
1 parent 9b1eb4e commit be520e7

3 files changed

Lines changed: 143 additions & 2 deletions

File tree

templates/build-template-linux.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ jobs:
1818
variables:
1919
CI_TEST: true
2020
steps:
21+
- script: |
22+
echo "=== Disk space before cleanup ==="
23+
df -h /
24+
# Remove pre-installed android sdk to free disk space
25+
sudo rm -rf /usr/local/lib/android || true
26+
echo "=== Disk space after cleanup ==="
27+
df -h /
28+
displayName: 'Free disk space'
2129
- task: UseDotNet@2
2230
displayName: 'Install .NET Core SDK'
2331
inputs:

test/AElf.Contracts.TestContract.Tests/AElf.Contracts.TestContract.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<OutputItemType>Contract</OutputItemType>
9898
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9999
</ProjectReference>
100+
<ProjectReference Include="..\AElf.TestBase\AElf.TestBase.csproj" />
100101
</ItemGroup>
101102

102103
<ItemGroup>

test/AElf.Contracts.TestContract.Tests/PatchedContractSecurityTests.cs

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
using System.Text;
22
using System.Threading.Tasks;
33
using 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;
48
using AElf.Sdk.CSharp;
9+
using AElf.TestBase;
510
using AElf.Types;
611
using Google.Protobuf;
712
using Google.Protobuf.WellKnownTypes;
13+
using Microsoft.Extensions.DependencyInjection;
814
using Shouldly;
915
using Xunit;
1016
using 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

Comments
 (0)