Skip to content

Commit

Permalink
Merge pull request #2411 from planetarium/release/100
Browse files Browse the repository at this point in the history
Merge Release/100 into main
  • Loading branch information
limebell authored Feb 19, 2024
2 parents d597a31 + 92e0c5c commit 28ca968
Show file tree
Hide file tree
Showing 60 changed files with 1,390 additions and 1,570 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 438 files
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void CheckPairs()
class PostActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateroothash)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
return new ICommittedActionEvaluation[]
{
Expand All @@ -85,7 +86,8 @@ public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock bl
class PreActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
return new ICommittedActionEvaluation[]
{
Expand Down Expand Up @@ -113,7 +115,7 @@ public void LoadPlainValue(IValue plainValue)
{
}

public IAccount Execute(IActionContext context) => context.PreviousState;
public IWorld Execute(IActionContext context) => context.PreviousState;
}

class MockBlock : IPreEvaluationBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ public static IPluginActionEvaluator CreateActionEvaluator(Assembly assembly, st
public static IPluginActionEvaluator CreateActionEvaluator(string pluginPath, string typeName, IKeyValueStore keyValueStore)
=> CreateActionEvaluator(LoadPlugin(pluginPath), typeName, new PluginKeyValueStore(keyValueStore));

public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
=> _pluginActionEvaluator.Evaluate(
PreEvaluationBlockMarshaller.Serialize(block),
baseStateRootHash is { } srh ? srh.ToByteArray() : null)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block,
HashDigest<SHA256>? baseStateRootHash)
{
var evaluations = _pluginActionEvaluator.Evaluate(
PreEvaluationBlockMarshaller.Serialize(block),
baseStateRootHash is { } srh ? srh.ToByteArray() : null)
.Select(eval => ActionEvaluationMarshaller.Deserialize(eval)).ToList().AsReadOnly();
return evaluations;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private class DummyAction : IAction
{
IValue IAction.PlainValue => Dictionary.Empty;

IAccount IAction.Execute(IActionContext context)
IWorld IAction.Execute(IActionContext context)
{
return context.PreviousState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public AccessControlServiceController(IMutableAccessControlService accessControl
[HttpPost("entries/add-tx-quota/{address}")]
public ActionResult AddTxQuota(string address, [FromBody] int quota)
{
var maxQuota = 10;
var maxQuota = 100;
if (quota > maxQuota)
{
return BadRequest($"The quota cannot exceed {maxQuota}.");
Expand All @@ -48,7 +48,7 @@ public ActionResult AddTxQuota(string address, [FromBody] int quota)
[HttpPost("entries/bulk-add-tx-quota")]
public ActionResult BulkAddTxQuota([FromBody] BulkAddTxQuotaInput bulkAddTxQuotaInput)
{
var maxQuota = 10;
var maxQuota = 100;
var maxAddressCount = 100;
if (bulkAddTxQuotaInput.Quota > maxQuota)
{
Expand Down
118 changes: 0 additions & 118 deletions NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Libplanet.Common;
using Libplanet.Crypto;
using Nekoyume.Action;
using Nekoyume.Action.Factory;
using Nekoyume.Model;
using Nekoyume.Model.State;
using NineChronicles.Headless.Executable.Commands;
Expand Down Expand Up @@ -59,50 +58,6 @@ public void ActivateAccount(bool invalid, int expectedCode)
}
}

[Fact]
public void MonsterCollect()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var resultCode = _command.MonsterCollect(1, filePath);
Assert.Equal(0, resultCode);
var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
string type = (Text)decoded[0];
Assert.Equal(nameof(Nekoyume.Action.MonsterCollect), type);

Dictionary plainValue = (Dictionary)decoded[1];
var action = new MonsterCollect();
action.LoadPlainValue(plainValue);
Assert.Equal(1, action.level);
}

[Theory]
[InlineData("0xab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", -1)]
[InlineData("ab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", 0)]
public void ClaimMonsterCollectReward(string addressString, int expectedCode)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var resultCode = _command.ClaimMonsterCollectionReward(addressString, filePath);
Assert.Equal(expectedCode, resultCode);

if (resultCode == 0)
{
var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
string type = (Text)decoded[0];
Assert.Equal(nameof(ClaimMonsterCollectionReward), type);

Dictionary plainValue = (Dictionary)decoded[1];
var action = new ClaimMonsterCollectionReward();
action.LoadPlainValue(plainValue);
Assert.Equal(new Address(addressString), action.avatarAddress);
}
else
{
Assert.Contains("System.FormatException: Input string was not in a correct format.", _console.Error.ToString());
}
}

[Theory]
[InlineData(10, 0, "transfer asset test1.")]
[InlineData(100, 0, "transfer asset test2.")]
Expand Down Expand Up @@ -185,79 +140,6 @@ public void ClaimStakeReward(string addressString, int expectedCode)
}
}

[Theory]
[InlineData(0L, typeof(ClaimStakeReward2))]
[InlineData(ClaimStakeReward2.ObsoletedIndex, typeof(ClaimStakeReward2))]
[InlineData(ClaimStakeReward2.ObsoletedIndex + 1, typeof(ClaimStakeReward3))]
[InlineData(ClaimStakeReward3.ObsoleteBlockIndex, typeof(ClaimStakeReward3))]
[InlineData(ClaimStakeReward3.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward4))]
[InlineData(ClaimStakeReward4.ObsoleteBlockIndex, typeof(ClaimStakeReward4))]
[InlineData(ClaimStakeReward4.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward5))]
[InlineData(ClaimStakeReward5.ObsoleteBlockIndex, typeof(ClaimStakeReward5))]
[InlineData(ClaimStakeReward5.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward6))]
[InlineData(ClaimStakeReward6.ObsoleteBlockIndex, typeof(ClaimStakeReward6))]
[InlineData(ClaimStakeReward6.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward7))]
[InlineData(ClaimStakeReward7.ObsoleteBlockIndex, typeof(ClaimStakeReward7))]
[InlineData(ClaimStakeReward7.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward8))]
[InlineData(ClaimStakeReward8.ObsoleteBlockIndex, typeof(ClaimStakeReward8))]
[InlineData(ClaimStakeReward8.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward))]
[InlineData(long.MaxValue, typeof(ClaimStakeReward))]
public void ClaimStakeRewardWithBlockIndex(long blockIndex, Type expectedActionType)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var addr = new PrivateKey().Address;
var resultCode = _command.ClaimStakeReward(
addr.ToHex(),
filePath,
blockIndex: blockIndex);
Assert.Equal(0, resultCode);

