-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3549 from greymistcube/feature/new-query-types
✨ New query types
- Loading branch information
Showing
20 changed files
with
582 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using GraphQL.Language.AST; | ||
using Libplanet.Common; | ||
using Libplanet.Explorer.GraphTypes; | ||
using Libplanet.Types.Blocks; | ||
using Xunit; | ||
|
||
namespace Libplanet.Explorer.Tests.GraphTypes | ||
{ | ||
public class BlockHashTypeTest : ScalarGraphTypeTestBase<BlockHashType> | ||
{ | ||
[Fact] | ||
public void ParseLiteral() | ||
{ | ||
Assert.Null(_type.ParseLiteral(new NullValue())); | ||
|
||
var bytes = TestUtils.GetRandomBytes(BlockHash.Size); | ||
var blockHash = new BlockHash(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal( | ||
blockHash, | ||
Assert.IsType<BlockHash>(_type.ParseLiteral(new StringValue(hex)))); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseLiteral(new LongValue(1234))); | ||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseValue(new StringValue("blockHash"))); | ||
} | ||
|
||
[Fact] | ||
public void ParseValue() | ||
{ | ||
Assert.Null(_type.ParseValue(null)); | ||
|
||
var bytes = TestUtils.GetRandomBytes(BlockHash.Size); | ||
var blockHash = new BlockHash(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal(blockHash, _type.ParseValue(hex)); | ||
|
||
Assert.Throws<InvalidOperationException>(() => _type.ParseValue(0)); | ||
Assert.Throws<InvalidOperationException>(() => _type.ParseValue(new BlockHash())); | ||
Assert.Throws<InvalidOperationException>(() => _type.ParseValue(new object())); | ||
} | ||
|
||
[Fact] | ||
public void Serialize() | ||
{ | ||
var bytes = TestUtils.GetRandomBytes(BlockHash.Size); | ||
var blockHash = new BlockHash(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal(hex, _type.Serialize(blockHash)); | ||
|
||
Assert.Throws<InvalidOperationException>(() => _type.Serialize(0)); | ||
Assert.Throws<InvalidOperationException>(() => _type.Serialize("")); | ||
Assert.Throws<InvalidOperationException>(() => _type.Serialize(new object())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using GraphQL.Language.AST; | ||
using Libplanet.Common; | ||
using Libplanet.Crypto; | ||
using Libplanet.Explorer.GraphTypes; | ||
using Xunit; | ||
|
||
namespace Libplanet.Explorer.Tests.GraphTypes | ||
{ | ||
public class HashDigestTypeTest : ScalarGraphTypeTestBase<HashDigestType<SHA256>> | ||
{ | ||
[Fact] | ||
public void ParseLiteral() | ||
{ | ||
Assert.Null(_type.ParseLiteral(new NullValue())); | ||
|
||
var bytes = TestUtils.GetRandomBytes(HashDigest<SHA256>.Size); | ||
var hashDigestSHA256 = new HashDigest<SHA256>(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal( | ||
hashDigestSHA256, | ||
Assert.IsType<HashDigest<SHA256>>(_type.ParseLiteral(new StringValue(hex)))); | ||
|
||
bytes = TestUtils.GetRandomBytes(HashDigest<SHA1>.Size); | ||
hex = ByteUtil.Hex(bytes); | ||
Assert.Throws<ArgumentOutOfRangeException>( | ||
() => _type.ParseLiteral(new StringValue(hex))); | ||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseLiteral(new LongValue(1234))); | ||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseValue(new StringValue("hashDigest"))); | ||
} | ||
|
||
[Fact] | ||
public void ParseValue() | ||
{ | ||
Assert.Null(_type.ParseValue(null)); | ||
|
||
var bytes = TestUtils.GetRandomBytes(HashDigest<SHA256>.Size); | ||
var hashDigest = new HashDigest<SHA256>(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal(hashDigest, _type.ParseValue(hex)); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseValue(0)); | ||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseValue(new HashDigest<SHA256>())); | ||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseValue(new object())); | ||
} | ||
|
||
[Fact] | ||
public void Serialize() | ||
{ | ||
var bytes = TestUtils.GetRandomBytes(HashDigest<SHA256>.Size); | ||
var hashDigest = new HashDigest<SHA256>(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal(hex, _type.Serialize(hashDigest)); | ||
|
||
Assert.Throws<InvalidOperationException>(() => _type.Serialize(0)); | ||
Assert.Throws<InvalidOperationException>(() => _type.Serialize("")); | ||
Assert.Throws<InvalidOperationException>(() => _type.Serialize(new object())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using GraphQL.Language.AST; | ||
using Libplanet.Common; | ||
using Libplanet.Explorer.GraphTypes; | ||
using Libplanet.Types.Tx; | ||
using Xunit; | ||
|
||
namespace Libplanet.Explorer.Tests.GraphTypes | ||
{ | ||
public class TxIdTypeTest : ScalarGraphTypeTestBase<TxIdType> | ||
{ | ||
[Fact] | ||
public void ParseLiteral() | ||
{ | ||
Assert.Null(_type.ParseLiteral(new NullValue())); | ||
|
||
var bytes = TestUtils.GetRandomBytes(TxId.Size); | ||
var txId = new TxId(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal( | ||
txId, | ||
Assert.IsType<TxId>(_type.ParseLiteral(new StringValue(hex)))); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseLiteral(new LongValue(1234))); | ||
Assert.Throws<InvalidOperationException>( | ||
() => _type.ParseValue(new StringValue("txId"))); | ||
} | ||
|
||
[Fact] | ||
public void ParseValue() | ||
{ | ||
Assert.Null(_type.ParseValue(null)); | ||
|
||
var bytes = TestUtils.GetRandomBytes(TxId.Size); | ||
var txId = new TxId(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal(txId, _type.ParseValue(hex)); | ||
|
||
Assert.Throws<InvalidOperationException>(() => _type.ParseValue(0)); | ||
Assert.Throws<InvalidOperationException>(() => _type.ParseValue(new TxId())); | ||
Assert.Throws<InvalidOperationException>(() => _type.ParseValue(new object())); | ||
} | ||
|
||
[Fact] | ||
public void Serialize() | ||
{ | ||
var bytes = TestUtils.GetRandomBytes(TxId.Size); | ||
var txId = new TxId(bytes); | ||
var hex = ByteUtil.Hex(bytes); | ||
Assert.Equal(hex, _type.Serialize(txId)); | ||
|
||
Assert.Throws<InvalidOperationException>(() => _type.Serialize(0)); | ||
Assert.Throws<InvalidOperationException>(() => _type.Serialize("")); | ||
Assert.Throws<InvalidOperationException>(() => _type.Serialize(new object())); | ||
} | ||
} | ||
} |
Oops, something went wrong.