diff --git a/src/neo/SmartContract/ApplicationEngine.Storage.cs b/src/neo/SmartContract/ApplicationEngine.Storage.cs index c0965806d7..ce87bc6211 100644 --- a/src/neo/SmartContract/ApplicationEngine.Storage.cs +++ b/src/neo/SmartContract/ApplicationEngine.Storage.cs @@ -100,10 +100,12 @@ private void PutExInternal(StorageContext context, byte[] key, byte[] value, Sto else { if (item.IsConstant) throw new InvalidOperationException(); - if (value.Length <= item.Value.Length) + if (value.Length == 0) newDataSize = 1; + else if (value.Length <= item.Value.Length) + newDataSize = (value.Length - 1) / 4 + 1; else - newDataSize = value.Length - item.Value.Length; + newDataSize = (item.Value.Length - 1) / 4 + 1 + value.Length - item.Value.Length; } AddGas(newDataSize * StoragePrice); diff --git a/tests/neo.UnitTests/SmartContract/UT_InteropPrices.cs b/tests/neo.UnitTests/SmartContract/UT_InteropPrices.cs index ab959e7f6e..00e3d09444 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropPrices.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropPrices.cs @@ -74,7 +74,7 @@ public void ApplicationEngineRegularPut() debugger.StepInto(); var setupPrice = ae.GasConsumed; debugger.Execute(); - (ae.GasConsumed - setupPrice).Should().Be(ApplicationEngine.StoragePrice * value.Length); + (ae.GasConsumed - setupPrice).Should().Be(ApplicationEngine.StoragePrice * (1 + value.Length)); } } @@ -145,7 +145,7 @@ public void ApplicationEngineReusedStorage_PartialReuse() var setupPrice = ae.GasConsumed; debugger.StepInto(); debugger.StepInto(); - (ae.GasConsumed - setupPrice).Should().Be(1 * ApplicationEngine.StoragePrice); + (ae.GasConsumed - setupPrice).Should().Be((1 + (oldValue.Length / 4) + value.Length - oldValue.Length) * ApplicationEngine.StoragePrice); } } @@ -185,7 +185,7 @@ public void ApplicationEngineReusedStorage_PartialReuseTwice() debugger.StepInto(); //syscall Storage.GetContext var setupPrice = ae.GasConsumed; debugger.StepInto(); //syscall Storage.Put - (ae.GasConsumed - setupPrice).Should().Be(1 * ApplicationEngine.StoragePrice); // = PUT basic fee + (ae.GasConsumed - setupPrice).Should().Be((sItem.Value.Length / 4 + 1) * ApplicationEngine.StoragePrice); // = PUT basic fee } }