-
Notifications
You must be signed in to change notification settings - Fork 1k
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
protected OnSysCall and OnCallT methods #3225
Conversation
Use no need to have this PR |
But in this way I still need to re-write a whole |
I'll write you an example give me an minute. |
If you want normal calling just add // Copyright (C) 2015-2024 The Neo Project.
//
// MyApplicationEngine.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
using Neo.VM;
namespace MyApp
{
public class MyApplicationEngine : ApplicationEngine
{
protected MyApplicationEngine(
TriggerType trigger,
IVerifiable container,
DataCache snapshot,
Block persistingBlock,
ProtocolSettings settings,
long gas,
IDiagnostic diagnostic,
JumpTable jumpTable = null)
: base(trigger, container, snapshot, persistingBlock, settings, gas, diagnostic, jumpTable)
{
}
protected override void OnSysCall(InteropDescriptor descriptor)
{
// TODO: Implement OnSysCall
}
}
public class MyApplicationEngineProvider : IApplicationEngineProvider
{
public ApplicationEngine Create(TriggerType trigger, IVerifiable container, DataCache snapshot, Block persistingBlock, ProtocolSettings settings, long gas, IDiagnostic diagnostic, JumpTable jumpTable)
{
return new MyApplicationEngine(trigger, container, snapshot, persistingBlock, settings, gas, diagnostic, new MyJumpTable());
}
}
public class MyJumpTable : JumpTable
{
public MyJumpTable() : base()
{
this[OpCode.SYSCALL] = Syscall;
this[OpCode.CALLT] = CallT;
}
public override void Syscall(ExecutionEngine engine, Instruction instruction)
{
// TODO: Implement Syscall
}
public override void CallT(ExecutionEngine engine, Instruction instruction)
{
// TODO: Implement CallT
}
}
} |
@Hecate2 Just fyi you just do ApplicationEngine.Provider = new MyApplicationEngineProvider();
ApplicationEngine.Run(script, snapshot, tx, settings: neoSystem.Settings); |
Does it still require re-writing a whole |
no, If you still want to call the // MyJumpTable Class ....
public override void CallT(ExecutionEngine engine, Instruction instruction)
{
// TODO: Add work before
base.CallT(engine, instruction);
// TODO: Add work After
} |
But neo/src/Neo.VM/JumpTable/JumpTable.Control.cs Lines 394 to 398 in 1d95792
|
Yes, if you dont want it to, then do this public class MyApplicationEngineProvider : IApplicationEngineProvider
{
public static Action<ExecutionEngine, Instruction> Original_OnCallT { get; private set; };
public ApplicationEngine Create(TriggerType trigger, IVerifiable container, DataCache snapshot, Block persistingBlock, ProtocolSettings settings, long gas, IDiagnostic diagnostic, JumpTable jumpTable)
{
Original_OnCallT = jumpTable.CallT;
return new MyApplicationEngine(trigger, container, snapshot, persistingBlock, settings, gas, diagnostic, new MyJumpTable());
}
}
public class MyJumpTable : JumpTable
{
public MyJumpTable() : base()
{
}
public override void Syscall(ExecutionEngine engine, Instruction instruction)
{
// TODO: Implement Syscall
}
public override void CallT(ExecutionEngine engine, Instruction instruction)
{
// TODO: Implement CallT
MyApplicationEngineProvider.Original_OnCallT(engine, instruction);
}
} |
Then we have to rewrite OnCallT again... |
@Hecate2 |
But with the codes above, I cannot construct a jumpTable with a modified |
Edit: |
@Hecate2 make |
So your discussion result is keeping this pr? |
@Jim8y yes, just needs to make changes I requested in #3225 (comment) |
e1104e2
to
414c997
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close #3226?
Description
For the testability of contracts, could we change the accessibility of
OnSysCall
andOnCallT
toprotected
?For example, we may need to use a fixed random number or a given timestamp in the runtime of contracts, in order to test contracts. Consequently we need to modify the InteropServices and the
OnSysCall
method in order to achieve it. I have posted an example at Hecate2/neo-fairy-test@ac22feb that utilizes the protectedOnCallT
. IfOnCallT
was private, I would have to re-implement the wholeOnCallT
by myself, with more dependent methods still being private.Type of change
There is almost no change...
How Has This Been Tested?
No need for new tests. There seems to be no problem in all the existing tests.
Checklist: