diff --git a/CodeCoverage.runsettings b/CodeCoverage.runsettings new file mode 100755 index 0000000..e58b313 --- /dev/null +++ b/CodeCoverage.runsettings @@ -0,0 +1,17 @@ + + + + + + + + cobertura + [xunit.*]*,[*Tests]* + **/test/**/*.cs, + Obsolete,GeneratedCodeAttribute + false + + + + + \ No newline at end of file diff --git a/README.md b/README.md index e3fdb08..569b64f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # AElf-Client +BRANCH | AZURE PIPELINES | TESTS | CODE COVERAGE +-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------- +MASTER | [![Build Status](https://dev.azure.com/AElfProject/aelf-sdk.cs/_apis/build/status/AElfProject.aelf-sdk.cs?branchName=master)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=master) | [![Test Status](https://img.shields.io/azure-devops/tests/AElfProject/aelf-sdk.cs/14/master)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=master) | [![codecov](https://codecov.io/gh/AElfProject/aelf-sdk.cs/branch/master/graph/badge.svg?token=mBrO9ZNFAS)](https://codecov.io/gh/AElfProject/aelf-sdk.cs) +DEV | [![Build Status](https://dev.azure.com/AElfProject/aelf-sdk.cs/_apis/build/status/AElfProject.aelf-sdk.cs?branchName=dev)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=dev) | [![Test Status](https://img.shields.io/azure-devops/tests/AElfProject/aelf-sdk.cs/14/dev)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=dev) | [![codecov](https://codecov.io/gh/AElfProject/aelf-sdk.cs/branch/dev/graph/badge.svg?token=mBrO9ZNFAS)](https://codecov.io/gh/AElfProject/aelf-sdk.cs) + + ## Introduction This is a C# client library, used to communicate with the [AElf](https://github.com/AElfProject/AElf) API. diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 464e1d0..68a7151 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ jobs: - task: UseDotNet@2 displayName: 'Install .NET Core SDK' inputs: - version: 3.1.101 + version: 6.0.x - powershell: ./scripts/aelf-node/start-window.ps1 displayName: 'Build and Test' # All tasks on Linux @@ -23,13 +23,28 @@ jobs: pool: vmImage: ubuntu-18.04 steps: - - task: DotNetCoreInstaller@0 + - task: UseDotNet@2 + displayName: 'Install .NET Core SDK' inputs: - version: '3.1.101' + version: 6.0.x - script: cd scripts/aelf-node && bash start.sh displayName: 'Deploy a full node' - - script: bash build.sh -target=test + - script: bash build.sh -target=test-with-codecov displayName: 'build and test' + - task: PublishTestResults@2 + condition: always() + inputs: + testRunner: VSTest + testResultsFiles: '**/*.trx' + - task: reportgenerator@5 + displayName: ReportGenerator + inputs: + reports: '$(Build.SourcesDirectory)/test/*/TestResults/*/coverage.cobertura.xml' + targetdir: '$(Build.SourcesDirectory)/CodeCoverage' + reporttypes: 'Cobertura' + assemblyfilters: '-xunit*' + - script: bash build.sh --target=upload-coverage-azure + displayName: 'Upload data to Codecov' # All tasks on macOS - job: build_all_macos displayName: Build all tasks (macos) @@ -38,10 +53,11 @@ jobs: variables: phpVersion: 7.2 steps: - - task: DotNetCoreInstaller@0 + - task: UseDotNet@2 + displayName: 'Install .NET Core SDK' inputs: - version: '3.1.101' + version: 6.0.x - script: cd scripts/aelf-node && bash start-mac.sh displayName: 'Deploy a full node' - - script: bash build.sh -target=test + - script: bash build.sh -target=test-with-codecov displayName: 'build and test' diff --git a/build.cake b/build.cake index 3f1db00..0a0ccb6 100755 --- a/build.cake +++ b/build.cake @@ -1,9 +1,13 @@ +#tool nuget:?package=Codecov +#addin nuget:?package=Cake.Codecov&version=0.8.0 + var target = Argument("target", "default"); +var configuration = Argument("configuration", "Debug"); var rootPath = "./"; var srcPath = rootPath + "AElf.Client/"; var testPath = rootPath + "AElf.Client.Test/"; var distPath = rootPath + "aelf-node/"; -var solution = rootPath + "AElf.Client.sln"; +var solution = rootPath + "all.sln"; var srcProjects = GetFiles(srcPath + "AElf.Client.csproj"); Task("clean") @@ -36,7 +40,7 @@ Task("build") { var buildSetting = new DotNetCoreBuildSettings{ NoRestore = true, - Configuration = "Debug", + Configuration = configuration, ArgumentCustomization = args => { return args.Append("/clp:ErrorsOnly") .Append("--no-incremental") @@ -62,6 +66,36 @@ Task("test") } }); +Task("test-with-codecov") + .Description("operation test") + .IsDependentOn("Build") + .Does(() => +{ + var testSetting = new DotNetCoreTestSettings{ + Configuration = configuration, + NoRestore = true, + NoBuild = true, + ArgumentCustomization = args => { + return args + .Append("--logger trx") + .Append("--settings CodeCoverage.runsettings") + .Append("--collect:\"XPlat Code Coverage\""); + } + }; + var testProjects = GetFiles("./test/*.Test/*.csproj"); + var testProjectList = testProjects.OrderBy(p=>p.FullPath).ToList(); + foreach(var testProject in testProjectList) + { + DotNetCoreTest(testProject.FullPath, testSetting); + } +}); + +Task("upload-coverage-azure") + .Does(() => +{ + Codecov("./CodeCoverage/Cobertura.xml","$CODECOV_TOKEN"); +}); + Task("default") .Description("default run test(-target test)") .IsDependentOn("build"); diff --git a/build.config b/build.config index 803c029..015ef8e 100644 --- a/build.config +++ b/build.config @@ -1,3 +1,3 @@ #!/usr/bin/env bash CAKE_VERSION=0.37.0 -DOTNET_VERSION=3.1.101 +DOTNET_VERSION=6.0.300 diff --git a/codecov.sh b/codecov.sh new file mode 100755 index 0000000..6b97c5b --- /dev/null +++ b/codecov.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +TOKEN=$1 +rm -r ./test/*.Tests/TestResults +rm -r CodeCoverage +for name in `ls ./test/*.Tests/*.csproj | awk '{print $NF}'`; +do + echo ${name} + dotnet test ${name} --logger trx --settings CodeCoverage.runsettings --collect:"XPlat Code Coverage" +done +reportgenerator /test/*/TestResults/*/coverage.cobertura.xml -reports:./test/*/TestResults/*/coverage.cobertura.xml -targetdir:./CodeCoverage -reporttypes:Cobertura -assemblyfilters:-xunit* +codecov -f ./CodeCoverage/Cobertura.xml -t ${TOKEN} \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100755 index 0000000..23be405 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +codecov: + notify: + after_n_builds: 1 \ No newline at end of file diff --git a/scripts/aelf-node/start-mac.sh b/scripts/aelf-node/start-mac.sh index e580f84..9e61a56 100644 --- a/scripts/aelf-node/start-mac.sh +++ b/scripts/aelf-node/start-mac.sh @@ -1,10 +1,14 @@ brew install redis brew services start redis brew install unzip +brew install wget mkdir -p ~/.local/share/aelf/keys cd ../../ -wget https://github.com/AElfProject/AElf/releases/download/v1.0.0/aelf.zip && unzip aelf.zip +wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip && unzip aelf.zip cp scripts/aelf-node/keys/SD6BXDrKT2syNd1WehtPyRo3dPBiXqfGUj8UJym7YP9W9RynM.json ~/.local/share/aelf/keys/ -cp scripts/aelf-node/app* aelf/ +cp scripts/aelf-node/app* AElf/ echo "start node" cd aelf && dotnet AElf.Launcher.dll >/dev/null 2>&1 & +sleep 30 +height=`curl -s http://127.0.0.1:8001/api/blockChain/blockHeight` +echo "height is $height" \ No newline at end of file diff --git a/scripts/aelf-node/start-window.ps1 b/scripts/aelf-node/start-window.ps1 index c708a48..2b9f83e 100644 --- a/scripts/aelf-node/start-window.ps1 +++ b/scripts/aelf-node/start-window.ps1 @@ -2,14 +2,14 @@ wget https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Red Expand-Archive -Path redis.zip -DestinationPath redis ; $job1 = Start-Job -ScriptBlock { cd D:\a\1\s\redis; .\redis-server.exe; } sleep 30 -mkdir -p C:\Users\VssAdministrator\AppData\Local\aelf\keys -cp -r scripts\aelf-node\keys\* C:\Users\VssAdministrator\AppData\Local\aelf\keys; -wget https://github.com/AElfProject/AElf/releases/download/v1.0.0/aelf.zip -OutFile aelf.zip ; +mkdir -p C:\AppData\Local\aelf\keys +cp -r scripts\aelf-node\keys\* C:\AppData\Local\aelf\keys; +wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip -OutFile aelf.zip ; Expand-Archive -Path aelf.zip -DestinationPath aelf ; -cp scripts\aelf-node\appsettings.json aelf\aelf\appsettings.json ; -cp scripts\aelf-node\appsettings.MainChain.TestNet.json aelf\aelf\appsettings.MainChain.TestNet.json ; -cd aelf/aelf -$job2 = Start-Job -ScriptBlock { cd D:\a\1\s\aelf\aelf; dotnet AElf.Launcher.dll; } +cp scripts\aelf-node\appsettings.json aelf\AElf\appsettings.json ; +cp scripts\aelf-node\appsettings.MainChain.TestNet.json aelf\AElf\appsettings.MainChain.TestNet.json ; +cd aelf/AElf +$job2 = Start-Job -ScriptBlock { cd D:\a\1\s\aelf\AElf; dotnet AElf.Launcher.dll; } sleep 60 cd D:\a\1\s -PowerShell.exe -file build.ps1 --target=test +PowerShell.exe -file build.ps1 --target=test-with-codecov diff --git a/scripts/aelf-node/start.sh b/scripts/aelf-node/start.sh index 138b5c5..4f7062b 100644 --- a/scripts/aelf-node/start.sh +++ b/scripts/aelf-node/start.sh @@ -3,14 +3,14 @@ ip=`ip a | grep eth0 |grep 'inet' | awk -F/ '{print $1}'| awk '{print $2}'` sudo apt update && apt install unzip sudo mkdir -p /home/ubuntu/.ssh/aelf/keys && sudo mkdir -p /root/.ssh/aelf/keys cd ../../ -wget https://github.com/AElfProject/AElf/releases/download/v1.0.0/aelf.zip +wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip sudo unzip aelf.zip sed -i "s/127.0.0.1/$ip/g" scripts/aelf-node/appsettings.json -sudo mkdir -p aelf/aelf/keys -sudo cp scripts/aelf-node/keys/*.json aelf/aelf/keys/ -sudo cp scripts/aelf-node/app* aelf/ +sudo mkdir -p AElf/aelf/keys +sudo cp scripts/aelf-node/keys/*.json AElf/aelf/keys/ +sudo cp scripts/aelf-node/app* AElf/ echo "start node" -cd aelf && sudo dotnet AElf.Launcher.dll >/dev/null 2>&1 & +cd AElf && sudo dotnet AElf.Launcher.dll >/dev/null 2>&1 & sleep 30 height=`curl -s http://$ip:8001/api/blockChain/blockHeight` echo "height is $height" diff --git a/test/AElf.Client.Test/AElf.Client.Test.csproj b/test/AElf.Client.Test/AElf.Client.Test.csproj index f6a8729..13defc3 100644 --- a/test/AElf.Client.Test/AElf.Client.Test.csproj +++ b/test/AElf.Client.Test/AElf.Client.Test.csproj @@ -11,6 +11,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/AElf.Client.Test/ClientTest.cs b/test/AElf.Client.Test/ClientTest.cs index 4127c7f..d783513 100644 --- a/test/AElf.Client.Test/ClientTest.cs +++ b/test/AElf.Client.Test/ClientTest.cs @@ -25,7 +25,7 @@ namespace AElf.Client.Test; public class ClientTest { - private const string BaseUrl = "http://192.168.196.116:8000"; + private const string BaseUrl = "http://127.0.0.1:8001"; private string _genesisAddress; private string GenesisAddress => GetGenesisContractAddress();