From b9c5d7007b2eca77edefde892c5595837c10be81 Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 14:06:51 +0100 Subject: [PATCH 01/14] update code metadata properties to be public --- src/smartcontracts/codeMetadata.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index 46e74a13..58d3562e 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -2,10 +2,10 @@ * The metadata of a Smart Contract, as an abstraction. */ export class CodeMetadata { - private upgradeable: boolean; - private readable: boolean; - private payable: boolean; - private payableBySc: boolean; + public upgradeable: boolean; + public readable: boolean; + public payable: boolean; + public payableBySc: boolean; /** * Creates a metadata object. By default, set the `upgradeable` attribute, and uset all others. From 930a79f999921f1e6b38a101d8ec3759644aa654 Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 14:09:01 +0100 Subject: [PATCH 02/14] add code metadata instantiation from buffer --- src/smartcontracts/codeMetadata.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index 58d3562e..5131d854 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -22,6 +22,25 @@ export class CodeMetadata { this.payableBySc = payableBySc } + /** + * Creates a metadata object from a buffer. + */ + static fromBuffer(buffer: Buffer): CodeMetadata { + if (buffer.length < 2) { + throw new Error('Buffer is too short.'); + } + + let byteZero = buffer[0]; + let byteOne = buffer[1]; + + let upgradeable = (byteZero & ByteZero.Upgradeable) !== 0; + let readable = (byteZero & ByteZero.Readable) !== 0; + let payable = (byteOne & ByteOne.Payable) !== 0; + let payableBySc = (byteOne & ByteOne.PayableBySc) !== 0; + + return new CodeMetadata(upgradeable, readable, payable, payableBySc); + } + /** * Adjust the metadata (the `upgradeable` attribute), when preparing the deployment transaction. */ From a2146ba3b306dafe8755bf13dc10847d4426a6d4 Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 14:09:40 +0100 Subject: [PATCH 03/14] add code metadata tests --- src/smartcontracts/codeMetadata.spec.ts | 52 +++++++++++++++++++++++++ src/smartcontracts/codeMetadata.ts | 4 +- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/smartcontracts/codeMetadata.spec.ts diff --git a/src/smartcontracts/codeMetadata.spec.ts b/src/smartcontracts/codeMetadata.spec.ts new file mode 100644 index 00000000..8a1383c9 --- /dev/null +++ b/src/smartcontracts/codeMetadata.spec.ts @@ -0,0 +1,52 @@ +import { assert } from "chai"; +import { CodeMetadata, ByteZero, ByteOne } from "./codeMetadata"; + +describe("CodeMetadata Class Tests", function() { + it("should create a default CodeMetadata instance", function() { + const metadata = new CodeMetadata(); + assert.isTrue(metadata.upgradeable); + assert.isFalse(metadata.readable); + assert.isFalse(metadata.payable); + assert.isFalse(metadata.payableBySc); + }); + + it("should toggle properties correctly", function() { + const metadata = new CodeMetadata(); + metadata.toggleUpgradeable(false); + metadata.toggleReadable(true); + metadata.togglePayable(true); + metadata.togglePayableBySc(true); + + assert.isFalse(metadata.upgradeable); + assert.isTrue(metadata.readable); + assert.isTrue(metadata.payable); + assert.isTrue(metadata.payableBySc); + }); + + it("should convert to buffer correctly", function() { + const metadata = new CodeMetadata(true, true, true, true); + const buffer = metadata.toBuffer(); + + assert.equal(buffer.length, 2); + assert.equal(buffer[0], ByteZero.Upgradeable | ByteZero.Readable); + assert.equal(buffer[1], ByteOne.Payable | ByteOne.PayableBySc); + }); + + it("should create from buffer correctly", function() { + const buffer = Buffer.from([ByteZero.Upgradeable | ByteZero.Readable, ByteOne.Payable | ByteOne.PayableBySc]); + const metadata = CodeMetadata.fromBuffer(buffer); + + assert.isTrue(metadata.upgradeable); + assert.isTrue(metadata.readable); + assert.isTrue(metadata.payable); + assert.isTrue(metadata.payableBySc); + }); + + it("should handle buffer too short error", function() { + const buffer = Buffer.from([ByteZero.Upgradeable]); + + assert.throws(() => { + CodeMetadata.fromBuffer(buffer); + }, Error, "Buffer is too short."); + }); +}); diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index 5131d854..88d0dfb6 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -119,13 +119,13 @@ export class CodeMetadata { } } -enum ByteZero { +export enum ByteZero { Upgradeable = 1, Reserved2 = 2, Readable = 4 } -enum ByteOne { +export enum ByteOne { Reserved1 = 1, Payable = 2, PayableBySc = 4 From 281f65176b2522dde2f64b83781ac92d3b34e47d Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 14:15:05 +0100 Subject: [PATCH 04/14] add further code metadata test --- src/smartcontracts/codeMetadata.spec.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/smartcontracts/codeMetadata.spec.ts b/src/smartcontracts/codeMetadata.spec.ts index 8a1383c9..17187a59 100644 --- a/src/smartcontracts/codeMetadata.spec.ts +++ b/src/smartcontracts/codeMetadata.spec.ts @@ -32,7 +32,7 @@ describe("CodeMetadata Class Tests", function() { assert.equal(buffer[1], ByteOne.Payable | ByteOne.PayableBySc); }); - it("should create from buffer correctly", function() { + it("should create from buffer correctly when all flags are set", function() { const buffer = Buffer.from([ByteZero.Upgradeable | ByteZero.Readable, ByteOne.Payable | ByteOne.PayableBySc]); const metadata = CodeMetadata.fromBuffer(buffer); @@ -42,6 +42,16 @@ describe("CodeMetadata Class Tests", function() { assert.isTrue(metadata.payableBySc); }); + it.only("should create from buffer correctly when some flags are set", function() { + const buffer = Buffer.from([ByteZero.Upgradeable, ByteOne.PayableBySc]); + const metadata = CodeMetadata.fromBuffer(buffer); + + assert.isTrue(metadata.upgradeable); + assert.isFalse(metadata.readable); + assert.isFalse(metadata.payable); + assert.isTrue(metadata.payableBySc); + }); + it("should handle buffer too short error", function() { const buffer = Buffer.from([ByteZero.Upgradeable]); From 8540bc7d35505e8726cd6813686def3b2fc3119a Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 14:18:26 +0100 Subject: [PATCH 05/14] refactor code metadata remove whitespace + change vars to const --- src/smartcontracts/codeMetadata.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index 88d0dfb6..ecf4e135 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -9,7 +9,7 @@ export class CodeMetadata { /** * Creates a metadata object. By default, set the `upgradeable` attribute, and uset all others. - * + * * @param upgradeable Whether the contract is upgradeable * @param readable Whether other contracts can read this contract's data (without calling one of its pure functions) * @param payable Whether the contract is payable @@ -30,13 +30,13 @@ export class CodeMetadata { throw new Error('Buffer is too short.'); } - let byteZero = buffer[0]; - let byteOne = buffer[1]; + const byteZero = buffer[0]; + const byteOne = buffer[1]; - let upgradeable = (byteZero & ByteZero.Upgradeable) !== 0; - let readable = (byteZero & ByteZero.Readable) !== 0; - let payable = (byteOne & ByteOne.Payable) !== 0; - let payableBySc = (byteOne & ByteOne.PayableBySc) !== 0; + const upgradeable = (byteZero & ByteZero.Upgradeable) !== 0; + const readable = (byteZero & ByteZero.Readable) !== 0; + const payable = (byteOne & ByteOne.Payable) !== 0; + const payableBySc = (byteOne & ByteOne.PayableBySc) !== 0; return new CodeMetadata(upgradeable, readable, payable, payableBySc); } @@ -68,7 +68,7 @@ export class CodeMetadata { togglePayableBySc(value: boolean) { this.payableBySc = value; } - + /** * Converts the metadata to the protocol-friendly representation. */ From fa83a1ab16a3eea725ae390540f865b28eeb310b Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 15:29:08 +0100 Subject: [PATCH 06/14] add code instantiation from hex --- src/smartcontracts/code.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/smartcontracts/code.ts b/src/smartcontracts/code.ts index 6a3c3b55..6d9d5861 100644 --- a/src/smartcontracts/code.ts +++ b/src/smartcontracts/code.ts @@ -15,6 +15,13 @@ export class Code { return new Code(code.toString("hex")); } + /** + * Creates a Code object from a hex-encoded string. + */ + static fromHex(hex: string): Code { + return new Code(hex) + } + /** * Returns the bytecode as a hex-encoded string. */ From 78780458dcf343face3fc2ebcb31210f0639f3f1 Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 15:29:17 +0100 Subject: [PATCH 07/14] add code hash computation --- src/smartcontracts/code.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/smartcontracts/code.ts b/src/smartcontracts/code.ts index 6d9d5861..bd069387 100644 --- a/src/smartcontracts/code.ts +++ b/src/smartcontracts/code.ts @@ -1,3 +1,8 @@ +import { Hash } from "../hash"; + +const createHasher = require('blake2b') +const CODE_HASH_LENGTH = 32 + /** * Bytecode of a Smart Contract, as an abstraction. */ @@ -32,4 +37,12 @@ export class Code { valueOf(): Buffer { return Buffer.from(this.hex, "hex"); } + + computeHash(): Hash { + const hash = createHasher(CODE_HASH_LENGTH) + .update(this.valueOf()) + .digest('hex') + + return new Hash(hash) + } } From 6a87354b5e19c84259c2fb0775a2dd5f3a8c0782 Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 16 Nov 2023 15:29:37 +0100 Subject: [PATCH 08/14] add code tests --- src/smartcontracts/code.spec.ts | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/smartcontracts/code.spec.ts diff --git a/src/smartcontracts/code.spec.ts b/src/smartcontracts/code.spec.ts new file mode 100644 index 00000000..0fa090df --- /dev/null +++ b/src/smartcontracts/code.spec.ts @@ -0,0 +1,37 @@ +import { assert } from "chai"; +import { Code } from "./code"; +import { Hash } from "../hash"; + +describe("Code Class Tests", function() { + const sampleHex = "abcdef0123456789"; + const sampleBuffer = Buffer.from(sampleHex, "hex"); + + it("should create Code from buffer", function() { + const code = Code.fromBuffer(sampleBuffer); + + assert.instanceOf(code, Code); + assert.equal(code.toString(), sampleHex); + }); + + it("should create Code from hex string", function() { + const code = Code.fromHex(sampleHex); + + assert.instanceOf(code, Code); + assert.equal(code.toString(), sampleHex); + }); + + it("should return the correct buffer from valueOf", function() { + const code = Code.fromHex(sampleHex); + const buffer = code.valueOf(); + + assert.isTrue(Buffer.isBuffer(buffer)); + assert.equal(buffer.toString("hex"), sampleHex); + }); + + it("should compute hash correctly", function() { + const code = Code.fromHex(sampleHex); + const hash = code.computeHash(); + + assert.instanceOf(hash, Hash); + }); +}); From eebfd3314f429d7fca794f596592296ba6e36043 Mon Sep 17 00:00:00 2001 From: micha vie Date: Fri, 17 Nov 2023 11:01:16 +0100 Subject: [PATCH 09/14] refactor code metadata byte info --- src/smartcontracts/codeMetadata.spec.ts | 15 ++++++---- src/smartcontracts/codeMetadata.ts | 40 ++++++++++++------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/smartcontracts/codeMetadata.spec.ts b/src/smartcontracts/codeMetadata.spec.ts index 17187a59..6bb0bdf3 100644 --- a/src/smartcontracts/codeMetadata.spec.ts +++ b/src/smartcontracts/codeMetadata.spec.ts @@ -1,5 +1,5 @@ import { assert } from "chai"; -import { CodeMetadata, ByteZero, ByteOne } from "./codeMetadata"; +import { CodeMetadata } from "./codeMetadata"; describe("CodeMetadata Class Tests", function() { it("should create a default CodeMetadata instance", function() { @@ -28,12 +28,15 @@ describe("CodeMetadata Class Tests", function() { const buffer = metadata.toBuffer(); assert.equal(buffer.length, 2); - assert.equal(buffer[0], ByteZero.Upgradeable | ByteZero.Readable); - assert.equal(buffer[1], ByteOne.Payable | ByteOne.PayableBySc); + assert.equal(buffer[0], CodeMetadata.ByteZero.Upgradeable | CodeMetadata.ByteZero.Readable); + assert.equal(buffer[1], CodeMetadata.ByteOne.Payable | CodeMetadata.ByteOne.PayableBySc); }); it("should create from buffer correctly when all flags are set", function() { - const buffer = Buffer.from([ByteZero.Upgradeable | ByteZero.Readable, ByteOne.Payable | ByteOne.PayableBySc]); + const buffer = Buffer.from([ + CodeMetadata.ByteZero.Upgradeable | CodeMetadata.ByteZero.Readable, + CodeMetadata.ByteOne.Payable | CodeMetadata.ByteOne.PayableBySc, + ]); const metadata = CodeMetadata.fromBuffer(buffer); assert.isTrue(metadata.upgradeable); @@ -43,7 +46,7 @@ describe("CodeMetadata Class Tests", function() { }); it.only("should create from buffer correctly when some flags are set", function() { - const buffer = Buffer.from([ByteZero.Upgradeable, ByteOne.PayableBySc]); + const buffer = Buffer.from([CodeMetadata.ByteZero.Upgradeable, CodeMetadata.ByteOne.PayableBySc]); const metadata = CodeMetadata.fromBuffer(buffer); assert.isTrue(metadata.upgradeable); @@ -53,7 +56,7 @@ describe("CodeMetadata Class Tests", function() { }); it("should handle buffer too short error", function() { - const buffer = Buffer.from([ByteZero.Upgradeable]); + const buffer = Buffer.from([CodeMetadata.ByteZero.Upgradeable]); assert.throws(() => { CodeMetadata.fromBuffer(buffer); diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index ecf4e135..03a54992 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -7,6 +7,18 @@ export class CodeMetadata { public payable: boolean; public payableBySc: boolean; + static ByteZero = { + Upgradeable: 1, + Reserved2: 2, + Readable: 4 + }; + + static ByteOne = { + Reserved1: 1, + Payable: 2, + PayableBySc: 4 + }; + /** * Creates a metadata object. By default, set the `upgradeable` attribute, and uset all others. * @@ -33,10 +45,10 @@ export class CodeMetadata { const byteZero = buffer[0]; const byteOne = buffer[1]; - const upgradeable = (byteZero & ByteZero.Upgradeable) !== 0; - const readable = (byteZero & ByteZero.Readable) !== 0; - const payable = (byteOne & ByteOne.Payable) !== 0; - const payableBySc = (byteOne & ByteOne.PayableBySc) !== 0; + const upgradeable = (byteZero & CodeMetadata.ByteZero.Upgradeable) !== 0; + const readable = (byteZero & CodeMetadata.ByteZero.Readable) !== 0; + const payable = (byteOne & CodeMetadata.ByteOne.Payable) !== 0; + const payableBySc = (byteOne & CodeMetadata.ByteOne.PayableBySc) !== 0; return new CodeMetadata(upgradeable, readable, payable, payableBySc); } @@ -77,16 +89,16 @@ export class CodeMetadata { let byteOne = 0; if (this.upgradeable) { - byteZero |= ByteZero.Upgradeable; + byteZero |= CodeMetadata.ByteZero.Upgradeable; } if (this.readable) { - byteZero |= ByteZero.Readable; + byteZero |= CodeMetadata.ByteZero.Readable; } if (this.payable) { - byteOne |= ByteOne.Payable; + byteOne |= CodeMetadata.ByteOne.Payable; } if (this.payableBySc) { - byteOne |= ByteOne.PayableBySc; + byteOne |= CodeMetadata.ByteOne.PayableBySc; } return Buffer.from([byteZero, byteOne]); @@ -118,15 +130,3 @@ export class CodeMetadata { this.payableBySc == other.payableBySc; } } - -export enum ByteZero { - Upgradeable = 1, - Reserved2 = 2, - Readable = 4 -} - -export enum ByteOne { - Reserved1 = 1, - Payable = 2, - PayableBySc = 4 -} From f4b91cd7ff712de00ab6d01b62d0aa0a540ee318 Mon Sep 17 00:00:00 2001 From: micha vie Date: Fri, 17 Nov 2023 11:22:07 +0100 Subject: [PATCH 10/14] update code hash computation to buffer output --- src/smartcontracts/code.spec.ts | 3 ++- src/smartcontracts/code.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/smartcontracts/code.spec.ts b/src/smartcontracts/code.spec.ts index 0fa090df..1a5f3d94 100644 --- a/src/smartcontracts/code.spec.ts +++ b/src/smartcontracts/code.spec.ts @@ -32,6 +32,7 @@ describe("Code Class Tests", function() { const code = Code.fromHex(sampleHex); const hash = code.computeHash(); - assert.instanceOf(hash, Hash); + assert.instanceOf(hash, Buffer); + assert.equal(hash.toString('hex'), 'ac86b78afd9bdda3641a47a4aff2a7ee26acd40cc534d63655e9dfbf3f890a02') }); }); diff --git a/src/smartcontracts/code.ts b/src/smartcontracts/code.ts index bd069387..54c540a3 100644 --- a/src/smartcontracts/code.ts +++ b/src/smartcontracts/code.ts @@ -38,11 +38,11 @@ export class Code { return Buffer.from(this.hex, "hex"); } - computeHash(): Hash { + computeHash(): Buffer { const hash = createHasher(CODE_HASH_LENGTH) .update(this.valueOf()) - .digest('hex') + .digest(); - return new Hash(hash) + return Buffer.from(hash) } } From fe2d0609c901d3dbd13343257324b518660ca32a Mon Sep 17 00:00:00 2001 From: micha vie Date: Tue, 21 Nov 2023 11:13:01 +0100 Subject: [PATCH 11/14] remove rogue test filtering --- src/smartcontracts/codeMetadata.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/smartcontracts/codeMetadata.spec.ts b/src/smartcontracts/codeMetadata.spec.ts index 6bb0bdf3..f5d56508 100644 --- a/src/smartcontracts/codeMetadata.spec.ts +++ b/src/smartcontracts/codeMetadata.spec.ts @@ -45,7 +45,7 @@ describe("CodeMetadata Class Tests", function() { assert.isTrue(metadata.payableBySc); }); - it.only("should create from buffer correctly when some flags are set", function() { + it("should create from buffer correctly when some flags are set", function() { const buffer = Buffer.from([CodeMetadata.ByteZero.Upgradeable, CodeMetadata.ByteOne.PayableBySc]); const metadata = CodeMetadata.fromBuffer(buffer); From b0ec5f8e3252c42845f99ebce9e623b73c7ead03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Sun, 26 Nov 2023 19:57:16 +0200 Subject: [PATCH 12/14] Bump version, run npm audit fix. --- package-lock.json | 201 ++++++++++++++++++++++++++++++++++++++++------ package.json | 6 +- 2 files changed, 178 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 266b424f..aab51dfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "12.14.0", + "version": "12.15.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "12.14.0", + "version": "12.15.0", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", @@ -19,7 +19,7 @@ "protobufjs": "7.2.4" }, "devDependencies": { - "@multiversx/sdk-network-providers": "2.0.0", + "@multiversx/sdk-network-providers": "2.2.0", "@multiversx/sdk-wallet": "3.0.0", "@multiversx/sdk-wallet-next": "npm:@multiversx/sdk-wallet@4.0.0", "@types/assert": "1.4.6", @@ -27,7 +27,7 @@ "@types/mocha": "9.1.0", "@types/node": "13.13.2", "assert": "2.0.0", - "axios": "0.24.0", + "axios": "1.6.2", "browserify": "17.0.0", "chai": "4.2.0", "esmify": "2.1.1", @@ -486,18 +486,29 @@ } }, "node_modules/@multiversx/sdk-network-providers": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@multiversx/sdk-network-providers/-/sdk-network-providers-2.0.0.tgz", - "integrity": "sha512-87QlwC2kaNtywDv2IVX/cavRfR4D5N7XgqOvsZTyMXRVbfWOUlDocrRr5BdvmC1gDdSOQH++nFEDHiMfnKmRng==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@multiversx/sdk-network-providers/-/sdk-network-providers-2.2.0.tgz", + "integrity": "sha512-2n/+7Ap6S9rJGTiX38GCZ2TmY9zQ1U7o1DwnWpHNRJRxArSN/xzLrbcSKy8InMyc+4A+VHf5pV0Pk8NdPV6++w==", "dev": true, "dependencies": { - "axios": "0.24.0", + "axios": "1.6.1", "bech32": "1.1.4", "bignumber.js": "9.0.1", "buffer": "6.0.3", "json-bigint": "1.0.0" } }, + "node_modules/@multiversx/sdk-network-providers/node_modules/axios": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.1.tgz", + "integrity": "sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@multiversx/sdk-transaction-decoder": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@multiversx/sdk-transaction-decoder/-/sdk-transaction-decoder-1.0.2.tgz", @@ -812,6 +823,12 @@ "node": "*" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -825,12 +842,14 @@ } }, "node_modules/axios": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", - "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dev": true, "dependencies": { - "follow-redirects": "^1.14.4" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/babel-code-frame": { @@ -1597,6 +1616,18 @@ "source-map": "~0.5.3" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1799,6 +1830,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/deps-sort": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/deps-sort/-/deps-sort-2.0.1.tgz", @@ -2066,9 +2106,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", + "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", "dev": true, "funding": [ { @@ -2094,6 +2134,20 @@ "is-callable": "^1.1.3" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2932,6 +2986,27 @@ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", "dev": true }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -3444,6 +3519,12 @@ "node": ">=12.0.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "node_modules/public-encrypt": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", @@ -4730,16 +4811,29 @@ "dev": true }, "@multiversx/sdk-network-providers": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@multiversx/sdk-network-providers/-/sdk-network-providers-2.0.0.tgz", - "integrity": "sha512-87QlwC2kaNtywDv2IVX/cavRfR4D5N7XgqOvsZTyMXRVbfWOUlDocrRr5BdvmC1gDdSOQH++nFEDHiMfnKmRng==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@multiversx/sdk-network-providers/-/sdk-network-providers-2.2.0.tgz", + "integrity": "sha512-2n/+7Ap6S9rJGTiX38GCZ2TmY9zQ1U7o1DwnWpHNRJRxArSN/xzLrbcSKy8InMyc+4A+VHf5pV0Pk8NdPV6++w==", "dev": true, "requires": { - "axios": "0.24.0", + "axios": "1.6.1", "bech32": "1.1.4", "bignumber.js": "9.0.1", "buffer": "6.0.3", "json-bigint": "1.0.0" + }, + "dependencies": { + "axios": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.1.tgz", + "integrity": "sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g==", + "dev": true, + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + } } }, "@multiversx/sdk-transaction-decoder": { @@ -5018,6 +5112,12 @@ "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -5025,12 +5125,14 @@ "dev": true }, "axios": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", - "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dev": true, "requires": { - "follow-redirects": "^1.14.4" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "babel-code-frame": { @@ -5677,6 +5779,15 @@ "source-map": "~0.5.3" } }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -5847,6 +5958,12 @@ "integrity": "sha512-hsBd2qSVCRE+5PmNdHt1uzyrFu5d3RwmFDKzyNZMFq/EwDNJF7Ee5+D5oEKF0hU6LhtoUF1macFvOe4AskQC1Q==", "dev": true }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "deps-sort": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/deps-sort/-/deps-sort-2.0.1.tgz", @@ -6071,9 +6188,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", + "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", "dev": true }, "for-each": { @@ -6085,6 +6202,17 @@ "is-callable": "^1.1.3" } }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -6713,6 +6841,21 @@ } } }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "requires": { + "mime-db": "1.52.0" + } + }, "minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -7104,6 +7247,12 @@ "long": "^5.0.0" } }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "public-encrypt": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", diff --git a/package.json b/package.json index 03a9351f..9a87d744 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "12.14.0", + "version": "12.15.0", "description": "MultiversX SDK for JavaScript and TypeScript", "main": "out/index.js", "types": "out/index.d.js", @@ -35,7 +35,7 @@ "protobufjs": "7.2.4" }, "devDependencies": { - "@multiversx/sdk-network-providers": "2.0.0", + "@multiversx/sdk-network-providers": "2.2.0", "@multiversx/sdk-wallet": "3.0.0", "@multiversx/sdk-wallet-next": "npm:@multiversx/sdk-wallet@4.0.0", "@types/assert": "1.4.6", @@ -43,7 +43,7 @@ "@types/mocha": "9.1.0", "@types/node": "13.13.2", "assert": "2.0.0", - "axios": "0.24.0", + "axios": "1.6.2", "browserify": "17.0.0", "chai": "4.2.0", "esmify": "2.1.1", From 6f9b166d17a157a49c7c9a71307dbdf671af94a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Sun, 26 Nov 2023 19:57:41 +0200 Subject: [PATCH 13/14] Update test contract (wrt. Sirius / required "init()"). --- src/testdata/answer.wasm | Bin 111 -> 151 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/testdata/answer.wasm b/src/testdata/answer.wasm index 3ed833dba9d0a4364bd3094a7abd3b6b18578c6d..d82972a060391966f83e96de8e15bc7a68a4eb4c 100755 GIT binary patch delta 117 zcmd0w&Nx9MpM{x`k&%U!u>eT1GBYwTv2ifgGdebOuyC{Mv#{l+=H?ewGBL1Z=4F;J zFtV2xq!%Toq%trGrl*#K=9FaSCYGc+<`tKx7BMh$DKaxN@N;uA2sAb{GyqwGjEr?o OT8az`3<5v_kO%;V1sNRx delta 56 zcmbQvm_I>-k!hl~q^=wjTW)G@eo-Y8gJ61UNoY< Date: Tue, 28 Nov 2023 18:23:42 +0200 Subject: [PATCH 14/14] Fix after merge. Bump version. --- package-lock.json | 4 ++-- package.json | 2 +- src/smartcontracts/codeMetadata.spec.ts | 2 ++ src/smartcontracts/codeMetadata.ts | 17 +++-------------- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index aab51dfc..bc8d0488 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "12.15.0", + "version": "v13.0.0-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "12.15.0", + "version": "v13.0.0-alpha.2", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index 9a87d744..394d74d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "12.15.0", + "version": "v13.0.0-alpha.2", "description": "MultiversX SDK for JavaScript and TypeScript", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/smartcontracts/codeMetadata.spec.ts b/src/smartcontracts/codeMetadata.spec.ts index 314d4a95..685d8cf5 100644 --- a/src/smartcontracts/codeMetadata.spec.ts +++ b/src/smartcontracts/codeMetadata.spec.ts @@ -1,3 +1,5 @@ +import { assert } from "chai"; +import { CodeMetadata } from "./codeMetadata"; describe("CodeMetadata Class Tests", function () { it("should create a default CodeMetadata instance", function () { diff --git a/src/smartcontracts/codeMetadata.ts b/src/smartcontracts/codeMetadata.ts index 611fe0dd..2133e66e 100644 --- a/src/smartcontracts/codeMetadata.ts +++ b/src/smartcontracts/codeMetadata.ts @@ -6,6 +6,7 @@ export class CodeMetadata { public readable: boolean; public payable: boolean; public payableBySc: boolean; + private static readonly codeMetadataLength = 2; static ByteZero = { Upgradeable: 1, @@ -35,26 +36,14 @@ export class CodeMetadata { } static fromBytes(bytes: Uint8Array): CodeMetadata { - if (bytes.length !== this.codeMetadataLength) { - return new CodeMetadata(); - } - - const byteZero = bytes[0]; - const byteOne = bytes[1]; - - const upgradeable = (byteZero & ByteZero.Upgradeable) !== 0; - const readable = (byteZero & ByteZero.Readable) !== 0; - const payable = (byteOne & ByteOne.Payable) !== 0; - const payableBySc = (byteOne & ByteOne.PayableBySc) !== 0; - - return new CodeMetadata(upgradeable, readable, payable, payableBySc); + return CodeMetadata.fromBuffer(Buffer.from(bytes)); } /** * Creates a metadata object from a buffer. */ static fromBuffer(buffer: Buffer): CodeMetadata { - if (buffer.length < 2) { + if (buffer.length < this.codeMetadataLength) { throw new Error('Buffer is too short.'); }