Skip to content

Commit

Permalink
Merge pull request #30 from make-software/support-node-v1415
Browse files Browse the repository at this point in the history
Support node v1415
  • Loading branch information
mrkara authored Jul 14, 2023
2 parents 3cd061a + 631651b commit 258350a
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Fixed: any bug fixes)
[comment]: <> (Security: in case of vulnerabilities)

## [1.1.2]

### Added
* New RPC method `GetEraSummary()`.
* New global state key `era-summary-0000...0000`.

## [1.1.1]

### Fixed
Expand All @@ -33,6 +39,7 @@ All notable changes to this project will be documented in this file. The format
### Added
* Initial release of Casper .NET SDK.

[1.1.2]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.2
[1.1.1]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.1
[1.1.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.0
[1.0.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.0.0
6 changes: 3 additions & 3 deletions Casper.Network.SDK.Test/NctlContractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task CallContractByNameTest()
"counter_inc",
null,
_faucetKey.PublicKey,
15_000_000,
150_000_000,
_chainName,
1, //gasPrice=1
24*3_600_000); //ttl='1day'
Expand All @@ -115,7 +115,7 @@ public async Task CallContractByHashTest()
"counter_inc",
null,
_faucetKey.PublicKey,
15_000_000,
150_000_000,
_chainName);
deploy.Sign(_faucetKey);

Expand Down Expand Up @@ -205,4 +205,4 @@ public async Task GetItemTest()
Assert.IsTrue((int)count > 0);
}
}
}
}
35 changes: 34 additions & 1 deletion Casper.Network.SDK.Test/NctlGetXTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,39 @@ public async Task GetAuctionInfoTest()
Assert.Fail(e.RpcError.Message);
}
}

[Test]
public async Task GetEraSummaryTest()
{
try
{
var response = await _client.GetEraSummary();
var result = response.Parse();
Assert.IsTrue(result.EraSummary.EraId > 0);
Assert.IsNotNull(result.EraSummary.StoredValue.EraInfo);
Assert.IsTrue(result.EraSummary.StoredValue.EraInfo.SeigniorageAllocations.Count > 0);

var response2 = await _client.GetEraSummary(result.EraSummary.BlockHash);
var result2 = response2.Parse();
Assert.IsTrue(result2.EraSummary.EraId > 0);
Assert.IsNotNull(result2.EraSummary.StoredValue.EraInfo);
Assert.IsTrue(result2.EraSummary.StoredValue.EraInfo.SeigniorageAllocations.Count > 0);

var response3 = await _client.GetBlock(result.EraSummary.BlockHash);
var result3 = response3.Parse();
Assert.IsNotNull(result3.Block.Hash);

var response4 = await _client.GetEraSummary((int)result3.Block.Header.Height);
var result4 = response4.Parse();
Assert.IsTrue(result4.EraSummary.EraId > 0);
Assert.IsNotNull(result4.EraSummary.StoredValue.EraInfo);
Assert.IsTrue(result4.EraSummary.StoredValue.EraInfo.SeigniorageAllocations.Count > 0);
}
catch (RpcClientException e)
{
Assert.Fail(e.RpcError.Message);
}
}

[Test]
public async Task GetValidatorChangesTest()
Expand Down Expand Up @@ -206,4 +239,4 @@ public async Task GetRpcSchemaTest()
}
}
}
}
}
4 changes: 2 additions & 2 deletions Casper.Network.SDK.Test/NctlMyDictContractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task CallVersionedContractByNameTest()
"store_mydict",
namedArgs,
_faucetKey.PublicKey,
100_000_000,
1_000_000_000,
_chainName);
deploy.Sign(_faucetKey);

Expand Down Expand Up @@ -176,4 +176,4 @@ public async Task GetDictItemByKey()
Assert.AreEqual("second-entry", (string) result.StoredValue.CLValue);
}
}
}
}
12 changes: 11 additions & 1 deletion Casper.Network.SDK.Test/NctlQueryGlobalStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public async Task QueryURef()
Assert.IsNotNull(clValue);
}

[Test]
public async Task QueryEraSummary()
{
var rpcResponse = await _client.QueryGlobalState("era-summary-0000000000000000000000000000000000000000000000000000000000000000");
var eraInfo = rpcResponse.Parse().StoredValue.EraInfo;
Assert.IsNotNull(eraInfo);
Assert.IsNotNull(eraInfo.SeigniorageAllocations);
Assert.IsTrue(eraInfo.SeigniorageAllocations.Count > 0);
}

[Test]
public async Task QueryWrongKey()
{
Expand All @@ -51,4 +61,4 @@ public async Task QueryWrongKey()
}
}
}
}
}
6 changes: 3 additions & 3 deletions Casper.Network.SDK.Test/NctlTransferTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task DelegateTokens()
_myAccount.PublicKey,
validatorPk,
600_000_000_000,
5_000_000_000,
10_000_000_000,
_chainName);
deploy.Sign(_myAccount);

Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task UndelegateTokens()
_myAccount.PublicKey,
validatorPk,
10_000_000_000,
5_000_000_000,
10_000_000_000,
_chainName);
deploy.Sign(_myAccount);

