Ejemplo n.º 1
0
        public void TestEqualSmallerBigger()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array = 3;" +
                       "if(1 <= 1){" +
                       "var test1 = 1;" +
                       "}" +
                       "if(1 <= 2){" +
                       "var test2 = 1;" +
                       "}" +
                       "if(2 >= 2){" +
                       "var test3 = 1;" +
                       "}" +
                       "if(3 >= 2){" +
                       "var test4 = 1;" +
                       "}" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("test1").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("test2").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("test3").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("test4").GetValueAs <int>().Should().Be(1);
        }
Ejemplo n.º 2
0
        public void EntryParaMeterTest()
        {
            var code = "Application {" +
                       "entry Main(length,stuff) {" +
                       "var var = length;" +
                       "var result = stuff * var;" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            var triggerTrans = new Transaction("you", 2, "pool")
                               .AddFee(0)
                               .AddData("Main")
                               .AddData("3")
                               .AddData("x")
                               .Final(_settings);

            comp.Run(triggerTrans);

            comp.CheckRegister("var").GetValueAs <int>().Should().Be(3);
            comp.CheckRegister("result").GetValueAs <string>().Should().Be("xxx");
        }
Ejemplo n.º 3
0
        public void IfSimpleTest01()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var comparer = 33;" +
                       "if(0 == 0){" +
                       "var Test1 = 1;" +
                       "}" +
                       "if(0 != comparer){" +
                       "var Test2 = 1;" +
                       "}" +
                       "if(33 == comparer){" +
                       "var Test3 = 1;" +
                       "}" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp   = ComputerCreator.CreateComputer(list);
            var result = comp.Run();

            comp.CheckRegister("Test1").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("Test2").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("Test3").GetValueAs <int>().Should().Be(1);
        }
Ejemplo n.º 4
0
        public void TestMetaDataAccess()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array = _META[3];" +
                       "var balance = _META[4];" +
                       "if(_META[3] == \"From\"){" +
                       "var test = 1;" +
                       "}" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });
            var triggerTrans = new Transaction("From", 2, "PoolAddress")
                               .AddOutput(100, "you")
                               .AddFee(0)
                               .AddData("Main")
                               .Final(_settings);

            comp.Run(triggerTrans);

            comp.CheckRegister("array").GetValueAs <string>().Should().Be("From");
            comp.CheckRegister("test").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("balance").GetValueAs <int>().Should().Be(100);
        }
Ejemplo n.º 5
0
        public void ArrayTest()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array[3];" +
                       "array[0] = 3;" +
                       "var test = array[0] + 3;" +

                       "var index = 0;" +
                       "var recursive = array[index];" +
                       "array[index] = index;" +
                       "index = index + 1;" +
                       "array[index] = index;" +
                       "index = index + 1;" +
                       "array[index] = index;" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("array_0").GetValueAs <int>().Should().Be(0);
            comp.CheckRegister("array_1").GetValueAs <int>().Should().Be(1);
            comp.CheckRegister("array_2").GetValueAs <int>().Should().Be(2);
            comp.CheckRegister("test").GetValueAs <int>().Should().Be(6);
            comp.CheckRegister("recursive").GetValueAs <int>().Should().Be(3);
        }
Ejemplo n.º 6
0
        public void SameVarNameTest()
        {
            var code = "Application {" +
                       "function test(){" +
                       "var test = 3;" +
                       "return test + 3;" +
                       "}" +
                       "entry Main() {" +
                       "var test = test();" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            var result = comp.CheckRegisterCollection("test");

            result[0].GetValueAs <int>().Should().Be(3);
            result[1].GetValueAs <int>().Should().Be(6);
        }
Ejemplo n.º 7
0
        public void StateArrayTest()
        {
            var code = "Application {" +
                       "state array[2];" +
                       "entry Main() {" +
                       "var index = 0;" +
                       "array[index] = 2;" +
                       "_META[3];" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var stateDict = new Dictionary <string, ISCType>()
            {
                { "array_0", new SC_Int(0) },
                { "array_1", new SC_Int(0) }
            };

            var comp = ComputerCreator.CreateComputer(list, stateDict);

            comp.Run();

            var state = comp.GetCompleteState();

            state["array_0"].GetValueAs <int>().Should().Be(2);
        }
Ejemplo n.º 8
0
        public void StateTest()
        {
            var code = "Application {" +
                       "state s1;" +
                       "entry Main() {" +
                       "s1 = s1 + 1;" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "s1", new SC_Int(0) }
            });

            comp.Run();

            var state = comp.GetCompleteState();

            //we run again
            var comp2 = ComputerCreator.CreateComputer(list, state);

            comp2.Run();

            comp2.State.GetFromRegister("s1").GetValueAs <int>().Should().Be(2);
        }
Ejemplo n.º 9
0
        public void WhileLoopTest()
        {
            var code = "Application {" +
                       "entry Main() {" +

                       "var array[3];" +
                       "var i = -1;" +

                       "while(i < 3){" +
                       "i = i + 1;" +
                       "array[i] = 2;" +
                       "}" +

                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list);

            comp.Run();

            comp.CheckRegister("array_0").GetValueAs <int>().Should().Be(2);
            comp.CheckRegister("array_1").GetValueAs <int>().Should().Be(2);
            comp.CheckRegister("array_2").GetValueAs <int>().Should().Be(2);
        }
Ejemplo n.º 10
0
        public void CommentTest()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "//Please ignore this one;" +
                       "var Test3 = 3; //also ignore this!;" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp   = ComputerCreator.CreateComputer(list);
            var result = comp.Run();

            comp.CheckRegister("Test3").GetValueAs <int>().Should().Be(3);
        }
