Skip to content
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
6 changes: 3 additions & 3 deletions yarn-project/foundation/src/buffer/buffer32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class Buffer32 extends BaseBuffer32 {
if (buffer.length != 28) {
throw new Error(`Expected Buffer32 input buffer to be 28 bytes`);
}
const padded = Buffer.concat([Buffer.alloc(this.SIZE - 28), buffer]);
const padded = Buffer.concat([Buffer.alloc(Buffer32.SIZE - 28), buffer]);
return new Buffer32(padded);
}

Expand All @@ -99,8 +99,8 @@ export class Buffer32 extends BaseBuffer32 {
if (str.startsWith('0x')) {
str = str.slice(2);
}
if (str.length !== this.SIZE * 2) {
throw new Error(`Expected string to be ${this.SIZE * 2} characters long, but was ${str.length}`);
if (str.length !== Buffer32.SIZE * 2) {
throw new Error(`Expected string to be ${Buffer32.SIZE * 2} characters long, but was ${str.length}`);
}
return new Buffer32(Buffer.from(str, 'hex'));
}
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/foundation/src/schemas/schemas.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Buffer32 } from '../buffer/buffer32.js';
import { schemas } from './schemas.js';

describe('schemas', () => {
describe('Buffer32', () => {
it('parses a valid hex string into a Buffer32', () => {
const buffer32 = Buffer32.random();
const parsed = schemas.Buffer32.parse(buffer32.toString());
expect(parsed).toBeInstanceOf(Buffer32);
expect(parsed.equals(buffer32)).toBe(true);
});
});

describe('Boolean', () => {
it('accepts a boolean value', () => {
expect(schemas.Boolean.parse(true)).toEqual(true);
Expand Down
Loading