Skip to content

Commit

Permalink
fix: constant names in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Feb 23, 2024
1 parent a38f739 commit 238a2b1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions sdk/test/unit/hex/bytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {bytesToHex, hexToBytes} from '../../../src';
describe('hex/bytes', () => {
describe('hexToBytes', () => {
it('Should convert hex strings to a buffer', () => {
const inputs = [
const tests = [
{hex: '0x00', serializedBuffer: '0'},
{hex: '0x10', serializedBuffer: '16'},
{hex: '0xff', serializedBuffer: '255'},
Expand All @@ -23,9 +23,9 @@ describe('hex/bytes', () => {
},
];

for (const input of inputs) {
const result = hexToBytes(input.hex);
expect(result.join(',')).toEqual(input.serializedBuffer);
for (const test of tests) {
const result = hexToBytes(test.hex);
expect(result.join(',')).toEqual(test.serializedBuffer);
}
});
});
Expand Down
16 changes: 8 additions & 8 deletions sdk/test/unit/hex/strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ensure0x, strip0x} from '../../../src';
describe('hex/strings', () => {
describe('ensure0x', () => {
it('Should ensure 0x prefixes', () => {
const inputs = [
const tests = [
// strip
{in: '0', out: '0x0'},
{in: '00', out: '0x00'},
Expand All @@ -15,15 +15,15 @@ describe('hex/strings', () => {
{in: '0x1234567890abcdef', out: '0x1234567890abcdef'},
];

for (const input of inputs) {
const result = ensure0x(input.in);
expect(result).toEqual(input.out);
for (const test of tests) {
const result = ensure0x(test.in);
expect(result).toEqual(test.out);
}
});
});
describe('strip0x', () => {
it('Should strip 0x prefixes', () => {
const inputs = [
const tests = [
// strip
{in: '0x0', out: '0'},
{in: '0x00', out: '00'},
Expand All @@ -35,9 +35,9 @@ describe('hex/strings', () => {
{in: '1234567890abcdef', out: '1234567890abcdef'},
];

for (const input of inputs) {
const result = strip0x(input.in);
expect(result).toEqual(input.out);
for (const test of tests) {
const result = strip0x(test.in);
expect(result).toEqual(test.out);
}
});
});
Expand Down
40 changes: 20 additions & 20 deletions sdk/test/unit/plugin/proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {ADDRESS_ONE, ADDRESS_ZERO} from '../../constants';
describe('plugin/proposal', () => {
describe('encodeProposalId', () => {
it('Should encode a nonce-based proposalId', () => {
const entries = [
const tests = [
{
addr: ADDRESS_ZERO,
nonce: 0,
Expand Down Expand Up @@ -48,14 +48,14 @@ describe('plugin/proposal', () => {
},
];

for (const entry of entries) {
expect(encodeProposalId(entry.addr, entry.nonce)).toBe(entry.output);
for (const test of tests) {
expect(encodeProposalId(test.addr, test.nonce)).toBe(test.output);
}
});
});
describe('decodeProposalId', () => {
it('Should decode a nonce-based proposalId', () => {
const entries = [
const tests = [
{
input: '0x0000000000000000000000000000000000000000_0x0',
addr: '0x0000000000000000000000000000000000000000',
Expand Down Expand Up @@ -93,16 +93,16 @@ describe('plugin/proposal', () => {
},
];

for (const entry of entries) {
const result = decodeProposalId(entry.input);
expect(result.pluginAddress).toBe(entry.addr);
expect(result.id).toBe(entry.nonce);
for (const test of tests) {
const result = decodeProposalId(test.input);
expect(result.pluginAddress).toBe(test.addr);
expect(result.id).toBe(test.nonce);
}
});
});
describe('getExtendedProposalId', () => {
it('Should get an extended version of a proposal id', () => {
const entries = [
const tests = [
{
in: '0x0000000000000000000000000000000000000000_0x1',
out: '0x0000000000000000000000000000000000000000_0x0000000000000000000000000000000000000000000000000000000000000001',
Expand All @@ -125,19 +125,19 @@ describe('plugin/proposal', () => {
},
];

for (const entry of entries) {
if (entry.error) {
expect(() => getExtendedProposalId(entry.in)).toThrow(entry.error);
for (const test of tests) {
if (test.error) {
expect(() => getExtendedProposalId(test.in)).toThrow(test.error);
} else {
const result = getExtendedProposalId(entry.in);
expect(result).toBe(entry.out);
const result = getExtendedProposalId(test.in);
expect(result).toBe(test.out);
}
}
});
});
describe('getCompactProposalId', () => {
it('Should get a compact version of a proposal id', () => {
const entries = [
const tests = [
{
in: '0x0000000000000000000000000000000000000000_0x0000000000000000000000000000000000000000000000000000000000000001',
out: '0x0000000000000000000000000000000000000000_0x1',
Expand Down Expand Up @@ -167,12 +167,12 @@ describe('plugin/proposal', () => {
},
];

for (const entry of entries) {
if (entry.error) {
expect(() => getCompactProposalId(entry.in)).toThrow(entry.error);
for (const test of tests) {
if (test.error) {
expect(() => getCompactProposalId(test.in)).toThrow(test.error);
} else {
const result = getCompactProposalId(entry.in);
expect(result).toBe(entry.out);
const result = getCompactProposalId(test.in);
expect(result).toBe(test.out);
}
}
});
Expand Down
14 changes: 7 additions & 7 deletions sdk/test/unit/plugin/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
describe('plugin/utils', () => {
describe('encodeRatio', () => {
it('Should encode a bigint from a float and the number of digits', () => {
const inputs = [
const tests = [
{float: 0.5, digits: 1, out: BigInt(5), error: null},
{float: 1, digits: 4, out: BigInt(10000), error: null},
{float: 0.25555, digits: 2, out: BigInt(26), error: null},
Expand All @@ -22,15 +22,15 @@ describe('plugin/utils', () => {
{float: 0.5, digits: 18, out: null, error: InvalidDigitsValueError},
];

for (const input of inputs) {
if (input.error) {
expect(() => encodeRatio(input.float, input.digits)).toThrow(
input.error
for (const test of tests) {
if (test.error) {
expect(() => encodeRatio(test.float, test.digits)).toThrow(
test.error
);
continue;
}
const result = encodeRatio(input.float, input.digits);
expect(result.toString()).toEqual(input.out.toString());
const result = encodeRatio(test.float, test.digits);
expect(result.toString()).toEqual(test.out.toString());
}
});
});
Expand Down

0 comments on commit 238a2b1

Please sign in to comment.