Ejemplo n.º 11
0
        public void SimpleMathTest02(string exp, int equals)
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var Test = 1;" +
                       $"Test = {exp};" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp   = ComputerCreator.CreateComputer(list);
            var result = comp.Run();

            comp.CheckRegister("Test").GetValueAs <int>().Should().Be(equals);
        }
Ejemplo n.º 12
0
        public void SimpleAssignTest()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var Test2 = 3;" +
                       "var Test3 = Test2;" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp   = ComputerCreator.CreateComputer(list);
            var result = comp.Run();

            comp.CheckRegister("Test2").GetValueAs <int>().Should().Be(3);
            comp.CheckRegister("Test3").GetValueAs <int>().Should().Be(3);
        }
Ejemplo n.º 13
0
        public void VoidLengthTest()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array[3];" +
                       "_LENGTH(array);" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();
        }
Ejemplo n.º 14
0
        public void TestArrayLength()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array[3];" +
                       "var length = _LENGTH(array);" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("length").GetValueAs <int>().Should().Be(3);
        }
Ejemplo n.º 15
0
        public void AndTest()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "if(1 == 1 && 1 == 1){" +
                       "var test = 3;" +
                       "}" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("test").GetValueAs <int>().Should().Be(3);
        }
Ejemplo n.º 16
0
        public void FunctionTestSimple02(int a, int b, int result)
        {
            var code = "Application {" +
                       "function test(test1, test2){" +
                       "return test1 + test2;" +
                       "}" +
                       "entry Main() {" +
                       $"var var = test({a},{b});" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("var").GetValueAs <int>().Should().Be(result);
        }
Ejemplo n.º 17
0
        public void FunctionStringTest()
        {
            var code = "Application {" +
                       "function test(multiplier){" +
                       "return \"x\" * multiplier;" +
                       "}" +
                       "entry Main() {" +
                       "var length = test(3);" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("length").GetValueAs <string>().Should().Be("xxx");
        }
Ejemplo n.º 18
0
        public void FunctionTestSimple01()
        {
            var code = "Application {" +
                       "function test(){" +
                       "var test1 = 3 + 3;" +
                       "return 0;" +
                       "}" +
                       "entry Main() {" +
                       "test();" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });

            comp.Run();

            comp.CheckRegister("test1").GetValueAs <int>().Should().Be(6);
        }
Ejemplo n.º 19
0
        public void OutTransactionTest()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array = 3;" +
                       "_OUT(array,\"LOL\");" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            }, _settings);
            var maybe = comp.Run();


            maybe.HasValue.Should().BeTrue();
            var result = maybe.Value;

            result.OutputReceiver.Should().Contain("LOL");
            result.OutputValue.Should().Contain(3);
        }
Ejemplo n.º 20
0
        public void TestDataAccess()
        {
            var code = "Application {" +
                       "entry Main() {" +
                       "var array = _DATA[2];" +
                       "}" +
                       "}";

            var list = new Strain.Strain(code).Compile();

            var comp = ComputerCreator.CreateComputer(list, new Dictionary <string, ISCType>()
            {
                { "state", new SC_Int(0) }
            });
            var triggerTrans = new Transaction("From", 2, "PoolAddress")
                               .AddFee(0)
                               .AddData("Main")
                               .AddData("CALLER")
                               .Final(_settings);

            comp.Run(triggerTrans);

            comp.CheckRegister("array").GetValueAs <string>().Should().Be("CALLER");
        }
        public void MultisignatureTestWithoutArray()
        {
            var strain = new Strain.Strain(CodeWithoutArray);

            var list = strain.Compile();

            var stateDict = new Dictionary <string, ISCType>()
            {
                { "user0", new SC_String() },
                { "user1", new SC_String() },
                { "vote0", new SC_String() },
                { "vote1", new SC_String() },
                { "balance0", new SC_Int(0) },
                { "balance1", new SC_Int(0) }
            };

            var comp = ComputerCreator.CreateComputer(list, stateDict, _settings);

            var triggertrans = new Transaction("person1", 2, "pool")
                               .AddFee(0)
                               .AddData("Init")
                               .AddData("person1")
                               .AddData("person2")
                               .Final(_settings);

            //init contract
            comp.Run(triggertrans);

            var state1 = comp.GetCompleteState();

            var comp2         = ComputerCreator.CreateComputer(list, state1, _settings);
            var triggertrans2 = new Transaction("person1", 2, "pool")
                                .AddFee(0)
                                .AddData("Vote")
                                .AddData("person3")
                                .AddData("Int_3")
                                .Final(_settings);

            //vote with person 1
            comp2.Run(triggertrans2);
            var state2 = comp2.GetCompleteState();

            //doing a test vote to get the money out!
            var testTrigger = new Transaction("person2", 2, "pool")
                              .AddFee(0)
                              .AddData("Send")
                              .Final(_settings);
            var shouldBeEmpty = comp2.Run(testTrigger);

            shouldBeEmpty.HasValue.Should().BeFalse();

            var comp3         = ComputerCreator.CreateComputer(list, state2, _settings);
            var triggertrans3 = new Transaction("person2", 2, "pool")
                                .AddFee(0)
                                .AddData("Vote")
                                .AddData("person3")
                                .AddData("Int_3")
                                .Final(_settings);

            //vote with person 2
            comp3.Run(triggertrans3);
            var state3 = comp3.GetCompleteState();

            var comp4         = ComputerCreator.CreateComputer(list, state3, _settings);
            var triggertrans4 = new Transaction("person2", 2, "pool")
                                .AddFee(0)
                                .AddData("Send")
                                .Final(_settings);

            //vote with person 2
            var maybe = comp4.Run(triggertrans4);

            maybe.HasValue.Should().BeTrue();
            var result = maybe.Value;

            result.OutputReceiver.Should().Contain("person3");
            result.OutputValue.Should().Contain(3);
        }