Skip to content

Commit

Permalink
Feat xml documentation (#70)
Browse files Browse the repository at this point in the history
* state comments

* removed comment

* adding missing xml comments

* added xml comments
  • Loading branch information
darkfriend77 authored Jan 13, 2024
1 parent 95517f1 commit 27aa6a7
Show file tree
Hide file tree
Showing 101 changed files with 7,824 additions and 6,551 deletions.
8 changes: 4 additions & 4 deletions Substrate.NetApi.Test/UtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void StringValueArrayBytesArrayTest()
[Test]
public void StringValueArrayBytesArrayFailedTest()
{
Assert.Throws<Exception>(delegate { Utils.StringValueArrayBytesArray("Test"); });
Assert.Throws<NotSupportedException>(delegate { Utils.StringValueArrayBytesArray("Test"); });
}

[Test]
Expand All @@ -138,7 +138,7 @@ public void Byte2ValueTest()

Assert.AreEqual(0x1312, Utils.Bytes2Value(new byte[] { 0x13, 0x12 }, false));

Assert.Throws<Exception>(delegate
Assert.Throws<NotSupportedException>(delegate
{
Utils.Bytes2Value(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
});
Expand All @@ -147,7 +147,7 @@ public void Byte2ValueTest()
[Test]
public void HexToByteArrayFailedTest()
{
Assert.Throws<Exception>(delegate { Utils.HexToByteArray("111"); });
Assert.Throws<NotSupportedException>(delegate { Utils.HexToByteArray("111"); });
}

[Test]
Expand All @@ -169,7 +169,7 @@ public void Value2BytesTest()
Assert.AreEqual(new byte[] { 0x15, 0x14, 0x13, 0x12 }, Utils.Value2Bytes((uint)0x12131415));
Assert.AreEqual(new byte[] { 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x09, 0x08 }, Utils.Value2Bytes((ulong)0x0809101112131415));
Assert.AreEqual(new byte[] { 0x11, 0x12 }, Utils.Value2Bytes((ushort)0x1112, false));
Assert.Throws<Exception>(delegate { Utils.Value2Bytes(1.4); });
Assert.Throws<NotSupportedException>(delegate { Utils.Value2Bytes(1.4); });
}

[Test]
Expand Down
18 changes: 3 additions & 15 deletions Substrate.NetApi.TestNode/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ public async Task GetBlocknumberAtBlockHashTestAsync()
/// </summary>
public sealed class Arr32U8 : BaseType
{
private U8[] _value;

public override int TypeSize
{
get
Expand All @@ -160,17 +158,7 @@ public override int TypeSize
}
}

public U8[] Value
{
get
{
return this._value;
}
set
{
this._value = value;
}
}
public U8[] Value { get; set; }

public override string TypeName()
{
Expand All @@ -180,15 +168,15 @@ public override string TypeName()
public override byte[] Encode()
{
var result = new List<byte>();
foreach (var v in Value) { result.AddRange(v.Encode()); };
foreach (var v in Value) { result.AddRange(v.Encode()); }
return result.ToArray();
}

public override void Decode(byte[] byteArray, ref int p)
{
var start = p;
var array = new U8[TypeSize];
for (var i = 0; i < array.Length; i++) { var t = new U8(); t.Decode(byteArray, ref p); array[i] = t; };
for (var i = 0; i < array.Length; i++) { var t = new U8(); t.Decode(byteArray, ref p); array[i] = t; }
var bytesLength = p - start;
Bytes = new byte[bytesLength];
System.Array.Copy(byteArray, start, Bytes, 0, bytesLength);
Expand Down
6 changes: 2 additions & 4 deletions Substrate.NetApi.TestNode/ExtrinsicsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@ public async Task Extrinsic_TransactionUnstableUnwatchAsync()
var subscriptionId = await _substrateClient.Unstable.TransactionUnstableSubmitAndWatchAsync(
(subscriptionId, extrinsicUpdate) =>
{
if (extrinsicUpdate.TransactionEvent != TransactionEvent.Validated)
{
if (extrinsicUpdate.TransactionEvent != TransactionEvent.Validated)
{
taskCompletionSource.SetResult(true);
}
taskCompletionSource.SetResult(true);
}
},
method, Alice, _chargeType, 64, cancellationTokenSource.Token);
Expand Down
60 changes: 41 additions & 19 deletions Substrate.NetApi.TestNode/ModuleStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task GetKeysPagedAtTestAsync()

var blockHash = await _substrateClient.Chain.GetBlockHashAsync(blockNumber);

var result = await _substrateClient.State.GetKeysPagedAtAsync(RequestGenerator.GetStorageKeyBytesHash("System", "BlockHash"), 10, null, blockHash.Bytes, CancellationToken.None);
var result = await _substrateClient.State.GetKeysPagedAsync(RequestGenerator.GetStorageKeyBytesHash("System", "BlockHash"), 10, null, blockHash.Bytes, CancellationToken.None);

Assert.IsNotNull(result);
Assert.AreEqual(10, result.Count);
Expand Down Expand Up @@ -68,8 +68,8 @@ public async Task GetMetaDataAt_ShouldWorkAsync()
{
var blockHash = await GivenBlockAsync();

var metadata_1 = await _substrateClient.State.GetMetaDataAtAsync(blockHash, CancellationToken.None);
var metadata_2 = await _substrateClient.State.GetMetaDataAtAsync(Utils.Bytes2HexString(blockHash), CancellationToken.None);
var metadata_1 = await _substrateClient.State.GetMetaDataAsync(blockHash, CancellationToken.None);
var metadata_2 = await _substrateClient.State.GetMetaDataAsync(Utils.Bytes2HexString(blockHash), CancellationToken.None);

Assert.That(metadata_1, Is.Not.Null);
Assert.That(metadata_2, Is.Not.Null);
Expand Down Expand Up @@ -99,8 +99,8 @@ public async Task GetRuntimeVersionAt_ShouldWorkAsync()
{
var blockHash = await GivenBlockAsync();

var runtimeVersion_1 = await _substrateClient.State.GetRuntimeVersionAtAsync(blockHash, CancellationToken.None);
var runtimeVersion_2 = await _substrateClient.State.GetRuntimeVersionAtAsync(Utils.Bytes2HexString(blockHash), CancellationToken.None);
var runtimeVersion_1 = await _substrateClient.State.GetRuntimeVersionAsync(blockHash, CancellationToken.None);
var runtimeVersion_2 = await _substrateClient.State.GetRuntimeVersionAsync(Utils.Bytes2HexString(blockHash), CancellationToken.None);

Assert.That(runtimeVersion_1, Is.Not.Null);
Assert.That(runtimeVersion_2, Is.Not.Null);
Expand Down Expand Up @@ -136,8 +136,8 @@ public async Task GetReadProofAt_ShouldWorkAsync(string storageKeyHex)
var blockHash = await GivenBlockAsync();
var storageKeys = new List<byte[]>() { Utils.HexToByteArray(storageKeyHex) };

var call_1 = await _substrateClient.State.GetReadProofAtAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetReadProofAtAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);
var call_1 = await _substrateClient.State.GetReadProofAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetReadProofAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);

Assert.That(call_1, Is.Not.Null);
Assert.That(call_2, Is.Not.Null);
Expand Down Expand Up @@ -166,8 +166,8 @@ public async Task GetStorageAt_ShouldWorkAsync(string storageKeyHex)
var blockHash = await GivenBlockAsync();
var storageKeys = Utils.HexToByteArray(storageKeyHex);

var call_1 = await _substrateClient.State.GetStorageAtAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetStorageAtAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);
var call_1 = await _substrateClient.State.GetStorageAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetStorageAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);

Assert.That(call_1, Is.Not.Null);
Assert.That(call_2, Is.Not.Null);
Expand Down Expand Up @@ -195,8 +195,8 @@ public async Task GetStorageHashAt_ShouldWorkAsync(string storageKeyHex)
var blockHash = await GivenBlockAsync();
var storageKeys = Utils.HexToByteArray(storageKeyHex);

var call_1 = await _substrateClient.State.GetStorageHashAtAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetStorageHashAtAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);
var call_1 = await _substrateClient.State.GetStorageHashAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetStorageHashAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);

