Skip to content

Commit

Permalink
Update code metadata to follow specs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Dec 18, 2024
1 parent d482a67 commit be16a79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/abi/codeMetadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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",
Expand All @@ -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(), {
Expand Down
6 changes: 3 additions & 3 deletions src/abi/codeMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/abi/codec/codemetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/abi/smartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit be16a79

Please sign in to comment.