示例#1
0
        public void TestContract_Destroy()
        {
            var engine = GetEngine(false, true);

            engine.DestroyContract();

            var snapshot = Blockchain.Singleton.GetSnapshot();
            var state    = TestUtils.GetContract();

            state.Manifest.Features = ContractFeatures.HasStorage;
            var scriptHash  = UInt160.Parse("0xcb9f3b7c6fb1cf2c13a40637c189bdd066a272b4");
            var storageItem = new StorageItem
            {
                Value      = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                IsConstant = false
            };

            var storageKey = new StorageKey
            {
                Id  = 0x43000000,
                Key = new byte[] { 0x01 }
            };

            snapshot.Contracts.Add(scriptHash, state);
            snapshot.Storages.Add(storageKey, storageItem);
            engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true);
            engine.LoadScript(new byte[0]);
            engine.DestroyContract();
            engine.Snapshot.Storages.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse();

            //storages are removed
            snapshot = Blockchain.Singleton.GetSnapshot();
            state    = TestUtils.GetContract();
            snapshot.Contracts.Add(scriptHash, state);
            engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true);
            engine.LoadScript(new byte[0]);
            engine.DestroyContract();
            engine.Snapshot.Storages.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse();
        }