Skip to content

Commit bd8690d

Browse files
committed
feat: implement vote power
1 parent e227a9d commit bd8690d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+640
-156
lines changed

Libplanet.Action.Tests/ActionContextTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Immutable;
2+
using System.Numerics;
23
using Libplanet.Action.State;
34
using Libplanet.Action.Tests.Mocks;
45
using Libplanet.Crypto;
@@ -35,6 +36,7 @@ public ActionContextTest()
3536
hash,
3637
DateTimeOffset.UtcNow,
3738
key.PublicKey,
39+
BigInteger.One,
3840
VoteFlag.PreCommit).Sign(key),
3941
}.ToImmutableArray());
4042
}

Libplanet.Action.Tests/ActionEvaluationTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Immutable;
2+
using System.Numerics;
23
using Bencodex.Types;
34
using Libplanet.Action.State;
45
using Libplanet.Action.Tests.Common;
@@ -46,6 +47,7 @@ public void Constructor()
4647
hash,
4748
DateTimeOffset.UtcNow,
4849
key.PublicKey,
50+
BigInteger.One,
4951
VoteFlag.PreCommit).Sign(key),
5052
}.ToImmutableArray());
5153
IWorld world = new World(new MockWorldState());

Libplanet.Action.Tests/Sys/InitializeTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void ExecuteInNonGenesis()
9191
hash,
9292
DateTimeOffset.UtcNow,
9393
key.PublicKey,
94+
BigInteger.One,
9495
VoteFlag.PreCommit).Sign(key),
9596
}.ToImmutableArray());
9697
var context = new ActionContext(

Libplanet.Benchmarks/Commit.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Immutable;
33
using System.Linq;
4+
using System.Numerics;
45
using BenchmarkDotNet.Attributes;
56
using Libplanet.Crypto;
67
using Libplanet.Types.Blocks;
@@ -65,6 +66,7 @@ private void SetupVotes()
6566
_blockHash,
6667
DateTimeOffset.UtcNow,
6768
_privateKeys[x].PublicKey,
69+
BigInteger.One,
6870
VoteFlag.PreCommit).Sign(_privateKeys[x]))
6971
.ToArray();
7072
}

Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Immutable;
33
using System.Linq;
4+
using System.Numerics;
45
using Bencodex.Types;
56
using Libplanet.Action;
67
using Libplanet.Action.Loader;
@@ -196,6 +197,7 @@ private void AddBlock(ImmutableArray<Transaction> transactions)
196197
block.Hash,
197198
DateTimeOffset.UtcNow,
198199
pk.PublicKey,
200+
BigInteger.One,
199201
VoteFlag.PreCommit).Sign(pk)).ToImmutableArray()));
200202
MinedBlocks = MinedBlocks
201203
.SetItem(

Libplanet.Explorer.Tests/GraphTypes/BlockCommitTypeTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
4+
using System.Numerics;
45
using GraphQL;
56
using GraphQL.Types;
67
using GraphQL.Execution;
@@ -28,6 +29,7 @@ public async void Query()
2829
blockHash,
2930
DateTimeOffset.Now,
3031
privateKey.PublicKey,
32+
BigInteger.One,
3133
VoteFlag.PreCommit).Sign(privateKey);
3234
var blockCommit = new BlockCommit(1, 0, blockHash, ImmutableArray.Create(vote));
3335

Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
4+
using System.Numerics;
45
using System.Security.Cryptography;
56
using GraphQL;
67
using GraphQL.Execution;
@@ -31,6 +32,7 @@ public async void Query()
3132
lastBlockHash,
3233
DateTimeOffset.Now,
3334
privateKey.PublicKey,
35+
BigInteger.One,
3436
VoteFlag.PreCommit).Sign(privateKey));
3537
var lastBlockCommit = new BlockCommit(1, 0, lastBlockHash, lastVotes);
3638
var preEval = new BlockContent(
@@ -70,6 +72,7 @@ public async void Query()
7072
blockHash
7173
timestamp
7274
validatorPublicKey
75+
validatorPower
7376
flag
7477
signature
7578
}
@@ -117,6 +120,7 @@ public async void Query()
117120
{ "blockHash", lastVotes[0].BlockHash.ToString() },
118121
{ "timestamp", new DateTimeOffsetGraphType().Serialize(lastVotes[0].Timestamp) },
119122
{ "validatorPublicKey", lastVotes[0].ValidatorPublicKey.ToString() },
123+
{ "validatorPower", lastVotes[0].ValidatorPower },
120124
{ "flag", lastVotes[0].Flag.ToString() },
121125
{ "signature", ByteUtil.Hex(lastVotes[0].Signature) },
122126
}

Libplanet.Explorer.Tests/GraphTypes/VoteTypeTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Numerics;
34
using GraphQL;
45
using GraphQL.Types;
56
using GraphQL.Execution;
@@ -27,6 +28,7 @@ public async void Query()
2728
blockHash,
2829
DateTimeOffset.Now,
2930
privateKey.PublicKey,
31+
123,
3032
VoteFlag.PreCommit).Sign(privateKey);
3133

3234
var query =
@@ -36,6 +38,7 @@ public async void Query()
3638
blockHash
3739
timestamp
3840
validatorPublicKey
41+
validatorPower
3942
flag
4043
signature
4144
}";
@@ -54,6 +57,7 @@ public async void Query()
5457
Assert.Equal(vote.BlockHash.ToString(), resultData["blockHash"]);
5558
Assert.Equal(new DateTimeOffsetGraphType().Serialize(vote.Timestamp), resultData["timestamp"]);
5659
Assert.Equal(vote.ValidatorPublicKey.ToString(), resultData["validatorPublicKey"]);
60+
Assert.Equal(vote.ValidatorPower, resultData["validatorPower"]);
5761
Assert.Equal(vote.Flag.ToString(), resultData["flag"]);
5862
Assert.Equal(ByteUtil.Hex(vote.Signature), resultData["signature"]);
5963
}

Libplanet.Explorer.Tests/Indexing/BlockChainIndexTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
44
using System.Linq;
5+
using System.Numerics;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Libplanet.Crypto;
@@ -57,6 +58,7 @@ await index.SynchronizeAsync(
5758
divergentBlock.Hash,
5859
DateTimeOffset.UtcNow,
5960
pk.PublicKey,
61+
BigInteger.One,
6062
VoteFlag.PreCommit)
6163
.Sign(pk))
6264
.ToImmutableArray()));

Libplanet.Explorer/GraphTypes/VoteType.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public VoteType()
3030
"ValidatorPublicKey",
3131
description: "Public key of the validator which is subject of the vote.",
3232
resolve: ctx => ctx.Source.ValidatorPublicKey);
33+
Field<NonNullGraphType<BigIntGraphType>>(
34+
"ValidatorPower",
35+
description: "Power of the validator which is subject of the vote.",
36+
resolve: ctx => ctx.Source.ValidatorPower);
3337
Field<NonNullGraphType<VoteFlagType>>(
3438
"Flag",
3539
description: "Flag of the vote",

0 commit comments

Comments
 (0)