Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Add] NeoToken to have 8 Decimals #3617

Draft
wants to merge 5 commits into
base: HF_Echidna
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Neo/SmartContract/Native/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

using Neo.Cryptography.ECC;
using Neo.Extensions;
using Neo.IO;
using Neo.Persistence;
using Neo.SmartContract.Iterators;
using Neo.VM;
Expand All @@ -32,7 +31,12 @@ namespace Neo.SmartContract.Native
public sealed class NeoToken : FungibleToken<NeoToken.NeoAccountState>
{
public override string Symbol => "NEO";
public override byte Decimals => 0;

[ContractMethod(true, Hardfork.HF_Echidna, Name = "decimals")]
public byte DecimalsV0 => 0;

[ContractMethod(Hardfork.HF_Echidna)]
public override byte Decimals => 8;

/// <summary>
/// Indicates the total amount of NEO.
Expand Down Expand Up @@ -69,7 +73,7 @@ public sealed class NeoToken : FungibleToken<NeoToken.NeoAccountState>
"new", ContractParameterType.Array)]
internal NeoToken() : base()
{
TotalAmount = 100000000 * Factor;
TotalAmount = 100_000_000 * Factor;
}

public override BigInteger TotalSupply(DataCache snapshot)
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task Check_BalanceOfTransferAndBurn()
NativeContract.NEO.Transfer(snapshot, from, to, BigInteger.Zero, true, persistingBlock).Should().BeTrue();
Assert.ThrowsException<ArgumentNullException>(() => NativeContract.NEO.Transfer(snapshot, from, null, BigInteger.Zero, true, persistingBlock));
Assert.ThrowsException<ArgumentNullException>(() => NativeContract.NEO.Transfer(snapshot, null, to, BigInteger.Zero, false, persistingBlock));
NativeContract.NEO.BalanceOf(snapshot, from).Should().Be(100000000);
NativeContract.NEO.BalanceOf(snapshot, from).Should().Be(100000000 * NativeContract.NEO.Factor);
NativeContract.NEO.BalanceOf(snapshot, to).Should().Be(0);

NativeContract.GAS.BalanceOf(snapshot, from).Should().Be(52000500_00000000);
Expand Down
22 changes: 11 additions & 11 deletions tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void TestSetup()
public void Check_Symbol() => NativeContract.NEO.Symbol(_snapshotCache).Should().Be("NEO");

[TestMethod]
public void Check_Decimals() => NativeContract.NEO.Decimals(_snapshotCache).Should().Be(0);
public void Check_Decimals() => NativeContract.NEO.Decimals(_snapshotCache).Should().Be(8);

[TestMethod]
public void Check_Vote()
Expand Down Expand Up @@ -338,7 +338,7 @@ public void Check_GetCommittee()
var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray();
clonedCache.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState()));
var accountState = clonedCache.TryGet(CreateStorageKey(20, G_Account)).GetInteroperable<NeoAccountState>();
accountState.Balance = 20000000;
accountState.Balance = 20000000 * NativeContract.NEO.Factor;
var ret = Check_RegisterValidator(clonedCache, ECCurve.Secp256r1.G.ToArray(), persistingBlock);
ret.State.Should().BeTrue();
ret.Result.Should().BeTrue();
Expand Down Expand Up @@ -408,15 +408,15 @@ public void Check_Transfer()
// Transfer

NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One, false, persistingBlock).Should().BeFalse(); // Not signed
NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One, true, persistingBlock).Should().BeTrue();
NativeContract.NEO.BalanceOf(clonedCache, from).Should().Be(99999999);
NativeContract.NEO.BalanceOf(clonedCache, to).Should().Be(1);
NativeContract.NEO.Transfer(clonedCache, from, to, BigInteger.One * NativeContract.NEO.Factor, true, persistingBlock).Should().BeTrue();
NativeContract.NEO.BalanceOf(clonedCache, from).Should().Be(99999999 * NativeContract.NEO.Factor);
NativeContract.NEO.BalanceOf(clonedCache, to).Should().Be(1 * NativeContract.NEO.Factor);

var (from_balance, _, _) = GetAccountState(clonedCache, new UInt160(from));
var (to_balance, _, _) = GetAccountState(clonedCache, new UInt160(to));

from_balance.Should().Be(99999999);
to_balance.Should().Be(1);
from_balance.Should().Be(99999999 * NativeContract.NEO.Factor);
to_balance.Should().Be(1 * NativeContract.NEO.Factor);

// Check unclaim

Expand All @@ -430,7 +430,7 @@ public void Check_Transfer()

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

NativeContract.NEO.Transfer(clonedCache, to, from, BigInteger.One, true, persistingBlock).Should().BeTrue();
NativeContract.NEO.Transfer(clonedCache, to, from, BigInteger.One * NativeContract.NEO.Factor, true, persistingBlock).Should().BeTrue();
NativeContract.NEO.BalanceOf(clonedCache, to).Should().Be(0);
clonedCache.GetChangeSet().Count().Should().Be(keyCount - 1); // Remove neo balance from address two

Expand All @@ -451,7 +451,7 @@ public void Check_BalanceOf()
var clonedCache = _snapshotCache.CloneCache();
byte[] account = Contract.GetBFTAddress(TestProtocolSettings.Default.StandbyValidators).ToArray();

NativeContract.NEO.BalanceOf(clonedCache, account).Should().Be(100_000_000);
NativeContract.NEO.BalanceOf(clonedCache, account).Should().Be(100_000_000 * NativeContract.NEO.Factor);

account[5]++; // Without existing balance

Expand Down Expand Up @@ -732,7 +732,7 @@ public void TestOnBalanceChanging()
public void TestTotalSupply()
{
var clonedCache = _snapshotCache.CloneCache();
NativeContract.NEO.TotalSupply(clonedCache).Should().Be(new BigInteger(100000000));
NativeContract.NEO.TotalSupply(clonedCache).Should().Be(100000000 * NativeContract.NEO.Factor);
}

[TestMethod]
Expand Down Expand Up @@ -760,7 +760,7 @@ public void TestEconomicParameter()
// Check calculate bonus
StorageItem storage = clonedCache.GetOrAdd(CreateStorageKey(20, UInt160.Zero.ToArray()), () => new StorageItem(new NeoAccountState()));
NeoAccountState state = storage.GetInteroperable<NeoAccountState>();
state.Balance = 1000;
state.Balance = 1000 * NativeContract.NEO.Factor;
state.BalanceHeight = 0;
height.Index = persistingBlock.Index + 1;
NativeContract.NEO.UnclaimedGas(clonedCache, UInt160.Zero, persistingBlock.Index + 2).Should().Be(6500);
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.UnitTests/Wallets/UT_AssetDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Check_NEO()
descriptor.AssetName.Should().Be(nameof(NeoToken));
descriptor.ToString().Should().Be(nameof(NeoToken));
descriptor.Symbol.Should().Be("NEO");
descriptor.Decimals.Should().Be(0);
descriptor.Decimals.Should().Be(8);
}
}
}
Loading