Skip to content

Commit

Permalink
apply
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommo-L committed Oct 29, 2020
1 parent a3adbad commit 5659931
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/neo/SmartContract/ApplicationEngine.Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
newDataSize = (1 + value.Length / 4);
if (value.Length < 4)
newDataSize = 1;
else if (value.Length <= item.Value.Length)
newDataSize = value.Length / 4;
else
newDataSize = (1 + item.Value.Length / 4 + value.Length - item.Value.Length);
newDataSize = item.Value.Length / 4 + value.Length - item.Value.Length;
}
AddGas(newDataSize * StoragePrice);

Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/SmartContract/UT_InteropPrices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void ApplicationEngineRegularPut()
debugger.StepInto();
var setupPrice = ae.GasConsumed;
debugger.Execute();
(ae.GasConsumed - setupPrice).Should().Be(ApplicationEngine.StoragePrice * (value.Length + 1));
(ae.GasConsumed - setupPrice).Should().Be(ApplicationEngine.StoragePrice * value.Length);
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public void ApplicationEngineReusedStorage_PartialReuse()
var setupPrice = ae.GasConsumed;
debugger.StepInto();
debugger.StepInto();
(ae.GasConsumed - setupPrice).Should().Be((oldValue.Length / 4 + 1 + value.Length - oldValue.Length) * ApplicationEngine.StoragePrice);
(ae.GasConsumed - setupPrice).Should().Be((oldValue.Length / 4 + value.Length - oldValue.Length) * ApplicationEngine.StoragePrice);
}
}

Expand Down

0 comments on commit 5659931

Please sign in to comment.