Skip to content

Commit

Permalink
Merge branch 'development' into rc-v100034
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae authored Mar 3, 2021
2 parents e3848ce + 9eabe34 commit be937cf
Show file tree
Hide file tree
Showing 52 changed files with 1,378 additions and 181 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/deploy_gh_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy gh pages
on:
push:
branches:
- development
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
submodules: recursive
node-version: '14'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm install -g @2fd/graphdoc
- name: Build
run: graphdoc -s schema.graphql -o doc
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc
4 changes: 3 additions & 1 deletion .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
- rc-*
- 9c-main
- development

jobs:
build_and_push:
Expand All @@ -17,7 +19,7 @@ jobs:
- name: login
run: docker login --username '${{ secrets.DOCKER_USERNAME }}' --password '${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}'
- name: build
run: docker build . -t planetariumhq/ninechronicles-headless:git-${{ github.sha }} --build-arg COMMIT=git-${{ github.sha }} --build-arg COMMIT=git-${{ github.sha }}
run: docker build . -t planetariumhq/ninechronicles-headless:git-${{ github.sha }} --build-arg COMMIT=git-${{ github.sha }}
- name: push git-version
run: docker push planetariumhq/ninechronicles-headless:git-${{ github.sha }}

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NineChronicles.Headless.Executable.Commands;
using NineChronicles.Headless.Executable.Tests.IO;
using Xunit;

namespace NineChronicles.Headless.Executable.Tests.Commands
{
public class ValidationCommandTest
{
private readonly StringIOConsole _console;
private readonly ValidationCommand _command;

public ValidationCommandTest()
{
_console = new StringIOConsole();
_command = new ValidationCommand(_console);
}

[Theory]
[InlineData("", -1, "The given private key, '', had an issue during parsing.\n")]
[InlineData("invalid hexadecimal", -1, "The given private key, 'invalid hexadecimal', had an issue during parsing.\n")]
[InlineData("000000000000000000000000000000000000000000000000000000000000000000", -1, "The given private key, '000000000000000000000000000000000000000000000000000000000000000000', had an issue during parsing.\n")]
[InlineData("ab8d591ccdcce263c39eb1f353e44b64869f0afea2df643bf6839ebde650d244", 0, "")]
[InlineData("d6c3e0d525dac340a132ae05aaa9f3e278d61b70d2b71326570e64aee249e566", 0, "")]
[InlineData("761f68d68426549df5904395b5ca5bce64a3da759085d8565242db42a5a1b0b9", 0, "")]
public void PrivateKey(string privateKeyHex, int exitCode, string errorOutput)
{
Assert.Equal(exitCode, _command.PrivateKey(privateKeyHex));
Assert.Equal(errorOutput, _console.Error.ToString());
}

[Theory]
[InlineData("", -1, "The given public key, '', had an issue during parsing.\n")]
[InlineData("invalid hexadecimal", -1, "The given public key, 'invalid hexadecimal', had an issue during parsing.\n")]
[InlineData("000000000000000000000000000000000000000000000000000000000000000000", -1, "The given public key, '000000000000000000000000000000000000000000000000000000000000000000', had an issue during parsing.\n")]
[InlineData("03b0868d9301b30c512d307ea67af4c8bef637ef099e39d32b808a43e6b41469c5", 0, "")]
[InlineData("03308c1618a75e85a5fb57f7e453a642c307dc6310e90a7418b1aec565d963534a", 0, "")]
[InlineData("028a6190bf643175b20e4a2d1d86fe6c4b8f7d5fe3d163632be4e59f83335824b8", 0, "")]
public void PublicKey(string publicKeyHex, int exitCode, string errorOutput)
{
Assert.Equal(exitCode, _command.PublicKey(publicKeyHex));
Assert.Equal(errorOutput, _console.Error.ToString());
}
}
}
32 changes: 32 additions & 0 deletions NineChronicles.Headless.Executable.Tests/IO/StringIOConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IO;
using NineChronicles.Headless.Executable.IO;

