From 75ab854badb52f2da0d161f7e3747dbbf688a2ae Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Thu, 5 Aug 2021 16:08:08 +0800 Subject: [PATCH] Revert "Refuel (#2444)" (#2560) --- src/neo/SmartContract/ApplicationEngine.cs | 10 +-- src/neo/SmartContract/Native/GasToken.cs | 12 ---- .../SmartContract/Native/UT_GasToken.cs | 62 ------------------- 3 files changed, 1 insertion(+), 83 deletions(-) diff --git a/src/neo/SmartContract/ApplicationEngine.cs b/src/neo/SmartContract/ApplicationEngine.cs index e0f0db6266..b7135ed055 100644 --- a/src/neo/SmartContract/ApplicationEngine.cs +++ b/src/neo/SmartContract/ApplicationEngine.cs @@ -40,7 +40,7 @@ public partial class ApplicationEngine : ExecutionEngine private static IApplicationEngineProvider applicationEngineProvider; private static Dictionary services; - private long gas_amount; + private readonly long gas_amount; private List notifications; private List disposables; private readonly Dictionary invocationCounter = new(); @@ -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; diff --git a/src/neo/SmartContract/Native/GasToken.cs b/src/neo/SmartContract/Native/GasToken.cs index 814992f74f..51cbb6dbaa 100644 --- a/src/neo/SmartContract/Native/GasToken.cs +++ b/src/neo/SmartContract/Native/GasToken.cs @@ -1,8 +1,5 @@ -#pragma warning disable IDE0051 - using Neo.Cryptography.ECC; using Neo.Network.P2P.Payloads; -using System; namespace Neo.SmartContract.Native { @@ -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); - } } } diff --git a/tests/neo.UnitTests/SmartContract/Native/UT_GasToken.cs b/tests/neo.UnitTests/SmartContract/Native/UT_GasToken.cs index 4bcd2e143f..0b1f4be296 100644 --- a/tests/neo.UnitTests/SmartContract/Native/UT_GasToken.cs +++ b/tests/neo.UnitTests/SmartContract/Native/UT_GasToken.cs @@ -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; @@ -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().Balance = 1 * NativeContract.GAS.Factor; - - key = NativeContract.GAS.CreateStorageKey(20, accBalance.ScriptHash); - entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState())); - entry.GetInteroperable().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().Balance); - } - [TestMethod] public async Task Check_BalanceOfTransferAndBurn() {