From 1f17562f7abd3bbdd73023c614eadae49b11f11b Mon Sep 17 00:00:00 2001 From: farpetrad-sl Date: Sat, 2 Mar 2024 06:12:36 -0700 Subject: [PATCH 1/3] add actions --- .github/workflows/CodeQL.yaml | 55 +++++++++++++++++++++++++++ .github/workflows/OpenPR.yaml | 52 ++++++++++++++++++++++++++ .github/workflows/Publish.yaml | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 .github/workflows/CodeQL.yaml create mode 100644 .github/workflows/OpenPR.yaml create mode 100644 .github/workflows/Publish.yaml diff --git a/.github/workflows/CodeQL.yaml b/.github/workflows/CodeQL.yaml new file mode 100644 index 0000000..c41787f --- /dev/null +++ b/.github/workflows/CodeQL.yaml @@ -0,0 +1,55 @@ +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'csharp' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/OpenPR.yaml b/.github/workflows/OpenPR.yaml new file mode 100644 index 0000000..d545dc4 --- /dev/null +++ b/.github/workflows/OpenPR.yaml @@ -0,0 +1,52 @@ +name: pull-request +on: + pull_request + +jobs: + update-version: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - uses: actions/checkout@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 8.0.x + + - name: Restore dependencies + run: dotnet restore + + - name: Bump version and push tag + id: bump-and-tag + uses: anothrNick/github-tag-action@1.36.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + + - name: version it + id: get-id + uses: actions/github-script@0.9.0 + env: + DATA: ${{ steps.bump-and-tag.outputs.new_tag }} + with: + script: | + const id = process.env.DATA.split('v')[1] + core.setOutput('version', id) + + - name: output + id: tag-and-version + run: echo "Output tag = ${{ steps.bump-and-tag.outputs.new_tag }} parsed = ${{ steps.get-id.outputs.version }}" + + - name: Build + run: dotnet build --no-restore -c Debug -p:Version=${{ steps.get-id.outputs.version }} + + - name: Test + env: + HIVEUSERNAME: ${{ secrets.USERNAME }} + KEY: ${{ secrets.KEY }} + run: dotnet test --no-build --verbosity normal + + \ No newline at end of file diff --git a/.github/workflows/Publish.yaml b/.github/workflows/Publish.yaml new file mode 100644 index 0000000..d54b1b2 --- /dev/null +++ b/.github/workflows/Publish.yaml @@ -0,0 +1,68 @@ +name: Publish release to nuget + +on: + push: + branches: + - master + +jobs: + Nuget: + runs-on: ubuntu-latest + environment: test + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: '0' + + - name: Setup .NET Core 6 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 8.0.x + env: + NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }} + + - name: Bump version and push tag + id: bump-and-tag + uses: anothrNick/github-tag-action@1.36.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + + - name: version it + id: get-id + uses: actions/github-script@0.9.0 + env: + DATA: ${{ steps.bump-and-tag.outputs.new_tag }} + with: + script: | + const id = process.env.DATA.split('v')[1] + core.setOutput('version', id) + + - name: Create releasse + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.bump-and-tag.outputs.new_tag }} + release_name: Release ${{ steps.bump-and-tag.outputs.new_tag }} + body: | + Changes in this release + draft: false + prerelease: false + + - name: Restore dependencies + run: dotnet restore + + - name: Pack it + run: dotnet pack -c Release --no-restore -p:Version=${{ steps.get-id.outputs.version }} -o out + + + - name: Publish SplinterLands.DTOs + run: nuget push ./**/SplinterLands.DTOs.*.nupkg -SkipDuplicate -NoSymbols -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }} + + - name: Publish SplinterLandsAPI + run: nuget push ./**/SplinterLandsAPI.*.nupkg -SkipDuplicate -NoSymbols -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }} + + From f7dda5ff8f07896870e11b77a1b32b5e60334dea Mon Sep 17 00:00:00 2001 From: farpetrad-sl Date: Sat, 2 Mar 2024 06:25:15 -0700 Subject: [PATCH 2/3] add secrets --- sl-Hive.Test/Readme.md | 10 ++++++++++ sl-Hive.Test/UnitTest1.cs | 26 ++++++++++++++++++++++++-- sl-Hive.Test/sl-Hive.Test.csproj | 4 ++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 sl-Hive.Test/Readme.md diff --git a/sl-Hive.Test/Readme.md b/sl-Hive.Test/Readme.md new file mode 100644 index 0000000..3675476 --- /dev/null +++ b/sl-Hive.Test/Readme.md @@ -0,0 +1,10 @@ +This project makes use of the .net secrets manager in order to protect the login and key of the user used to validate tests that require a login. +To setup the secrets manager first run `dotnet user-secrets init` from the project directory. + +Next add two secrets, one for the user `HIVEUSERNAME` and one for your private posting key `KEY`. + +`dotnet user-secrets set "HIVEUSERNAME" "YOUR_USER_NAME_HERE"` + +`dotnet user-secrets set "KEY" "YOUR_PRIVATE_POSTING_KEY_HERE"` + +See more info at https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-8.0&tabs=windows \ No newline at end of file diff --git a/sl-Hive.Test/UnitTest1.cs b/sl-Hive.Test/UnitTest1.cs index aaf6208..200e298 100644 --- a/sl-Hive.Test/UnitTest1.cs +++ b/sl-Hive.Test/UnitTest1.cs @@ -1,6 +1,8 @@ +using Microsoft.Extensions.Configuration; using sl_Hive.Models; using sl_Hive.Requests; using sl_Hive.Splinterlands_Ops; +using System.Reflection; namespace sl_Hive.Test { @@ -10,7 +12,27 @@ public class UnitTest1 private HiveEngine hive = new HiveEngine(new HttpClient(), RPCNodeCollection.DefaultNodes); const string PrivKey = "5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw"; const string PublicKey = "STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA"; + private readonly string User; + private readonly string PrivatePostingKey; + public UnitTest1() + { + var builder = new ConfigurationBuilder().AddUserSecrets(Assembly.GetExecutingAssembly(), true).AddEnvironmentVariables(); + + var Configuration = builder.Build(); + + PrivatePostingKey = Configuration["KEY"] ?? string.Empty; + User = Configuration["HIVEUSERNAME"] ?? string.Empty; + + if (PrivatePostingKey == string.Empty) + { + PrivatePostingKey = Environment.GetEnvironmentVariable("KEY") ?? string.Empty; + } + if (User == string.Empty) + { + User = Environment.GetEnvironmentVariable("HIVEUSERNAME") ?? string.Empty; + } + } [TestMethod] public async Task ReadGlobalBlockchainProperties() { @@ -93,8 +115,8 @@ public async Task PostTransaction() request.Params = new JsonArray(JsonSerializer.SerializeToNode(trans.ToParams(), HiveEngine._options)); var post = await hive.QueryBlockchain(request);*/ var post = await hive.BroadcastCustomJson(new StakeTokens() { qty = 1 }, - "ahsoka", - ""); + User, + PrivatePostingKey); Assert.IsNotNull(post); } diff --git a/sl-Hive.Test/sl-Hive.Test.csproj b/sl-Hive.Test/sl-Hive.Test.csproj index cd2d1de..01a850b 100644 --- a/sl-Hive.Test/sl-Hive.Test.csproj +++ b/sl-Hive.Test/sl-Hive.Test.csproj @@ -7,9 +7,13 @@ enable false + + fe95abbd-4c03-414f-9cc0-d43750a3e68f + + From d9e39ccdda7f78d985be006a9ef18f3e5f6353b2 Mon Sep 17 00:00:00 2001 From: farpetrad-sl Date: Sat, 2 Mar 2024 09:10:19 -0700 Subject: [PATCH 3/3] cleanup --- sl-Hive.Test/UnitTest1.cs | 45 --------------------------------------- 1 file changed, 45 deletions(-) diff --git a/sl-Hive.Test/UnitTest1.cs b/sl-Hive.Test/UnitTest1.cs index 200e298..cfdda61 100644 --- a/sl-Hive.Test/UnitTest1.cs +++ b/sl-Hive.Test/UnitTest1.cs @@ -69,51 +69,6 @@ public async Task GetAccounts() { [TestMethod] public async Task PostTransaction() { - //var hash = Sha256Manager.GetHash( - // Encoding.ASCII.GetBytes( - // "farpetrad" + new DateTimeOffset(new DateTime()).ToUnixTimeMilliseconds().ToString()) - // ); - //var bytes = CBase58.DecodePrivateWif(""); - //var sig = Secp256K1Manager.SignCompressedCompact(hash, bytes); - //var signature = Hex.ToString(sig); - - - /*var response = await hive.QueryBlockchain(HiveDynamicGlobalPropertiesRequest.Instance); - var request = new CustomJsonTx(); - - var trx = new custom_json() - { - id = "sm_stake_tokens", // whatever operation the game should perform - required_posting_auths = ["ahsoka"], // posting key ops - required_auths = [], // active key ops - json = JsonSerializer.Serialize(new StakeTokens() { qty = 1 }, HiveEngine._options), - }; - var trans = new Transaction() - { - ref_block_num = (ushort)((ushort)response.Result?.Head_Block_Number & (ushort)0xFFFF), - ref_block_prefix = response.Result?.Ref_Block_Prefix ?? 0, - operations = new object[] { trx }, - expiration = response?.Result?.Time.AddSeconds(30) ?? DateTime.UtcNow.AddSeconds(30), - signatures = new string[0], - extensions = new string[0], - }; - var serializer = new SignatureSerializer(); - var msg = serializer.Serialize(trans); - using(var memStream = new MemoryStream()) - { - var chainIdBytes = Hex.HexToBytes(CHAINID); - memStream.Write(chainIdBytes, 0, chainIdBytes.Length); - memStream.Write(msg, 0, msg.Length); - - var digest = Sha256Manager.GetHash(memStream.ToArray()); - var signatureBytes = CBase58.DecodePrivateWif(""); - - - trans.signatures = new[] { Hex.ToString(Secp256K1Manager.SignCompressedCompact(digest, signatureBytes)) }; - var trxId = Hex.ToString(Sha256Manager.GetHash(msg)).Substring(0, 40); - }; - request.Params = new JsonArray(JsonSerializer.SerializeToNode(trans.ToParams(), HiveEngine._options)); - var post = await hive.QueryBlockchain(request);*/ var post = await hive.BroadcastCustomJson(new StakeTokens() { qty = 1 }, User, PrivatePostingKey);