diff --git a/package-lock.json b/package-lock.json index 23228e33..96c74793 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "13.13.0", + "version": "13.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "13.13.0", + "version": "13.13.1", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index a68e5f55..0bc0b4cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "13.13.0", + "version": "13.13.1", "description": "MultiversX SDK for JavaScript and TypeScript", "author": "MultiversX", "homepage": "https://multiversx.com", diff --git a/src/smartcontracts/codeMetadata.spec.ts b/src/smartcontracts/codeMetadata.spec.ts index 7b0eab88..7d184c4e 100644 --- a/src/smartcontracts/codeMetadata.spec.ts +++ b/src/smartcontracts/codeMetadata.spec.ts @@ -63,7 +63,7 @@ describe("CodeMetadata Class Tests", function () { CodeMetadata.fromBuffer(buffer); }, Error, - "Buffer is too short.", + "code metadata buffer has length 1, expected 2", ); }); diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index 9d2fa2bc..7efff036 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -1,3 +1,5 @@ +export const CodeMetadataLength = 2; + /** * The metadata of a Smart Contract, as an abstraction. */ @@ -6,7 +8,6 @@ export class CodeMetadata { public readable: boolean; public payable: boolean; public payableBySc: boolean; - private static readonly codeMetadataLength = 2; static ByteZero = { Upgradeable: 1, @@ -48,8 +49,8 @@ export class CodeMetadata { * Creates a metadata object from a buffer. */ static fromBuffer(buffer: Buffer): CodeMetadata { - if (buffer.length < this.codeMetadataLength) { - throw new Error("Buffer is too short."); + if (buffer.length != CodeMetadataLength) { + throw new Error(`code metadata buffer has length ${buffer.length}, expected ${CodeMetadataLength}`); } const byteZero = buffer[0]; diff --git a/src/smartcontracts/codec/codemetadata.ts b/src/smartcontracts/codec/codemetadata.ts index a631502d..e5502ad8 100644 --- a/src/smartcontracts/codec/codemetadata.ts +++ b/src/smartcontracts/codec/codemetadata.ts @@ -1,16 +1,14 @@ -import { CodeMetadata } from "../codeMetadata"; +import { CodeMetadata, CodeMetadataLength } from "../codeMetadata"; import { CodeMetadataValue } from "../typesystem/codeMetadata"; export class CodeMetadataCodec { decodeNested(buffer: Buffer): [CodeMetadataValue, number] { - const codeMetadata = CodeMetadata.fromBuffer(buffer); - - return [new CodeMetadataValue(codeMetadata), length]; + const codeMetadata = CodeMetadata.fromBuffer(buffer.slice(0, CodeMetadataLength)); + return [new CodeMetadataValue(codeMetadata), CodeMetadataLength]; } decodeTopLevel(buffer: Buffer): CodeMetadataValue { const codeMetadata = CodeMetadata.fromBuffer(buffer); - return new CodeMetadataValue(codeMetadata); }