From 330be5315d6841e6636c3e1105aa3e625da0b10b Mon Sep 17 00:00:00 2001 From: Claudiu-Marcel Bruda Date: Thu, 3 Feb 2022 12:23:58 +0200 Subject: [PATCH 1/7] fix guard messages when endpoints are not found --- src/smartcontracts/abi.ts | 4 ++-- src/smartcontracts/typesystem/contractInterface.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/smartcontracts/abi.ts b/src/smartcontracts/abi.ts index cf91f535..5595cd62 100644 --- a/src/smartcontracts/abi.ts +++ b/src/smartcontracts/abi.ts @@ -1,6 +1,6 @@ import { ErrInvariantFailed } from "../errors"; import { loadAbiRegistry } from "../testutils"; -import { guardValueIsSet } from "../utils"; +import { guardValueIsSetWithMessage } from "../utils"; import { ContractFunction } from "./function"; import { AbiRegistry, EndpointDefinition } from "./typesystem"; import { ContractInterface } from "./typesystem/contractInterface"; @@ -33,7 +33,7 @@ export class SmartContractAbi { name = name.name; } let result = this.getAllEndpoints().find(item => item.name === name); - guardValueIsSet("result", result); + guardValueIsSetWithMessage(`endpoint [${name}] not found`, result); return result!; } diff --git a/src/smartcontracts/typesystem/contractInterface.ts b/src/smartcontracts/typesystem/contractInterface.ts index 4c23e6ee..058ae253 100644 --- a/src/smartcontracts/typesystem/contractInterface.ts +++ b/src/smartcontracts/typesystem/contractInterface.ts @@ -1,4 +1,4 @@ -import { guardValueIsSet } from "../../utils"; +import { guardValueIsSetWithMessage } from "../../utils"; import { EndpointDefinition } from "./endpoint"; const NamePlaceholder = "?"; @@ -32,7 +32,7 @@ export class ContractInterface { getEndpoint(name: string): EndpointDefinition { let result = this.endpoints.find(e => e.name == name); - guardValueIsSet("result", result); + guardValueIsSetWithMessage(`endpoint [${name}] not found`, result); return result!; } } From 616e9c3af74a78e86fe459ef0f69fd6030a712fe Mon Sep 17 00:00:00 2001 From: Claudiu-Marcel Bruda Date: Thu, 3 Feb 2022 12:46:13 +0200 Subject: [PATCH 2/7] update nft marketplace abi with getAllAuctions --- src/testdata/esdt-nft-marketplace.abi.json | 305 +++++++++++++++++---- 1 file changed, 256 insertions(+), 49 deletions(-) diff --git a/src/testdata/esdt-nft-marketplace.abi.json b/src/testdata/esdt-nft-marketplace.abi.json index ea395cc3..9d667b12 100644 --- a/src/testdata/esdt-nft-marketplace.abi.json +++ b/src/testdata/esdt-nft-marketplace.abi.json @@ -1,4 +1,21 @@ { + "buildInfo": { + "rustc": { + "version": "1.59.0-nightly", + "commitHash": "399ba6bb377ce02224b57c4d6e127e160fa76b34", + "commitDate": "2022-01-03", + "channel": "Nightly", + "short": "rustc 1.59.0-nightly (399ba6bb3 2022-01-03)" + }, + "contractCrate": { + "name": "esdt-nft-marketplace", + "version": "0.0.0" + }, + "framework": { + "name": "elrond-wasm", + "version": "0.25.0" + } + }, "name": "EsdtNftMarketplace", "constructor": { "inputs": [ @@ -12,6 +29,7 @@ "endpoints": [ { "name": "setCutPercentage", + "mutability": "mutable", "inputs": [ { "name": "new_cut_percentage", @@ -22,6 +40,7 @@ }, { "name": "auctionToken", + "mutability": "mutable", "payableInTokens": [ "*" ], @@ -46,16 +65,35 @@ "name": "opt_accepted_payment_token_nonce", "type": "optional", "multi_arg": true + }, + { + "name": "opt_sft_max_one_per_payment", + "type": "optional", + "multi_arg": true + }, + { + "name": "opt_start_time", + "type": "optional", + "multi_arg": true } ], - "outputs": [] + "outputs": [ + { + "type": "u64" + } + ] }, { "name": "bid", + "mutability": "mutable", "payableInTokens": [ "*" ], "inputs": [ + { + "name": "auction_id", + "type": "u64" + }, { "name": "nft_type", "type": "TokenIdentifier" @@ -69,7 +107,26 @@ }, { "name": "endAuction", + "mutability": "mutable", + "inputs": [ + { + "name": "auction_id", + "type": "u64" + } + ], + "outputs": [] + }, + { + "name": "buySft", + "mutability": "mutable", + "payableInTokens": [ + "*" + ], "inputs": [ + { + "name": "auction_id", + "type": "u64" + }, { "name": "nft_type", "type": "TokenIdentifier" @@ -77,33 +134,94 @@ { "name": "nft_nonce", "type": "u64" + }, + { + "name": "opt_sft_buy_amount", + "type": "optional", + "multi_arg": true } ], "outputs": [] }, { "name": "withdraw", + "mutability": "mutable", "inputs": [ { - "name": "nft_type", + "name": "auction_id", + "type": "u64" + } + ], + "outputs": [] + }, + { + "name": "claimTokens", + "mutability": "mutable", + "inputs": [ + { + "name": "token_id", "type": "TokenIdentifier" }, { - "name": "nft_nonce", + "name": "token_nonce", "type": "u64" + }, + { + "name": "claim_destination", + "type": "Address" } ], "outputs": [] }, { - "name": "isAlreadyUpForAuction", + "name": "getMarketplaceCutPercentage", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "BigUint" + } + ] + }, + { + "name": "getLastValidAuctionId", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "u64" + } + ] + }, + { + "name": "getClaimableAmount", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", + "name": "address", + "type": "Address" + }, + { + "name": "token_id", "type": "TokenIdentifier" }, { - "name": "nft_nonce", + "name": "token_nonce", + "type": "u64" + } + ], + "outputs": [ + { + "type": "BigUint" + } + ] + }, + { + "name": "doesAuctionExist", + "mutability": "readonly", + "inputs": [ + { + "name": "auction_id", "type": "u64" } ], @@ -114,136 +232,192 @@ ] }, { - "name": "getPaymentTokenForAuctionedNft", + "name": "getAuctionedToken", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, + "name": "auction_id", + "type": "u64" + } + ], + "outputs": [ { - "name": "nft_nonce", + "type": "optional>", + "multi_result": true + } + ] + }, + { + "name": "getAuctionType", + "mutability": "mutable", + "inputs": [ + { + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option" + "type": "AuctionType" + } + ] + }, + { + "name": "getPaymentTokenForAuction", + "mutability": "readonly", + "inputs": [ + { + "name": "auction_id", + "type": "u64" + } + ], + "outputs": [ + { + "type": "optional>", + "multi_result": true } ] }, { "name": "getMinMaxBid", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, + "name": "auction_id", + "type": "u64" + } + ], + "outputs": [ { - "name": "nft_nonce", + "type": "optional>", + "multi_result": true + } + ] + }, + { + "name": "getStartTime", + "mutability": "readonly", + "inputs": [ + { + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option>" + "type": "optional", + "multi_result": true } ] }, { "name": "getDeadline", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, - { - "name": "nft_nonce", + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option" + "type": "optional", + "multi_result": true } ] }, { "name": "getOriginalOwner", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, - { - "name": "nft_nonce", + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option
" + "type": "optional
", + "multi_result": true } ] }, { "name": "getCurrentWinningBid", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, - { - "name": "nft_nonce", + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option" + "type": "optional", + "multi_result": true } ] }, { "name": "getCurrentWinner", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, - { - "name": "nft_nonce", + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option
" + "type": "optional
", + "multi_result": true } ] }, { "name": "getFullAuctionData", + "mutability": "readonly", "inputs": [ { - "name": "nft_type", - "type": "TokenIdentifier" - }, - { - "name": "nft_nonce", + "name": "auction_id", "type": "u64" } ], "outputs": [ { - "type": "Option" + "type": "optional", + "multi_result": true + } + ] + }, + { + "name": "getAllAuctions", + "mutability": "readonly", + "inputs": [], + "outputs": [ + { + "type": "List>" } ] } ], + "hasCallback": false, "types": { "Auction": { "type": "struct", "fields": [ + { + "name": "auctioned_token", + "type": "EsdtToken" + }, + { + "name": "nr_auctioned_tokens", + "type": "BigUint" + }, + { + "name": "auction_type", + "type": "AuctionType" + }, { "name": "payment_token", "type": "EsdtToken" @@ -254,7 +428,11 @@ }, { "name": "max_bid", - "type": "BigUint" + "type": "Option" + }, + { + "name": "start_time", + "type": "u64" }, { "name": "deadline", @@ -271,6 +449,35 @@ { "name": "current_winner", "type": "Address" + }, + { + "name": "marketplace_cut_percentage", + "type": "BigUint" + }, + { + "name": "creator_royalties_percentage", + "type": "BigUint" + } + ] + }, + "AuctionType": { + "type": "enum", + "variants": [ + { + "name": "None", + "discriminant": 0 + }, + { + "name": "Nft", + "discriminant": 1 + }, + { + "name": "SftAll", + "discriminant": 2 + }, + { + "name": "SftOnePerPayment", + "discriminant": 3 } ] }, @@ -288,4 +495,4 @@ ] } } -} \ No newline at end of file +} From c02730e073e3e21fd7011732bf1ae20abec97793 Mon Sep 17 00:00:00 2001 From: Claudiu-Marcel Bruda Date: Thu, 3 Feb 2022 12:47:36 +0200 Subject: [PATCH 3/7] add basic TokenIdentifier tests --- src/smartcontracts/codec/binary.spec.ts | 43 +++++++-- .../typesystem/typeMapper.spec.ts | 88 ++++++++++--------- 2 files changed, 83 insertions(+), 48 deletions(-) diff --git a/src/smartcontracts/codec/binary.spec.ts b/src/smartcontracts/codec/binary.spec.ts index a928fe9b..cdb3c77b 100644 --- a/src/smartcontracts/codec/binary.spec.ts +++ b/src/smartcontracts/codec/binary.spec.ts @@ -1,6 +1,6 @@ import { assert } from "chai"; import { BinaryCodec, BinaryCodecConstraints } from "./binary"; -import { AddressType, AddressValue, BigIntType, BigUIntType, BigUIntValue, BooleanType, BooleanValue, I16Type, I32Type, I64Type, I8Type, NumericalType, NumericalValue, Struct, Field, StructType, TypedValue, U16Type, U32Type, U32Value, U64Type, U64Value, U8Type, U8Value, List, ListType, EnumType, EnumVariantDefinition, EnumValue, ArrayVec, ArrayVecType, U16Value } from "../typesystem"; +import { AddressType, AddressValue, BigIntType, BigUIntType, BigUIntValue, BooleanType, BooleanValue, I16Type, I32Type, I64Type, I8Type, NumericalType, NumericalValue, Struct, Field, StructType, TypedValue, U16Type, U32Type, U32Value, U64Type, U64Value, U8Type, U8Value, List, ListType, EnumType, EnumVariantDefinition, EnumValue, ArrayVec, ArrayVecType, U16Value, TokenIdentifierType, TokenIdentifierValue } from "../typesystem"; import { discardSuperfluousBytesInTwosComplement, discardSuperfluousZeroBytes, isMsbOne } from "./utils"; import { Address } from "../../address"; import { Balance } from "../../balance"; @@ -112,7 +112,7 @@ describe("test binary codec (advanced)", () => { assert.deepEqual(decodedTopLevel, list); }); - it("benchmark: should work well with large lists", async function() { + it("benchmark: should work well with large lists", async function () { let numItems = 2 ** 12; let codec = new BinaryCodec(new BinaryCodecConstraints({ maxListLength: numItems, @@ -133,7 +133,7 @@ describe("test binary codec (advanced)", () => { assert.equal(buffer.length, 4 + numItems * 4); console.time("decoding"); - let [decodedList, decodedLength] = codec.decodeNested(buffer, new ListType(new U32Type())); + let [decodedList, decodedLength] = codec.decodeNested(buffer, new ListType(new U32Type())); console.timeEnd("decoding"); assert.equal(decodedLength, buffer.length); assert.deepEqual(decodedList, list); @@ -214,6 +214,39 @@ describe("test binary codec (advanced)", () => { }); }); + it("should encode / decode structs containing a TokenIdentifier", async () => { + let codec = new BinaryCodec(); + let paymentType = new StructType( + "Payment", + [ + new FieldDefinition("token_identifier", "", new TokenIdentifierType()), + new FieldDefinition("nonce", "", new U64Type()), + new FieldDefinition("amount", "", new BigUIntType()), + ] + ); + + let paymentStruct = new Struct(paymentType, [ + new Field(new TokenIdentifierValue(Buffer.from("TEST-1234")), "token_identifier"), + new Field(new U64Value(new BigNumber(42)), "nonce"), + new Field(new BigUIntValue(new BigNumber("123450000000000000000")), "amount") + ]); + + let encodedExpected = serialized("[00000009|544553542d31323334] [000000000000002a] [00000009|06b13680ef11f90000]"); + let encoded = codec.encodeNested(paymentStruct); + assert.deepEqual(encoded, encodedExpected); + + let [decoded, decodedLength] = codec.decodeNested(encodedExpected, paymentType); + assert.equal(decodedLength, encodedExpected.length); + assert.deepEqual(decoded, paymentStruct); + + let decodedPayment = decoded.valueOf(); + assert.deepEqual(decodedPayment, { + token_identifier: Buffer.from("TEST-1234"), + nonce: new BigNumber(42), + amount: new BigNumber("123450000000000000000"), + }); + }); + it("should encode / decode enums", async () => { let codec = new BinaryCodec(); let enumType = new EnumType("Colour", [ @@ -263,8 +296,8 @@ describe("test binary codec (advanced)", () => { ]); let enumType = new EnumType("Colour", [ - orangeVariant, - blueVariant + orangeVariant, + blueVariant ]); let orange = new EnumValue(enumType, orangeVariant, [ diff --git a/src/smartcontracts/typesystem/typeMapper.spec.ts b/src/smartcontracts/typesystem/typeMapper.spec.ts index ef3d9d7a..052d2cea 100644 --- a/src/smartcontracts/typesystem/typeMapper.spec.ts +++ b/src/smartcontracts/typesystem/typeMapper.spec.ts @@ -10,59 +10,61 @@ import { OptionalType } from "./algebraic"; import { CompositeType } from "./composite"; import { ListType, OptionType } from "./generic"; import { TupleType } from "./tuple"; +import { TokenIdentifierType } from ".."; type TypeConstructor = new (...typeParameters: Type[]) => Type; describe("test mapper", () => { - let parser = new TypeExpressionParser(); - let mapper = new TypeMapper(); + let parser = new TypeExpressionParser(); + let mapper = new TypeMapper(); - it("should map primitive types", () => { - testMapping("u8", U8Type); - testMapping("u16", U16Type); - testMapping("u32", U32Type); - testMapping("u64", U64Type); - testMapping("BigUint", BigUIntType); - }); + it("should map primitive types", () => { + testMapping("u8", U8Type); + testMapping("u16", U16Type); + testMapping("u32", U32Type); + testMapping("u64", U64Type); + testMapping("BigUint", BigUIntType); + testMapping("TokenIdentifier", TokenIdentifierType); + }); - it("should map generic types", () => { - testMapping("Option", OptionType, [new U64Type()]); - testMapping("List", ListType, [new U64Type()]); - }); + it("should map generic types", () => { + testMapping("Option", OptionType, [new U64Type()]); + testMapping("List", ListType, [new U64Type()]); + }); - it("should map variadic types", () => { - testMapping("VarArgs", VariadicType, [new U32Type()]); - testMapping("VarArgs", VariadicType, [new BytesType()]); - testMapping("MultiResultVec", VariadicType, [new U32Type()]); - testMapping("MultiResultVec
", VariadicType, [new AddressType()]); - }); + it("should map variadic types", () => { + testMapping("VarArgs", VariadicType, [new U32Type()]); + testMapping("VarArgs", VariadicType, [new BytesType()]); + testMapping("MultiResultVec", VariadicType, [new U32Type()]); + testMapping("MultiResultVec
", VariadicType, [new AddressType()]); + }); - it("should map complex generic, composite, variadic types", () => { - testMapping("MultiResultVec>", VariadicType, [ - new CompositeType(new I32Type(), new BytesType()), - ]); - testMapping("VarArgs>", VariadicType, [new CompositeType(new I32Type(), new BytesType())]); - testMapping("OptionalResult
", OptionalType, [new AddressType()]); - }); + it("should map complex generic, composite, variadic types", () => { + testMapping("MultiResultVec>", VariadicType, [ + new CompositeType(new I32Type(), new BytesType()), + ]); + testMapping("VarArgs>", VariadicType, [new CompositeType(new I32Type(), new BytesType())]); + testMapping("OptionalResult
", OptionalType, [new AddressType()]); + }); - it("should map tuples", () => { - testMapping("tuple2", TupleType, [new U32Type(), new BytesType()]); - testMapping("tuple2", TupleType, [new AddressType(), new BigUIntType()]); - testMapping("tuple3", TupleType, [new U32Type(), new BytesType(), new U64Type()]); - //TODO: Rewrite serializer to map more complex objects + it("should map tuples", () => { + testMapping("tuple2", TupleType, [new U32Type(), new BytesType()]); + testMapping("tuple2", TupleType, [new AddressType(), new BigUIntType()]); + testMapping("tuple3", TupleType, [new U32Type(), new BytesType(), new U64Type()]); + //TODO: Rewrite serializer to map more complex objects - // After improvement enable the following test - // testMapping("tuple2, Address>", TupleType, [ - // new TupleType(new Type("tuple3", [new U32Type(), new BytesType(), new U64Type()])), - // new AddressType(), - // ]); - }); + // After improvement enable the following test + // testMapping("tuple2, Address>", TupleType, [ + // new TupleType(new Type("tuple3", [new U32Type(), new BytesType(), new U64Type()])), + // new AddressType(), + // ]); + }); - function testMapping(expression: string, constructor: TypeConstructor, typeParameters: Type[] = []) { - let type = parser.parse(expression); - let mappedType = mapper.mapType(type); + function testMapping(expression: string, constructor: TypeConstructor, typeParameters: Type[] = []) { + let type = parser.parse(expression); + let mappedType = mapper.mapType(type); - assert.instanceOf(mappedType, constructor); - assert.deepEqual(mappedType, new constructor(...typeParameters)); - } + assert.instanceOf(mappedType, constructor); + assert.deepEqual(mappedType, new constructor(...typeParameters)); + } }); From 7625f619755f6f51c873650ad1044242b4bf8f0c Mon Sep 17 00:00:00 2001 From: Claudiu-Marcel Bruda Date: Thu, 3 Feb 2022 12:48:14 +0200 Subject: [PATCH 4/7] add getAllAuctions test --- src/smartcontracts/wrapper/esdt.spec.ts | 47 +++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/smartcontracts/wrapper/esdt.spec.ts b/src/smartcontracts/wrapper/esdt.spec.ts index 54705929..bf4c85ab 100644 --- a/src/smartcontracts/wrapper/esdt.spec.ts +++ b/src/smartcontracts/wrapper/esdt.spec.ts @@ -1,6 +1,8 @@ import { Address, ContractWrapper, createBalanceBuilder, Egld, Token, SystemWrapper, TokenType, setupInteractiveWithProvider } from "../.."; import { isOnBrowserTests, MockProvider, setupUnitTestWatcherTimeouts, TestWallet } from "../../testutils"; import { assert } from "chai"; +import { ArgSerializer } from ".."; +import BigNumber from "bignumber.js"; describe("test ESDT transfers via the smart contract wrapper", async function () { let dummyAddress = new Address("erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3"); @@ -18,7 +20,7 @@ describe("test ESDT transfers via the smart contract wrapper", async function () market.address(dummyAddress).sender(alice).gas(500_000); }); - it("calling ", async function () { + it("formats the call arguments with an NFT transfer", async function () { setupUnitTestWatcherTimeouts(); let minBid = 100; @@ -45,7 +47,48 @@ describe("test ESDT transfers via the smart contract wrapper", async function () "544553542d31323334", "1388" ]); - }); + }) + + it("binary codec encodes / decodes the result of getAllAuctions", async function () { + let definitions = market.getSmartContract().getAbi().getEndpoint("getAllAuctions").output; + let data = "AAAAAAAAABAAAAALVEVTVC1mZWVkNjAAAAAAAAAAAQAAAAEBAQAAAARFR0xEAAAAAAAAAAAAAAAIDeC2s6dkAAABAAAACIrHIwSJ6AAAAAAAAGH5jkwAAAAAYfmYSHcAUz3KJ/38F1qkbu0H68K6R6XlPs1xLnqrL6ipWMb5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgPoAAAAAgnE"; + let serializer = new ArgSerializer(); + + const values = serializer.buffersToValues([Buffer.from(data, 'base64')], definitions); + + assert.equal(values.length, 1); + const value = values[0].valueOf(); + + const expected = Array.from([{ + field0: new BigNumber(16), + field1: { + auction_type: { + fields: [], + name: "Nft" + }, + auctioned_token: { + nonce: new BigNumber(1), + token_type: Buffer.from("TEST-feed60"), + }, + creator_royalties_percentage: new BigNumber(2500), + current_bid: new BigNumber(0), + current_winner: new Address("0000000000000000000000000000000000000000000000000000000000000000"), + deadline: new BigNumber(1643747400), + marketplace_cut_percentage: new BigNumber(1000), + max_bid: new BigNumber("10000000000000000000"), + min_bid: new BigNumber("1000000000000000000"), + nr_auctioned_tokens: new BigNumber(1), + original_owner: new Address("erd1wuq9x0w2yl7lc96653hw6pltc2ay0f098mxhztn64vh6322ccmussa83g9"), + payment_token: { + nonce: new BigNumber(0), + token_type: Buffer.from("EGLD") + }, + start_time: new BigNumber(1643744844) + } + }]); + + assert.deepEqual(value, expected); + }) }); function callBuffersToStrings(values: Buffer[]): string[] { From b4bbcaa565d20f5d24c9303b72948cb2d8332a5d Mon Sep 17 00:00:00 2001 From: Claudiu-Marcel Bruda Date: Thu, 3 Feb 2022 12:48:30 +0200 Subject: [PATCH 5/7] fix recursivity issue --- src/smartcontracts/typesystem/typeMapper.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/smartcontracts/typesystem/typeMapper.ts b/src/smartcontracts/typesystem/typeMapper.ts index f722a8a0..8476e449 100644 --- a/src/smartcontracts/typesystem/typeMapper.ts +++ b/src/smartcontracts/typesystem/typeMapper.ts @@ -97,7 +97,7 @@ export class TypeMapper { } } - mapType(type: Type): Type { + mapRecursiveType(type: Type): Type | null { let isGeneric = type.isGenericType(); if (type instanceof EnumType) { @@ -114,13 +114,21 @@ export class TypeMapper { // This will call mapType() recursively, for all the type parameters. return this.mapGenericType(type); } + return null; + } + + mapType(type: Type): Type { + let mappedType = this.mapRecursiveType(type); + if (mappedType !== null) { + return mappedType; + } let knownClosedType = this.closedTypesMap.get(type.getName()); if (!knownClosedType) { throw new errors.ErrTypingSystem(`Cannot map the type "${type.getName()}" to a known type`); } - return knownClosedType; + return this.mapRecursiveType(knownClosedType) ?? knownClosedType; } feedCustomType(type: Type): void { From 20ced10ae4ade0961c8249acc43461d45cf3d6c3 Mon Sep 17 00:00:00 2001 From: Andrei Bancioiu Date: Tue, 8 Feb 2022 13:15:34 +0200 Subject: [PATCH 6/7] Bump version, since previously published "8.0.2-alpha.1" version is picked as "latest" version by npmjs. --- CHANGELOG.md | 3 +++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec6be7e7..e08ab008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [Unreleased] +## [9.0.2] + - Bump version, since previously published `8.0.2-alpha.1` version is picked as `latest` version by npmjs. + ## [9.0.1] - [Add globals polyfill for Buffer](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/112) diff --git a/package-lock.json b/package-lock.json index 415db346..67f6ab9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@elrondnetwork/erdjs", - "version": "8.0.1-alpha.22", + "version": "9.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5458db58..c6749457 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@elrondnetwork/erdjs", - "version": "9.0.1", + "version": "9.0.2", "description": "Smart Contracts interaction framework", "main": "out/index.js", "types": "out/index.d.js", From 607b5ca1b9e7278560892fa4bf73f511f1761117 Mon Sep 17 00:00:00 2001 From: Andrei Bancioiu Date: Tue, 8 Feb 2022 13:28:02 +0200 Subject: [PATCH 7/7] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e08ab008..b24ae051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [Unreleased] ## [9.0.2] + - [Fix recursivity issue when mapping types](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/114). - Bump version, since previously published `8.0.2-alpha.1` version is picked as `latest` version by npmjs. ## [9.0.1]