Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Refuel (#2444)" #2560

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public partial class ApplicationEngine : ExecutionEngine

private static IApplicationEngineProvider applicationEngineProvider;
private static Dictionary<uint, InteropDescriptor> services;
private long gas_amount;
private readonly long gas_amount;
private List<NotifyEventArgs> notifications;
private List<IDisposable> disposables;
private readonly Dictionary<UInt160, int> invocationCounter = new();
Expand Down Expand Up @@ -156,14 +156,6 @@ protected internal void AddGas(long gas)
throw new InvalidOperationException("Insufficient GAS.");
}

internal void Refuel(long gas)
{
checked
{
gas_amount += gas;
}
}

protected override void OnFault(Exception ex)
{
FaultException = ex;
Expand Down
12 changes: 0 additions & 12 deletions src/neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma warning disable IDE0051

using Neo.Cryptography.ECC;
using Neo.Network.P2P.Payloads;
using System;

namespace Neo.SmartContract.Native
{
Expand Down Expand Up @@ -36,14 +33,5 @@ internal override async ContractTask OnPersist(ApplicationEngine engine)
UInt160 primary = Contract.CreateSignatureRedeemScript(validators[engine.PersistingBlock.PrimaryIndex]).ToScriptHash();
await Mint(engine, primary, totalNetworkFee, false);
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
private async ContractTask Refuel(ApplicationEngine engine, UInt160 account, long amount)
{
if (amount < 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (!engine.CheckWitnessInternal(account)) throw new InvalidOperationException();
await Burn(engine, account, amount);
engine.Refuel(amount);
}
}
}
62 changes: 0 additions & 62 deletions tests/neo.UnitTests/SmartContract/Native/UT_GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.UnitTests.Extensions;
using Neo.VM;
using System;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -36,67 +35,6 @@ public void TestSetup()
[TestMethod]
public void Check_Decimals() => NativeContract.GAS.Decimals(_snapshot).Should().Be(8);

[TestMethod]
public void Refuel()
{
// Prepare

var wallet = TestUtils.GenerateTestWallet();
var snapshot = TestBlockchain.GetTestSnapshot();

using var unlock = wallet.Unlock("");
var accBalance = wallet.CreateAccount();
var accNoBalance = wallet.CreateAccount();

// Fake balance

var key = NativeContract.GAS.CreateStorageKey(20, accNoBalance.ScriptHash);
var entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
entry.GetInteroperable<AccountState>().Balance = 1 * NativeContract.GAS.Factor;

key = NativeContract.GAS.CreateStorageKey(20, accBalance.ScriptHash);
entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
entry.GetInteroperable<AccountState>().Balance = 100 * NativeContract.GAS.Factor;

snapshot.Commit();

// Make transaction

byte[] script;
using (ScriptBuilder sb = new())
{
sb.EmitDynamicCall(NativeContract.GAS.Hash, "refuel", accBalance.ScriptHash, 100 * NativeContract.GAS.Factor);
sb.Emit(OpCode.DROP);
sb.EmitSysCall(ApplicationEngine.System_Runtime_GasLeft);
script = sb.ToArray();
}

var signers = new Signer[]{ new Signer
{
Account = accBalance.ScriptHash,
Scopes = WitnessScope.CalledByEntry
} ,
new Signer
{
Account = accNoBalance.ScriptHash,
Scopes = WitnessScope.CalledByEntry
} };

var tx = wallet.MakeTransaction(snapshot, script, accBalance.ScriptHash, signers);
Assert.IsNotNull(tx);

// Check

using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Application, tx, snapshot, settings: TestBlockchain.TheNeoSystem.Settings, gas: tx.NetworkFee);
engine.LoadScript(tx.Script);
Assert.AreEqual(VMState.HALT, engine.Execute());
Assert.AreEqual(1, engine.ResultStack.Count);
Assert.AreEqual(100_00300140, engine.ResultStack.Pop().GetInteger());

entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
Assert.AreEqual(0, entry.GetInteroperable<AccountState>().Balance);
}

[TestMethod]
public async Task Check_BalanceOfTransferAndBurn()
{
Expand Down