Add Memory utility library (#5189)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
This commit is contained in:
Ernesto García
2025-07-10 01:15:27 -06:00
committed by GitHub
parent a5350ecdd3
commit 21cd7e8aa3
7 changed files with 146 additions and 1 deletions

39
test/utils/Memory.test.js Normal file
View File

@ -0,0 +1,39 @@
const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
async function fixture() {
const mock = await ethers.deployContract('$Memory');
return { mock };
}
describe('Memory', function () {
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
});
describe('free pointer', function () {
it('sets free memory pointer', async function () {
const ptr = ethers.toBeHex(0xa0, 32);
await expect(this.mock.$setFreeMemoryPointer(ptr)).to.not.be.reverted;
});
it('gets free memory pointer', async function () {
await expect(this.mock.$getFreeMemoryPointer()).to.eventually.equal(
ethers.toBeHex(0x80, 32), // Default pointer
);
});
});
describe('pointer conversions', function () {
it('asBytes32', async function () {
const ptr = ethers.toBeHex('0x1234', 32);
await expect(this.mock.$asBytes32(ptr)).to.eventually.equal(ptr);
});
it('asPointer', async function () {
const ptr = ethers.toBeHex('0x1234', 32);
await expect(this.mock.$asPointer(ptr)).to.eventually.equal(ptr);
});
});
});