Skip to content

Commit

Permalink
feat: Remove World.Create()
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedgeLee committed Nov 2, 2023
1 parent 200b7ad commit f42967f
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 25 deletions.
10 changes: 5 additions & 5 deletions Libplanet.Action.Tests/ActionContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void RandomShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: World.Create(new MockWorldState()),
previousState: new World(new MockWorldState()),
randomSeed: seed,
gasLimit: 0
);
Expand All @@ -54,7 +54,7 @@ public void GuidShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: World.Create(new MockWorldState()),
previousState: new World(new MockWorldState()),
randomSeed: 0,
gasLimit: 0
);
Expand All @@ -65,7 +65,7 @@ public void GuidShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: World.Create(new MockWorldState()),
previousState: new World(new MockWorldState()),
randomSeed: 0,
gasLimit: 0
);
Expand All @@ -76,7 +76,7 @@ public void GuidShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: World.Create(new MockWorldState()),
previousState: new World(new MockWorldState()),
randomSeed: 1,
gasLimit: 0
);
Expand Down Expand Up @@ -115,7 +115,7 @@ public void GuidVersionAndVariant()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: World.Create(new MockWorldState()),
previousState: new World(new MockWorldState()),
randomSeed: i,
gasLimit: 0
);
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void Constructor()
address,
1,
Block.CurrentProtocolVersion,
World.Create(new MockWorldState()),
new World(new MockWorldState()),
123,
0,
false),
World.Create(
new World(
new MockWorldState().SetAccount(
ReservedAddresses.LegacyAccount,
new Account(MockAccountState.Empty.SetState(address, (Text)"item"))))
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Sys/InitializeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Execute()
{
var random = new System.Random();
Address signer = random.NextAddress();
var prevState = World.Create(new MockWorldState());
var prevState = new World(new MockWorldState());
BlockHash genesisHash = random.NextBlockHash();
var context = new ActionContext(
signer: signer,
Expand Down Expand Up @@ -79,7 +79,7 @@ public void ExecuteInNonGenesis()
{
var random = new System.Random();
Address signer = random.NextAddress();
var prevState = World.Create(new MockWorldState());
var prevState = new World(new MockWorldState());
BlockHash genesisHash = random.NextBlockHash();
var context = new ActionContext(
signer: signer,
Expand Down
12 changes: 1 addition & 11 deletions Libplanet.Action/State/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public World(IWorldState baseState, IWorldDelta delta)
{
_baseState = baseState;
Delta = delta;
Legacy = true;
Legacy = baseState.Legacy;
}

/// <inheritdoc/>
Expand All @@ -38,16 +38,6 @@ public World(IWorldState baseState, IWorldDelta delta)
[Pure]
public bool Legacy { get; private set; }

/// <summary>
/// Creates a new World from given <paramref name="previousWorld"/>.
/// </summary>
/// <param name="previousWorld">The previous <see cref="WorldBaseState"/> to initialize
/// new World.</param>
/// <returns>A null world using <paramref name="previousWorld"/> as its base state.
/// </returns>
public static IWorld Create(IWorldState previousWorld) =>
new World(previousWorld) { Legacy = previousWorld.Legacy };

/// <summary>
/// Creates a null worlds from given <see cref="IWorld"/>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tests/Action/AccountV0Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AccountV0Test(ITestOutputHelper output)
public override IActionContext CreateContext(
IAccount delta, Address signer)
{
IWorld world = World.Create(new MockWorldState());
IWorld world = new World(new MockWorldState());
world = world.SetAccount(_accountAddress, delta);
return new ActionContext(
signer,
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tests/Action/AccountV1Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AccountV1Test(ITestOutputHelper output)

public override IActionContext CreateContext(IAccount delta, Address signer)
{
IWorld world = World.Create(new MockWorldState());
IWorld world = new World(new MockWorldState());
world = world.SetAccount(_accountAddress, delta);
return new ActionContext(
signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AnonymousActionRendererTest
{
private static IValue _action = new DumbAction().PlainValue;

private static IWorld _world = World.Create(new MockWorldState());
private static IWorld _world = new World(new MockWorldState());

private static ICommittedActionContext _actionContext =
new CommittedActionContext(new ActionContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LoggedActionRendererTest : IDisposable
{
private static IValue _action = new DumbAction().PlainValue;

private static IWorld _world = World.Create(new MockWorldState());
private static IWorld _world = new World(new MockWorldState());

private static Block _genesis =
TestUtils.ProposeGenesisBlock(TestUtils.GenesisProposer);
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tests/Fixtures/IntegerSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void Append(Block block) =>
Chain.Append(block, TestUtils.CreateBlockCommit(block));

public IWorld CreateWorld(BlockHash? offset = null)
=> World.Create(Chain.GetWorldState(offset ?? Tip.Hash));
=> new World(Chain.GetWorldState(offset ?? Tip.Hash));

public ITrie GetTrie(BlockHash? blockHash)
{
Expand Down

0 comments on commit f42967f

Please sign in to comment.