Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code metadata to follow specs #554

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading