Skip to content

Commit

Permalink
Add GetCallFlags (neo-project#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and Tommo-L committed Jun 22, 2020
1 parent 53ea390 commit 8d23322
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit 8d23322

Please sign in to comment.