diff --git a/src/smartcontracts/argSerializer.ts b/src/smartcontracts/argSerializer.ts index 31be8cff..bd4a21bf 100644 --- a/src/smartcontracts/argSerializer.ts +++ b/src/smartcontracts/argSerializer.ts @@ -74,8 +74,8 @@ export class ArgSerializer { let typedValue = readValue(type.getFirstTypeParameter()); return new OptionalValue(type, typedValue); } else if (type.hasExactClass(VariadicType.ClassName)) { - let variadicType = type; - let typedValues = []; + const variadicType = type; + const typedValues = []; if (variadicType.isCounted) { const count: number = readValue(new U32Type()).valueOf().toNumber(); @@ -166,8 +166,8 @@ export class ArgSerializer { handleValue(valueAsOptional.getTypedValue()); } } else if (value.hasExactClass(VariadicValue.ClassName)) { - let valueAsVariadic = value; - let variadicType = valueAsVariadic.getType(); + const valueAsVariadic = value; + const variadicType = valueAsVariadic.getType(); if (variadicType.isCounted) { const countValue = new U32Value(valueAsVariadic.getItems().length); diff --git a/src/smartcontracts/resultsParser.spec.ts b/src/smartcontracts/resultsParser.spec.ts index 134c42fa..25c0576b 100644 --- a/src/smartcontracts/resultsParser.spec.ts +++ b/src/smartcontracts/resultsParser.spec.ts @@ -8,7 +8,7 @@ import { LogLevel, Logger } from "../logger"; import { ArgSerializer } from "./argSerializer"; import { ResultsParser } from "./resultsParser"; import { ReturnCode } from "./returnCode"; -import { BigUIntType, BigUIntValue, EndpointDefinition, EndpointModifiers, EndpointParameterDefinition, TypedValue, U32Type, U32Value, U64Type, U64Value, VariadicType, VariadicValue } from "./typesystem"; +import { BigUIntType, BigUIntValue, EndpointDefinition, EndpointModifiers, EndpointParameterDefinition, StringType, StringValue, TypedValue, U32Type, U32Value, U64Type, U64Value, VariadicType, VariadicValue } from "./typesystem"; import { BytesType, BytesValue } from "./typesystem/bytes"; const KnownReturnCodes: string[] = [ @@ -112,7 +112,7 @@ describe("test smart contract results parser", () => { assert.deepEqual(bundle.values[0], VariadicValue.fromItems(new U32Value(42), new U32Value(43))); }); - it("should parse query response (counted-variadic arguments)", async () => { + it("should parse query response (one counted-variadic arguments)", async () => { const endpointModifiers = new EndpointModifiers("", []); const outputParameters = [new EndpointParameterDefinition("a", "a", new VariadicType(new U32Type(), true))]; const endpoint = new EndpointDefinition("foo", [], outputParameters, endpointModifiers); @@ -128,6 +128,34 @@ describe("test smart contract results parser", () => { assert.deepEqual(bundle.values[0], VariadicValue.fromItemsCounted(new U32Value(42), new U32Value(43))); }); + it("should parse query response (multiple counted-variadic arguments)", async () => { + const endpointModifiers = new EndpointModifiers("", []); + const outputParameters = [ + new EndpointParameterDefinition("a", "a", new VariadicType(new U32Type(), true)), + new EndpointParameterDefinition("b", "b", new VariadicType(new StringType(), true)), + new EndpointParameterDefinition("c", "c", new BigUIntType()), + + ]; + const endpoint = new EndpointDefinition("foo", [], outputParameters, endpointModifiers); + const queryResponse = new ContractQueryResponse({ + returnData: [ + Buffer.from([2]).toString("base64"), + Buffer.from([42]).toString("base64"), + Buffer.from([43]).toString("base64"), + Buffer.from([3]).toString("base64"), + Buffer.from("a").toString("base64"), + Buffer.from("b").toString("base64"), + Buffer.from("c").toString("base64"), + Buffer.from([42]).toString("base64") + ] + }); + + const bundle = parser.parseQueryResponse(queryResponse, endpoint); + assert.deepEqual(bundle.values[0], VariadicValue.fromItemsCounted(new U32Value(42), new U32Value(43))); + assert.deepEqual(bundle.values[1], VariadicValue.fromItemsCounted(new StringValue("a"), new StringValue("b"), new StringValue("c"))); + assert.deepEqual(bundle.values[2], new BigUIntValue(42)); + }); + it("should parse contract outcome", async () => { let endpointModifiers = new EndpointModifiers("", []); let outputParameters = [