Skip to content

Commit

Permalink
Change Initialize GAS to 52000000 * Factor (#2544)
Browse files Browse the repository at this point in the history
  • Loading branch information
superboyiii committed Jul 19, 2021
1 parent e7fbba3 commit a12eddb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public record ProtocolSettings
/// </summary>
public IReadOnlyDictionary<string, uint[]> NativeUpdateHistory { get; init; }

/// <summary>
/// Indicates the amount of gas to distribute during initialization.
/// </summary>
public ulong InitialGasDistribution { get; init; }

private IReadOnlyList<ECPoint> _standbyValidators;
/// <summary>
/// The public keys of the standby validators.
Expand Down Expand Up @@ -130,6 +135,7 @@ public record ProtocolSettings
MaxTransactionsPerBlock = 512,
MemoryPoolMaxTransactions = 50_000,
MaxTraceableBlocks = 2_102_400,
InitialGasDistribution = 52_000_000_00000000,
NativeUpdateHistory = new Dictionary<string, uint[]>
{
[nameof(ContractManagement)] = new[] { 0u },
Expand Down Expand Up @@ -179,6 +185,7 @@ public static ProtocolSettings Load(IConfigurationSection section)
MaxTransactionsPerBlock = section.GetValue("MaxTransactionsPerBlock", Default.MaxTransactionsPerBlock),
MemoryPoolMaxTransactions = section.GetValue("MemoryPoolMaxTransactions", Default.MemoryPoolMaxTransactions),
MaxTraceableBlocks = section.GetValue("MaxTraceableBlocks", Default.MaxTraceableBlocks),
InitialGasDistribution = section.GetValue("InitialGasDistribution", Default.InitialGasDistribution),
NativeUpdateHistory = section.GetSection("NativeUpdateHistory").Exists()
? section.GetSection("NativeUpdateHistory").GetChildren().ToDictionary(p => p.Key, p => p.GetChildren().Select(q => uint.Parse(q.Value)).ToArray())
: Default.NativeUpdateHistory
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal GasToken()
internal override ContractTask Initialize(ApplicationEngine engine)
{
UInt160 account = Contract.GetBFTAddress(engine.ProtocolSettings.StandbyValidators);
return Mint(engine, account, 30_000_000 * Factor, false);
return Mint(engine, account, engine.ProtocolSettings.InitialGasDistribution, false);
}

internal override async ContractTask OnPersist(ApplicationEngine engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UT_FungibleToken : TestKit
public void TestTotalSupply()
{
var snapshot = TestBlockchain.GetTestSnapshot();
NativeContract.GAS.TotalSupply(snapshot).Should().Be(3000000050000000);
NativeContract.GAS.TotalSupply(snapshot).Should().Be(5200000050000000);
}
}
}
20 changes: 10 additions & 10 deletions tests/neo.UnitTests/SmartContract/Native/UT_GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task Check_BalanceOfTransferAndBurn()
byte[] to = new byte[20];
var keyCount = snapshot.GetChangeSet().Count();
var supply = NativeContract.GAS.TotalSupply(snapshot);
supply.Should().Be(3000000050000000); // 3000000000000000 + 50000000 (neo holder reward)
supply.Should().Be(5200000050000000); // 3000000000000000 + 50000000 (neo holder reward)

// Check unclaim

Expand All @@ -120,7 +120,7 @@ public async Task Check_BalanceOfTransferAndBurn()
NativeContract.NEO.BalanceOf(snapshot, from).Should().Be(100000000);
NativeContract.NEO.BalanceOf(snapshot, to).Should().Be(0);

NativeContract.GAS.BalanceOf(snapshot, from).Should().Be(30000500_00000000);
NativeContract.GAS.BalanceOf(snapshot, from).Should().Be(52000500_00000000);
NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(0);

// Check unclaim
Expand All @@ -130,21 +130,21 @@ public async Task Check_BalanceOfTransferAndBurn()
unclaim.State.Should().BeTrue();

supply = NativeContract.GAS.TotalSupply(snapshot);
supply.Should().Be(3000050050000000);
supply.Should().Be(5200050050000000);

snapshot.GetChangeSet().Count().Should().Be(keyCount + 3); // Gas

// Transfer

keyCount = snapshot.GetChangeSet().Count();

NativeContract.GAS.Transfer(snapshot, from, to, 30000500_00000000, false, persistingBlock).Should().BeFalse(); // Not signed
NativeContract.GAS.Transfer(snapshot, from, to, 30000500_00000001, true, persistingBlock).Should().BeFalse(); // More than balance
NativeContract.GAS.Transfer(snapshot, from, to, 30000500_00000000, true, persistingBlock).Should().BeTrue(); // All balance
NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000000, false, persistingBlock).Should().BeFalse(); // Not signed
NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000001, true, persistingBlock).Should().BeFalse(); // More than balance
NativeContract.GAS.Transfer(snapshot, from, to, 52000500_00000000, true, persistingBlock).Should().BeTrue(); // All balance

// Balance of

NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(30000500_00000000);
NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(52000500_00000000);
NativeContract.GAS.BalanceOf(snapshot, from).Should().Be(0);

snapshot.GetChangeSet().Count().Should().Be(keyCount + 1); // All
Expand All @@ -160,19 +160,19 @@ await Assert.ThrowsExceptionAsync<ArgumentOutOfRangeException>(async () =>
// Burn more than expected

await Assert.ThrowsExceptionAsync<InvalidOperationException>(async () =>
await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(30000500_00000001)));
await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(52000500_00000001)));

// Real burn

await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(1));

NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(3000049999999999);
NativeContract.GAS.BalanceOf(snapshot, to).Should().Be(5200049999999999);

keyCount.Should().Be(snapshot.GetChangeSet().Count());

// Burn all

await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(3000049999999999));
await NativeContract.GAS.Burn(engine, new UInt160(to), new BigInteger(5200049999999999));

(keyCount - 1).Should().Be(snapshot.GetChangeSet().Count());

Expand Down

0 comments on commit a12eddb

Please sign in to comment.