Port Base64 tests to truffle (#4926) (#4929)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Ernesto García
2024-02-29 10:59:48 -06:00
committed by GitHub
parent bd325d56b4
commit a6286d0fde
5 changed files with 55 additions and 12 deletions

View File

@ -1,8 +1,9 @@
const { expect } = require('chai');
const Base64 = artifacts.require('$Base64');
const Base64Dirty = artifacts.require('$Base64Dirty');
contract('Strings', function () {
contract('Base64', function () {
beforeEach(async function () {
this.base64 = await Base64.new();
});
@ -30,4 +31,13 @@ contract('Strings', function () {
expect(await this.base64.$encode([])).to.equal('');
});
});
it('Encode reads beyond the input buffer into dirty memory', async function () {
const mock = await Base64Dirty.new();
const buffer32 = Buffer.from(web3.utils.soliditySha3('example').replace(/0x/, ''), 'hex');
const buffer31 = buffer32.slice(0, -2);
expect(await mock.encode(buffer31)).to.equal(buffer31.toString('base64'));
expect(await mock.encode(buffer32)).to.equal(buffer32.toString('base64'));
});
});