Add Strings.equal (#3774)

Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Matteo Casonato
2022-12-28 22:23:24 +01:00
committed by GitHub
parent f799475d93
commit 7a6a9d1516
4 changed files with 37 additions and 0 deletions

View File

@ -83,4 +83,29 @@ contract('Strings', function (accounts) {
expect(await this.strings.methods['toHexString(address)'](addr)).to.equal(addr);
});
});
describe('equal', function () {
it('compares two empty strings', async function () {
expect(await this.strings.methods['equal(string,string)']('', '')).to.equal(true);
});
it('compares two equal strings', async function () {
expect(await this.strings.methods['equal(string,string)']('a', 'a')).to.equal(true);
});
it('compares two different strings', async function () {
expect(await this.strings.methods['equal(string,string)']('a', 'b')).to.equal(false);
});
it('compares two different strings of different lengths', async function () {
expect(await this.strings.methods['equal(string,string)']('a', 'aa')).to.equal(false);
expect(await this.strings.methods['equal(string,string)']('aa', 'a')).to.equal(false);
});
it('compares two different strings of different (big) lengths', async function () {
const str1 = 'a'.repeat(201);
const str2 = 'a'.repeat(200) + 'b';
expect(await this.strings.methods['equal(string,string)'](str1, str2)).to.equal(false);
});
});
});