CityOfZion / neo-debugger-tools

A set of tools to develop NEO smart contracts
MIT License
24 stars 20 forks source link

Is there a sample source setting arguments and executing UnitTest? #170

Closed skashitam closed 5 years ago

skashitam commented 5 years ago

I want to do UnitTest of SmartContract using "Neo.Emulator".

I can execute methods without arguments, but I can not execute methods that require arguments. Is there a sample source setting arguments and executing UnitTest?

It is a source that has been successfully executed.

        public void NameTest()
        {
            var inputs = DataNode.CreateArray();
            inputs.AddValue("name");
            inputs.AddValue(null);

            emulator.Reset(inputs, null);
            emulator.Run();

            var result = emulator.GetOutput();
            var name = result.GetString();

            if (name != "Test Token") Assert.Fail();
        }
lock9 commented 5 years ago

Hello @skashitam. What version are you using?

We use DebugParameters to configure the tests. Could try something similar to this:

var testCase = _tests.cases[testItem.TestName];
debugParams.ArgList = testCase.args; // Arglist will be something similar to "[name, [arg1, arg2]]"
SetDebugParameters(debugParams);
Run();
var result = _emulator.GetOutput();

Please contact me in Discord for further assistance ricklock#4529.

skashitam commented 5 years ago

thank you for your answer.

I am using NeoEmulator 1.0.0. I installed NeoEmulator from NugetPM.

Thank you for letting me know about "debugParam".

I can not use name space "Neo.Debugger" in my project, Is the version of NeoEmulator old?

lock9 commented 5 years ago

I'm not very sure, I'm not responsible for publishing it into Nuget, sorry :( Maybe you can try it by cloning the repository instead?

skashitam commented 5 years ago

@lock9 Thank you very much.

I will clone from github's master repository and try it.

By the way, which version are you using? From which version will "debugParam" work?

lock9 commented 5 years ago

I'm using the development branch, however I'm sure this is present in the current master branch too

lock9 commented 5 years ago

@skashitam Were you able to solve your problem?

skashitam commented 5 years ago

@lock9 Thank you very much. My problem is solved!