From be16a79bd0ea086b4991a5ebcf7e90d1a00916d2 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 18 Dec 2024 11:43:05 +0200 Subject: [PATCH] Update code metadata to follow specs --- src/abi/codeMetadata.spec.ts | 8 ++++---- src/abi/codeMetadata.ts | 6 +++--- src/abi/codec/codemetadata.ts | 4 ++-- src/abi/smartContract.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/abi/codeMetadata.spec.ts b/src/abi/codeMetadata.spec.ts index 7d184c4e..2322a641 100644 --- a/src/abi/codeMetadata.spec.ts +++ b/src/abi/codeMetadata.spec.ts @@ -37,7 +37,7 @@ describe("CodeMetadata Class Tests", function () { CodeMetadata.ByteZero.Upgradeable | CodeMetadata.ByteZero.Readable, CodeMetadata.ByteOne.Payable | CodeMetadata.ByteOne.PayableBySc, ]); - const metadata = CodeMetadata.fromBuffer(buffer); + const metadata = CodeMetadata.newFromBuffer(buffer); assert.isTrue(metadata.upgradeable); assert.isTrue(metadata.readable); @@ -47,7 +47,7 @@ describe("CodeMetadata Class Tests", 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); + const metadata = CodeMetadata.newFromBuffer(buffer); assert.isTrue(metadata.upgradeable); assert.isFalse(metadata.readable); @@ -60,7 +60,7 @@ describe("CodeMetadata Class Tests", function () { assert.throws( () => { - CodeMetadata.fromBuffer(buffer); + CodeMetadata.newFromBuffer(buffer); }, Error, "code metadata buffer has length 1, expected 2", @@ -69,7 +69,7 @@ describe("CodeMetadata Class Tests", function () { it("should test code metadata from bytes", () => { const bytes = new Uint8Array([1, 0]); - const codeMetadata = CodeMetadata.fromBytes(bytes); + const codeMetadata = CodeMetadata.newFromBytes(bytes); assert.equal(codeMetadata.toString(), "0100"); assert.deepEqual(codeMetadata.toJSON(), { diff --git a/src/abi/codeMetadata.ts b/src/abi/codeMetadata.ts index 7efff036..34160f5c 100644 --- a/src/abi/codeMetadata.ts +++ b/src/abi/codeMetadata.ts @@ -41,14 +41,14 @@ export class CodeMetadata { this.payableBySc = payableBySc; } - static fromBytes(bytes: Uint8Array): CodeMetadata { - return CodeMetadata.fromBuffer(Buffer.from(bytes)); + static newFromBytes(bytes: Uint8Array): CodeMetadata { + return CodeMetadata.newFromBuffer(Buffer.from(bytes)); } /** * Creates a metadata object from a buffer. */ - static fromBuffer(buffer: Buffer): CodeMetadata { + static newFromBuffer(buffer: Buffer): CodeMetadata { if (buffer.length != CodeMetadataLength) { throw new Error(`code metadata buffer has length ${buffer.length}, expected ${CodeMetadataLength}`); } diff --git a/src/abi/codec/codemetadata.ts b/src/abi/codec/codemetadata.ts index e5502ad8..09682de2 100644 --- a/src/abi/codec/codemetadata.ts +++ b/src/abi/codec/codemetadata.ts @@ -3,12 +3,12 @@ import { CodeMetadataValue } from "../typesystem/codeMetadata"; export class CodeMetadataCodec { decodeNested(buffer: Buffer): [CodeMetadataValue, number] { - const codeMetadata = CodeMetadata.fromBuffer(buffer.slice(0, CodeMetadataLength)); + const codeMetadata = CodeMetadata.newFromBuffer(buffer.slice(0, CodeMetadataLength)); return [new CodeMetadataValue(codeMetadata), CodeMetadataLength]; } decodeTopLevel(buffer: Buffer): CodeMetadataValue { - const codeMetadata = CodeMetadata.fromBuffer(buffer); + const codeMetadata = CodeMetadata.newFromBuffer(buffer); return new CodeMetadataValue(codeMetadata); } diff --git a/src/abi/smartContract.ts b/src/abi/smartContract.ts index 2a48e597..624ada69 100644 --- a/src/abi/smartContract.ts +++ b/src/abi/smartContract.ts @@ -165,7 +165,7 @@ export class SmartContract implements ISmartContract { } { let metadata: CodeMetadata; if (codeMetadata) { - metadata = CodeMetadata.fromBytes(Buffer.from(codeMetadata.toString(), "hex")); + metadata = CodeMetadata.newFromBytes(Buffer.from(codeMetadata.toString(), "hex")); } else { metadata = new CodeMetadata(); }