public void FunctionCallWithTooIncorrectElementTypeOnStackThrows(VmType type1, VmType type2, VmType type3) { var functionDefinition1 = new FunctionDefinition( new List <Instruction>() { BuildConstantToStackInstruction(type1), BuildConstantToStackInstruction(type2), BuildConstantToStackInstruction(type3), new Instruction(CallFunction, 1L) }, new List <VmType>(), new List <VmType> { VmType.Integer, VmType.Integer, VmType.Boolean }, 0 ); var functionDefinition2 = new FunctionDefinition( new List <Instruction>(), new List <VmType> { VmType.Integer, VmType.Integer, VmType.Boolean }, new List <VmType> { VmType.Integer }, 0 ); var vm = new VirtualMachine(functionDefinition1, functionDefinition2); var exception = Assert.Throws <InvalidSourceException>(() => vm.Execute()); Assert.Equal(InvalidSourceDetail.IncorrectCallArgumentType, exception.DetailCode); }
public VmDefinition(StorageAccountDefinition saDefinition) { this.vmName = TestSettings.Instance.VirtualMachineName; this.vmRg = TestSettings.Instance.VirtualMachineResourceGroupName; this.vmType = (VmType)Enum.Parse(typeof(VmType), TestSettings.Instance.VirtualMachineType); this.saDefinition = saDefinition; }
public void ConditionalBranchingWithIncorrectTypesOnStackThrows(VmType type, InstructionCode instructionCode) { var instructions = new List <Instruction>() { BuildConstantToStackInstruction(type), new Instruction(instructionCode, 0L) }; var exception = Assert.Throws <InvalidSourceException>(() => ExecuteBooleanFunction(instructions)); Assert.Equal(InvalidSourceDetail.IncorrectElementTypeOnStack, exception.DetailCode); }
protected Instruction BuildConstantToStackInstruction(VmType dataType) { switch (dataType) { case VmType.Boolean: return(new Instruction(BooleanConstantToStack, true)); case VmType.Integer: return(new Instruction(IntegerConstantToStack, 0L)); default: Assert.True(false); throw new System.Exception("Unrecognized Type"); } }
public static InvokeCode makeInvokeCode(string funcname, JArray parameters, string hash, VmType vmtype = VmType.NativeVM) { var invokeCode = new InvokeCode(); var vmCode = new VmCode(); var code = buildSmartContractParam(funcname, parameters); //Console.WriteLine("code:" + code); code += Crypto.NumberToHex(Crypto.HexToInteger(OPCODE.TAILCALL)); code += hash; vmCode.code = code; vmCode.vmType = vmtype; invokeCode.code = vmCode; return(invokeCode); }
public void FunctionCallWithIncorrectArgumentTypesOnExitThrows(int elementsOnStackPreCall, VmType type1, VmType type2, VmType type3) { var instructions1 = new List <Instruction>(); for (int i = 0; i < elementsOnStackPreCall; i++) { instructions1.Add(new Instruction(BooleanConstantToStack, true)); } instructions1.Add(new Instruction(CallFunction, 1L)); instructions1.Add(new Instruction(StackToVariable, 0L)); instructions1.Add(new Instruction(StackToVariable, 0L)); for (int i = 0; i < elementsOnStackPreCall; i++) { } var functionDefinition1 = new FunctionDefinition( instructions1, new List <VmType>(), new List <VmType> { VmType.Boolean }, 1 ); var functionDefinition2 = new FunctionDefinition( new List <Instruction> { BuildConstantToStackInstruction(type1), BuildConstantToStackInstruction(type2), BuildConstantToStackInstruction(type3), }, new List <VmType> { }, new List <VmType> { VmType.Integer, VmType.Integer, VmType.Boolean }, 1 ); var vm = new VirtualMachine(functionDefinition1, functionDefinition2); var exception = Assert.Throws <InvalidSourceException>(() => vm.Execute()); Assert.Equal(InvalidSourceDetail.IncorrectReturnArgumentType, exception.DetailCode); }
public static InvokeCode makeInvokeCode(string funcname, JArray parameters, string hash, VmType vmtype = VmType.NativeVM) { var invokeCode = new InvokeCode(); var vmCode = new VmCode(); var args = buildSmartContractParam(funcname, parameters); //Console.WriteLine("code:" + code); var contract = new Contract(); contract.address = hash; contract.args = args; contract.method = ""; var code = contract.serialize(); code = Crypto.NumberToHex(Crypto.HexToInteger(OPCODE.APPCALL)) + code; vmCode.code = code; vmCode.vmType = vmtype; invokeCode.code = vmCode; return(invokeCode); }
public void InstructionRequiringDataWithInvalidTypeThrows(InstructionCode instructionCode, VmType vmType) { var instructions = new List <Instruction>(); switch (vmType) { case VmType.Integer: instructions.Add(new Instruction(instructionCode, 0L)); break; case VmType.Boolean: instructions.Add(new Instruction(instructionCode, true)); break; default: Assert.True(false); // error in test; break; } var functionDefinition = new FunctionDefinition(instructions, new List <VmType>(), new List <VmType>() { VmType.Boolean }, 0); var exception = Assert.Throws <InvalidSourceException>(() => new VirtualMachine(functionDefinition)); Assert.Equal(InvalidSourceDetail.InvalidInstructionData, exception.DetailCode); }