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 GetCallFlags #1587

Merged
merged 1 commit into from
Apr 19, 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
9 changes: 9 additions & 0 deletions src/neo/SmartContract/InteropService.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class Contract
public static readonly InteropDescriptor Call = Register("System.Contract.Call", Contract_Call, 0_01000000, TriggerType.System | TriggerType.Application, CallFlags.AllowCall);
public static readonly InteropDescriptor CallEx = Register("System.Contract.CallEx", Contract_CallEx, 0_01000000, TriggerType.System | TriggerType.Application, CallFlags.AllowCall);
public static readonly InteropDescriptor IsStandard = Register("System.Contract.IsStandard", Contract_IsStandard, 0_00030000, TriggerType.All, CallFlags.None);
public static readonly InteropDescriptor GetCallFlags = Register("System.Contract.GetCallFlags", Contract_GetCallFlags, 0_00030000, TriggerType.All, CallFlags.None);

/// <summary>
/// Calculate corresponding account scripthash for given public key
/// Warning: check first that input public key is valid, before creating the script.
Expand All @@ -36,6 +38,13 @@ private static long GetDeploymentPrice(EvaluationStack stack, StoreView snapshot
return Storage.GasPerByte * size;
}

private static bool Contract_GetCallFlags(ApplicationEngine engine)
{
var state = engine.CurrentContext.GetState<ExecutionContextState>();
engine.Push((int)state.CallFlags);
return true;
}

private static bool Contract_Create(ApplicationEngine engine)
{
if (!engine.TryPop(out ReadOnlySpan<byte> script)) return false;
Expand Down
9 changes: 9 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ public void TestExecutionEngine_GetEntryScriptHash()
.Should().Be(engine.EntryScriptHash.ToArray().ToHexString());
}

[TestMethod]
public void TestContract_GetCallFlags()
{
var engine = GetEngine();
InteropService.Invoke(engine, InteropService.Contract.GetCallFlags).Should().BeTrue();
engine.CurrentContext.EvaluationStack.Pop().GetBigInteger()
.Should().Be(((int)CallFlags.All));
}

[TestMethod]
public void TestRuntime_Platform()
{
Expand Down