Expand All @@ -190,4 +190,4 @@ public async Task UndelegateTokens()
Assert.IsTrue(execResult.IsSuccess);
}
}
}
}
Binary file modified Casper.Network.SDK.Test/TestData/delegate.wasm
Binary file not shown.
Binary file modified Casper.Network.SDK.Test/TestData/undelegate.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions Casper.Network.SDK/Casper.Network.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<FileVersion>1.1.1</FileVersion>
<PackageVersion>1.1.1</PackageVersion>
<AssemblyVersion>1.1.2.0</AssemblyVersion>
<FileVersion>1.1.2</FileVersion>
<PackageVersion>1.1.2</PackageVersion>
<Title>Casper.Network.SDK</Title>
<Authors>make-software</Authors>
<PackageProjectUrl>https://github.com/make-software/casper-net-sdk</PackageProjectUrl>
Expand Down
19 changes: 19 additions & 0 deletions Casper.Network.SDK/JsonRpc/CasperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ public GetEraInfoBySwitchBlock(int height) : base("chain_get_era_info_by_switch_
}
}

public class GetEraSummary : RpcMethod
{
/// <summary>
/// Retrieves current era info from the network given a block hash
/// </summary>
/// <param name="blockHash">Block hash.</param>
public GetEraSummary(string blockHash) : base("chain_get_era_summary", blockHash)
{
}

/// <summary>
/// Retrieves current era info from the network given a block height
/// </summary>
/// <param name="height">Block height.</param>
public GetEraSummary(int height) : base("chain_get_era_summary", height)
{
}
}

public class GetDictionaryItem : RpcMethod
{
/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions Casper.Network.SDK/JsonRpc/ResultTypes/GetEraSummaryResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
using Casper.Network.SDK.Types;

namespace Casper.Network.SDK.JsonRpc.ResultTypes
{
/// <summary>
/// Result for "chain_get_era_summary" RPC response.
/// </summary>
public class GetEraSummaryResult : RpcResult
{
/// <summary>
/// The Era summary.
/// </summary>
[JsonPropertyName("era_summary")]
public EraSummary EraSummary { get; init; }
}
}
22 changes: 21 additions & 1 deletion Casper.Network.SDK/NetCasperClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@ public async Task<RpcResponse<GetEraInfoBySwitchBlockResult>> GetEraInfoBySwitch
var method = new GetEraInfoBySwitchBlock(blockHeight);
return await SendRpcRequestAsync<GetEraInfoBySwitchBlockResult>(method);
}

/// <summary>
/// Request current Era Info from the network given a block hash
/// </summary>
/// <param name="blockHash">Block hash. Null for the latest block.</param>
public async Task<RpcResponse<GetEraSummaryResult>> GetEraSummary(string blockHash = null)
{
var method = new GetEraSummary(blockHash);
return await SendRpcRequestAsync<GetEraSummaryResult>(method);
}

/// <summary>
/// Request current Era Info from the network given a block hash
/// </summary>
/// <param name="blockHeight">Block height.</param>
public async Task<RpcResponse<GetEraSummaryResult>> GetEraSummary(int blockHeight)
{
var method = new GetEraSummary(blockHeight);
return await SendRpcRequestAsync<GetEraSummaryResult>(method);
}

/// <summary>
/// Lookup a dictionary item from its dictionary item key.
Expand Down Expand Up @@ -533,4 +553,4 @@ protected virtual void Dispose(bool disposing)
}
}
}
}
}
23 changes: 20 additions & 3 deletions Casper.Network.SDK/Types/GlobalStateKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public enum KeyIdentifier
/// <summary>
/// Dictionary keys store dictionary items.
/// </summary>
Dictionary = 0x09
Dictionary = 0x09,
/// <summary>
/// Era Summary keys store current era info.
/// </summary>
EraSummary = 0x11,
}

/// <summary>
Expand Down Expand Up @@ -127,7 +131,8 @@ public static GlobalStateKey FromString(string value)
return new WithdrawKey(value);
if (value.StartsWith("dictionary"))
return new DictionaryKey(value);

if (value.StartsWith("era-summary-"))
return new EraSummaryKey(value);
throw new ArgumentException($"Key not valid. Unknown key prefix.");
}

Expand Down Expand Up @@ -401,4 +406,16 @@ public DictionaryKey(byte[] key) : this("dictionary-" + CEP57Checksum.Encode(key
{
}
}
}

/// <summary>
/// Key used to query current era info.
/// Format: 32-byte length with prefix 'era-summary-'.
/// </summary>
public class EraSummaryKey : GlobalStateKey
{
public EraSummaryKey(string key) : base(key, "era-summary-")
{
KeyIdentifier = KeyIdentifier.EraSummary;
}
}
}
29 changes: 27 additions & 2 deletions Casper.Network.SDK/Types/SeigniorageAllocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,33 @@ public override void Write(
SeigniorageAllocation value,
JsonSerializerOptions options)
{
throw new NotImplementedException("Write method for SeigniorageAllocation not yet implemented");
if (value.IsDelegator)
{
writer.WriteStartObject();
writer.WritePropertyName("Delegator");
writer.WriteStartObject();
writer.WritePropertyName("delegator_public_key");
writer.WriteStringValue(value.DelegatorPublicKey.ToString());
writer.WritePropertyName("validator_public_key");
writer.WriteStringValue(value.ValidatorPublicKey.ToString());
writer.WritePropertyName("amount");
writer.WriteStringValue(value.Amount.ToString());
writer.WriteEndObject();
writer.WriteEndObject();
}
else //validator
{
writer.WriteStartObject();
writer.WritePropertyName("Validator");
writer.WriteStartObject();
writer.WritePropertyName("validator_public_key");
writer.WriteStringValue(value.ValidatorPublicKey.ToString());
writer.WritePropertyName("amount");
writer.WriteStringValue(value.Amount.ToString());
writer.WriteEndObject();
writer.WriteEndObject();
}
}
}
}
}
}

0 comments on commit 258350a

Please sign in to comment.