Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Mar 18, 2020
2 parents 93fe8a7 + 4cc9717 commit e9f2214
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/neo/SmartContract/InteropService.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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;
if (!contract.HasStorage && engine.Snapshot.Storages.Find(BitConverter.GetBytes(contract.Id)).Any()) return false;
}

return true;
Expand All @@ -100,7 +100,7 @@ private static bool Contract_Destroy(ApplicationEngine engine)
if (contract == null) return true;
engine.Snapshot.Contracts.Delete(hash);
if (contract.HasStorage)
foreach (var (key, _) in engine.Snapshot.Storages.Find(hash.ToArray()))
foreach (var (key, _) in engine.Snapshot.Storages.Find(BitConverter.GetBytes(contract.Id)))
engine.Snapshot.Storages.Delete(key);
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Neo.VM;
using Neo.VM.Types;
using Neo.Wallets;
using System;
using System.Linq;
using VMArray = Neo.VM.Types.Array;

Expand Down Expand Up @@ -218,6 +219,7 @@ public void TestContract_Update()
Signature = signature
}
};
manifest.Features = ContractFeatures.HasStorage;
var snapshot = Blockchain.Singleton.GetSnapshot();
var state = TestUtils.GetContract();
state.Manifest.Features = ContractFeatures.HasStorage;
Expand All @@ -239,6 +241,7 @@ public void TestContract_Update()
engine.CurrentContext.EvaluationStack.Push(manifest.ToString());
engine.CurrentContext.EvaluationStack.Push(script);
InteropService.Invoke(engine, InteropService.Contract.Update).Should().BeTrue();
engine.Snapshot.Storages.Find(BitConverter.GetBytes(state.Id)).ToList().Count().Should().Be(1);
}

[TestMethod]
Expand Down
3 changes: 3 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ public void TestContract_Destroy()
engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0);
engine.LoadScript(new byte[0]);
InteropService.Invoke(engine, InteropService.Contract.Destroy).Should().BeTrue();
engine.Snapshot.Storages.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse();

//storages are removed
snapshot = Blockchain.Singleton.GetSnapshot();
Expand All @@ -856,6 +857,8 @@ public void TestContract_Destroy()
engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0);
engine.LoadScript(new byte[0]);
InteropService.Invoke(engine, InteropService.Contract.Destroy).Should().BeTrue();
engine.Snapshot.Storages.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse();

}

[TestMethod]
Expand Down
1 change: 1 addition & 0 deletions tests/neo.UnitTests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ internal static ContractState GetContract()
{
return new ContractState
{
Id = 0x43000000,
Script = new byte[] { 0x01, 0x01, 0x01, 0x01 },
Manifest = ContractManifest.CreateDefault(UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01"))
};
Expand Down

0 comments on commit e9f2214

Please sign in to comment.