namespace NineChronicles.Headless.Executable.Tests.IO
{
public sealed class StringIOConsole : IConsole
{
public StringIOConsole(StringReader @in, StringWriter @out, StringWriter error)
{
In = @in;
Out = @out;
Error = error;
}

public StringIOConsole(string input = "")
: this(new StringReader(input), new StringWriter(), new StringWriter())
{
}

public StringReader In { get; }

public StringWriter Out { get; }

public StringWriter Error { get; }

TextReader IConsole.In => In;

TextWriter IConsole.Out => Out;

TextWriter IConsole.Error => Error;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8</LangVersion>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference
Include="..\NineChronicles.Headless.Executable\NineChronicles.Headless.Executable.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions NineChronicles.Headless.Executable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.RocksDBStore", "L
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Stun", "Lib9c\.Libplanet\Libplanet.Stun\Libplanet.Stun.csproj", "{3B2875B4-B6C6-4929-B885-18A922110ED2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NineChronicles.Headless.Executable.Tests", "NineChronicles.Headless.Executable.Tests\NineChronicles.Headless.Executable.Tests.csproj", "{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -153,6 +155,18 @@ Global
{3B2875B4-B6C6-4929-B885-18A922110ED2}.Release|x64.Build.0 = Release|Any CPU
{3B2875B4-B6C6-4929-B885-18A922110ED2}.Release|x86.ActiveCfg = Release|Any CPU
{3B2875B4-B6C6-4929-B885-18A922110ED2}.Release|x86.Build.0 = Release|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Debug|x64.ActiveCfg = Debug|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Debug|x64.Build.0 = Debug|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Debug|x86.ActiveCfg = Debug|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Debug|x86.Build.0 = Debug|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Release|Any CPU.Build.0 = Release|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Release|x64.ActiveCfg = Release|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Release|x64.Build.0 = Release|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Release|x86.ActiveCfg = Release|Any CPU
{6E38A2CF-B93F-4CD5-9CAC-DE121998FF18}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
55 changes: 55 additions & 0 deletions NineChronicles.Headless.Executable/Commands/ValidationCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Cocona;
using Libplanet;
using Libplanet.Crypto;
using NineChronicles.Headless.Executable.IO;

namespace NineChronicles.Headless.Executable.Commands
{
public class ValidationCommand : CoconaLiteConsoleAppBase
{
private readonly IConsole _console;

public ValidationCommand(IConsole console)
{
_console = console;
}

[Command(Description = "Validate private key")]
public int PrivateKey(
[Argument(
Name = "PRIVATE-KEY",
Description = "A hexadecimal representation of private key to validate.")]
string privateKeyHex)
{
try
{
_ = new PrivateKey(ByteUtil.ParseHex(privateKeyHex));
return 0;
}
catch
{
_console.Error.WriteLine($"The given private key, '{privateKeyHex}', had an issue during parsing.");
return -1;
}
}

[Command(Description = "Validate public key")]
public int PublicKey(
[Argument(
Name = "PUBLIC-KEY",
Description = "A hexadecimal representation of public key to validate.")]
string publicKeyHex)
{
try
{
_ = new PublicKey(ByteUtil.ParseHex(publicKeyHex));
return 0;
}
catch
{
_console.Error.WriteLine($"The given public key, '{publicKeyHex}', had an issue during parsing.");
return -1;
}
}
}
}
11 changes: 11 additions & 0 deletions NineChronicles.Headless.Executable/IO/IConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.IO;

namespace NineChronicles.Headless.Executable.IO
{
public interface IConsole
{
TextReader In { get; }
TextWriter Out { get; }
TextWriter Error { get; }
}
}
21 changes: 21 additions & 0 deletions NineChronicles.Headless.Executable/IO/StandardConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.IO;

namespace NineChronicles.Headless.Executable.IO
{
public class StandardConsole : IConsole
{
public StandardConsole()
{
In = Console.In;
Out = Console.Out;
Error = Console.Error;
}

public TextReader In { get; }

public TextWriter Out { get; }

public TextWriter Error { get; }
}
}
9 changes: 7 additions & 2 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Libplanet;
using Libplanet.KeyStore;
using Microsoft.Extensions.Hosting;
using NineChronicles.Headless.Executable.Commands;
using NineChronicles.Headless.Executable.IO;
using NineChronicles.Headless.Properties;
using Org.BouncyCastle.Security;
using Sentry;
Expand All @@ -21,6 +23,7 @@

namespace NineChronicles.Headless.Executable
{
[HasSubCommands(typeof(ValidationCommand), "validation")]
public class Program : CoconaLiteConsoleAppBase
{
const string SentryDsn = "https://[email protected]/5287621";
Expand All @@ -33,7 +36,9 @@ static async Task Main(string[] args)
#if SENTRY || ! DEBUG
using var _ = SentrySdk.Init(ConfigureSentryOptions);
#endif
await CoconaLiteApp.RunAsync<Program>(args);
await CoconaLiteApp.Create()
.ConfigureServices(services => services.AddSingleton<IConsole, StandardConsole>())
.RunAsync<Program>(args);
}

static void ConfigureSentryOptions(SentryOptions o)
Expand All @@ -47,7 +52,7 @@ static void ConfigureSentryOptions(SentryOptions o)
#endif
}

[Command(Description = "Run headless application with options.")]
[PrimaryCommand]
public async Task Run(
bool noMiner = false,
[Option("app-protocol-version", new[] { 'V' }, Description = "App protocol version token")]
Expand Down
3 changes: 3 additions & 0 deletions NineChronicles.Headless.Tests/GraphQLTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GraphQL;
using GraphQL.Types;
using Microsoft.Extensions.DependencyInjection;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless.Tests
{
Expand All @@ -23,6 +24,8 @@ public static Task<ExecutionResult> ExecuteQueryAsync<TObjectGraphType>(
services.AddSingleton(standaloneContext);
}

services.AddLibplanetExplorer<NCAction>();

var serviceProvider = services.BuildServiceProvider();
return ExecuteQueryAsync<TObjectGraphType>(
serviceProvider,
Expand Down
2 changes: 2 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Microsoft.Extensions.DependencyInjection;
using Nekoyume.Model.State;
using Nekoyume.TableData;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless.Tests.GraphTypes
{
Expand Down Expand Up @@ -96,6 +97,7 @@ public GraphQLTestBase(ITestOutputHelper output)
services.AddSingleton(StandaloneContextFx);
services.AddSingleton<IConfiguration>(configuration);
services.AddGraphTypes();
services.AddLibplanetExplorer<NCAction>();
services.AddSingleton<StateQuery>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
Schema = new StandaloneSchema(serviceProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public async Task GetTx()
timestamp
updatedAddresses
actions {{
plainValue
inspection
}}
}}
}}";
Expand Down Expand Up @@ -576,7 +576,7 @@ public async Task GetTx()
var plainValue = tx["actions"]
.As<List<object>>()
.First()
.As<Dictionary<string, object>>()["plainValue"];
.As<Dictionary<string, object>>()["inspection"];
Assert.Equal(transaction.Actions.First().PlainValue.Inspection, plainValue);
}

Expand Down
23 changes: 23 additions & 0 deletions NineChronicles.Headless/BlockChainContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Libplanet.Action;
using Libplanet.Blockchain;
using Libplanet.Explorer.Interfaces;
using Libplanet.Store;
using Nekoyume.Action;
using NCAction = Libplanet.Action.PolymorphicAction<Nekoyume.Action.ActionBase>;

namespace NineChronicles.Headless
{
public class BlockChainContext : IBlockChainContext<NCAction>
{
private readonly StandaloneContext _standaloneContext;

public BlockChainContext(StandaloneContext standaloneContext)
{
_standaloneContext = standaloneContext;
}

public bool Preloaded => _standaloneContext.NodeStatus.PreloadEnded;
public BlockChain<PolymorphicAction<ActionBase>> BlockChain => _standaloneContext.BlockChain;
public IStore Store => _standaloneContext.Store;
}
}
Loading

0 comments on commit be937cf

Please sign in to comment.