Example #1
0
        public void TestStorage_Delete()
        {
            var engine   = GetEngine(false, true);
            var snapshot = Blockchain.Singleton.GetSnapshot();
            var state    = TestUtils.GetContract();

            state.Manifest.Features = ContractFeatures.HasStorage;
            var storageKey = new StorageKey
            {
                Id  = 0x42000000,
                Key = new byte[] { 0x01 }
            };
            var storageItem = new StorageItem
            {
                Value      = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                IsConstant = false
            };

            snapshot.Contracts.Add(state.ScriptHash, state);
            snapshot.Storages.Add(storageKey, storageItem);
            engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true);
            engine.LoadScript(new byte[] { 0x01 });
            state.Manifest.Features = ContractFeatures.HasStorage;
            var key            = new byte[] { 0x01 };
            var storageContext = new StorageContext
            {
                Id         = state.Id,
                IsReadOnly = false
            };

            engine.Delete(storageContext, key);

            //context is readonly
            storageContext.IsReadOnly = true;
            Assert.ThrowsException <ArgumentException>(() => engine.Delete(storageContext, key));
        }