Assert.That(call_1, Is.Not.Null);
Assert.That(call_2, Is.Not.Null);
Expand Down Expand Up @@ -224,8 +224,8 @@ public async Task GetStorageSizeAt_ShouldWorkAsync(string storageKeyHex)
var blockHash = await GivenBlockAsync();
var storageKeys = Utils.HexToByteArray(storageKeyHex);

var call_1 = await _substrateClient.State.GetStorageSizeAtAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetStorageSizeAtAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);
var call_1 = await _substrateClient.State.GetStorageSizeAsync(storageKeys, blockHash, CancellationToken.None);
var call_2 = await _substrateClient.State.GetStorageSizeAsync(storageKeys, Utils.Bytes2HexString(blockHash), CancellationToken.None);

Assert.That(call_1, Is.Not.Null);
Assert.That(call_2, Is.Not.Null);
Expand All @@ -237,21 +237,43 @@ public async Task GetStorageSizeAt_ShouldWorkAsync(string storageKeyHex)
[TestCase("0xf0c365c3cf59d671eb72da0e7a4113c49f1f0515f462cdcf84e0f1d6045dfcbb")]
public async Task SubscribeStorage_ShouldWorkAsync(string storageKeyHex)
{
Action<string, StorageChangeSet> callBack = (key, storacheChangeSet) =>
var tcs = new TaskCompletionSource<bool>();

Action<string, StorageChangeSet> callBack = (key, storageChangeSet) =>
{
Assert.AreEqual("String", key.GetType().Name);
Assert.AreEqual(1, storacheChangeSet.Changes.Length);
Assert.AreEqual(2, storacheChangeSet.Changes[0].Length);
Assert.AreEqual(storageKeyHex, storacheChangeSet.Changes[0][0]);
try
{
Assert.AreEqual("String", key.GetType().Name);
Assert.AreEqual(1, storageChangeSet.Changes.Length);
Assert.AreEqual(2, storageChangeSet.Changes[0].Length);
Assert.AreEqual(storageKeyHex, storageChangeSet.Changes[0][0]);

tcs.SetResult(true); // Signal that the test can continue
}
catch (Exception ex)
{
tcs.SetException(ex); // Propagate the exception to the awaiting test
}
};

var subscriptionId = await _substrateClient.State.SubscribeStorageAsync(new JArray() { storageKeyHex }, callBack, CancellationToken.None);

Thread.Sleep(20 * 1000);
// Wait for the callback to complete or timeout after 20 seconds
if (await Task.WhenAny(tcs.Task, Task.Delay(20000)) == tcs.Task)
{
// The callback completed within 20 seconds
await tcs.Task; // Rethrow exception if the test failed
}
else
{
// The test timed out
Assert.Fail("Test timed out.");
}

await _substrateClient.State.UnsubscribeStorageAsync(subscriptionId, CancellationToken.None);
}


[Test]
public void SubscribeStorageAll_Failure()
{
Expand Down
10 changes: 10 additions & 0 deletions Substrate.NetApi/Attributes/SubstrateNodeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@

namespace Substrate.NetApi.Attributes
{
/// <summary>
/// Substrate Node Type Attribute
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class SubstrateNodeTypeAttribute : Attribute
{
/// <summary>
/// Node Type
/// </summary>
public TypeDefEnum NodeType { get; set; }

/// <summary>
/// Substrate Node Type Attribute
/// </summary>
/// <param name="nodeType"></param>
public SubstrateNodeTypeAttribute(TypeDefEnum nodeType)
{
NodeType = nodeType;
Expand Down
Loading

0 comments on commit 27aa6a7

Please sign in to comment.