Migrate utils to ethersjs v6 (#4736)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
@ -1,33 +1,29 @@
|
||||
const { ethers } = require('hardhat');
|
||||
const { expect } = require('chai');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const Base64 = artifacts.require('$Base64');
|
||||
async function fixture() {
|
||||
const mock = await ethers.deployContract('$Base64');
|
||||
return { mock };
|
||||
}
|
||||
|
||||
contract('Strings', function () {
|
||||
describe('Strings', function () {
|
||||
beforeEach(async function () {
|
||||
this.base64 = await Base64.new();
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
describe('from bytes - base64', function () {
|
||||
it('converts to base64 encoded string with double padding', async function () {
|
||||
const TEST_MESSAGE = 'test';
|
||||
const input = web3.utils.asciiToHex(TEST_MESSAGE);
|
||||
expect(await this.base64.$encode(input)).to.equal('dGVzdA==');
|
||||
});
|
||||
for (const { title, input, expected } of [
|
||||
{ title: 'converts to base64 encoded string with double padding', input: 'test', expected: 'dGVzdA==' },
|
||||
{ title: 'converts to base64 encoded string with single padding', input: 'test1', expected: 'dGVzdDE=' },
|
||||
{ title: 'converts to base64 encoded string without padding', input: 'test12', expected: 'dGVzdDEy' },
|
||||
{ title: 'empty bytes', input: '0x', expected: '' },
|
||||
])
|
||||
it(title, async function () {
|
||||
const raw = ethers.isBytesLike(input) ? input : ethers.toUtf8Bytes(input);
|
||||
|
||||
it('converts to base64 encoded string with single padding', async function () {
|
||||
const TEST_MESSAGE = 'test1';
|
||||
const input = web3.utils.asciiToHex(TEST_MESSAGE);
|
||||
expect(await this.base64.$encode(input)).to.equal('dGVzdDE=');
|
||||
});
|
||||
|
||||
it('converts to base64 encoded string without padding', async function () {
|
||||
const TEST_MESSAGE = 'test12';
|
||||
const input = web3.utils.asciiToHex(TEST_MESSAGE);
|
||||
expect(await this.base64.$encode(input)).to.equal('dGVzdDEy');
|
||||
});
|
||||
|
||||
it('empty bytes', async function () {
|
||||
expect(await this.base64.$encode([])).to.equal('');
|
||||
});
|
||||
expect(await this.mock.$encode(raw)).to.equal(ethers.encodeBase64(raw));
|
||||
expect(await this.mock.$encode(raw)).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user