From 4d9c39ba35c145266b24f787516bcfd5984d4893 Mon Sep 17 00:00:00 2001 From: Shargon <shargon@gmail.com> Date: Tue, 12 Nov 2019 09:40:22 +0100 Subject: [PATCH 1/3] Prevent remove storage when it has somethinh stored --- neo/SmartContract/InteropService.NEO.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/neo/SmartContract/InteropService.NEO.cs b/neo/SmartContract/InteropService.NEO.cs index e500eeb235..ce26067a74 100644 --- a/neo/SmartContract/InteropService.NEO.cs +++ b/neo/SmartContract/InteropService.NEO.cs @@ -225,6 +225,7 @@ private static bool Contract_Update(ApplicationEngine engine) contract = engine.Snapshot.Contracts.GetAndChange(contract.ScriptHash); contract.Manifest = ContractManifest.Parse(manifest); if (!contract.Manifest.IsValid(contract.ScriptHash)) return false; + if (!contract.HasStorage && engine.Snapshot.Storages.Find(engine.CurrentScriptHash.ToArray()).Any()) return false; } return true; From 7c57d236eed9b3933786c54a113bd40b225fb5b1 Mon Sep 17 00:00:00 2001 From: Shargon <shargon@gmail.com> Date: Tue, 12 Nov 2019 15:01:23 +0100 Subject: [PATCH 2/3] UT --- neo.UnitTests/SmartContract/UT_InteropService.NEO.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs b/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs index 885f3d3498..6e427b81c5 100644 --- a/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs +++ b/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs @@ -232,6 +232,18 @@ public void TestContract_Update() engine.CurrentContext.EvaluationStack.Push(manifest.ToString()); engine.CurrentContext.EvaluationStack.Push(script); InteropService.Invoke(engine, InteropService.Neo_Contract_Update).Should().BeTrue(); + + // Update to noStorage with something stored + + state.Manifest.Features = ContractFeatures.NoProperty; + mockSnapshot.SetupGet(p => p.Contracts).Returns(new TestDataCache<UInt160, ContractState>(state.ScriptHash, state)); + mockSnapshot.SetupGet(p => p.Storages).Returns(new TestDataCache<StorageKey, StorageItem>(storageKey, storageItem)); + + engine = new ApplicationEngine(TriggerType.Application, null, mockSnapshot.Object, 0); + engine.LoadScript(state.Script); + engine.CurrentContext.EvaluationStack.Push(manifest.ToString()); + engine.CurrentContext.EvaluationStack.Push(script); + InteropService.Invoke(engine, InteropService.Neo_Contract_Update).Should().BeFalse(); } [TestMethod] From 1a23dcb8a08c3aa39ef6f532abe672a347a611a9 Mon Sep 17 00:00:00 2001 From: Shargon <shargon@gmail.com> Date: Tue, 12 Nov 2019 15:13:48 +0100 Subject: [PATCH 3/3] Update UT_InteropService.NEO.cs --- neo.UnitTests/SmartContract/UT_InteropService.NEO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs b/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs index 6e427b81c5..ec9f680654 100644 --- a/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs +++ b/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs @@ -233,7 +233,7 @@ public void TestContract_Update() engine.CurrentContext.EvaluationStack.Push(script); InteropService.Invoke(engine, InteropService.Neo_Contract_Update).Should().BeTrue(); - // Update to noStorage with something stored + // Remove Storage flag with something stored state.Manifest.Features = ContractFeatures.NoProperty; mockSnapshot.SetupGet(p => p.Contracts).Returns(new TestDataCache<UInt160, ContractState>(state.ScriptHash, state));