Skip to content

Commit

Permalink
release 0.9.24-rc1 (#89)
Browse files Browse the repository at this point in the history
* release candidate 1

* added CheckMetadataHash
added metadata v15
added runtime calls metadata

* added interface and simple metadata call

* added test

* fixed tests, and directed to polkadot
  • Loading branch information
darkfriend77 authored Jul 31, 2024
1 parent 3448b93 commit 1974420
Show file tree
Hide file tree
Showing 39 changed files with 1,365 additions and 556 deletions.
12 changes: 6 additions & 6 deletions Substrate.NetApi.TestNode/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task GetSystemChainTestAsync()
{
var result = await _substrateClient.System.ChainAsync(CancellationToken.None);

Assert.AreEqual("Bajun Kusama", result);
Assert.AreEqual("Polkadot", result);
}

[Test]
Expand Down Expand Up @@ -80,9 +80,9 @@ public async Task GetSystemPropertiesTestAsync()
{
var result = await _substrateClient.System.PropertiesAsync(CancellationToken.None);

Assert.AreEqual(1337, result.Ss58Format);
Assert.AreEqual(12, result.TokenDecimals);
Assert.AreEqual("BAJU", result.TokenSymbol);
Assert.AreEqual(0, result.Ss58Format);
Assert.AreEqual(10, result.TokenDecimals);
Assert.AreEqual("DOT", result.TokenSymbol);
}

[Test]
Expand All @@ -93,7 +93,7 @@ public async Task GetBlockNumberTestAsync()

var result = await _substrateClient.Chain.GetBlockHashAsync(blockNumber, CancellationToken.None);

Assert.AreEqual("0x35A06BFEC2EDF0FF4BE89A6428CCD9FF5BD0167D618C5A0D4341F9600A458D14", result.Value);
Assert.AreEqual("0x91B171BB158E2D3848FA23A9F1C25182FB8E20313B2C1EB49219DA7A70CE90C3", result.Value);
}

[Test]
Expand All @@ -110,7 +110,7 @@ public async Task GetAccountInfoTestAsync()
var result = await _substrateClient.GetStorageAsync<Arr32U8>(parameters, CancellationToken.None);

Assert.IsNotNull(result);
Assert.AreEqual("0x35A06BFEC2EDF0FF4BE89A6428CCD9FF5BD0167D618C5A0D4341F9600A458D14", Utils.Bytes2HexString(result.Value.Select(p => p.Value).ToArray()));
Assert.AreEqual("0x91B171BB158E2D3848FA23A9F1C25182FB8E20313B2C1EB49219DA7A70CE90C3", Utils.Bytes2HexString(result.Value.Select(p => p.Value).ToArray()));

blockNumber.Create(999999999);

Expand Down
28 changes: 28 additions & 0 deletions Substrate.NetApi.TestNode/ModuleChainTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using StreamJsonRpc;
using Substrate.NetApi.Model.Rpc;
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Primitive;

