Skip to content

Commit

Permalink
test: Remove test code for GasTracer
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Oct 25, 2024
1 parent a501943 commit 680df7e
Showing 1 changed file with 0 additions and 124 deletions.
124 changes: 0 additions & 124 deletions test/Libplanet.Tests/Action/ActionEvaluatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,130 +1343,6 @@ public void OrderTxsForEvaluation(
.Select(tx => tx.Signer.ToString())));
}

[Fact]
public void EvaluateActionAndCollectFee()
{
var privateKey = new PrivateKey();
var address = privateKey.Address;
Currency foo = Currency.Uncapped(
"FOO",
18,
null
);

var freeGasAction = new UseGasAction()
{
GasUsage = 0,
Memo = "FREE",
MintValue = FungibleAssetValue.FromRawValue(foo, 10),
Receiver = address,
};

var payGasAction = new UseGasAction()
{
GasUsage = 1,
Memo = "CHARGE",
};

var store = new MemoryStore();
var stateStore = new TrieStateStore(new MemoryKeyValueStore());
var chain = TestUtils.MakeBlockChain(
policy: new BlockPolicy(),
actions: new[] { freeGasAction, },
store: store,
stateStore: stateStore,
actionLoader: new SingleActionLoader(typeof(UseGasAction)));
var tx = Transaction.Create(
nonce: 0,
privateKey: privateKey,
genesisHash: chain.Genesis.Hash,
maxGasPrice: FungibleAssetValue.FromRawValue(foo, 1),
gasLimit: 3,
actions: new[]
{
payGasAction,
}.ToPlainValues());

chain.StageTransaction(tx);
var miner = new PrivateKey();
Block block = chain.ProposeBlock(miner);

var evaluations = chain.ActionEvaluator.Evaluate(
block, chain.GetNextStateRootHash((BlockHash)block.PreviousHash));

Assert.False(evaluations[0].InputContext.IsPolicyAction);
Assert.Single(evaluations);
Assert.Null(evaluations.Single().Exception);
Assert.Equal(2, GasTracer.GasAvailable);
Assert.Equal(1, GasTracer.GasUsed);
}

[Fact]
public void EvaluateThrowingExceedGasLimit()
{
var privateKey = new PrivateKey();
var address = privateKey.Address;
Currency foo = Currency.Uncapped(
"FOO",
18,
null
);

var freeGasAction = new UseGasAction()
{
GasUsage = 0,
Memo = "FREE",
MintValue = FungibleAssetValue.FromRawValue(foo, 10),
Receiver = address,
};

var payGasAction = new UseGasAction()
{
GasUsage = 10,
Memo = "CHARGE",
};

var store = new MemoryStore();
var stateStore = new TrieStateStore(new MemoryKeyValueStore());
var chain = TestUtils.MakeBlockChain(
policy: new BlockPolicy(),
actions: new[]
{
freeGasAction,
},
store: store,
stateStore: stateStore,
actionLoader: new SingleActionLoader(typeof(UseGasAction)));
var tx = Transaction.Create(
nonce: 0,
privateKey: privateKey,
genesisHash: chain.Genesis.Hash,
maxGasPrice: FungibleAssetValue.FromRawValue(foo, 1),
gasLimit: 5,
actions: new[]
{
payGasAction,
}.ToPlainValues());

chain.StageTransaction(tx);
var miner = new PrivateKey();
Block block = chain.ProposeBlock(miner);

var evaluations = chain.ActionEvaluator.Evaluate(
block,
chain.GetNextStateRootHash((BlockHash)block.PreviousHash));

Assert.False(evaluations[0].InputContext.IsPolicyAction);
Assert.Single(evaluations);
Assert.NotNull(evaluations.Single().Exception);
Assert.NotNull(evaluations.Single().Exception?.InnerException);
Assert.Equal(
typeof(GasLimitExceededException),
evaluations.Single().Exception?.InnerException?.GetType());
Assert.Equal(0, GasTracer.GasAvailable);
Assert.Equal(5, GasTracer.GasUsed);
}

[Fact]
public void GenerateRandomSeed()
{
Expand Down

0 comments on commit 680df7e

Please sign in to comment.