public void TestParseStringParameter_empty_string() { var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter(string.Empty); param.Type.Should().Be(ContractParameterType.String); param.Value.Should().Be(string.Empty); }
public void TestParseStringParameter_at_account_missing() { const string account = "test-account"; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter($"@{account}"); param.Type.Should().Be(ContractParameterType.String); param.Value.Should().Be($"@{account}"); }
public void TestParseStringParameter_string() { const string expected = "string-value"; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter(expected); param.Type.Should().Be(ContractParameterType.String); param.Value.Should().Be(expected); }
public void TestParseStringParameter_hash_uint160_fail() { const string hashString = "#30f41a14ca6019038b055b585d002b287b5fdd4"; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter(hashString); param.Type.Should().Be(ContractParameterType.String); param.Value.Should().Be(hashString); }
public void TestParseStringParameter_hash_uint256_fail() { const string hashString = "#a372ac8f778eeebb1ccdbb250fe596b83d1d1b9f366d71dfd4c53956bed5cce"; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter(hashString); param.Type.Should().Be(ContractParameterType.String); param.Value.Should().Be(hashString); }
public void TestParseStringParameter_hash_uint160() { const string hashString = "30f41a14ca6019038b055b585d002b287b5fdd47"; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter($"#{hashString}"); param.Type.Should().Be(ContractParameterType.Hash160); param.Value.Should().Be(UInt160.Parse(hashString)); }
public void TestParseStringParameter_at_address() { var expectedValue = UInt160.Parse("30f41a14ca6019038b055b585d002b287b5fdd47"); var address = Neo.Wallets.Helper.ToAddress(expectedValue, DEFAULT_ADDRESS_VERSION); var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter($"@{address}"); param.Type.Should().Be(ContractParameterType.Hash160); param.Value.Should().Be(expectedValue); }
public void TestParseStringParameter_at_address_fallthru() { var uint160 = UInt160.Parse("30f41a14ca6019038b055b585d002b287b5fdd47"); var address = Neo.Wallets.Helper.ToAddress(uint160, DEFAULT_ADDRESS_VERSION); var expected = "@" + address.Substring(0, address.Length - 1); var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseStringParameter(expected); param.Type.Should().Be(ContractParameterType.String); param.Value.Should().Be(expected); }
public void TestParseStringParameter_at_account() { const string account = "test-account"; var expectedValue = UInt160.Parse("30f41a14ca6019038b055b585d002b287b5fdd47"); var accounts = new Dictionary <string, UInt160> { { account, expectedValue } }; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION, tryGetAccount: accounts.TryGetValue); var param = parser.ParseStringParameter($"@{account}"); param.Type.Should().Be(ContractParameterType.Hash160); param.Value.Should().Be(expectedValue); }
public static UInt160 ParseScriptHash(this ContractParameterParser parser, string hashOrContract) { if (UInt160.TryParse(hashOrContract, out var hash)) { return(hash); } if (parser.TryLoadScriptHash(hashOrContract, out var value)) { return(value); } throw new ArgumentException(nameof(hashOrContract)); }
public void ParseObjectParameter_bytearray_hex() { var value = "0xbcbbcd38fb0c097be28e6aef0177f5d65534eb3b"; var expected = Convert.FromHexString(value.Substring(2)); var json = new JObject() { ["type"] = "ByteArray", ["value"] = value }; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseObjectParameter(json); param.Type.Should().Be(ContractParameterType.ByteArray); param.Value.Should().BeOfType <byte[]>(); ((byte[])param.Value).AsSpan().SequenceEqual(expected).Should().BeTrue(); }
public void ParseObjectParameter_bytearray_base64() { var value = "9WPqQLwoPU0OBcSOowWz8qBzQO8="; var expected = Convert.FromBase64String(value); var json = new JObject() { ["type"] = "ByteArray", ["value"] = value }; var parser = new ContractParameterParser(DEFAULT_ADDRESS_VERSION); var param = parser.ParseObjectParameter(json); param.Type.Should().Be(ContractParameterType.ByteArray); param.Value.Should().BeOfType <byte[]>(); ((byte[])param.Value).AsSpan().SequenceEqual(expected).Should().BeTrue(); }
public static void EmitContractCall <T>(this ScriptBuilder builder, UInt160 scriptHash, Expression <Action <T> > expression) { var methodCall = (MethodCallExpression)expression.Body; var operation = methodCall.Method.Name; for (var x = methodCall.Arguments.Count - 1; x >= 0; x--) { var obj = Expression.Lambda(methodCall.Arguments[x]).Compile().DynamicInvoke(); var param = ContractParameterParser.ConvertObject(obj); builder.EmitPush(param); } builder.EmitPush(methodCall.Arguments.Count); builder.Emit(OpCode.PACK); builder.EmitPush(CallFlags.All); builder.EmitPush(operation); builder.EmitPush(scriptHash); builder.EmitSysCall(ApplicationEngine.System_Contract_Call); }
static ContractParameter ConvertArg(string arg, ContractParameterParser parser) { if (bool.TryParse(arg, out var boolArg)) { return(new ContractParameter() { Type = ContractParameterType.Boolean, Value = boolArg }); } if (long.TryParse(arg, out var longArg)) { return(new ContractParameter() { Type = ContractParameterType.Integer, Value = new BigInteger(longArg) }); } return(parser.ParseParameter(arg)); }
public LaunchConfigParser(LaunchArguments launchArguments) { config = launchArguments.ConfigurationProperties; paramParser = new ContractParameterParser(accounts.TryGetValue, contracts.TryGetValue); }