var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
var plainValue = Assert.IsType<Dictionary>(decoded[1]);
var action = ClaimStakeRewardFactory.CreateByBlockIndex(blockIndex, addr);
Assert.NotNull(action);
var actionType = action.GetType();
Assert.Equal(expectedActionType, actionType);
action.LoadPlainValue(plainValue);
string type = (Text)decoded[0];
Assert.Equal(type, actionType.Name);
}

[Theory]
[InlineData(0, 0, -1)]
[InlineData(1, 9, 0)]
[InlineData(10, 10, -1)]
public void ClaimStakeRewardWithActionVersion(
int actionVersionMin,
int actionVersionMax,
int expectedCode)
{
for (var i = actionVersionMin; i < actionVersionMax + 1; i++)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var addr = new PrivateKey().Address;
var resultCode = _command.ClaimStakeReward(
addr.ToHex(),
filePath,
actionVersion: i);
Assert.Equal(expectedCode, resultCode);

if (expectedCode < 0)
{
continue;
}

var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
var plainValue = Assert.IsType<Dictionary>(decoded[1]);
var action = ClaimStakeRewardFactory.CreateByVersion(i, addr);
action.LoadPlainValue(plainValue);
string type = (Text)decoded[0];
Assert.Equal(action.GetType().Name, type);
}
}

