Skip to content

Commit

Permalink
Merge pull request #89 from make-software/feat-2-0/csdk-199-seigniora…
Browse files Browse the repository at this point in the history
…ge-allocation-parsing

[CSDK-199] SeigniorageAllocation parsing bug fix
  • Loading branch information
davidatwhiletrue authored Dec 18, 2024
2 parents c18a6ad + 3738240 commit 7bcc82f
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 1 deletion.
44 changes: 44 additions & 0 deletions Casper.Network.SDK.Test/StoredValueTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.IO;
using Casper.Network.SDK.Types;
using NUnit.Framework;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace NetCasperTest
{
public class StoredValueTest
{
[Test]
public void SeigniorageAllocationsTest_V200()
{
string json = File.ReadAllText(TestContext.CurrentContext.TestDirectory +
"/TestData/seigniorage_allocation_v200.json");

var storedValue = JsonSerializer.Deserialize<StoredValue>(json);
Assert.IsNotNull(storedValue);
Assert.IsNotNull(storedValue.EraInfo);
Assert.AreEqual(20, storedValue.EraInfo.SeigniorageAllocations.Count);
Assert.IsTrue(storedValue.EraInfo.SeigniorageAllocations[0].IsDelegator);
Assert.AreEqual("018b46617b2b97e633b36530f2964b3f4c15916235910a2737e83d4fa2c7fad542", storedValue.EraInfo.SeigniorageAllocations[0].DelegatorKind.PublicKey.ToString().ToLower());
Assert.AreEqual("01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6", storedValue.EraInfo.SeigniorageAllocations[0].ValidatorPublicKey.ToString().ToLower());
Assert.AreEqual("2515330120214391", storedValue.EraInfo.SeigniorageAllocations[0].Amount.ToString());
Assert.IsFalse(storedValue.EraInfo.SeigniorageAllocations[1].IsDelegator);
}

[Test]
public void SeigniorageAllocationsTest_V158()
{
string json = File.ReadAllText(TestContext.CurrentContext.TestDirectory +
"/TestData/seigniorage_allocation_v158.json");

var storedValue = JsonSerializer.Deserialize<StoredValue>(json);
Assert.IsNotNull(storedValue);
Assert.IsNotNull(storedValue.EraInfo);
Assert.AreEqual(10, storedValue.EraInfo.SeigniorageAllocations.Count);
Assert.IsTrue(storedValue.EraInfo.SeigniorageAllocations[0].IsDelegator);
Assert.AreEqual("018b46617b2b97e633b36530f2964b3f4c15916235910a2737e83d4fa2c7fad542", storedValue.EraInfo.SeigniorageAllocations[0].DelegatorKind.PublicKey.ToString().ToLower());
Assert.AreEqual("01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6", storedValue.EraInfo.SeigniorageAllocations[0].ValidatorPublicKey.ToString().ToLower());
Assert.AreEqual("4414692857142857", storedValue.EraInfo.SeigniorageAllocations[0].Amount.ToString());
Assert.IsFalse(storedValue.EraInfo.SeigniorageAllocations[1].IsDelegator);
}
}
}
71 changes: 71 additions & 0 deletions Casper.Network.SDK.Test/TestData/seigniorage_allocation_v158.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"EraInfo": {
"seigniorage_allocations": [
{
"Delegator": {
"delegator_public_key": "018b46617b2b97e633b36530f2964b3f4c15916235910a2737e83d4fa2c7fad542",
"validator_public_key": "01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6",
"amount": "4414692857142857"
}
},
{
"Validator": {
"validator_public_key": "01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6",
"amount": "4585307142857143"
}
},
{
"Delegator": {
"delegator_public_key": "0197b79d1a1351f8fb922b9f7f556d2bbfdba5105df9eaa6caa07804c703a641ed",
"validator_public_key": "0190664e16a17594ed2d0e3c279c4cf5894e8db0da15e3b91c938562a1caae32ab",
"amount": "4414692857142857"
}
},
{
"Validator": {
"validator_public_key": "0190664e16a17594ed2d0e3c279c4cf5894e8db0da15e3b91c938562a1caae32ab",
"amount": "4585307142857143"
}
},
{
"Delegator": {
"delegator_public_key": "01a5a5b7328118681638be3e06c8749609280dba4c9daf9aeb3d3464b8839b018a",
"validator_public_key": "01c867ff3cf1d4e4e68fc00922fdcb740304def196e223091dee62012f444b9eba",
"amount": "4414692857142857"
}
},
{
"Validator": {
"validator_public_key": "01c867ff3cf1d4e4e68fc00922fdcb740304def196e223091dee62012f444b9eba",
"amount": "4585307142857143"
}
},
{
"Delegator": {
"delegator_public_key": "0106ed45915392c02b37136618372ac8dde8e0e3b8ee6190b2ca6db539b354ede4",
"validator_public_key": "01f58b94526d280881f79744effebc555426190950d5dfdd2f8aaf10ceaec010c6",
"amount": "4414692857142857"
}
},
{
"Validator": {
"validator_public_key": "01f58b94526d280881f79744effebc555426190950d5dfdd2f8aaf10ceaec010c6",
"amount": "4585307142857143"
}
},
{
"Delegator": {
"delegator_public_key": "0184f6d260f4ee6869ddb36affe15456de6ae045278fa2f467bb677561ce0dad55",
"validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
"amount": "4414692857142857"
}
},
{
"Validator": {
"validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
"amount": "4585307142857143"
}
}
]
}
}
156 changes: 156 additions & 0 deletions Casper.Network.SDK.Test/TestData/seigniorage_allocation_v200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"EraInfo": {
"seigniorage_allocations": [
{
"Delegator": {
"delegator_kind": {
"PublicKey": "018b46617b2b97e633b36530f2964b3f4c15916235910a2737e83d4fa2c7fad542"
},
"validator_public_key": "01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6",
"amount": "2515330120214391"
}
},
{
"Validator": {
"validator_public_key": "01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6",
"amount": "2728720430156545"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "018b46617b2b97e633b36530f2964b3f4c15916235910a2737e83d4fa2c7fad542"
},
"validator_public_key": "01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6",
"amount": "109303520813010"
}
},
{
"Validator": {
"validator_public_key": "01509254f22690fbe7fb6134be574c4fbdb060dfa699964653b99753485e518ea6",
"amount": "118554941151112"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "0197b79d1a1351f8fb922b9f7f556d2bbfdba5105df9eaa6caa07804c703a641ed"
},
"validator_public_key": "0190664e16a17594ed2d0e3c279c4cf5894e8db0da15e3b91c938562a1caae32ab",
"amount": "8599696498056110"
}
},
{
"Validator": {
"validator_public_key": "0190664e16a17594ed2d0e3c279c4cf5894e8db0da15e3b91c938562a1caae32ab",
"amount": "9377950843219784"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "0197b79d1a1351f8fb922b9f7f556d2bbfdba5105df9eaa6caa07804c703a641ed"
},
"validator_public_key": "0190664e16a17594ed2d0e3c279c4cf5894e8db0da15e3b91c938562a1caae32ab",
"amount": "285067736921916"
}
},
{
"Validator": {
"validator_public_key": "0190664e16a17594ed2d0e3c279c4cf5894e8db0da15e3b91c938562a1caae32ab",
"amount": "310701366981535"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "01a5a5b7328118681638be3e06c8749609280dba4c9daf9aeb3d3464b8839b018a"
},
"validator_public_key": "01c867ff3cf1d4e4e68fc00922fdcb740304def196e223091dee62012f444b9eba",
"amount": "5976757455713484"
}
},
{
"Validator": {
"validator_public_key": "01c867ff3cf1d4e4e68fc00922fdcb740304def196e223091dee62012f444b9eba",
"amount": "6492754998004464"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "01a5a5b7328118681638be3e06c8749609280dba4c9daf9aeb3d3464b8839b018a"
},
"validator_public_key": "01c867ff3cf1d4e4e68fc00922fdcb740304def196e223091dee62012f444b9eba",
"amount": "162277940193805"
}
},
{
"Validator": {
"validator_public_key": "01c867ff3cf1d4e4e68fc00922fdcb740304def196e223091dee62012f444b9eba",
"amount": "176125500882714"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "0106ed45915392c02b37136618372ac8dde8e0e3b8ee6190b2ca6db539b354ede4"
},
"validator_public_key": "01f58b94526d280881f79744effebc555426190950d5dfdd2f8aaf10ceaec010c6",
"amount": "6111063397723576"
}
},
{
"Validator": {
"validator_public_key": "01f58b94526d280881f79744effebc555426190950d5dfdd2f8aaf10ceaec010c6",
"amount": "6660504858490961"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "0106ed45915392c02b37136618372ac8dde8e0e3b8ee6190b2ca6db539b354ede4"
},
"validator_public_key": "01f58b94526d280881f79744effebc555426190950d5dfdd2f8aaf10ceaec010c6",
"amount": "183204228041446"
}
},
{
"Validator": {
"validator_public_key": "01f58b94526d280881f79744effebc555426190950d5dfdd2f8aaf10ceaec010c6",
"amount": "199637730476608"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "0184f6d260f4ee6869ddb36affe15456de6ae045278fa2f467bb677561ce0dad55"
},
"validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
"amount": "2170319328593039"
}
},
{
"Validator": {
"validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
"amount": "2366902069827651"
}
},
{
"Delegator": {
"delegator_kind": {
"PublicKey": "0184f6d260f4ee6869ddb36affe15456de6ae045278fa2f467bb677561ce0dad55"
},
"validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
"amount": "217749920954248"
}
},
{
"Validator": {
"validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
"amount": "237377113583604"
}
}
]
}
}
4 changes: 3 additions & 1 deletion Casper.Network.SDK/Types/SeigniorageAllocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ public override SeigniorageAllocation Read(
{
var field = reader.GetString();
reader.Read();
if (field == "delegator_public_key")
if (field == "delegator_kind")
delegatorKind = JsonSerializer.Deserialize<DelegatorKind>(ref reader, options);
else if (field == "delegator_public_key")
delegatorKind = new DelegatorKind() { PublicKey = PublicKey.FromHexString(reader.GetString()) };
else if (field == "validator_public_key")
validatorPk = reader.GetString();
else if (field == "amount")
Expand Down

0 comments on commit 7bcc82f

Please sign in to comment.