namespace Substrate.NetApi.TestNode
{
public class ModuleChainTest : NodeTest
{
[Test]
public async Task GetBlockAsyncTestAsync()
{
var result = await _substrateClient.Chain.GetBlockAsync(CancellationToken.None);

Assert.IsNotNull(result);
}


}
}
4 changes: 2 additions & 2 deletions Substrate.NetApi.TestNode/ModulePaymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Substrate.NetApi.TestNode
public class ModulePaymentTest : NodeTest
{
[Test]
[TestCase("0x5d02840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270128da3e1cd19a10e3bbdd37ef0f24a0424a6febc1a6adeaa46ef0294a0f300e795dc4cfd380345b4fa53e28a8c258bd4ff4b0ed6554b78fc292d3aed0659ac48a45031989000f0700c87277c3912dfe4107ab28c32309c6b10ca6c0ad6ebc540fbfd26674db51b5291f0000005b2c765c5c43be65")]
[TestCase("0x4902840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c582701b475d9d1d45cc3f372607f3542ba5671a9328303610e4b6274e7e574eeff3064a7d1a2bfb807d7a0577f9fc2b47925db22ffb9ec8c1bf04793c5a3a789edf28245020101000005030094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270700e40b5402")]
public async Task QueryFeeDetailTestAsync(string extrinsicHex)
{
await _substrateClient.ConnectAsync(false, CancellationToken.None);
Expand All @@ -23,7 +23,7 @@ public async Task QueryFeeDetailTestAsync(string extrinsicHex)
}

[Test]
[TestCase("0x5d02840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270128da3e1cd19a10e3bbdd37ef0f24a0424a6febc1a6adeaa46ef0294a0f300e795dc4cfd380345b4fa53e28a8c258bd4ff4b0ed6554b78fc292d3aed0659ac48a45031989000f0700c87277c3912dfe4107ab28c32309c6b10ca6c0ad6ebc540fbfd26674db51b5291f0000005b2c765c5c43be65")]
[TestCase("0x4902840094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c582701b475d9d1d45cc3f372607f3542ba5671a9328303610e4b6274e7e574eeff3064a7d1a2bfb807d7a0577f9fc2b47925db22ffb9ec8c1bf04793c5a3a789edf28245020101000005030094546ff56643b8c0fed386347d7a8cd0b995383125a0fc0f0e45f0e33a6c58270700e40b5402")]

public async Task QueryInfoTestAsync(string extrinsicHex)
{
Expand Down
47 changes: 47 additions & 0 deletions Substrate.NetApi.TestNode/ModuleRuntimeCallTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using NUnit.Framework;
using Substrate.NetApi.Model.Types.Metadata;
using Substrate.NetApi.Model.Types.Metadata.V14;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Primitive;

namespace Substrate.NetApi.TestNode
{
public class ModuleRuntimeCallTest : NodeTest
{
[Test]
public async Task GetMetadataTestAsync()
{
var result14 = await _substrateClient.RuntimeCall.MetadataAsync(CancellationToken.None);
var mdv14 = new RuntimeMetadata<RuntimeMetadataV14>();
mdv14.Create(result14.Value.Select(p => p.Value).ToArray());
Assert.IsNotNull(mdv14);
}

[Test]
public async Task GetMetadataAtVersionTestAsync()
{
var result14 = await _substrateClient.RuntimeCall.MetadataAtVersionAsync(14, CancellationToken.None);
var mdv14 = new RuntimeMetadata<RuntimeMetadataV14>();
mdv14.Create(result14.Value.Value.Select(p => p.Value).ToArray());
Assert.IsNotNull(mdv14);

var result15 = await _substrateClient.RuntimeCall.MetadataAtVersionAsync(15, CancellationToken.None);
var mdv15 = new RuntimeMetadata<RuntimeMetadataV15>();
mdv15.Create(result15.Value.Value.Select(p => p.Value).ToArray());
Assert.IsNotNull(mdv15);
}

[Test]
public async Task GetMetadataVersionsTestAsync()
{
var result = await _substrateClient.RuntimeCall.MetadataVersionsAsync(CancellationToken.None);

Assert.IsNotNull(result);
Assert.AreEqual(14, result.Value[0].Value);
Assert.AreEqual(15, result.Value[1].Value);
}
}
}
10 changes: 5 additions & 5 deletions Substrate.NetApi.TestNode/ModuleStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public async Task GetKeysPagedAtTestAsync()
}

[Test]
[TestCase("0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746b4def25cfda6ef3a00000000")]
public async Task GetQueryStorageAtAsyncTestAsync(string storageKeyHex)
[TestCase("0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac", "0xa6aeb4a363120918b0a844e2bb17113d7d96f512c025dacd0fa015b9125669cf")]
public async Task GetQueryStorageAtAsyncTestAsync(string storageKeyHex, string blockHash)
{
var storageKeys = new List<byte[]>() { Utils.HexToByteArray(storageKeyHex) };

var results = await _substrateClient.State.GetQueryStorageAtAsync(storageKeys, string.Empty, CancellationToken.None);
var results = await _substrateClient.State.GetQueryStorageAtAsync(storageKeys, blockHash, CancellationToken.None);

Assert.IsNotNull(results);
Assert.IsNotNull(results.First());

var result = results.First();
Assert.True(result.Block.Value.StartsWith("0x"));
Assert.AreEqual(1, result.Changes.Length);
Assert.AreEqual("0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746b4def25cfda6ef3a00000000", result.Changes[0][0]);
Assert.AreEqual("0x35a06bfec2edf0ff4be89a6428ccd9ff5bd0167d618c5a0d4341f9600a458d14", result.Changes[0][1]);
Assert.AreEqual("0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac", result.Changes[0][0]);
Assert.AreEqual("0xc50c4e01", result.Changes[0][1]);
}

[Test]
Expand Down
12 changes: 7 additions & 5 deletions Substrate.NetApi.TestNode/NodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Substrate.NetApi.Model.Types.Base;

namespace Substrate.NetApi.TestNode
{
public abstract class NodeTest
{
protected const string WebSocketUrl = "ws://rpc-parachain.bajun.network";
//protected const string WebSocketUrl = "wss://rpc-paseo.bajun.network";
//protected const string WebSocketUrl = "wss://rpc-parachain.bajun.network";
protected const string WebSocketUrl = "wss://polkadot-rpc.dwellir.com";

protected SubstrateClient _substrateClient;

Expand Down Expand Up @@ -43,14 +46,13 @@ public void DisposeClient()
/// Return the 20th hash block from now (totally arbitrary)
/// </summary>
/// <returns></returns>
protected async Task<byte[]> GivenBlockAsync()
protected async Task<Hash> GivenBlockAsync()
{
var lastBlockData = await _substrateClient.Chain.GetBlockAsync();
var lastBlockNumber = lastBlockData.Block.Header.Number.Value;

var blockNumber = new Model.Types.Base.BlockNumber();
blockNumber.Create((uint)(lastBlockNumber - 20));
return (await _substrateClient.Chain.GetBlockHashAsync(blockNumber)).Bytes;
var blockNumber = new BlockNumber((uint)(lastBlockNumber - 20));
return await _substrateClient.Chain.GetBlockHashAsync(blockNumber);
}
}
}
2 changes: 1 addition & 1 deletion Substrate.NetApi/Attributes/SubstrateNodeType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Substrate.NetApi.Model.Types.Metadata.V14;
using Substrate.NetApi.Model.Types.Metadata.Base;

namespace Substrate.NetApi.Attributes
{
Expand Down
13 changes: 8 additions & 5 deletions Substrate.NetApi/Model/Meta/MetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Substrate.NetApi.Model.Types.Metadata;
using Substrate.NetApi.Model.Types.Metadata.Base;
using Substrate.NetApi.Model.Types.Metadata.Base.Portable;
using Substrate.NetApi.Model.Types.Metadata.V14;
using Substrate.NetApi.Model.Types.Metadata.V15;

namespace Substrate.NetApi.Model.Meta
{
Expand All @@ -18,7 +21,7 @@ public class MetaData
/// </summary>
/// <param name="rtmd"></param>
/// <param name="origin"></param>
public MetaData(RuntimeMetadata rtmd, string origin = "unknown")
public MetaData(RuntimeMetadata<RuntimeMetadataV14> rtmd, string origin = "unknown")
{
Origin = origin;
Magic = Utils.Bytes2HexString(rtmd.MetaDataInfo.Magic.Bytes);
Expand Down Expand Up @@ -255,7 +258,7 @@ public static Dictionary<uint, NodeType> CreateNodeTypeDict(PortableType[] types
/// <param name="modules"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static Dictionary<uint, PalletModule> CreateModuleDict(PalletMetadata[] modules)
public static Dictionary<uint, PalletModule> CreateModuleDict(PalletMetadataV14[] modules)
{
var result = new Dictionary<uint, PalletModule>();

Expand Down Expand Up @@ -286,7 +289,7 @@ public static Dictionary<uint, PalletModule> CreateModuleDict(PalletMetadata[] m
Modifier = entry.StorageModifier.Value,
StorageType = entry.StorageType.Value,
Default = entry.StorageDefault.Value.Select(p => p.Value).ToArray(),
Docs = entry.Documentation.Value.Select(p => p.Value).ToArray(),
Docs = entry.Docs.Value.Select(p => p.Value).ToArray(),
};

switch (entry.StorageType.Value)
Expand Down Expand Up @@ -339,7 +342,7 @@ public static Dictionary<uint, PalletModule> CreateModuleDict(PalletMetadata[] m
Name = constant.ConstantName.Value,
TypeId = (uint)constant.ConstantType.Value,
Value = constant.ConstantValue.Value.Select(p => p.Value).ToArray(),
Docs = constant.Documentation.Value.Select(p => p.Value).ToArray()
Docs = constant.Docs.Value.Select(p => p.Value).ToArray()
};
}

Expand All @@ -361,7 +364,7 @@ public static Dictionary<uint, PalletModule> CreateModuleDict(PalletMetadata[] m
/// </summary>
/// <param name="extrinsic"></param>
/// <returns></returns>
private static ExtrinsicMetadata CreateExtrinsic(ExtrinsicMetadataStruct extrinsic)
private static ExtrinsicMetadata CreateExtrinsic(ExtrinsicMetadataV14 extrinsic)
{
return new ExtrinsicMetadata()
{
Expand Down
2 changes: 1 addition & 1 deletion Substrate.NetApi/Model/Meta/MetadataTree.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Substrate.NetApi.Model.Types.Metadata.V14;
using Substrate.NetApi.Model.Types.Metadata.Base;

namespace Substrate.NetApi.Model.Meta
{
Expand Down
12 changes: 12 additions & 0 deletions Substrate.NetApi/Model/Types/Metadata/Base/ByteGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Primitive;

namespace Substrate.NetApi.Model.Types.Metadata.Base
{
/// <summary>
/// Byte Getter
/// </summary>
public class ByteGetter : BaseVec<U8>
{
}
}
34 changes: 34 additions & 0 deletions Substrate.NetApi/Model/Types/Metadata/Base/ErrorMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Metadata.Base;
using System;

namespace Substrate.NetApi.Model.Types.Metadata.V14
{
/// <summary>
/// Error Metadata
/// </summary>
public class ErrorMetadata : BaseType
{
/// <inheritdoc/>
public override byte[] Encode()
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public override void Decode(byte[] byteArray, ref int p)
{
var start = p;

ErrorType = new TType();
ErrorType.Decode(byteArray, ref p);

TypeSize = p - start;
}

/// <summary>
/// Error Type
/// </summary>
public TType ErrorType { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Metadata.Base;
using Substrate.NetApi.Model.Types.Primitive;
using System;

namespace Substrate.NetApi.Model.Types.Metadata.V14
{
Expand Down
46 changes: 46 additions & 0 deletions Substrate.NetApi/Model/Types/Metadata/Base/MetaDataInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Substrate.NetApi.Model.Types.Base;
using Substrate.NetApi.Model.Types.Primitive;
using System;

namespace Substrate.NetApi.Model.Types.Metadata.Base
{
/// <summary>
/// Meta Data Info Type
/// </summary>
public class MetaDataInfo : BaseType
{
/// <inheritdoc/>
public override byte[] Encode()
{
throw new NotImplementedException();
}

/// <summary>
/// Decode from byte array
/// </summary>
/// <param name="byteArray"></param>
/// <param name="p"></param>
public override void Decode(byte[] byteArray, ref int p)
{
var start = p;

Magic = new U32();
Magic.Decode(byteArray, ref p);

Version = new U8();
Version.Decode(byteArray, ref p);

TypeSize = p - start;
}

/// <summary>
/// Magic
/// </summary>
public U32 Magic { get; private set; }

/// <summary>
/// Version
/// </summary>
public U8 Version { get; private set; }
}
}
Loading

0 comments on commit 1974420

Please sign in to comment.