Base64.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. const { expect } = require('chai');
  2. const Base64 = artifacts.require('$Base64');
  3. contract('Strings', function () {
  4. beforeEach(async function () {
  5. this.base64 = await Base64.new();
  6. });
  7. describe('from bytes - base64', function () {
  8. it('converts to base64 encoded string with double padding', async function () {
  9. const TEST_MESSAGE = 'test';
  10. const input = web3.utils.asciiToHex(TEST_MESSAGE);
  11. expect(await this.base64.$encode(input)).to.equal('dGVzdA==');
  12. });
  13. it('converts to base64 encoded string with single padding', async function () {
  14. const TEST_MESSAGE = 'test1';
  15. const input = web3.utils.asciiToHex(TEST_MESSAGE);
  16. expect(await this.base64.$encode(input)).to.equal('dGVzdDE=');
  17. });
  18. it('converts to base64 encoded string without padding', async function () {
  19. const TEST_MESSAGE = 'test12';
  20. const input = web3.utils.asciiToHex(TEST_MESSAGE);
  21. expect(await this.base64.$encode(input)).to.equal('dGVzdDEy');
  22. });
  23. it('empty bytes', async function () {
  24. expect(await this.base64.$encode([])).to.equal('');
  25. });
  26. });
  27. });