From ec4e3d63fa605657ff080874e990909e13b2e7c5 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 23 Jan 2025 16:58:43 +0300 Subject: [PATCH] SmartContract: refactor obsolete code Signed-off-by: Anna Shaleva --- src/Neo/SmartContract/Native/GasToken.cs | 2 +- src/Neo/SmartContract/Native/PolicyContract.cs | 2 +- .../SmartContract/Native/UT_GasToken.cs | 16 +++------------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Neo/SmartContract/Native/GasToken.cs b/src/Neo/SmartContract/Native/GasToken.cs index 9d5ef7d88e..313e789b9f 100644 --- a/src/Neo/SmartContract/Native/GasToken.cs +++ b/src/Neo/SmartContract/Native/GasToken.cs @@ -49,7 +49,7 @@ internal override async ContractTask OnPersistAsync(ApplicationEngine engine) var notaryAssisted = tx.GetAttribute(); if (notaryAssisted is not null) { - totalNetworkFee -= (notaryAssisted.NKeys + 1) * Policy.GetAttributeFee(engine.Snapshot, (byte)notaryAssisted.Type); + totalNetworkFee -= (notaryAssisted.NKeys + 1) * Policy.GetAttributeFee(engine.SnapshotCache, (byte)notaryAssisted.Type); } } ECPoint[] validators = NEO.GetNextBlockValidators(engine.SnapshotCache, engine.ProtocolSettings.ValidatorsCount); diff --git a/src/Neo/SmartContract/Native/PolicyContract.cs b/src/Neo/SmartContract/Native/PolicyContract.cs index c958fb3a7e..78171217a1 100644 --- a/src/Neo/SmartContract/Native/PolicyContract.cs +++ b/src/Neo/SmartContract/Native/PolicyContract.cs @@ -92,7 +92,7 @@ internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfor } if (hardfork == Hardfork.HF_Echidna) { - engine.Snapshot.Add(CreateStorageKey(Prefix_AttributeFee).Add((byte)TransactionAttributeType.NotaryAssisted), new StorageItem(DefaultNotaryAssistedAttributeFee)); + engine.SnapshotCache.Add(CreateStorageKey(Prefix_AttributeFee).Add((byte)TransactionAttributeType.NotaryAssisted), new StorageItem(DefaultNotaryAssistedAttributeFee)); } return ContractTask.CompletedTask; } diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs index 663d13e761..0ee1cf6227 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs @@ -15,25 +15,15 @@ using Neo.Extensions; using Neo.IO; using Neo.Network.P2P.Payloads; -using Neo.Network.P2P.Payloads; -using Neo.Persistence; using Neo.Persistence; using Neo.SmartContract; -using Neo.SmartContract; using Neo.SmartContract.Native; -using Neo.SmartContract.Native; -using Neo.UnitTests.Extensions; using Neo.UnitTests.Extensions; using Neo.VM; using Neo.Wallets; using System; -using System; -using System; -using System.Linq; using System.Linq; using System.Numerics; -using System.Numerics; -using System.Numerics; using System.Threading.Tasks; using VMTypes = Neo.VM.Types; // using VMArray = Neo.VM.Types.Array; @@ -209,9 +199,9 @@ public void Check_OnPersist_NotaryAssisted() var engine = ApplicationEngine.Create(TriggerType.OnPersist, null, snapshot, persistingBlock, settings: TestBlockchain.TheNeoSystem.Settings); // Check that block's Primary balance is 0. - ECPoint[] validators = NativeContract.NEO.GetNextBlockValidators(engine.Snapshot, engine.ProtocolSettings.ValidatorsCount); + ECPoint[] validators = NativeContract.NEO.GetNextBlockValidators(engine.SnapshotCache, engine.ProtocolSettings.ValidatorsCount); var primary = Contract.CreateSignatureRedeemScript(validators[engine.PersistingBlock.PrimaryIndex]).ToScriptHash(); - NativeContract.GAS.BalanceOf(engine.Snapshot, primary).Should().Be(0); + NativeContract.GAS.BalanceOf(engine.SnapshotCache, primary).Should().Be(0); // Execute OnPersist script. engine.LoadScript(script.ToArray()); @@ -221,7 +211,7 @@ public void Check_OnPersist_NotaryAssisted() // will be minted to Notary nodes as a reward once Notary contract is implemented. Assert.AreEqual(2 + 1, engine.Notifications.Count()); // burn tx1 and tx2 network fee + mint primary reward Assert.AreEqual(netFee1 + netFee2 - expectedNotaryReward, engine.Notifications[2].State[2]); - NativeContract.GAS.BalanceOf(engine.Snapshot, primary).Should().Be(netFee1 + netFee2 - expectedNotaryReward); + NativeContract.GAS.BalanceOf(engine.SnapshotCache, primary).Should().Be(netFee1 + netFee2 - expectedNotaryReward); } } }