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

Fix asset symbol #2136

Merged
merged 2 commits into from
Dec 11, 2020
Merged
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
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/Tokens/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class GasToken : Nep17Token<AccountState>
public override int Id => -2;
public override string Name => "GAS";
public override uint ActiveBlockIndex => 0;
public override string Symbol => "gas";
public override string Symbol => "GAS";
public override byte Decimals => 8;

internal GasToken()
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/Tokens/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class NeoToken : Nep17Token<NeoToken.NeoAccountState>
public override int Id => -1;
public override string Name => "NEO";
public override uint ActiveBlockIndex => 0;
public override string Symbol => "neo";
public override string Symbol => "NEO";
public override byte Decimals => 0;
public BigInteger TotalAmount { get; }

Expand Down
9 changes: 6 additions & 3 deletions src/neo/Wallets/AssetDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace Neo.Wallets
{
public class AssetDescriptor
{
public UInt160 AssetId;
public string AssetName;
public byte Decimals;
public UInt160 AssetId { get; }
public string AssetName { get; }
public string Symbol { get; }
public byte Decimals { get; }

public AssetDescriptor(UInt160 asset_id)
{
Expand All @@ -23,12 +24,14 @@ public AssetDescriptor(UInt160 asset_id)
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitAppCall(asset_id, "decimals");
sb.EmitAppCall(asset_id, "symbol");
script = sb.ToArray();
}
using ApplicationEngine engine = ApplicationEngine.Run(script, snapshot, gas: 0_02000000);
if (engine.State.HasFlag(VMState.FAULT)) throw new ArgumentException();
this.AssetId = asset_id;
this.AssetName = contract.Manifest.Name;
this.Symbol = engine.ResultStack.Pop().GetString();
this.Decimals = (byte)engine.ResultStack.Pop().GetInteger();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void TestSetup()
public void Check_Name() => NativeContract.GAS.Name.Should().Be("GAS");

[TestMethod]
public void Check_Symbol() => NativeContract.GAS.Symbol(_snapshot).Should().Be("gas");
public void Check_Symbol() => NativeContract.GAS.Symbol(_snapshot).Should().Be("GAS");

[TestMethod]
public void Check_Decimals() => NativeContract.GAS.Decimals(_snapshot).Should().Be(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void TestSetup()
public void Check_Name() => NativeContract.NEO.Name.Should().Be("NEO");

[TestMethod]
public void Check_Symbol() => NativeContract.NEO.Symbol(_snapshot).Should().Be("neo");
public void Check_Symbol() => NativeContract.NEO.Symbol(_snapshot).Should().Be("NEO");

[TestMethod]
public void Check_Decimals() => NativeContract.NEO.Decimals(_snapshot).Should().Be(0);
Expand Down
2 changes: 2 additions & 0 deletions tests/neo.UnitTests/Wallets/UT_AssetDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void Check_GAS()
var descriptor = new Neo.Wallets.AssetDescriptor(NativeContract.GAS.Hash);
descriptor.AssetId.Should().Be(NativeContract.GAS.Hash);
descriptor.AssetName.Should().Be("GAS");
descriptor.Symbol.Should().Be("GAS");
descriptor.ToString().Should().Be("GAS");
descriptor.Decimals.Should().Be(8);
}
Expand All @@ -40,6 +41,7 @@ public void Check_NEO()
var descriptor = new Neo.Wallets.AssetDescriptor(NativeContract.NEO.Hash);
descriptor.AssetId.Should().Be(NativeContract.NEO.Hash);
descriptor.AssetName.Should().Be("NEO");
descriptor.Symbol.Should().Be("NEO");
descriptor.ToString().Should().Be("NEO");
descriptor.Decimals.Should().Be(0);
}
Expand Down