Skip to content

Commit

Permalink
Prevent remove storage flag when there are something stored (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and erikzhang committed Nov 14, 2019
1 parent 7c6a147 commit 69f3f15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions neo.UnitTests/SmartContract/UT_InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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();

// Remove Storage flag 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]
Expand Down
1 change: 1 addition & 0 deletions neo/SmartContract/InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,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;
Expand Down

0 comments on commit 69f3f15

Please sign in to comment.