[Theory]
[InlineData("0xab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", -1)]
[InlineData("ab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", 0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void Snapshot(StoreType storeType)
};
Guid chainId = chain.Id;

for (var i = 0; i < 2; i++)
for (var i = 0; i < 5; i++)
{
chain.MakeTransaction(GenesisHelper.ValidatorKey, new ActionBase[] { action });
Block block = chain.ProposeBlock(
Expand Down Expand Up @@ -334,9 +334,10 @@ public void Snapshot(StoreType storeType)
IStore storeAfterSnapshot = storeType.CreateStore(_storePath);
chainId = storeAfterSnapshot.GetCanonicalChainId() ?? new Guid();
var tipHashAfterSnapshot = storeAfterSnapshot.IndexBlockHash(chainId, -1);
var snapshotTipIndex = storeAfterSnapshot.GetBlockIndex((BlockHash)tipHashAfterSnapshot!);
var expectedGenesisPartitionSnapshotPath = Path.Combine(outputDirectory, "partition", $"snapshot-{genesisBlockEpoch}-{genesisBlockEpoch}.zip");
var expectedGenesisMetadataPath = Path.Combine(outputDirectory, "metadata", $"snapshot-{genesisBlockEpoch}-{genesisBlockEpoch}.json");
var expectedFullSnapshotPath = Path.Combine(outputDirectory, "full", $"{genesisHash}-snapshot-{tipHashAfterSnapshot}.zip");
var expectedFullSnapshotPath = Path.Combine(outputDirectory, "full", $"{genesisHash}-snapshot-{tipHashAfterSnapshot}-{snapshotTipIndex}.zip");
storeAfterSnapshot.Dispose();

Assert.True(File.Exists(expectedGenesisPartitionSnapshotPath));
Expand All @@ -360,8 +361,8 @@ public void Snapshot(StoreType storeType)
Assert.True(File.Exists(expectedPartitionSnapshotPath));
Assert.True(File.Exists(expectedStateSnapshotPath));
Assert.True(File.Exists(expectedMetadataPath));
Assert.Equal(3, indexCountBeforeSnapshot);
Assert.Equal(2, indexCountAfterSnapshot);
Assert.Equal(6, indexCountBeforeSnapshot);
Assert.Equal(5, indexCountAfterSnapshot);

Directory.Delete(outputDirectory, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ public void Sign_ActivateAccount(int txNonce)
Assert_Tx(txNonce, filePath, false);
}

[Fact]
public void Sign_MonsterCollect()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var actionCommand = new ActionCommand(_console);
actionCommand.MonsterCollect(1, filePath);
Assert_Tx(1, filePath, false);
}

[Fact]
public void Sign_ClaimMonsterCollectionReward()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var actionCommand = new ActionCommand(_console);
var avatarAddress = new Address();
actionCommand.ClaimMonsterCollectionReward(avatarAddress.ToHex(), filePath);
Assert_Tx(1, filePath, false);
}

[Theory]
[InlineData(1, false)]
[InlineData(10, true)]
Expand Down Expand Up @@ -97,7 +78,6 @@ public void Sign_Stake(bool gas)
[InlineData(ClaimStakeReward2.ObsoletedIndex - 1, null, false)]
[InlineData(ClaimStakeReward2.ObsoletedIndex, null, true)]
[InlineData(ClaimStakeReward2.ObsoletedIndex + 1, null, false)]
[InlineData(ClaimStakeReward3.ObsoleteBlockIndex - 1, null, true)]
[InlineData(long.MaxValue, null, true)]
[InlineData(null, 1, false)]
[InlineData(null, 2, true)]
Expand All @@ -111,9 +91,7 @@ public void Sign_ClaimStakeReward(long? blockIndex, int? actionVersion, bool gas
var avatarAddress = new Address();
actionCommand.ClaimStakeReward(
avatarAddress.ToHex(),
filePath,
blockIndex,
actionVersion);
filePath);
Assert_Tx(1, filePath, gas);
}

Expand Down
9 changes: 6 additions & 3 deletions NineChronicles.Headless.Executable/Commands/AccountCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Bencodex;
using Cocona;
using Libplanet.Action.State;
using Libplanet.Blockchain;
using Libplanet.Crypto;
using Libplanet.Store;
Expand All @@ -11,6 +12,7 @@
using Libplanet.Types.Tx;
using Nekoyume.Action;
using Nekoyume.Model.State;
using Nekoyume.Module;
using NineChronicles.Headless.Executable.IO;
using Serilog.Core;
using static NineChronicles.Headless.NCActionUtils;
Expand Down Expand Up @@ -52,15 +54,16 @@ public void Balance(
Block offset = DevExUtils.ParseBlockOffset(chain, block);
_console.Error.WriteLine("The offset block: #{0} {1}.", offset.Index, offset.Hash);

IWorldState worldState = chain.GetWorldState(offset.Hash);
Bencodex.Types.Dictionary goldCurrencyStateDict = (Bencodex.Types.Dictionary)
chain.GetState(GoldCurrencyState.Address);
worldState.GetLegacyState(GoldCurrencyState.Address);
GoldCurrencyState goldCurrencyState = new GoldCurrencyState(goldCurrencyStateDict);
Currency gold = goldCurrencyState.Currency;

if (address is { } addrStr)
{
Address addr = DevExUtils.ParseAddress(addrStr);
FungibleAssetValue balance = chain.GetBalance(addr, gold, offset.Hash);
FungibleAssetValue balance = worldState.GetBalance(addr, gold);
_console.Out.WriteLine("{0}\t{1}", addr, balance);
return;
}
Expand Down Expand Up @@ -96,7 +99,7 @@ public void Balance(
{
if (!printed.Contains(addr))
{
FungibleAssetValue balance = chain.GetBalance(addr, gold, offset.Hash);
FungibleAssetValue balance = worldState.GetBalance(addr, gold);
_console.Out.WriteLine("{0}\t{1}", addr, balance);
printed.Add(addr);
}
Expand Down
Loading

0 comments on commit 28ca968

Please sign in to comment.