From 970c411ee3763b598806ea4edbb3ef07d333e7b1 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 7 Jul 2024 11:31:38 +0800 Subject: [PATCH] rename snapshot --- benchmarks/Neo.Benchmarks/Benchmarks.cs | 2 +- src/Neo.GUI/GUI/MainForm.cs | 2 +- src/Neo/Ledger/Blockchain.cs | 4 +- src/Neo/NeoSystem.cs | 14 +++++- src/Neo/Persistence/DataCache.cs | 10 ++++ src/Neo/SmartContract/ApplicationEngine.cs | 2 +- src/Neo/SmartContract/Helper.cs | 2 +- src/Neo/Wallets/Helper.cs | 2 +- src/Neo/Wallets/Wallet.cs | 2 +- .../DBFTPlugin/Consensus/ConsensusContext.cs | 2 +- src/Plugins/OracleService/OracleService.cs | 2 +- src/Plugins/RpcServer/RpcServer.Blockchain.cs | 10 ++-- src/Plugins/RpcServer/RpcServer.Wallet.cs | 10 ++-- src/Plugins/RpcServer/Session.cs | 2 +- .../TestBlockchain.cs | 2 +- .../TestBlockchain.cs | 2 +- .../UT_RpcServer.Blockchain.cs | 44 +++++++++--------- .../UT_RpcServer.cs | 4 +- .../Neo.UnitTests/IO/Caching/UT_CloneCache.cs | 2 +- .../Neo.UnitTests/IO/Caching/UT_DataCache.cs | 2 +- tests/Neo.UnitTests/Ledger/UT_Blockchain.cs | 4 +- tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs | 2 +- .../Network/P2P/Payloads/UT_Header.cs | 2 +- .../Persistence/UT_MemoryStore.cs | 4 +- .../SmartContract/Native/UT_GasToken.cs | 2 +- .../SmartContract/Native/UT_NativeContract.cs | 4 +- .../SmartContract/Native/UT_NeoToken.cs | 46 +++++++++---------- .../SmartContract/Native/UT_PolicyContract.cs | 14 +++--- .../SmartContract/Native/UT_RoleManagement.cs | 4 +- .../SmartContract/UT_SmartContractHelper.cs | 2 +- tests/Neo.UnitTests/TestBlockchain.cs | 2 +- tests/Neo.UnitTests/UT_DataCache.cs | 6 +-- 32 files changed, 118 insertions(+), 96 deletions(-) diff --git a/benchmarks/Neo.Benchmarks/Benchmarks.cs b/benchmarks/Neo.Benchmarks/Benchmarks.cs index 081f806622..52eec04d44 100644 --- a/benchmarks/Neo.Benchmarks/Benchmarks.cs +++ b/benchmarks/Neo.Benchmarks/Benchmarks.cs @@ -67,7 +67,7 @@ private static void Run(string name, string poc) Script = Convert.FromBase64String(poc), Witnesses = Array.Empty() }; - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); using var engine = ApplicationEngine.Create(TriggerType.Application, tx, snapshot, system.GenesisBlock, protocol, tx.SystemFee); engine.LoadScript(tx.Script); Stopwatch stopwatch = Stopwatch.StartNew(); diff --git a/src/Neo.GUI/GUI/MainForm.cs b/src/Neo.GUI/GUI/MainForm.cs index 3114e542b6..fc1a3e8d99 100644 --- a/src/Neo.GUI/GUI/MainForm.cs +++ b/src/Neo.GUI/GUI/MainForm.cs @@ -201,7 +201,7 @@ private void timer1_Tick(object sender, EventArgs e) check_nep5_balance = false; UInt160[] addresses = Service.CurrentWallet.GetAccounts().Select(p => p.ScriptHash).ToArray(); if (addresses.Length == 0) return; - using var snapshot = Service.NeoSystem.GetSnapshot(); + using var snapshot = Service.NeoSystem.GetSnapshotCache(); foreach (UInt160 assetId in NEP5Watched) { byte[] script; diff --git a/src/Neo/Ledger/Blockchain.cs b/src/Neo/Ledger/Blockchain.cs index b35dd069e3..f63e42e8fe 100644 --- a/src/Neo/Ledger/Blockchain.cs +++ b/src/Neo/Ledger/Blockchain.cs @@ -439,7 +439,7 @@ private void Persist(Block block) all_application_executed.Add(application_executed); transactionStates = engine.GetState(); } - DataCache clonedSnapshot = snapshot.CreateSnapshot(); + DataCache clonedSnapshot = snapshot.CloneCache(); // Warning: Do not write into variable snapshot directly. Write into variable clonedSnapshot and commit instead. foreach (TransactionState transactionState in transactionStates) { @@ -453,7 +453,7 @@ private void Persist(Block block) } else { - clonedSnapshot = snapshot.CreateSnapshot(); + clonedSnapshot = snapshot.CloneCache(); } ApplicationExecuted application_executed = new(engine); Context.System.EventStream.Publish(application_executed); diff --git a/src/Neo/NeoSystem.cs b/src/Neo/NeoSystem.cs index b752f16712..3121432db5 100644 --- a/src/Neo/NeoSystem.cs +++ b/src/Neo/NeoSystem.cs @@ -275,12 +275,24 @@ public void SuspendNodeStartup() /// /// Gets a snapshot of the blockchain storage. /// - /// + /// An instance of + [Obsolete("This method is obsolete, use GetSnapshotCache instead.")] public SnapshotCache GetSnapshot() { return new SnapshotCache(store.GetSnapshot()); } + /// + /// Gets a snapshot of the blockchain storage with an execution cache. + /// With the snapshot, we have the latest state of the blockchain, with the cache, + /// we can run transactions in a sandboxed environment. + /// + /// An instance of + public SnapshotCache GetSnapshotCache() + { + return new SnapshotCache(store.GetSnapshot()); + } + /// /// Determines whether the specified transaction exists in the memory pool or storage. /// diff --git a/src/Neo/Persistence/DataCache.cs b/src/Neo/Persistence/DataCache.cs index 86fbd69961..29c610c6c8 100644 --- a/src/Neo/Persistence/DataCache.cs +++ b/src/Neo/Persistence/DataCache.cs @@ -152,11 +152,21 @@ public virtual void Commit() /// Creates a snapshot, which uses this instance as the underlying storage. /// /// The snapshot of this instance. + [Obsolete("CreateSnapshot is deprecated, please use CloneCache instead.")] public DataCache CreateSnapshot() { return new ClonedCache(this); } + /// + /// Creates a clone of the snapshot cache, which uses this instance as the underlying storage. + /// + /// The of this instance. + public DataCache CloneCache() + { + return new ClonedCache(this); + } + /// /// Deletes an entry from the cache. /// diff --git a/src/Neo/SmartContract/ApplicationEngine.cs b/src/Neo/SmartContract/ApplicationEngine.cs index fab17a2bb1..6fd69439ab 100644 --- a/src/Neo/SmartContract/ApplicationEngine.cs +++ b/src/Neo/SmartContract/ApplicationEngine.cs @@ -460,7 +460,7 @@ public ExecutionContext LoadScript(Script script, int rvcount = -1, int initialP // Create and configure context ExecutionContext context = CreateContext(script, rvcount, initialPosition); ExecutionContextState state = context.GetState(); - state.Snapshot = Snapshot?.CreateSnapshot(); + state.Snapshot = Snapshot?.CloneCache(); configureState?.Invoke(state); // Load context diff --git a/src/Neo/SmartContract/Helper.cs b/src/Neo/SmartContract/Helper.cs index ae31d66a50..d0bc3c939b 100644 --- a/src/Neo/SmartContract/Helper.cs +++ b/src/Neo/SmartContract/Helper.cs @@ -326,7 +326,7 @@ internal static bool VerifyWitness(this IVerifiable verifiable, ProtocolSettings { return false; } - using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot?.CreateSnapshot(), null, settings, datoshi)) + using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot?.CloneCache(), null, settings, datoshi)) { if (witness.VerificationScript.Length == 0) { diff --git a/src/Neo/Wallets/Helper.cs b/src/Neo/Wallets/Helper.cs index 1273bafc50..b8427d078d 100644 --- a/src/Neo/Wallets/Helper.cs +++ b/src/Neo/Wallets/Helper.cs @@ -133,7 +133,7 @@ public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot, size += Array.Empty().GetVarSize() + invSize; // Check verify cost - using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot(), settings: settings, gas: maxExecutionCost); + using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CloneCache(), settings: settings, gas: maxExecutionCost); engine.LoadContract(contract, md, CallFlags.ReadOnly); if (invocationScript != null) engine.LoadScript(invocationScript, configureState: p => p.CallFlags = CallFlags.None); if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.Hash} verification fault."); diff --git a/src/Neo/Wallets/Wallet.cs b/src/Neo/Wallets/Wallet.cs index aca30b008f..dabe6049c6 100644 --- a/src/Neo/Wallets/Wallet.cs +++ b/src/Neo/Wallets/Wallet.cs @@ -574,7 +574,7 @@ private Transaction MakeTransaction(DataCache snapshot, ReadOnlyMemory scr }; // will try to execute 'transfer' script to check if it works - using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.CreateSnapshot(), tx, settings: ProtocolSettings, gas: maxGas, persistingBlock: persistingBlock)) + using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.CloneCache(), tx, settings: ProtocolSettings, gas: maxGas, persistingBlock: persistingBlock)) { if (engine.State == VMState.FAULT) { diff --git a/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.cs b/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.cs index abd0309783..2e6a3a19a6 100644 --- a/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.cs +++ b/src/Plugins/DBFTPlugin/Consensus/ConsensusContext.cs @@ -192,7 +192,7 @@ public void Reset(byte viewNumber) if (viewNumber == 0) { Snapshot?.Dispose(); - Snapshot = neoSystem.GetSnapshot(); + Snapshot = neoSystem.GetSnapshotCache(); uint height = NativeContract.Ledger.CurrentIndex(Snapshot); Block = new Block { diff --git a/src/Plugins/OracleService/OracleService.cs b/src/Plugins/OracleService/OracleService.cs index 6f291e763d..bb5da83654 100644 --- a/src/Plugins/OracleService/OracleService.cs +++ b/src/Plugins/OracleService/OracleService.cs @@ -431,7 +431,7 @@ public static Transaction CreateResponseTx(DataCache snapshot, OracleRequest req // Calculate network fee var oracleContract = NativeContract.ContractManagement.GetContract(snapshot, NativeContract.Oracle.Hash); - var engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot(), settings: settings); + var engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CloneCache(), settings: settings); ContractMethodDescriptor md = oracleContract.Manifest.Abi.GetMethod(ContractBasicMethod.Verify, ContractBasicMethod.VerifyPCount); engine.LoadContract(oracleContract, md, CallFlags.None); if (engine.Execute() != VMState.HALT) return null; diff --git a/src/Plugins/RpcServer/RpcServer.Blockchain.cs b/src/Plugins/RpcServer/RpcServer.Blockchain.cs index 4abddbc183..7bc4711f1c 100644 --- a/src/Plugins/RpcServer/RpcServer.Blockchain.cs +++ b/src/Plugins/RpcServer/RpcServer.Blockchain.cs @@ -49,7 +49,7 @@ protected internal virtual JToken GetBlock(JArray _params) { JToken key = Result.Ok_Or(() => _params[0], RpcError.InvalidParams.WithData($"Invalid Block Hash or Index: {_params[0]}")); bool verbose = _params.Count >= 2 && _params[1].AsBoolean(); - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); Block block; if (key is JNumber) { @@ -245,7 +245,7 @@ protected internal virtual JToken GetRawTransaction(JArray _params) [RpcMethod] protected internal virtual JToken GetStorage(JArray _params) { - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); if (!int.TryParse(_params[0].AsString(), out int id)) { UInt160 hash = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid contract hash {_params[0]}")); @@ -273,7 +273,7 @@ protected internal virtual JToken GetStorage(JArray _params) [RpcMethod] protected internal virtual JToken FindStorage(JArray _params) { - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); if (!int.TryParse(_params[0].AsString(), out int id)) { UInt160 hash = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid contract hash {_params[0]}")); @@ -341,7 +341,7 @@ protected internal virtual JToken GetTransactionHeight(JArray _params) [RpcMethod] protected internal virtual JToken GetNextBlockValidators(JArray _params) { - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount); return validators.Select(p => { @@ -360,7 +360,7 @@ protected internal virtual JToken GetNextBlockValidators(JArray _params) [RpcMethod] protected internal virtual JToken GetCandidates(JArray _params) { - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); byte[] script; using (ScriptBuilder sb = new()) { diff --git a/src/Plugins/RpcServer/RpcServer.Wallet.cs b/src/Plugins/RpcServer/RpcServer.Wallet.cs index 9083f916c6..ab5724e588 100644 --- a/src/Plugins/RpcServer/RpcServer.Wallet.cs +++ b/src/Plugins/RpcServer/RpcServer.Wallet.cs @@ -196,7 +196,7 @@ protected virtual JToken SendFrom(JArray _params) UInt160 assetId = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid asset id: {_params[0]}")); UInt160 from = AddressToScriptHash(_params[1].AsString(), system.Settings.AddressVersion); UInt160 to = AddressToScriptHash(_params[2].AsString(), system.Settings.AddressVersion); - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); AssetDescriptor descriptor = new(snapshot, system.Settings, assetId); BigDecimal amount = new(BigInteger.Parse(_params[3].AsString()), descriptor.Decimals); (amount.Sign > 0).True_Or(RpcErrorFactory.InvalidParams("Amount can't be negative.")); @@ -243,7 +243,7 @@ protected virtual JToken SendMany(JArray _params) Signer[] signers = _params.Count >= to_start + 2 ? ((JArray)_params[to_start + 1]).Select(p => new Signer() { Account = AddressToScriptHash(p.AsString(), system.Settings.AddressVersion), Scopes = WitnessScope.CalledByEntry }).ToArray() : null; TransferOutput[] outputs = new TransferOutput[to.Count]; - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); for (int i = 0; i < to.Count; i++) { UInt160 asset_id = UInt160.Parse(to[i]["asset"].AsString()); @@ -279,7 +279,7 @@ protected virtual JToken SendToAddress(JArray _params) CheckWallet(); UInt160 assetId = Result.Ok_Or(() => UInt160.Parse(_params[0].AsString()), RpcError.InvalidParams.WithData($"Invalid asset hash: {_params[0]}")); UInt160 to = AddressToScriptHash(_params[1].AsString(), system.Settings.AddressVersion); - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); AssetDescriptor descriptor = new(snapshot, system.Settings, assetId); BigDecimal amount = new(BigInteger.Parse(_params[2].AsString()), descriptor.Decimals); (amount.Sign > 0).True_Or(RpcError.InvalidParams); @@ -354,7 +354,7 @@ protected virtual JToken InvokeContractVerify(JArray _params) private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signer[] signers = null, Witness[] witnesses = null) { - using var snapshot = system.GetSnapshot(); + using var snapshot = system.GetSnapshotCache(); var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash).NotNull_Or(RpcError.UnknownContract); var md = contract.Manifest.Abi.GetMethod(ContractBasicMethod.Verify, ContractBasicMethod.VerifyPCount).NotNull_Or(RpcErrorFactory.InvalidContractVerification(contract.Hash)); (md.ReturnType == ContractParameterType.Boolean).True_Or(RpcErrorFactory.InvalidContractVerification("The verify method doesn't return boolean value.")); @@ -365,7 +365,7 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar Witnesses = witnesses, Script = new[] { (byte)OpCode.RET } }; - using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot(), settings: system.Settings); + using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CloneCache(), settings: system.Settings); engine.LoadContract(contract, md, CallFlags.ReadOnly); var invocationScript = Array.Empty(); diff --git a/src/Plugins/RpcServer/Session.cs b/src/Plugins/RpcServer/Session.cs index 1dd8808dde..60be3e19b1 100644 --- a/src/Plugins/RpcServer/Session.cs +++ b/src/Plugins/RpcServer/Session.cs @@ -29,7 +29,7 @@ class Session : IDisposable public Session(NeoSystem system, byte[] script, Signer[] signers, Witness[] witnesses, long datoshi, Diagnostic diagnostic) { Random random = new(); - Snapshot = system.GetSnapshot(); + Snapshot = system.GetSnapshotCache(); Transaction tx = signers == null ? null : new Transaction { Version = 0, diff --git a/tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs b/tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs index d689578e22..bc6be0d8bf 100644 --- a/tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs +++ b/tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs @@ -30,7 +30,7 @@ public static void InitializeMockNeoSystem() internal static DataCache GetTestSnapshot() { - return TheNeoSystem.GetSnapshot().CreateSnapshot(); + return TheNeoSystem.GetSnapshotCache().CloneCache(); } } } diff --git a/tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs b/tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs index f6e35cf695..7708db6fdc 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/TestBlockchain.cs @@ -43,7 +43,7 @@ internal static void ResetStore() internal static DataCache GetTestSnapshot() { - return TheNeoSystem.GetSnapshot().CreateSnapshot(); + return TheNeoSystem.GetSnapshotCache().CloneCache(); } } } diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs index 5fd37b2bc3..0dc89f7ba5 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs @@ -33,7 +33,7 @@ public void TestGetBestBlockHash() var key = NativeContract.Ledger.CreateStorageKey(12); var expectedHash = UInt256.Zero; - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var b = snapshot.GetAndChange(key, () => new StorageItem(new HashIndexState())).GetInteroperable(); b.Hash = UInt256.Zero; b.Index = 100; @@ -47,7 +47,7 @@ public void TestGetBestBlockHash() [TestMethod] public void TestGetBlockByHash() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -65,7 +65,7 @@ public void TestGetBlockByHash() [TestMethod] public void TestGetBlockByIndex() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -99,7 +99,7 @@ public void TestGetBlockHeaderCount() [TestMethod] public void TestGetBlockHash() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -111,7 +111,7 @@ public void TestGetBlockHash() [TestMethod] public void TestGetBlockHeader() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -125,7 +125,7 @@ public void TestGetBlockHeader() [TestMethod] public void TestGetContractState() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var contractState = TestUtils.GetContract(); snapshot.AddContract(contractState.Hash, contractState); snapshot.Commit(); @@ -137,7 +137,7 @@ public void TestGetContractState() [TestMethod] public void TestGetRawMemPool() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var tx = TestUtils.CreateValidTx(snapshot, _wallet, _walletAccount); snapshot.Commit(); _neoSystem.MemPool.TryAdd(tx, snapshot); @@ -150,7 +150,7 @@ public void TestGetRawMemPool() [TestMethod] public void TestGetRawTransaction() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var tx = TestUtils.CreateValidTx(snapshot, _wallet, _walletAccount); _neoSystem.MemPool.TryAdd(tx, snapshot); var parameters = new JArray(tx.Hash.ToString(), true); @@ -164,7 +164,7 @@ public void TestGetRawTransaction() [TestMethod] public void TestGetStorage() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var contractState = TestUtils.GetContract(); snapshot.AddContract(contractState.Hash, contractState); var key = new byte[] { 0x01 }; @@ -179,7 +179,7 @@ public void TestGetStorage() [TestMethod] public void TestFindStorage() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var contractState = TestUtils.GetContract(); snapshot.AddContract(contractState.Hash, contractState); var key = new byte[] { 0x01 }; @@ -203,7 +203,7 @@ public void TestFindStorage() [TestMethod] public void TestGetTransactionHeight() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 1); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -215,7 +215,7 @@ public void TestGetTransactionHeight() [TestMethod] public void TestGetNextBlockValidators() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var result = _rpcServer.GetNextBlockValidators(new JArray()); var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, _neoSystem.Settings.ValidatorsCount); @@ -232,7 +232,7 @@ public void TestGetNextBlockValidators() [TestMethod] public void TestGetCandidates() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var result = _rpcServer.GetCandidates(new JArray()); var json = new JArray(); var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, _neoSystem.Settings.ValidatorsCount); @@ -253,7 +253,7 @@ public void TestGetCandidates() [TestMethod] public void TestGetCommittee() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var result = _rpcServer.GetCommittee(new JArray()); var committee = NativeContract.NEO.GetCommittee(snapshot); var expected = new JArray(committee.Select(p => (JToken)p.ToString())); @@ -271,7 +271,7 @@ public void TestGetNativeContracts() [TestMethod] public void TestGetBlockByUnknownIndex() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -291,7 +291,7 @@ public void TestGetBlockByUnknownIndex() [TestMethod] public void TestGetBlockByUnknownHash() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -311,7 +311,7 @@ public void TestGetBlockByUnknownHash() [TestMethod] public void TestGetBlockByUnKnownIndex() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -331,7 +331,7 @@ public void TestGetBlockByUnKnownIndex() [TestMethod] public void TestGetBlockByUnKnownHash() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -351,7 +351,7 @@ public void TestGetBlockByUnKnownHash() [TestMethod] public void TestGetBlockHashInvalidIndex() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var block = TestUtils.CreateBlockWithValidTransactions(snapshot, _wallet, _walletAccount, 3); TestUtils.BlocksAdd(snapshot, block.Hash, block); snapshot.Commit(); @@ -361,7 +361,7 @@ public void TestGetBlockHashInvalidIndex() [TestMethod] public void TestGetContractStateUnknownContract() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var randomHash = TestUtils.RandomUInt160(); try { @@ -377,7 +377,7 @@ public void TestGetContractStateUnknownContract() [TestMethod] public void TestGetStorageUnknownContract() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var randomHash = TestUtils.RandomUInt160(); var key = new byte[] { 0x01 }; try @@ -394,7 +394,7 @@ public void TestGetStorageUnknownContract() [TestMethod] public void TestGetStorageUnknownStorageItem() { - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var contractState = TestUtils.GetContract(); snapshot.AddContract(contractState.Hash, contractState); snapshot.Commit(); diff --git a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs index 4ba95b7798..beed9a1883 100644 --- a/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs +++ b/tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.cs @@ -42,7 +42,7 @@ public void TestSetup() _rpcServer = new RpcServer(_neoSystem, RpcServerSettings.Default); _walletAccount = _wallet.CreateAccount(); var key = new KeyBuilder(NativeContract.GAS.Id, 20).Add(_walletAccount.ScriptHash); - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 100_000_000 * NativeContract.GAS.Factor; snapshot.Commit(); @@ -52,7 +52,7 @@ public void TestSetup() public void TestCleanup() { _memoryStore.Reset(); - var snapshot = _neoSystem.GetSnapshot(); + var snapshot = _neoSystem.GetSnapshotCache(); var key = new KeyBuilder(NativeContract.GAS.Id, 20).Add(_walletAccount.ScriptHash); var entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState())); entry.GetInteroperable().Balance = 100_000_000 * NativeContract.GAS.Factor; diff --git a/tests/Neo.UnitTests/IO/Caching/UT_CloneCache.cs b/tests/Neo.UnitTests/IO/Caching/UT_CloneCache.cs index 4d57da62b9..3dd3d2dd67 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_CloneCache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_CloneCache.cs @@ -156,7 +156,7 @@ public void TestUpdateInternal() public void TestCacheOverrideIssue2572() { var snapshot = TestBlockchain.GetTestSnapshot(); - var storages = snapshot.CreateSnapshot(); + var storages = snapshot.CloneCache(); storages.Add ( diff --git a/tests/Neo.UnitTests/IO/Caching/UT_DataCache.cs b/tests/Neo.UnitTests/IO/Caching/UT_DataCache.cs index 5235b99c70..242905a13a 100644 --- a/tests/Neo.UnitTests/IO/Caching/UT_DataCache.cs +++ b/tests/Neo.UnitTests/IO/Caching/UT_DataCache.cs @@ -133,7 +133,7 @@ public void TestCommit() [TestMethod] public void TestCreateSnapshot() { - myDataCache.CreateSnapshot().Should().NotBeNull(); + myDataCache.CloneCache().Should().NotBeNull(); } [TestMethod] diff --git a/tests/Neo.UnitTests/Ledger/UT_Blockchain.cs b/tests/Neo.UnitTests/Ledger/UT_Blockchain.cs index cedc68bb4d..2c5ed88ef8 100644 --- a/tests/Neo.UnitTests/Ledger/UT_Blockchain.cs +++ b/tests/Neo.UnitTests/Ledger/UT_Blockchain.cs @@ -57,7 +57,7 @@ public void Clean() [TestMethod] public void TestValidTransaction() { - var snapshot = TestBlockchain.TheNeoSystem.GetSnapshot(); + var snapshot = TestBlockchain.TheNeoSystem.GetSnapshotCache(); var walletA = TestUtils.GenerateTestWallet("123"); var acc = walletA.CreateAccount(); @@ -95,7 +95,7 @@ internal static StorageKey CreateStorageKey(byte prefix, byte[] key = null) [TestMethod] public void TestMaliciousOnChainConflict() { - var snapshot = TestBlockchain.TheNeoSystem.GetSnapshot(); + var snapshot = TestBlockchain.TheNeoSystem.GetSnapshotCache(); var walletA = TestUtils.GenerateTestWallet("123"); var accA = walletA.CreateAccount(); var walletB = TestUtils.GenerateTestWallet("456"); diff --git a/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs b/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs index 1063413073..73cbb37dc9 100644 --- a/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs +++ b/tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs @@ -47,7 +47,7 @@ public static void TestSetup(TestContext ctx) private static DataCache GetSnapshot() { - return testBlockchain.StoreView.CreateSnapshot(); + return testBlockchain.StoreView.CloneCache(); } [TestInitialize] diff --git a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs index a597c88cb6..55419fc8bc 100644 --- a/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs +++ b/tests/Neo.UnitTests/Network/P2P/Payloads/UT_Header.cs @@ -52,7 +52,7 @@ public void GetHashCodeTest() public void TrimTest() { UInt256 val256 = UInt256.Zero; - var snapshot = TestBlockchain.GetTestSnapshot().CreateSnapshot(); + var snapshot = TestBlockchain.GetTestSnapshot().CloneCache(); TestUtils.SetupHeaderWithValues(uut, val256, out _, out _, out _, out _, out _, out _); uut.Witness = new Witness() { InvocationScript = Array.Empty(), VerificationScript = Array.Empty() }; diff --git a/tests/Neo.UnitTests/Persistence/UT_MemoryStore.cs b/tests/Neo.UnitTests/Persistence/UT_MemoryStore.cs index 4cddf07e65..133d9eb66c 100644 --- a/tests/Neo.UnitTests/Persistence/UT_MemoryStore.cs +++ b/tests/Neo.UnitTests/Persistence/UT_MemoryStore.cs @@ -91,7 +91,7 @@ public void NeoSystemStoreViewTest() [TestMethod] public void NeoSystemStoreAddTest() { - var storeCache = _neoSystem.GetSnapshot(); + var storeCache = _neoSystem.GetSnapshotCache(); var key = new KeyBuilder(0, 0); storeCache.Add(key, new StorageItem(UInt256.Zero.ToArray())); storeCache.Commit(); @@ -102,7 +102,7 @@ public void NeoSystemStoreAddTest() [TestMethod] public void NeoSystemStoreGetAndChange() { - var storeView = _neoSystem.GetSnapshot(); + var storeView = _neoSystem.GetSnapshotCache(); var key = new KeyBuilder(1, 1); var item = new StorageItem([1, 2, 3]); storeView.Delete(key); diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs index 51617b6744..1557f9778d 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs @@ -49,7 +49,7 @@ public void TestSetup() [TestMethod] public async Task Check_BalanceOfTransferAndBurn() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; byte[] from = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray(); byte[] to = new byte[20]; diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs index 61e6e67f48..d19fc5d90f 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs @@ -123,7 +123,7 @@ public void TestGenesisNEP17Manifest() }, Transactions = [] }; - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Ensure that native NEP17 contracts contain proper supported standards and events declared // in the manifest constructed for all hardforks enabled. Ref. https://github.com/neo-project/neo/pull/3195. @@ -150,7 +150,7 @@ public void TestGenesisNativeState() }, Transactions = [] }; - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Ensure that all native contracts have proper state generated with an assumption that // all hardforks enabled. diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs index 0a19314153..92f1e0e5f2 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs @@ -56,7 +56,7 @@ public void TestSetup() [TestMethod] public void Check_Vote() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); @@ -114,7 +114,7 @@ public void Check_Vote() [TestMethod] public void Check_Vote_Sameaccounts() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); @@ -147,7 +147,7 @@ public void Check_Vote_Sameaccounts() [TestMethod] public void Check_Vote_ChangeVote() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); snapshot.Add(storageKey, new StorageItem(new HashIndexState { Hash = UInt256.Zero, Index = persistingBlock.Index - 1 })); @@ -182,7 +182,7 @@ public void Check_Vote_ChangeVote() [TestMethod] public void Check_Vote_VoteToNull() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); snapshot.Add(storageKey, new StorageItem(new HashIndexState { Hash = UInt256.Zero, Index = persistingBlock.Index - 1 })); @@ -219,7 +219,7 @@ public void Check_Vote_VoteToNull() [TestMethod] public void Check_UnclaimedGas() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; var storageKey = new KeyBuilder(NativeContract.Ledger.Id, 12); @@ -239,7 +239,7 @@ public void Check_UnclaimedGas() [TestMethod] public void Check_RegisterValidator() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var keyCount = snapshot.GetChangeSet().Count(); var point = TestProtocolSettings.Default.StandbyValidators[0].EncodePoint(true).Clone() as byte[]; @@ -267,7 +267,7 @@ public void Check_RegisterValidator() [TestMethod] public void Check_UnregisterCandidate() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); _persistingBlock.Header.Index = 1; var keyCount = snapshot.GetChangeSet().Count(); var point = TestProtocolSettings.Default.StandbyValidators[0].EncodePoint(true); @@ -328,7 +328,7 @@ public void Check_UnregisterCandidate() [TestMethod] public void Check_GetCommittee() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var keyCount = snapshot.GetChangeSet().Count(); var point = TestProtocolSettings.Default.StandbyValidators[0].EncodePoint(true); var persistingBlock = _persistingBlock; @@ -388,7 +388,7 @@ public void Check_GetCommittee() [TestMethod] public void Check_Transfer() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header { Index = 1000 } }; byte[] from = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray(); @@ -447,7 +447,7 @@ public void Check_Transfer() [TestMethod] public void Check_BalanceOf() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); byte[] account = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray(); NativeContract.NEO.BalanceOf(snapshot, account).Should().Be(100_000_000); @@ -460,7 +460,7 @@ public void Check_BalanceOf() [TestMethod] public void Check_CommitteeBonus() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header @@ -485,7 +485,7 @@ public void Check_CommitteeBonus() [TestMethod] public void Check_Initialize() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // StandbyValidators @@ -495,7 +495,7 @@ public void Check_Initialize() [TestMethod] public void TestCalculateBonus() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block(); StorageKey key = CreateStorageKey(20, UInt160.Zero.ToArray()); @@ -584,7 +584,7 @@ public void TestGetNextBlockValidators1() [TestMethod] public void TestGetNextBlockValidators2() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var result = NativeContract.NEO.GetNextBlockValidators(snapshot, 7); result.Length.Should().Be(7); result[0].ToArray().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); @@ -607,7 +607,7 @@ public void TestGetCandidates1() [TestMethod] public void TestGetCandidates2() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var result = NativeContract.NEO.GetCandidatesInternal(snapshot); result.Count().Should().Be(0); @@ -619,7 +619,7 @@ public void TestGetCandidates2() [TestMethod] public void TestCheckCandidate() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var committee = NativeContract.NEO.GetCommittee(snapshot); var point = committee[0].EncodePoint(true); @@ -700,7 +700,7 @@ public void TestGetCommittee() [TestMethod] public void TestGetValidators() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var result = NativeContract.NEO.ComputeNextBlockValidators(snapshot, TestProtocolSettings.Default); result[0].ToArray().ToHexString().Should().Be("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"); result[1].ToArray().ToHexString().Should().Be("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d"); @@ -730,7 +730,7 @@ public void TestOnBalanceChanging() [TestMethod] public void TestTotalSupply() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); NativeContract.NEO.TotalSupply(snapshot).Should().Be(new BigInteger(100000000)); } @@ -738,7 +738,7 @@ public void TestTotalSupply() public void TestEconomicParameter() { const byte Prefix_CurrentBlock = 12; - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var persistingBlock = new Block { Header = new Header() }; (BigInteger, bool) result = Check_GetGasPerBlock(snapshot, persistingBlock); @@ -768,7 +768,7 @@ public void TestEconomicParameter() [TestMethod] public void TestClaimGas() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Initialize block snapshot.Add(CreateStorageKey(1), new StorageItem(new BigInteger(30000000))); @@ -877,7 +877,7 @@ public void TestClaimGas() [TestMethod] public void TestUnclaimedGas() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); NativeContract.NEO.UnclaimedGas(snapshot, UInt160.Zero, 10).Should().Be(new BigInteger(0)); snapshot.Add(CreateStorageKey(20, UInt160.Zero.ToArray()), new StorageItem(new NeoAccountState())); NativeContract.NEO.UnclaimedGas(snapshot, UInt160.Zero, 10).Should().Be(new BigInteger(0)); @@ -886,7 +886,7 @@ public void TestUnclaimedGas() [TestMethod] public void TestVote() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); UInt160 account = UInt160.Parse("01ff00ff00ff00ff00ff00ff00ff00ff00ff00a4"); StorageKey keyAccount = CreateStorageKey(20, account.ToArray()); StorageKey keyValidator = CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()); @@ -924,7 +924,7 @@ public void TestVote() internal (bool State, bool Result) Transfer4TesingOnBalanceChanging(BigInteger amount, bool addVotes) { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); _persistingBlock.Header.Index = 1; var engine = ApplicationEngine.Create(TriggerType.Application, TestBlockchain.TheNeoSystem.GenesisBlock, snapshot, _persistingBlock, settings: TestBlockchain.TheNeoSystem.Settings); ScriptBuilder sb = new(); diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs index 703253364c..a8d9495b5c 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_PolicyContract.cs @@ -40,7 +40,7 @@ public void TestSetup() [TestMethod] public void Check_Default() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); var ret = NativeContract.Policy.Call(snapshot, "getFeePerByte"); ret.Should().BeOfType(); @@ -56,7 +56,7 @@ public void Check_Default() [TestMethod] public void Check_SetAttributeFee() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Fake blockchain Block block = new() @@ -115,7 +115,7 @@ public void Check_SetAttributeFee() [TestMethod] public void Check_SetFeePerByte() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Fake blockchain @@ -154,7 +154,7 @@ public void Check_SetFeePerByte() [TestMethod] public void Check_SetBaseExecFee() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Fake blockchain @@ -204,7 +204,7 @@ public void Check_SetBaseExecFee() [TestMethod] public void Check_SetStoragePrice() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Fake blockchain @@ -254,7 +254,7 @@ public void Check_SetStoragePrice() [TestMethod] public void Check_BlockAccount() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Fake blockchain @@ -310,7 +310,7 @@ public void Check_BlockAccount() [TestMethod] public void Check_Block_UnblockAccount() { - var snapshot = _snapshot.CreateSnapshot(); + var snapshot = _snapshot.CloneCache(); // Fake blockchain diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs index 25ca7ee0d6..7db5ce4e01 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs @@ -62,7 +62,7 @@ public void TestSetAndGet() List roles = new List() { Role.StateValidator, Role.Oracle, Role.NeoFSAlphabetNode, Role.P2PNotary }; foreach (var role in roles) { - var snapshot1 = _snapshot.CreateSnapshot(); + var snapshot1 = _snapshot.CloneCache(); UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot1); List notifications = new List(); EventHandler ev = (o, e) => notifications.Add(e); @@ -79,7 +79,7 @@ public void TestSetAndGet() ApplicationEngine.Notify -= ev; notifications.Count.Should().Be(1); notifications[0].EventName.Should().Be("Designation"); - var snapshot2 = _snapshot.CreateSnapshot(); + var snapshot2 = _snapshot.CloneCache(); ret = NativeContract.RoleManagement.Call( snapshot2, "getDesignatedByRole", diff --git a/tests/Neo.UnitTests/SmartContract/UT_SmartContractHelper.cs b/tests/Neo.UnitTests/SmartContract/UT_SmartContractHelper.cs index c1161213ce..f864fbe749 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_SmartContractHelper.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_SmartContractHelper.cs @@ -124,7 +124,7 @@ public void TestIsStandardContract() [TestMethod] public void TestVerifyWitnesses() { - var snapshot1 = TestBlockchain.GetTestSnapshot().CreateSnapshot(); + var snapshot1 = TestBlockchain.GetTestSnapshot().CloneCache(); UInt256 index1 = UInt256.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff01"); TestUtils.BlocksAdd(snapshot1, index1, new TrimmedBlock() { diff --git a/tests/Neo.UnitTests/TestBlockchain.cs b/tests/Neo.UnitTests/TestBlockchain.cs index f7e06d0595..7bf26edbd7 100644 --- a/tests/Neo.UnitTests/TestBlockchain.cs +++ b/tests/Neo.UnitTests/TestBlockchain.cs @@ -43,7 +43,7 @@ internal static void ResetStore() internal static DataCache GetTestSnapshot() { - return TheNeoSystem.GetSnapshot().CreateSnapshot(); + return TheNeoSystem.GetSnapshotCache().CloneCache(); } } } diff --git a/tests/Neo.UnitTests/UT_DataCache.cs b/tests/Neo.UnitTests/UT_DataCache.cs index 008f166b6f..01bd84c949 100644 --- a/tests/Neo.UnitTests/UT_DataCache.cs +++ b/tests/Neo.UnitTests/UT_DataCache.cs @@ -23,7 +23,7 @@ public class UT_DataCache public void TestCachedFind_Between() { var snapshot = TestBlockchain.GetTestSnapshot(); - var storages = snapshot.CreateSnapshot(); + var storages = snapshot.CloneCache(); var cache = new ClonedCache(storages); storages.Add @@ -62,7 +62,7 @@ public void TestCachedFind_Between() public void TestCachedFind_Last() { var snapshot = TestBlockchain.GetTestSnapshot(); - var storages = snapshot.CreateSnapshot(); + var storages = snapshot.CloneCache(); var cache = new ClonedCache(storages); storages.Add @@ -94,7 +94,7 @@ public void TestCachedFind_Last() public void TestCachedFind_Empty() { var snapshot = TestBlockchain.GetTestSnapshot(); - var storages = snapshot.CreateSnapshot(); + var storages = snapshot.CloneCache(); var cache = new ClonedCache(storages); cache.Add